コード例 #1
0
        private void OnGUI()
        {
            var rect = new Rect(0, 0, position.width, position.height);

            GUICustomUtils.DrawTitle("Dash AOT Scanner/Generator");

            var titleStyle = new GUIStyle();

            titleStyle.alignment        = TextAnchor.MiddleLeft;
            titleStyle.padding.left     = 5;
            titleStyle.normal.textColor = new Color(1, .5f, 0);
            titleStyle.fontStyle        = FontStyle.Bold;
            titleStyle.fontSize         = 16;

            var infoStyle = new GUIStyle();

            infoStyle.normal.textColor = Color.gray;
            infoStyle.alignment        = TextAnchor.MiddleLeft;
            infoStyle.padding.left     = 5;

            var scrollViewStyle = new GUIStyle();

            scrollViewStyle.normal.background = TextureUtils.GetColorTexture(new Color(.1f, .1f, .1f));

            GUILayout.Space(4);
            GUILayout.Label("Scanned types", titleStyle, GUILayout.ExpandWidth(true));
            GUILayout.Label(
                "Last scan found " +
                (DashEditorCore.EditorConfig.scannedAOTTypes == null
                    ? 0
                    : DashEditorCore.EditorConfig.scannedAOTTypes.Count) + " types", infoStyle,
                GUILayout.ExpandWidth(true));
            GUILayout.Space(2);

            _scrollPositionScanned = GUILayout.BeginScrollView(_scrollPositionScanned, scrollViewStyle,
                                                               GUILayout.ExpandWidth(true), GUILayout.Height(rect.height / 2 - 100));
            GUILayout.BeginVertical();

            if (DashEditorCore.EditorConfig.scannedAOTTypes != null)
            {
                foreach (Type type in DashEditorCore.EditorConfig.scannedAOTTypes)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label((string.IsNullOrEmpty(type.Namespace) ? "" : type.Namespace + ".") +
                                    type.GetReadableTypeName());
                    if (GUILayout.Button("Remove", GUILayout.Width(120)))
                    {
                        DashAOTScanner.RemoveScannedAOTType(type);
                        break;
                    }
                    GUILayout.EndHorizontal();
                }
            }

            GUILayout.EndVertical();
            GUILayout.EndScrollView();


            GUILayout.Space(4);
            GUILayout.Label("Explicit Types", titleStyle, GUILayout.ExpandWidth(true));
            GUILayout.Label(
                "You have " +
                (DashEditorCore.EditorConfig.explicitAOTTypes == null
                    ? 0
                    : DashEditorCore.EditorConfig.explicitAOTTypes.Count) + " explicitly defined types.", infoStyle,
                GUILayout.ExpandWidth(true));
            GUILayout.Space(2);

            _scrollPositionExplicit = GUILayout.BeginScrollView(_scrollPositionExplicit, scrollViewStyle,
                                                                GUILayout.ExpandWidth(true), GUILayout.Height(rect.height / 2 - 100));
            GUILayout.BeginVertical();

            if (DashEditorCore.EditorConfig.explicitAOTTypes != null)
            {
                int index = 0;
                foreach (Type type in DashEditorCore.EditorConfig.explicitAOTTypes)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label((string.IsNullOrEmpty(type.Namespace) ? "" : type.Namespace + ".") +
                                    type.GetReadableTypeName());

                    if (type.IsGenericType && type.GetGenericArguments()[0].FullName == null)
                    {
                        if (GUILayout.Button("Inflate", GUILayout.Width(120)))
                        {
                            AddTypeContextMenu.ShowAsPopup((p) => InflateType(p, type, index));
                        }
                    }

                    if (GUILayout.Button("Remove", GUILayout.Width(120)))
                    {
                        DashAOTScanner.RemoveExplicitAOTType(type);
                        break;
                    }
                    GUILayout.EndHorizontal();
                    index++;
                }
            }

            GUILayout.EndVertical();
            GUILayout.EndScrollView();

            GUILayout.Space(4);
            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            _generateLinkXml =
                GUILayout.Toggle(_generateLinkXml, new GUIContent("Generate Link Xml"), GUILayout.Width(140));
            _includeOdin = GUILayout.Toggle(_includeOdin, new GUIContent("Include Odin Assembly"));

            GUILayout.EndHorizontal();
            GUILayout.Space(2);
            GUILayout.BeginHorizontal();

            bool generate = GUILayout.Button("Generate AOT DLL", GUILayout.Height(40));

            bool scan = GUILayout.Button("Scan Types", GUILayout.Height(40));

            if (GUILayout.Button("Add Explicit Type", GUILayout.Height(40)))
            {
                AddTypeContextMenu.ShowAsPopup(AddType);
            }

            GUILayout.EndHorizontal();

            var dll = PluginImporter.GetAtPath(DashEditorCore.EditorConfig.AOTAssemblyPath + "/" +
                                               DashEditorCore.EditorConfig.AOTAssemblyName + ".dll");

            if (dll != null)
            {
                GUILayout.Label("Assembly generated in " + DashEditorCore.EditorConfig.AOTAssemblyPath + "/" +
                                DashEditorCore.EditorConfig.AOTAssemblyName + ".dll" + " last generated on " +
                                DashEditorCore.EditorConfig.AOTAssemblyGeneratedTime);
            }
            else
            {
                GUILayout.Label("No generated Dash AOT Assembly found.");
            }

            GUILayout.EndVertical();

            if (scan)
            {
                DashAOTScanner.Scan();
            }
            else if (generate)
            {
                DashAOTScanner.GenerateDLL(_generateLinkXml, _includeOdin);
            }
        }
