コード例 #1
0
ファイル: Config.cs プロジェクト: msp/virtual-gallery
        private static Config GetInstance(bool assertIfNotFound)
        {
#if UNITY_EDITOR
            // Do not cache the instance during editing in order to handle new asset created or moved.
            if (!Application.isPlaying || ms_Instance == null)
#else
            if (ms_Instance == null)
#endif
            {
#if UNITY_EDITOR
                if (ms_IsCreatingInstance)
                {
                    Debug.LogError(string.Format("Trying to access Config.Instance while creating it. Breaking before infinite loop."));
                    return(null);
                }
#endif
                {
                    var newInstance = Resources.Load <ConfigOverride>(ConfigOverride.kAssetName + PlatformHelper.GetCurrentPlatformSuffix());

                    if (newInstance == null)
                    {
                        newInstance = Resources.Load <ConfigOverride>(ConfigOverride.kAssetName);
                    }

#if UNITY_EDITOR
                    if (newInstance && newInstance != ms_Instance)
                    {
                        ms_Instance = newInstance;
                        newInstance.RefreshGlobalShaderProperties(); // make sure noise textures are properly loaded as soon as the editor is started
                    }
#endif

                    ms_Instance = newInstance;
                }

                if (ms_Instance == null)
                {
#if UNITY_EDITOR
                    ms_IsCreatingInstance = true;
                    ms_Instance           = ConfigOverride.CreateInstanceOverride();
                    ms_IsCreatingInstance = false;

                    ms_Instance.AutoSelectRenderPipeline();

                    if (Application.isPlaying)
                    {
                        ms_Instance.Reset(); // Reset is not automatically when instancing a ScriptableObject when in playmode
                    }
#endif
                    Debug.Assert(!(assertIfNotFound && ms_Instance == null), string.Format("Can't find any resource of type '{0}'. Make sure you have a ScriptableObject of this type in a 'Resources' folder.", typeof(Config)));
                }
            }

            return(ms_Instance);
        }
コード例 #2
0
        void OnAddConfigPerPlatform(object platform)
        {
            var p     = (RuntimePlatform)platform;
            var clone = Object.Instantiate(m_TargetConfig);

            Debug.Assert(clone);
            var path = AssetDatabase.GetAssetPath(m_TargetConfig).Replace(m_TargetConfig.name + ".asset", "");

            ConfigOverride.CreateAsset(clone, path + ConfigOverride.kAssetName + p.ToString() + ".asset");
            Selection.activeObject = clone;
        }