public bool comprobarInteraccio(GameObject origen) { DialogCameraScript DCScript = GameObject.Find("DialogLayout").GetComponent <DialogCameraScript>(); Debug.Log("Origen de combinacio: " + origen); ConversationNodeClass nodeALlencar = defaultNode; if (objecteBo == origen) { return(true); } else { foreach (erronis erroni in objectesErronis) { foreach (GameObject objecte in erroni.objectes) { if (objecte == origen) { nodeALlencar = erroni.frase; DCScript.NextNode = nodeALlencar; DCScript.enabled = true; return(false); } } } DCScript.NextNode = nodeALlencar; DCScript.enabled = true; return(false); } }
bool IsAnySelected(ConversationNodeClass Node) { for (int i=0; i<Node.cncArray.Length; i++){ if (Node.cncArray[i].bIsSelected) return true; } return false; }
bool IsAnySelected(ConversationNodeClass Node) { for (int i = 0; i < Node.cncArray.Length; i++) { if (Node.cncArray[i].bIsSelected) { return(true); } } return(false); }
public override void OnInspectorGUI() { //GUI.changed = false; cnc.ShowNode = (ConversationNodeClass.show)EditorGUILayout.EnumPopup("Show Node", cnc.ShowNode); switch (cnc.ShowNode) { case ConversationNodeClass.show.ALWAYS: //cnc.var = GUILayout.Toggle(false,"Variable"); break; case ConversationNodeClass.show.IF: case ConversationNodeClass.show.IF_NOT: //cnc.var = GUILayout.Toggle(true,"Variable"); cnc.var = EditorGUILayout.TextField("Variable", cnc.var); break; } cnc.sFirstOption = EditorGUILayout.TextField("sFirstOption", cnc.sFirstOption); cnc.sSecondOption = EditorGUILayout.TextField("sSecondOption", cnc.sSecondOption); cnc.cCharacter = (ConversationNodeClass.costume)EditorGUILayout.EnumPopup("cCharacter", cnc.cCharacter); cnc.sSpeaker = (ConversationNodeClass.speaker)EditorGUILayout.EnumPopup("sSpeaker", cnc.sSpeaker); cnc.fSeconds = EditorGUILayout.FloatField("fSeconds", cnc.fSeconds); //cnc.bIsEnabled = EditorGUILayout.Toggle ("IsEnabled", cnc.bIsEnabled); //cnc.sNextAction = EditorGUILayout.TextField("sNextAction",cnc.sNextAction); //cnc.GOApplied = (GameObject)EditorGUILayout.ObjectField ("GOApplied", cnc.GOApplied, typeof(GameObject),true); cnc.showNodes = EditorGUILayout.Foldout(cnc.showNodes, "Nodes"); if (cnc.showNodes) { int size = EditorGUILayout.IntField("Size", cnc.cncArray.Length); ConversationNodeClass[] aux = new ConversationNodeClass[size]; for (int i = 0; i < size - 1; i++) { if (i < cnc.cncArray.Length) { aux[i] = (ConversationNodeClass)EditorGUILayout.ObjectField("Node " + i, cnc.cncArray[i], typeof(ConversationNodeClass), true); } else { aux[i] = (ConversationNodeClass)EditorGUILayout.ObjectField("Node " + i, null, typeof(ConversationNodeClass), true); } } cnc.cncArray = aux; } if (GUI.changed) { EditorUtility.SetDirty(cnc); } //cnc.fSeconds = EditorGUILayout.FloatField ("fSeconds", cnc.fSeconds); //cnc.cncArray = EditorGUILayout.ObjectField("cncArray",cnc.cncArray,typeof(ConversationNodeClass[]),true); }
public override void OnInspectorGUI() { //GUI.changed = false; cnc.ShowNode = (ConversationNodeClass.show)EditorGUILayout.EnumPopup("Show Node",cnc.ShowNode); switch (cnc.ShowNode) { case ConversationNodeClass.show.ALWAYS: //cnc.var = GUILayout.Toggle(false,"Variable"); break; case ConversationNodeClass.show.IF: case ConversationNodeClass.show.IF_NOT: //cnc.var = GUILayout.Toggle(true,"Variable"); cnc.var = EditorGUILayout.TextField("Variable",cnc.var); break; } cnc.sFirstOption = EditorGUILayout.TextField("sFirstOption",cnc.sFirstOption); cnc.sSecondOption = EditorGUILayout.TextField("sSecondOption",cnc.sSecondOption); cnc.cCharacter = (ConversationNodeClass.costume)EditorGUILayout.EnumPopup ("cCharacter", cnc.cCharacter); cnc.sSpeaker = (ConversationNodeClass.speaker)EditorGUILayout.EnumPopup ("sSpeaker", cnc.sSpeaker); cnc.fSeconds = EditorGUILayout.FloatField ("fSeconds", cnc.fSeconds); //cnc.bIsEnabled = EditorGUILayout.Toggle ("IsEnabled", cnc.bIsEnabled); //cnc.sNextAction = EditorGUILayout.TextField("sNextAction",cnc.sNextAction); //cnc.GOApplied = (GameObject)EditorGUILayout.ObjectField ("GOApplied", cnc.GOApplied, typeof(GameObject),true); cnc.showNodes = EditorGUILayout.Foldout (cnc.showNodes, "Nodes"); if(cnc.showNodes) { int size = EditorGUILayout.IntField("Size",cnc.cncArray.Length); ConversationNodeClass[] aux = new ConversationNodeClass[size]; for (int i = 0 ; i < size-1;i++) { if(i<cnc.cncArray.Length) aux[i] = (ConversationNodeClass)EditorGUILayout.ObjectField("Node "+i, cnc.cncArray[i], typeof(ConversationNodeClass), true); else aux[i] = (ConversationNodeClass)EditorGUILayout.ObjectField("Node "+i, null, typeof(ConversationNodeClass), true); } cnc.cncArray = aux; } if(GUI.changed) EditorUtility.SetDirty(cnc); //cnc.fSeconds = EditorGUILayout.FloatField ("fSeconds", cnc.fSeconds); //cnc.cncArray = EditorGUILayout.ObjectField("cncArray",cnc.cncArray,typeof(ConversationNodeClass[]),true); }
public GameObject GetRootNode() { GameObject parent = transform.parent.gameObject; if (parent.GetComponent <ConversationTreeClass>()) { return(parent); } else if (parent.GetComponent <ConversationNodeClass>()) { ConversationNodeClass cnc = parent.GetComponent <ConversationNodeClass>(); return(cnc.GetRootNode()); } else { Debug.LogError("[ConversationNodeClass] No NodeClass o TreeClass in parent object"); } return(null); }
void Awake() { cnc = (ConversationNodeClass)target; }
void OnGUI() { ConversationNodeClass curNode = NextNode; if (curNode == null) { return; } if (curNode.cncArray.Length == 0) { Debug.Log("Now we are supposed to leave"); //check if any action to do //if (curNode.sNextAction!=null){ // BroadcastMessage(curNode.sNextAction, curNode.GOApplied); //} //sortir PreviousNode = null; Debug.Log(Camera.current); if (CCScript.IsIn()) { CCScript.TransferOut(); } this.enabled = false; } if (PreviousNode == null) { GUI.Button(new Rect(0.005f * Screen.width, 0.01f * Screen.height, 0.24f * Screen.width, 0.22f * Screen.height), curNode.sFirstOption, style_alien); if (gettime < curNode.fSeconds) { //curNode.cncArray [0].bIsSelected = false; //NextNode = curNode.cncArray [0]; gettime += Time.deltaTime; return; } else { gettime = 0; } } int length = 0; // for (int i=0; i<curNode.cncArray.Length; i++) { // switch(curNode.cncArray[i].ShowNode){ // case ConversationNodeClass.show.ALWAYS:length++;break; // case ConversationNodeClass.show.IF : break; // //if(gs.GetVariable(curNode.cncArray[i].var)) // } // } //Automatic dialog (only one option) if (curNode.cncArray.Length == 1) { if (curNode.cncArray [0].sSpeaker == ConversationNodeClass.speaker.ALIEN) { GUI.Button(new Rect(0.005f * Screen.width, 0.01f * Screen.height, 0.24f * Screen.width, 0.22f * Screen.height), curNode.cncArray [0].sFirstOption, style_alien); if (!curNode.cncArray [0].bIsSelected) { Debug.Log("Automatic Button1"); gettime = Time.time; curNode.cncArray [0].bIsSelected = true; } else { if (gettime + curNode.fSeconds < Time.time) { curNode.cncArray [0].bIsSelected = false; NextNode = curNode.cncArray [0]; gettime = 0; } } //selected } else if (curNode.cncArray [0].sSpeaker == ConversationNodeClass.speaker.THEOTHER) { GUI.Button(new Rect(0.74f * Screen.width, 0.05f * Screen.height, 0.24f * Screen.width, 0.22f * Screen.height), curNode.cncArray [0].sFirstOption, style_theother); if (!curNode.cncArray [0].bIsSelected) { Debug.Log("Automatic Other"); gettime = Time.time; curNode.cncArray [0].bIsSelected = true; } else { if (gettime + curNode.fSeconds < Time.time) { curNode.cncArray [0].bIsSelected = false; NextNode = curNode.cncArray [0]; gettime = 0; } } //selected } //alien or the other } //single option //TODO: set as single when selected??? if (curNode.cncArray.Length > 1) { if (!IsAnySelected(curNode)) { if (GUI.Button(new Rect(0.005f * Screen.width, 0.01f * Screen.height, 0.24f * Screen.width, 0.22f * Screen.height), curNode.cncArray[0].sFirstOption, style_think)) { Debug.Log("Button1"); gettime = Time.time; curNode.cncArray[0].bIsSelected = true; } } else //node selected { if (curNode.cncArray[0].bIsSelected) { GUI.Button(new Rect(0.005f * Screen.width, 0.01f * Screen.height, 0.24f * Screen.width, 0.22f * Screen.height), curNode.cncArray[0].sFirstOption, style_alien); if (gettime + curNode.fSeconds < Time.time) { curNode.cncArray[0].bIsSelected = false; NextNode = curNode.cncArray[0]; gettime = 0; } } } //Button1 if (!IsAnySelected(curNode)) { if (GUI.Button(new Rect(0.25f * Screen.width, 0.05f * Screen.height, 0.24f * Screen.width, 0.22f * Screen.height), curNode.cncArray[1].sFirstOption, style_think)) { Debug.Log("Button2"); gettime = Time.time; curNode.cncArray[1].bIsSelected = true; } } else //node selected { if (curNode.cncArray[1].bIsSelected) { GUI.Button(new Rect(0.005f * Screen.width, 0.01f * Screen.height, 0.24f * Screen.width, 0.22f * Screen.height), curNode.cncArray [1].sFirstOption, style_alien); if (gettime + curNode.fSeconds < Time.time) { curNode.cncArray[1].bIsSelected = false; NextNode = curNode.cncArray[1]; gettime = 0; } } } //Button2 } //2 options if (curNode.cncArray.Length > 2) { if (!IsAnySelected(curNode)) { if (GUI.Button(new Rect(0.495f * Screen.width, 0.01f * Screen.height, 0.24f * Screen.width, 0.22f * Screen.height), curNode.cncArray[2].sFirstOption, style_think)) { Debug.Log("Button3"); gettime = Time.time; curNode.cncArray[2].bIsSelected = true; } } else //node selected { if (curNode.cncArray[2].bIsSelected) { GUI.Button(new Rect(0.005f * Screen.width, 0.01f * Screen.height, 0.24f * Screen.width, 0.22f * Screen.height), curNode.cncArray [2].sFirstOption, style_alien); if (gettime + curNode.fSeconds < Time.time) { curNode.cncArray [2].bIsSelected = false; NextNode = curNode.cncArray[2]; gettime = 0; } } } } //3 options if (curNode.cncArray.Length > 3) { if (!IsAnySelected(curNode)) { if (GUI.Button(new Rect(0.74f * Screen.width, 0.05f * Screen.height, 0.24f * Screen.width, 0.22f * Screen.height), curNode.cncArray[3].sFirstOption, style_think)) { Debug.Log("Button4"); gettime = Time.time; curNode.cncArray[3].bIsSelected = true; } } else //node selected { if (curNode.cncArray[3].bIsSelected) { GUI.Button(new Rect(0.005f * Screen.width, 0.01f * Screen.height, 0.24f * Screen.width, 0.22f * Screen.height), curNode.cncArray [3].sFirstOption, style_alien); if (gettime + curNode.fSeconds < Time.time) { curNode.cncArray [3].bIsSelected = false; NextNode = curNode.cncArray[3]; gettime = 0; } } } } //4 options PreviousNode = curNode; } //OnGui
void OnGUI() { ConversationNodeClass curNode = NextNode; if (curNode == null) return; if (curNode.cncArray.Length==0){ Debug.Log ("Now we are supposed to leave"); //check if any action to do //if (curNode.sNextAction!=null){ // BroadcastMessage(curNode.sNextAction, curNode.GOApplied); //} //sortir PreviousNode = null; Debug.Log(Camera.current); if(CCScript.IsIn()) CCScript.TransferOut(); this.enabled = false; } if (PreviousNode == null) { GUI.Button (new Rect (0.005f * Screen.width, 0.01f * Screen.height, 0.24f * Screen.width, 0.22f * Screen.height), curNode.sFirstOption, style_alien); if (gettime < curNode.fSeconds) { //curNode.cncArray [0].bIsSelected = false; //NextNode = curNode.cncArray [0]; gettime +=Time.deltaTime; return; } else{ gettime =0; } } int length = 0; // for (int i=0; i<curNode.cncArray.Length; i++) { // switch(curNode.cncArray[i].ShowNode){ // case ConversationNodeClass.show.ALWAYS:length++;break; // case ConversationNodeClass.show.IF : break; // //if(gs.GetVariable(curNode.cncArray[i].var)) // } // } //Automatic dialog (only one option) if (curNode.cncArray.Length == 1) { if (curNode.cncArray [0].sSpeaker == ConversationNodeClass.speaker.ALIEN) { GUI.Button (new Rect (0.005f * Screen.width, 0.01f * Screen.height, 0.24f * Screen.width, 0.22f * Screen.height), curNode.cncArray [0].sFirstOption, style_alien); if (!curNode.cncArray [0].bIsSelected) { Debug.Log ("Automatic Button1"); gettime = Time.time; curNode.cncArray [0].bIsSelected = true; }else{ if (gettime + curNode.fSeconds < Time.time) { curNode.cncArray [0].bIsSelected = false; NextNode = curNode.cncArray [0]; gettime = 0; } }//selected } else if (curNode.cncArray [0].sSpeaker == ConversationNodeClass.speaker.THEOTHER) { GUI.Button (new Rect (0.74f * Screen.width, 0.05f * Screen.height, 0.24f * Screen.width, 0.22f * Screen.height), curNode.cncArray [0].sFirstOption, style_theother); if (!curNode.cncArray [0].bIsSelected) { Debug.Log ("Automatic Other"); gettime = Time.time; curNode.cncArray [0].bIsSelected = true; } else { if (gettime + curNode.fSeconds < Time.time) { curNode.cncArray [0].bIsSelected = false; NextNode = curNode.cncArray [0]; gettime = 0; } }//selected }//alien or the other }//single option //TODO: set as single when selected??? if(curNode.cncArray.Length>1){ if(!IsAnySelected(curNode)){ if (GUI.Button (new Rect (0.005f*Screen.width, 0.01f*Screen.height, 0.24f*Screen.width, 0.22f*Screen.height), curNode.cncArray[0].sFirstOption, style_think)){ Debug.Log ("Button1"); gettime = Time.time; curNode.cncArray[0].bIsSelected = true; } }else{ //node selected if(curNode.cncArray[0].bIsSelected){ GUI.Button (new Rect (0.005f * Screen.width, 0.01f * Screen.height, 0.24f * Screen.width, 0.22f * Screen.height), curNode.cncArray[0].sFirstOption, style_alien); if (gettime + curNode.fSeconds < Time.time) { curNode.cncArray[0].bIsSelected = false; NextNode = curNode.cncArray[0]; gettime = 0; } } }//Button1 if(!IsAnySelected(curNode)){ if (GUI.Button (new Rect (0.25f*Screen.width, 0.05f*Screen.height, 0.24f*Screen.width, 0.22f*Screen.height), curNode.cncArray[1].sFirstOption, style_think)){ Debug.Log ("Button2"); gettime = Time.time; curNode.cncArray[1].bIsSelected = true; } }else{ //node selected if(curNode.cncArray[1].bIsSelected){ GUI.Button (new Rect (0.005f * Screen.width, 0.01f * Screen.height, 0.24f * Screen.width, 0.22f * Screen.height), curNode.cncArray [1].sFirstOption, style_alien); if (gettime + curNode.fSeconds < Time.time) { curNode.cncArray[1].bIsSelected = false; NextNode = curNode.cncArray[1]; gettime = 0; } } }//Button2 }//2 options if(curNode.cncArray.Length>2){ if(!IsAnySelected(curNode)){ if (GUI.Button (new Rect (0.495f*Screen.width, 0.01f*Screen.height, 0.24f*Screen.width, 0.22f*Screen.height), curNode.cncArray[2].sFirstOption, style_think)){ Debug.Log ("Button3"); gettime = Time.time; curNode.cncArray[2].bIsSelected = true; } }else{ //node selected if(curNode.cncArray[2].bIsSelected){ GUI.Button (new Rect (0.005f * Screen.width, 0.01f * Screen.height, 0.24f * Screen.width, 0.22f * Screen.height), curNode.cncArray [2].sFirstOption, style_alien); if (gettime + curNode.fSeconds < Time.time) { curNode.cncArray [2].bIsSelected = false; NextNode = curNode.cncArray[2]; gettime = 0; } } } }//3 options if(curNode.cncArray.Length>3){ if(!IsAnySelected(curNode)){ if (GUI.Button (new Rect (0.74f*Screen.width, 0.05f*Screen.height, 0.24f*Screen.width, 0.22f*Screen.height), curNode.cncArray[3].sFirstOption, style_think)){ Debug.Log ("Button4"); gettime = Time.time; curNode.cncArray[3].bIsSelected = true; } }else{ //node selected if(curNode.cncArray[3].bIsSelected){ GUI.Button (new Rect (0.005f * Screen.width, 0.01f * Screen.height, 0.24f * Screen.width, 0.22f * Screen.height), curNode.cncArray [3].sFirstOption, style_alien); if (gettime + curNode.fSeconds < Time.time) { curNode.cncArray [3].bIsSelected = false; NextNode = curNode.cncArray[3]; gettime = 0; } } } }//4 options PreviousNode = curNode; }