playMaker

Author Topic: Detecting a device's platform, aka Operating System, or OS, in most cases  (Read 876 times)

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 653
    • View Profile
I used IsOnPlatformEvent.cs quite safely and happily thus far but a recent switch to iOS and an update of APIs and more has rendered this action unworkable.

Code: [Select]
Assets/PlayMaker Custom Actions/Application/IsOnPlatformEvent.cs(131,10): error CS0103: The name 'Enum' does not exist in the current context
Assets/PlayMaker Custom Actions/Application/IsOnPlatformEvent.cs(131,32): error CS0103: The name 'i' does not exist in the current context
Assets/PlayMaker Custom Actions/Application/IsOnPlatformEvent.cs(137,10): error CS0103: The name 'Enum' does not exist in the current context
Assets/PlayMaker Custom Actions/Application/IsOnPlatformEvent.cs(137,32): error CS0103: The name 'i' does not exist in the current context

I look into the script with Visual Studio, there are several suggestions for a workable fix. Does anyone have any idea which one would be the best solution here?

I tried an update through the Ecosystem but all actions are marked as updatable even when they're of the latest version so it's pointless.


On a side note, this action has the following description;

Quote
"The counterpart to 'PlatformDependentEvents'. Sends an Event if or if not on the specified Platforms."

This other action (plural to Events, but there's also one a bit different written PlatformDependentEvent.cs) also has a few fields which are in gray because of potential improvements.

These actions are practical because they provide a list (enum) of the known operating systems.
« Last Edit: March 06, 2021, 12:55:32 PM by Broken Stylus »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3905
  • Official Playmaker Support
    • View Profile
    • LinkedIn
It looks like the action got refactored at some point and the ios part was not updated. It's always tricky to refactor code with so many defines!

Replace the section starting at line 131 with this:

Code: [Select]
#if UNITY_IPHONE || UNITY_IOS
if(_flag == PlatformDependentFlags.UNITY_IPHONE )
{
UnityEngine.Debug.Log("---------- WE FIRE "+onEvent.Name);
isOnIPhone = true;
return;
}
if(_flag == PlatformDependentFlags.UNITY_IOS )
{
UnityEngine.Debug.Log("---------- WE FIRE "+onEvent.Name);
isOnIOS = true;
return;
}
#endif

Djaydino can you update the action on the Ecosystem?

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 653
    • View Profile
Ok! Many thanks, I will quickly try that.
DJ's two other actions, very closely related, would probably need a little refresh too. They're not broken but VS insists on improving on many lines, reducing the code here and there.

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 653
    • View Profile
Good news. I updated the script.
Now I'm assaulted with a bajillion errors because I used this action in prefabs.

Code: [Select]
[Prefab;child]: [FSM]: IsOnPlatformEvent: Action has changed since FSM was saved. Could not recover parameters. Parameters reset to default values.
UnityEngine.Debug:LogError(Object, Object)
HutongGames.PlayMaker.ActionReport:LogError(Fsm, FsmState, FsmStateAction, Int32, String, String) (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/ActionReport.cs:96)
HutongGames.PlayMaker.ActionData:LogError(Context, String) (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/ActionData.cs:1550)
HutongGames.PlayMaker.ActionData:CreateAction(Context, Int32) (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/ActionData.cs:934)
HutongGames.PlayMaker.ActionData:LoadActions(FsmState) (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/ActionData.cs:787)
HutongGames.PlayMaker.FsmState:get_Actions() (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:771)
HutongGames.PlayMakerEditor.FsmSearch:DoSearch() (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmSearch.cs:821)
HutongGames.PlayMakerEditor.FsmSearch:Update() (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmSearch.cs:404)
HutongGames.PlayMakerEditor.FsmSearch:Update(Fsm) (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmSearch.cs:221)
HutongGames.PlayMakerEditor.FsmSearch:UpdateAll() (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmSearch.cs:198)
HutongGames.PlayMakerEditor.FsmSearch:UpdateAllIfNeeded() (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmSearch.cs:168)
HutongGames.PlayMakerEditor.FsmEditor:Init() (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmEditor.cs:607)
HutongGames.PlayMakerEditor.FsmEditor:OnEnable() (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmEditor.cs:561)
HutongGames.PlayMakerEditor.FsmEditorWindow:Initialize() (at Assets/PlayMaker/Editor/FsmEditorWindow.cs:193)
HutongGames.PlayMakerEditor.BaseEditorWindow:OnGUI() (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/BaseEditorWindow.cs:131)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:197)

I can go inside the prefab and access the game object child that suffers the issue, but I can't display its FSM, active or not.

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 653
    • View Profile
I had to erase the script to sanitize the situation. Fortunately it was used in a few places but I'd dread think about larger projects being afflicted by a similar problem.
Since Ecosystem hosts the old version, I used the code from the old one on Github and changed the problematic bit. This has come with a new batch of troubles.
As pointed out here, it constantly generates loop exception errors.

Maybe this could be avoided by separating the iOS and iPhone directive codes? Would that work?

I also saw a more contracted form of the code using 'elif' here.

EDIT: I'm posting the link to the original thread, I saw the URL in the script.
http://hutonggames.com/playmakerforum/index.php?topic=15458.0
« Last Edit: March 08, 2021, 12:58:52 PM by Broken Stylus »

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 653
    • View Profile
