Exemplo n.º 1
0
        protected override IEnumerator OnGenerate()
        {
            var num         = Random.Range(NumMin, NumMax + 1);
            var headSwimmer = gameObject.AddComponent <Swimmer>();
            var gdata       = App.GetGameData <FishGameData>();

            if (gdata.EvtLeaderInstance != null)
            {
                gdata.EvtLeaderInstance(headSwimmer);
            }
            gameObject.AddComponent <DestroyWhenSwimmerOut>();
            Prefab_Fish.swimmer.CopyDataTo(headSwimmer);
            headSwimmer.gameObject.AddComponent <FishDimenSetWhenEnterWorld>();
            headSwimmer.SetLiveDimension(Radius / headSwimmer.BoundCircleRadius * 2F);
            var hole = KindGenerator.CreateBirthHole(Radius, headSwimmer.SwimDepth);

            SetSwimmer(headSwimmer, hole);
            headSwimmer.Go();

            for (var i = 0; i < num; i++)
            {
                var f = Instantiate(Prefab_Fish);
                var s = f.swimmer;
                f.name = Prefab_Fish.name;
                //删除所有其他ai
                f.ClearAi();
                var aiFollow = f.gameObject.AddComponent <FishAI_Flock>();
                aiFollow.SetLeader(headSwimmer);
                SetSwimmer(s, hole);
                s.Go();
            }
            yield break;
        }
Exemplo n.º 2
0
        protected override IEnumerator OnGenerate()
        {
            var num         = Random.Range(NumMin, NumMax + 1);
            var headSwimmer = gameObject.AddComponent <Swimmer>();

            gameObject.AddComponent <DestroyWhenSwimmerOut>();
            var gdata = App.GetGameData <FishGameData>();

            if (gdata.EvtLeaderInstance != null)
            {
                gdata.EvtLeaderInstance(headSwimmer);
            }

            FishPerfab.swimmer.CopyDataTo(headSwimmer);
            headSwimmer.SetLiveDimension(Defines.ClearFishRadius);
            headSwimmer.RotateSpd = Fish_RotateSpd;
            headSwimmer.Speed     = Fish_Speed;

            var fishAiLeader = gameObject.AddComponent <FishAI_FreeSwimSingle>();

            FishPerfab.GetComponent <FishAI_FreeSwimSingle>().CopyDataTo(fishAiLeader);
            fishAiLeader.enabled                = false;
            fishAiLeader.RotateAngleRndRange    = Fish_RotateAngleRndRange;
            fishAiLeader.RotateInterval         = Fish_RotateInterval;
            fishAiLeader.RotateIntervalRndRange = Fish_RotateIntervalRndRange;
            var hole = KindGenerator.CreateBirthHole(headSwimmer.BoundCircleRadius, headSwimmer.SwimDepth);

            transform.localPosition = hole.Position;
            transform.rotation      = hole.Rotation;
            headSwimmer.Go();

            Fish lastFish         = null;
            var  distanceToLeader = 0F;

            for (var i = 0; i < num; i++)
            {
                yield return(new WaitForSeconds((Distance + headSwimmer.BoundCircleRadius * 2F) / headSwimmer.Speed));

                var f = Instantiate(FishPerfab);
                var s = f.swimmer;
                f.name = FishPerfab.name;

                s.RotateSpd = Fish_RotateSpd;
                s.Speed     = Fish_Speed;
                //动画设置
                if (lastFish != null)
                {
                    f.AniSprite.PlayFrom(f.AniSprite.DefaultClip, lastFish.AniSprite.ClipTimeSeconds);
                }
                //删除所有其他ai
                f.ClearAi();
                var aiFollow = f.gameObject.AddComponent <FishAI_Follow>();
                aiFollow.SetTarget(headSwimmer);
                distanceToLeader         += (Distance + headSwimmer.BoundCircleRadius * 2F);
                aiFollow.DistanceToLeader = distanceToLeader;

                //方位设置
                var fishTs = f.transform;
                fishTs.parent                  = GameMain.Singleton.FishGenerator.transform;
                fishTs.transform.parent        = hole.Parent;
                fishTs.transform.localPosition = hole.Position;
                fishTs.transform.localRotation = hole.Rotation;
                s.Go();
                lastFish = f;
            }
            fishAiLeader.enabled = true;
        }