コード例 #1
0
ファイル: DragFloderWindow.cs プロジェクト: kt2/LearnUnity
    private void OnGUI()
    {
        // 方法一:
        // 需要构建的路径
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("需要打包的路径 (鼠标拖拽文件夹到这里)");
        EditorGUILayout.Space();
        // this.path = EditorGUILayout.TextField(this.path);
        GUI.SetNextControlName("input1");//设置下一个控件的名字
        pathRect = EditorGUILayout.GetControlRect(GUILayout.Width(400));
        path     = EditorGUI.TextField(pathRect, path);
        EditorGUILayout.Space();

        // 构建后的路径
        EditorGUILayout.LabelField("打包后的路径 (鼠标拖拽文件夹到这里)");
        EditorGUILayout.Space();
        // this.buildPath = EditorGUILayout.TextField(this.buildPath);
        GUI.SetNextControlName("input2");//设置下一个控件的名字
        buildPathRect = EditorGUILayout.GetControlRect(GUILayout.Width(400));
        buildPath     = EditorGUI.TextField(buildPathRect, buildPath);
        EditorGUILayout.Space();

        // 文件拖拽
        DragFolder();


        // 方法二(更简洁):
        EditorGUILayoutTools.DrawObjectField("添加文件夹", ref destDir, typeof(Object), (v) =>
        {
            path1 = AssetDatabase.GetAssetPath(destDir);
            Debug.Log("路径:" + path1);
        });
        EditorGUILayout.TextField(path1);
    }
コード例 #2
0
        /// <summary>
        /// Draws the body GUI section
        /// </summary>
        /// <param name="settings"></param>
        public virtual void DrawContent(GenesisSettings settings)
        {
            // The default implementation for draw content enables its content to be collapsed via a foldout header bar.
            _drawContent = EditorGUILayoutTools.DrawSectionHeaderToggle(Title, _drawContent);
            if (!_drawContent)
            {
                return;
            }

            EditorGUILayoutTools.BeginSectionContent();
            DrawContentBody(settings);
            EditorGUILayoutTools.EndSectionContent();
        }
コード例 #3
0
        private void DrawSystemList(DebugSystems systems)
        {
            _showSystemsList = EditorGUILayoutTools.DrawSectionHeaderToggle(SYSTEMS_TITLE, _showSystemsList);
            if (_showSystemsList)
            {
                using (new EditorGUILayout.VerticalScope(EntitasReduxStyles.SectionContent))
                {
                    EditorGUILayout.HelpBox(SYSTEMS_DESCRIPTION, MessageType.Info);

                    using (new EditorGUILayout.HorizontalScope())
                    {
                        DebugSystems.avgResetInterval = (AvgResetInterval)EditorGUILayout.EnumPopup(
                            RESET_AVERAGE_DURATION_LABEL,
                            DebugSystems.avgResetInterval);

                        if (GUILayout.Button(RESET_AVERAGE_NOW_LABEL, EditorStyles.miniButton, GUILayout.Width(150f)))
                        {
                            systems.ResetDurations();
                        }
                    }

                    _threshold = EditorGUILayout.Slider(
                        THRESHOLD_SLIDER_LABEL,
                        _threshold,
                        0f,
                        33f);

                    _hideEmptySystems = EditorGUILayout.Toggle(HIDE_EMPTY_SYSTEMS_LABEL, _hideEmptySystems);
                    EditorGUILayout.Space();

                    using (new EditorGUILayout.HorizontalScope())
                    {
                        _systemSortMethod = (SortMethod)EditorGUILayout.EnumPopup(
                            _systemSortMethod,
                            EditorStyles.popup,
                            GUILayout.Width(150));
                        _systemNameSearchString = EditorGUILayoutTools.SearchTextField(_systemNameSearchString);
                    }

                    EditorGUILayout.Space();

                    DrawSystemSection(INITIALIZE_SYSTEMS_TITLE, ref _showInitializeSystems, systems, SystemInterfaceFlags.InitializeSystem);
                    DrawSystemSection(FIXED_UPDATE_SYSTEMS_TITLE, ref _showFixedUpdateSystems, systems, SystemInterfaceFlags.FixedUpdateSystem);
                    DrawSystemSection(UPDATE_SYSTEMS_TITLE, ref _showUpdateSystems, systems, SystemInterfaceFlags.UpdateSystem);
                    DrawSystemSection(LATE_UPDATE_SYSTEMS_TITLE, ref _showLateUpdateSystems, systems, SystemInterfaceFlags.LateUpdateSystem);
                    DrawSystemSection(REACTIVE_SYSTEMS_TITLE, ref _showReactiveSystems, systems, SystemInterfaceFlags.ReactiveSystem);
                    DrawSystemSection(CLEANUP_SYSTEMS_TITLE, ref _showCleanupSystems, systems, SystemInterfaceFlags.CleanupSystem);
                    DrawSystemSection(TEARDOWN_SYSTEMS_TITLE, ref _showTearDownSystems, systems, SystemInterfaceFlags.TearDownSystem);
                }
            }
        }
コード例 #4
0
 private void DrawSystemSection(string header,
                                ref bool showSystems,
                                DebugSystems systems,
                                SystemInterfaceFlags systemInterfaceFlags)
 {
     showSystems = EditorGUILayoutTools.DrawSectionHeaderToggle(header, showSystems);
     if (showSystems && ShouldShowSystems(systems, systemInterfaceFlags))
     {
         using (new EditorGUILayout.VerticalScope(EntitasReduxStyles.SectionContent))
         {
             var systemsDrawn = DrawSystemInfos(systems, systemInterfaceFlags);
             if (systemsDrawn == 0)
             {
                 EditorGUILayout.LabelField(string.Empty);
             }
         }
     }
 }
コード例 #5
0
 private static void DrawSystemsOverview(DebugSystems systems)
 {
     _showDetails = EditorGUILayoutTools.DrawSectionHeaderToggle(DETAILS_TITLE, _showDetails);
     if (_showDetails)
     {
         using (new EditorGUILayout.VerticalScope(EntitasReduxStyles.SectionContent))
         {
             EditorGUILayout.LabelField(INITIALIZE_SYSTEMS_COUNT_LABEL, systems.TotalInitializeSystemsCount.ToString());
             EditorGUILayout.LabelField(FIXED_UPDATE_SYSTEMS_COUNT_LABEL, systems.TotalFixedUpdateSystemsCount.ToString());
             EditorGUILayout.LabelField(UPDATE_SYSTEMS_COUNT_LABEL, systems.TotalUpdateSystemsCount.ToString());
             EditorGUILayout.LabelField(LATE_UPDATE_SYSTEMS_COUNT_LABEL, systems.TotalLateUpdateSystemsCount.ToString());
             EditorGUILayout.LabelField(REACTIVE_SYSTEMS_COUNT_LABEL, systems.TotalReactiveSystemsCount.ToString());
             EditorGUILayout.LabelField(CLEANUP_SYSTEMS_COUNT_LABEL, systems.TotalCleanupSystemsCount.ToString());
             EditorGUILayout.LabelField(TEARDOWN_SYSTEMS_COUNT_LABEL, systems.TotalTearDownSystemsCount.ToString());
             EditorGUILayout.LabelField(TOTAL_SYSTEMS_COUNT_LABEL, systems.TotalSystemsCount.ToString());
         }
     }
 }
コード例 #6
0
        private void DrawLegendLabel(string label, Color color)
        {
            using (new EditorGUILayout.HorizontalScope(GUILayout.ExpandWidth(false)))
            {
                var newGUIContent = new GUIContent(label);
                var size          = EditorStyles.label.CalcSize(newGUIContent);
                EditorGUILayout.LabelField(newGUIContent, GUILayout.Width(size.x));

                var fixedUpdateLegendRect = GUILayoutUtility.GetRect(
                    BOX_HEIGHT_WIDTH,
                    BOX_HEIGHT_WIDTH,
                    BOX_HEIGHT_WIDTH,
                    BOX_HEIGHT_WIDTH,
                    LEGEND_LABEL_OPTIONS);

                EditorGUILayoutTools.DrawRectWithBorder(
                    fixedUpdateLegendRect,
                    2f,
                    color,
                    Color.black);

                GUILayout.FlexibleSpace();
            }
        }