So far so good, the separation worked well, iOS and iPhone are detected separately in Unity if building for iOS. No errors.
I'm not reordering the enum entries by category and updating the list, plus their respective booleans.

I hesitate to put UNITY_SWITCH for the Nintendo Switch, this would require a slightly different piece of code based on the official detection pattern.
Nintendo provides a specific version of Unity the moment you are accepted as an applicant to their registration program.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 6175
    • View Profile
    • jinxtergames
Hi

@broken Stylus
Could you post (ore use a pastebin link) the updated script so i can update on the ecosystem.
You can leave switch out.

I Think it would be good to have a new action using the RuntimePlatform Enum.

I'm thinking something like the Enum Switch Action but then checks the runtime instead of a enum value.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3905
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Good news. I updated the script.
Now I'm assaulted with a bajillion errors because I used this action in prefabs.

Code: [Select]
[Prefab;child]: [FSM]: IsOnPlatformEvent: Action has changed since FSM was saved. Could not recover parameters. Parameters reset to default values.
UnityEngine.Debug:LogError(Object, Object)
HutongGames.PlayMaker.ActionReport:LogError(Fsm, FsmState, FsmStateAction, Int32, String, String) (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/ActionReport.cs:96)
HutongGames.PlayMaker.ActionData:LogError(Context, String) (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/ActionData.cs:1550)
HutongGames.PlayMaker.ActionData:CreateAction(Context, Int32) (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/ActionData.cs:934)
HutongGames.PlayMaker.ActionData:LoadActions(FsmState) (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/ActionData.cs:787)
HutongGames.PlayMaker.FsmState:get_Actions() (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:771)
HutongGames.PlayMakerEditor.FsmSearch:DoSearch() (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmSearch.cs:821)
HutongGames.PlayMakerEditor.FsmSearch:Update() (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmSearch.cs:404)
HutongGames.PlayMakerEditor.FsmSearch:Update(Fsm) (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmSearch.cs:221)
HutongGames.PlayMakerEditor.FsmSearch:UpdateAll() (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmSearch.cs:198)
HutongGames.PlayMakerEditor.FsmSearch:UpdateAllIfNeeded() (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmSearch.cs:168)
HutongGames.PlayMakerEditor.FsmEditor:Init() (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmEditor.cs:607)
HutongGames.PlayMakerEditor.FsmEditor:OnEnable() (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/FsmEditor.cs:561)
HutongGames.PlayMakerEditor.FsmEditorWindow:Initialize() (at Assets/PlayMaker/Editor/FsmEditorWindow.cs:193)
HutongGames.PlayMakerEditor.BaseEditorWindow:OnGUI() (at C:/Projects/Playmaker_1.9.1/Projects/Playmaker.source.unity/Assets/PlayMaker/Editor/Classes/BaseEditorWindow.cs:131)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:197)

I can go inside the prefab and access the game object child that suffers the issue, but I can't display its FSM, active or not.

Strange, there's nothing in that edit that should cause this error. Maybe you were working with a script already modified from the github version...? The version on github won't compile on ios, so I was just fixing that problem. I would need to look at the script you're editing to know what happened here.

BTW, that error means a script has been modified and the exposed parameters have changed in a way that Playmaker can't recover the original parameter values, so the parameters have been reset. It's expected if you modify an action a lot, changing it's parameters (MonoBehaviours do the same thing, just silently). The error should go away once the FSM has been re-saved.

Note sure what you mean by "but I can't display its FSM, active or not." What were you seeing when you tried to edit the prefab FSM? Were there any errors?

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 653
    • View Profile
Quote
Maybe you were working with a script already modified from the github version...?

Not on this one, I directly went into the "virgin" script and just commented out the problematic iOS||iPhone section and inserted your code underneath, checked everything, compiled and got the errors. So Unity wasn't really seeing the changes, it seems. I thought that maybe I'd have to get into the state containing the action and just change everything one step at a time, but I was blocked out of the FSM.  >:(

Quote
The version on github won't compile on ios, so I was just fixing that problem. I would need to look at the script you're editing to know what happened here.

Ok. I'll provide it in a separate post.

Quote
BTW, that error means a script has been modified and the exposed parameters have changed in a way that Playmaker can't recover the original parameter values, so the parameters have been reset. It's expected if you modify an action a lot, changing it's parameters (MonoBehaviours do the same thing, just silently). The error should go away once the FSM has been re-saved.

On my side, I couldn't stop the error. The FSM containing the troublesome action in one of the prefab's children was not accessible in Graph View even when I made pseudo-changes in other parts of the prefab just to get the * and save the whole prefab manually.
I couldn't even delete the action or simply reset it to the necessary parameters.
I had to use a more violent solution.

I restarted Unity like two or three times too, went back into the prefab multiple times, tried to access the annoying FSM, etc. but it was blocked and the console kept being flooded.

So I decided to delete the action altogether, then open an advanced text editor and copy the whole script from the github version, then insert your modification and comment out the old iOS/iPhone part that was causing trouble.

I think the prefab made the whole thing very sensitive for some reason because I've been testing the action in some separate and independent game object, with its own test FSM (meaning, it's not an instance of any prefab), and earlier on today I even reverted to the version with your correction (piece of code which I reactivated/uncommented) while I commented out my own later modification (where I separated both iOS and iPhone checks) and also left commented out the original code block, and it doesn't throw me errors.
For now, I have also reintroduced this stable version of the action into the prefab and there is no error either.
Unity just wanted me to delete the script and start from scratch.
I reckon that prefabs can be bizarre sometimes, right from what I read on UnityAnswers and other places, they seem to be prone to corruption if adventurous changes are brought upon them.

Quote
Note sure what you mean by "but I can't display its FSM, active or not." What were you seeing when you tried to edit the prefab FSM? Were there any errors?

That's the thing, I'm not sure how I could describe that but I went into prefab edit mode on the prefab, I selected the prefab's child that had this error-related FSM on it, the one with the IsOnPlatformEvent action, but it just wouldn't load into the Graph View. It was however showing up in the Inspector just like any other FSM (I notice btw that the component has much less content now, I have to see if that's a design choice and if there are Prefs I need to change to display more information as it was done before, even right up to 1.9.0).

PS: nice update to the forum code, now all text remains crisp as ever. I now have to see if I can post pictures again.
« Last Edit: March 09, 2021, 06:10:41 AM by Broken Stylus »

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 653
    • View Profile
Hi

@broken Stylus
Could you post (ore use a pastebin link) the updated script so i can update on the ecosystem.
You can leave switch out.

I Think it would be good to have a new action using the RuntimePlatform Enum.

I'm thinking something like the Enum Switch Action but then checks the runtime instead of a enum value.

Yep. The annoying thing with enum is how static the order is, I'm surprised the designers of c# didn't come up with a solution to allow enums to be updated without breaking a software using older versions of this same enum.
I suppose a refactoring tool comparing code with both versions would be able to make changes where the old enum is replaced with the new one but then indexes don't get messed up and therefore get properly updated too.

There are systems which are clearly old, I was wondering if there was a need to create a separate "new" version of this action, like IsOnPlatformEvent2021, to reflect the types of platforms that are actually supported by Unity.

Apple has separated its respective phone and tablet OSes; phones still use iPhone OS or iOS, tablets use iPadOs, so maybe they should be in the script too now, but Unity hasn't changed the documentation with UNITY_IPADOS, put into the enum just in case?

There's the Nintendo Switch, I added it but I'm not sure it would work. It checks the Application and compares it to the RuntimePlatform and does a combined check with the enum's _flag value to see if it's ok on both sides.

Stadia is supposed to be supported by Unity but I'm not seeing any valid code in the Manual although it should probably work like it does for the Switch since it's listed in the same way.
https://docs.unity3d.com/ScriptReference/RuntimePlatform.html
There's also Cloud Rendering but I don't think Playmaker users would feel concerned by this.

I also added
Code: [Select]
Using Unity Engine because of
Code: [Select]
Application.platform == RuntimePlatform. but it's also possible to just append UnityEngine before them. I'm not that good at coding so I'll leave this to you.

I haven't bothered with "elif" syntax.
Switch functions might be good but it would lose the quick region test filtering.
« Last Edit: March 09, 2021, 06:05:29 AM by Broken Stylus »

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 653
    • View Profile
Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2020. All rights reserved. 
// License: Attribution 4.0 International(CC BY 4.0)
/*--- __ECO__ __PLAYMAKER__ __ACTION__ ---*/
// Author : Deek
// Additions and modifications : BrokenStylus

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Application)]
[HelpUrl("http://hutonggames.com/playmakerforum/index.php?topic=15458.0")]
[Tooltip("Sends an Event if on the specified Platforms or not. Detects the targeted build platform.")]
//[Note("Stadia and Cloud Rendering not yet supported.")]

