123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- #if UNITY_EDITOR
- using UnityEditor;
- using UnityEditor.PackageManager;
- using UnityEditor.PackageManager.Requests;
- [InitializeOnLoad]
- public class ZEDDefineHandler : AssetPostprocessor
- {
- static ZEDDefineHandler()
- {
- }
- static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
- {
- #region VR Plugins
- if (CheckPackageExists("OVRManager"))
- {
- ActivateDefine("Oculus", "ZED_OCULUS");
- }
- else
- {
- DeactivateDefine("Oculus", "ZED_OCULUS");
- }
- if (CheckPackageExists("SteamVR_Camera"))
- {
- ActivateDefine("SteamVR", "ZED_STEAM_VR");
- }
- else
- {
- DeactivateDefine("SteamVR", "ZED_STEAM_VR");
- }
- if (CheckPackageExists("SteamVR_Input_Sources"))
- {
- ActivateDefine("SteamVR_2_0_Input", "ZED_SVR_2_0_INPUT");
- }
- else
- {
- DeactivateDefine("SteamVR_2_0_Input", "ZED_SVR_2_0_INPUT");
- }
- #endregion
- #region OpenCV
- string opencvfilename = "opencvforunity.dll";
- opencvfilename = "opencvforunity";
-
- if (CheckPackageExists(opencvfilename))
- {
- ActivateDefine("ZEDOpenCV", "ZED_OPENCV_FOR_UNITY");
- }
- else
- {
- DeactivateDefine("ZEDOpenCV", "ZED_OPENCV_FOR_UNITY");
- }
- #endregion
- }
-
-
-
-
-
-
-
- public static bool CheckPackageExists(string name)
- {
- string[] packages = AssetDatabase.FindAssets(name);
- return packages.Length != 0;
- }
-
-
-
-
- public static void ActivateDefine(string packageName, string defineName)
- {
- EditorPrefs.SetBool(packageName, true);
- string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone);
- if (defines.Length != 0)
- {
- if (!defines.Contains(defineName))
- {
- defines += ";" + defineName;
- }
- }
- else
- {
- if (!defines.Contains(defineName))
- {
- defines += defineName;
- }
- }
- PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, defines);
-
- string defines_android = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android);
- if (defines_android.Length != 0)
- {
- if (!defines_android.Contains(defineName))
- {
- defines_android += ";" + defineName;
- }
- }
- else
- {
- if (!defines_android.Contains(defineName))
- {
- defines_android += defineName;
- }
- }
- PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Android, defines_android);
- }
-
-
-
-
-
- public static void DeactivateDefine(string packagename, string defineName)
- {
- EditorPrefs.SetBool(packagename, false);
- string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone);
- if (defines.Length != 0)
- {
- if (defineName != null && defines.Contains(defineName))
- {
- defines = defines.Remove(defines.IndexOf(defineName), defineName.Length);
- if (defines.LastIndexOf(";") == defines.Length - 1 && defines.Length != 0)
- {
- defines.Remove(defines.LastIndexOf(";"), 1);
- }
- }
- }
- PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, defines);
- }
- }
- #endif
|