Пример #1
0
 void Gopatrol()
 {
     if (move_sign) {
         //不需要转向则设定一个目的地,按照矩形移动
         switch (dirction) {
             case Dirction.EAST:
                 pos_x -= move_length;
                 break;
             case Dirction.NORTH:
                 pos_z += move_length;
                 break;
             case Dirction.WEST:
                 pos_x += move_length;
                 break;
             case Dirction.SOUTH:
                 pos_z -= move_length;
                 break;
         }
         move_sign = false;
     }
     this.transform.LookAt (new Vector3 (pos_x, 0, pos_z));
     float distance = Vector3.Distance (transform.position, new Vector3 (pos_x, 0, pos_z));
     //当前位置与目的地距离浮点数的比较
     if (distance > 0.9) {
         transform.position = Vector3.MoveTowards (this.transform.position, new Vector3 (pos_x, 0, pos_z), move_speed * Time.deltaTime);
     } else {
         dirction = dirction + 1;
         if (dirction > Dirction.SOUTH) {
             dirction = Dirction.EAST;
         }
         move_sign = true;
     }
 }
Пример #2
0
        public static Tuple <int, int> ShiftClockWise(
            this Tuple <int, int> src
            , Dirction direction
            )
        {
            switch (direction)
            {
            case Dirction.Up:
                return(Tuple.Create(src.Item1 - 1, src.Item2));

            case Dirction.UpRt:
                return(Tuple.Create(src.Item1 - 1, src.Item2 + 1));

            case Dirction.Rt:
                return(Tuple.Create(src.Item1, src.Item2 + 1));

            case Dirction.DwRt:
                return(Tuple.Create(src.Item1 + 1, src.Item2 + 1));

            case Dirction.Dw:
                return(Tuple.Create(src.Item1 + 1, src.Item2));

            case Dirction.DwLt:
                return(Tuple.Create(src.Item1 + 1, src.Item2 - 1));

            case Dirction.Lt:
                return(Tuple.Create(src.Item1, src.Item2 - 1));

            case Dirction.UpLt:
                return(Tuple.Create(src.Item1 - 1, src.Item2 - 1));

            default:
                return(null);
            }
        }
Пример #3
0
    public override void Update()
    {
        if (move_sign)
        {
            //不需要转向则设定一个目的地,按照矩形移动
            switch (dirction)
            {
            case Dirction.EAST:
                pos_x -= move_length;
                break;

            case Dirction.NORTH:
                pos_z += move_length;
                break;

            case Dirction.WEST:
                pos_x += move_length;
                break;

            case Dirction.SOUTH:
                pos_z -= move_length;
                break;
            }
            move_sign = false;
        }
        this.transform.LookAt(new Vector3(pos_x, 0, pos_z));
        float distance = Vector3.Distance(transform.position, new Vector3(pos_x, 0, pos_z));

        //当前位置与目的地距离浮点数的比较
        if (distance > 1)
        {
            transform.position = Vector3.MoveTowards(this.transform.position, new Vector3(pos_x, 0, pos_z), move_speed * Time.deltaTime);
        }
        else
        {
            dirction = dirction + 1;
            if (dirction > Dirction.SOUTH)
            {
                dirction = Dirction.EAST;
            }
            move_sign = true;
        }
        //触发跟随后侦查动作删除
        if (this.gameObject.GetComponent <Prop>().is_follow&& this.gameObject.GetComponent <Prop>().player_pos == this.gameObject.GetComponent <Prop>().block)
        {
            this.destroy = true;
            this.callback.SSActionEvent(this, 0, this.gameObject);
        }
    }
    public void Move()
    {
        if (reach)
        {
            // 如果已到达,就换方向
            switch (dirction)
            {
            case Dirction.EAST:
                posX -= rectLength;
                break;

            case Dirction.NORTH:
                posZ += rectLength;
                break;

            case Dirction.WEST:
                posX += rectLength;
                break;

            case Dirction.SOUTH:
                posZ -= rectLength;
                break;
            }
            reach = false;
        }

        //面朝目的地
        this.transform.LookAt(new Vector3(posX, 0.5f, posZ));

        //计算距离
        float distance = Vector3.Distance(transform.position, new Vector3(posX, 0.5f, posZ));

        if (distance > 1)
        {
            transform.position = Vector3.MoveTowards(this.transform.position, new Vector3(posX, 0.5f, posZ), speed * Time.deltaTime);
        }
        else
        {
            dirction = dirction + 1;
            if (dirction > Dirction.SOUTH)
            {
                dirction = Dirction.EAST;
            }
            reach = true;
        }
    }