public class IsOnPlatformEvent : FsmStateAction
{
[UIHint(UIHint.Description)]
public string desc = "Warning: Stadia and Cloud Rendering not yet supported.";

public enum PlatformDependentFlags
{
UNITY_EDITOR,
UNITY_EDITOR_WIN,
UNITY_EDITOR_OSX,
UNITY_EDITOR_LINUX, //added March 2021
UNITY_STANDALONE,
UNITY_STANDALONE_WIN,
UNITY_STANDALONE_OSX,
UNITY_STANDALONE_LINUX, //added March 2021
UNITY_WSA, //added March 2021
NETFX_CORE, //added March 2021
UNITY_WSA_10_0, //added March 2021
WINDOWS_UWP, //added March 2021
UNITY_WINRT,
UNITY_WEBPLAYER,
UNITY_WEBGL,
UNITY_FACEBOOK, //added March 2021
UNITY_FLASH,
UNITY_NACL,
UNITY_WII,
UNITY_SWITCH_Experimental, //added March 2021
UNITY_PS3,
UNITY_PS4,
UNITY_XBOX360,
UNITY_XBOXONE,
UNITY_LUMIN, //added March 2021
UNITY_STADIA_Unsupported, //added March 2021 - no code found
UNITY_TVOS,
UNITY_IOS,
UNITY_IPHONE,
UNITY_ANDROID,
UNITY_TIZEN,
UNITY_METRO,
UNITY_WP8,
UNITY_BLACKBERRY,
UNITY_ASSERTIONS, //added March 2021
UNITY_64, //added March 2021
UNITY_ANALYTICS, //added March 2021
UNITY_CLOUD_RENDERING_Unsupported, //added March 2021 - no code found
UNITY_DASHBOARD_WIDGET,
}

[RequiredField]
[Tooltip("The platforms")]
public PlatformDependentFlags[] platforms;

[Tooltip("The event to send IF on any of the specified platforms. Note: Gets send on the first platform it finds it is on.")]
public FsmEvent onEvent;

[Tooltip("The event to send IF NOT on any of the specified platforms.")]
public FsmEvent notOnEvent;

public static RuntimePlatform platform;

private bool isOnEditor = false;
private bool isOnEditorWin = false;
private bool isOnEditorOSX = false;
private bool isOnEditorLinux = false; //added March 2021

private bool isOnStandalone = false;
private bool isOnStandaloneWin = false;
private bool isOnStandaloneOSX = false;
private bool isOnStandaloneLinux = false;

private bool isOnWSA = false;  //added March 2021
private bool isOnNetFXCore = false; //added March 2021
private bool isOnWSA1010 = false; //added March 2021
private bool isOnWindowsUWP = false; //added March 2021
private bool isOnWinRT = false;

private bool isOnWebplayer = false;
private bool isOnWebGL = false;
private bool isOnFacebook = false; //added March 2021
private bool isOnFlash = false;
private bool isOnNACL = false;

private bool isOnWii = false;
private bool isOnSwitch = false; //added March 2021
private bool isOnPS3 = false;
private bool isOnPS4 = false;
private bool isOnXBOX360 = false;
private bool isOnXBoxOne = false;

private bool isOnLumin = false; //added March 2021
private bool isOnStadia = false; //added March 2021
private bool isOnTVOS = false;

private bool isOnIOS = false;
private bool isOnIPhone = false;
private bool isOnAndroid = false;
private bool isOnTizen = false;
private bool isOnMetro = false;
private bool isOnWP8 = false;
private bool isOnBlackberry = false;

private bool isOnAssertions = false; //added March 2021
private bool isOn64 = false; //added March 2021
private bool isOnUnityAnalytics = false; //added March 2021
private bool isOnCloudRendering = false; //added March 2021
private bool isOnDashboardWidget = false;


public override void Reset()
{
platforms = new PlatformDependentFlags[1];
platforms[0] = PlatformDependentFlags.UNITY_WEBPLAYER;
onEvent = null;
notOnEvent = null;
}

public override void OnEnter()
{

foreach(PlatformDependentFlags _flag in platforms)
{

//Unity Editor
#if UNITY_EDITOR
    if(_flag == PlatformDependentFlags.UNITY_EDITOR) isOnEditor = true;
#endif

#if UNITY_EDITOR_WIN
    if(_flag == PlatformDependentFlags.UNITY_EDITOR_WIN) isOnEditorWin = true;
#endif

#if UNITY_EDITOR_OSX
if(_flag == PlatformDependentFlags.UNITY_EDITOR_OSX )  isOnEditorOSX = true;
#endif

#if UNITY_EDITOR_LINUX
if(_flag == PlatformDependentFlags.UNITY_EDITOR_LINUX )  isOnEditorLinux = true;
#endif


//Unity Standalone
#if UNITY_STANDALONE
    if(_flag == PlatformDependentFlags.UNITY_STANDALONE) isOnStandalone = true;
#endif

#if UNITY_STANDALONE_WIN
    if(_flag == PlatformDependentFlags.UNITY_STANDALONE_WIN) isOnStandaloneWin = true;
#endif

#if UNITY_STANDALONE_OSX
if(_flag == PlatformDependentFlags.UNITY_STANDALONE_OSX )  isOnStandaloneOSX = true;
#endif

#if UNITY_STANDALONE_LINUX
if(_flag == PlatformDependentFlags.UNITY_STANDALONE_LINUX )  isOnStandaloneLinux = true;
#endif


//More Microsoft
#if UNITY_WSA
if(_flag == PlatformDependentFlags.UNITY_WSA )  isOnWSA = true;
#endif

#if NETFX_CORE
if(_flag == PlatformDependentFlags.NETFX_CORE )  isOnNetFXCore = true;
#endif

#if UNITY_WSA_10_10
if(_flag == PlatformDependentFlags.UNITY_WSA_10_10 )  isOnWSA1010 = true;
#endif

#if WINDOWS_UWP
if(_flag == PlatformDependentFlags.WINDOWS_UWP )  isOnWindowsUWP = true;
#endif

#if UNITY_WINRT
if(_flag == PlatformDependentFlags.UNITY_WINRT )  isOnWinRT = true;
#endif


//Web
#if UNITY_WEBPLAYER
if(_flag == PlatformDependentFlags.UNITY_WEBPLAYER )  isOnWebplayer = true;
#endif

#if UNITY_WEBGL
if(_flag == PlatformDependentFlags.UNITY_WEBGL )  isOnWebGL = true;
#endif

#if UNITY_FACEBOOK
if(_flag == PlatformDependentFlags.UNITY_FACEBOOK )  isOnFacebook = true;
#endif

#if UNITY_FLASH
if(_flag == PlatformDependentFlags.UNITY_FLASH )  isOnFlash = true;
#endif

#if UNITY_NACL
if(_flag == PlatformDependentFlags.UNITY_NACL )  isOnNACL = true;
#endif


//Video Game Consoles
#if UNITY_WII
if(_flag == PlatformDependentFlags.UNITY_WII )  isOnWii = true;
#endif

//Nintendo Switch
if (Application.platform == RuntimePlatform.Switch && _flag == PlatformDependentFlags.UNITY_SWITCH_Experimental )  isOnSwitch = true;


#if UNITY_PS3
if(_flag == PlatformDependentFlags.UNITY_PS3 )  isOnPS3 = true;
#endif

#if UNITY_PS4
if(_flag == PlatformDependentFlags.UNITY_PS4 )  isOnPS4 = true;
#endif

#if UNITY_XBOX360
if(_flag == PlatformDependentFlags.UNITY_XBOX360 )  isOnXBOX360 = true;
#endif

#if UNITY_XBOXONE
if(_flag == PlatformDependentFlags.UNITY_XBOXONE )  isOnXBoxOne = true;
#endif


//AR, VR, TV and Cloud Platforms
#if UNITY_LUMIN
if(_flag == PlatformDependentFlags.UNITY_LUMIN )  isOnLumin = true;
#endif

//Google Stadia                   
                    if (Application.platform == RuntimePlatform.Stadia && _flag == PlatformDependentFlags.UNITY_STADIA_Unsupported) isOnStadia = true;


#if UNITY_TVOS
if (_flag == PlatformDependentFlags.UNITY_TVOS )  isOnTVOS = true;
#endif


//Smartphones and Tablets
//1st group: original code block
/*#if UNITY_IPHONE || UNITY_IOS
if (Enum.Equals(platforms[i],PlatformDependentFlags.UNITY_IPHONE ) )
{
UnityEngine.Debug.Log("---------- WE FIRE "+onEvent.Name);
isOnIPhone = true;
return;
}
if( Enum.Equals(platforms[i],PlatformDependentFlags.UNITY_IOS ) )
{
UnityEngine.Debug.Log("---------- WE FIRE "+onEvent.Name);
isOnIOS = true;
return;
}
#endif*/
//new block by Alex Chouls (March 2021)
#if UNITY_IPHONE || UNITY_IOS
if(_flag == PlatformDependentFlags.UNITY_IPHONE )
{
UnityEngine.Debug.Log("---------- WE FIRE "+onEvent.Name);
isOnIPhone = true;
return;
}
if(_flag == PlatformDependentFlags.UNITY_IOS )
{
UnityEngine.Debug.Log("---------- WE FIRE "+onEvent.Name);
isOnIOS = true;
return;
}
#endif

//version with separate checks,
/*#if UNITY_IOS
                    if (_flag == PlatformDependentFlags.UNITY_IOS ) isOnIOS = true;
#endif

#if UNITY_IPHONE
if(_flag == PlatformDependentFlags.UNITY_IPHONE ) isOnIPhone = true;
#endif*/

//could need an iPad OS check here with UNITY_IPADOS and isOnIpadOS
//if not, then a separate iPhoneOS check is necessary so users can check if it's on iPhone or not
//assuming Unity translates iPadOs as iOS and doesn't trigger iPhoneOS too

#if UNITY_ANDROID
if(_flag == PlatformDependentFlags.UNITY_ANDROID )  isOnAndroid = true;
#endif

#if UNITY_TIZEN
if(_flag == PlatformDependentFlags.UNITY_TIZEN )  isOnTizen = true;
#endif

#if UNITY_METRO
if(_flag == PlatformDependentFlags.UNITY_METRO )  isOnMetro = true;
#endif

#if UNITY_WP8
if(_flag == PlatformDependentFlags.UNITY_WP8 )  isOnWP8 = true;
#endif

#if UNITY_BLACKBERRY
if(_flag == PlatformDependentFlags.UNITY_BLACKBERRY )  isOnBlackberry = true;
#endif


//Miscellaneous
#if UNITY_ASSERTIONS
if(_flag == PlatformDependentFlags.UNITY_ASSERTIONS )  isOnAssertions = true;
#endif

#if UNITY_64
if(_flag == PlatformDependentFlags.UNITY_64 )  isOn64 = true;
#endif

#if UNITY_ANALYTICS
if(_flag == PlatformDependentFlags.UNITY_ANALYTICS )  isOnUnityAnalytics = true;
#endif

//Cloud Rendering
                    if (Application.platform == RuntimePlatform.CloudRendering && _flag == PlatformDependentFlags.UNITY_CLOUD_RENDERING_Unsupported ) isOnCloudRendering = true;


#if UNITY_DASHBOARD_WIDGET
if(_flag == PlatformDependentFlags.UNITY_DASHBOARD_WIDGET )  isOnDashboardWidget = true;
#endif


}

if(isOnEditor || isOnEditorWin || isOnEditorOSX || isOnEditorLinux || isOnStandalone || isOnStandaloneOSX || isOnStandaloneWin || isOnStandaloneLinux || isOnWSA || isOnNetFXCore || isOnWSA1010 || isOnWindowsUWP || isOnWinRT || isOnWebplayer || isOnWebGL || isOnFacebook || isOnFlash || isOnNACL || isOnWii || isOnSwitch || isOnPS3 || isOnPS4 || isOnXBOX360 || isOnXBoxOne || isOnLumin || isOnStadia || isOnTVOS || isOnIOS || isOnIPhone || isOnAndroid || isOnTizen || isOnMetro || isOnWP8 || isOnBlackberry || isOnAssertions || isOn64 || isOnUnityAnalytics || isOnCloudRendering || isOnDashboardWidget)
{
Fsm.Event(onEvent);
} else
{
Fsm.Event(notOnEvent);
}

Finish();
}

}
}

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 653
    • View Profile