コード例 #2
0
        private void OnGUI()
        {
            var rect = new Rect(0, 0, position.width, position.height);

            GUICustomUtils.DrawTitle("Dash Expressions Editor");

            DashEditorCore.RuntimeConfig.enableCustomExpressionClasses = GUILayout.Toggle(DashEditorCore.RuntimeConfig.enableCustomExpressionClasses, new GUIContent("Enable Custom Expression Classes (has small runtime impact)"));

            var titleStyle = new GUIStyle();

            titleStyle.alignment        = TextAnchor.MiddleLeft;
            titleStyle.padding.left     = 5;
            titleStyle.normal.textColor = new Color(1, .5f, 0);
            titleStyle.fontStyle        = FontStyle.Bold;
            titleStyle.fontSize         = 16;

            var infoStyle = new GUIStyle();

            infoStyle.normal.textColor = Color.gray;
            infoStyle.alignment        = TextAnchor.MiddleLeft;
            infoStyle.padding.left     = 5;

            var scrollViewStyle = new GUIStyle();

            scrollViewStyle.normal.background = TextureUtils.GetColorTexture(new Color(.1f, .1f, .1f));

            GUI.enabled = DashEditorCore.RuntimeConfig.enableCustomExpressionClasses;

            GUILayout.Space(4);
            GUILayout.Label("Expression classes", titleStyle, GUILayout.ExpandWidth(true));
            GUILayout.Label(
                "You have " +
                (DashEditorCore.RuntimeConfig.expressionClasses == null
                    ? 0
                    : DashEditorCore.RuntimeConfig.expressionClasses.Count) + " expression classes defined.", infoStyle,
                GUILayout.ExpandWidth(true));
            GUILayout.Space(2);

            _scrollPositionScanned = GUILayout.BeginScrollView(_scrollPositionScanned, scrollViewStyle,
                                                               GUILayout.ExpandWidth(true), GUILayout.Height(rect.height / 2 - 140));
            GUILayout.BeginVertical();

            if (DashEditorCore.RuntimeConfig.expressionClasses != null)
            {
                foreach (Type type in DashEditorCore.RuntimeConfig.expressionClasses)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label((string.IsNullOrEmpty(type.Namespace) ? "" : type.Namespace + ".") +
                                    type.GetReadableTypeName());
                    if (GUILayout.Button("Remove", GUILayout.Width(120)))
                    {
                        RemoveExpressionClass(type);
                        break;
                    }
                    GUILayout.EndHorizontal();
                }
            }

            GUILayout.EndVertical();
            GUILayout.EndScrollView();

            GUILayout.Space(4);
            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Add Expression Class", GUILayout.Height(40)))
            {
                AddTypeContextMenu.ShowAsPopup(AddExpressionClass);
            }

            GUILayout.EndHorizontal();

            GUI.enabled = true;

            GUILayout.Space(4);
            GUILayout.Label("Expression macros", titleStyle, GUILayout.ExpandWidth(true));
            GUILayout.Label(
                "You have " +
                (DashEditorCore.RuntimeConfig.expressionMacros == null
                    ? 0
                    : DashEditorCore.RuntimeConfig.expressionMacros.Count) + " expression macros defined.", infoStyle,
                GUILayout.ExpandWidth(true));
            GUILayout.Space(2);

            _scrollPositionScanned = GUILayout.BeginScrollView(_scrollPositionScanned, scrollViewStyle,
                                                               GUILayout.ExpandWidth(true), GUILayout.Height(rect.height / 2 - 100));
            GUILayout.BeginVertical();

            if (DashEditorCore.RuntimeConfig.expressionMacros != null)
            {
                foreach (var pair in DashEditorCore.RuntimeConfig.expressionMacros)
                {
                    GUILayout.BeginHorizontal();
                    string strippedName = pair.Key.Substring(1, pair.Key.Length - 2);

                    string newName = GUILayout.TextField(strippedName, GUILayout.Width(160)).ToUpper();
                    newName = Regex.Replace(newName, @"[^a-zA-Z0-9 _]", "");

                    if (newName != strippedName)
                    {
                        DashEditorCore.RuntimeConfig.expressionMacros.Remove(pair.Key);
                        DashEditorCore.RuntimeConfig.expressionMacros.Add("{" + GetUniqueName(newName) + "}", pair.Value);
                        break;
                    }

                    string newValue = GUILayout.TextField(pair.Value);
                    if (newValue != pair.Value)
                    {
                        DashEditorCore.RuntimeConfig.expressionMacros[pair.Key] = newValue;
                        break;
                    }

                    if (GUILayout.Button("Remove", GUILayout.Width(120)))
                    {
                        RemoveExpressionMacro(pair.Key);
                        break;
                    }
                    GUILayout.EndHorizontal();
                }
            }

            GUILayout.EndVertical();
            GUILayout.EndScrollView();

            GUILayout.Space(4);
            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Add Expression Macro", GUILayout.Height(40)))
            {
                AddExpressionMacro();
            }

            GUILayout.EndHorizontal();
        }