IEnumerator _Coro_CenterFishGenerateAndMove(int circleIdx) { float elapse = 0F; float rotateSpeed = 6.283185F / OneCircleTime;//弧度/s float useTime = OneCircleTime * mRunRound + CenterFishRunoutTime[circleIdx]; Fish fishCenter = Instantiate(Prefabs_FishCenter[circleIdx]) as Fish; Swimmer centerSwimmer = fishCenter.swimmer; fishCenter.ClearAI(); fishCenter.transform.parent = transform; fishCenter.transform.localPosition = new Vector3(Locals_Center[circleIdx].x, Locals_Center[circleIdx].y, Locals_Center[circleIdx].z - 0.1F); fishCenter.transform.localRotation = Quaternion.identity; centerSwimmer.RotateSpd = 6.283185F; while (elapse < useTime) { if (centerSwimmer == null || fishCenter == null || !fishCenter.Attackable)//暂时用attackable来确定鱼死亡 { break; } //中间鱼转动 centerSwimmer.transform.localRotation = Quaternion.AxisAngle(Vector3.forward, centerSwimmer.RotateSpd); centerSwimmer.RotateSpd -= rotateSpeed * Time.deltaTime; elapse += Time.deltaTime; yield return(0); } if (centerSwimmer != null) { centerSwimmer.Speed = FishRunoutSpeed * 0.7F; centerSwimmer.Go(); } }
void _Coro_GenerateFish(int circleIdx, int lineIdx) { //Vector3 newPos = new Vector3(DataGenFish[lineIdx].EllipseA * Mathf.Cos(f.RotateSpd), DataGenFish[lineIdx].EllipseA * 0.75F * Mathf.Sin(f.RotateSpd), 0F); //f.transform.localPosition = newPos; //f.transform.localRotation = Quaternion.AngleAxis(-90F + f.RotateSpd * Mathf.Rad2Deg, Vector3.forward); //f.RotateSpd -= rotateSpeed * Time.deltaTime; GenerateData gd = DataGenFishs[circleIdx].GDs[lineIdx]; float rotateRadAdvance = 6.283185F / gd.NumToGenerate; //递增弧度 float curRotateRad = 6.283185F; //当前旋转 FishGenerator fishGenerator = GameMain.Singleton.FishGenerator; float depthFish = 1F; //生成条数 for (int i = 0; i != gd.NumToGenerate; ++i) { Fish f = Instantiate(gd.Prefab_Fish) as Fish; Swimmer s = f.swimmer; f.ClearAI(); //f.AniSprite.clipTime = 0F; f.AniSprite.Play(); s.RotateSpd = curRotateRad;//使用旋转速度记录当前已转动角度,转向:360到0度 s.transform.parent = transform; s.transform.localPosition = Locals_Center[circleIdx] + new Vector3(gd.EllipseA * Mathf.Cos(s.RotateSpd), gd.EllipseA /** 0.75F*/ * Mathf.Sin(s.RotateSpd), depthFish); depthFish += 0.1F; s.transform.localRotation = Quaternion.AngleAxis(-90F + s.RotateSpd * Mathf.Rad2Deg, Vector3.forward); curRotateRad -= rotateRadAdvance; mAllSwimmer[circleIdx][lineIdx].Add(s); } }
void Update() { if (m_BornDim.Contains(mTs.position)) //进入生成区域 { Fish f = Instantiate(Prefab_Fish) as Fish; if (IsClearAI) { f.ClearAI(); } f.swimmer.SetLiveDimension(10000); f.AniSprite.playAutomatically = false; f.AniSprite.PlayFrom(f.AniSprite.DefaultClip, Time.time); f.gameObject.AddComponent <FishDimenSetWhenEnterWorld>(); f.transform.parent = mTs.parent; f.transform.localPosition = new Vector3(mTs.localPosition.x, mTs.localPosition.y, mTs.localPosition.z); f.transform.localRotation = mTs.localRotation; f.transform.localScale = mTs.localScale; SendMessage("Msg_FishGenerateWhenEnterWorld_Generated", f, SendMessageOptions.DontRequireReceiver); if (EvtFishGenerated != null) { EvtFishGenerated(f); } Destroy(gameObject); } }
IEnumerator _Coro_GenerateDelay(GenerateData gd) { yield return(new WaitForSeconds(gd.Delay)); // Rect worldDim = GameMain.Singleton.WorldDimension; float elapse = 0F; while (elapse < gd.Elapse) { Fish f = Instantiate(gd.Prefab_Fish) as Fish; Swimmer s = f.swimmer; f.transform.localPosition = new Vector3(GetRndLineX() , gd.IsUp? (worldDim.yMax + s.BoundCircleRadius) :(worldDim.yMin - s.BoundCircleRadius) , Defines.GMDepth_Fish + mFishDepthOffset); mFishDepthOffset -= 0.025F; if (mFishDepthOffset < -100F) { mFishDepthOffset = 0F; } f.transform.localRotation = gd.IsUp ? TowardDownRotation : TowardUpRotation; f.ClearAI(); f.swimmer.Speed = FishMoveSpd; f.swimmer.Go(); elapse += gd.IntervalGenerate / NumScreen; yield return(new WaitForSeconds(gd.IntervalGenerate / NumScreen)); } }
IEnumerator _Coro_Process() { yield return(0); StartCoroutine("_Coro_LaJiaoGenerating"); // //求出最大鲨鱼半径 // foreach (Fish f in Prefab_Sharks) // { // 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_Sharks[emitSharkIdx]) as Fish; Vector3 generatorPot = new Vector3(isLeft ? GameMain.Singleton.WorldDimension.x - shark.swimmer.BoundCircleRadius : GameMain.Singleton.WorldDimension.xMax + shark.swimmer.BoundCircleRadius , 0F, 0F); emitSharkIdx = (emitSharkIdx + 1) % Prefab_Sharks.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); generatorPot.z = Defines.GlobleDepth_FishBase + mDepthOffset; mDepthOffset -= Defines.OffsetAdv_FishGlobleDepth; 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)); StopCoroutine("_Coro_LaJiaoGenerating"); StartCoroutine(_Coro_WaitNullFish()); ////等待清鱼,改用时间限制 //while (GameMain.Singleton.NumFishAlive != 0) //{ // yield return 0; //} //EndPrelude(); }
IEnumerator _Coro_GenerateFish(int circleIdx, int lineIdx) { //Vector3 newPos = new Vector3(DataGenFish[lineIdx].EllipseA * Mathf.Cos(f.RotateSpd), DataGenFish[lineIdx].EllipseA * 0.75F * Mathf.Sin(f.RotateSpd), 0F); //f.transform.localPosition = newPos; //f.transform.localRotation = Quaternion.AngleAxis(-90F + f.RotateSpd * Mathf.Rad2Deg, Vector3.forward); //f.RotateSpd -= rotateSpeed * Time.deltaTime; GenerateData gd = DataGenFishs[circleIdx].GDs[lineIdx]; //float rotateRadAdvance = 6.283185F / gd.NumToGenerate;//递增弧度 //float curRotateRad = 6.283185F;//当前旋转 //FishGenerator fishGenerator = GameMain.Singleton.FishGenerator; float depthFish = 0F; float elapse = 0F; //float clipTime = 0F; float generateInterval = OneCircleTime / gd.NumToGenerate;//为了不重叠生成多一条 //生成条数 for (int i = 0; i != gd.NumToGenerate; ++i) { Fish f = Instantiate(gd.Prefab_Fish) as Fish; Swimmer s = f.swimmer; f.ClearAI(); //f.AniSprite.clipTime = elapse; //f.AniSprite.Play(elapse); f.AniSprite.PlayFrom(f.AniSprite.DefaultClip, elapse); //s.RotateSpd = curRotateRad;//使用旋转速度记录当前已转动角度,转向:360到0度 s.RotateSpd = 6.283185F; s.transform.parent = transform; //s.transform.localPosition = Locals_Center[circleIdx] // + new Vector3(gd.EllipseA * Mathf.Cos(s.RotateSpd), gd.EllipseA /** 0.75F*/ * Mathf.Sin(s.RotateSpd), depthFish); s.transform.localPosition = Locals_Center[circleIdx] + new Vector3(gd.EllipseA, 0F, depthFish); depthFish -= 0.005F; //s.transform.localRotation = Quaternion.AngleAxis(-90F + s.RotateSpd * Mathf.Rad2Deg, Vector3.forward); s.transform.rotation = Quaternion.AngleAxis(-90F, Vector3.forward); //curRotateRad -= rotateRadAdvance; mAllSwimmer[circleIdx][lineIdx].Add(s); elapse += generateInterval; yield return(new WaitForSeconds(generateInterval)); } }
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); generatorPot.z = Defines.GlobleDepth_FishBase + GameMain.Singleton.FishGenerator.ApplyFishDepth(); 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(); }
IEnumerator _Coro_Process() { //散花出鱼 int flowEmitNum = FlowerEmitDatas.Length; int curflowEmitNum = 0; float baseRotateAngle = 90F; float depth = 0F; while (curflowEmitNum < flowEmitNum) { FlowerEmitData emitData = FlowerEmitDatas[curflowEmitNum]; //float emitElapse = 0F; float angleLineDelta = 360F / emitData.NumLine; //一群 //while (emitElapse < emitData.EmitUseTime) { //6方向一起出 for (int i = 0; i != emitData.NumLine; ++i) { Fish f = Instantiate(emitData.PrefabFish) as Fish; f.ClearAI(); f.transform.parent = transform; f.transform.localRotation = Quaternion.AngleAxis(baseRotateAngle + angleLineDelta * i /*+ Random.Range(-15F, 15F)*/, Vector3.forward); f.transform.localPosition = new Vector3(0F, 0F, depth) + f.transform.up * OffsetYInitPos; depth += 0.001F; f.swimmer.Speed = emitData.SwimSpd; f.swimmer.Go(); } //emitElapse += emitData.EmitInterval; //yield return new WaitForSeconds(emitData.EmitInterval); yield return(new WaitForSeconds(emitData.EmitCooldown)); } baseRotateAngle += 45F; ++curflowEmitNum; yield return(new WaitForSeconds(1F)); } //等待清鱼,[过期]改用时间作限制 while (GameMain.Singleton.NumFishAlive != 0) { yield return(0); } EndPrelude(); }
IEnumerator _Coro_Generate() { int num = Random.Range(NumMin, NumMax + 1); int generatedNum = 0; yield return(0);//为取得transform.localPosition //生成leaderFish GameObject goLeader = new GameObject("领队_" + Prefab_Fish.name); Swimmer fishLeader = goLeader.AddComponent <Swimmer>(); goLeader.AddComponent <DestroyWhenSwimmerOut>(); if (GameMain.EvtLeaderInstance != null) { GameMain.EvtLeaderInstance(fishLeader); } //fishLeader.Attackable = false; Prefab_Fish.swimmer.CopyDataTo(fishLeader); fishLeader.SetLiveDimension(Defines.ClearFishRadius);//swim to fix fishLeader.RotateSpd = Fish_RotateSpd; fishLeader.Speed = Fish_Speed; FishAI_FreeSwimSingle fishAILeader = goLeader.AddComponent <FishAI_FreeSwimSingle>(); Prefab_Fish.GetComponent <FishAI_FreeSwimSingle>().CopyDataTo(fishAILeader); fishAILeader.enabled = false; fishAILeader.RotateAngleRndRange = Fish_RotateAngleRndRange; fishAILeader.RotateInterval = Fish_RotateInterval; fishAILeader.RotateIntervalRndRange = Fish_RotateIntervalRndRange; fishLeader.transform.parent = GameMain.Singleton.FishGenerator.transform; Vector3 localPos = transform.localPosition; localPos.z = Defines.GMDepth_Fish + GameMain.Singleton.FishGenerator.ApplyFishDepth(); fishLeader.transform.localPosition = localPos; fishLeader.transform.localRotation = transform.localRotation; fishLeader.Go(); Fish preFish = null; float distanceToLeader = 0F; while (generatedNum < num) { yield return(new WaitForSeconds((Distance + fishLeader.BoundCircleRadius * 2F) / fishLeader.Speed)); if (fishLeader == null) { break; } Fish f = Instantiate(Prefab_Fish) as Fish; Swimmer s = f.swimmer; f.name = Prefab_Fish.name; s.RotateSpd = Fish_RotateSpd; s.Speed = Fish_Speed; //动画设置 if (preFish != null) { //f.AniSprite.clipTime = preFish.AniSprite.clipTime; //f.AniSprite.Play(preFish.AniSprite.ClipTimeSeconds); f.AniSprite.PlayFrom(f.AniSprite.DefaultClip, preFish.AniSprite.ClipTimeSeconds); } //删除所有其他ai f.ClearAI(); FishAI_Follow aiFollow = f.gameObject.AddComponent <FishAI_Follow>(); aiFollow.SetTarget(fishLeader); distanceToLeader += (Distance + fishLeader.BoundCircleRadius * 2F); aiFollow.DistanceToLeader = distanceToLeader; //方位设置 f.transform.parent = GameMain.Singleton.FishGenerator.transform; localPos = transform.localPosition; localPos.z = Defines.GMDepth_Fish + GameMain.Singleton.FishGenerator.ApplyFishDepth(); f.transform.localPosition = localPos; f.transform.localRotation = transform.localRotation; s.Go(); ++generatedNum; preFish = f; } yield return(0); if (fishAILeader != null) { fishAILeader.enabled = true; } Destroy(gameObject); }
public int NumMin = 4; //最少生成个数 //void Awake() //{ // //if (GameMain.EvtStopGenerateFish != null) // // Debug.Log("s GameMain.EvtStopGenerateFish.length = " + GameMain.EvtStopGenerateFish.GetInvocationList().Length); // GameMain.EvtStopGenerateFish += Handle_StopGenerateFish; //} //void OnDestroy() //{ // //Debug.Log("destroy"); // if(GameMain.EvtStopGenerateFish != null) // Debug.Log("GameMain.EvtStopGenerateFish.length = " + GameMain.EvtStopGenerateFish.GetInvocationList().Length); //} //void Handle_StopGenerateFish() //{ // //StopCoroutine("_Coro_Generate"); // //GameMain.EvtStopGenerateFish -= Handle_StopGenerateFish; // //Destroy(gameObject); //} //public void Generate() //{ // StartCoroutine("_Coro_Generate"); //} public void Generate() { int num = Random.Range(NumMin, NumMax + 1); int generatedNum = 0; //yield return 0;//为取得transform.localPosition Swimmer leader = null; //Swimmer[] allSwimmer = new Swimmer[num]; while (generatedNum < num) { Swimmer s = null; if (generatedNum == 0) { GameObject goLeader = new GameObject("领队_" + Prefab_Fish.name); leader = goLeader.AddComponent <Swimmer>(); s = leader; if (GameMain.EvtLeaderInstance != null) { GameMain.EvtLeaderInstance(leader); } goLeader.AddComponent <DestroyWhenSwimmerOut>(); Prefab_Fish.swimmer.CopyDataTo(leader); } else { Fish f = Instantiate(Prefab_Fish) as Fish; s = f.swimmer; f.name = Prefab_Fish.name; //删除所有其他ai f.ClearAI(); FishAI_Flock aiFollow = f.gameObject.AddComponent <FishAI_Flock>(); aiFollow.SetLeader(leader); } s.gameObject.AddComponent <FishDimenSetWhenEnterWorld>(); //allSwimmer[generatedNum] = s; s.SetLiveDimension(Radius / s.BoundCircleRadius * 2F); Transform tsSwimmer = s.transform; tsSwimmer.parent = GameMain.Singleton.FishGenerator.transform; Vector3 localPos = Random.insideUnitCircle * (Radius - s.BoundCircleRadius); localPos = transform.localPosition + localPos; localPos.z = Defines.GMDepth_Fish + GameMain.Singleton.FishGenerator.ApplyFishDepth(); tsSwimmer.localPosition = localPos; tsSwimmer.localRotation = transform.localRotation /* * Quaternion.AngleAxis(Random.Range(-AngleRndInit,AngleRndInit),Vector3.forward)*/; //f.transform.right = Vector3.zero - transform.localPosition; s.Go(); ++generatedNum; //yield return 0;//不连续创建 } //int fishLiveDimSetted = 0; //while (fishLiveDimSetted < num) //{ // for (int i = 0; i != num;++i ) // { // if (allSwimmer[i] != null && allSwimmer[i].IsInWorld()) // { // allSwimmer[i].SetLiveDimension(Defines.ClearFishRadius); // allSwimmer[i] = null; // ++fishLiveDimSetted; // } // } // yield return new WaitForSeconds(0.3F); //} //GameMain.EvtStopGenerateFish -= Handle_StopGenerateFish; Destroy(gameObject); }
IEnumerator _Coro_Process() { tk2dSpriteAnimation s; //云母出现 AniSpr_YunMu.AnimationEventTriggered += Handle_YunMuAnimating; //出蝴蝶鱼 米字 方向45度一格 int hudieNum = 3; int hudieInstedNum = 0; int[] rndArray = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }; System.Array.Sort(rndArray, (a, b) => { return(Random.Range(0, 3) - 1); }); while (hudieInstedNum < hudieNum) { yield return(new WaitForSeconds(1F)); Fish fishHuDie = Instantiate(Prefab_FirstFish) as Fish; fishHuDie.ClearAI(); fishHuDie.transform.parent = transform; fishHuDie.transform.localPosition = Vector3.zero; fishHuDie.transform.rotation = Quaternion.AngleAxis(45F * rndArray[hudieInstedNum], Vector3.forward); //特殊版本最后一条蝴蝶方向偏移 if (hudieInstedNum == hudieNum - 1) { fishHuDie.transform.rotation *= Quaternion.AngleAxis(-15F, Vector3.forward); } fishHuDie.swimmer.Go(); fishHuDie.swimmer.Speed = SpeedFirstFish; ++hudieInstedNum; } //云母fadeOut yield return(new WaitForSeconds(1F)); StartCoroutine(_Coro_YunMuAlphaDown()); //散花出鱼 int flowEmitNum = FlowerEmitDatas.Length; int curflowEmitNum = 0; //rndArray = new int[FlowerEmitDatas.Length]; //for(int i = 0; i != rndArray.Length; ++i) // rndArray[i] = i; //System.Array.Sort(rndArray,(a,b)=>{return Random.Range(0,3)-1;}); float baseRotateAngle = 90F; float depth = 0F; while (curflowEmitNum < flowEmitNum) { FlowerEmitData emitData = FlowerEmitDatas[curflowEmitNum]; float emitElapse = 0F; //一群 while (emitElapse < emitData.EmitUseTime) { //6方向一起出 for (int i = 0; i != 6; ++i) { Fish f = Instantiate(emitData.PrefabFish) as Fish; f.ClearAI(); f.transform.parent = transform; f.transform.localRotation = Quaternion.AngleAxis(baseRotateAngle + 60F * i + Random.Range(-15F, 15F), Vector3.forward); f.transform.localPosition = new Vector3(0F, 0F, depth) + f.transform.up * 0.02F; depth += 0.001F; f.swimmer.Speed = emitData.SwimSpd; f.swimmer.Go(); } emitElapse += emitData.EmitInterval; yield return(new WaitForSeconds(emitData.EmitInterval)); } baseRotateAngle += 45F; ++curflowEmitNum; yield return(new WaitForSeconds(1F)); } //等待清鱼,[过期]改用时间作限制 while (GameMain.Singleton.NumFishAlive != 0) { yield return(0); } EndPrelude(); }