public void OnExecute()
    {
        if (curRunningNode == null)
        {
            return;
        }
        bool hasFinished = true;

        while (hasFinished && curRunningNode != null)
        {
            hasFinished = false;
            hasFinished = curRunningNode.Execute();
            if (hasFinished)
            {
                lastSentence   = GetLastSentence(curRunningNode);
                curRunningNode = curRunningNode.GetNext();
                if (curRunningNode == null)
                {
                    saveData.curNodeId = -1;
                    return;
                }
            }
        }
        curSection            = ChatManager.Instance.LoadSectionByID(curPairID, curRunningNode.sectionId);
        saveData.curNodeId    = curRunningNode.nodeId;
        saveData.curSectionId = curSection.sectionID;
        ChatManager.Instance.Refresh();
    }
Exemple #2
0
    public GraphCanvasType LoadSectionByID(int pairId, int id)
    {
        int aid   = (pairId << 8) + id;
        int index = poolList.IndexOf(aid);

        if (index == -1)
        {
            GraphCanvasType c = Resources.Load <GraphCanvasType> ("Sections/" + pairId.ToString() + "/" + id.ToString());
            if (c == null)
            {
                return(null);
            }
            c.sectionID = id;
            for (int i = 0; i < c.nodes.Count; i++)
            {
                c.nodes [i].nodeId    = i;
                c.nodes [i].sectionId = id;
            }
            if (c.GetFirst() != null)
            {
                c.GenerateOrder(c.GetFirst());
            }
            poolList.Add(aid);
            selectionPool.Add(aid, c);
            return(c);
        }
        poolList.RemoveAt(index);
        poolList.Add(aid);
        return(selectionPool[aid]);
    }
    public void OnExecute()
    {
        ChatManager.Instance.curExecuteInstance = this;
        if (curRunningNode == null)
        {
            return;
        }
        bool hasFinished = true;
        int  finishCount = 0;

        while (hasFinished && curRunningNode != null)
        {
            hasFinished = false;
            hasFinished = curRunningNode.Execute();
            if (hasFinished)
            {
                DeactiveNode(curRunningNode);
                finishCount++;
                lastSentence = GetLastSentence(curRunningNode);
                Node temp = curRunningNode;
                curRunningNode = GetNext(curRunningNode);
                if (curRunningNode == null)
                {
                    saveData.curNodeId = -1;
                }
                else
                {
                    curRunningNode.TrySetReverseOption(temp);
                    ActiveNode(curRunningNode);
                }
            }
        }
        if (finishCount != 0)
        {
            lastChatTimeStamp = GameManager.Instance.time;
            if (curRunningNode != null)
            {
                curSection         = ChatManager.Instance.LoadSectionByID(curPairID, curRunningNode.sectionId);
                saveData.curNodeId = curRunningNode.nodeId;
            }
            else
            {
                saveData.curNodeId = -1;
            }
            saveData.curSectionId = curSection.sectionID;
            if (ChatManager.Instance.curInstance != this)
            {
                saveData.redCount += finishCount;
            }
            ChatManager.Instance.RefreshMsg();
            EventFactory.chatEventCenter.TriggerEvent(ChatEvent.OnCurInstancePopNewMsg);
        }
    }
    Node GetNext(Node curNode)
    {
        Node node = null;

        node = curNode.GetNext();
        if (node != null)
        {
            return(node);
        }
        GraphCanvasType canvas = ChatManager.Instance.LoadSectionByID(curPairID, curNode.sectionId + 1);

        if (canvas == null)
        {
            return(null);
        }
        return(canvas.GetFirst());
    }
    Node GetFront(Node curNode)
    {
        Node node = null;

        node = curNode.GetFront();
        if (node != null)
        {
            return(node);
        }
        if (curNode.sectionId == 0)
        {
            return(null);
        }
        GraphCanvasType canvas = ChatManager.Instance.LoadSectionByID(curPairID, curNode.sectionId - 1);

        return(canvas.GetLast());
    }
    public void OnInit(int friendId)
    {
        ChatManager.Instance.curExecuteInstance = this;
        int pairId = ChatManager.Instance.GetPairID(curUserId, friendId);

        this.friendId     = friendId;
        this.friendData   = XMLSaver.saveData.GetAccountData(friendId);
        this.friendName   = friendData.enname;
        curPairID         = pairId;
        saveData          = XMLSaver.saveData.GetInstanceData(curPairID);
        lastChatTimeStamp = saveData.lastChatTimeStamp;
        curSection        = ChatManager.Instance.LoadSectionByID(curPairID, saveData.curSectionId);
        Node front = null;

        if (saveData.curNodeId >= 0)
        {
            curRunningNode = curSection.nodes[saveData.curNodeId];
            front          = curRunningNode.GetFront();
        }
        else if (saveData.curNodeId == ChatManager.finished)
        {
            front = curSection.GetLast();
        }
        else if (saveData.curNodeId == ChatManager.need2Init)
        {
            nextReadNode        = curRunningNode = curSection.GetFirst();
            saveData.curNodeId  = curRunningNode.nodeId;
            saveData.readNodeId = nextReadNode.nodeId;
        }
        if (saveData.readNodeId >= 0)
        {
            nextReadNode = ChatManager.Instance.LoadSectionByID(curPairID, saveData.readSectionId).nodes [saveData.readNodeId];
        }
        else
        {
            //nextReadNode = ChatManager.Instance.LoadSectionByID (curPairID, saveData.curSectionId).GetLast ();
        }
        if (front != null)
        {
            lastSentence = GetLastSentence(front);
        }
        totalRectHeight = saveData.totalRectHeight;
    }
    public void OnInit(string name, string otherName, int pairId)
    {
        userName          = name;
        otherUserName     = otherName;
        curPairID         = pairId;
        saveData          = XMLSaver.saveData.GetInstanceData(curPairID);
        lastChatTimeStamp = saveData.lastChatTimeStamp;
        curSection        = ChatManager.Instance.LoadSectionByID(curPairID, saveData.curSectionId);
        if (saveData.curNodeId != -1)
        {
            curRunningNode = curSection.nodes [saveData.curNodeId];
        }
        Node front = curRunningNode.GetFront();

        if (front != null)
        {
            lastSentence = GetLastSentence(front);
        }
        totalRectHeight = saveData.totalRectHeight;
    }
    public Node GetNext(Node curNode, bool showableOnly = false)
    {
        Node node = null;

        node = curNode.GetNext(showableOnly);
        if (node != null)
        {
            return(node);
        }
        GraphCanvasType canvas = ChatManager.Instance.LoadSectionByID(curPairID, curNode.sectionId + 1);

        if (canvas == null)
        {
            return(null);
        }
        if (showableOnly && canvas.GetFirst() is SetParamNode)
        {
            return(GetNext(canvas.GetFirst(), showableOnly));
        }
        return(canvas.GetFirst());
    }
