コード例 #1
0
        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);
            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();
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        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();
        }