Esempio n. 1
0
 public void RemoveChild(NodeBehaviour child)
 {
     Debug.Assert(child.parent == this, "childs parent is not this");
     this.children.Remove(child);
     child.parent = null;
     NodeHelper.SetParentKeepLocals(child.transform, null);
 }
Esempio n. 2
0
            public override NodeBehaviour Create()
            {
                var oldWall = this.getOldWall();

                var newWall = new EmptyCreator(oldWall.ToJson()).Create();

                newWall.transform.localRotation = oldWall.transform.localRotation;
                newWall.SetParent(oldWall.Parent);
                NodeBehaviour.MoveNodeChildren(oldWall, newWall);

                newWall.nodeType = NodeType.HOLE;

                var top    = createWallPart(" top", oldWall, newWall);
                var bottom = createWallPart(" bottom", oldWall, newWall);
                var right  = createWallPart(" right", oldWall, newWall);
                var left   = createWallPart(" left", oldWall, newWall);

                updateTop(top);
                updateBot(bottom);
                updateRight(right);
                updateLeft(left);

                this.fixHoleOutSideOfQuad(top, bottom, right, left);

                this.deleteNode(oldWall);

                return(newWall);
            }
Esempio n. 3
0
 public void AddChild(NodeBehaviour child)
 {
     Debug.Assert(child.parent == null, "child already has a parent");
     this.children.Add(child);
     child.parent = this;
     NodeHelper.SetParentKeepLocals(child.transform, child.parent.transform);
 }
 private void changeParentMenu(NodeBehaviour node)
 {
     if (this.showChangeParent)
     {
         GUIHelper.HorizontalLine();
         GUILayout.Label("Change Parent");
         GUI.enabled = false;
         EditorGUILayout.ObjectField("Current Parent", node.Parent, typeof(NodeBehaviour), true);
         GUI.enabled    = true;
         this.newParent = EditorGUILayout.ObjectField("New Parent", this.newParent, typeof(NodeBehaviour), true) as NodeBehaviour;
         GUILayout.BeginHorizontal();
         if (GUILayout.Button("Accept Parent"))
         {
             if (this.validateNewParent(node, this.newParent))
             {
                 node.ChangeParent(this.newParent);
             }
             this.resetChangeParent();
         }
         if (GUILayout.Button("Cancel"))
         {
             this.resetChangeParent();
         }
         GUILayout.EndHorizontal();
         GUIHelper.HorizontalLine();
     }
     else
     {
         if (GUILayout.Button("Change Parent"))
         {
             this.showChangeParent = true;
         }
     }
 }
Esempio n. 5
0
 public static void MoveNodeChildren(NodeBehaviour oldNode, NodeBehaviour newNode)
 {
     foreach (var child in oldNode.children)
     {
         newNode.children.Add(child);
         child.parent = newNode;
     }
 }
Esempio n. 6
0
            private NodeBehaviour createWallPart(string nodeName, NodeBehaviour oldWall, NodeBehaviour parent)
            {
                var node = new QuadCreator(oldWall.ToJson()).Create();

                node.SetParent(parent);
                node.name   = this.name + nodeName;
                node.noJson = true;

                return(node);
            }
Esempio n. 7
0
 private void regularNodeGUI()
 {
     GUI.enabled = false;
     EditorGUILayout.TextField("name", this.node.name);
     GUI.enabled          = true;
     this.node.position   = EditorGUILayout.Vector3Field("position", this.node.position);
     this.node.scale      = EditorGUILayout.Vector3Field("scale", this.node.scale);
     this.parent          = EditorGUILayout.ObjectField("parent", this.parent, typeof(NodeBehaviour), true) as NodeBehaviour;
     this.node.parentName = this.parent != null ? this.parent.name : "";
 }
