コード例 #1
0
    // Update is called once per frame
    public void InitializeAgent()
    {
        if (s_GameObjPool == null)
        {
            s_GameObjPool = new GameObjPool();
        }

        if (resElevator == null)
        {
            resElevator = (GameObject)Resources.Load("Elevator/elevator_unit");
        }

        if (resfloor == null)
        {
            resfloor = (GameObject)Resources.Load("Elevator/build_floor");
        }


        if (academy == null)
        {
            academy = FindObjectOfType <ElevatorAcademy>();
        }
    }
コード例 #2
0
    public void InitEnv()
    {
        if (s_GameObjPool == null)
        {
            s_GameObjPool = new GameObjPool();
        }

        if (resElevator == null)
        {
            resElevator = (GameObject)Resources.Load("Elevator/elevator_unit");
        }

        if (resfloor == null)
        {
            resfloor = (GameObject)Resources.Load("Elevator/build_floor");
        }

        if (academy == null)
        {
            academy = FindObjectOfType <ElevatorAcademy>();
        }


        callReqReserveCar = new Elevator[ElevatorAcademy.floors, 2];

        ElevatorPassenger.InitPooler();


        centerCtrlAgent = gameObject.GetComponent <ElevatorCtrlCenterAgent>();



        if (centerCtrlAgent != null)
        {
            resElevator.GetComponent <Elevator>().enabled = false;
        }


        //if (centerCtrlAgent == null)
        {
            var brainObj = academy.gameObject.transform.Find("ElevatorctrlBrain");

            if (brainObj)
            {
                elevatorBrain = brainObj.GetComponent <MLAgents.Brain>();
            }
        }



        restPassinger    = ElevatorAcademy.passinger;
        destPassinger    = 0;
        simulattion_time = 0;
        addPassinger     = 0;


        int dist = 4;
        int rest = ElevatorAcademy.elevatorCount % 2;
        int mok  = ElevatorAcademy.elevatorCount / 2;

        Vector3 startPos = transform.position;

        if (rest < 0.5f)
        {
            mok     -= 1;
            startPos = transform.position - (Vector3.right * dist * mok) - (Vector3.right * (dist / 2));
        }
        else
        {
            startPos = transform.position - (Vector3.right * dist * mok);
        }

        startPos += Vector3.back;


        for (int i = 0; i < ElevatorAcademy.elevatorCount; ++i)
        {
            if (i < listElve.Count)
            {
                listElve[i].Init();
                continue;
            }

            GameObject ele = (GameObject)Instantiate(resElevator, this.transform);

            ele.transform.position = startPos + (Vector3.right * dist * i);
            var el = ele.GetComponent <Elevator>();
            listElve.Add(el);
            el.InitFloor(i, ElevatorAcademy.floors);


            var agent = ele.GetComponent <Elevator>();
            agent.enabled = false;
            el.agent      = centerCtrlAgent;
        }

        for (int i = 0; i < ElevatorAcademy.floors; ++i)
        {
            if (i < listFloor.Count)
            {
                listFloor[i].Init();
                continue;
            }


            GameObject fl = (GameObject)Instantiate(resfloor, this.transform);
            fl.transform.position = transform.position + (Vector3.up * ElevatorAcademy.height * i);
            fl.GetComponent <Buildfloor>().SetFloor(i, this);
            listFloor.Add(fl.GetComponent <Buildfloor>());
        }

        startTime = Time.fixedTime;
    }
コード例 #3
0
    public void InitEnv()
    {
        if (s_GameObjPool == null)
        {
            s_GameObjPool = new GameObjPool();
        }

        if (resElevator == null)
        {
            resElevator = (GameObject)Resources.Load("Elevator/elevator_unit");
        }

        if (resfloor == null)
        {
            resfloor = (GameObject)Resources.Load("Elevator/build_floor");
        }

        if (academy == null)
        {
            academy = FindObjectOfType <ElevatorAcademy>();
        }


        callReqReserveCar = new ElevatorAgent[ElevatorAcademy.floors, 2];

        ElevatorPassenger.InitPooler();


        //if (elevatorBrain == null)
        //    elevatorBrain = academy.transform.Find("ElevatorBrain").GetComponent<Brain>();



        restPassenger    = ElevatorAcademy.passenger;
        destPassenger    = 0;
        simulattion_time = 0;
        addPassenger     = 0;
        scenario_index   = 0;


        int dist = 4;
        int rest = ElevatorAcademy.elevatorCount % 2;
        int mok  = ElevatorAcademy.elevatorCount / 2;

        Vector3 startPos = transform.position;

        if (rest < 0.5f)
        {
            mok     -= 1;
            startPos = transform.position - (Vector3.right * dist * mok) - (Vector3.right * (dist / 2));
        }
        else
        {
            startPos = transform.position - (Vector3.right * dist * mok);
        }

        startPos += Vector3.back;


        for (int i = 0; i < ElevatorAcademy.elevatorCount; ++i)
        {
            if (i < listElve.Count)
            {
                listElve[i].Init();
                continue;
            }

            GameObject ele = (GameObject)Instantiate(resElevator, this.transform);
            ele.transform.position = startPos + (Vector3.right * dist * i);

            var agent = ele.GetComponent <ElevatorAgent>();
            listElve.Add(agent);
            //agent.GiveBrain(elevatorBrain);
            agent.InitFloor(i, ElevatorAcademy.floors);
            //agent.agentParameters.agentCameras[0] = GameObject.Find("agent_cam").GetComponent<Camera>();
            agent.AgentReset();
        }

        for (int i = 0; i < ElevatorAcademy.floors; ++i)
        {
            if (i < listFloor.Count)
            {
                listFloor[i].Init();
                continue;
            }


            GameObject fl = (GameObject)Instantiate(resfloor, this.transform);
            fl.transform.position = transform.position + (Vector3.up * ElevatorAcademy.height * i);
            fl.GetComponent <Buildfloor>().SetFloor(i, this);
            listFloor.Add(fl.GetComponent <Buildfloor>());
        }

        startTime = Time.fixedTime;
    }