Exemple #9
0
        public static GraphCanvas CreateGraph(
            string key, GraphCanvasType gcType,
            bool realtime, bool multiPlot,
            float val1, float val2
            )
        {
            GraphCanvas gc = new GraphCanvas();

            gc.realtime  = realtime;
            gc.multiPlot = multiPlot;
            gc.name      = key;
            gc.gcType    = gcType;

            gc.minValue = val1;
            gc.maxValue = val2;

            gc.gameobject = new GameObject("Graph: **Name**");
            RectTransform rt = gc.gameobject.AddComponent <RectTransform>();

            rt.SetParent(Setup.instance.debugGrapherGroup.gameObject.transform);
            rt.anchorMin = Vector2.zero;
            rt.anchorMax = Vector2.zero;
            rt.pivot     = Vector2.zero;

            rt.anchoredPosition = new Vector2(Setup.settings.graphMargin, Setup.settings.graphMargin);
            rt.sizeDelta        = new Vector2(Screen.width - (2 * Setup.settings.graphMargin) - 110, Screen.height - (2 * Setup.settings.graphMargin));

            gc.image              = gc.gameobject.AddComponent <RawImage>();
            gc.texture            = new Texture2D(Mathf.RoundToInt(rt.rect.width / Setup.settings.graphLineSize), Mathf.RoundToInt(rt.rect.height / Setup.settings.graphLineSize));
            gc.texture.filterMode = FilterMode.Point;
            gc.texture.wrapMode   = TextureWrapMode.Repeat;

            gc.image.texture = gc.texture;
            gc.ClearTexture();

            //InvokeRepeating ("UpdateGraphTexture", 0f, 1f / (float)settings.graphUpdateFrequency);

            gc.canvas = gc.gameobject.AddComponent <CanvasGroup> ();

            GameObject g = new GameObject("GrapherButton");

            rt           = g.AddComponent <RectTransform>();
            rt.anchorMin = Vector2.zero;
            rt.anchorMax = Vector2.zero;
            rt.pivot     = Vector2.one;

            rt.anchoredPosition = new Vector2(Screen.width, Screen.height)
                                  - new Vector2(Setup.settings.generalMargin, Setup.settings.generalMargin)
                                  - new Vector2(0, instance.allGraphs.Count * 60);

            rt.sizeDelta = new Vector2(100, 50);
            rt.SetParent(gc.gameobject.transform.parent);

            Button b = g.AddComponent <Button>();

            b.targetGraphic = g.AddComponent <Image>();
            g = new GameObject("Label");
            g.transform.SetParent(b.transform);
            Text t = g.AddComponent <Text>();

            t.text      = key;
            t.font      = Font.CreateDynamicFontFromOSFont("Arial", 14);
            t.color     = Color.black;
            t.alignment = TextAnchor.MiddleCenter;
            g.GetComponent <RectTransform>().anchoredPosition = Vector2.zero;
            //b.transform.Find("Text").GetComponent<Text>().text = "Show/Hide";

            b.onClick.AddListener(() => {
                instance.HideAllGraphs();
                gc.Activate();
                //Debug.Log("test");
            });

            instance.allGraphs.Add(gc);

            instance.HideAllGraphs();
            gc.Activate();

            return(gc);
        }
 public GraphTraversal(GraphCanvasType canvas) : base(canvas)
 {
     Canvas = canvas;
 }