Exemplo n.º 1
0
        public virtual void DeSerialize(XmlElement root)
        {
            DeSerializeField(root, "name", ref m_name);
            DeSerializeField(root, "rotateAngle", ref rotateAngle);
            DeSerializeField(root, "rotateOffset", ref rotateOffset);
            DeSerializeField(root, "color", ref color);
            DeSerializeField(root, "contentColor", ref contentColor);
            DeSerializeField(root, "backgroundColor", ref backgroundColor);
            DeSerializeField(root, "active", ref m_active);
            DeSerializeField(root, "enable", ref m_enable);
            calculator.DeSerialize(root.SelectSingleNode("RectCalculator") as XmlElement);
            children.Clear();
            XmlElement ele = root.SelectSingleNode("children") as XmlElement;

            for (int i = 0; i < ele.ChildNodes.Count; i++)
            {
                XmlElement child = ele.ChildNodes[i] as XmlElement;
                Type       type  = GUINodes.nodeTypes.Find((tmp) =>
                {
                    return(tmp.Name == child.GetAttribute("ElementType"));
                });
                GUINode element = Activator.CreateInstance(type, null) as GUINode;
                element.DeSerialize(child);
                element.parent = this;
            }
        }
Exemplo n.º 2
0
 public GUINode Find(string path)
 {
     if (children.Count == 0)
     {
         return(null);
     }
     if (!path.Contains("/"))
     {
         for (int i = 0; i < children.Count; i++)
         {
             GUINode tmp = children[i] as GUINode;
             if (tmp.name == path)
             {
                 return(tmp);
             }
         }
         return(null);
     }
     else
     {
         int    index = path.IndexOf("/");
         string tmp   = path.Substring(0, index);
         path = path.Substring(index + 1);
         for (int i = 0; i < children.Count; i++)
         {
             GUINode tmpE = children[i] as GUINode;
             if (tmpE.name == tmp)
             {
                 return(tmpE.Find(path));
             }
         }
         return(null);
     }
 }
Exemplo n.º 3
0
        protected void BeginGUI()
        {
            preSkin         = GUI.skin;
            preContentColor = GUI.contentColor;
            preBgColor      = GUI.backgroundColor;
            preColor        = GUI.color;
            preMat4x4       = GUI.matrix;
            preEnable       = GUI.enabled;

            GUI.color           = color;
            GUI.backgroundColor = backgroundColor;
            GUI.contentColor    = contentColor;
            Vector2 tmp = new Vector2(rotateOffset.x * position.width, rotateOffset.y * position.height);

            GUIUtility.RotateAroundPivot(rotateAngle, position.center + tmp);

            bool bo = this.enable;

            if (bo)
            {
                GUINode d = this;
                while (d.parent != null)
                {
                    d  = d.parent;
                    bo = d.enable && bo;
                    if (!bo)
                    {
                        break;
                    }
                }
            }
            GUI.enabled = bo;
        }
            private void OnCeateElement(Type type)
            {
                GUINode copy = Activator.CreateInstance(type) as GUINode;

                this.element.Node(copy);
                //copy.parent = this.element;
                //tree.OnTreeChange();
            }
            protected virtual void OnCtrlD()
            {
                if (this.element.GetType() == typeof(GUICanvas))
                {
                    return;
                }
                GUINode copy = Activator.CreateInstance(this.element.GetType(), this.element) as GUINode;

                (this.element.parent as GUINode).Node(copy);
            }
Exemplo n.º 6
0
        public static void SaveXmlPrefab(this GUINode e, string path)
        {
            XmlDocument doc = new XmlDocument();
            XmlElement  ele = doc.CreateElement("Element_Prefab");

            ele.SetAttribute("Type", e.GetType().Name);
            ele.AppendChild(e.Serialize(doc));
            doc.AppendChild(ele);
            doc.Save(path);
        }
