Exemple #1
0
    public void GeneratePatrol(int num)
    {
        for (int i = 0; i < num; ++i)
        {
            IPatrolData patrolData = ScriptableObject.CreateInstance <IPatrolData>();
            patrolData.speed        = Random.Range(5f, 15f);
            patrolData.patrolPoints = pathGenerator.GetRandomRect();

            GameObject patrol = null;
            if (notUse.Count > 0)
            {
                patrol = notUse[0];
                notUse.RemoveAt(0);
            }
            else
            {
                patrolCount++;
                patrol      = Instantiate(patrolPrefab) as GameObject;
                patrol.name = "Patrol" + patrolCount.ToString();
            }
            patrol.GetComponent <IPatrol>().SetFromData(patrolData).ClearActions().InitialColor().InitialPosition().StartPatrol();

            patrol.GetComponent <IPatrol>().OnCatchPlayer    += GameEvents.CatchPlayer;
            patrol.GetComponent <IPatrol>().OnDiscoverPlayer += GameEvents.ChasePlayer;
            patrol.GetComponent <IPatrol>().OnDropPlayer     += GameEvents.DropPlayer;

            inUse.Add(patrol);
        }
    }
Exemple #2
0
 /**
  * Set patrol data from patrolData
  * @return patrol itself
  */
 public IPatrol SetFromData(IPatrolData data)
 {
     patrolPoints = data.patrolPoints;
     speed        = data.speed;
     discover     = false;
     dropOff      = false;
     return(this);
 }