OpenFilePanel() private method

private OpenFilePanel ( string title, string directory, string extension ) : string
title string
directory string
extension string
return string
示例#1
0
        private void OnGUI()
        {
            bool  recording = NetworkProfiler.IsRunning;
            float deltaTime = (float)(EditorApplication.timeSinceStartup - lastSetup);

            lastSetup = EditorApplication.timeSinceStartup;

            //Draw top bar
            EditorGUILayout.BeginVertical();
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(recording ? "Stop" : "Capture"))
            {
                ChangeRecordState();
            }

            if (GUILayout.Button("Clear"))
            {
                ClearDrawing();
            }
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            if (GUILayout.Button("Import datafile"))
            {
                string path = EditorUtility.OpenFilePanel("Choose a NetworkProfiler file", "", "");
                if (!string.IsNullOrEmpty(path))
                {
                    ProfilerTick[] ticks = ProfilerContainer.FromBytes(File.ReadAllBytes(path)).ticks;
                    if (ticks.Length >= 2)
                    {
                        curve   = AnimationCurve.Constant(ticks[0].EventId, ticks[(ticks.Length - 1)].EventId, 0);
                        showMax = ticks.Length;
                        showMin = ticks.Length - Mathf.Clamp(100, 0, ticks.Length);
                    }
                    else
                    {
                        curve = AnimationCurve.Constant(0, 1, 0);
                    }
                    currentTicks.Clear();
                    for (int i = 0; i < ticks.Length; i++)
                    {
                        currentTicks.Add(ticks[i]);

                        uint bytes = 0;
                        if (ticks[i].Events.Count > 0)
                        {
                            for (int j = 0; j < ticks[i].Events.Count; j++)
                            {
                                TickEvent tickEvent = ticks[i].Events[j];
                                bytes += tickEvent.Bytes;
                            }
                        }
                        curve.AddKey(ticks[i].EventId, bytes);
                    }
                }
            }

            if (GUILayout.Button("Export datafile"))
            {
                int            max          = (int)showMax;
                int            min          = (int)showMin;
                int            ticksInRange = max - min;
                ProfilerTick[] ticks        = new ProfilerTick[ticksInRange];
                for (int i = min; i < max; i++)
                {
                    ticks[i - min] = currentTicks[i];
                }
                string path = EditorUtility.SaveFilePanel("Save NetworkProfiler data", "", "networkProfilerData", "");
                if (!string.IsNullOrEmpty(path))
                {
                    File.WriteAllBytes(path, new ProfilerContainer()
                    {
                        ticks = ticks
                    }.ToBytes());
                }
            }

            EditorGUILayout.EndHorizontal();
            float prevHis = captureCount;

            captureCount = EditorGUILayout.DelayedIntField("History count", captureCount);
            if (captureCount <= 0)
            {
                captureCount = 1;
            }
            updateDelay = EditorGUILayout.Slider("Refresh delay", updateDelay, 0.1f, 10f);
            EditorGUILayout.EndVertical();

            if (prevHis != captureCount)
            {
                StartRecording();
            }

            //Cache
            if (NetworkProfiler.IsRunning)
            {
                if (Time.unscaledTime - lastDrawn > updateDelay)
                {
                    lastDrawn = Time.unscaledTime;
                    currentTicks.Clear();
                    if (NetworkProfiler.Ticks.Count >= 2)
                    {
                        curve = AnimationCurve.Constant(NetworkProfiler.Ticks.ElementAt(0).EventId, NetworkProfiler.Ticks.ElementAt(NetworkProfiler.Ticks.Count - 1).EventId, 0);
                    }

                    for (int i = 0; i < NetworkProfiler.Ticks.Count; i++)
                    {
                        ProfilerTick tick = NetworkProfiler.Ticks.ElementAt(i);
                        currentTicks.Add(tick);

                        uint bytes = 0;
                        if (tick.Events.Count > 0)
                        {
                            for (int j = 0; j < tick.Events.Count; j++)
                            {
                                TickEvent tickEvent = tick.Events[j];
                                bytes += tickEvent.Bytes;
                            }
                        }
                        curve.AddKey(tick.EventId, bytes);
                    }
                }
            }


            //Draw Animation curve and slider
            curve = EditorGUILayout.CurveField(curve);
            EditorGUILayout.MinMaxSlider(ref showMin, ref showMax, 0, currentTicks.Count);
            //Verify slider values
            if (showMin < 0)
            {
                showMin = 0;
            }
            if (showMax > currentTicks.Count)
            {
                showMax = currentTicks.Count;
            }
            if (showMin <= 0 && showMax <= 0)
            {
                showMin = 0;
                showMax = currentTicks.Count;
            }

            //Draw main board
            bool hover            = false;
            int  nonEmptyTicks    = 0;
            int  largestTickCount = 0;
            int  totalTicks       = ((int)showMax - (int)showMin);

            for (int i = (int)showMin; i < (int)showMax; i++)
            {
                if (currentTicks[i].Events.Count > 0)
                {
                    nonEmptyTicks++;                                                   //Count non empty ticks
                }
                if (currentTicks[i].Events.Count > largestTickCount)
                {
                    largestTickCount = currentTicks[i].Events.Count;                                                                  //Get how many events the tick with most events has
                }
            }
            int emptyTicks = totalTicks - nonEmptyTicks;

            float equalWidth   = position.width / totalTicks;
            float propWidth    = equalWidth * 0.3f;
            float widthPerTick = ((position.width - emptyTicks * propWidth) / nonEmptyTicks);

            float currentX    = 0;
            int   emptyStreak = 0;

            for (int i = (int)showMin; i < (int)showMax; i++)
            {
                ProfilerTick tick = currentTicks[i];
                if (tick.Events.Count == 0 && i != totalTicks - 1)
                {
                    emptyStreak++;
                    continue;
                }
                else if (emptyStreak > 0 || i == totalTicks - 1)
                {
                    Rect dataRect = new Rect(currentX, 140f, propWidth * emptyStreak, position.height - 140f);
                    currentX += propWidth * emptyStreak;
                    if (emptyStreak >= 2)
                    {
                        EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y, dataRect.width, dataRect.height), emptyStreak.ToString(), wrapStyle);
                    }
                    emptyStreak = 0;
                }

                if (tick.Events.Count > 0)
                {
                    float heightPerEvent = ((position.height - 140f) - (5f * largestTickCount)) / largestTickCount;

                    float currentY = 140f;
                    for (int j = 0; j < tick.Events.Count; j++)
                    {
                        TickEvent tickEvent = tick.Events[j];
                        Rect      dataRect  = new Rect(currentX, currentY, widthPerTick, heightPerEvent);

                        if (dataRect.Contains(Event.current.mousePosition))
                        {
                            hover      = true;
                            eventHover = tickEvent;
                        }

                        EditorGUI.DrawRect(dataRect, TickTypeToColor(tickEvent.EventType, true));
                        /* EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y, dataRect.width, dataRect.height / 2), tickEvent.EventType.ToString(), wrapStyle); */
                        EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y, dataRect.width, dataRect.height / 2), tickEvent.Time, wrapStyle);
                        EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y + dataRect.height / 2, dataRect.width, dataRect.height / 2), tickEvent.Bytes + "B", wrapStyle);

                        currentY += heightPerEvent + 5f;
                    }
                }
                EditorGUI.DrawRect(new Rect(currentX, 100, widthPerTick, 40), TickTypeToColor(tick.Type, false));
                EditorGUI.LabelField(new Rect(currentX, 100, widthPerTick, 20), tick.Type.ToString(), wrapStyle);
                EditorGUI.LabelField(new Rect(currentX, 120, widthPerTick, 20), tick.Frame.ToString(), wrapStyle);
                currentX += widthPerTick;
            }

            //Calculate alpha
            if (hover)
            {
                hoverAlpha += deltaTime * 10f;

                if (hoverAlpha > 1f)
                {
                    hoverAlpha = 1f;
                }
                else if (hoverAlpha < 0f)
                {
                    hoverAlpha = 0f;
                }
            }
            else
            {
                hoverAlpha -= deltaTime * 10f;
                if (hoverAlpha > 1f)
                {
                    hoverAlpha = 1f;
                }
                else if (hoverAlpha < 0f)
                {
                    hoverAlpha = 0f;
                }
            }

            //Draw hover thingy
            if (eventHover != null)
            {
                Rect rect = new Rect(Event.current.mousePosition, new Vector2(500, 100));
                EditorGUI.DrawRect(rect, GetEditorColorWithAlpha(hoverAlpha));

                float heightPerField = (rect.height - 5) / 4;
                /* EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + 5, rect.width, rect.height), "EventType: " + eventHover.EventType.ToString(), GetStyleWithTextAlpha(EditorStyles.label, hoverAlpha)); */
                EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + 5, rect.width, rect.height), "Time: " + eventHover.Time.ToString(), GetStyleWithTextAlpha(EditorStyles.label, hoverAlpha));
                EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + heightPerField * 1 + 5, rect.width, rect.height), "Size: " + eventHover.Bytes + "B", GetStyleWithTextAlpha(EditorStyles.label, hoverAlpha));
                EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + heightPerField * 2 + 5, rect.width, rect.height), "Channel: " + eventHover.ChannelName, GetStyleWithTextAlpha(EditorStyles.label, hoverAlpha));
                EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + heightPerField * 3 + 5, rect.width, rect.height), "MessageType: " + eventHover.MessageType, GetStyleWithTextAlpha(EditorStyles.label, hoverAlpha));
            }
            Repaint();
        }
