예제 #1
0
        /// <summary>
        /// Finds the singleton PtSettings instance. Works during edit time and run time.
        /// At edit time, we search for the asset using FindAssets("t:PtSettings").
        /// At run time, we load it as a resource.
        /// </summary>
        /// <returns>The project's PtSettings instance.</returns>
        static PtSettings FindPtSettings()
        {
            if (Application.isPlaying)
            {
                // At run-time, just load the resource.
                PtSettings ptSettings = Resources.Load <PtSettings>("PtSettings");
                if (ptSettings == null)
                {
                    Debug.LogError("PtSettings not found in Resources. Re-import Poly Toolkit.");
                }
                return(ptSettings);
            }
#if UNITY_EDITOR
            // We're in the editor at edit-time, so just search for the asset in the project.
            string[] foundPaths = UnityEditor.AssetDatabase.FindAssets("t:PtSettings")
                                  .Select(UnityEditor.AssetDatabase.GUIDToAssetPath).ToArray();
            if (foundPaths.Length == 0)
            {
                Debug.LogError("Found no PtSettings assets. Re-import Poly Toolkit");
                return(null);
            }
            else
            {
                if (foundPaths.Length > 1)
                {
                    Debug.LogErrorFormat(
                        "Found multiple PtSettings assets; delete them and re-import Poly Toolkit\n{0}",
                        string.Join("\n", foundPaths));
                }
                return(UnityEditor.AssetDatabase.LoadAssetAtPath <PtSettings>(
                           foundPaths[0]));
            }
#else
            // We are not in the editor but somehow Application.isPlaying is false, which shouldn't happen.
            Debug.LogError("Unexpected config: UNITY_EDITOR not defined but Application.isPlaying==false.");
            return(null);
#endif
        }
예제 #2
0
 /// <summary>
 /// Initialize PtSettings. Must be called on main thread.
 /// </summary>
 public static void Init()
 {
     instance = FindPtSettings();
 }