Skip to content

Instantly share code, notes, and snippets.

@solkar
Forked from bzgeb/PlatformMonitor.cs
Created November 14, 2016 15:32
Show Gist options
  • Save solkar/4721e1d0f223c03962d27fcb95c31892 to your computer and use it in GitHub Desktop.
Save solkar/4721e1d0f223c03962d27fcb95c31892 to your computer and use it in GitHub Desktop.
Example Platform Monitoring script
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