Ejemplo n.º 1
0
    // Use this for initialization
    void Awake()
    {
        //print("EF START!!!");

        EF = this;

        //Dont destroy me.
        DontDestroyOnLoad(this.gameObject);

        //Create the target pool.
        TargetPool = new List <PooledObject <Target> >();

        //Create the list for active targets
        ActiveTargetList = new List <Target>();

        //Create list for active cannons
        ActiveCannonList = new List <Cannon>();

        //Create the cannon pool.
        CannonPool = new List <PooledObject <Cannon> >();

        //Create a pool for each item in each list we want to pool.
        int TargetTypeIndex = 0;

        //Creating the pools for each targets.
        foreach (Target t in TargetCatalogue)
        {
            PooledObject <Target> pT = new PooledObject <Target>();

            //Add 3 of each to start off with.
            for (int i = 0; i < PreAllocatedTargetCount; i++)
            {
                Target temp = Instantiate(t, Vector3.zero, Quaternion.identity) as Target;

                //Set the target ID
                temp.ID = (TargetTypes)TargetTypeIndex;

                temp.transform.parent = transform;

                //Add to the pool.
                pT.AddItem(temp);

                temp.ForceDisable();
            }

            //Add the pooled object to the target pool.
            TargetPool.Add(pT);

            TargetTypeIndex++;
        }


        foreach (Cannon c in CannonCatalogue)
        {
            //Create a pool per cannon type.
            PooledObject <Cannon> pC = new PooledObject <Cannon>();

            //Add the pooled object to the cannon pool ist.
            CannonPool.Add(pC);
        }

        PUF = Instantiate(PUF) as PowerupFactory;
        PUF.transform.parent = transform;
    }