コード例 #7
0
        void OnGUI()
        {
            EditorGUILayoutTools.Horizontal(() =>
            {
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("快速定位GUI文件夹", GUILayout.Width(150), GUILayout.Height(30)))
                {
                    var assetObj = AssetDatabase.LoadAssetAtPath <Object>(GUIPath);
                    EditorGUIUtility.PingObject(assetObj);
                }
                GUILayout.FlexibleSpace();
            });

            GUILayout.Space(15);

            EditorGUILayoutTools.Horizontal(() =>
            {
                inputText = EditorGUILayout.TextField("输入需要查找的Text", inputText);
            });

            EditorGUILayoutTools.Horizontal(() =>
            {
                searchType = (SearchType)EditorGUILayout.EnumPopup("匹配模式", searchType, "ToolbarPopup");
            });

            for (int i = 0; i < destDirList.Count; i++)
            {
                EditorGUILayoutTools.Horizontal(() =>
                {
                    destDirList[i] = EditorGUILayout.ObjectField("文件夹" + (i + 1), destDirList[i], typeof(Object), false);
                    if (GUILayout.Button("Delete", GUILayout.Width(50), GUILayout.Height(15)))
                    {
                        destDirList.RemoveAt(i);
                    }
                });
            }

            EditorGUILayoutTools.DrawObjectField("添加文件夹", ref destDir, typeof(Object), (v) =>
            {
                if (destDirList.Contains(destDir))
                {
                    EditorUtility.DisplayDialog("添加失败!", "已经添加该文件夹", "OK");
                    destDir = null;
                }
                else
                {
                    destDirList.Add(destDir);
                    destDir = null;
                }
            });

            if (prefabList.Count > 0)
            {
                EditorGUILayoutTools.DrawPopup("预制体列表", ref selectIndex, prefabList.ToArray(), (path) =>
                {
                    selectPrefab = AssetDatabase.LoadAssetAtPath <GameObject>(RecoverPrefabPath(path));
                    EditorGUIUtility.PingObject(selectPrefab);
                });
            }

            GUILayout.Space(30);
            EditorGUILayoutTools.Horizontal(() =>
            {
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("查找预制体", GUILayout.Width(300), GUILayout.Height(40)))
                {
                    if (inputText == null || inputText.Equals(""))
                    {
                        EditorUtility.DisplayDialog("查找失败!", "请输入需要查找的字符!", "OK");
                        return;
                    }
                    var stime = EditorApplication.timeSinceStartup;
                    StartSearch();
                    Debug.Log("查询时间:" + (EditorApplication.timeSinceStartup - stime).ToString());
                }
                GUILayout.FlexibleSpace();
            });
            GUILayout.Space(30);
        }
