Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        //如果当前状态时等待状态时
        if (m_eRS == AutoRunState.eIdle)
        {
            //按下键盘右键激活自动运行状态
            if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                m_curCol = (int)(transform.position.x / m_moveStep);
                m_curRow = (int)(transform.position.z / m_moveStep);
                m_curCol = Mathf.Clamp(m_curCol, 0, m_maxCol);
                m_curRow = Mathf.Clamp(m_curRow, 0, m_maxRow);

                if (m_curRow == m_maxRow && m_curCol == m_maxCol)
                {
                    Debug.Log("AutoRunCamera::reach end point !!!");
                }
                else
                {
                    m_curPos.x         = m_curCol * m_moveStep; // +m_offset.x;
                    m_curPos.z         = m_curRow * m_moveStep; // +m_offset.z;
                    m_curPos.y         = transform.position.y;
                    transform.position = m_curPos;

                    if (m_curCol == m_maxCol)
                    {
                        m_eMoveDir = MoveDir.eUp;
                        m_distZ    = m_curPos.z + m_moveStep;
                    }
                    else
                    {
                        m_eMoveDir = MoveDir.eRight;
                        m_distX    = m_curPos.x + m_moveStep;
                        //m_eMoveDir = MoveDir.eLeft;
                        //m_distX = m_curPos.x - m_moveStep;
                    }

                    m_eRS = AutoRunState.eMove;
                }
            }
        }

        //如果当前状态是移动状态
        if (m_eRS == AutoRunState.eMove)
        {
            m_curPos = this.transform.position;
            float _step = m_moveSpd * Time.deltaTime;

            if (m_eMoveDir == MoveDir.eRight)  //如果移动方向向右
            {
                m_curPos.x += _step;

                if (m_curPos.x >= m_distX || m_curPos.x >= m_terrainSize) //8189.0f)
                {
                    m_curPos.x = m_distX;
                    m_eRS      = AutoRunState.eWaitFillVegetation;
                    ++m_curCol;
                }
            }
            else if (m_eMoveDir == MoveDir.eLeft) //如果移动方向向左
            {
                m_curPos.x -= _step;
                if (m_curPos.x <= m_distX || m_curPos.x <= 0.0f)
                {
                    m_curPos.x = m_distX;
                    m_eRS      = AutoRunState.eWaitFillVegetation;
                    --m_curCol;
                }
            }
            else if (m_eMoveDir == MoveDir.eUp) //如果移动方向向
            {
                m_curPos.z += _step;
                if (m_curPos.z >= m_distZ)
                {
                    m_curPos.z = m_distZ;
                    m_eRS      = AutoRunState.eWaitFillVegetation;
                    ++m_curRow;
                }
            }

            m_curPos.y = 1600.0f;
            Ray        _ray = new Ray(m_curPos, new Vector3(0.0f, -1.0f, 0.0f));
            RaycastHit _raycastHit;
            if (Physics.Raycast(_ray, out _raycastHit, m_curPos.y))
            {
                m_curPos    = _raycastHit.point;
                m_curPos.y += m_offset.y;
                this.transform.position = m_curPos;
            }
        }

        //如果当前状态时等待种植植被的状态
        if (m_eRS == AutoRunState.eWaitFillVegetation)
        {
            if (!VFVoxelTerrain.self.IsInGenerating)
            {
                m_elps += Time.deltaTime;
                if (m_elps >= 6.0f)
                {
                    m_voxelEditor.AutoFillVegetation();
                    m_elps = 0.0f;
                    if (m_curCol == m_maxCol && m_curRow == m_maxRow)
                    {
                        m_eRS = AutoRunState.eIdle;
                    }
                    else
                    {
                        if (m_eMoveDir == MoveDir.eRight)
                        {
                            if (m_curCol == m_maxCol)
                            {
                                m_eMoveDir = MoveDir.eUp;
                                m_distZ    = m_curPos.z + m_moveStep;
                            }
                            else
                            {
                                m_distX = m_curPos.x + m_moveStep;
                            }
                        }
                        else if (m_eMoveDir == MoveDir.eLeft)
                        {
                            if (m_curCol == 0)
                            {
                                m_eMoveDir = MoveDir.eUp;
                                m_distZ    = m_curPos.z + m_moveStep;
                            }
                            else
                            {
                                m_distX = m_curPos.x - m_moveStep;
                            }
                        }
                        else if (m_eMoveDir == MoveDir.eUp)
                        {
                            if (m_curCol == 0)
                            {
                                m_eMoveDir = MoveDir.eRight;
                                m_distX    = m_curPos.x + m_moveStep;
                            }
                            else if (m_curCol == m_maxCol)
                            {
                                m_eMoveDir = MoveDir.eLeft;
                                m_distX    = m_curPos.x - m_moveStep;
                            }
                        }

                        m_eRS = AutoRunState.eMove;
                    }
                }
            }
        }
    }
 /// <summary>
 /// Default ctor
 /// </summary>
 public VirtualMode(bool enabled, RailwayState railwayState)
 {
     this.enabled      = enabled;
     this.railwayState = railwayState;
     autoRunState      = new AutoRunState(railwayState);
 }