Exemplo n.º 1
0
 public ConditionValue(BaseNodule _nodule, ValueType _dataParam)
 {
     nodule    = _nodule;
     equality  = EqualityState.Equal;
     dataParam = _dataParam;
     userParam = false;
 }
Exemplo n.º 2
0
 public ConditionValue(BaseNodule _nodule, EqualityState _equality, ValueType _dataParam, ValueType _userParam)
 {
     nodule    = _nodule;
     equality  = _equality;
     dataParam = _dataParam;
     userParam = _userParam;
 }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public static BaseNodule Create(string className, string _name, BaseNode _mainNode)
        {
            BaseNodule nodule = Instantiate(NoduleTypes.GetDefaultNodule(className));

            nodule.Construct(_name, _mainNode);
            return(nodule);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
 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();
        }
Exemplo n.º 8
0
        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--;
            }
        }
Exemplo n.º 9
0
        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;
        }
Exemplo n.º 10
0
        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));
                }
            }
        }
Exemplo n.º 11
0
        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;
        }
Exemplo n.º 12
0
        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;
                }
            }
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        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;
            }
        }
Exemplo n.º 15
0
        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();
            }
        }
Exemplo n.º 16
0
        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);
        }