示例#2
0
        private void OnGUI()
        {
            if (mStyles == null)
            {
                mStyles = new Styles();
            }

            //toolbar
            EditorGUILayout.BeginHorizontal(mStyles.mPreviewBox, GUILayout.Height(22));
            {
                if (GUILayout.Button("加载obj文件", GUILayout.Width(80)))
                {
                    string path = EditorUtility.OpenFilePanel("select obj file", mOpenMeshPath, "obj");
                    if (!string.IsNullOrEmpty(path))
                    {
                        int id = path.LastIndexOf("/");
                        mOpenMeshPath = path.Substring(0, id + 1);
                        LoadMesh(path);
                    }
                }

                if (GUILayout.Button("加载rip文件", GUILayout.Width(80)))
                {
                    string path = EditorUtility.OpenFilePanel("select rip file", mOpenMeshPath, "rip");
                    if (!string.IsNullOrEmpty(path))
                    {
                        int id = path.LastIndexOf("/");
                        mOpenMeshPath = path.Substring(0, id + 1);
                        LoadRipFile(path);
                    }
                }

                GUILayout.FlexibleSpace();
                if (GUILayout.Button("策略另存为"))
                {
                    SaveConfigDataToFile();
                }
                GUILayout.Space(30);
                if (GUILayout.Button("打开策略"))
                {
                    LoadConfigDataFromFile();
                }
                GUILayout.Space(30);

                newStrategyName = EditorGUILayout.TextField(newStrategyName, GUILayout.Width(100));
                GUILayout.Space(5);
                if (GUILayout.Button("新建策略", GUILayout.Width(80)))
                {
                    if (!StrategyMap.ContainsKey(newStrategyName))
                    {
                        var strategy = new ConvertStrategy();
                        strategy.BufferInfos.Add(ESemantic.Position, new ConvertStrategy.BufferDataInfo(ESemantic.Position));
                        strategy.BufferInfos.Add(ESemantic.Normal, new ConvertStrategy.BufferDataInfo(ESemantic.Normal));
                        strategy.BufferInfos.Add(ESemantic.Coord0, new ConvertStrategy.BufferDataInfo(ESemantic.Coord0));
                        StrategyMap.Add(newStrategyName, strategy);
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.Space(1);

                //draw mesh list
                EditorGUILayout.BeginVertical(mStyles.mPreviewBox, GUILayout.Width(155));
                {
                    GUILayout.Space(2);
                    mMeshListScroll = EditorGUILayout.BeginScrollView(mMeshListScroll);
                    foreach (var p in MeshPathMap)
                    {
                        if (string.IsNullOrEmpty(p.Value) && !MeshMap.ContainsKey(p.Key))
                        {
                            RemoveMeshData(p.Key);
                            break;
                        }
                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Space(2);
                        if (GUILayout.Button(p.Key, EditorStyles.toolbarButton, GUILayout.Width(120)))
                        {
                            MeshData mesh;
                            if (!MeshMap.TryGetValue(p.Key, out mesh))
                            {
                                LoadMesh(p.Value);
                                if (!MeshMap.TryGetValue(p.Key, out mesh))
                                {
                                    Debug.LogWarning("无法打开文件:" + p.Value);
                                    RemoveMeshData(p.Key);
                                    break;
                                }
                            }
                            ViewMeshData(mesh);
                        }
                        if (GUILayout.Button("R", EditorStyles.toolbarButton, GUILayout.Width(30)))
                        {
                            RemoveMeshData(p.Key);
                            break;
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUILayout.EndScrollView();
                }
                EditorGUILayout.EndVertical();
                GUILayout.Space(0);

                //draw strategy list
                EditorGUILayout.BeginVertical();
                {
                    mStrategyListScroll = EditorGUILayout.BeginScrollView(mStrategyListScroll);
                    foreach (var strategy in StrategyMap)
                    {
                        if (!DrawStrategy(strategy.Key, strategy.Value))
                        {
                            break;
                        }
                    }
                    EditorGUILayout.EndScrollView();
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndHorizontal();
        }