playMaker

Author Topic: Platform dependent events  (Read 5379 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14500
  • Official Playmaker Support
    • View Profile
Platform dependent events
« on: January 21, 2014, 09:59:06 PM »
Hi,

After a request, please find a new action that will let you fire events based on Unity platform dependent compilation flags.

http://docs.unity3d.com/Documentation/Manual/PlatformDependentCompilation.html

Warning, read properly all the different flags from the documentation above to understand when they are validated. If you run on previous versions of Unity, some Flags will never be validated because not defined ( like if running on 3.5 and checking for blackberry, this will never be available).

Bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14500
  • Official Playmaker Support
    • View Profile
Re: Platform dependent events
« Reply #1 on: February 10, 2014, 01:14:07 AM »
Hi,

 please find the source code, until I can send attachment again..

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.

using System;
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Application)]
[Tooltip("Sends Events based on platform dependent flags")]
public class PlatformDependentEvents : FsmStateAction
{
public enum platformDependentFlags
{
UNITY_EDITOR,
UNITY_EDITOR_WIN,
UNITY_EDITOR_OSX,
UNITY_STANDALONE_OSX,
UNITY_DASHBOARD_WIDGET,
UNITY_STANDALONE_WIN,
UNITY_STANDALONE_LINUX,
UNITY_STANDALONE,
UNITY_WEBPLAYER,
UNITY_WII,
UNITY_IPHONE,
UNITY_ANDROID,
UNITY_PS3,
UNITY_XBOX360,
UNITY_NACL,
UNITY_FLASH,
UNITY_BLACKBERRY,
UNITY_WP8,
UNITY_METRO,
UNITY_WINRT
}

[ActionSection("Platforms")]
[CompoundArray("Count", "Key", "Value")]

[RequiredField]
[Tooltip("The platform")]
public platformDependentFlags[] platforms;
[Tooltip("The event to send for that platform")]
public FsmEvent[] events;

public override void Reset()
{
platforms = new platformDependentFlags[1];
platforms[0] = platformDependentFlags.UNITY_WEBPLAYER;
events = new FsmEvent[1];
events[0] = null;
}

public override void OnEnter()
{
int i = 0;
foreach(platformDependentFlags _flag in platforms)
{
FsmEvent _event = events[i];

#if UNITY_EDITOR
if(_flag == platformDependentFlags.UNITY_EDITOR ) Fsm.Event(_event);
#endif

#if UNITY_EDITOR_WIN
if(_flag == platformDependentFlags.UNITY_EDITOR_WIN ) Fsm.Event(_event);
#endif

#if UNITY_EDITOR_OSX
if(_flag == platformDependentFlags.UNITY_EDITOR_OSX ) Fsm.Event(_event);
#endif

#if UNITY_STANDALONE_OSX
if(_flag == platformDependentFlags.UNITY_STANDALONE_OSX ) Fsm.Event(_event);
#endif

#if UNITY_DASHBOARD_WIDGET
if(_flag == platformDependentFlags.UNITY_DASHBOARD_WIDGET ) Fsm.Event(_event);
#endif

#if UNITY_STANDALONE_WIN
if(_flag == platformDependentFlags.UNITY_STANDALONE_WIN ) Fsm.Event(_event);
#endif

#if UNITY_STANDALONE_LINUX
if(_flag == platformDependentFlags.UNITY_STANDALONE_LINUX ) Fsm.Event(_event);
#endif

#if UNITY_STANDALONE
if(_flag == platformDependentFlags.UNITY_STANDALONE ) Fsm.Event(_event);
#endif

#if UNITY_WEBPLAYER
if(_flag == platformDependentFlags.UNITY_WEBPLAYER ) Fsm.Event(_event);
#endif

#if UNITY_WII
if(_flag == platformDependentFlags.UNITY_WII ) Fsm.Event(_event);
#endif

#if UNITY_IPHONE
if(_flag == platformDependentFlags.UNITY_IPHONE ) Fsm.Event(_event);
#endif

#if UNITY_ANDROID
if(_flag == platformDependentFlags.UNITY_ANDROID ) Fsm.Event(_event);
#endif

#if UNITY_PS3
if(_flag == platformDependentFlags.UNITY_PS3 ) Fsm.Event(_event);
#endif

#if UNITY_XBOX360
if(_flag == platformDependentFlags.UNITY_XBOX360 ) Fsm.Event(_event);
#endif

#if UNITY_NACL
if(_flag == platformDependentFlags.UNITY_NACL ) Fsm.Event(_event);
#endif

#if UNITY_FLASH
if(_flag == platformDependentFlags.UNITY_FLASH ) Fsm.Event(_event);
#endif

#if UNITY_BLACKBERRY
if(_flag == platformDependentFlags.UNITY_BLACKBERRY ) Fsm.Event(_event);
#endif

#if UNITY_WP8
if(_flag == platformDependentFlags.UNITY_WP8 ) Fsm.Event(_event);
#endif

#if UNITY_METRO
if(_flag == platformDependentFlags.UNITY_METRO ) Fsm.Event(_event);
#endif

#if UNITY_WINRT
if(_flag == platformDependentFlags.UNITY_WINRT ) Fsm.Event(_event);
#endif

i++;
}

Finish();
}

}
}

jess84

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
Re: Platform dependent events
« Reply #2 on: May 04, 2014, 02:45:38 PM »
Hi Jean,

I've been using this action for a while to detect different versions, however I've just tried to distinguish between a Windows Standalone build and a Unity Editor instance.

See the attachment - It never detects that it's running in the Unity Editor.

Does this work for you?


Marsh

  • Full Member
  • ***
  • Posts: 227
  • Comfort the disturbed, disturb the comfortable
    • View Profile
Re: Platform dependent events
« Reply #3 on: May 04, 2014, 03:34:19 PM »
What build are you in? Because it will detect android if you are on a android build of Unity then call the action.

If you only want to trigger on unity editor you have to check if its the editor first, as android and editor are both returning true (most likely).

Or just if UNITY_ANDROID && !UNITY_EDITOR

jess84

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
Re: Platform dependent events
« Reply #4 on: May 04, 2014, 03:46:03 PM »
PC, Mac, Linux Standalone build.  Not really sure why you're mentioning Android at all.

My problem is that I think it should detect as UNITY_EDITOR or UNITY_EDITOR_WIN - but it doesn't (for either), it detects as UNITY_STANDALONE_WIN.


Marsh

  • Full Member
  • ***
  • Posts: 227
  • Comfort the disturbed, disturb the comfortable
    • View Profile
Re: Platform dependent events
« Reply #5 on: May 04, 2014, 04:09:06 PM »
Ah, I was just saying that as your screenshot had android and iOS stuff in it. Good luck with your bug.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14500
  • Official Playmaker Support
    • View Profile
Re: Platform dependent events
« Reply #6 on: May 06, 2014, 04:45:26 AM »
Hi,
 
I would cut this into two states.

first state you cehck just if you are in editor or not and then you transit ( if not in editor) into a new set of checks for platforms.

Bye,

 Jean