Skip to content

Instantly share code, notes, and snippets.

@fith
Created November 10, 2017 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fith/4d44dcc4d7e103866b95d6440c0548f8 to your computer and use it in GitHub Desktop.
Save fith/4d44dcc4d7e103866b95d6440c0548f8 to your computer and use it in GitHub Desktop.
Unity plugin to control systemDeviceVersion specific behavior sets.
using UnityEngine;
using System.Linq;
public class PlatformManager : MonoBehaviour {
public bool logDebugSystemInfo = false;
public bool disableAllBehaviorsOnAwake = false;
[System.Serializable]
public class PlatformBehaviors
{
public bool enabled = false;
public string[] deviceVersionKeys;
public bool exactMatch = false;
public MonoBehaviour[] behaviors;
}
public PlatformBehaviors[] graphicsDeviceVersionBehaviors;
void Start() {
if( logDebugSystemInfo ) {
debugStrings();
}
}
// Use this for initialization
void Awake () {
if (disableAllBehaviorsOnAwake) {
disableAll();
}
string deviceVersion = SystemInfo.graphicsDeviceVersion;
foreach(PlatformBehaviors pb in graphicsDeviceVersionBehaviors) {
if (pb.enabled) {
foreach(string key in pb.deviceVersionKeys) {
if(deviceVersion.Contains(key)) {
foreach(MonoBehaviour behavior in pb.behaviors) {
behavior.enabled = true;
}
}
}
}
}
}
}
void debugStrings() {
Debug.Log ("Device model: " + SystemInfo.deviceModel);
Debug.Log ("Device name: " + SystemInfo.deviceName);
Debug.Log ("Device type: " + SystemInfo.deviceType);
Debug.Log ("Graphics device name: " + SystemInfo.graphicsDeviceName);
Debug.Log ("Graphics device vendor: " + SystemInfo.graphicsDeviceVendor);
Debug.Log ("Graphics device version: " + SystemInfo.graphicsDeviceVersion);
Debug.Log ("OS: " + SystemInfo.operatingSystem);
Debug.Log ("Processor count: " + SystemInfo.processorCount);
Debug.Log ("Processor type: " + SystemInfo.processorType);
Debug.Log ("Memory size: " + SystemInfo.systemMemorySize);
}
void enableEffects(MonoBehaviour[] behaviors) {
foreach(MonoBehaviour behavior in behaviors) {
behavior.enabled = true;
}
}
void disableAll() {
foreach(PlatformBehaviors pb in graphicsDeviceVersionBehaviors) {
foreach(MonoBehaviour behavior in pb.behaviors) {
behavior.enabled = false;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment