public void TwinePromptGUI() { // get list of twine nodes we need prompts for, the keys of our dictionary AssociatedTwineNodes associatedNodes = this.prompt.gameObject.GetComponent <AssociatedTwineNodes> (); List <string> twineNodeNames = new List <string> (); foreach (GameObject twineNodeObject in associatedNodes.associatedTwineNodeObjects) { TwineNode twineNode = twineNodeObject.GetComponent <TwineNode> (); twineNodeNames.Add(twineNode.name); } // special case: if only one twine node - use the basic input if (twineNodeNames.Count == 1) { // use the simple prompt GUI without allowing for cycles EditorGUI.BeginChangeCheck(); SimplePromptGUI(cyclicAllowed: false); if (EditorGUI.EndChangeCheck()) { // bind the result from simple GUI back to the twine based key prompt.twinePrompts.Set(twineNodeNames[0], prompt.firstPrompt); // since this is effectivally a reflection of the data modified, we do // not need to create a seperate undo event } // do not fall through into the dictionary input return; } EditorGUILayout.LabelField("Twine Prompts:"); // build dictionary and get a value for each key foreach (string nodeName in twineNodeNames) { string previousValue = this.prompt.twinePrompts.ValueForKey(nodeName); if (previousValue == null) { previousValue = ""; // default to empty string } GUIContent label = new GUIContent(nodeName, "Text displayed when a player can progress the story to this twine node."); EditorGUI.BeginChangeCheck(); string newPromptText = EditorGUILayout.TextField(label, previousValue); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(prompt, "Change Prompt"); this.prompt.twinePrompts.Set(nodeName, newPromptText); } } }
/// <summary> /// Search the game objects associated with the Twine node (associatedTwineNodes), and gather their indices /// relative to the allNodes list. /// </summary> /// <returns>The selected indices from object list.</returns> /// <param name="associatedTwineNodes">The associated twine nodes component being edited.</param> /// <param name="allNodes">All Twine nodes in the scene.</param> private List <int> GetSelectedIndicesFromObjectList(AssociatedTwineNodes associatedTwineNodes, TwineNode[] allNodes) { List <int> selectedTwineNodeIndices = new List <int> (); for (int i = 0; i < associatedTwineNodes.associatedTwineNodeObjects.Count; i++) { GameObject nodeObject = associatedTwineNodes.associatedTwineNodeObjects [i]; for (int j = 0; j < allNodes.Length; j++) { TwineNode node = allNodes [j]; if (node.gameObject == nodeObject) { selectedTwineNodeIndices.Add(j); } } } return(selectedTwineNodeIndices); }
// check if the current object has an active twine node public bool isAssociatedTwineNodeActive() { AssociatedTwineNodes nodes = this.gameObject.GetComponent <AssociatedTwineNodes>(); if (nodes == null) { return(false); } // sanity check foreach (GameObject twineNodeObject in nodes.associatedTwineNodeObjects) { TwineNode twineNode = twineNodeObject.GetComponent <TwineNode> (); if (twineNode.enabled) { return(true); } } return(false); }
// ---- TWINE PROMPT ---- // returns the twine node this prompt which is currently active public TwineNode GetActiveAssociatedTwineNode() { AssociatedTwineNodes nodes = this.gameObject.GetComponent <AssociatedTwineNodes>(); if (nodes == null) { return(null); } // sanity check foreach (GameObject twineNodeObject in nodes.associatedTwineNodeObjects) { TwineNode twineNode = twineNodeObject.GetComponent <TwineNode> (); if (twineNode.HasActiveParentNode()) { return(twineNode); } } // no active twine node was found return(null); }
public void Awake() { this.associatedTwineNodes = (AssociatedTwineNodes)target; }