And its readable cousin.

Quote
// (c) Copyright HutongGames, LLC 2010-2020. All rights reserved. 
// License: Attribution 4.0 International(CC BY 4.0)
/*--- __ECO__ __PLAYMAKER__ __ACTION__ ---*/
// Author : Deek
// Additions and modifications : BrokenStylus

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
   [ActionCategory(ActionCategory.Application)]
   [HelpUrl("http://hutonggames.com/playmakerforum/index.php?topic=15458.0")]
   [Tooltip("Sends an Event if on the specified Platforms or not. Detects the targeted build platform.")]
   //[Note("Stadia and Cloud Rendering not yet supported.")]

   public class IsOnPlatformEvent : FsmStateAction
   {
      [UIHint(UIHint.Description)]
      public string desc = "Warning: Stadia and Cloud Rendering not yet supported.";

      public enum PlatformDependentFlags
      {
         UNITY_EDITOR,
         UNITY_EDITOR_WIN,
         UNITY_EDITOR_OSX,
         UNITY_EDITOR_LINUX, //added March 2021
         UNITY_STANDALONE,
         UNITY_STANDALONE_WIN,
         UNITY_STANDALONE_OSX,
         UNITY_STANDALONE_LINUX, //added March 2021
         UNITY_WSA, //added March 2021
         NETFX_CORE, //added March 2021
         UNITY_WSA_10_0, //added March 2021
         WINDOWS_UWP, //added March 2021
         UNITY_WINRT,
         UNITY_WEBPLAYER,
         UNITY_WEBGL,
         UNITY_FACEBOOK, //added March 2021
         UNITY_FLASH,
         UNITY_NACL,
         UNITY_WII,
         UNITY_SWITCH_Experimental, //added March 2021
         UNITY_PS3,
         UNITY_PS4,
         UNITY_XBOX360,
         UNITY_XBOXONE,
         UNITY_LUMIN, //added March 2021
         UNITY_STADIA_Unsupported, //added March 2021 - no code found
         UNITY_TVOS,
         UNITY_IOS,
         UNITY_IPHONE,
         UNITY_ANDROID,
         UNITY_TIZEN,
         UNITY_METRO,
         UNITY_WP8,
         UNITY_BLACKBERRY,
         UNITY_ASSERTIONS, //added March 2021
         UNITY_64, //added March 2021
         UNITY_ANALYTICS, //added March 2021
         UNITY_CLOUD_RENDERING_Unsupported, //added March 2021 - no code found
         UNITY_DASHBOARD_WIDGET,
      }

      [RequiredField]
      [Tooltip("The platforms")]
      public PlatformDependentFlags[] platforms;

      [Tooltip("The event to send IF on any of the specified platforms. Note: Gets send on the first platform it finds it is on.")]
      public FsmEvent onEvent;

      [Tooltip("The event to send IF NOT on any of the specified platforms.")]
      public FsmEvent notOnEvent;

      public static RuntimePlatform platform;

      private bool isOnEditor = false;
      private bool isOnEditorWin = false;
      private bool isOnEditorOSX = false;
      private bool isOnEditorLinux = false; //added March 2021

      private bool isOnStandalone = false;
      private bool isOnStandaloneWin = false;
      private bool isOnStandaloneOSX = false;
      private bool isOnStandaloneLinux = false;

      private bool isOnWSA = false;  //added March 2021
      private bool isOnNetFXCore = false; //added March 2021
      private bool isOnWSA1010 = false; //added March 2021
      private bool isOnWindowsUWP = false; //added March 2021
      private bool isOnWinRT = false;

      private bool isOnWebplayer = false;
      private bool isOnWebGL = false;
      private bool isOnFacebook = false; //added March 2021
      private bool isOnFlash = false;
      private bool isOnNACL = false;

      private bool isOnWii = false;
      private bool isOnSwitch = false; //added March 2021
      private bool isOnPS3 = false;
      private bool isOnPS4 = false;
      private bool isOnXBOX360 = false;
      private bool isOnXBoxOne = false;

      private bool isOnLumin = false; //added March 2021
      private bool isOnStadia = false; //added March 2021
      private bool isOnTVOS = false;

      private bool isOnIOS = false;
      private bool isOnIPhone = false;
      private bool isOnAndroid = false;
      private bool isOnTizen = false;
      private bool isOnMetro = false;
      private bool isOnWP8 = false;
      private bool isOnBlackberry = false;

      private bool isOnAssertions = false; //added March 2021
      private bool isOn64 = false; //added March 2021
      private bool isOnUnityAnalytics = false; //added March 2021
      private bool isOnCloudRendering = false; //added March 2021
      private bool isOnDashboardWidget = false;


      public override void Reset()
      {
         platforms = new PlatformDependentFlags[1];
         platforms[0] = PlatformDependentFlags.UNITY_WEBPLAYER;
         onEvent = null;
         notOnEvent = null;
      }

      public override void OnEnter()
      {

         foreach(PlatformDependentFlags _flag in platforms)
         {

//Unity Editor
#if UNITY_EDITOR
                if(_flag == PlatformDependentFlags.UNITY_EDITOR) isOnEditor = true;
#endif

#if UNITY_EDITOR_WIN
                if(_flag == PlatformDependentFlags.UNITY_EDITOR_WIN) isOnEditorWin = true;
#endif

#if UNITY_EDITOR_OSX
               if(_flag == PlatformDependentFlags.UNITY_EDITOR_OSX )  isOnEditorOSX = true;
#endif

#if UNITY_EDITOR_LINUX
               if(_flag == PlatformDependentFlags.UNITY_EDITOR_LINUX )  isOnEditorLinux = true;
#endif


//Unity Standalone
#if UNITY_STANDALONE
                if(_flag == PlatformDependentFlags.UNITY_STANDALONE) isOnStandalone = true;
#endif

#if UNITY_STANDALONE_WIN
                if(_flag == PlatformDependentFlags.UNITY_STANDALONE_WIN) isOnStandaloneWin = true;
#endif

#if UNITY_STANDALONE_OSX
               if(_flag == PlatformDependentFlags.UNITY_STANDALONE_OSX )  isOnStandaloneOSX = true;
#endif

#if UNITY_STANDALONE_LINUX
               if(_flag == PlatformDependentFlags.UNITY_STANDALONE_LINUX )  isOnStandaloneLinux = true;
#endif


//More Microsoft
#if UNITY_WSA
               if(_flag == PlatformDependentFlags.UNITY_WSA )  isOnWSA = true;
#endif

#if NETFX_CORE
               if(_flag == PlatformDependentFlags.NETFX_CORE )  isOnNetFXCore = true;
#endif

#if UNITY_WSA_10_10
               if(_flag == PlatformDependentFlags.UNITY_WSA_10_10 )  isOnWSA1010 = true;
#endif

#if WINDOWS_UWP
               if(_flag == PlatformDependentFlags.WINDOWS_UWP )  isOnWindowsUWP = true;
#endif

#if UNITY_WINRT
               if(_flag == PlatformDependentFlags.UNITY_WINRT )  isOnWinRT = true;
#endif


//Web
#if UNITY_WEBPLAYER
               if(_flag == PlatformDependentFlags.UNITY_WEBPLAYER )  isOnWebplayer = true;
#endif

#if UNITY_WEBGL
               if(_flag == PlatformDependentFlags.UNITY_WEBGL )  isOnWebGL = true;
#endif

#if UNITY_FACEBOOK
               if(_flag == PlatformDependentFlags.UNITY_FACEBOOK )  isOnFacebook = true;
#endif

#if UNITY_FLASH
               if(_flag == PlatformDependentFlags.UNITY_FLASH )  isOnFlash = true;
#endif

#if UNITY_NACL
               if(_flag == PlatformDependentFlags.UNITY_NACL )  isOnNACL = true;
#endif


//Video Game Consoles
#if UNITY_WII
               if(_flag == PlatformDependentFlags.UNITY_WII )  isOnWii = true;
#endif

   //Nintendo Switch
               if (Application.platform == RuntimePlatform.Switch && _flag == PlatformDependentFlags.UNITY_SWITCH_Experimental )  isOnSwitch = true;


#if UNITY_PS3
               if(_flag == PlatformDependentFlags.UNITY_PS3 )  isOnPS3 = true;
#endif

#if UNITY_PS4
               if(_flag == PlatformDependentFlags.UNITY_PS4 )  isOnPS4 = true;
#endif

#if UNITY_XBOX360
               if(_flag == PlatformDependentFlags.UNITY_XBOX360 )  isOnXBOX360 = true;
#endif

#if UNITY_XBOXONE
               if(_flag == PlatformDependentFlags.UNITY_XBOXONE )  isOnXBoxOne = true;
#endif


//AR, VR, TV and Cloud Platforms
#if UNITY_LUMIN
               if(_flag == PlatformDependentFlags.UNITY_LUMIN )  isOnLumin = true;
#endif

   //Google Stadia                   
                    if (Application.platform == RuntimePlatform.Stadia && _flag == PlatformDependentFlags.UNITY_STADIA_Unsupported) isOnStadia = true;


#if UNITY_TVOS
               if (_flag == PlatformDependentFlags.UNITY_TVOS )  isOnTVOS = true;
#endif


//Smartphones and Tablets
   //1st group: original code block
/*#if UNITY_IPHONE || UNITY_IOS
               if (Enum.Equals(platforms,PlatformDependentFlags.UNITY_IPHONE ) )
               {
                  UnityEngine.Debug.Log("---------- WE FIRE "+onEvent.Name);
                   isOnIPhone = true;
                  return;
               }
               if( Enum.Equals(platforms,PlatformDependentFlags.UNITY_IOS ) )
               {
                  UnityEngine.Debug.Log("---------- WE FIRE "+onEvent.Name);
                   isOnIOS = true;
                  return;
               }
#endif*/
   //new block by Alex Chouls (March 2021)
#if UNITY_IPHONE || UNITY_IOS
               if(_flag == PlatformDependentFlags.UNITY_IPHONE )
               {
                  UnityEngine.Debug.Log("---------- WE FIRE "+onEvent.Name);
                   isOnIPhone = true;
                  return;
               }
               if(_flag == PlatformDependentFlags.UNITY_IOS )
               {
                  UnityEngine.Debug.Log("---------- WE FIRE "+onEvent.Name);
                   isOnIOS = true;
                  return;
               }
#endif

   //version with separate checks,
/*#if UNITY_IOS
                    if (_flag == PlatformDependentFlags.UNITY_IOS )    isOnIOS = true;
#endif

#if UNITY_IPHONE
               if(_flag == PlatformDependentFlags.UNITY_IPHONE )   isOnIPhone = true;
#endif*/

   //could need an iPad OS check here with UNITY_IPADOS and isOnIpadOS
   //if not, then a separate iPhoneOS check is necessary so users can check if it's on iPhone or not
   //assuming Unity translates iPadOs as iOS and doesn't trigger iPhoneOS too

#if UNITY_ANDROID
               if(_flag == PlatformDependentFlags.UNITY_ANDROID )  isOnAndroid = true;
#endif

#if UNITY_TIZEN
               if(_flag == PlatformDependentFlags.UNITY_TIZEN )  isOnTizen = true;
#endif

#if UNITY_METRO
               if(_flag == PlatformDependentFlags.UNITY_METRO )  isOnMetro = true;
#endif

#if UNITY_WP8
               if(_flag == PlatformDependentFlags.UNITY_WP8 )  isOnWP8 = true;
#endif

#if UNITY_BLACKBERRY
               if(_flag == PlatformDependentFlags.UNITY_BLACKBERRY )  isOnBlackberry = true;
#endif


//Miscellaneous
#if UNITY_ASSERTIONS
               if(_flag == PlatformDependentFlags.UNITY_ASSERTIONS )  isOnAssertions = true;
#endif

#if UNITY_64
               if(_flag == PlatformDependentFlags.UNITY_64 )  isOn64 = true;
#endif

#if UNITY_ANALYTICS
               if(_flag == PlatformDependentFlags.UNITY_ANALYTICS )  isOnUnityAnalytics = true;
#endif

   //Cloud Rendering
                    if (Application.platform == RuntimePlatform.CloudRendering && _flag == PlatformDependentFlags.UNITY_CLOUD_RENDERING_Unsupported ) isOnCloudRendering = true;


#if UNITY_DASHBOARD_WIDGET
               if(_flag == PlatformDependentFlags.UNITY_DASHBOARD_WIDGET )  isOnDashboardWidget = true;
#endif


         }

         if(isOnEditor || isOnEditorWin || isOnEditorOSX || isOnEditorLinux || isOnStandalone || isOnStandaloneOSX || isOnStandaloneWin || isOnStandaloneLinux || isOnWSA || isOnNetFXCore || isOnWSA1010 || isOnWindowsUWP || isOnWinRT || isOnWebplayer || isOnWebGL || isOnFacebook || isOnFlash || isOnNACL || isOnWii || isOnSwitch || isOnPS3 || isOnPS4 || isOnXBOX360 || isOnXBoxOne || isOnLumin || isOnStadia || isOnTVOS || isOnIOS || isOnIPhone || isOnAndroid || isOnTizen || isOnMetro || isOnWP8 || isOnBlackberry || isOnAssertions || isOn64 || isOnUnityAnalytics || isOnCloudRendering || isOnDashboardWidget)
         {
            Fsm.Event(onEvent);
         } else
         {
            Fsm.Event(notOnEvent);
         }

         Finish();
      }

   }
}

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 6175
    • View Profile
    • jinxtergames
Hi.
Thx, i will update the action

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 6175
    • View Profile
    • jinxtergames
Hi.
There where 2 errors on the action due to missing #if....
But i fixed them and updated on the Ecosystem

I also made a new Action called RuntimePlatformEvent.

Have a go with it if you have time :)

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 653
    • View Profile
Great. In this case you might have forgotten the #if for the Switch too. But I skipped those IFs because UNITY_SWITCH, UNITY_STADIA and UNITY_CLOUD_RENDERING are just me keeping up with the official directive nomenclature, so the user will see UNITY_SOMETHING because technically it's supposed to be Unity supported, but such platforms are not listed on the Platform dependent compilation page, so they're not valid region code blocks. Their detection is done through RuntimePlatform.
So I think, but I could be wrong here, that surrounding their relevant code with #if and #endif is just going to have Unity not seeing them ever.

Now, since you did a RuntimePlatform action, maybe the Nintendo Switch, Stadia and Cloud Rendering should be made exclusive to this new action and left out of isOnPlatformEvent entirely?

The reason being that as described above, I check for these platforms precisely using
Code: [Select]
Application.platform == RuntimePlatform.[name of platform]