Ejemplo n.º 1
0
        public void OpenSnapshot(SnapshotFileData snapshot)
        {
            if (First != null)
            {
                if (Second != null)
                {
                    Second.GuiData.CurrentState = SnapshotFileGUIData.State.Closed;
                    UIElementsHelper.SwitchVisibility(Second.GuiData.dynamicVisualElements.openButton, Second.GuiData.dynamicVisualElements.closeButton);
                }
                Second = First;


                m_OpenSnapshotsPane.SetSnapshotUIData(false, Second.GuiData, false);
                Second.GuiData.CurrentState = SnapshotFileGUIData.State.Open;
            }

            First = snapshot;

            m_OpenSnapshotsPane.SetSnapshotUIData(true, snapshot.GuiData, true);
            First.GuiData.CurrentState = SnapshotFileGUIData.State.InView;

            var loadedPackedSnapshot = snapshot.LoadSnapshot();

            if (loadedPackedSnapshot != null)
            {
                m_UIState.SetFirstSnapshot(loadedPackedSnapshot);
            }
        }
Ejemplo n.º 2
0
        void SwapOpenSnapshots()
        {
            var temp = Second;

            Second = First;
            First  = temp;

            m_UIState.SwapLastAndCurrentSnapshot();

            if (First != null)
            {
                m_OpenSnapshotsPane.SetSnapshotUIData(true, First.GuiData, m_UIState.CurrentViewMode == UIState.ViewMode.ShowFirst);
            }
            else
            {
                m_OpenSnapshotsPane.SetSnapshotUIData(true, null, false);
            }

            if (Second != null)
            {
                m_OpenSnapshotsPane.SetSnapshotUIData(false, Second.GuiData, m_UIState.CurrentViewMode == UIState.ViewMode.ShowSecond);
            }
            else
            {
                m_OpenSnapshotsPane.SetSnapshotUIData(false, null, false);
            }
        }
        public void RenameSnapshot(SnapshotFileData snapshot, string name)
        {
            int    nameStart  = snapshot.FileInfo.FullName.LastIndexOf(snapshot.FileInfo.Name);
            string targetPath = snapshot.FileInfo.FullName.Substring(0, nameStart) + name + MemoryProfilerWindow.k_SnapshotFileExtension;

            if (targetPath == snapshot.FileInfo.FullName)
            {
                snapshot.GuiData.dynamicVisualElements.snapshotNameLabel.text = snapshot.GuiData.name.text;
                snapshot.GuiData.RenamingFieldVisible = false;
                return;
            }

            snapshot.GuiData.name = new GUIContent(name);
            snapshot.GuiData.dynamicVisualElements.snapshotNameLabel.text = name;
            snapshot.GuiData.RenamingFieldVisible = false;

#if UNITY_2019_3_OR_NEWER
            if (snapshot.GuiData.texture != null)
            {
                string possibleSSPath = Path.ChangeExtension(snapshot.FileInfo.FullName, ".png");
                if (File.Exists(possibleSSPath))
                {
                    File.Move(possibleSSPath, Path.ChangeExtension(targetPath, ".png"));
                }
            }
#endif
            //move snapshot after screenshot
            snapshot.FileInfo.MoveTo(targetPath);
            m_Info.Refresh();
        }
Ejemplo n.º 4
0
        public void RenameSnapshot(SnapshotFileData snapshot, string name)
        {
            int    nameStart  = snapshot.FileInfo.FullName.LastIndexOf(snapshot.FileInfo.Name);
            string targetPath = snapshot.FileInfo.FullName.Substring(0, nameStart) + name + MemoryProfilerWindow.k_SnapshotFileExtension;

            snapshot.FileInfo.MoveTo(targetPath);
            snapshot.GuiData.name = new GUIContent(name);
            snapshot.GuiData.dynamicVisualElements.snapshotNameLabel.text = name;
            snapshot.GuiData.RenamingFieldVisible = false;
            m_Info.Refresh();
        }
