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"); } }
void OnDestroy() { if (!this.accepted && this.node.behaviour != null) { DestroyImmediate(this.node.behaviour.gameObject); } this.node = null; }
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); }
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); }
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 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); } }
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); } }
private void createNewNode(string nodeType) { this.node = new NodeJson(NodeDataManager.NextName(nodeType), Vector3.zero, Vector3.one, "", nodeType); }
private static bool findAndSetParent(NodeJson json, List <NodeBehaviour> currentNodes) { NodeBehaviour b; return(findAndSetParent(json, currentNodes, out b)); }
public QuadCreator(NodeJson json) : base(json) { }
public static bool NodeJsonExist(NodeJson json) { return(Instance.holder.nodes.Any(n => n.name == json.name)); }
public CubeCreator(NodeJson json) : base(json) { }
public void OnEnable() { this.node = null; }
public HoleCreator(NodeJson json) : base(json) { }
public EmptyCreator(NodeJson json) : base(json) { }
public Creator(NodeJson json) { this.name = json.name; this.position = json.position; this.scale = json.scale; }