Example #1
0
        public void AddSequence(Action <Action> newSequence)
        {
            SequenceObject sobj = new SequenceObject();

            sobj.MainAction = newSequence;
            _sequences.Add(sobj);
        }
    void Init()
    {
        if (sequence == null)
        {
            sequence = new SequenceObject();
        }

        foreach (EventNode node in sequence.nodes)
        {
            foreach (int i in node.previousNodesId)
            {
                node.previousNodes.Add(sequence.nodesList[i]);
            }

            if (node.GetType() != typeof(ChoiceNode))
            {
                if (node.nextNodeId != -1)
                {
                    node.nextNode = sequence.nodesList[node.nextNodeId];
                }
            }
            else
            {
                for (int i = 0; i < ((ChoiceNode)node).nbChoice; i++)
                {
                    ((ChoiceNode)node).nextNodeList[i] = sequence.nodesList[((ChoiceNode)node).nextNodeIdList[i]];
                }
            }
        }
    }
    public void ChangeSequence(string name, bool changedByExplo, int beginingNodeId = -1, bool newPlace = false)
    {
        string sequenceId = "";
        int    nodeId     = -1;

        if (!newPlace && !changedByExplo && beginingNodeId == -1)
        {
            sequenceId = currentSequence.id;
            nodeId     = currentNode.id;
        }

        StopAllCoroutines();

        SequenceObject newSequence = GameInfoManager.getSequence(name);

        if (changedByExplo)
        {
            newSequence.invokedByExploration = true;
        }
        else
        {
            newSequence.invokedByExploration = false;
            newSequence.invokedBySequence    = sequenceId;
            newSequence.invokedByNode        = nodeId;
        }

        currentSequence = newSequence;

        StartCoroutine(ReadSequence(newSequence, beginingNodeId));
    }
 public OneModelComputation(ModelObject model, SequenceObject sequence, int step, int maxSize)
 {
     this.model    = model;
     this.sequence = sequence;
     this.step     = step;
     this.maxSize  = maxSize;
 }
Example #5
0
    protected void copy(SequenceObject sequenceToCopy)
    {
        id          = sequenceToCopy.id;
        firstNodeId = sequenceToCopy.firstNodeId;

        colorR = sequenceToCopy.colorR;
        colorG = sequenceToCopy.colorG;
        colorB = sequenceToCopy.colorB;

        nodes = sequenceToCopy.nodes;
    }
