Exemplo n.º 1
0
        public TreeViewItem(TreeViewControl parentControl, TreeViewItem parent)
        {
            ParentControl = parentControl;
            Parent        = parent;

            if (null == parentControl)
            {
                return;
            }
        }
Exemplo n.º 2
0
        // Use this for initialization
        public void Start()
        {
            m_myTreeView = gameObject.GetComponent <TreeViewControl>();
            if (null == m_myTreeView)
            {
                Debug.LogError("Use the tree view menu to add the control");
                return;
            }

            PopulateExampleData(m_myTreeView);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Add a tree view control to the game object
        /// </summary>
        /// <param name="go"></param>
        public static TreeViewControl AddTreeView(GameObject go)
        {
            if (null == go)
            {
                return(null);
            }

            TreeViewControl item = go.AddComponent <TreeViewControl>();

            AssignDefaults(go);
            return(item);
        }
Exemplo n.º 4
0
        public void OnSceneGUI()
        {
            bool needsRepainted = false;

            if (null != Event.current &&
                m_mousePos != Event.current.mousePosition)
            {
                needsRepainted = true;
            }

            if (null == target &&
                !(target is TreeViewControl))
            {
                Debug.LogError("Not a TreeViewControl");
                return;
            }

            TreeViewControl item = (TreeViewControl)target;

            if (null == item)
            {
                Debug.LogError("TreeViewControl is null");
                return;
            }

            if (!item.DisplayOnScene)
            {
                return;
            }

            item.DisplayTreeView(TreeViewControl.DisplayTypes.USE_SCROLL_AREA);

            if (item.SelectedItem != m_lastSelectedItem)
            {
                m_lastSelectedItem = item.SelectedItem;
                needsRepainted     = true;
            }

            if (needsRepainted)
            {
                Repaint();
                SceneView.RepaintAll();
            }
        }
Exemplo n.º 5
0
        public static bool CheckApplySkin()
        {
            GameObject go = Selection.activeGameObject;

            if (null == go ||
                !(go is GameObject))
            {
                return(false);
            }

            TreeViewControl item = go.GetComponent <TreeViewControl>();

            if (null == item)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 6
0
        public static void PopulateExampleData(TreeViewControl item)
        {
            item.Width  = 600;
            item.Height = 500;
            item.Header = "Example.cs populated this treeview control";
            AddEvents(item.RootItem);
            TreeViewItem item1 = item.RootItem.AddItem("You can also add a tree view control");

            AddEvents(item1);
            AddEvents(item1.AddItem("to any existing game object by"));
            AddEvents(item1.AddItem("selecting the game object and"));
            AddEvents(item1.AddItem("using the menu item"));
            TreeViewItem games = item1.AddItem("TreeView->Add Tree View to selected.", false);

            AddEvents(games);
            AddEvents(games.AddItem("You can also drag and drop the"));
            AddEvents(games.AddItem("TreeViewControl script onto a"));
            AddEvents(games.AddItem("game object."));
            AddEvents(games.AddItem("New checked and", false, true));
            AddEvents(games.AddItem("unchecked checkboxes", false, false));
        }
Exemplo n.º 7
0
 static void CreateTreeView()
 {
     if (null == m_treeViewGO)
     {
         m_treeViewGO = GameObject.Find(GO_NAME);
     }
     if (null != m_treeViewGO)
     {
         m_treeViewControl = m_treeViewGO.GetComponent <TreeViewControl>();
     }
     if (null != m_treeViewControl)
     {
         return;
     }
     m_treeViewGO = new GameObject(GO_NAME);
     Selection.activeGameObject           = m_treeViewGO;
     m_treeViewControl                    = TreeViewInspector.AddTreeView(m_treeViewGO);
     m_treeViewControl.DisplayInInspector = false;
     m_treeViewControl.DisplayOnGame      = false;
     m_treeViewControl.DisplayOnScene     = false;
     Example.PopulateExampleData(m_treeViewControl);
 }
Exemplo n.º 8
0
        public override void OnInspectorGUI()
        {
            if (Application.isPlaying)
            {
                GUILayout.Label("Please avoid editing these fields while playing");
            }

            if (null == target &&
                !(target is TreeViewControl))
            {
                Debug.LogError("Not a TreeViewControl");
                return;
            }

            TreeViewControl item = (TreeViewControl)target;

            if (null == item)
            {
                Debug.LogError("TreeViewControl is null");
                return;
            }

            bool needsRepainted = false;

            if (null != Event.current &&
                m_mousePos != Event.current.mousePosition)
            {
                needsRepainted = true;
            }

            if (item.SelectedItem != m_lastSelectedItem)
            {
                m_lastSelectedItem = item.SelectedItem;
                needsRepainted     = true;
            }

            if (null != item.SelectedItem &&
                string.IsNullOrEmpty(item.SelectedItem.Header))
            {
                item.SelectedItem.Header = "Root item";
                needsRepainted           = true;
            }

            if (GUILayout.Button("Select Root TreeViewItem"))
            {
                item.SelectedItem          = item.RootItem;
                Selection.activeGameObject = item.gameObject;
                needsRepainted             = true;
            }

            if (null != item.SelectedItem &&
                GUILayout.Button("Add Child TreeView Item"))
            {
                item.SelectedItem.AddItem("Default text");
                needsRepainted = true;
            }

            if (null != item.SelectedItem &&
                item.SelectedItem != item.RootItem &&
                null != item.SelectedItem.Parent &&
                GUILayout.Button("Remove TreeView Item"))
            {
                TreeViewItem oldItem = item.SelectedItem;
                item.SelectedItem.Parent.Items.Remove(oldItem);
                item.SelectedItem = null;
                needsRepainted    = true;
            }

            if (null != item.SelectedItem &&
                null != item.SelectedItem.Parent &&
                item.SelectedItem != item.RootItem &&
                item.SelectedItem.Parent.Items.IndexOf(item.SelectedItem) > 0 &&
                GUILayout.Button("Move Up"))
            {
                TreeViewItem oldItem = item.SelectedItem;
                item.SelectedItem = null;
                int index = oldItem.Parent.Items.IndexOf(oldItem);
                oldItem.Parent.Items.Remove(oldItem);
                oldItem.Parent.Items.Insert(index - 1, oldItem);
                item.SelectedItem = oldItem;
                needsRepainted    = true;
            }

            if (null != item.SelectedItem &&
                null != item.SelectedItem.Parent &&
                item.SelectedItem != item.RootItem &&
                (item.SelectedItem.Parent.Items.IndexOf(item.SelectedItem) + 1) < item.SelectedItem.Parent.Items.Count &&
                GUILayout.Button("Move Down"))
            {
                TreeViewItem oldItem = item.SelectedItem;
                item.SelectedItem = null;
                int index = oldItem.Parent.Items.IndexOf(oldItem);
                oldItem.Parent.Items.Remove(oldItem);
                oldItem.Parent.Items.Insert(index + 1, oldItem);
                item.SelectedItem = oldItem;
                needsRepainted    = true;
            }

            if (null != item.SelectedItem &&
                null != item.SelectedItem.Parent &&
                null != item.SelectedItem.Parent.Parent &&
                item.SelectedItem != item.RootItem &&
                item.SelectedItem.Parent != item.RootItem &&
                GUILayout.Button("Promote TreeView Item"))
            {
                TreeViewItem oldItem = item.SelectedItem;
                item.SelectedItem = null;
                oldItem.Parent.Items.Remove(oldItem);
                oldItem.Parent.Parent.Items.Insert(0, oldItem);
                oldItem.Parent    = oldItem.Parent.Parent;
                item.SelectedItem = oldItem;
                needsRepainted    = true;
            }

            EditorGUILayout.Separator();

            if (null != item.SelectedItem)
            {
                EditorGUILayout.LabelField("Parent:", (item.SelectedItem.Parent == null) ? "(null)" : "(valid)");
                EditorGUILayout.LabelField("Parent Control:", (item.SelectedItem.ParentControl == null) ? "(null)" : "(valid)");
            }

            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("***** Selected Item:", "(editable fields) *******");
            if (null != item.SelectedItem)
            {
                if (!string.IsNullOrEmpty(item.SelectedItem.Header))
                {
                    string header = EditorGUILayout.TextField("Header:", item.SelectedItem.Header);
                    if (!item.SelectedItem.Header.Equals(header))
                    {
                        item.SelectedItem.Header = header;
                        needsRepainted           = true;
                    }
                }
                bool isExpanded = EditorGUILayout.Toggle("IsExpanded:", item.SelectedItem.IsExpanded);
                if (isExpanded != item.SelectedItem.IsExpanded)
                {
                    item.SelectedItem.IsExpanded = isExpanded;
                    needsRepainted = true;
                }
                bool isCheckBox = EditorGUILayout.Toggle("IsCheckBox:", item.SelectedItem.IsCheckBox);
                if (isCheckBox != item.SelectedItem.IsCheckBox)
                {
                    item.SelectedItem.IsCheckBox = isCheckBox;
                    needsRepainted = true;
                }
                bool isChecked = EditorGUILayout.Toggle("IsChecked:", item.SelectedItem.IsChecked);
                if (isChecked != item.SelectedItem.IsChecked)
                {
                    item.SelectedItem.IsChecked = isChecked;
                    needsRepainted = true;
                }
            }

            if (needsRepainted)
            {
                Repaint();
                SceneView.RepaintAll();
            }

            base.OnInspectorGUI();

            if (item.DisplayInInspector)
            {
                EditorGUILayout.Separator();
                item.DisplayTreeView(TreeViewControl.DisplayTypes.NONE);
                EditorGUILayout.Separator();
            }
        }