Esempio n. 8
0
 public bool HasChild(NodeBehaviour checkChild)
 {
     foreach (var child in this.children)
     {
         if (child == checkChild)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 9
0
        private void holeNodeGUI()
        {
            this.parent = EditorGUILayout.ObjectField("target", this.parent, typeof(NodeBehaviour), true) as NodeBehaviour;

            if (this.parent != null)
            {
                this.node.name = this.parent.name;
            }
            GUI.enabled = false;
            EditorGUILayout.TextField("name", this.node.name);
            GUI.enabled        = true;
            this.node.position = EditorGUILayout.Vector3Field("position", this.node.position);
            this.node.scale    = EditorGUILayout.Vector3Field("scale", this.node.scale);
        }
Esempio n. 10
0
 public bool HasDescendant(NodeBehaviour checkChild)
 {
     if (this.HasChild(checkChild))
     {
         return(true);
     }
     foreach (var child in this.children)
     {
         if (child.HasDescendant(checkChild))
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 11
0
            private void fixHoleOutSideOfQuad(NodeBehaviour top, NodeBehaviour bot, NodeBehaviour right, NodeBehaviour left)
            {
                if (top != null && top.transform.localScale.y < 0)
                {
                    var extraScale = top.transform.localScale.y;

                    if (right != null)
                    {
                        right.transform.localPosition += Vector3.up * (extraScale / 2f);
                        right.transform.localScale    += Vector3.up * (extraScale);
                    }
                    if (left != null)
                    {
                        left.transform.localPosition += Vector3.up * (extraScale / 2f);
                        left.transform.localScale    += Vector3.up * (extraScale);
                    }

                    UnityEngine.Object.DestroyImmediate(top.gameObject);
                }
                if (bot != null && bot.transform.localScale.y < 0)
                {
                    var extraScale = bot.transform.localScale.y;

                    if (right != null)
                    {
                        right.transform.localPosition -= Vector3.up * (extraScale / 2f);
                        right.transform.localScale    += Vector3.up * (extraScale);
                    }
                    if (left != null)
                    {
                        left.transform.localPosition -= Vector3.up * (extraScale / 2f);
                        left.transform.localScale    += Vector3.up * (extraScale);
                    }

                    UnityEngine.Object.DestroyImmediate(bot.gameObject);
                }


                if (left != null && left.transform.localScale.x < 0)
                {
                    UnityEngine.Object.DestroyImmediate(left.gameObject);
                }
                if (right != null && right.transform.localScale.x < 0)
                {
                    UnityEngine.Object.DestroyImmediate(right.gameObject);
                }
            }
Esempio n. 12
0
        public static void NormaliseScale(NodeBehaviour node)
        {
            if (node == null || node.GetScale() == Vector3.one)
            {
                return;
            }

            foreach (var child in node.Children)
            {
                child.transform.localScale    = NodeHelper.Scale(child.transform.localScale, node.transform.localScale);
                child.transform.localPosition = NodeHelper.Scale(child.transform.localPosition, node.transform.localScale);

                if (child.ScaleFromChild)
                {
                    NormaliseScale(child);
                }
            }
            node.transform.localScale = Vector3.one;
        }
Esempio n. 13
0
            private void updateTop(NodeBehaviour node)
            {
                var w = node.transform;

                w.localRotation = Quaternion.identity;
                var startScale = w.localScale;
                var holeTop    = this.position.y + this.scale.y / 2;
                var hs         = w.localScale.y / 2;

                var s2 = hs - holeTop;
                var p2 = (hs + holeTop) / 2;

                w.localPosition = new Vector3(0, p2, 0);
                w.localScale   += new Vector3(0, s2 - hs * 2, 0);

                w.localPosition = NodeHelper.InverseScale(w.localPosition, startScale);
                w.localScale    = NodeHelper.InverseScale(w.localScale, startScale);

                if (Mathf.Abs(s2) < SMALLEST_WALL)
                {
                    this.deleteNode(node);
                }
            }
        private bool validateNewParent(NodeBehaviour node, NodeBehaviour newParent)
        {
            if (node == newParent)
            {
                Debug.LogError("new parent is this node");
                return(false);
            }

            if (node.Parent == newParent)
            {
                Debug.LogError("new parent is already this nodes parent");
                return(false);
            }

            if (node.HasDescendant(newParent))
            {
                Debug.LogError("new parent is a descendant of this node");
                return(false);
            }


            return(true);
        }
Esempio n. 15
0
            private void updateLeft(NodeBehaviour node)
            {
                var w = node.transform;

                w.localRotation = Quaternion.identity;
                var startScale = w.localScale;
                var holeLeft   = this.position.x - this.scale.x / 2;
                var hs         = w.localScale.x / 2;

                var s2 = hs + holeLeft;
                var p2 = (-hs + holeLeft) / 2;

                w.localPosition = new Vector3(p2, this.position.y, 0);
                w.localScale   += new Vector3(s2 - hs * 2, this.scale.y - w.localScale.y, 0);

                w.localPosition = NodeHelper.InverseScale(w.localPosition, startScale);
                w.localScale    = NodeHelper.InverseScale(w.localScale, startScale);

                if (Mathf.Abs(s2) < SMALLEST_WALL)
                {
                    this.deleteNode(node);
                }
            }
 public static void NodeDisabled(NodeBehaviour node)
 {
     Instance.nodes.Remove(node);
 }
 public static void NodeEnabled(NodeBehaviour node)
 {
     Instance.nodes.Add(node);
 }
Esempio n. 18
0
            private NodeBehaviour createQuad(string nameDirection, Vector3 pos, Vector3 sca, Quaternion rot, NodeBehaviour parent)
            {
                var creator = new QuadCreator(string.Format("{0} {1}", this.name, nameDirection), NodeHelper.Scale(pos, this.scale / 2), sca)
                {
                    rotation = rot
                };
                var node = creator.Create();

                node.SetParent(parent);
                node.noJson = true;
                return(node);
            }
Esempio n. 19
0
 public void ChangeParent(NodeBehaviour newParent)
 {
     this.RemoveParent();
     this.SetParent(newParent);
 }
Esempio n. 20
0
 private void deleteNode(NodeBehaviour node)
 {
     node.Parent.RemoveChild(node);
     UnityEngine.Object.DestroyImmediate(node.gameObject);
 }
Esempio n. 21
0
 public void SetParent(NodeBehaviour parent)
 {
     Debug.Assert(this.parent == null, "this already has a parent");
     parent.AddChild(this);
 }
Esempio n. 22
0
 protected abstract void setNodeType(NodeBehaviour node);
Esempio n. 23
0
 protected override void setNodeType(NodeBehaviour node)
 {
     node.nodeType = NodeType.HOLE;
 }
        private static bool findAndSetParent(NodeJson json, List <NodeBehaviour> currentNodes, out NodeBehaviour node)
        {
            var parentExist = currentNodes.Any(n => n.name == json.parentName);

            if (parentExist)
            {
                node = CreateNode(json);
                var parent = currentNodes.Find(n => n.name == json.parentName);
                node.SetParent(parent);

                return(true);
            }
            else
            {
                node = null;
                return(false);
            }
        }
 private void resetChangeParent()
 {
     this.showChangeParent = false;
     this.newParent        = null;
 }