Example #1
0
        /// <summary>初期化 Initialize.</summary>
        /// <param name="duration">遷移時間 Transition duration.</param>
        /// <param name="next">遷移先ノード Next node.</param>
        /// <param name="process">処理イベント Processing function.</param>
        public void Initialize(float duration, FlowAINode next, ProcessingEventHandler process)
        {
            Initialize(duration, next);
            onProcess += process;

            _initial = Copy();
        }
Example #2
0
 public PrepareData(FlowAINode node, int depthX, int depthY, bool isActive, bool isFocus, Rect rect)
 {
     this.node     = node;
     this.depthX   = depthX;
     this.depthY   = depthY;
     this.isActive = isActive;
     this.rect     = rect;
     this.isFocus  = isFocus;
 }
Example #3
0
        /// <summary>初期化 Initialize.</summary>
        /// <param name="trueNode">結果が真の場合の遷移先ノード Next node.In case of true.</param>
        /// <param name="trueDuration">結果が真の場合の遷移時間 Transition duration.In case of true.</param>
        /// <param name="falseNode">結果が偽の場合の遷移先ノード Next node.In case of false.</param>
        /// <param name="falseDuration">結果が偽の場合の遷移先ノード Transition duration.In case of false.</param>
        /// <param name="pred">叙述関数 Predicate function.</param>
        public void Initialize(FlowAINode trueNode, float trueDuration, FlowAINode falseNode, float falseDuration, Predicate pred)
        {
            _trueNode     = trueNode;
            _trueDuration = trueDuration;

            _falseNode     = falseNode;
            _falseDuration = falseDuration;

            predicate += pred;
        }
Example #4
0
        void Prepare(FlowAINode node, int depthX, int depthY)
        {
            if (node == null)
            {
                return;
            }

            //準備済みノードならば終了
            if (_prepares.Exists(item => item.node == node))
            {
                return;
            }

            _maxDepthX = Mathf.Max(depthX, _maxDepthX);
            _maxDepthY = Mathf.Max(depthY, _maxDepthY);

            //準備済みリストに追加
            //位置
            Vector2 pos = new Vector2(depthX * _nodeHorizontalSpace, depthY * _nodeVerticalSpace);

            pos += _globalOffset;

            //矩形
            Rect nodeRect = new Rect(Vector2.zero, _nodeSize);

            nodeRect.center = pos;

            Vector2 mousePos = Input.mousePosition;

            mousePos.y = Screen.height - mousePos.y;

            _prepares.Add(new PrepareData(node, depthX, depthY, _targetBasis.currentNode == node, nodeRect.Contains(mousePos), nodeRect));

            //処理ノードかエントリポイントノードならば
            if (node is ProcessNode || node is FlowAIBasis.EntryPointNode)
            {
                //Y方向の深さを1つ掘る
                Prepare(node.GetNextNode(), depthX, depthY + 1);
                return;
            }

            //分岐ノードならば
            else if (node is BranchNode)
            {
                var branch = node as BranchNode;

                //Y方向の深さを1つ掘る
                Prepare(branch.trueNode, depthX, depthY + 1);
                //X方向とY方向の深さを1つ掘る
                Prepare(branch.falseNode, depthX + 1, depthY + 1);
                return;
            }
        }
Example #5
0
        /// <summary>初期化 Initialize.</summary>
        /// <param name="trueNode">結果が真の場合の遷移先ノード Next node.In case of true.</param>
        /// <param name="trueDuration">結果が真の場合の遷移時間 Transition duration.In case of true.</param>
        /// <param name="falseNode">結果が偽の場合の遷移先ノード Next node.In case of false.</param>
        /// <param name="falseDuration">結果が偽の場合の遷移先ノード Transition duration.In case of false.</param>
        /// <param name="pred">叙述関数 Predicate function.</param>
        /// <param name="summary">node's summary</param>
        public void Initialize(FlowAINode trueNode, float trueDuration, FlowAINode falseNode, float falseDuration, Predicate pred, string summary)
        {
            _trueNode     = trueNode;
            _trueDuration = trueDuration;

            _falseNode     = falseNode;
            _falseDuration = falseDuration;

            _summary = summary;

            predicate += pred;
        }
Example #6
0
 /// <summary>処理 Processing.</summary>
 public override void Processing()
 {
     if (predicate())
     {
         _selectedNode = _trueNode;
         duration      = _trueDuration;
     }
     else
     {
         _selectedNode = _falseNode;
         duration      = _falseDuration;
     }
 }