Exemplo n.º 7
0
        public static T Node <T>(this T t, GUINode element) where T : GUINode
        {
            element.parent = t;
            GUICanvas canvas = element.root as GUICanvas;

            if (canvas != null)
            {
                canvas.TreeChange();
            }
            return(t);
        }
Exemplo n.º 8
0
        private void EleGUI(GUINode ele)
        {
            GUINodeEditor des = dic[ele.GetType()];

            des.element = ele;
            des.OnSceneGUI(() => {
                for (int i = 0; i < ele.Children.Count; i++)
                {
                    EleGUI(ele.Children[i] as GUINode);
                }
            });
        }
Exemplo n.º 9
0
        public static void LoadXmlPrefab(this GUINode e, string path)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(path);
            if (doc.DocumentElement.Name != "Element_Prefab")
            {
                return;
            }
            string  attr    = doc.DocumentElement.GetAttribute("Type");
            Type    type    = GUINodes.nodeTypes.Find((t) => { return(t.Name == attr); });
            GUINode element = Activator.CreateInstance(type) as GUINode;

            element.DeSerialize(doc.FirstChild.FirstChild as XmlElement);
            e.Node(element);
        }
            public Trunk(Trunk parent, GUINode element)
            {
                this.element         = element;
                this.parent          = parent;
                nameLabel            = new RenameLabelDrawer();
                nameLabel.value      = element.name;
                nameLabel.onEndEdit += (str) => { element.name = str.Trim(); };

                children = new List <Trunk>();
                if (element.Children.Count > 0)
                {
                    for (int i = 0; i < element.Children.Count; i++)
                    {
                        children.Add(new Trunk(this, element.Children[i] as GUINode));
                    }
                }
            }
