public static Block CreateBlock(Flowchart flowchart, Vector2 position) { Block newBlock = flowchart.CreateBlock(position); Undo.RegisterCreatedObjectUndo(newBlock, "New Block"); ShowBlockInspector(flowchart); flowchart.selectedBlock = newBlock; flowchart.ClearSelectedCommands(); return(newBlock); }
//MIKEHACK public virtual void CreateNewBlock() { //TODO: fix block position; Flowchart flow = FindObjectOfType <Flowchart>(); //Create block Vector2 blockPos = new Vector2(-500, -500); Block b = flow.CreateBlock(blockPos); //load in data string textData = FindObjectOfType <Localization>().rtfDocument.text; b.blockName = FindObjectOfType <Localization>().rtfDocument.name; string[] lines = textData.Split('\n'); Character lastSpeaker = flow.gameObject.AddComponent(typeof(Character)) as Character; //used to keep track of who spoke last, outside of loop to remember. Character currentSpeaker = flow.gameObject.AddComponent(typeof(Character)) as Character; //used to keep track of who's speaking, outside of loop to remember. Sprite speakerSprite = null; bool portraitStart = false; //process line by line foreach (string line in lines) { string buffer = line.Trim(); if (buffer == "") { continue; } //title of the block and create a new one if (buffer.StartsWith("TITLE:")) { blockPos = new Vector2(blockPos.x + 250, -500); b = flow.CreateBlock(blockPos); buffer = buffer.Substring(7, buffer.Length - 7); //cuts "TITLE: " from the front b.blockName = buffer; continue; } //fade the scene with default params if (buffer.StartsWith("<<fade>>")) { FadeScreen newCommand = flow.gameObject.AddComponent(typeof(FadeScreen)) as FadeScreen; newCommand.parentBlock = b; newCommand.itemId = flow.NextItemId(); b.commandList.Add(newCommand); continue; } //if it's a bg change then write the lineID and the buffer if (buffer.StartsWith("<<bg>>")) { //Add Say command Say newCommand = flow.gameObject.AddComponent(typeof(Say)) as Say; newCommand.parentBlock = b; newCommand.itemId = flow.NextItemId(); b.commandList.Add(newCommand); //assign text newCommand.storyText = "ADD BACKGROUND TO OBJECT #" + flow.NextItemId() + " :" + buffer; continue; } //description of the block for reference of bgs if (buffer.StartsWith("BG:")) { buffer = buffer.Substring(4, buffer.Length - 4); //cuts "BG: " from the front b.description = buffer; continue; } else { //if it starts with some portrait, we try and find that portrait and set it if (buffer.StartsWith("<mei") || buffer.StartsWith("<bastion") || buffer.StartsWith("<soldier") || buffer.StartsWith("<mercy") || buffer.StartsWith("<genji")) { portraitStart = true; //using this to track whether or not to remember portrait int lasti = buffer.LastIndexOf(">"); string spriteName = buffer.Substring(1, lasti - 1); speakerSprite = FindSprite(spriteName); buffer = buffer.Substring(lasti + 1, buffer.Length - lasti - 1).Trim(); } else { portraitStart = false; } //Check second character is a colon, which would indicate that someone must have been speaking. //we're assuming the id's won't ever be longer than 1 //if that's the case we look for the speaker based on the first letter and save that for later if (buffer.Substring(1, 1) == ":") { currentSpeaker = WhoIsSpeaking(buffer.Substring(0, 1)); // will return null if it's the narrator //if there is no portrait and the sentence starts with an ID we reset the speakerSprite if (!portraitStart) { speakerSprite = null; } //cuts the identifier + the space from the front buffer = buffer.Substring(3, buffer.Length - 3); } else { currentSpeaker = lastSpeaker; } //Add Say command Say newCommand = flow.gameObject.AddComponent(typeof(Say)) as Say; newCommand.parentBlock = b; newCommand.itemId = flow.NextItemId(); b.commandList.Add(newCommand); //assign text newCommand.storyText = buffer; //assign speaker newCommand.character = currentSpeaker; if (speakerSprite != null) { //if a portrait should be shown while narrator speaks if (currentSpeaker == null) { newCommand.showNarratorPortrait = true; //show narrator portrait newCommand.narratorCharacter = WhoHasSprite(speakerSprite); //replace narrator character with whoever owns the sprite. newCommand.narratorPortrait = speakerSprite; //replace narrator portrait } else { newCommand.portrait = speakerSprite; } } else { if (currentSpeaker != null && currentSpeaker.portraits.Count > 0) { newCommand.portrait = currentSpeaker.portraits[0]; //default } } lastSpeaker = currentSpeaker; //remove speaker objects again //TODO: fix this garbage, it's a workaround for the lack of "new" keyword DestroyImmediate(flow.gameObject.GetComponent <Character>()); } } }