示例#1
0
    // Update is called once per frame
    void Update()
    {
        if (dlg.Active == true)
        {
            return;
        }
        if (TrackingObject != null)
        {
            float camera_angle    = 90f;
            float toCheckDistance = 6f;
            ViewRadar(camera_angle, toCheckDistance, GetComponent <Transform>().position);

            int index = Search(camera_angle, toCheckDistance, GetComponent <Transform>().position, TrackingObject);
            if (index == -1)
            {
                if (floor.BGM() == "Warning")
                {
                    floor.BGM("Default");
                }
                TrackingObject.GetComponent <PlayerCellController>().SetColor();
            }
            else
            {
                floor.BGM("Warning");
                TrackingObject.GetComponent <PlayerCellController>().SetColor(new Color32(255, 0, 255,
                                                                                          TrackingObject.GetComponent <PlayerCellController>().defaultColor.a));
                autoMovingSpeed = 5.0f;
                if (nextNavigation.Count == 0 || nextNavigation[nextNavigation.Count - 1] != index)
                {
                    pmotion.Cancel();
                    autoMovedTime = Time.realtimeSinceStartup - AutoMovingSpan;
                    List <int> route = floor.blocks.Solve(floor.blocks.GetBlockIndex(GetComponent <Transform>().position), index);
                    nextNavigation.Clear();
                    for (int cnt = 1; cnt < route.Count; cnt++)
                    {
                        nextNavigation.Add(route[cnt]);
                    }
                    routeRenderer.Render(route, i => floor.blocks.GetBlockPosition(i), Color.red);
                }
            }
        }

        if (AutoMovingSpan == 0)
        {
            foreach (var elem in actions)
            {
                if (Input.GetKeyDown(elem.Key))
                {
                    Move(elem.Value);
                }
            }
        }
        else if (Time.realtimeSinceStartup > autoMovedTime + AutoMovingSpan / autoMovingSpeed)
        {
            autoMovedTime = Time.realtimeSinceStartup;
            pmotion.Unset();

            int[] pos = floor.blocks.GetBlockIndexXZ(GetComponent <Transform>().position);

            bool moved = false;
            while (nextNavigation.Count > 0)
            {
                int next = nextNavigation[0];
                int x    = floor.blocks.i2x(next);
                int z    = floor.blocks.i2z(next);
                if (x - pos[0] != 0 || z - pos[1] != 0)
                {
                    Move(new int[] { x - pos[0], z - pos[1], 0, 1 }, () =>
                    {
                        nextNavigation.RemoveAt(0);
                        if (nextNavigation.Count == 0)
                        {
                            autoMovingSpeed = 1.0f;
                            routeRenderer.Clear();
                        }
                    });
                    moved = true;
                    break;
                }
                else
                {
                    nextNavigation.RemoveAt(0);
                }
            }

            if (moved == false)
            {
                List <string> avail = new List <string>();
                foreach (var d in nextPosition)
                {
                    if (floor.blocks.IsWall(pos[0] + d.Value[0], pos[1] + d.Value[1]) == false)
                    {
                        avail.Add(d.Key);
                    }
                }
                if (avail.Count != 0)
                {
                    Move(nextPosition[avail[UnityEngine.Random.Range(0, avail.Count)]]);
                }
            }
        }
        floor.UpdateObjPosition(gameObject.name, GetComponent <Transform>().position, GetComponent <Transform>().rotation);
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        if (dlg.Active == true)
        {
            return;
        }
        if (TrackingObject != null)
        {
            float camera_angle    = 90f;
            float toCheckDistance = 6f;
            ViewRader(camera_angle, toCheckDistance, GetComponent <Transform>().position);

            int index = Search(camera_angle, toCheckDistance, GetComponent <Transform>().position, TrackingObject);
            // Debug.Log(index);

            // エネミーに見つかっていないときの処理
            if (index == -1)
            {
                if (floor.BGM() == "Warning")
                {
                    floor.BGM("Default");
                }
                TrackingObject.GetComponent <PlayerCellController>().SetColor();
                // 自作
                // autoMovingSpeed = 1.0f;
            }
            // エネミーに見つかっているときの処理
            else
            {
                floor.BGM("Warning");
                TrackingObject.GetComponent <PlayerCellController>().SetColor(new Color32(255, 0, 255,
                                                                                          TrackingObject.GetComponent <PlayerCellController>().defaultColor.a));
                autoMovingSpeed = 5.0f;
                // 初めて相手を見つけたときまたは見つけた相手が動いたとき(index番号が変わったとき)
                if (nextNavigation.Count == 0 || nextNavigation[nextNavigation.Count - 1] != index)
                {
                    pmotion.Cancel();
                    // 一個前に自動移動した時間autoMovedTime
                    autoMovedTime = Time.realtimeSinceStartup - AutoMovingSpan;                                         //プレイヤーのいち
                    List <int> route = floor.blocks.Solve(floor.blocks.GetBlockIndex(GetComponent <Transform>().position), index);
                    nextNavigation.Clear();
                    for (int cnt = 1; cnt < route.Count; cnt++)
                    {
                        nextNavigation.Add(route[cnt]);
                    }
                    routeRenderer.Render(route, i => floor.blocks.GetBlockPosition(i), Color.red);
                }
            }
        }

        // Playerの条件分岐
        if (AutoMovingSpan == 0)
        {
            foreach (var elem in actions)
            {
                if (Input.GetKeyDown(elem.Key))
                {
                    Move(elem.Value);
                }
            }
        }
        // エネミーの条件分岐
        else if (Time.realtimeSinceStartup > autoMovedTime + AutoMovingSpan / autoMovingSpeed)
        {
            autoMovedTime = Time.realtimeSinceStartup;
            pmotion.Unset();

            int[] pos = floor.blocks.GetBlockIndexXZ(GetComponent <Transform>().position);

            bool moved = false;
            while (nextNavigation.Count > 0)
            {
                int next = nextNavigation[0];
                int x    = floor.blocks.i2x(next);
                int z    = floor.blocks.i2z(next);
                if (x - pos[0] != 0 || z - pos[1] != 0)
                {
                    Move(new int[] { x - pos[0], z - pos[1], 0, 1 }, () =>
                    {
                        nextNavigation.RemoveAt(0);
                        if (nextNavigation.Count == 0)
                        {
                            autoMovingSpeed = 1.0f;
                            routeRenderer.clear();
                            // Clearが効かない
                            // routeRenderer.Clear();
                        }
                    });
                    moved = true;
                    break;
                }
                else
                {
                    nextNavigation.RemoveAt(0);
                }
            }
            // movedがfalseだった場合は自動運転(ランダム)に切り替える
            if (moved == false)
            {
                List <string> avail = new List <string>();
                // 動ける範囲があるか探す処理
                foreach (var d in nextPosition)
                {
                    if (floor.blocks.IsWall(pos[0] + d.Value[0], pos[1] + d.Value[1]) == false)
                    {
                        avail.Add(d.Key);
                    }
                }
                if (avail.Count != 0)
                {
                    Move(nextPosition[avail[UnityEngine.Random.Range(0, avail.Count)]]);
                }
            }
        }
        // めちゃくちゃ大事な処理
        // 動いたあとの場所をしゅとくする
        // gameObject.nameが何の名前なのかを調べる
        floor.UpdateObjectPosition(gameObject.name, GetComponent <Transform>().position, GetComponent <Transform>().rotation);
    }