Exemplo n.º 11
0
 protected GUINode(GUINode other)
 {
     m_name          = other.m_name;
     m_enable        = other.m_enable;
     m_active        = other.m_active;
     rotateAngle     = other.rotateAngle;
     rotateOffset    = other.rotateOffset;
     color           = other.color;
     contentColor    = other.contentColor;
     backgroundColor = other.backgroundColor;
     this.calculator = new RectCalculator(other.calculator);
     for (int i = 0; i < other.children.Count; i++)
     {
         GUINode element = other.children[i] as GUINode;
         GUINode copy    = Activator.CreateInstance(element.GetType(), other.children[i]) as GUINode;
         copy.parent = this;
     }
 }
            protected virtual void OnCtrlV()
            {
                if (GUINodeSelection.copyNode == null)
                {
                    return;
                }
                GUINode copy = Activator.CreateInstance(GUINodeSelection.copyNode.GetType(), GUINodeSelection.copyNode) as GUINode;

                if (this.element.GetType() != typeof(GUICanvas))
                {
                    (this.element.parent as GUINode).Node(copy);
                }
                else
                {
                    (this.element as GUINode).Node(copy);
                }
                GUINodeSelection.copyNode = null;
            }
            private void MouseDragEve(Rect r, Rect sf, /*Rect tr,*/ Rect br, Event e)
            {
                bool    CouldPutdown = r.Contains(e.mousePosition) && GUINodeSelection.dragNode != null && GUINodeSelection.dragNode != this.element;
                GUINode tmp          = this.element;

                while (tmp.parent != null)
                {
                    tmp = tmp.parent;
                    if (tmp == GUINodeSelection.dragNode)
                    {
                        CouldPutdown = false;
                        break;
                    }
                }
                if (CouldPutdown)
                {
                    if (sf.Contains(e.mousePosition))
                    {
                        GUI.Box(sf, "", "SelectionRect");
                    }
                    //else if (tr.Contains(e.mousePosition))
                    //{
                    //    if (!(element is GUICanvas))
                    //        GUI.Box(new Rect(tr.x, tr.y - SingleLineHeight, tr.width, SingleLineHeight), "", "PR Insertion");
                    //}
                    else if (br.Contains(e.mousePosition))
                    {
                        if (!(element is GUICanvas))
                        {
                            GUI.Box(sf, "", "PR Insertion");
                        }
                    }
                }
                if (CouldPutdown && e.type == EventType.MouseUp)
                {
                    if (sf.Contains(e.mousePosition))
                    {
                        this.element.Node(GUINodeSelection.dragNode);
                    }
                    //else if (tr.Contains(e.mousePosition))
                    //{
                    //    if (!(element is GUICanvas))
                    //    {
                    //        ElementSelection.dragElement.parent = this.element.parent;
                    //        element.parent.Children.Remove(ElementSelection.dragElement);
                    //        element.parent.Children.Insert(element.siblingIndex /*- 1*/, ElementSelection.dragElement);
                    //        dragTrunk.parent = this.parent;
                    //        parent.children.Remove(dragTrunk);
                    //        parent.children.Insert(element.siblingIndex /*- 1*/, dragTrunk);
                    //    }

                    //}
                    else if (br.Contains(e.mousePosition))
                    {
                        if (!(element is GUICanvas))
                        {
                            (this.element.parent as GUINode).Node(GUINodeSelection.dragNode);
                            GUINodeSelection.dragNode.siblingIndex = element.siblingIndex + 1;
                        }
                    }

                    GUINodeSelection.dragNode = null;
                }
                else if (GUINodeSelection.node == this.element)
                {
                    if (e.type == EventType.MouseDrag)
                    {
                        GUINodeSelection.dragNode = GUINodeSelection.node;
                    }
                    else if (e.type == EventType.MouseUp)
                    {
                        GUINodeSelection.dragNode = null;
                    }
                }
            }
            public void OnCanvasTreeGUI(Rect rect, Event e)
            {
                bool active = element.active;

                if (active)
                {
                    GUINode ele = element;
                    while (ele.parent != null)
                    {
                        ele    = ele.parent;
                        active = active && ele.active;
                        if (!active)
                        {
                            break;
                        }
                    }
                }
                GUI.enabled = active;


                var  rs       = rect.HorizontalSplit(LineHeight);
                Rect selfRect = rs[0];

                if (GUINodeSelection.node == this.element && e.type == EventType.Repaint)
                {
                    new GUIStyle("SelectionRect").Draw(selfRect, false, false, false, false);
                }
                selfRect.xMin += 20 * element.depth;
                Rect childrenRect = rs[1];

                childrenRect.xMin += 20 * element.depth;

                //Rect topR = new Rect(selfRect.position, new Vector2(selfRect.width, gapHeight));
                Rect sf   = new Rect(selfRect.position, new Vector2(selfRect.width, SingleLineHeight));
                Rect butR = new Rect(new Vector2(selfRect.x, selfRect.yMin + SingleLineHeight), new Vector2(selfRect.width, gapHeight));

                if (children.Count > 0)
                {
                    var rss = sf.VerticalSplit(12);
                    foldOn = EditorGUI.Foldout(rss[0], foldOn, "", false);
                    nameLabel.OnGUI(rss[1]);
                    //GUI.Label(rss[1], element.name);
                    if (tree.HandleEve)
                    {
                        Eve(selfRect, rss[1], /*topR,*/ butR, e);
                    }
                    if (!foldOn)
                    {
                        return;
                    }
                    float y = 0;
                    for (int i = 0; i < children.Count; i++)
                    {
                        Rect r = new Rect(rect.x, childrenRect.y + y, rect.width, children[i].Height);
                        y += children[i].Height;
                        children[i].OnCanvasTreeGUI(r, e);
                    }
                }
                else
                {
                    nameLabel.OnGUI(sf);

                    //GUI.Label(sf, element.name);
                    if (tree.HandleEve)
                    {
                        Eve(selfRect, sf, /*topR,*/ butR, e);
                    }
                }
                GUI.enabled = true;
            }