private void Awake() { if (instance != null) { Destroy(gameObject); return; } instance = this; if (m_textMesh == null) { m_textMesh = GetComponent <TextMeshPro>(); } if (m_textMesh == null) { Debug.LogErrorFormat("Must set (or have) text mesh in {0}. Destroying.", name); Destroy(gameObject); return; } m_textMesh.enableWordWrapping = true; m_textMesh.gameObject.AddComponent <SortingOrder>().sortingName = "Text"; if (m_portraitLabel == null) { Debug.LogErrorFormat("Must set text mesh in {0} for speaker. Destroying.", name); Destroy(gameObject); return; } m_portraitLabel.gameObject.AddComponent <SortingOrder>().sortingName = "Text"; IsFullPageRevealed = false; Clear(); }
private void Awake() { dialogueScript = dialogueContainer.GetComponent <DialogueWindow>(); exhaustedDialogue = false; dialogueScript.ConnectWithManager(this); currentLineIndex = -1; }
//[ATK] Elysian Emblem [SUPP] You may choose 1 ally other than your attacking unit, and move them. public override void ActivateAttackSupportSkill() { //Checks that there is more than one ally in play. if (Owner.FieldCards.Count > 1) { //check if the player wants to activate Crodelia's skill. Call a dialogue box. DialogueWindowDetails details = new DialogueWindowDetails { windowTitleText = "Elysian Emblem", questionText = "Would you like to activate " + CharName + "'s Elysian Emblem?" + "\n\n[ATK] Elysian Emblem [SUPP] You may choose one ally that is not the attacking unit, and move it.", button1Details = new DialogueButtonDetails { buttonText = "Yes", buttonAction = () => { TargetElysianEmblem(); } }, button2Details = new DialogueButtonDetails { buttonText = "No", buttonAction = () => { GameManager.instance.ActivateDefenderSupport(); } } }; DialogueWindow dialogueWindow = DialogueWindow.Instance(); dialogueWindow.MakeChoice(details); } else { GameManager.instance.ActivateDefenderSupport(); } }
//[ATK] Elysian Emblem [SUPP] Choose 1 ally other than your attacking unit. You may move that ally. public static void ElysianEmblem() { //Checks that there is more than one other ally besides the attacking card in play. if (GameManager.instance.CurrentAttacker.OtherAllies.Count > 0) { //check if the player wants to activate this skill. Call a dialogue box. DialogueWindowDetails details = new DialogueWindowDetails { windowTitleText = "Elysian Emblem", questionText = "Would you like to activate the supported " + GameManager.instance.CurrentAttacker.Owner.SupportCard.CharName + "'s Elysian Emblem?" + "\n\n[ATK] Elysian Emblem [SUPP] Choose 1 ally other than your attacking unit. You may move that ally.", button1Details = new DialogueButtonDetails { buttonText = "Yes", buttonAction = () => { TargetElysianEmblem(); } }, button2Details = new DialogueButtonDetails { buttonText = "No", buttonAction = () => { GameManager.instance.ActivateDefenderSupport(); } } }; DialogueWindow dialogueWindow = DialogueWindow.Instance(); dialogueWindow.MakeChoice(details); } else { GameManager.instance.ActivateDefenderSupport(); } }
// Use this for initialization void Start() { runes = transform.GetComponentsInChildren <SpriteRenderer>(); dw = FindObjectOfType <DialogueWindow>(); shaman = FindObjectOfType <Shaman>(); portal = FindObjectOfType <SpawnPortal>(); }
// Use this for initialization void Start() { animator = GetComponent <Animator>(); dw = FindObjectOfType <DialogueWindow>(); shaman = FindObjectOfType <Shaman>(); audio = GetComponent <AudioSource>(); }
private void Start() { dw = FindObjectOfType <DialogueWindow>(); exclamation = GetComponentInChildren <Exclamation>(); soulCounter = FindObjectOfType <SoulCounter>(); Debug.Log("Exclamation: " + exclamation); }
private void ShowEditMenu(ChoiceData choice, int index) { GUI.FocusControl(null); var menu = new GenericMenu(); menu.AddItem(new GUIContent("View"), false, () => { Selection.activeObject = choice; }); menu.AddItem(new GUIContent("Move Up"), false, () => { _callbacks.Push(() => { MoveChoice(choice, index, -1); DialogueWindow.SaveGraph(); }); }); menu.AddItem(new GUIContent("Move Down"), false, () => { _callbacks.Push(() => { MoveChoice(choice, index, 1); DialogueWindow.SaveGraph(); }); }); menu.AddSeparator(""); menu.AddItem(new GUIContent("Delete"), false, () => { _graveyard.Add(_data.choices[index]); }); menu.ShowAsContext(); }
//deploys a card on the field //should only be called by the ContextMenu buttons and so doesn't do any checks on location, etc. public void DeployToFieldFromHand(BasicCard card) { //Update the used bonds before anything changes on the board. GameManager.instance.bondDeployCount += card.DeploymentCost; //remove the card from the hand. Hand.Remove(card); //We need to know where to deploy this card. Call a dialogue box. DialogueWindowDetails details = new DialogueWindowDetails { windowTitleText = "Deployment", questionText = "Where would you like to deploy " + card.CharName + "?", button1Details = new DialogueButtonDetails { buttonText = "Front Line", buttonAction = () => { DeployToFrontLine(card); } }, button2Details = new DialogueButtonDetails { buttonText = "Back Line", buttonAction = () => { DeployToBackLine(card); } } }; DialogueWindow dialogueWindow = DialogueWindow.Instance(); dialogueWindow.MakeChoice(details); }
public static void Open(Dialogue d, DialogueSystemWindow dsw) { DialogueWindow window = (DialogueWindow)EditorWindow.GetWindow( typeof(DialogueWindow)); window.Initialize(d, dsw); window.Show(); }
public bool DoInteract() { if (DialogueWindow.TalkWith(this)) { SetMachineState <CharacterTalkingState>(); return(true); } return(false); }
public ChoiceCollection(NodeEditorBase node, NodeDataChoiceBase data, DialogueWindow window) { _window = window; _node = node; _data = data; _serializedData = new SerializedObject(data); _propChoices = _serializedData.FindProperty("choices"); RebuildChoices(); }
static void Initialise() { window = (DialogueWindow)EditorWindow.GetWindow(typeof(DialogueWindow)); window.Show(); allResponses = new List <ResponseScript>(); playerResponses = new List <ResponseScript>(); npcResponses = new List <ResponseScript>(); xmlWriter = GameObject.Find("XMLObject").GetComponent <XMLWriter>(); dialogueScript = GameObject.Find("XMLObject").GetComponent <DialogueScript>(); window.AddNewNPCResponse(); }
public void InitializeUI(List <Team> teams) { CorrespondingTeams = teams; GamemodeUiBase.InitializeTeamBasedUI(teamPanels); gameEndPanel = Instantiate(gameEndPanelPreFab.gameObject, FindObjectOfType <Canvas>().transform).GetComponent <DialogueWindow>(); gameEndPanel.gameObject.SetActive(false); // TODO: spawn round end screen Debug.Log("<color=green>Gamemode Ui Initialized: Team Deathmatch</color>"); }
private void Start() { cavemanStartPos = transform.position; enabledCaveman = GetComponent <EnabledCaveman>(); rebirth = FindObjectOfType <Rebirth>(); health = startHealth; runes = FindObjectOfType <ActivateRunes>(); sprite = GetComponent <SpriteRenderer>(); dw = FindObjectOfType <DialogueWindow>(); life = FindObjectOfType <Life_Counter>(); audio = GetComponent <AudioSource>(); }
public static DialogueWindow Instance() { if (!dialogueWindow) { dialogueWindow = FindObjectOfType(typeof(DialogueWindow)) as DialogueWindow; if (!dialogueWindow) { Debug.LogError("There needs to be one active DialogueWindow script on a GameObject in your scene."); } } return(dialogueWindow); }
public void ShowTalkMenu(DragonNPC npc) { Time.timeScale = 0f; this.dialogueWindow = this.container.InstantiatePrefab(this.dialgueWindowPrefab); this.dialogueWindow.transform.SetParent(this.canvas.transform, false); this.dialogueWindow.GetComponent <RectTransform> ().localPosition = new Vector3(0.0f, 0.0f, 0.0f); this.dialogueWindow.transform.localScale = new Vector3(1, 1, 1); DialogueWindow window = this.dialogueWindow.GetComponent <DialogueWindow> (); window.gameController = this; window.dialog = npc.GetDialog(); window.dialog.Start(); }
public override void OnInspectorGUI() { DrawDefaultInspector(); if (GUILayout.Button("Spell Check")) { RunSpellCheck(); } if (GUILayout.Button("Edit Dialogue")) { DialogueWindow.ShowGraph(target as DialogueGraph); } }
public void InitializeUI(List <Team> teams) { CorrespondingTeams = teams; GamemodeUiBase.InitializeNonTeamBasedUI(teamPanels); gameEndPanel = Instantiate(gameEndPanelPreFab.gameObject, FindObjectOfType <Canvas>().transform).GetComponent <DialogueWindow>(); gameEndPanel.gameObject.SetActive(false); roundEndPanel = Instantiate(roundEndPanelPreFab.gameObject, FindObjectOfType <Canvas>().transform).GetComponent <DialogueWindow>(); roundEndPanel.gameObject.SetActive(false); Debug.Log("<color=green>Gamemode Ui Initialized: All vs. All</color>"); }
public void Setup(DialogueWindow window, NodeDataBase data) { Window = window; Data = data; _styles = new NodeStyles(NodeColor); Data.rect.width = NodeWidth; serializedObject = new SerializedObject(data); CreateConnection(ConnectionType.Out, data, true); Out[0].Hide = !HasOutConnection; CreateConnection(ConnectionType.In, data, true); In[0].Hide = !HasInConnection; OnSetup(); }
public void ShowContextMenu() { if (Type == ConnectionType.In) { return; } var menu = new GenericMenu(); menu.AddItem( new GUIContent("Clear Connections"), false, () => { Undo.RecordObject(_childCollection as Object, "Clear connections"); Links.ClearAllLinks(); _childCollection.ClearConnectionChildren(); DialogueWindow.SaveGraph(); }); menu.ShowAsContext(); }
//[Formation Skill] Bord, Cord, and Barst [TRIGGER] [Tap allied "Bord" and "Cord"] //When this unit attacks, you may pay the cost, and if you do: //Until the end of this combat, this unit gains +50 attack and the number of Orbs that this unit's attack will destroy becomes 2. //Ensures the conditions are met to activate the formation skill and then asks the player if they want to activate that ability. private void CheckFormationSkill(bool attacking) { //check that this unit is attacking and that there are other allies. if (attacking && OtherAllies.Count >= 1) { //check if Bord is deployed List <BasicCard> otherAllies = OtherAllies; int b = otherAllies.FindIndex(ally => ally.CompareNames("Bord")); if (b >= 0) { //check if Cord is deployed int c = otherAllies.FindIndex(ally => ally.CompareNames("Cord")); if (c >= 0) { //confirm Bord and Cord are both untapped. if (!otherAllies[b].Tapped && !otherAllies[c].Tapped) { //conditions met; call a dialogue box to confirm if the player wants to use Formation Skill. DialogueWindowDetails details = new DialogueWindowDetails { windowTitleText = "Formation Skill", questionText = "Would you like to activate Barst's Formation Skill?" + "\n\n[Formation Skill] Bord, Cord, and Barst [TRIGGER] [Tap allied \"Bord\" and \"Cord\"] When this unit attacks, you may pay the cost, and if you do: Until the end of this combat, this unit gains +50 attack and the number of Orbs that this unit's attack will destroy becomes 2.", button1Details = new DialogueButtonDetails { buttonText = "Yes", buttonAction = () => { FormationSkill(otherAllies[b], otherAllies[c]); } }, button2Details = new DialogueButtonDetails { buttonText = "No", buttonAction = () => { Debug.Log("No Formation Skill. :("); } } }; DialogueWindow dialogueWindow = DialogueWindow.Instance(); dialogueWindow.MakeChoice(details); } } } } }
public bool PlayAnimationSequence(AnimationIndex index, DialogueWindow.CharacterTexture characterTexture) { NPCAnimations.AnimationSequence playerAnim = RetrieveAnimationSequence(index); List<Texture> playerTex = playerAnim.textures; if (playerTex.Count > 0) { characterTexture.animation.StopAnimation(); characterTexture.animation.SetAnimationList(playerTex); characterTexture.animation.PlayAnimation(); characterTexture.animation.SetSpeed(playerAnim.speed); characterTexture.stretch.initialSize = new Vector2 (playerTex[0].width, playerTex[0].height); return true; } else { Debug.LogError("No texures were found for index " + index.ToString()); return false; } }
//Green-Red Twin Strike [TRIGGER] [Tap an allied "Cain"] When this unit attacks, you may pay the cost and if you do: Until the end of this combat, this unit gains +40 attack. //Ensures the conditions are met to make a twin strike and then asks the player if they want to activate that ability. private void CheckTwinStrike(bool attacking) { //check that this unit is attacking. if (attacking) { //Check that there are other allies. if (OtherAllies.Count >= 1) { //check if Cain is deployed List <BasicCard> otherAllies = OtherAllies; int n = otherAllies.FindIndex(ally => ally.CompareNames("Cain")); if (n >= 0) { //confirm Cain is untapped. if (!otherAllies[n].Tapped) { //conditions met; call a dialogue box to confirm if the player wants to use Green-Red Twin Strike. DialogueWindowDetails details = new DialogueWindowDetails { windowTitleText = "Green-Red Twin Strike", questionText = "Would you like to activate Abel's Green-Red Twin Strike?" + "\n\nGreen-Red Twin Strike [TRIGGER] [Tap an allied \"Cain\"] When this unit attacks, you may pay the cost and if you do: Until the end of this combat, this unit gains +40 attack.", button1Details = new DialogueButtonDetails { buttonText = "Yes", buttonAction = () => { GreenRedTwinStrike(otherAllies[n]); } }, button2Details = new DialogueButtonDetails { buttonText = "No", buttonAction = () => { Debug.Log("No Green-Red Twin Strike. :("); } } }; DialogueWindow dialogueWindow = DialogueWindow.Instance(); dialogueWindow.MakeChoice(details); } } } } }
// Update is called once per frame void Update() { fwd = transform.TransformDirection(Vector3.forward); int layerMask = 1 << 8; layerMask = ~layerMask; if (Physics.Raycast(transform.position, fwd, out hit, range, layerMask)) { DialogueActor actor = hit.transform.gameObject.GetComponent <DialogueActor>(); if (actor != null) { StoryObject.SendMessage("ActivateTalk", actor.actorName); } else { StoryObject.SendMessage("NoTalk"); } } if (Input.GetKeyDown(KeyCode.E)) { if (lastPressed + 0.2f < Time.time) { lastPressed = Time.time; if (Physics.Raycast(transform.position, fwd, out hit, range, layerMask)) { if (hit.distance < range) { if (hit.collider is CapsuleCollider) { DialogueWindow window = hit.transform.gameObject.GetComponent(typeof(DialogueWindow)) as DialogueWindow; //Debug.Log(actor.actorName); window.OnTalkPrompt(); } } } } } }
//calls the dialogue box for the player to choose to use Warning Shot. public override void ActivateTriggerSkill(BasicCard triggeringCard) { DialogueWindowDetails details = new DialogueWindowDetails { windowTitleText = "Gordin's Warning Shot", questionText = "Would you like to activate Gordin's skill?" + "\n\nWarning Shot [TRIGGER] When you deploy an ally with a Deployment Cost 2 or less, you may choose 1 <Flier> enemy, and move them.", button1Details = new DialogueButtonDetails { buttonText = "Yes", buttonAction = () => { ChooseWSTarget(); }, }, button2Details = new DialogueButtonDetails { buttonText = "No", buttonAction = () => { Owner.deployTriggerTracker.RecheckTrigger(); }, } }; DialogueWindow dialogueWindow = DialogueWindow.Instance(); dialogueWindow.MakeChoice(details); }
//calls the dialogue box for the player to choose to use Prince of Light. public override void ActivateTriggerSkill(BasicCard triggeringCard) { DialogueWindowDetails details = new DialogueWindowDetails { windowTitleText = "Marth's Prince of Light", questionText = "Would you like to activate Marth's skill?" + "\n\nPrince of Light [TRIGGER] [ONCE PER TURN] When you deploy an ally with a Deployment Cost 2 or lower, you may choose 1 enemy in the Back Line, and move them.", button1Details = new DialogueButtonDetails { buttonText = "Yes", buttonAction = () => { ChooseHoLTarget(); }, }, button2Details = new DialogueButtonDetails { buttonText = "No", buttonAction = () => { Owner.deployTriggerTracker.RecheckTrigger(); }, } }; DialogueWindow dialogueWindow = DialogueWindow.Instance(); dialogueWindow.MakeChoice(details); }
/* * 0. need two windows - Dialogue/DialogueSystem * 1. ds- load every dialogue, present them in a scrollview with an open button * 2. dw- textare for lines, + de * if there's none, create */ void OnGUI() { List <Dialogue> ds = dialogueHolder.dialogues; Dialogue toRemove = null; GUILayout.BeginHorizontal(); if (GUILayout.Button("+")) { var newDialogueID = 0; if (ds.Count > 0) { newDialogueID = ds[ds.Count - 1].id + 1; } DialogueWindow.Open(new Dialogue(newDialogueID), this); } GUILayout.EndHorizontal(); foreach (Dialogue d in dialogueHolder.dialogues) { GUILayout.BeginHorizontal(); GUILayout.Label(d.id + ": " + d.lines.Substring(0, Mathf.Min(20, d.lines.Length))); if (GUILayout.Button("edit")) { DialogueWindow.Open(d, this); } if (GUILayout.Button("del")) { toRemove = d; } GUILayout.EndHorizontal(); } if (toRemove != null) { dialogueHolder.dialogues.Remove(toRemove); } }
//Calls the dialogue box for the player to choose to use this skill public override void ActivateTriggerSkill(BasicCard triggeringCard) { //lets the player choose whether to activate the skill or not. DialogueWindowDetails details = new DialogueWindowDetails { windowTitleText = "Caeda's Wyvern Whip", questionText = "Would you like to activate Caeda's skill?" + "\n\nWyvern Whip [TRIGGER] Each time an ally with a Deployment Cost of 2 or lower is deployed, you may choose as many allies as you wish, and move them.", button1Details = new DialogueButtonDetails { buttonText = "Yes", buttonAction = () => { ChooseWWTarget(); }, }, button2Details = new DialogueButtonDetails { buttonText = "No", buttonAction = () => { Owner.deployTriggerTracker.RecheckTrigger(); }, } }; DialogueWindow dialogueWindow = DialogueWindow.Instance(); dialogueWindow.MakeChoice(details); }
void OnDestroy() { instance = null; }
void OnGUI() { TextAnchor oldAlignment = GUI.skin.window.alignment; GUI.skin.window.alignment = TextAnchor.UpperLeft; // check if windows need to be recreated if (Event.current.type == EventType.Repaint && filePopupSelectedIndex >= 0 && selectedEntry != null) createWindows(); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(GUILayout.Width(200)); GUILayout.Space(5); GUILayout.BeginHorizontal(); int t = filePopupSelectedIndex; filePopupSelectedIndex = EditorGUILayout.Popup(filePopupSelectedIndex, filePopupList); if (t != filePopupSelectedIndex) { } // the selected index has changed, load the correct dialogue file // create new dialogue file if (GUILayout.Button("+")) { saveUndo("creating dialogue file"); // create new dialogueFile DialogueFile file = ScriptableObject.CreateInstance<DialogueFile>(); AssetDatabase.CreateAsset(file, AssetDatabase.GenerateUniqueAssetPath("Assets/Script.asset")); AssetDatabase.SaveAssets(); files.Add(file); buildFilePopupArray(); } GUILayout.EndHorizontal(); // import export buttons GUILayout.BeginHorizontal(); if (filePopupSelectedIndex < 0) GUI.enabled = false; if (GUILayout.Button("Import")) { string filename = EditorUtility.OpenFilePanel("Import dialogue", ".", "xml"); DialogueFile importedFile = deserializeFromXML(filename); // import the various entries and lines // check if the existing file already has the same entries bool foundSameEntryName = false; string sameEntryName = ""; foreach (DialogueFile.DialogueEntry entry in importedFile.entries) { foreach (DialogueFile.DialogueEntry oldEntry in files[filePopupSelectedIndex].entries) { if (entry.id == oldEntry.id) { // found same entry foundSameEntryName = true; sameEntryName = entry.id; break; } } } bool continueImport = true; if (foundSameEntryName) { continueImport = EditorUtility.DisplayDialog("Same dialogue entry found", "The existing dialogue already has an entry named " + sameEntryName + ". If you continue, existing dialogues will be overwritten. Do you want to continue?", "Continue", "Cancel"); } if (continueImport) { saveUndo("Importing dialogue"); // add the entries and lines foreach (DialogueFile.DialogueEntry entry in importedFile.entries) { // check if it already exists bool dialogueExists = false; foreach (DialogueFile.DialogueEntry oldEntry in files[filePopupSelectedIndex].entries) { if (entry.id == oldEntry.id) { dialogueExists = true; // clear out existing lines files[filePopupSelectedIndex].lines.RemoveAll((item) => item.dialogueEntry == entry.id); } } if (!dialogueExists) files[filePopupSelectedIndex].entries.Add(entry); // add entry if it does not exists } // add the lines in one go files[filePopupSelectedIndex].lines.AddRange(importedFile.lines); EditorUtility.SetDirty(files[filePopupSelectedIndex]); } } if (GUILayout.Button("Export")) { // test serialization string filename = EditorUtility.SaveFilePanelInProject("Export dialogue", "dialogue", "xml", ""); serializeToXML(filename, files[filePopupSelectedIndex]); AssetDatabase.Refresh(); } if (filePopupSelectedIndex < 0) GUI.enabled = true; GUILayout.EndHorizontal(); // draw the dialogues dialogueListScroll = GUILayout.BeginScrollView(dialogueListScroll, (GUIStyle)"box"); if (filePopupSelectedIndex >= 0) { foreach (DialogueFile.DialogueEntry entry in files[filePopupSelectedIndex].entries) { if (entry == selectedEntry) { GUILayout.Label(entry.id, (GUIStyle)"boldLabel"); } else { if (GUILayout.Button(entry.id, (GUIStyle)"label")) { selectedEntry = entry; // build windows createWindows(); } } } } GUILayout.EndScrollView(); GUILayout.BeginHorizontal(); if (filePopupSelectedIndex < 0) GUI.enabled = false; if (GUILayout.Button("+")) { saveUndo("creating dialogue"); // create new dialogue entry DialogueFile.DialogueEntry newEntry = new DialogueFile.DialogueEntry(createUniqueDialogueName()); DialogueFile.DialogueLine beginLine = new DialogueFile.DialogueLine(); beginLine.dialogueEntry = newEntry.id; beginLine.id = 0; beginLine.position = new Vector2(10, 10); files[filePopupSelectedIndex].entries.Add(newEntry); files[filePopupSelectedIndex].lines.Add(beginLine); EditorUtility.SetDirty(files[filePopupSelectedIndex]); } if (GUILayout.Button("-")) { saveUndo("deleting dialogue"); // delete all the lines corresponding to this entry files[filePopupSelectedIndex].lines.RemoveAll((item) => item.dialogueEntry == selectedEntry.id); // delete the entry files[filePopupSelectedIndex].entries.Remove(selectedEntry); selectedEntry = null; windows.Clear(); EditorUtility.SetDirty(files[filePopupSelectedIndex]); } if (filePopupSelectedIndex < 0) GUI.enabled = true; GUILayout.EndHorizontal(); GUILayout.Space(5); GUILayout.EndVertical(); GUILayout.BeginVertical(); // show selected dialogueinfo GUILayout.BeginHorizontal(); // display name if (selectedEntry != null) GUILayout.Label("Name: " + selectedEntry.id); else GUILayout.Label("Name: "); GUILayout.FlexibleSpace(); if (selectedEntry == null) GUI.enabled = false; // rename button if (GUILayout.Button("Rename")) { // open rename dialog RenameDialogue dialog = GetWindow<RenameDialogue>(true); dialog.oldName = dialog.newName = selectedEntry.id; dialog.file = files[filePopupSelectedIndex]; } if (GUILayout.Button("Edit Speakers")) { // open rename dialog EditSpeakers dialog = GetWindow<EditSpeakers>(true); dialog.Init(files[filePopupSelectedIndex], selectedEntry.id); } if (selectedEntry == null) GUI.enabled = true; GUILayout.EndHorizontal(); // get rect for scrollview GUIStyle style = new GUIStyle(); style.stretchHeight = true; style.stretchWidth = true; style.margin = new RectOffset(4, 4, 4, 4); Rect rc = GUILayoutUtility.GetRect(new GUIContent(), style); GUI.Box(rc, ""); Rect bounds = getBoundingRect(new Rect(25, 25, rc.width - 50, rc.height - 50)); bounds.x -= 25; bounds.y -= 25; bounds.width += 50; bounds.height += 50; dialogueTreeScroll = GUI.BeginScrollView(rc, dialogueTreeScroll, bounds); BeginWindows(); int index = 0; bool createWindow = false; bool createLink = false; bool breakLink = false; bool deleteWindow = false; foreach (DialogueWindow window in windows) { string title = ""; if (window.line.id == 0) { title = "BEGIN"; } else { if (window.line != null) title = window.line.dialogue; } // draw output lines if (window.line != null) { foreach (int outputId in window.line.output) { // find connecting line foreach (DialogueFile.DialogueLine outputLine in files[filePopupSelectedIndex].lines) { if (outputLine.dialogueEntry == selectedEntry.id && outputLine.id == outputId) { Color color = Color.black; if (lastFocusWindow >= 0 && windows.Count > lastFocusWindow && windows[lastFocusWindow].line.id == outputId) color = Color.green; else if (lastFocusWindow >= 0 && windows.Count > lastFocusWindow && windows[lastFocusWindow].line == window.line) color = Color.red; Vector2 startPos = window.line.position + new Vector2(100, 25); Vector2 endPos = outputLine.position + new Vector2(0, 25); Vector2 midPos = (endPos - startPos).normalized; // found correct line float diffY = Mathf.Abs(startPos.y - endPos.y) / 4; float diffX = Mathf.Abs(startPos.x - endPos.x) / 4; Vector2 tPos = new Vector2(startPos.x + Mathf.Min(25, diffX), (startPos.y < endPos.y) ? startPos.y + Mathf.Min(25, diffY) : startPos.y - Mathf.Min(25, diffY)); Vector2 tPos2 = new Vector2(endPos.x - Mathf.Min(25, diffX), (startPos.y < endPos.y) ? endPos.y - Mathf.Min(25, diffY) : endPos.y + Mathf.Min(25, diffY)); Handles.DrawBezier(startPos, tPos, startPos + new Vector2(10, 0), tPos + midPos * -20, color, linetexture, 2); Handles.DrawBezier(tPos, tPos2, tPos + midPos * 20, tPos2 + midPos * -20, color, linetexture, 2); Handles.DrawBezier(tPos2, endPos, tPos2 + midPos * 20, endPos + new Vector2(-10, 0), color, linetexture, 2); break; } } } } window.rect = GUI.Window(index, window.rect, doWindow, title); if (window.line != null) window.line.position = new Vector2(window.rect.x, window.rect.y); //if (FocusedWindow < 0) GUI.FocusWindow(lastFocusWindow); GUI.FocusWindow(FocusedWindow); if (index == FocusedWindow) { // show extra buttons if (GUI.Button(new Rect(window.rect.xMax, window.rect.y + 10, 20, 20), "+", windowButtonStyle)) { createWindow = true; } if (GUI.Button(new Rect(window.rect.xMax, window.rect.y + 30, 20, 20), "->", windowButtonStyle)) { createLink = true; } if (GUI.Button(new Rect(window.rect.x - 20, window.rect.y + 10, 20, 20), "X", windowButtonStyle)) { breakLink = true; } if (index != 0) { if (GUI.Button(new Rect(window.rect.x + 80, window.rect.y - 15, 15, 15), "x", windowButtonStyle)) { deleteWindow = true; } } } lastFocusWindow = FocusedWindow; index++; } if (createdWindow >= 0) { GUI.BringWindowToFront(createdWindow); createdWindow = -1; } if (createWindow) { saveUndo("creating node"); // create new line and window DialogueFile.DialogueLine line = new DialogueFile.DialogueLine(); line.dialogue = ""; line.dialogueEntry = selectedEntry.id; line.id = selectedEntry.maxLineId++; // set line's position Rect windowRc = windows[lastFocusWindow].rect; line.position = new Vector2(windowRc.xMax + 50, windowRc.y); files[filePopupSelectedIndex].lines.Add(line); if (windows[lastFocusWindow].line != null) windows[lastFocusWindow].line.output.Add(line.id); int w = addWindow(line); GUI.FocusWindow(w); createdWindow = w; EditorUtility.SetDirty(files[filePopupSelectedIndex]); } if (createLink) { linkDragging = true; linkDragStartWindow = windows[lastFocusWindow]; wantsMouseMove = true; } if (breakLink) { linkDragging = true; this.breakLink = true; linkDragStartWindow = windows[lastFocusWindow]; wantsMouseMove = true; } if (linkDragging) { if (Event.current.type == EventType.MouseMove) { mousePos = Event.current.mousePosition; Repaint(); } if (this.breakLink) { // draw bezier curve from start window to cursor Vector2 pos1 = linkDragStartWindow.line.position + new Vector2(0, 25); Vector2 pos2 = mousePos; Handles.DrawBezier(pos1, pos2, pos1, pos2, Color.red, linetexture, 2); } else { // draw bezier curve from start window to cursor Vector2 pos1 = linkDragStartWindow.line.position + new Vector2(100, 25); Vector2 pos2 = mousePos; Handles.DrawBezier(pos1, pos2, pos1, pos2, Color.green, linetexture, 2); } } if (deleteWindow) { saveUndo("deleting node"); // find lines that link to this one foreach (DialogueFile.DialogueLine line in files[filePopupSelectedIndex].lines) { if (line.dialogueEntry == windows[lastFocusWindow].line.dialogueEntry) { if (line.output.Contains(windows[lastFocusWindow].line.id)) line.output.Remove(windows[lastFocusWindow].line.id); } } // remove currently selected window files[filePopupSelectedIndex].lines.Remove(windows[lastFocusWindow].line); windows.RemoveAt(lastFocusWindow); GUI.FocusWindow(0); lastFocusWindow = 0; EditorUtility.SetDirty(files[filePopupSelectedIndex]); } EndWindows(); // dialogue line text area GUI.EndScrollView(); if (lastFocusWindow > 0 && windows.Count > lastFocusWindow) windows[lastFocusWindow].line.dialogue = GUILayout.TextArea(windows[lastFocusWindow].line.dialogue, GUILayout.Height(GUI.skin.textArea.lineHeight * 3.1f)); else GUILayout.TextArea("", GUILayout.Height(GUI.skin.textArea.lineHeight * 3.1f)); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUI.skin.window.alignment = oldAlignment; }
void Awake() { // Save static instance of the object instance = this; playerParentTransform = playerTexture.texture.transform.parent; }
private static void OpenWindow() { DialogueWindow window = GetWindow <DialogueWindow>(); window.titleContent = new GUIContent("Dialogue Editor"); }