private void OnClickAddNode(Vector2 mousePosition) { if (nodes == null) { nodes = new List <Node>(); } Rect _rect = new Rect(mousePosition.x, mousePosition.y, nodeWidth, nodeHeight); nodes.Add(new Node(_rect, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, titleStyle, OnClickRemoveNode, this, (highestID + 1))); highestID++; GameObject nodeObject = new GameObject(); nodeObject.name = "Generated_Node_" + (highestID); nodeObject.tag = "NarrativeTrigger"; nodeObject.transform.parent = nodesParent.transform; nodeObject.AddComponent <BoxCollider>(); nodeObject.AddComponent <TriggerNodeInfo>(); nodeObject.GetComponent <BoxCollider>().size = new Vector3(10, 10, 1); nodeObject.GetComponent <BoxCollider>().isTrigger = true; TriggerNodeInfo script = nodeObject.GetComponent <TriggerNodeInfo>(); Node currentNode = nodes[nodes.Count - 1]; script.SaveTriggerData(currentNode.rect, currentNode.ID, currentNode.title, currentNode.showAudio, currentNode.playedAudioClips, currentNode.delays, null, currentNode.pathType, currentNode.scrollViewVector, currentNode.worldPosition); sceneItems.Add(script); }
public void LoadTriggerInfo(TriggerNodeInfo trig) { if (trig.ID != 1) { trig.gameObject.SetActive(false); inactiveTriggers.Add(trig); } else { trig.gameObject.SetActive(true); trig.hasBeenActivated = true; activeTriggers.Add(trig); } }
public void EnableTriggers(List <int> triggerIDs) { if (activeTriggers.Count > 0) { DisableAllTriggers(); } foreach (int id in triggerIDs) { TriggerNodeInfo foundTrigger = inactiveTriggers.Find(x => x.ID == id); if (!foundTrigger.hasBeenActivated) { foundTrigger.gameObject.SetActive(true); foundTrigger.hasBeenActivated = true; activeTriggers.Add(foundTrigger); inactiveTriggers.Remove(foundTrigger); } } }
private void SaveData() { foreach (Node _node in nodes) { TriggerNodeInfo script = sceneItems.Where(t => t.ID == _node.ID).First(); GameObject obj = script.gameObject; obj.name = "Generated_Node_" + script.ID; //The name shows the node ID to make it easier. List <Vector2> v2Cons = null; if (_node.nodeCons.Count > 0) { v2Cons = new List <Vector2>(); foreach (Connection con in _node.nodeCons) { v2Cons.Add(new Vector2(con.inPoint.ID, con.outPoint.ID)); } } script.SaveTriggerData(_node.rect, _node.ID, _node.title, _node.showAudio, _node.playedAudioClips, _node.delays, v2Cons, _node.pathType, _node.scrollViewVector, _node.worldPosition); } ConnectionsManager conManager = GetConnectionManager(); List <ConnectionInfo> conList = new List <ConnectionInfo>(); foreach (Connection con in connections) { conList.Add(new ConnectionInfo(con.inPoint.ID, con.outPoint.ID, con.connectionType)); } conManager.SaveConnections(conList); //When the nodes and connections get saved, save the scene too to make sure everything is saved. string[] path = EditorSceneManager.GetActiveScene().path.Split(char.Parse("/")); path[path.Length - 1] = path[path.Length - 1]; bool saveOK = EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene(), string.Join("/", path)); Debug.Log("Saved the Nodes and the Scene " + (saveOK ? "Sucessfully" : "Error!")); nextSave = (float)EditorApplication.timeSinceStartup + saveTime; }
private void LoadData() { //Objects can only be loaded when the have the correct tag. List <GameObject> loadedObjects = GameObject.FindGameObjectsWithTag("NarrativeTrigger").ToList(); List <GameObject> objectsToRemove = new List <GameObject>(); //The triggers need a parent in the scene, that way it does not get messy in the scene. (This can be changed to a different tag etc). nodesParent = GameObject.FindGameObjectWithTag("ObjectsParent"); if (nodesParent == null) { nodesParent = new GameObject(); nodesParent.name = "GeneratedTriggers"; nodesParent.tag = "ObjectsParent"; } //Every gamobject that gets loaded in must have a TriggerNodeInfo script. Otherwise there's no data to be loaded. foreach (GameObject obj in loadedObjects) { TriggerNodeInfo tempScript = obj.GetComponent <TriggerNodeInfo>(); if (tempScript != null) { sceneItems.Add(tempScript); } else { objectsToRemove.Add(obj); } } if (objectsToRemove.Count > 0) { Debug.LogWarning("WARNING: Some gameobjects with the tag NarrativeTrigger don't have a TriggerNodeInfo script. Please fix or remove those!"); } if (nodes == null) { nodes = new List <Node>(); } //For every node we load in the data and create a new node. foreach (TriggerNodeInfo info in sceneItems) { Node tempNode = new Node(info.rect, nodeStyle, selectedNodeStyle, inPointStyle, outPointStyle, titleStyle, OnClickRemoveNode, this, nodesCreated); //We need to update the highest node id to make sure we dont get duplicate IDs. if (info.ID > highestID) { highestID = info.ID; } tempNode.ID = info.ID; tempNode.title = info.stepDescription; tempNode.showAudio = info.showAudio; tempNode.playedAudioClips = info.playedAudioClips; tempNode.delays = info.delays; tempNode.pathType = info.pathType; tempNode.scrollViewVector = info.scrollViewVector; tempNode.worldPosition = info.transform.position; nodes.Add(tempNode); nodesCreated++; } //We need the ConnectionManager to load in the connecitions between nodes. ConnectionsManager conManager = GetConnectionManager(); List <ConnectionInfo> connectionsToRemove = new List <ConnectionInfo>(); if (connections == null) { connections = new List <Connection>(); } if (nodes.Count > 0) { if (conManager.connections != null) { foreach (ConnectionInfo info in conManager.connections) { bool bothNodesExist = false; Node inPoint = nodes.Where(t => t.ID == info.inPointID).First(); Node outPoint = nodes.Where(t => t.ID == info.outPointID).First(); Connection tempCon = new Connection(inPoint, outPoint, info.connectionType, OnClickRemoveConnection); if (inPoint != null && outPoint != null) { bothNodesExist = true; } else { connectionsToRemove.Add(info); } if (bothNodesExist) { //The connection needs to be added to both nodes (This way, in the game it knows which node(s) it needs to enable) and the connection list. inPoint.AddNewConnection(tempCon); outPoint.AddNewConnection(tempCon); connections.Add(tempCon); } } } } else { //if there are no nodes, we need to clear the connections connectionsToRemove = conManager.connections; } if (connectionsToRemove != null) { if (connectionsToRemove.Count > 0) { foreach (ConnectionInfo inf in connectionsToRemove) { conManager.connections.Remove(inf); } connectionsToRemove.Clear(); } } }