示例#1
0
    void Start()
    {
        // INITIALIZE NUMBER OF AGENTS
        if (GUI.Reset == false && GUI.SuggestedShapeSelected == false)
        {
            NumAgents = defaultNumAgents;    // Set Number of Agents to default Number: 120
        }
        // INITIALIZE DEFAULT GOAL SHAPE
        if (GUI.GoalShape == null)
        {
            GUI.GoalShape = DefaultShape;
        }

        GameObject GoalShape = Instantiate(GUI.GoalShape, new Vector3(0.05f, 0, 0.05f), Quaternion.identity);  //Pivot: bottom left corner

        GoalShape.layer = 8;
        shapePoints     = CM.PointsFromGeometry(GoalShape, Cell.CellSize).ToList();
        //if (GUI.SuggestedShapeSelected)
        NumAgents = shapePoints.Count;
        Destroy(GoalShape);



        // SET MAX ACTIVE AGENTS
        if (NumAgents < 100)
        {
            maxActiveAgents = 10;
        }
        else if (NumAgents > 1000)
        {
            maxActiveAgents = 100;
        }
        else
        {
            maxActiveAgents = NumAgents / 10;
        }



        // SET AREA PROPERTIES
        AreaMin = 0;
        if (NumAgents <= 50)
        {
            AreaMax = 2.5f;
        }
        else if (NumAgents > 750)
        {
            AreaMax = 7.5f;          // DO NOT EXCEED 500x500!
        }
        else
        {
            AreaMax = 5.0f;// NumAgents;
        }
        // INSTANTIATE EMPTY GRID OF CELLS
        grid = new CellGrid(AreaMin, AreaMax);

        // INSTANTIATE AGENTS
        agents = new Agents(grid, agentPrefab, Material, physicsMaterial, NumAgents);



        // INSTANTIATE LIST OF AGENTS (with different agent placement methods)
        //listAgents = agents.FillCellsWithAgents();  //Not in use
        //listAgents = agents.PlaceAgentsRandomly();  //Not in use
        //listAgents = agents.PlaceAgentsInGivenGeometry(shapePoints);         //Not in use
        //listAgents = agents.PlaceConnectedAgentsRandomly(new Vector3Int(1, 0, 1));   //Not in use

        //if ((int)Mathf.Ceil(Mathf.Sqrt(NumAgents)) < grid.AreaSize)
        listAgents = agents.PlaceAgentsIn2DRows(new Vector3Int(1, 0, 1));
        //else
        //    listAgents = agents.PlaceAgentsIn3DRows(new Vector3Int(1, 0, 1));



        // INSTANTIATE RECONFIGURATION RULES
        reconfiguration = new ReconfigurationRules(grid);

        //foreach (var item in shapePoints)
        //{
        //    Instantiate(agentPrefab, item, Quaternion.identity);
        //}
        //ModulesTest();
        //AddSupport();
        //AddJoints();



        //foo();



        //OptimizationAlgorithms Optimize = new OptimizationAlgorithms(grid, 30, 500);
        ////var l = Optimize.GenerateGoalShape(new List<Vector3Int>() { new Vector3Int(5, 0, 5), new Vector3Int(10, 0, 5), new Vector3Int(5, 0, 10), new Vector3Int(10, 0, 10) }, 90);
        //Optimize.SimulatedAnnealing(new List<Vector3Int>() { new Vector3Int(5, 0, 5), new Vector3Int(10, 0, 5), new Vector3Int(5, 0, 10), new Vector3Int(10, 0, 10) }, 90);
        //foreach (var cell in Optimize.bestCandidate)
        //    cell.GoalCell = true;



        //foreach (var item in shapePoints)
        //    Instantiate(agentPrefab, item, Quaternion.identity);
    }