Пример #5
0
    void Gopatrol()
    {
        // 到达了一条边的尽头就要换个方向继续进行移动
        if (move_sign)
        {
            //不需要转向则设定一个目的地,按照矩形移动
            switch (dirction)
            {
            case Dirction.EAST:
                pos_x -= move_length;
                break;

            case Dirction.NORTH:
                pos_z += move_length;
                break;

            case Dirction.WEST:
                pos_x += move_length;
                break;

            case Dirction.SOUTH:
                pos_z -= move_length;
                break;
            }
            move_sign = false;
        }
        // 巡逻兵旋转自身,老是朝着Vector3所在的位置
        this.transform.LookAt(new Vector3(pos_x, 0, pos_z));
        float distance = Vector3.Distance(transform.position, new Vector3(pos_x, 0, pos_z));

        //当前位置与目的地距离浮点数的比较
        //如果当前位置与目标位置相差大于0.9,则换一个方向继续巡逻
        if (distance > 0.9)
        {
            transform.position = Vector3.MoveTowards(this.transform.position, new Vector3(pos_x, 0, pos_z), move_speed * Time.deltaTime);
        }
        else
        {
            dirction = dirction + 1;
            if (dirction > Dirction.SOUTH)
            {
                dirction = Dirction.EAST;
            }
            move_sign = true;
        }
    }
Пример #6
0
    //按照随机矩形轨迹运动
    void patrolMove()
    {
        if (is_turn)
        {
            switch (dirction)
            {
            case Dirction.EAST:
                pos_x -= move_length;
                break;

            case Dirction.NORTH:
                pos_z += move_length;
                break;

            case Dirction.WEST:
                pos_x += move_length;
                break;

            case Dirction.SOUTH:
                pos_z -= move_length;
                break;
            }
            is_turn = false;
        }
        this.transform.LookAt(new Vector3(pos_x, 0, pos_z));
        //比较两点的距离
        float distance = Vector3.Distance(transform.position, new Vector3(pos_x, 0, pos_z));

        //巡逻兵移动
        if (distance > 0.9)
        {
            transform.position = Vector3.MoveTowards(this.transform.position, new Vector3(pos_x, 0, pos_z), 1.5f * Time.deltaTime);
        }
        //巡逻兵改变方向
        else
        {
            dirction = dirction + 1;
            if (dirction > Dirction.SOUTH)
            {
                dirction = Dirction.WEST;
            }
            is_turn = true;
        }
    }
Пример #7
0
    void Gopatrol()
    {
        if (move_sign)
        {
            //不需要转向则设定一个目的地,按照矩形移动
            switch (dirction)
            {
            case Dirction.EAST:
                pos_x -= move_length;
                break;

            case Dirction.NORTH:
                pos_z += move_length;
                break;

            case Dirction.WEST:
                pos_x += move_length;
                break;

            case Dirction.SOUTH:
                pos_z -= move_length;
                break;
            }
            move_sign = false;
        }
        this.transform.LookAt(new Vector3(pos_x, 0, pos_z));
        float distance = Vector3.Distance(transform.position, new Vector3(pos_x, 0, pos_z));

        if (distance > 0.9)
        {
            rigid.velocity = new Vector3(planarVec.x, rigid.velocity.y, planarVec.z);
        }
        else
        {
            dirction = dirction + 1;
            if (dirction > Dirction.SOUTH)
            {
                dirction = Dirction.EAST;
            }
            move_sign = true;
        }
    }
Пример #8
0
    void Gopatrol()
    {
        if (move_sign)
        {
            switch (dirction)
            {
            case Dirction.E:
                pos_x -= move_length;
                break;

            case Dirction.N:
                pos_z += move_length;
                break;

            case Dirction.W:
                pos_x += move_length;
                break;

            case Dirction.S:
                pos_z -= move_length;
                break;
            }
            move_sign = false;
        }
        this.transform.LookAt(new Vector3(pos_x, 0, pos_z));
        float distance = Vector3.Distance(transform.position, new Vector3(pos_x, 0, pos_z));

        if (distance > 0.9)
        {
            transform.position = Vector3.MoveTowards(this.transform.position, new Vector3(pos_x, 0, pos_z), move_speed * Time.deltaTime);
        }
        else
        {
            dirction = dirction + 1;
            if (dirction > Dirction.S)
            {
                dirction = Dirction.E;
            }
            move_sign = true;
        }
    }
Пример #9
0
 void ReciveInput()
 {
     if (canMove)
     {
         if (Input.GetKeyDown(KeyCode.A) && dic != Dirction.right && dic != Dirction.left)
         {
             transform.rotation = Quaternion.Euler(0, 270, 0);
             moveDic.x          = -moveSpeed;
             moveDic.z          = 0;
             dic = Dirction.left;
             ChangeCanMove();
         }
         if (Input.GetKeyDown(KeyCode.D) && dic != Dirction.left && dic != Dirction.right)
         {
             transform.rotation = Quaternion.Euler(0, 90, 0);
             moveDic.x          = moveSpeed;
             moveDic.z          = 0;
             dic = Dirction.right;
             ChangeCanMove();
         }
         if (Input.GetKeyDown(KeyCode.W) && dic != Dirction.back && dic != Dirction.forward)
         {
             transform.rotation = Quaternion.Euler(0, 0, 0);
             moveDic.x          = 0;
             moveDic.z          = moveSpeed;
             dic = Dirction.forward;
             ChangeCanMove();
         }
         if (Input.GetKeyDown(KeyCode.S) && dic != Dirction.forward && dic != Dirction.back)
         {
             transform.rotation = Quaternion.Euler(0, 180, 0);
             moveDic.x          = 0;
             moveDic.z          = -moveSpeed;
             dic = Dirction.back;
             ChangeCanMove();
         }
     }
 }
Пример #10
0
        private IEnumerator ToMoveIE(List <Node> path, Action endCallBack)
        {
            IsRigibody = true;
            for (int i = 0; i < path.Count; i++)
            {
                bool    isRun    = true;
                Vector2 startPos = new Vector2(transform.position.x, transform.position.y);
                Vector2 endPos   = GridManager.Instance.GetScalePos(path[i].Position, GridManager.Instance.YScale);
                float   distance = Vector2.Distance(transform.position, endPos);
                float   time     = distance / Speed;
                float   process  = 0;
                float   timer    = 0;
                //六个方向
                Node selfNode = GridManager.Instance.GetNodeByPos(transform.position);
                if (selfNode == path[i])
                {
                    continue;
                }
                float row   = path[i].Row - selfNode.Row;
                float colum = path[i].Column - selfNode.Column;
                m_Aniamtor.SetTrigger("ToRun");
                if (row == 0 && colum == -1)
                {
                    m_Aniamtor.SetInteger("RunType", 0);
                    m_Dirction = Dirction.Left;
                    //Debug.Log("左");
                }
                else if (row == 1 && colum == -1)
                {
                    m_Aniamtor.SetInteger("RunType", 1);
                    m_Dirction = Dirction.LeftUp;
                    //Debug.Log("左上");
                }
                else if (row == 1 && colum == 0)
                {
                    m_Aniamtor.SetInteger("RunType", 2);
                    m_Dirction = Dirction.RightUp;
                    //Debug.Log("右上");
                }
                else if (row == 0 && colum == 1)
                {
                    m_Aniamtor.SetInteger("RunType", 3);
                    m_Dirction = Dirction.Right;
                    //Debug.Log("右");
                }
                else if (row == -1 && colum == 1)
                {
                    m_Aniamtor.SetInteger("RunType", 4);
                    m_Dirction = Dirction.RightDown;
                    //Debug.Log("右下");
                }
                else if (row == -1 && colum == 0)
                {
                    m_Aniamtor.SetInteger("RunType", 5);
                    m_Dirction = Dirction.LeftDown;
                    //Debug.Log("左下");
                }

                while (isRun)
                {
                    timer  += Time.deltaTime;
                    process = timer / time;
                    if (process >= 1)
                    {
                        process = 1;
                        isRun   = false;
                        //EazySoundManager.PlaySound(MoveClip);
                    }
                    Vector2 pos = Vector2.Lerp(startPos, endPos, process);
                    transform.position = new Vector3(pos.x, pos.y, transform.position.z);
                    if (Vector2.Distance(transform.position, Target.transform.position) < AttackRange)
                    {
                        if (!IsPlayer)
                        {
                            ToAttack();
                            yield return(new WaitForSeconds(0.4f));

                            RoleCtrl ctrl = Target.GetComponent <RoleCtrl>();
                            ctrl.ToDie();
                            yield return(new WaitForSeconds(0.25f));

                            ToStand();
                            yield return(new WaitForSeconds(1f));
                        }
                        else
                        {
                            ToWin();
                            transform.position = new Vector3(endPos.x, endPos.y, transform.position.z);
                            yield return(new WaitForSeconds(0.5f));
                        }
                        if (OnWin != null)
                        {
                            OnWin(IsPlayer);
                        }

                        yield break;
                    }
                    yield return(null);
                }
            }
            if (endCallBack != null)
            {
                endCallBack();
            }
            IsRigibody = false;
            ToStand();
        }
