IEnumerator _Coro_FishGenerating() { WeightTotal_FishGenerate = 0; foreach (FishGenerateData d in FishGenerateDatas) { WeightTotal_FishGenerate += d.Weight; d.HittedWeight = WeightTotal_FishGenerate; } while (true) { if (GameMain.Singleton.NumFishAlive >= MaxFishAtWorld) { goto TAG_NextGenerateWait; } //随机 int curWeight = Random.Range(0, WeightTotal_FishGenerate); Fish prefabFishToGen = null; foreach (FishGenerateData fd in FishGenerateDatas) { if (curWeight < fd.HittedWeight) { prefabFishToGen = fd.Prefab_Fish; break; } } if (prefabFishToGen == null) { goto TAG_NextGenerateWait; } //Fish f = Pool_GameObj.GetObj(prefabFishToGen.gameObject).GetComponent<Fish>(); Fish f = Instantiate(prefabFishToGen) as Fish; f.name = prefabFishToGen.name; Vector2 interectPot; Vector2 rndPos = RndPosInWorldRect(); rndPos.Normalize(); if (InterectWorldRectWithOriginRay(rndPos, out interectPot)) { Vector3 posInstance = interectPot + rndPos * (f.swimmer.BoundCircleRadius); posInstance.z = Defines.GMDepth_Fish + ApplyFishDepth(); f.transform.parent = transform; f.transform.localPosition = posInstance; //fe.transform.right = -rndPos /*+ ((Vector2)Random.onUnitSphere).normalized * 0.5F*/; f.transform.rotation = PubFunc.RightToRotation(-rndPos); f.swimmer.Go(); } TAG_NextGenerateWait: yield return(new WaitForSeconds(Interval_FishGenerate.Value)); } }
IEnumerator _Coro_FishFlockGenerating() { if (Prefab_FishEmitterFlock == null) { yield break; } while (true) { if (GameMain.Singleton.NumFishAlive >= MaxFishAtWorld) { goto TAG_NextGenerateWait; } FishEmitter_Flock fe = Instantiate(Prefab_FishEmitterFlock) as FishEmitter_Flock; Vector2 interectPot; Vector2 rndPos = RndPosInWorldRect(); rndPos.Normalize(); if (InterectWorldRectWithOriginRay(rndPos, out interectPot)) { Vector3 posInstance = interectPot + rndPos * (fe.Radius); fe.transform.parent = transform; fe.transform.localPosition = posInstance; //fe.transform.right = -rndPos /*+ ((Vector2)Random.onUnitSphere).normalized * 0.5F*/; fe.transform.rotation = PubFunc.RightToRotation(-rndPos); fe.Generate(); } TAG_NextGenerateWait: yield return(new WaitForSeconds(Interval_FlockGenerate.Value)); } }
IEnumerator _Coro_Process() { yield return(0); // //求出最大鲨鱼半径 // foreach (Fish f in Prefab_Fish) // { // if (f.swimmer.BoundCircleRadius > mMaxSharkRadius) // mMaxSharkRadius = f.swimmer.BoundCircleRadius; // } //随机左右边 bool isLeft = Random.Range(0, 2) == 0; float elapse = 0F; int emitSharkIdx = 0; while (elapse < TimeEmitShark) { Fish shark = Instantiate(Prefab_Fish[emitSharkIdx]) as Fish; Rect worldDim = GameMain.Singleton.WorldDimension; Vector3 generatorPot = new Vector3(isLeft ? worldDim.x - shark.swimmer.BoundCircleRadius : worldDim.xMax + shark.swimmer.BoundCircleRadius //x , Random.Range(EmitLineUpLimit, EmitLineDownLimit) //y , 0F); emitSharkIdx = (emitSharkIdx + 1) % Prefab_Fish.Length; shark.ClearAi(); shark.swimmer.Speed = SpeedShark; shark.transform.parent = transform; //shark.transform.rotation = Quaternion.AngleAxis((isLeft?0F:180F)+Random.Range(-AngleGenerateShark,AngleGenerateShark),Vector3.forward); shark.transform.rotation = isLeft ? Quaternion.identity : PubFunc.RightToRotation(-Vector3.right); var depth = App.GetGameData <FishGameData>().ApplyFishDepth(shark.swimmer.SwimDepth); generatorPot.z = depth; shark.transform.localPosition = generatorPot; shark.swimmer.Go(); float delta = Random.Range(IntervalGenerateSharkMin, IntervalGenerateSharkMax); elapse += delta; yield return(new WaitForSeconds(delta)); } float swimNeedTime = GameMain.Singleton.WorldDimension.width / SpeedShark;//todo 不准确 yield return(new WaitForSeconds(swimNeedTime)); //等待清鱼,改用时间限制 while (GameMain.Singleton.NumFishAlive != 0) { yield return(0); } EndPrelude(); }
//public Transform tmpTsEmitFishPot; IEnumerator _Coro_FishQueueGenerating() { WeightTotal_QueuGenerate = 0; foreach (FishQueueGenerateData d in FishQueueData) { WeightTotal_QueuGenerate += d.Weight; d.HittedWeight = WeightTotal_QueuGenerate; } while (true) { if (GameMain.Singleton.NumFishAlive >= MaxFishAtWorld) { goto TAG_NextGenerateWait; } //随机 int curWeight = Random.Range(0, WeightTotal_QueuGenerate); int queueIdx = 0; for (; queueIdx != FishQueueData.Length; ++queueIdx) { if (curWeight < FishQueueData[queueIdx].HittedWeight) { break; } } if (queueIdx >= FishQueueData.Length) { goto TAG_NextGenerateWait; } FishEmitter_Queue fg = Instantiate(FishQueueData[queueIdx].Prefab_Queue) as FishEmitter_Queue; Vector2 interectPot; Vector2 rndPos = Random.onUnitSphere; rndPos.Normalize(); if (InterectWorldRectWithOriginRay(rndPos, out interectPot)) { Vector3 posInstance = interectPot + rndPos * (fg.Prefab_Fish.swimmer.BoundCircleRadius); fg.transform.parent = transform; fg.transform.localPosition = posInstance; //fg.transform.right = -rndPos /*+ ((Vector2)Random.onUnitSphere).normalized * 0.5F*/; fg.transform.rotation = PubFunc.RightToRotation(-rndPos); fg.Generate(); } TAG_NextGenerateWait: yield return(new WaitForSeconds(Interval_QueuGenerate.Value)); } }
/// <summary> /// 设置生产位置 /// </summary> /// <param name="bound"></param> /// <param name="depth"></param> public virtual BirthHole CreateBirthHole(float bound, float depth) { var hole = new BirthHole(); Vector2 interectPot; Vector2 rndPos = Random.onUnitSphere; Generator.InterectWorldRectWithOriginRay(rndPos, out interectPot); Vector3 posInstance = interectPot + rndPos * (bound); hole.Parent = Generator.transform; var z = App.GetGameData <FishGameData>().ApplyFishDepth(depth); posInstance.z = z; hole.Position = posInstance; hole.Rotation = PubFunc.RightToRotation(-rndPos + new Vector2(Random.Range(-0.5f, 0.5f), Random.Range(-0.5f, 0.5f))); return(hole); }
IEnumerator _Coro_FishUniqueGenerating() { if (FishGenerateUniqueDatas.Length == 0) { yield break; } WeightTotal_FishUniqueGenerate = 0; foreach (FishGenerateData d in FishGenerateUniqueDatas) { WeightTotal_FishUniqueGenerate += d.Weight; d.HittedWeight = WeightTotal_FishUniqueGenerate; } while (true) { if (GameMain.Singleton.NumFishAlive >= MaxFishAtWorld) { goto TAG_NextGenerateWait; } if (mUniqueFishToGenerate.Count == 0) { List <FishGenerateData> tmpFishGdLst = new List <FishGenerateData>(); foreach (FishGenerateData fgd in FishGenerateUniqueDatas) { tmpFishGdLst.Add(fgd); } tmpFishGdLst.Sort((FishGenerateData a, FishGenerateData b) => { return(Random.Range(0, a.Weight) < Random.Range(0, b.Weight) ? 1 : -1); }); int gdNum = FishGenerateUniqueDatas.Length * 7 / 10;//队列70%的鱼 foreach (FishGenerateData fgd in tmpFishGdLst) { mUniqueFishToGenerate.Enqueue(fgd.Prefab_Fish); if (--gdNum < 0) { break; } //Debug.Log(fgd.Prefab_Fish.name); } } Fish prefabFishToGen = mUniqueFishToGenerate.Dequeue(); if (FishTypeIndexMap[prefabFishToGen.TypeIndex] != null && FishTypeIndexMap[prefabFishToGen.TypeIndex].Count != 0) { goto TAG_NextGenerateWait; } Fish f = Instantiate(prefabFishToGen) as Fish; f.name = prefabFishToGen.name; Vector2 interectPot; Vector2 rndPos = RndPosInWorldRect(); rndPos.Normalize(); if (InterectWorldRectWithOriginRay(rndPos, out interectPot)) { Vector3 posInstance = interectPot + rndPos * (f.swimmer.BoundCircleRadius); posInstance.z = Defines.GMDepth_Fish + ApplyFishDepth(); f.transform.parent = transform; f.transform.localPosition = posInstance; //f.transform.right = -rndPos + ((Vector2)Random.onUnitSphere).normalized * 0.2F; f.transform.rotation = PubFunc.RightToRotation(-rndPos + ((Vector2)Random.onUnitSphere).normalized * 0.2F); f.swimmer.Go(); } TAG_NextGenerateWait: yield return(new WaitForSeconds(Interval_FishUniqueGenerate.Value)); } }