Пример #1
0
    /// <summary>
    /// Adds a pedestrian to the simulation
    /// </summary>
    public void AddPedestrian()
    {
        // Yes, it is a hack. Deal with it
        if (!mPedestriansParent)
        {
            mPedestriansParent      = new GameObject();
            mPedestriansParent.name = "Pedestrians";
        }

        GameObject pedestrian = GameObject.Instantiate(PedestrianPrefab);

        pedestrian.name = "AIPedestrian_" + mAgents.Count;
        pedestrian.transform.SetParent(mPedestriansParent.transform);
        Vector3 position = AStarSearch.GetRandomWaypoint(WaypointsExample.PedestriansGraph);

        position.y = 0.0f;
        pedestrian.transform.position = position;

        // Init the pedestrian behaviour
        pedestrian.GetComponent <PedestrianBehavior>().Init();
        pedestrian.GetComponent <NN.NeuralNetwork>().Init();

        if (mNNController == null)
        {
            mNNController = GameObject.FindGameObjectWithTag("Neural Network Controller").GetComponent <NN.NeuralNetwork>();
            mNNController.Init();
        }

        pedestrian.GetComponent <NN.NeuralNetwork>().SetConnectionWeights(mNNController.GetConnectionWeights());
        mAgents.Add(pedestrian.GetComponent <PedestrianBehavior>());
    }
Пример #2
0
    // Call this function whenever the game is ready, to start updating the GameObject
    public void Init()
    {
        mState      = PedestrianState.kPedestrianState_Searching;
        mLeader     = null;
        mNeighbours = new List <GameObject>();
        RigidBody   = gameObject.GetComponent <Rigidbody>();
        Velocity    = transform.forward;

        mNN           = this.GetComponent <NN.NeuralNetwork>();
        mNNController = GameObject.FindGameObjectWithTag("Neural Network Controller").GetComponent <NN.NeuralNetwork>();

        ConvertToLeader(StartAsLeader);

        //Begin updating the GameObject
        mInitialized = true;
    }