예제 #1
0
    public void SetManTargetPosition(GameObject man, Vector3 targetPos, float tol, TileEdge.MovementType type = TileEdge.MovementType.WALK)
    {
        switch (type)
        {
        case TileEdge.MovementType.WALK:
            man.GetComponent <CrowdControl>().MoveTo(targetPos, tol, CrowdControl.CrowdState.WALK);
            break;

        case TileEdge.MovementType.CLIMB_BACK:
            man.GetComponent <CrowdControl>().MoveTo(targetPos, tol, CrowdControl.CrowdState.CLIMB_BACK);
            break;

        case TileEdge.MovementType.CLIMB_SIDE:
            man.GetComponent <CrowdControl>().MoveTo(targetPos, tol, CrowdControl.CrowdState.CLIMB_SIDE);
            break;

        default:
            man.GetComponent <CrowdControl>().MoveTo(targetPos, tol, CrowdControl.CrowdState.WALK);
            break;
        }
    }
예제 #2
0
 public virtual void InsertAtHead(GameObject obj, TileEdge.MovementType type = TileEdge.MovementType.WALK)
 {
 }
예제 #3
0
 public virtual void InsertAtHead(Vector3 pos, TileEdge.MovementType type = TileEdge.MovementType.WALK)
 {
 }
예제 #4
0
        public override void InsertAtHead(GameObject obj, TileEdge.MovementType type = TileEdge.MovementType.WALK)
        {
            TilePathUnit t = new TilePathUnit(obj, type);

            paths.Insert(0, t);
        }
예제 #5
0
        public override void InsertAtHead(Vector3 pos, TileEdge.MovementType type = TileEdge.MovementType.WALK)
        {
            PosPathUnit t = new PosPathUnit(pos, type);

            paths.Insert(0, t);
        }
예제 #6
0
 public PosPathUnit(Vector3 p, TileEdge.MovementType t)
 {
     pos      = p;
     pathType = t;
 }
예제 #7
0
    public override bool FindPath(GameObject actor, Vector3 endPos, float clampTol = 0.5F)
    {
        recentPath = new TileBasedFoundPath();

        Vector3    startPos  = actor.transform.position;
        GameObject startTile = FindNearestTile(startPos);
        GameObject endTile   = FindNearestTile(endPos);

        if (startTile == null || endTile == null)
        {
            return(false);
        }

        recentPath.endUnit = endTile;

        // re-number all the pathpoints
        Dictionary <GameObject, int> IDs = new Dictionary <GameObject, int>();
        int N = 0;

        foreach (GameObject tile in tiles)
        {
            if (!IDs.ContainsKey(tile))
            {
                IDs.Add(tile, N);
                ++N;
            }
        }

        // init path matrix
        float[,] path = new float[tiles.Count, tiles.Count];
        TileEdge.MovementType[,] pathTypes = new TileEdge.MovementType[tiles.Count, tiles.Count];
        for (int i = 0; i < N; ++i)
        {
            for (int j = 0; j < N; ++j)
            {
                path[i, j] = float.MaxValue;
            }
        }
        foreach (GameObject edge in tileEdges)
        {
            GameObject p0 = edge.GetComponent <TileEdge>().t0;
            GameObject p1 = edge.GetComponent <TileEdge>().t1;
            if (p0.GetComponent <Tile>().enabled&& p1.GetComponent <Tile>().enabled)
            {
                int id0 = IDs[p0];
                int id1 = IDs[p1];
                path[id0, id1]      = path[id1, id0] = Vector3.Distance(p0.transform.position, p1.transform.position);
                pathTypes[id0, id1] = pathTypes[id1, id0] = edge.GetComponent <TileEdge>().type;
            }
            //Debug.Log(p0 + " " + p1 + " " + id0 + " " + id1 + " " + edge.GetComponent<TileEdge>().type);
        }

        float[]    d       = new float[N];
        int[]      preTile = new int[N];
        List <int> queue   = new List <int>();

        bool[] inQueue = new bool[N];
        for (int i = 0; i < N; ++i)
        {
            inQueue[i] = false;
            preTile[i] = -1;
            d[i]       = float.MaxValue;
        }

        int startID = IDs[startTile];
        int endID   = IDs[endTile];

        int head = 0;
        int tail = 0;

        queue.Add(startID);
        inQueue[startID] = true;
        ++tail;
        d[startID] = 0;
        while (head < tail)
        {
            int o = queue[head];
            inQueue[o] = false;
            for (int i = 0; i < N; ++i)
            {
                if (d[i] > d[o] + path[o, i])
                {
                    d[i] = d[o] + path[o, i];
                    if (!inQueue[i])
                    {
                        queue.Add(i);
                        inQueue[i] = true;
                        ++tail;
                        preTile[i] = o;
                    }
                }
            }
            ++head;
        }

        if (d[endID] >= float.MaxValue)
        {
            return(false);
        }

        int curTile = endID;

        recentPath.InsertAtHead(endPos);
        while (curTile != -1)
        {
            if (preTile[curTile] == -1)
            {
                recentPath.InsertAtHead(tiles[curTile]);
            }
            else
            {
                //Debug.Log(curTile + " " + preTile[curTile] + " " + pathTypes[curTile, preTile[curTile]]);
                recentPath.InsertAtHead(tiles[curTile], pathTypes[curTile, preTile[curTile]]);
            }
            curTile = preTile[curTile];
        }
        recentPath.InsertAtHead(startPos);
        recentPath.isComplete = true;

        return(true);
    }
예제 #8
0
 public TilePathUnit(GameObject p, TileEdge.MovementType t)
 {
     tile     = p;
     pathType = t;
 }