public ConditionValue(BaseNodule _nodule, ValueType _dataParam) { nodule = _nodule; equality = EqualityState.Equal; dataParam = _dataParam; userParam = false; }
public ConditionValue(BaseNodule _nodule, EqualityState _equality, ValueType _dataParam, ValueType _userParam) { nodule = _nodule; equality = _equality; dataParam = _dataParam; userParam = _userParam; }
public static bool CheckCompatibility(BaseNode node, BaseNodule nodule) { if (!node || !nodule) { Debug.LogError(""); return(false); } if (node is StartNode && node.Nodules.Count > 0) { Debug.LogWarning(""); return(false); } if (node is OptionNode) { if ((node as OptionNode).MainNode && nodule is InputNodule) { Debug.LogWarning("Can not make a Input Nodule for a node connected another."); return(false); } } if (node.Nodules.Contains(nodule)) { Debug.LogError("Nodule '" + nodule + "' already exist in this node ' " + node + "."); return(false); } return(true); }
public static BaseNodule Create(string className, string _name, BaseNode _mainNode) { BaseNodule nodule = Instantiate(NoduleTypes.GetDefaultNodule(className)); nodule.Construct(_name, _mainNode); return(nodule); }
public static BaseNodule Create(string className, BaseNode _mainNode) { BaseNodule nodule = Instantiate(NoduleTypes.GetDefaultNodule(className)); nodule.Construct(_mainNode.Nodules.NextItemName(nodule.GetType().Name), _mainNode); return(nodule); }
protected override void Construct() { name = "Start Node"; position = new Rect(CanvasGUI.CanvasToScreenPosition(CanvasGUI.CanvasRect.center), ResourceManager.START_NODE_SIZE); nodules = NoduleDatabase.CreateNew(this); nodules.Add(BaseNodule.Create <OutputNodule> (this)); DialogueEditorGUI.Cache.SaveNewObject(this, false); }
public static void OnGUI(EditorStates states) { States = states; EditorState curState = states.curState; CanvasGUI.BeginGroup(new Rect(curState.panDelta, curState.canvasSize), (states.curSpace | EventSpace.CanvasSpace) == EventSpace.CanvasSpace); for (int i = 0; i < Cache.Nodes.Count; i++) { Cache.Nodes.Get(i).DrawConnection(); } if (curState.connectionIndex > -1) { BaseNodule startNodule = curState.selectedObject as BaseNodule; if (curState.connectionIndex > startNodule.Nodules.Count - 1) { InputHandlers.OnSelectConnection(states); } else { CanvasGUI.DrawConnection(startNodule, startNodule.Nodules.Get(curState.connectionIndex), Color.red); } } Cache.Nodes.OnGUI(); CanvasGUI.EndGroup(); CanvasGUI.BeginGroup(CanvasGUI.OptionRect, GUI.skin.box, states.curSpace == EventSpace.Actor); switch (tab) { case OptionTab.actor: Cache.Actors.OnGUI(); break; case OptionTab.condition: Cache.Conditions.OnGUI(); break; } if (CanvasGUI.Button(new Rect(5, 5, 70, 20), "Conditions")) { tab = OptionTab.condition; } else if (CanvasGUI.Button(new Rect(80, 5, 50, 20), "Actors")) { tab = OptionTab.actor; } CanvasGUI.EndGroup(); }
public static void DeleteConnection(EditorStates states) { EditorState state = states.curState; BaseNodule nodule = state.selectedObject as BaseNodule; if (nodule.Nodules.Count > 0 && state.connectionIndex == -1) { state.connectionIndex++; } if (state.connectionIndex > -1) { nodule.Nodules.RemoveAt(state.connectionIndex); state.connectionIndex--; } }
public void UpdateParams(EditorState oldES) { focusedObjects = oldES.focusedObjects; selectedObject = oldES.selectedObject; dragNode = oldES.dragNode; panWindow = oldES.panWindow; dragStartPos = oldES.dragStartPos; startPos = oldES.startPos; dragDelta = oldES.dragDelta; panDelta = oldES.panDelta; makeConnection = oldES.makeConnection; startNodule = oldES.startNodule; endNodule = oldES.endNodule; }
public override void Init() { base.Init(); if (nodules.Count == 0) { nodules.Add(BaseNodule.Create <OutputNodule> (nodules.NextItemName("OutputNodule"), this)); } else { OutputNodule output = nodules.First(i => i is OutputNodule) as OutputNodule; if (!output) { nodules.Insert(0, BaseNodule.Create <OutputNodule> (nodules.NextItemName("OutputNodule"), this)); } } }
public void Reset() { focusedObjects = null; selectedObject = null; dragNode = false; panWindow = false; dragStartPos = Vector2.zero; startPos = Vector2.zero; dragDelta = Vector2.zero; canvasSize = new Vector2(10000, 10000); panDelta = -canvasSize / 2; makeConnection = false; connectionIndex = -1; startNodule = null; endNodule = null; }
public static void OnMakingConnection(EditorStates states) { EditorState state = states.curState; if (state.makeConnection) { switch (states.curSpace) { case EventSpace.Node: BaseNode node = state.selectedObject as BaseNode; state.endNodule = node.Nodules.Find(i => i.GetType() == (state.startNodule is OutputNodule ? typeof(InputNodule) : typeof(OutputNodule))) ?? BaseNodule.Create(state.startNodule is OutputNodule ? "InputNodule" : "OutputNodule", node); if (!state.endNodule.MainNode) { goto default; } if (state.startNodule && state.endNodule) { node.Nodules.Add(state.endNodule); state.startNodule.Nodules.Add(state.endNodule); } goto default; case EventSpace.Nodule: state.endNodule = state.selectedObject as BaseNodule; if (state.startNodule && state.endNodule) { state.startNodule.Nodules.Add(state.endNodule); } goto default; default: state.startNodule = null; state.endNodule = null; state.makeConnection = false; break; } } }
public static void DrawConnection (BaseNodule startNodule, BaseNodule endNodule, Color lineColor) { Vector2 startPos = new Vector2 (startNodule.side == NoduleSide.Left ? startNodule.Position.xMin : startNodule.Position.xMax, startNodule.Position.center.y); Vector2 endPos = new Vector2 (endNodule.side == NoduleSide.Left ? endNodule.Position.xMin : endNodule.Position.xMax, endNodule.Position.center.y); Handles.DrawBezier (startPos, endPos, startPos + startNodule.Dir * 80, endPos + endNodule.Dir * 80, lineColor, null, 3); }
public static void ConnectionCallBack(object callBackObj) { EditorStates states = callBackObj as EditorStates; if (states == null) { throw new UnityException(); } EditorState state = states.curState; switch (states.curSpace) { case EventSpace.Nodule: if (!state.makeConnection) { state.startNodule = state.selectedObject as BaseNodule; state.makeConnection = true; } else { goto default; } break; case EventSpace.Node: if (!state.makeConnection) { BaseNode node = (state.selectedObject as BaseNode); state.startNodule = node.Nodules.Find(i => i.GetType().ToString().Contains(states.info)) ?? BaseNodule.Create(states.info, node.Nodules.NextItemName(states.info), node); if (state.startNodule.MainNode) { node.Nodules.Add(state.startNodule); } else { state.startNodule.Delete(); } if (state.startNodule) { state.makeConnection = true; } else { goto default; } } else { goto default; } break; default: state.startNodule = null; state.endNodule = null; state.makeConnection = false; break; } }
static void AddCallBack(object callBackObj) { EditorStates states = callBackObj as EditorStates; if (states == null) { throw new UnityException(); } EditorState state = states.curState; if (states.info.Contains("Node")) { switch (states.curSpace) { case EventSpace.Node: if (states.info == "OptionNode") { if (state.selectedObject is MainNode) { MainNode main = state.selectedObject as MainNode; main.Options.Add(OptionNode.Create(main.Options.NextItemName("Option"), main)); } else { goto default; } } else if (states.info == "MainNode") { goto default; } else { Debug.LogError("Cannot recognise name of 'Node'. Add More Error here"); return; } break; default: EditorCache cache = DialogueEditorGUI.Cache; cache.Nodes.Add(DialogueNode.Create(states.info, cache.Nodes.NextItemName(states.info), CanvasGUI.CanvasToScreenPosition(state, states.mousePos), cache.Actors.DefaultActor)); break; } } else if (states.info.Contains("Nodule")) { BaseNode node = (states.curSpace == EventSpace.Node) ? state.selectedObject as BaseNode : (states.curSpace == EventSpace.Nodule) ? (state.selectedObject as BaseNodule).MainNode : null; if (node) { node.Nodules.Add(BaseNodule.Create(states.info, node.Nodules.NextItemName(states.info), node)); } } else { throw new UnityException(); } }
public static bool CheckCompatibility(BaseNodule startNodule, BaseNodule endNodule) { if (!startNodule || !endNodule) { Debug.LogWarning((!startNodule ? "Start " : "End ") + " nodule is null."); return(false); } if (!startNodule.MainNode || !endNodule.MainNode) { Debug.LogWarning(""); return(false); } if (startNodule == endNodule) { Debug.Log(startNodule.GetInstanceID() + ", " + endNodule.GetInstanceID()); Debug.LogWarning("Start and end nodules are both the same object."); return(false); } if (startNodule.MainNode == endNodule.MainNode) { Debug.LogWarning("Start and end nodules have the same node."); return(false); } if (!GetNoduleAttritube(startNodule.GetID).CheckCompatibility(endNodule.GetID)) { Debug.LogWarning("Start and end nodules are not compatible."); return(false); } if (startNodule.Nodules.Contains(endNodule) || endNodule.Nodules.Contains(startNodule)) { Debug.LogWarning("Start and end nodules are already connected."); return(false); } if (startNodule.MainNode is OptionNode && !(startNodule is OutputNodule) || endNodule.MainNode is OptionNode && !(endNodule is OutputNodule)) { OptionNode option = ((startNodule.MainNode is OptionNode) ? startNodule.MainNode : endNodule.MainNode) as OptionNode; if (option.MainNode == endNodule.MainNode) { Debug.LogWarning("Recursive connection is a world of hurt, just dont do it."); return(false); } } if (startNodule.MainNode is StartNode && startNodule is InputNodule) { Debug.LogError(""); return(false); } else if (endNodule.MainNode is StartNode && endNodule is InputNodule) { Debug.LogError(""); return(false); } return(true); }