Ejemplo n.º 5
0
 public void CloseAllOpenSnapshots()
 {
     if (Second != null)
     {
         CloseCapture(Second);
         Second = null;
     }
     if (First != null)
     {
         CloseCapture(First);
         First = null;
     }
 }
        public void RemoveSnapshotFromCollection(SnapshotFileData snapshot)
        {
            snapshot.FileInfo.Delete();
            m_Snapshots.Remove(snapshot);
#if UNITY_2019_3_OR_NEWER
            string possibleSSPath = Path.ChangeExtension(snapshot.FileInfo.FullName, ".png");
            if (File.Exists(possibleSSPath))
            {
                File.Delete(possibleSSPath);
            }
#endif
            m_Info.Refresh();
        }
        public bool RenameSnapshot(SnapshotFileData snapshot, string name)
        {
            if (name.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
            {
                EditorUtility.DisplayDialog("Error", $"Filename '{name}' contains invalid characters", "OK");
                return(false);
            }
            int    nameStart  = snapshot.FileInfo.FullName.LastIndexOf(snapshot.FileInfo.Name);
            string targetPath = snapshot.FileInfo.FullName.Substring(0, nameStart) + name + MemoryProfilerWindow.k_SnapshotFileExtension;

            if (targetPath == snapshot.FileInfo.FullName)
            {
                snapshot.GuiData.dynamicVisualElements.snapshotNameLabel.text = snapshot.GuiData.name.text;
                snapshot.GuiData.RenamingFieldVisible = false;
                return(false);
            }

            var dir = snapshot.FileInfo.FullName.Substring(0, nameStart);

            if (Directory.GetFiles(dir).Contains($"{dir}{name}{ MemoryProfilerWindow.k_SnapshotFileExtension}"))
            {
                EditorUtility.DisplayDialog("Error", $"Filename '{name}' already exists", "OK");
                return(false);
            }

            snapshot.GuiData.name = new GUIContent(name);
            snapshot.GuiData.dynamicVisualElements.snapshotNameLabel.text = name;
            snapshot.GuiData.RenamingFieldVisible = false;

#if UNITY_2019_3_OR_NEWER
            if (snapshot.GuiData.guiTexture != null)
            {
                string possibleSSPath = Path.ChangeExtension(snapshot.FileInfo.FullName, ".png");
                if (File.Exists(possibleSSPath))
                {
                    File.Move(possibleSSPath, Path.ChangeExtension(targetPath, ".png"));
                }
            }
#endif
            //move snapshot after screenshot
            snapshot.FileInfo.MoveTo(targetPath);
            m_Info.Refresh();
            return(true);
        }
Ejemplo n.º 8
0
        internal void RefreshOpenSnapshots(SnapshotCollectionEnumerator snaps)
        {
            SnapshotFileGUIData firstGUIData = null, secondGUIData = null;

            snaps.Reset();
            while (snaps.MoveNext())
            {
                if (First == snaps.Current)
                {
                    First        = snaps.Current;
                    firstGUIData = First.GuiData;
                    firstGUIData.CurrentState = SnapshotFileGUIData.State.Open;
                }
                else if (Second == snaps.Current)
                {
                    Second        = snaps.Current;
                    secondGUIData = Second.GuiData;
                    secondGUIData.CurrentState = SnapshotFileGUIData.State.Open;
                }
            }
            m_OpenSnapshotsPane.RefreshScreenshots(firstGUIData, secondGUIData);
        }
Ejemplo n.º 9
0
        public void CloseCapture(SnapshotFileData snapshot)
        {
            if (snapshot == null)
            {
                return;
            }
            try
            {
                if (Second != null)
                {
                    if (snapshot == Second)
                    {
                        m_UIState.ClearSecondMode();
                        Second.GuiData.CurrentState = SnapshotFileGUIData.State.Closed;
                    }
                    else if (snapshot == First)
                    {
                        m_UIState.ClearFirstMode();
                        if (First != null)
                        {
                            First.GuiData.CurrentState = SnapshotFileGUIData.State.Closed;
                        }
                        First = Second;
                        m_UIState.SwapLastAndCurrentSnapshot();
                    }
                    else
                    {
                        // The snapshot wasn't open, there is nothing left todo here.
                        return;
                    }
                    UIElementsHelper.SwitchVisibility(snapshot.GuiData.dynamicVisualElements.openButton, snapshot.GuiData.dynamicVisualElements.closeButton);
                    Second = null;
                    m_UIState.CurrentViewMode = UIState.ViewMode.ShowFirst;

                    if (First != null)
                    {
                        m_OpenSnapshotsPane.SetSnapshotUIData(true, First.GuiData, true);
                    }
                    else
                    {
                        m_OpenSnapshotsPane.SetSnapshotUIData(true, null, true);
                    }
                    m_OpenSnapshotsPane.SetSnapshotUIData(false, null, false);
                    // With two snapshots open, there could also be a diff to be closed/cleared.
                    m_UIState.ClearDiffMode();
                }
                else
                {
                    if (snapshot == First)
                    {
                        First.GuiData.CurrentState = SnapshotFileGUIData.State.Closed;
                        First = null;
                        m_UIState.ClearAllOpenModes();
                    }
                    else if (snapshot == Second)
                    {
                        Second.GuiData.CurrentState = SnapshotFileGUIData.State.Closed;
                        Second = null;
                        m_UIState.ClearAllOpenModes();
                    }
                    else
                    {
                        // The snapshot wasn't open, there is nothing left todo here.
                        return;
                    }
                    m_OpenSnapshotsPane.SetSnapshotUIData(true, null, false);
                    m_OpenSnapshotsPane.SetSnapshotUIData(false, null, false);
                }
                UIElementsHelper.SwitchVisibility(snapshot.GuiData.dynamicVisualElements.openButton, snapshot.GuiData.dynamicVisualElements.closeButton);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 10
0
 public bool IsSnapshotOpen(SnapshotFileData snapshot)
 {
     return(snapshot == First || snapshot == Second);
 }
Ejemplo n.º 11
0
 public void RemoveSnapshotFromCollection(SnapshotFileData snapshot)
 {
     snapshot.FileInfo.Delete();
     m_Snapshots.Remove(snapshot);
     m_Info.Refresh();
 }
        public SnapshotFileData AddSnapshotToCollection(string path, ImportMode mode)
        {
            FileInfo file = new FileInfo(path);

            StringBuilder newPath = new StringBuilder(256);

            newPath.Append(Path.Combine(MemoryProfilerSettings.AbsoluteMemorySnapshotStoragePath, Path.GetFileNameWithoutExtension(file.Name)));
            string finalPath = string.Format("{0}{1}", newPath.ToString(), MemoryProfilerWindow.k_SnapshotFileExtension);
            bool   samePath  = finalPath.ToLowerInvariant() == path.ToLowerInvariant();

            if (File.Exists(finalPath) && !samePath)
            {
                string searchStr = string.Format("{0}*{1}",
                                                 Path.GetFileNameWithoutExtension(file.Name), MemoryProfilerWindow.k_SnapshotFileExtension);

                var files = m_Info.GetFiles(searchStr);

                int           snapNum    = 1;
                StringBuilder postFixStr = new StringBuilder("(1)");
                for (int i = 0; i < files.Length; ++i)
                {
                    if (files[i].Name.Contains(postFixStr.ToString()))
                    {
                        ++snapNum;
                        postFixStr.Clear();
                        postFixStr.Append('(');
                        postFixStr.Append(snapNum);
                        postFixStr.Append(')');
                    }
                }

                newPath.Append(' ');
                newPath.Append(postFixStr);
                newPath.Append(MemoryProfilerWindow.k_SnapshotFileExtension);
                finalPath = newPath.ToString();
            }


            string originalSSPath = path.Replace(MemoryProfilerWindow.k_SnapshotFileExtension, ".png");
            bool   ssExists       = File.Exists(originalSSPath);

            switch (mode)
            {
            case ImportMode.Copy:
                file = file.CopyTo(finalPath, false);
                if (ssExists)
                {
                    File.Copy(originalSSPath, finalPath.Replace(MemoryProfilerWindow.k_SnapshotFileExtension, ".png"));
                }
                break;

            case ImportMode.Move:
                file.MoveTo(finalPath);
                if (ssExists)
                {
                    File.Move(originalSSPath, finalPath.Replace(MemoryProfilerWindow.k_SnapshotFileExtension, ".png"));
                }
                break;
            }


            var snapFileData = new SnapshotFileData(file);

            m_Snapshots.Add(snapFileData);
            m_Info.Refresh();
            m_Snapshots.Sort();

            if (collectionRefresh != null)
            {
                using (var it = GetEnumerator())
                    collectionRefresh(it);
            }

            return(snapFileData);
        }