Exemple #1
0
    public void UpdatePredators(List <PredatorData> listPredator)
    {
        for (int idx = 0; idx < listPredator.Count; idx++)
        {
            PredatorData data = listPredator[idx];
            int          fIdx = registeredPredator.FindIndex(x => x.predatorId.Equals(data.id));
            //Find the given data in the list. If it's not in the list, create new predator
            if (fIdx < 0)
            {
                GameObject         go      = predatorPool.GetGameObject(data.assetKeyword);
                PredatorController control = go.GetComponent <PredatorController>();
                //reset animation before deploying
                control.SetAnimationToMove();

                LayerController.Instance.SetFishLayer(go, 10);
                if (control == null)
                {
                    control = go.AddComponent <PredatorController>();
                }
                control.SetData(data);
                registeredPredator.Add(control);
//				Debug.Log ("predator id = "+data.id);
            }
            //When it's already in the list, just reset the data
            else
            {
                registeredPredator[fIdx].SetData(data);
            }
        }

        predatorUpdateCount += 1;
        //Clear food after 10 updates, to reduce procesing cost
        if (predatorUpdateCount >= 10)
        {
            ClearPredator(listPredator);
            predatorUpdateCount = 0;
        }
    }