public void ReturnFlockInSwarmToHive(SwarmTravelController swarmCtrl) { UnityFlock flock = swarmCtrl.UnregisterRandomFlock(); if (flock == null) { return; } originSwarm.RegisterFlock(flock); //foreach(UnityFlock flock in swarm) }
//public void SetDestinationSwarm(int indexSwarm) //{ // if (indexSwarm < swarmControllers.Count) // { // print("SetDestinationSwarm: " + indexSwarm.ToString()); // destinationSwarm = swarmControllers[indexSwarm]; // } //} public void SendFlockBetweenSwarms() { print("swarms count:" + swarmControllers.Count); UnityFlock flock = originSwarm.UnregisterRandomFlock(); if (flock == null) { return; } destinationSwarm.RegisterFlock(flock); print("flock A:" + originSwarm.flockTransforms.Count.ToString()); print("flock B:" + destinationSwarm.flockTransforms.Count.ToString()); OnHomeWorkerCountChange.Invoke(originSwarm.flockBehaviors.Count); }
// there is a fixed number of bees // allocate all swarm arrays for the max number of bees // Use this for initialization void Start() { travelOrigin = null; randomFreq = 1.0f / randomFreq;//获取随机变化的频率 //设置父节点为origin origin = transform.parent; transformCompont = transform; //临时组件数组 Component[] tempFlocks = null; if (transform.parent) { tempFlocks = transform.parent.GetComponentsInChildren <UnityFlock>(); } // objects=new Transform[tempFlocks.Length]; // otherFlocks=new UnityFlock[tempFlocks.Length]; // //将群体的位置信息和群体加载到数组 //for (int i = 0; i < tempFlocks.Length; i++) //{ // objects[i] = tempFlocks[i].transform; // otherFlocks[i] = (UnityFlock)tempFlocks[i]; //} int maxBees = 4; travelOrigin = transform.parent.GetComponent <SwarmTravelController>(); for (int i = 0; i < tempFlocks.Length; i++) { travelOrigin.RegisterFlock((UnityFlock)tempFlocks[i]); } // parent to root level in game world transform.parent = GameObject.Find("GameWorld").transform; StartCoroutine(UpdateRandom()); }