Beispiel #1
0
 public static void Show(lhTriggerManager.Node node)
 {
     if (m_inspector != null)
     {
         m_inspector = null;
     }
     m_inspector           = ScriptableObject.CreateInstance <lhTriggerPropertyScriptable>();
     m_inspector.hideFlags = UnityEngine.HideFlags.DontSave;
     m_inspector.name      = node.name;
     m_currentNode         = node;
     values = new List <Data>();
     if (node.content != null)
     {
         elements = node.content.Descendants("prop");
         foreach (var item in elements)
         {
             var data = new Data(null, item);
             if (item.Attribute("typeof") != null)
             {
                 data.type = item.Attribute("typeof").Value;
             }
             values.Add(data);
         }
     }
     else
     {
     }
     Selection.activeObject = m_inspector;
 }
Beispiel #2
0
 private void AddSelected(lhTriggerManager.Node node)
 {
     if (!m_selectList.Contains(node))
     {
         m_selectList.Add(node);
         node.isSelected = true;
     }
 }
Beispiel #3
0
 private void AddSingleSelected(lhTriggerManager.Node node)
 {
     foreach (var selNode in m_selectList)
     {
         selNode.isSelected = false;
     }
     m_selectList.Clear();
     m_selectList.Add(node);
     node.isSelected = true;
 }