Example #6
0
        private void btOMCCalculateProbability_Click(object sender, EventArgs e)
        {
            if (lbOMCModelPath.Text != "" && lbOMCSequencePath.Text != "" && tbOMCSegmentLength.Text != "" && tbOMCSequenceLength.Text != "")
            {
                int     segmentSize    = Int32.Parse(tbOMCSegmentLength.Text);  //добавить проверку
                int     sequenceLength = Int32.Parse(tbOMCSequenceLength.Text); //добавить проверку
                HMM_QPN Model          = new HMM_QPN(lbOMCModelPath.Text);
                if (Model.IsCorrect() == 1)
                {
                    int[] res = new int[sequenceLength + 1];
                    try
                    {
                        res = HMM_PSM.GetOutputSequence(lbOMCSequencePath.Text, sequenceLength);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Желаемая длина последовательности превышает размер файла");
                        return;
                    }
                    ModelObject         model         = new ModelObject(lbOMCModelPath.Text, Model);
                    SequenceObject      sequence      = new SequenceObject(lbOMCSequencePath.Text, res);
                    OneModelComputation computor      = new OneModelComputation(model, sequence, segmentSize, sequenceLength);
                    List <double>       probabilities = computor.compute();

                    string s = "Model: " + model.ModelName + "\r\n Sequence: " + sequence.SequenceName + "\r\n Sequence length: " + sequenceLength + "\r\n Segment size: " + segmentSize + "\r\n";
                    for (int i = 0; i < probabilities.Count(); i++)
                    {
                        s += probabilities.ElementAt(i) + ",";
                    }
                    OutStreamer os = new OutStreamer("omc.txt", FileOpenMode.RewriteMode);

                    os.StringToFile(s);
                    if (saveFileDialogExperiment.ShowDialog() == DialogResult.OK)
                    {
                        StreamReader f   = File.OpenText("omc.txt");
                        string       Buf = f.ReadToEnd();
                        StreamWriter sw  = new StreamWriter(File.Create(saveFileDialogExperiment.FileName));
                        sw.Write(Buf);
                        sw.Close();
                        f.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Модель некорректна");
                }
            }
            else
            {
                MessageBox.Show("Не все параметры заданы");
            }
        }
            private UniRx.IObservable <Unit> CreateTimer(SequenceObject sequenceObject, GameObject owner, float delay)
            {
                var sequence = sequenceObject.Invoke(this.target).Pause();
                var observer = Observable.Timer(TimeSpan.FromSeconds(delay)).Share();

                observer.SubscribeWithState2(this, sequence, (_, _this, s) =>
                {
                    s.Play();
                })
                .AddTo(owner);

                return(sequence.OnCompleteAsObservable());
            }
Example #8
0
    public static SequenceObject getSequence(string sequenceName)
    {
        SequenceObject sO = gameInfo.sequences[0];

        foreach (SequenceObject s in gameInfo.sequences)
        {
            if (s.id == sequenceName)
            {
                sO = s;
            }
        }

        return(sO);
    }
Example #9
0
        public void Execute()
        {
            OnProgressSequence?.Invoke(0);
            for (int i = 0; i < _sequences.Count; i++)
            {
                if (i < _sequences.Count - 1)
                {
                    int index = i;
                    _sequences[i].FinishAction += () =>
                    {
                        float prog = ((float)index + 1) / _sequences.Count;
                        OnProgressSequence?.Invoke(prog);
                    };

                    if (_separator != null)
                    {
                        SequenceObject sep = new SequenceObject();
                        sep.MainAction              = _separator;
                        sep.FinishAction           += () => _sequences[index + 1].Execute();
                        _sequences[i].FinishAction += () => sep.Execute();
                    }
                    else
                    {
                        _sequences[i].FinishAction += () => _sequences[index + 1].Execute();
                    }
                }
                else
                {
                    _sequences[i].FinishAction += () =>
                    {
                        OnProgressSequence?.Invoke(1);
                        OnFinishSequence?.Invoke();
                    };
                }
            }

            if (_sequences.Count > 0)
            {
                _sequences[0].Execute();
            }
            else
            {
                OnProgressSequence?.Invoke(1);
                OnFinishSequence?.Invoke();
            }
        }
    void OnGUI()
    {
        GUILayout.BeginVertical();
        scrollPos = GUILayout.BeginScrollView(scrollPos, false, false);
        GUILayout.BeginVertical();

        foreach (SequenceObject sequence in sequences)
        {
            GUILayout.BeginHorizontal();

            sequence.id    = EditorGUILayout.TextField(sequence.id);
            sequence.color = EditorGUILayout.ColorField(sequence.color);

            if (GUILayout.Button("Edit"))
            {
                SequenceEditor.ShowEditor(sequences.IndexOf(sequence));
            }

            GUILayout.EndHorizontal();
        }

        GUILayout.EndVertical();
        GUILayout.EndScrollView();

        if (GUILayout.Button("New"))
        {
            SequenceObject sO = new SequenceObject();
            sO.id = "Sequence " + (sequences.Count + 1);
            sequences.Add(sO);
            Save();
        }

        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Save"))
        {
            Save();
        }

        GUILayout.EndVertical();
    }
Example #11
0
 public void SetOwner(SequenceObject sequenceObject) {
     owner = sequenceObject;
 }
    static void Load()
    {
        GameInfoManager.LoadGameInfo();

        sequence = GameInfoManager.gameInfo.sequences[seqIndex];
    }
    IEnumerator ReadSequence(SequenceObject sequence, int beginingNodeId = -1)
    {
        if (beginingNodeId != -1)
        {
            currentNode = sequence.GetNode(sequence.GetNode(beginingNodeId).nextNodeId);
        }
        else
        {
            currentNode = sequence.GetNode(sequence.firstNodeId);
        }

        int nextNodeId = -1;

        int newId;

        canRead = true;

        nodeHandler.InitNodes();

        while (currentNode != null && canRead)
        {
            if (currentNode.GetType() != typeof(WaitForInputNode) &&
                currentNode.GetType() != typeof(GoToSequenceNode) &&
                currentNode.GetType() != typeof(GoToPlaceNode) &&
                currentNode.GetType() != typeof(GoToExplorationNode) &&
                nodeHandler.CanGoNextNode(false, out newId))
            {
                if (newId != -1)
                {
                    currentNode = sequence.GetNode(newId);
                }
                else
                {
                    nodeHandler.HandleNode(currentNode);

                    nextNodeId = nodeHandler.GetNextNodeId(currentNode);

                    currentNode = sequence.GetNode(nextNodeId);
                }
            }
            else if (currentNode.GetType() == typeof(WaitForInputNode))
            {
                if (inputGetter.click /*Input.GetMouseButtonUp(0)*/ && nodeHandler.CanGoNextNode(true, out newId))
                {
                    nextNodeId = nodeHandler.GetNextNodeId(currentNode);

                    currentNode = sequence.GetNode(nextNodeId);
                }
            }
            else if (currentNode.GetType() == typeof(GoToSequenceNode))
            {
                if (nodeHandler.CanGoNextNode(false, out newId))
                {
                    ChangeSequence(((GoToSequenceNode)currentNode).sequenceId, false);
                }
            }
            else if (currentNode.GetType() == typeof(GoToPlaceNode))
            {
                if (nodeHandler.CanGoNextNode(false, out newId))
                {
                    ChangePlace(((GoToPlaceNode)currentNode).placeId);
                }
            }
            else if (currentNode.GetType() == typeof(GoToExplorationNode))
            {
                if (nodeHandler.CanGoNextNode(false, out newId))
                {
                    ChangeExploration(((GoToExplorationNode)currentNode).explorationId);
                }
            }

            yield return(null);
        }

        Debug.Log("End Sequence");

        if (canRead)
        {
            if (currentSequence.invokedByExploration)
            {
                nodeHandler.ClearNodes();
            }
            else if (currentSequence.invokedByNode != -1 && currentSequence.invokedBySequence != "")
            {
                ChangeSequence(currentSequence.invokedBySequence, false, currentSequence.invokedByNode);
            }
        }

        yield return(null);
    }