Ejemplo n.º 1
0
        /// <summary>
        /// 新しいSymbolCatalogアセットを生成します.
        /// Create new SymbolCatalog asset.
        /// </summary>
        static SymbolCatalog CreateCatalog()
        {
            if (!Directory.Exists("Assets/Editor"))
            {
                AssetDatabase.CreateFolder("Assets", "Editor");
            }

            //DefineSymbolsアセット生成して保存.
            SymbolCatalog catalog = ScriptableObject.CreateInstance(typeof(SymbolCatalog)) as SymbolCatalog;

            AssetDatabase.CreateAsset(catalog, "Assets/Editor/" + typeof(SymbolCatalog).Name + ".asset");
            AssetDatabase.SaveAssets();
            return(catalog);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// GUIを表示します.
        /// Draw GUI.
        /// </summary>
        void OnGUI()
        {
            Initialize();

            // カタログアセットを取得/作成します.
            // Get/Create catalog asset.
            catalog = catalog
                      ?? AssetDatabase.FindAssets("t:" + typeof(SymbolCatalog).Name)
                      .Select(x => AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(x), typeof(SymbolCatalog)) as SymbolCatalog)
                      .FirstOrDefault()
                      ?? CreateCatalog();

            // 変更チェック.PlayerSettingsなどで直接変えた場合も検知します.
            // Sync script define symbol.
            string define = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);

            if (currentDefine != define)
            {
                currentDefine = define;
                catalog.Revert();
            }

            using (var svs = new EditorGUILayout.ScrollViewScope(scrollPosition))
            {
                scrollPosition = svs.scrollPosition;
                EditorGUI.BeginChangeCheck();

                // タイトル
                // Title
                GUILayout.Label(new GUIContent("   Available Scripting Define Symbols", EditorGUIUtility.ObjectContent(catalog, typeof(SymbolCatalog)).image), styleTitle);

                // シンボルリスト.
                // Draw all symbols in catalog.
                ro.list = catalog.list;
                ro.DoLayoutList();

                // Applyボタン.
                // Button to apply scripting define symbols.
                using (new EditorGUI.DisabledGroupScope(EditorApplication.isCompiling))
                {
                    using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox))
                    {
                        GUILayout.Label(new GUIContent("Apply To", EditorGUIUtility.FindTexture("vcs_check")));

                        if (GUILayout.Button("All Targets"))
                        {
                            catalog.Apply();
                        }
                        if (GUILayout.Button(string.Format("Current ({0})", EditorUserBuildSettings.selectedBuildTargetGroup)))
                        {
                            catalog.Apply(EditorUserBuildSettings.selectedBuildTargetGroup);
                        }
                    }
                }

                if (EditorGUI.EndChangeCheck())
                {
                    EditorUtility.SetDirty(catalog);
                }
            }

            // コンパイル中.
            // Request repain during compiling.
            if (EditorApplication.isCompiling)
            {
                Repaint();
            }

            // Addされたら自動でシンボル名の入力開始します.
            // When add new symbol, focus input field.
            if (!string.IsNullOrEmpty(focus))
            {
                EditorGUI.FocusTextInControl(focus);
                focus = null;
            }
        }