コード例 #8
0
ファイル: BezierEditor.cs プロジェクト: kt2/LearnUnity
    private void OnGUI()
    {
        GUIStyle style = new GUIStyle();

        style.fontSize         = 16;
        style.normal.textColor = new Color32(255, 255, 255, 255);
        GUILayout.Space(15);

        EditorGUILayoutTools.DrawSliderField("曲线宽度", ref lineWidth, 1, (v) =>
        {
            SetLineWidth(v);
        });
        EditorGUILayout.Space(10);

        EditorGUILayout.BeginHorizontal();
        {
            EditorGUILayoutTools.DrawObjectField("曲线材质", ref lineMat, typeof(Material), (v) =>
            {
                SetLineMat(v);
            });

            EditorGUILayoutTools.DrawGradientField("曲线颜色", ref lineColor, (v) =>
            {
                SetLineColor();
            });
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space(10);
        EditorGUILayoutTools.DrawColorField("辅助线颜色", ref sublineColor, (v) =>
        {
            SetSublineColor(v);
        });
        EditorGUILayout.Space(10);
        EditorGUILayout.BeginHorizontal();
        {
            EditorGUILayoutTools.DrawObjectField("执行对象", ref player, typeof(GameObject), (v) =>
            {
                // SetLineMat(player);
            });

            EditorGUILayoutTools.DrawFloatField("运动时长", ref duration, (v) => { });

            EditorGUILayoutTools.DrawEnumPopup("Ease", ref ease, (value) => { });
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space(10);

        EditorGUILayoutTools.DrawTextField("曲线保存路径", ref curPath, (v) => { });

        EditorGUILayout.Space(10);

        EditorGUILayout.BeginHorizontal();
        {
            if (GUILayout.Button("保存曲线为预制体", GUILayout.Height(20)))
            {
                SaveCurvePrefab();
            }

            if (GUILayout.Button("播放", GUILayout.Height(20)))
            {
                Run();
            }
        }
        EditorGUILayout.EndHorizontal();
    }
コード例 #9
0
        private int DrawSystemInfos(DebugSystems systems, SystemInterfaceFlags type)
        {
            IEnumerable <SystemInfo> systemInfos = null;

            switch (type)
            {
            case SystemInterfaceFlags.InitializeSystem:
                systemInfos = systems.InitializeSystemInfos
                              .Where(systemInfo => systemInfo.InitializationDuration >= _threshold);
                break;

            case SystemInterfaceFlags.FixedUpdateSystem:
                systemInfos = systems.FixedUpdateSystemInfos
                              .Where(systemInfo => systemInfo.AverageFixedUpdateDuration >= _threshold);
                break;

            case SystemInterfaceFlags.UpdateSystem:
                systemInfos = systems.UpdateSystemInfos
                              .Where(systemInfo => systemInfo.AverageUpdateDuration >= _threshold);
                break;

            case SystemInterfaceFlags.LateUpdateSystem:
                systemInfos = systems.LateUpdateSystemInfos
                              .Where(systemInfo => systemInfo.AverageLateUpdateDuration >= _threshold);
                break;

            case SystemInterfaceFlags.ReactiveSystem:
                systemInfos = systems.ReactiveSystemInfos
                              .Where(systemInfo => systemInfo.AverageReactiveDuration >= _threshold);
                break;

            case SystemInterfaceFlags.CleanupSystem:
                systemInfos = systems.CleanupSystemInfos
                              .Where(systemInfo => systemInfo.CleanupDuration >= _threshold);
                break;

            case SystemInterfaceFlags.TearDownSystem:
                systemInfos = systems.TearDownSystemInfos
                              .Where(systemInfo => systemInfo.TeardownDuration >= _threshold);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            systemInfos = GetSortedSystemInfos(systemInfos, _systemSortMethod);

            var systemsDrawn = 0;

            foreach (var systemInfo in systemInfos)
            {
                if (systemInfo.System is DebugSystems debugSystems)
                {
                    if (!ShouldShowSystems(debugSystems, type))
                    {
                        continue;
                    }
                }

                if (EditorGUILayoutTools.MatchesSearchString(systemInfo.SystemName.ToLower(), _systemNameSearchString.ToLower()))
                {
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        var indent = EditorGUI.indentLevel;
                        EditorGUI.indentLevel = 0;

                        var wasActive        = systemInfo.isActive;
                        var areParentsActive = systemInfo.AreAllParentsActive;
                        if (areParentsActive)
                        {
                            systemInfo.isActive = EditorGUILayout.Toggle(systemInfo.isActive, GUILayout.Width(20));
                        }
                        else
                        {
                            using (new EditorGUI.DisabledScope(true))
                            {
                                EditorGUILayout.Toggle(false, GUILayout.Width(20));
                            }
                        }

                        EditorGUI.indentLevel = indent;

                        if (systemInfo.isActive != wasActive)
                        {
                            if (systemInfo.System is IReactiveSystem reactiveSystem)
                            {
                                if (systemInfo.isActive)
                                {
                                    reactiveSystem.Activate();
                                }
                                else
                                {
                                    reactiveSystem.Deactivate();
                                }
                            }
                        }

                        using (new EditorGUI.DisabledScope(!systemInfo.isActive || !areParentsActive))
                        {
                            var guiStyle = GetSystemStyle(systemInfo, type);

                            switch (type)
                            {
                            case SystemInterfaceFlags.InitializeSystem:
                                DrawSimpleSystemInfoPerformance(
                                    systemInfo.SystemName,
                                    systemInfo.InitializationDuration,
                                    guiStyle);
                                break;

                            case SystemInterfaceFlags.FixedUpdateSystem:
                                DrawDetailedSystemInfoPerformance(
                                    systemInfo.SystemName,
                                    systemInfo.AverageFixedUpdateDuration,
                                    systemInfo.MinFixedUpdateDuration,
                                    systemInfo.MaxFixedUpdateDuration,
                                    guiStyle);
                                break;

                            case SystemInterfaceFlags.UpdateSystem:
                                DrawDetailedSystemInfoPerformance(
                                    systemInfo.SystemName,
                                    systemInfo.AverageUpdateDuration,
                                    systemInfo.MinUpdateDuration,
                                    systemInfo.MaxUpdateDuration,
                                    guiStyle);
                                break;

                            case SystemInterfaceFlags.LateUpdateSystem:
                                DrawDetailedSystemInfoPerformance(
                                    systemInfo.SystemName,
                                    systemInfo.AverageLateUpdateDuration,
                                    systemInfo.MinLateUpdateDuration,
                                    systemInfo.MaxLateUpdateDuration,
                                    guiStyle);
                                break;

                            case SystemInterfaceFlags.ReactiveSystem:
                                DrawDetailedSystemInfoPerformance(
                                    systemInfo.SystemName,
                                    systemInfo.AverageReactiveDuration,
                                    systemInfo.MinReactiveDuration,
                                    systemInfo.MaxReactiveDuration,
                                    guiStyle);
                                break;

                            case SystemInterfaceFlags.CleanupSystem:
                                DrawDetailedSystemInfoPerformance(
                                    systemInfo.SystemName,
                                    systemInfo.AverageCleanupDuration,
                                    systemInfo.MinCleanupDuration,
                                    systemInfo.MaxCleanupDuration,
                                    guiStyle);
                                break;

                            case SystemInterfaceFlags.TearDownSystem:
                                DrawSimpleSystemInfoPerformance(
                                    systemInfo.SystemName,
                                    systemInfo.TeardownDuration,
                                    guiStyle);
                                break;

                            default:
                                throw new ArgumentOutOfRangeException(nameof(type), type, null);
                            }
                        }
                    }

                    systemsDrawn += 1;
                }

                if (systemInfo.System is DebugSystems debugSystem)
                {
                    var indent = EditorGUI.indentLevel;
                    EditorGUI.indentLevel += 1;
                    systemsDrawn          += DrawSystemInfos(debugSystem, type);
                    EditorGUI.indentLevel  = indent;
                }
            }

            return(systemsDrawn);
        }
コード例 #10
0
        private void DrawSystemsMonitor(DebugSystems systems)
        {
            _showSystemsMonitor = EditorGUILayoutTools.DrawSectionHeaderToggle(PERFORMANCE_TITLE, _showSystemsMonitor);
            if (_showSystemsMonitor)
            {
                using (new EditorGUILayout.VerticalScope(VisualDebugStyles.SectionContent))
                {
                    // Draw Average Performance Stats
                    using (new EditorGUILayout.VerticalScope())
                    {
                        EditorGUILayout.LabelField(AVERAGE_PERFORMANCE_TITLE, EditorStyles.boldLabel);

                        DrawDurationLabel(FIXED_UPDATE_DURATION_LABEL, systems.AverageFixedUpdateDuration);
                        DrawDurationLabel(UPDATE_DURATION_LABEL, systems.AverageUpdateDuration);
                        DrawDurationLabel(LATE_UPDATE_DURATION_LABEL, systems.AverageLateUpdateDuration);
                        DrawDurationLabel(REACTIVE_DURATION_LABEL, systems.AverageReactiveDuration);
                        DrawDurationLabel(CLEANUP_DURATION_LABEL, systems.AverageCleanupDuration);
                    }

                    // Draw Legend
                    using (var legendScope = new EditorGUILayout.VerticalScope())
                    {
                        using (new EditorGUILayout.HorizontalScope())
                        {
                            GUILayout.FlexibleSpace();
                            EditorGUILayout.LabelField(GRAPH_LEGEND, EditorStyles.boldLabel, GUILayout.Width(60f));
                            GUILayout.FlexibleSpace();
                        }

                        GUILayout.Space(5);

                        using (new EditorGUILayout.HorizontalScope())
                        {
                            DrawLegendLabel(FIXED_UPDATE_LEGEND, VisualDebuggingPreferences.FixedUpdateColor);
                            GUILayout.FlexibleSpace();

                            DrawLegendLabel(UPDATE_LEGEND, VisualDebuggingPreferences.UpdateColor);
                            GUILayout.FlexibleSpace();

                            DrawLegendLabel(LATE_UPDATE_LEGEND, VisualDebuggingPreferences.LateUpdateColor);
                        }
                    }

                    EditorGUILayout.Space(5);

                    // Update Graph
                    if (!EditorApplication.isPaused)
                    {
                        AddSystemDurations(systems);
                    }

                    // Draw Graph
                    const float GRAPH_HEIGHT = 100f;
                    _systemsMonitor.Draw(
                        new[]
                    {
                        _fixedUpdateSystemMonitorData.ToArray(),
                        _updateSystemMonitorData.ToArray(),
                        _lateUpdateSystemMonitorData.ToArray()
                    },
                        Screen.width,
                        GRAPH_HEIGHT,
                        new[]
                    {
                        VisualDebuggingPreferences.FixedUpdateColor,
                        VisualDebuggingPreferences.UpdateColor,
                        VisualDebuggingPreferences.LateUpdateColor
                    });
                }
            }
        }
コード例 #11
0
        public override void OnInspectorGUI()
        {
            var contextObserver = ((ContextObserverBehaviour)target).ContextObserver;

            EditorGUILayoutTools.BeginSectionContent();
            {
                EditorGUILayout.LabelField(contextObserver.Context.ContextInfo.name, EditorStyles.boldLabel);
                EditorGUILayout.LabelField("Entities", contextObserver.Context.Count.ToString());
                EditorGUILayout.LabelField("Reusable entities", contextObserver.Context.ReusableEntitiesCount.ToString());

                var retainedEntitiesCount = contextObserver.Context.RetainedEntitiesCount;
                if (retainedEntitiesCount != 0)
                {
                    var c = GUI.color;
                    GUI.color = Color.red;
                    EditorGUILayout.LabelField("Retained entities", retainedEntitiesCount.ToString());
                    GUI.color = c;
                    EditorGUILayout.HelpBox(
                        "WARNING: There are retained entities.\nDid you call entity.Retain(owner) and forgot to call entity.Release(owner)?",
                        MessageType.Warning);
                }

                EditorGUILayout.BeginHorizontal();
                {
                    if (GUILayout.Button("Create Entity"))
                    {
                        var entity          = contextObserver.Context.CreateEntity();
                        var entityBehaviour = FindObjectsOfType <EntityBehaviour>()
                                              .Single(eb => eb.Entity == entity);

                        Selection.activeGameObject = entityBehaviour.gameObject;
                    }

                    var bgColor = GUI.backgroundColor;
                    GUI.backgroundColor = Color.red;
                    if (GUILayout.Button("Destroy All Entities"))
                    {
                        contextObserver.Context.DestroyAllEntities();
                    }

                    GUI.backgroundColor = bgColor;
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayoutTools.EndSectionContent();

            var groups = contextObserver.Groups;

            if (groups.Length != 0)
            {
                EditorGUILayoutTools.BeginSectionContent();
                {
                    EditorGUILayout.LabelField("Groups (" + groups.Length + ")", EditorStyles.boldLabel);
                    foreach (var group in groups.OrderByDescending(g => g.Count))
                    {
                        EditorGUILayout.BeginHorizontal();
                        {
                            EditorGUILayout.LabelField(group.ToString());
                            EditorGUILayout.LabelField(group.Count.ToString(), GUILayout.Width(48));
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }
                EditorGUILayoutTools.EndSectionContent();
            }

            EditorUtility.SetDirty(target);
        }