-
-
Save solkar/4721e1d0f223c03962d27fcb95c31892 to your computer and use it in GitHub Desktop.
Example Platform Monitoring script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System.Collections; | |
[InitializeOnLoad] | |
public class PlatformMonitor { | |
static BuildTarget cachedPlatform; | |
static PlatformMonitor() { | |
cachedPlatform = EditorUserBuildSettings.activeBuildTarget; | |
// EditorApplication.update += Update; | |
EditorUserBuildSettings.activeBuildTargetChanged += OnChangedPlatform; | |
} | |
static void OnChangedPlatform() { | |
Debug.Log( "Changed Platform to " + EditorUserBuildSettings.activeBuildTarget ); | |
GameObject go = GameObject.Find("Plane"); | |
if ( cachedPlatform == BuildTarget.StandaloneOSXIntel || cachedPlatform == BuildTarget.StandaloneOSXIntel64 || cachedPlatform == BuildTarget.StandaloneOSXUniversal ) { | |
DestroyOSXStuff( go ); | |
} else if ( cachedPlatform == BuildTarget.StandaloneWindows || cachedPlatform == BuildTarget.StandaloneWindows64 ) { | |
DestroyWindowsStuff( go ); | |
} | |
if ( EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows || EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows64 ) { | |
AddWindowsStuff( go ); | |
} else if ( EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneOSXIntel || EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneOSXIntel64 || EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneOSXUniversal ) { | |
AddOSXStuff( go ); | |
} | |
cachedPlatform = EditorUserBuildSettings.activeBuildTarget; | |
} | |
static void DestroyOSXStuff( GameObject go ) { | |
// GameObject.DestroyImmediate( go.GetComponent<SomethingOSX>() ); | |
} | |
static void DestroyWindowsStuff( GameObject go ) { | |
// GameObject.DestroyImmediate( go.GetComponent<SomethingWindows>() ); | |
} | |
static void AddOSXStuff( GameObject go ) { | |
// go.AddComponent<SomethingOSX>(); | |
} | |
static void AddWindowsStuff( GameObject go ) { | |
// go.AddComponent<SomethingWindows>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment