Exemple #1
0
    public ArrayList OnFindPathFromNoWayPointPaths()
    {
        GameObject startPos = GameObject.Find("StartPos");
        GameObject endPos   = GameObject.Find("EndPos");

        Vector3 startPosVec = CUtility.RoundVector3(startPos.transform.position);
        Vector3 endPosVec   = CUtility.RoundVector3(endPos.transform.position);

        CAStar AStar = new CAStar();

        AStar.InitTiles(ref Tiles);
        int StartIdx = (int)(startPosVec.y * Size + startPosVec.x);
        int EndIdx   = (int)(endPosVec.y * Size + endPosVec.x);

        ArrayList InitTiles = AStar.GetTiles();

        PathIdxs = AStar.FindPaths(StartIdx, EndIdx, 0);
        ArrayList PathTiles = new ArrayList();

        for (int i = 0; i < PathIdxs.Count; ++i)
        {
            Tile CurTile = InitTiles[(int)PathIdxs[i]] as Tile;
            PathTiles.Add(CurTile);
        }
        return(PathTiles);
    }
Exemple #2
0
    public void RandomMove()
    {
        Vector3 EndPos = gameObject.transform.position + new Vector3(UnityEngine.Random.Range(-1.0f, 1.0f), UnityEngine.Random.Range(-1.0f, 1.0f), 0.0f);

        EndPos = CUtility.RoundVector3(EndPos);
        bool bMove = Move(gameObject.transform.position, EndPos);

        if (bMove)
        {
            curState = EState.Move;
        }
    }
Exemple #3
0
    public void MoveAttackRange()
    {
        Vector3 CurPos     = gameObject.transform.position;
        Vector3 TargetPos  = TargetObj.transform.position;
        float   TargetDist = Vector3.Distance(CurPos, TargetPos);

        if (AttackRange < TargetDist)
        {
            Vector3 GoalPos = TargetPos - CurPos;
            float   Rate    = 1.0f - AttackRange / TargetDist;
            GoalPos = CurPos + (GoalPos * Rate);
            GoalPos = CUtility.RoundVector3(GoalPos);
            bool bMove = Move(CurPos, GoalPos);
            if (bMove)
            {
                curState = EState.Move;
            }
            else
            {
                for (int y = -1; y < 2; ++y)
                {
                    for (int x = -1; x < 2; ++x)
                    {
                        if (x != 0 && y != 0)
                        {
                            Vector3 AddPos     = new Vector3(x, y, 0);
                            Vector3 NewGoalPos = GoalPos + AddPos;
                            NewGoalPos = CUtility.RoundVector3(NewGoalPos);
                            bool bNewMove = Move(CurPos, NewGoalPos);
                            if (bNewMove)
                            {
                                curState = EState.Move;
                                return;
                            }
                        }
                    }
                }
            }
        }
    }