示例#1
0
        private void OnTriggerEnter(Collider other)
        {
            if (other.As <IUnitProperties>() == null)
            {
                return;
            }

            var unit = other.GetUnitFacade();

            if (unit == null)
            {
                return;
            }

            var grp = unit.transientGroup;

            if (grp == null)
            {
                return;
            }

            if (grp.currentWaypoints.count <= 1)
            {
                Vector3 lastPOI = _poiSource.GetPOI(this.transform.position);
                for (int i = 0; i < waypointIterations; i++)
                {
                    grp.MoveTo(lastPOI, true);
                    lastPOI = _poiSource.GetPOI(lastPOI);
                }
            }

            float lastChanged;

            if (_recentlyChanged.TryGetValue(grp, out lastChanged) && (Time.time - lastChanged) < 10f)
            {
                return;
            }

            _recentlyChanged[grp] = Time.time;

            var randomFormation = grp.currentFormation == null?GetFormation(Random.Range(0, 6)) : GetRandomFormation(grp.currentFormation);

            grp.SetFormation(randomFormation);
        }
        private void Start()
        {
            for (int i = 0; i < spawnPoints.Length; i++)
            {
                var randomColor = new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value);
                var grp         = new DefaultSteeringTransientUnitGroup(this.groupSize);
                for (int j = 0; j < this.groupSize; j++)
                {
                    var agent = Instantiate(this.agentMold, spawnPoints[i], Quaternion.identity) as GameObject;
                    agent.SetActive(true);
                    grp.Add(agent.GetUnitFacade());

                    var renderer = agent.GetComponent <Renderer>();
                    renderer.material.color = randomColor;
                }

                Vector3 lastPOI = _poiSource.GetPOI(Vector3.zero);
                for (int j = 0; j < waypointIterations; j++)
                {
                    grp.MoveTo(lastPOI, true);
                    lastPOI = _poiSource.GetPOI(lastPOI);
                }
            }
        }