Beispiel #4
0
        private bool TreeLayout(lhTriggerManager.Node node)
        {
            bool     isSelected  = m_selectList.Contains(node);
            GUIStyle selectStyle = isSelected ? lhGUIStyles.GetStyle("TreeSelectedBlue") : lhGUIStyles.GetStyle("TreeSelectedGrey");

            if (m_isAdd == node)
            {
                selectStyle = lhGUIStyles.GetStyle("TreeAdd");
            }
            if (m_isInsertUp == node)
            {
                selectStyle = lhGUIStyles.GetStyle("TreeInsertUp");
            }
            if (m_isInsertDown == node)
            {
                selectStyle = lhGUIStyles.GetStyle("TreeInsertDown");
            }
            if (isSelected)
            {
                if (m_isControl)
                {
                    if (Event.current.keyCode == KeyCode.D && Event.current.type == EventType.keyUp)
                    {
                        node.Copy();
                        Repaint();
                        return(true);
                    }
                }
            }
            Rect nodeRect = EditorGUILayout.BeginHorizontal(selectStyle);

            {
                GUILayout.Space(20 * node.layer);
                EditorGUILayout.LabelField(node.name);
                if (node.content != null)
                {
                    var    eles  = node.content.Elements("prop");
                    string label = "";
                    int    count = 0;
                    foreach (var item in eles)
                    {
                        label += item.Attribute("name").Value + "=" + item.Value;
                        if (count < eles.Count() - 1)
                        {
                            label += ",";
                        }
                        count++;
                    }
                    GUILayout.Label("(" + label + ")", GUILayout.MaxWidth(999999999));
                }
                GUILayout.FlexibleSpace();
                if (node.layer != 0)
                {
                    if (GUILayout.Button("-", EditorStyles.miniLabel))
                    {
                        node.DeleteOwn();
                        Repaint();
                        return(true);
                    }
                }
            } EditorGUILayout.EndHorizontal();
            GenericMenu menu = new GenericMenu();

            if (node.menulist != null)
            {
                foreach (var item in node.menulist)
                {
                    string name     = item.Attribute("name").Value;
                    string classify = item.Attribute("classify").Value;
                    menu.AddItem(new GUIContent(classify + "/" + name), false, node.AddChild, item);
                }
                menu.AddSeparator("");
                menu.AddItem(new GUIContent("And"), false, node.AddJudge, lhTriggerManager.NodeType.And);
                menu.AddItem(new GUIContent("Or"), false, node.AddJudge, lhTriggerManager.NodeType.Or);
                menu.AddItem(new GUIContent("Not"), false, node.AddJudge, lhTriggerManager.NodeType.Not);
            }
            if (IsMouseOn(nodeRect))
            {
                if (Event.current.button == 1 && Event.current.type == EventType.mouseUp)
                {
                    Vector2 mousePos = Event.current.mousePosition;
                    menu.DropDown(new Rect(mousePos.x, mousePos.y, 0, 0));
                }
                if (Event.current.button == 0)
                {
                    if (Event.current.type == EventType.mouseDown)
                    {
                        if (node.parent != null)
                        {
                            if (Event.current.shift)
                            {
                                AddSelected(node);
                            }
                            else
                            {
                                AddSingleSelected(node);
                            }
                            Repaint();
                            lhTriggerPropertyEditor.Show(node);
                        }
                        if (m_doubleClick == 0)
                        {
                            m_doubleClick = System.DateTime.Now.Millisecond;
                        }
                        else
                        {
                            if (System.DateTime.Now.Millisecond - m_doubleClick < 170)
                            {
                                m_doubleClick = 0;
                                node.ShowPing();
                            }
                        }
                    }
                    if (Event.current.type == EventType.mouseDrag)
                    {
                        if (node.parent != null)
                        {
                            m_dragHandler.PrepareStartDrag(new string[] { }, new Object[] { });
                            m_dragHandler.SetGenericData("Node", node);
                            m_dragHandler.MouseDrag("NodeMove");
                        }
                    }
                    if (Event.current.type == EventType.DragExited)
                    {
                        m_isAdd        = null;
                        m_isInsertUp   = null;
                        m_isInsertDown = null;
                    }
                    if (Event.current.type == EventType.DragUpdated)
                    {
                        var movedNode = (lhTriggerManager.Node)m_dragHandler.GetGenericData("Node");
                        if (movedNode != node && movedNode.nodeClassify == node.nodeClassify)
                        {
                            if (Event.current.mousePosition.y > nodeRect.center.y + nodeRect.height / 3)//down
                            {
                                if (node.parent != null)
                                {
                                    m_isInsertUp   = null;
                                    m_isInsertDown = node;
                                    m_isAdd        = null;
                                }
                                else
                                {
                                    m_isInsertUp   = null;
                                    m_isInsertDown = null;
                                    m_isAdd        = null;
                                }
                            }
                            else if (Event.current.mousePosition.y < nodeRect.center.y - nodeRect.height / 3)//up
                            {
                                if (node.parent != null)
                                {
                                    m_isInsertDown = null;
                                    m_isInsertUp   = node;
                                    m_isAdd        = null;
                                }
                                else
                                {
                                    m_isInsertUp   = null;
                                    m_isInsertDown = null;
                                    m_isAdd        = null;
                                }
                            }
                            else
                            {
                                m_isAdd        = node;
                                m_isInsertUp   = null;
                                m_isInsertDown = null;
                            }
                            m_dragHandler.SetVisualMode(DragAndDropVisualMode.Move);
                            Repaint();
                        }
                    }
                    if (Event.current.type == EventType.DragPerform)
                    {
                        var movedNode = (lhTriggerManager.Node)m_dragHandler.GetGenericData("Node");
                        if (movedNode != node && movedNode.nodeClassify == node.nodeClassify && !movedNode.HasNode(node))
                        {
                            if (Event.current.mousePosition.y > nodeRect.center.y + nodeRect.height / 3) //down
                            {
                                if (node.parent != null)
                                {
                                    movedNode.DeleteOwn();
                                    node.InsertChildDown(movedNode);
                                }
                            }
                            else if (Event.current.mousePosition.y < nodeRect.center.y - nodeRect.height / 3)//up
                            {
                                if (node.parent != null)
                                {
                                    movedNode.DeleteOwn();
                                    node.InsertChildUp(movedNode);
                                }
                            }
                            else
                            {
                                movedNode.DeleteOwn();
                                node.AddChild(movedNode);
                            }
                            m_dragHandler.AcceptDrag();
                            Repaint();
                            m_isInsertUp   = null;
                            m_isInsertDown = null;
                            m_isAdd        = null;
                            return(true);
                        }
                        else
                        {
                            m_isInsertUp   = null;
                            m_isInsertDown = null;
                            m_isAdd        = null;
                        }
                    }
                }
            }
            foreach (var item in node.childList)
            {
                bool repaint = TreeLayout(item);
                if (repaint)
                {
                    return(true);
                }
            }
            return(false);
        }