Example #7
0
        public FlowAIBasis()
        {
            _idCount = 0;
            _nodes   = new List <FlowAINode>();

            //エントリポイント生成
            _entryPoint          = new EntryPointNode();
            _entryPoint.duration = 0f;
            AddNode(_entryPoint);
            _currentNode = _entryPoint;

            _elapsed   = 0f;
            _isStopped = false;
        }
Example #8
0
        /// <summary>遷移 Transition</summary>
        /// <param name="localId">遷移先のノードID LocalID of next node</param>
        public void Transition(int localId)
        {
            var node = _nodes.FirstOrDefault(item => item.localId == localId);

            //そのIDのノードが存在しない場合
            if (node == null)
            {
                TFDebug.Log("FlowAIBasis", "[TRNS]この基盤に存在しないローカルID:{0}", localId);
                _isStopped = true;
                return;
            }

            _currentNode = node;
            _currentNode.Processing();

            //終端ノードだった場合
            if (_currentNode.GetNextNode() == null)
            {
                _isStopped = true;
                TFDebug.Log("FlowAIBasis", "[TRNS]終端ノードに到達しました ローカルID:{0}", localId);
                return;
            }
        }
Example #9
0
 /// <summary>初期化 Initialize.</summary>
 /// <param name="duration">遷移時間 Transition duration.</param>
 /// <param name="next">遷移先ノード Next node.</param>
 public void Initialize(float duration, FlowAINode next)
 {
     this.duration = duration;
     _nextNode     = next;
 }
Example #10
0
        void OnGUI()
        {
            /*if (!_isInHacking)
             * {
             *      if (GUI.Button(new Rect(0, 0, 100, 33), "hack begin"))
             *      {
             *              BeginHacking(0.05f);
             *      }
             * }*/

            TFDebug.Write("visualizer", "show time:{0}\n", _showElapsed);

            //非表示
            if (!_isVisible)
            {
                return;
            }

            GUI.Box(new Rect(_windowPosition, _windowSize), "");

            //ターゲットにするAIがnull
            if (_targetBasis == null)
            {
                var temp = GUI.color;
                GUI.color = Color.red;
                GUI.Label(new Rect(_windowPosition + _globalOffset, new Vector2(100f, 100f)), "Target AI not found");
                GUI.color = temp;
                return;
            }

            Prepare(_targetBasis.entryPointNode);
            DrawLines();
            DrawNodes();
            DrawFocus();

            if (_isInHacking)
            {
                ExitButton(new Rect(_exitButtonPosX + _windowPosition.x, _exitButtonPosY + _windowPosition.y, _exitButtonWidth, _exitButtonHeight));

                PrepareData?focused = _prepares
                                      .Select(item => item as PrepareData?)
                                      .FirstOrDefault(item => item.Value.isFocus);

                if (Input.GetMouseButtonDown(0) && focused.HasValue && focused.Value.node is ProcessNode)
                {
                    _isInDrag = true;
                    _from     = focused.Value.node;
                }

                if (Input.GetMouseButtonUp(0) && _isInDrag && focused.HasValue && focused.Value.node is ProcessNode)
                {
                    _isInDrag = false;
                    _to       = focused.Value.node;

                    if (!_isInSwapping)
                    {
                        _targetBasis.ImitativeSwap(_from.localId, _to.localId);

                        _isInSwapping    = true;
                        _swappingElapsed = 0f;
                        _swappingFromId  = _from.localId;
                        _swappingToId    = _to.localId;
                    }
                }
                else if (Input.GetMouseButtonUp(0) && _isInDrag)
                {
                    _isInDrag = false;
                    _from     = null;
                }

                if (_isInDrag)
                {
                    OnSwap();
                }

                TFDebug.Write("visualizer", "is in swap:{0}\n", _isInDrag.ToString());
            }
        }
Example #11
0
 void Prepare(FlowAINode node)
 {
     _prepares.Clear();
     Prepare(node, 0, 0);
 }
Example #12
0
 public EntryPointNode()
 {
     _nextNode = null;
     _summary  = "ENTRY";
 }
Example #13
0
 /// <summary>ノード追加 Add node.</summary>
 /// <param name="node">ノード node.</param>
 public void AddNode(FlowAINode node)
 {
     node.localId = _idCount++;
     _nodes.Add(node);
 }