Пример #1
0
 private void OnEnable()
 {
     selectionHistory            = EditorTemporaryMemory.Instance.selectionHistory;
     Selection.selectionChanged += OnSelectionChanged;
     wantsMouseMove              = true;
     shouldReloadPreferences     = true;
 }
        void OnEnable()
        {
            automaticRemoveDeleted = EditorPrefs.GetBool(HistoryAutomaticRemoveDeletedPrefKey, true);

            selectionHistory             = EditorTemporaryMemory.Instance.selectionHistory;
            selectionHistory.HistorySize = EditorPrefs.GetInt(HistorySizePrefKey, 10);

            Selection.selectionChanged += delegate {
                if (selectionHistory.IsSelected(selectionHistory.GetHistoryCount() - 1))
                {
                    _historyScrollPosition.y = float.MaxValue;
                }

                Repaint();
            };

            try {
                var asm = Assembly.GetAssembly(typeof(EditorWindow));
                var t   = asm.GetType("UnityEditor.PreferencesWindow");
                openPreferencesWindow = t.GetMethod("ShowPreferencesWindow", BindingFlags.NonPublic | BindingFlags.Static);
            } catch {
                // couldnt get preferences window...
                openPreferencesWindow = null;
            }
        }
        public void TestRemoveDuplicatedElementsInOrder()
        {
            var selectionHistory = new SelectionHistory();

            var selection1 = new GameObject();
            var selection2 = new GameObject();
            var selection3 = new GameObject();

            selectionHistory.UpdateSelection(selection1);
            selectionHistory.UpdateSelection(selection2);
            selectionHistory.UpdateSelection(selection1);
            selectionHistory.UpdateSelection(selection3);
            selectionHistory.UpdateSelection(selection1);

            selectionHistory.RemoveDuplicated();

            Assert.That(selectionHistory.GetHistoryCount(), Is.EqualTo(3));
            Assert.That(selectionHistory.GetSelection(), Is.SameAs(selection1));
            Assert.That(selectionHistory.IsSelected(2), Is.True);

            selectionHistory.UpdateSelection(selection3);
            Assert.That(selectionHistory.GetSelection(), Is.SameAs(selection3));

            selectionHistory.UpdateSelection(selection2);
            Assert.That(selectionHistory.GetSelection(), Is.SameAs(selection2));
        }
        public void TestPreviousAndNextShouldntUpdateHistory()
        {
            var selectionHistory = new SelectionHistory();

            var selection1 = new GameObject();
            var selection2 = new GameObject();

            selectionHistory.UpdateSelection(selection1);
            selectionHistory.UpdateSelection(selection2);

            Assert.AreSame(selectionHistory.GetSelection(), selection2);
            Assert.AreEqual(selectionHistory.GetHistoryCount(), 2);

            selectionHistory.Previous();
            selectionHistory.UpdateSelection(selection1);

            Assert.AreSame(selectionHistory.GetSelection(), selection1);
            Assert.AreEqual(selectionHistory.GetHistoryCount(), 2);

            selectionHistory.Next();
            selectionHistory.UpdateSelection(selection2);

            Assert.AreSame(selectionHistory.GetSelection(), selection2);
            Assert.AreEqual(selectionHistory.GetHistoryCount(), 2);
        }
        public void ClearDeletedEntriesShouldKeepSelectedIndex()
        {
            var selectionHistory = new SelectionHistory();

            var selection1 = new GameObject();
            var selection2 = new GameObject();
            var selection3 = new GameObject();
            var selection4 = new GameObject();

            selectionHistory.UpdateSelection(selection1);
            selectionHistory.UpdateSelection(selection2);
            selectionHistory.UpdateSelection(selection3);
            selectionHistory.UpdateSelection(selection4);

            Assert.IsTrue(selectionHistory.IsSelected(3));
            Assert.AreEqual(selectionHistory.GetHistoryCount(), 4);

            GameObject.DestroyImmediate(selection2);

            selectionHistory.ClearDeleted();

            Assert.IsTrue(selectionHistory.IsSelected(2));
            Assert.AreEqual(selectionHistory.GetHistoryCount(), 3);

            selectionHistory.SetSelection(selection3);

            GameObject.DestroyImmediate(selection1);
            GameObject.DestroyImmediate(selection4);

            selectionHistory.ClearDeleted();

            Assert.IsTrue(selectionHistory.IsSelected(0));
            Assert.AreEqual(selectionHistory.GetHistoryCount(), 1);
        }
        public void NextAndPreviousShouldntExplodeWithoutItems()
        {
            var selectionHistory = new SelectionHistory();

            selectionHistory.Previous();
            selectionHistory.Next();

            Assert.Pass();
        }
        public void NavigationWindowTest()
        {
            var selectionHistory = new SelectionHistory();

            var selection1 = new GameObject();

            selectionHistory.UpdateSelection(selection1);

            Assert.AreSame(selectionHistory.GetSelection(), selection1);
            Assert.AreEqual(selectionHistory.GetHistoryCount(), 1);
        }
        public void UpdateWithSameSelectionShouldntAddTwiceToHistory()
        {
            var selectionHistory = new SelectionHistory();

            var selection1 = new GameObject();

            selectionHistory.UpdateSelection(selection1);
            selectionHistory.UpdateSelection(selection1);

            Assert.AreSame(selectionHistory.GetSelection(), selection1);
            Assert.AreEqual(selectionHistory.GetHistoryCount(), 1);
        }
Пример #9
0
        public static void SelectionRecorder()
        {
            if (Selection.activeObject != null)
            {
                if (debugEnabled)
                {
                    Debug.Log("Recording new selection: " + Selection.activeObject.name);
                }

                selectionHistory = EditorTemporaryMemory.Instance.selectionHistory;
                selectionHistory.UpdateSelection(Selection.activeObject);
            }
        }
        public void ClearDeletedItemsShouldntSelectIfSelectionDeleted()
        {
            var selectionHistory = new SelectionHistory();

            var selection1 = new GameObject();
            var selection2 = new GameObject();
            var selection3 = new GameObject();

            selectionHistory.UpdateSelection(selection1);
            selectionHistory.UpdateSelection(selection2);
            selectionHistory.UpdateSelection(selection3);

            Assert.IsTrue(selectionHistory.IsSelected(2));
            Assert.That(selectionHistory.GetHistoryCount(), Is.EqualTo(3));

            GameObject.DestroyImmediate(selection3);

            selectionHistory.ClearDeleted();

            Assert.IsFalse(selectionHistory.IsSelected(0));
            Assert.IsFalse(selectionHistory.IsSelected(1));
            Assert.AreEqual(selectionHistory.GetHistoryCount(), 2);
        }