public static void AddNode(NodeJson json)
        {
            if (!Instance.holder.nodes.Contains(json))
            {
                if (NodeJsonExist(json))
                {
                    Debug.LogError("node with name already exist but instances are out of sync");
                }

                Instance.holder.nodes.Add(json);
                if (json.behaviour != null)
                {
                    Instance.nodes.Add(json.behaviour);
                }
                Instance.needSave = true;

                if (onAddNode != null)
                {
                    onAddNode(json);
                }
            }
            else
            {
                Debug.LogWarning("Can not add node already in holder");
            }
        }
Ejemplo n.º 2
0
 void OnDestroy()
 {
     if (!this.accepted && this.node.behaviour != null)
     {
         DestroyImmediate(this.node.behaviour.gameObject);
     }
     this.node = null;
 }
Ejemplo n.º 3
0
        public static NodeBehaviour CreateNode(NodeJson json)
        {
            json.ValidateNodeType();
            var creator = getNodeCreator(json);
            var node    = creator.Create();

            node.json      = json;
            json.behaviour = node;
            return(node);
        }
        public void OnGUI()
        {
            this.container            = EditorGUILayout.ObjectField("container", this.container, typeof(Transform), true) as Transform;
            NodeDataName.DataFileName = EditorGUILayout.TextField("Data File Name", NodeDataName.DataFileName);


            GUI.enabled = this.container != null && !NodeDataManager.IsLoaded && !this.hasCreated;
            if (GUILayout.Button("Create"))
            {
                Debug.Log("Creating new room layout from cubes, old data will be deleted");
                var data = NodeDataLoader.LoadAll(NodeDataName.DataFileName);
                NodeDataManager.Load(NodeDataName.DataFileName, data);
                NodeDataManager.DeleteAll();

                var cubes = this.container.GetComponentsInChildren <Transform>();
                foreach (var cube in cubes)
                {
                    if (cube == this.container)
                    {
                        continue;
                    }
                    if (cube.parent != this.container)
                    {
                        Debug.LogWarning("Container has 2nd level a child that will be ignored"); continue;
                    }

                    var node = new NodeJson(NodeDataManager.NextName(NodeType.CUBE), cube.position, cube.localScale, "", NodeType.CUBE);

                    NodeDataManager.AddNode(node);
                }

                NodeFactory.CreateNodes(NodeDataManager.NodeJsons);

                this.container.gameObject.SetActive(false);
                this.hasCreated = true;
            }
            GUI.enabled = true;
            if (NodeDataManager.IsLoaded)
            {
                GUILayout.Label("Please Unload first");
            }


            GUIHelper.HorizontalLine();
            GUI.skin.label.wordWrap = true;
            GUILayout.Label("** This Action will overrite current data **");
            GUILayout.Label("If you dont want to lose any data please change the data file that is being used");

            GUI.enabled = this.hasCreated;
            if (GUILayout.Button("Save"))
            {
                NodeDataLoader.SaveAll(NodeDataManager.SaveFilePath(), NodeDataManager.SaveDataHolder());
            }
            GUI.enabled = true;
        }
 public static void RemoveNode(NodeJson node)
 {
     if (Instance.holder.nodes.Contains(node))
     {
         Instance.holder.nodes.Remove(node);
         Instance.needSave = true;
     }
     else
     {
         Debug.LogWarning(string.Format("Can not remove '{0}', it is not in holder", node.name));
     }
 }
        private static void cutHole(Vector3 pos, Vector3 sca, Transform wall)
        {
            var position = calculateHolePosition(pos, wall);
            var scale = calculateHoleScale(sca, wall);

            var parentScale = getParentScale(wall);
            var scaledPos = NodeHelper.InverseScale(position, parentScale);
            var scaledSca = NodeHelper.InverseScale(scale, parentScale);

            var hole = new NodeJson(wall.name, scaledPos, scaledSca, "", NodeType.HOLE);

            NodeDataManager.AddNode(hole);
            NodeFactory.CreateNode(hole);
        }
Ejemplo n.º 7
0
        public NodeJson ToJson()
        {
            if (this.json == null)
            {
                var parentName = this.HasParent ? this.parent.name : "";
                this.json = new NodeJson(this.name, this.transform.localPosition, this.GetScale(), parentName, this.nodeType);
            }
            else
            {
                this.UpdateJson();
            }

            return(this.json);
        }
Ejemplo n.º 8
0
        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);
            }
        }
Ejemplo n.º 9
0
        private static NodeCreator.Creator getNodeCreator(NodeJson json)
        {
            switch (json.nodeType)
            {
            case NodeType.EMPTY:
                return(new NodeCreator.EmptyCreator(json));

            case NodeType.CUBE:
                return(new NodeCreator.CubeCreator(json));

            case NodeType.HOLE:
                return(new NodeCreator.HoleCreator(json));

            case NodeType.QUAD:
                return(new NodeCreator.QuadCreator(json));

            default:
                throw new System.Exception("Node type not found: " + json.nodeType);
            }
        }
Ejemplo n.º 10
0
        public void UpdateFromJson(NodeJson updatedJson)
        {
            if (updatedJson == null)
            {
                return;
            }

            this.name = updatedJson.name;
            this.transform.localPosition = updatedJson.position;
            if (this.GetScale() != updatedJson.scale)
            {
                var newScale = NodeHelper.InverseScale(updatedJson.scale, this.GetScale());
                this.transform.localScale = newScale;
                NodeHelper.NormaliseScale(this);
            }

            var parentName = this.HasParent ? this.parent.name : "";

            if (updatedJson.parentName != parentName)
            {
                var newParent = updatedJson.parentName == "" ? RootParent : NodeDataManager.FindNode(updatedJson.parentName);
                this.ChangeParent(newParent);
            }
        }
Ejemplo n.º 11
0
 private void createNewNode(string nodeType)
 {
     this.node = new NodeJson(NodeDataManager.NextName(nodeType), Vector3.zero, Vector3.one, "", nodeType);
 }
Ejemplo n.º 12
0
        private static bool findAndSetParent(NodeJson json, List <NodeBehaviour> currentNodes)
        {
            NodeBehaviour b;

            return(findAndSetParent(json, currentNodes, out b));
        }
Ejemplo n.º 13
0
 public QuadCreator(NodeJson json) : base(json)
 {
 }
 public static bool NodeJsonExist(NodeJson json)
 {
     return(Instance.holder.nodes.Any(n => n.name == json.name));
 }
Ejemplo n.º 15
0
 public CubeCreator(NodeJson json) : base(json)
 {
 }
Ejemplo n.º 16
0
 public void OnEnable()
 {
     this.node = null;
 }
Ejemplo n.º 17
0
 public HoleCreator(NodeJson json) : base(json)
 {
 }
Ejemplo n.º 18
0
 public EmptyCreator(NodeJson json) : base(json)
 {
 }
Ejemplo n.º 19
0
 public Creator(NodeJson json)
 {
     this.name     = json.name;
     this.position = json.position;
     this.scale    = json.scale;
 }