Пример #11
0
        Boolean FloodStart()
        {
            //读入dem,manning,rain
            this.Invoke(pm.addInfomation, new object[] { "正在读取DEM文件..." });
            DemPath = txbDemIpute.Text;
            GISdataManager.readRaster(DemPath, ref demRaster);
            dem = GISdataManager.Raster2Mat(demRaster);
            this.Invoke(pm.addInfomation, new object[] { "DEM数据读取完毕,并写入DEM数组中" });
            this.Invoke(pm.addInfomation, new object[] { "正在读取曼宁系数文件..." });
            ManningPath = txbManingInput.Text;
            GISdataManager.readRaster(ManningPath, ref manningRaster);
            manNing = GISdataManager.Raster2Mat(manningRaster);
            this.Invoke(pm.addInfomation, new object[] { "曼宁系数数据读取完毕,并写入曼宁系数数组中" });
            RainRecordPath = txbRaintxt.Text;
            rainRecordList = TxTReader.txt2List2(RainRecordPath);
            this.Invoke(pm.addInfomation, new object[] { "正在判断雨量格式是否正确..." });
            if (rainRecordList.Count > 0)
            {
                this.Invoke(pm.addInfomation, new object[] { "雨量数据格式正确" });
            }
            else
            {
                this.Invoke(pm.addInfomation, new object[] { "请重新输入有效降雨数据" });
                return(false);
            }
            //获取栅格分辨率
            IRasterInfo rasterinfo = (demRaster.Raster as IRawBlocks).RasterInfo;

            flowLength = Convert.ToInt32(rasterinfo.CellSize.X);
            this.Invoke(pm.addInfomation, new object[] { String.Format("DEM栅格宽度为:{0}m", flowLength) });
            //maxSpeed = (float)Math.Sqrt(flowLength * 10);
            maxSpeed    = 10f;
            flowLength2 = flowLength * 1.141f;
            //判断DEM与曼宁系数栅格是否一致!
            if (demRaster.ColumnCount != manningRaster.ColumnCount || demRaster.RowCount != manningRaster.RowCount)
            {
                this.Invoke(pm.addInfomation, new object[] { "曼宁糙率栅格行列与DEM不一致,请对应后重新输入!" });
                return(false);
            }
            rowCount = demRaster.RowCount;
            colCount = demRaster.ColumnCount;
            Console.WriteLine(rowCount + "," + colCount);
            //初始化中间参数
            slope       = new float[colCount, rowCount];    //坡度矩阵
            flowDir     = new Dirction[colCount, rowCount]; //流向矩阵
            canCuculate = new bool[colCount, rowCount];     //用于判断矩阵中的点是否在DEM范围内
            waterDeep   = new float[colCount, rowCount];    //水深矩阵
            tempDeep    = new float[colCount, rowCount];    //
            flowVel     = new float[colCount, rowCount];
            for (int i = 0; i < colCount; i++)
            {
                for (int j = 0; j < rowCount; j++)
                {
                    slope[i, j]   = 0f;
                    flowDir[i, j] = new Dirction()
                    {
                        x = 0, y = 0
                    };
                    if (dem[i, j] == nodataValue)
                    {
                        waterDeep[i, j] = nodataValue;
                    }
                    else
                    {
                        waterDeep[i, j] = 0f;
                    }
                    tempDeep[i, j] = 0f;
                    flowVel[i, j]  = 0f;
                }
            }

            for (int i = 0; i < colCount; i++)
            {
                for (int j = 0; j < rowCount; j++)
                {
                    if (dem[i, j] != nodataValue)
                    {
                        canCuculate[i, j] = true;
                    }
                }
            }
            return(true);
        }