예제 #1
0
    public void Load()
    {
        Width          = (int)Utility.Instance.Width;
        Height         = (int)Utility.Instance.Height;
        GlobalGrid     = new CC_GlobalCell[Width, Height];
        GlobalCellList = new List <CC_GlobalCell>();

        InitDebug();

        for (int x = 0; x < Width; x++)
        {
            for (int y = 0; y < Height; y++)
            {
                Vector2       coord    = new Vector2((float)x, (float)y);
                Vector3       WorldPos = Utility.Instance.CoordToVec3(x, y);
                CC_GlobalCell newGC    = new CC_GlobalCell(WorldPos, coord);
                GlobalGrid[x, y] = newGC;
                GlobalCellList.Add(newGC);
                SetUpDebug(x, y, WorldPos);
            }
        }


        AgentList = AgentManager.Instance.agentTransforms;
        AgentData = new List <CC_AgentData>();
        foreach (Transform obj in AgentList)
        {
            AgentData.Add(obj.GetComponent <CC_AgentData>());
        }
    }
예제 #2
0
    void Start()
    {
        // get map width/height
        Width  = (int)Utility.Instance.Width;
        Height = (int)Utility.Instance.Height;

        // initialize grid and cell list
        GlobalGrid     = new CC_GlobalCell[Width, Height];
        GlobalCellList = new List <CC_GlobalCell>();

        // set density min
        DensityMin = 1f / Mathf.Pow(2f, Lambda);

        InitDebug();

        // put data in global grid
        for (int x = 0; x < Width; x++)
        {
            for (int y = 0; y < Height; y++)
            {
                Vector2       coord    = new Vector2((float)x, (float)y);
                Vector3       WorldPos = Utility.Instance.CoordToVec3(x, y);
                CC_GlobalCell newGC    = new CC_GlobalCell(WorldPos, coord);
                GlobalGrid[x, y]        = newGC;
                GlobalGrid[x, y].Height = WorldPos.z;
                GlobalCellList.Add(newGC);
                SetUpDebug(x, y, WorldPos);
            }
        }

        // get agent data that pertains to contuum crowd data
        AgentList = AgentManager.Instance.agentTransforms;
        AgentData = new List <CC_AgentData>();
        foreach (Transform obj in AgentList)
        {
            AgentData.Add(obj.GetComponent <CC_AgentData>());
        }

        // set up group grid(s)
        GroupGridList = new List <CC_GridCell[, ]>();
        int agentPerGroup = AgentList.Count / GroupNumber;

        for (int i = 0; i < GroupNumber; i++)
        {
            GroupGridList.Add(new CC_GridCell[Width, Height]);
            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    Vector2 coord    = GlobalGrid[x, y].Coord;
                    Vector3 worldPos = GlobalGrid[x, y].WorldPos;
                    GroupGridList[i][x, y]       = new CC_GridCell(worldPos, coord);
                    GroupGridList[i][x, y].East  = new CellFaceInfo();
                    GroupGridList[i][x, y].West  = new CellFaceInfo();
                    GroupGridList[i][x, y].North = new CellFaceInfo();
                    GroupGridList[i][x, y].South = new CellFaceInfo();
                }
            }
        }

        // set up group height stuff
        for (int i = 0; i < GroupNumber; i++)
        {
            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    GroupGridList[i][x, y].East.DeltaHeight =
                        HeightDifference(x, y, Vector2.right);

                    GroupGridList[i][x, y].West.DeltaHeight =
                        HeightDifference(x, y, Vector2.left);

                    GroupGridList[i][x, y].North.DeltaHeight =
                        HeightDifference(x, y, Vector2.up);

                    GroupGridList[i][x, y].South.DeltaHeight =
                        HeightDifference(x, y, Vector2.down);
                }
            }
        }
    }