Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public enum Class
- {
- None,
- Fighter,
- Mage,
- Asshole,
- Max
- }
- public class Conversation : MonoBehaviour
- {
- public enum State
- {
- Idle,
- Run,
- Max
- }
- public State state;
- public Block currentBlock;
- public string startBlock;
- public string notes;
- [System.Serializable]
- public class Block
- {
- public Block()
- {
- isOpen = true;
- name = "newBlock";
- dialog = "";
- branches = new List<Branch>();
- }
- public void AddNewBranch()
- {
- branches.Add(new Branch());
- }
- public void RemoveBranch(Branch branch)
- {
- branches.Remove(branch);
- }
- public string name;
- public string dialog;
- public bool isOpen;
- public List<Branch> branches;
- }
- [System.Serializable]
- public class Branch
- {
- public Branch()
- {
- dialog = "";
- gotoBlock = "";
- condition = new Condition();
- }
- public string dialog;
- public string gotoBlock;
- public Condition condition;
- }
- [System.Serializable]
- public class Condition
- {
- public enum Comparison
- {
- Ignore,
- EqualTo,
- NotEqualTo,
- GreaterThan,
- LessThan
- }
- public Condition()
- {
- isOpen = false;
- }
- public bool IsMet()
- {
- bool isMet = true;
- // evaluate disposition
- switch (dispositionComparison)
- {
- case Comparison.Ignore:
- break;
- case Comparison.EqualTo:
- break;
- case Comparison.GreaterThan:
- break;
- case Comparison.LessThan:
- break;
- case Comparison.NotEqualTo:
- break;
- }
- return isMet;
- }
- public bool isOpen;
- public int dispositionValue;
- public Comparison dispositionComparison;
- public Comparison classComparison;
- public Class classValue;
- }
- public List<Block> blocks;
- public void AddNewBlock()
- {
- blocks.Add(new Block());
- }
- public void RemoveBlock(Block block)
- {
- blocks.Remove(block);
- }
- public void MoveBlockUp(Block block)
- {
- int index = blocks.IndexOf(block);
- index --;
- if (index < 0)
- {
- index = 0;
- }
- blocks.Remove(block);
- blocks.Insert(index, block);
- }
- public void MoveBlockDown(Block block)
- {
- int index = blocks.IndexOf(block);
- index ++;
- if (index >= blocks.Count)
- {
- index = blocks.Count-1;
- }
- blocks.Remove(block);
- blocks.Insert(index, block);
- }
- public void Run()
- {
- state = State.Run;
- if (startBlock == "")
- {
- currentBlock = blocks[0];
- }
- else
- {
- GotoBlockNamed(startBlock);
- }
- }
- void Awake()
- {
- state = State.Idle;
- }
- void OnGUI()
- {
- switch (state)
- {
- case State.Run:
- GUILayout.BeginVertical();
- GUILayout.Label(currentBlock.dialog);
- foreach (Branch branch in currentBlock.branches)
- {
- if (branch.condition.IsMet())
- {
- if (GUILayout.Button(branch.dialog))
- {
- GotoBlockNamed(branch.gotoBlock);
- }
- }
- }
- GUILayout.EndVertical();
- break;
- }
- }
- void GotoBlockNamed(string blockName)
- {
- currentBlock = GetBlockNamed(blockName);
- if (currentBlock == null)
- {
- state = State.Idle;
- }
- else
- {
- state = State.Run;
- }
- }
- public Block GetBlockNamed(string blockName)
- {
- foreach (Block block in blocks)
- {
- if (block.name == blockName)
- {
- return block;
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment