Beispiel #1
0
    public static bool RecycleGO(GameObject prefab,GameObject instGO)
    {
        if (msPoolsDict == null)
        {
            msPoolsDict = new Dictionary<int, Pool_GameObj>();
        }

        //�ҳ���Ӧ��PoolGameObject
        if(prefab == null)
        {
            IPoolObj poolObj = instGO.GetComponent(typeof(IPoolObj)) as IPoolObj;
            prefab = poolObj.Prefab;
            if (prefab == null)
            {
                //Debug.LogWarning("noPrefab ="+instGO.name);
                return false;
            }
         }

        Pool_GameObj poolGo = null;
        if (!msPoolsDict.TryGetValue(prefab.GetInstanceID(), out poolGo))
        {
            poolGo = new Pool_GameObj(prefab);
            msPoolsDict.Add(prefab.GetInstanceID(), poolGo);
        }
        poolGo.RecycleGO(instGO);
        return true;
    }
Beispiel #2
0
        private void PushOneStack(int coinNum, int fishOdd, int gunScore)
        {
            //return;
            if (coinNum <= 0)
            {
                return;
            }


            //CoinStack coinStackNew = Instantiate(Prefab_coinStack) as CoinStack;
            CoinStack coinStackNew   = Pool_GameObj.GetObj(Prefab_coinStack.gameObject).GetComponent <CoinStack>();
            Transform coinStackNewTs = coinStackNew.transform;

            mCoinStackCurrentDepth       = mCoinStacks.Count == 0 ? 0F : mCoinStackCurrentDepth - 0.1F;
            coinStackNewTs.parent        = transform;
            coinStackNewTs.localRotation = Quaternion.identity;
            coinStackNewTs.localPosition = new Vector3(-mCoinStacks.Count * (OneStackWidth + OneStackSpace), 0F, mCoinStackCurrentDepth);
            coinStackNew.PileUp(coinNum, GetCoinStackHeight(fishOdd, gunScore), mCurCoinStackBGColor);

            mCurCoinStackBGColor = !mCurCoinStackBGColor;

            coinStackNew.EvtDisappear  += Handle_CoinStackDisappear;
            coinStackNew.EvtRoleToHead += Handle_CoinStackRollToHead;

            mCoinStacks.Enqueue(coinStackNew);

            //mState_IsMovingStacks = true;
        }
Beispiel #3
0
    void Handle_GunFire(Player p, Gun g, int score)
    {
        //Debug.Log("Handle_GunFire");
        Bullet prefabBullet = ModuleBullet.Get_PrefabBullet_Used(g);

        //tk2dAnimatedSprite ani;

        if (prefabBullet == null)
        {
            return;
        }
        GunLevelType gLvType     = g.GetLevelType();
        GunPowerType gPowerType  = g.GetPowerType();
        int          NumInstance = 2 + (int)gLvType;//生成的数量
        float        widthBullet = WidthBulletNormal[(int)g.GetLevelType()];
        Vector3      posOffset   = new Vector3(-widthBullet * NumInstance / 2F, 0F);

        for (int i = 0; i != NumInstance; ++i)
        {
            Bullet b = Pool_GameObj.GetObj(prefabBullet.gameObject).GetComponent <Bullet>();
            b.Prefab_GoAnisprBullet = Prefab_AniBullet;
            b.Prefab_SpriteNameSet  = gPowerType == GunPowerType.Normal ? nameSetAniBulletNor : nameSetAniBulletLizi;

            BulletEx_Splitor bEx_Splitor = b.gameObject.AddComponent <BulletEx_Splitor>();
            bEx_Splitor.FactorSplit = NumInstance;

            b.transform.position = g.local_GunFire.position + g.AniSpr_GunPot.transform.rotation * posOffset;
            posOffset.x         += widthBullet;
            b.Score = score;
            b.Fire(p, null, g.AniSpr_GunPot.transform.rotation);
        }
    }
Beispiel #4
0
    public static bool RecycleGO(GameObject prefab, GameObject instGO)
    {
        if (msPoolsDict == null)
        {
            msPoolsDict = new Dictionary <int, Pool_GameObj>();
        }

        //????????PoolGameObject
        if (prefab == null)
        {
            IPoolObj poolObj = instGO.GetComponent(typeof(IPoolObj)) as IPoolObj;
            prefab = poolObj.Prefab;
            if (prefab == null)
            {
                //Debug.LogWarning("noPrefab ="+instGO.name);
                return(false);
            }
        }

        Pool_GameObj poolGo = null;

        if (!msPoolsDict.TryGetValue(prefab.GetInstanceID(), out poolGo))
        {
            poolGo = new Pool_GameObj(prefab);
            msPoolsDict.Add(prefab.GetInstanceID(), poolGo);
        }
        poolGo.RecycleGO(instGO);
        return(true);
    }
Beispiel #5
0
        void Start()
        {
            mState1             = State1.ScaleUp;
            mState2_IsFadingOut = false;
            mShakeDirects       = new Vector3[] {
                new Vector3(-1F, 1F, 0F)
                , new Vector3(1F, -1.2F, 0F)
                , new Vector3(1.2F, 1F, 0F)
                , new Vector3(-1.2F, -0.8F, 0F)
            };

            mSprWeb = Pool_GameObj.GetObj(Prefab_GoSpriteWeb).GetComponent <tk2dSprite>();
            if (NameSprite != null && NameSprite != "")
            {
                mSprWeb.spriteId = mSprWeb.GetSpriteIdByName(NameSprite);
            }
            Transform ts = mSprWeb.transform;

            mSprWeb.gameObject.SetActive(true);
            ts.parent        = transform;
            ts.localPosition = Vector3.zero;
            Color c = ColorInitialize;

            c.a           = 1F;
            mSprWeb.color = c;
            mTsWeb        = ts;

            mTimeWaitFadeout = TimeWebScaleUp + TimeShake - TimeFadeOut;
            mColorWeb        = mSprWeb.color;
        }
Beispiel #6
0
        public override void OnGetGameInfo(ISFSObject gameInfo)
        {
            YxDebug.Log("-----------游戏开始--------------");
            var gdata = App.GetGameData <FishGameData>();

            gdata.GameState                = YxGameState.Run;
            State_                         = State.Normal;
            GameOdds.GainRatio             = GameOdds.GainRatios[(int)(BSSetting.GameDifficult_.Val)];
            GameOdds.GainRatioConditFactor = GameOdds.GainRatioConditFactors[(int)(BSSetting.ArenaType_.Val)];
            StartCoroutine(_Coro_MainProcess());
            Pool_GameObj.Init();
            var evtMainProcessStartGame = gdata.EvtMainProcessStartGame;

            if (evtMainProcessStartGame != null)
            {
                evtMainProcessStartGame();
            }
            App.GetGameData <FishGameData>().Msgrate = gameInfo.GetInt(FishRequestKey.Msgrate);
            GameSystemUI.Init(gameInfo);
            PlayersBatterys.Init(gameInfo);
            var self = PlayersBatterys.UserSelf;

            Operation.UserSelf = self;
            if (self.Idx >= PlayersBatterys.Count / 2)
            {
                RotatePond(180);
            }

            FishGenerator.Init(gameInfo);
            StartCoroutine(_Coro_DelayInitGame());
        }
Beispiel #7
0
        /// <summary>
        /// 死亡动画
        /// </summary>
        /// <param name="delayTotal"></param>
        protected virtual void DeathAnimation(float delayTotal)
        {
            //播放死亡动画
            if (Prefab_GoAniDead == null)
            {
                return;
            }
            var goDieAnimation = Pool_GameObj.GetObj(Prefab_GoAniDead);

            goDieAnimation.GetComponent <tk2dSprite>().color = Colour;
            var goDieAniTs = goDieAnimation.transform;

            goDieAnimation.SetActive(true);

            goDieAniTs.parent   = GameMain.Singleton.FishGenerator.transform;
            goDieAniTs.position = new Vector3(MTs.position.x, MTs.position.y, MTs.position.z);
            goDieAniTs.rotation = MTs.rotation;
            var dshadow = YxShadow.AddShadow(goDieAnimation);

            dshadow.SetRecycleShadowModel(Prefab_GoAniDead, goDieAniTs, delayTotal);
            var fishRecycleDelay = goDieAnimation.AddComponent <RecycleDelay>();

            fishRecycleDelay.delay  = delayTotal;
            fishRecycleDelay.Prefab = Prefab_GoAniDead;
        }
Beispiel #8
0
        /// <summary>
        /// 清除,从屏幕上消失
        /// </summary>
        public void Clear()
        {
            if (GameMain.Singleton != null)
            {
                --GameMain.Singleton.NumFishAlive;
            }
            var gdata = App.GetGameData <FishGameData>();

            if (gdata.EvtFishClear != null)
            {
                gdata.EvtFishClear(this);
            }
            Attackable = false;
            _mId       = 0;
            if (_shadow != null)
            {
                _shadow.Clear();
            }
            Pool_GameObj.RecycleGO(Prefab_GoAniSwim, MGoAniSprite);
            MGoAniSprite.SetActive(false);
            var tsAniSwim = MGoAniSprite.transform;

            tsAniSwim.position   = new Vector3(1000F, 0F, 0F);
            tsAniSwim.rotation   = Quaternion.identity;
            tsAniSwim.localScale = Vector3.one;
            MGoAniSprite         = null;
            MAnimationSprite     = null;
            App.GetGameData <FishGameData>().RmoveFish(TypeIndex);
            Destroy(gameObject);
        }
Beispiel #9
0
        private static GameObject CreateModel(GameObject modelPerf, out tk2dSpriteAnimator animator, Vector3 posOff, Color color, Transform parentTs)
        {
            var model = Pool_GameObj.GetObj(modelPerf);

            model.SetActive(true);
            animator = model.GetComponent <tk2dSpriteAnimator>() ?? model.GetComponentInChildren <tk2dSpriteAnimator>();
            var crenderers = model.GetComponentsInChildren <Renderer>();

            foreach (var r in crenderers)
            {
                r.enabled = true;
            }
            var aniTs = model.transform;

            aniTs.parent   = parentTs.parent;
            aniTs.position = parentTs.position + posOff;
            aniTs.rotation = parentTs.rotation;
            var tk2Ds = model.GetComponentsInChildren <tk2dSprite>();

            foreach (var tks in tk2Ds)
            {
                tks.color = color;
            }
            return(model);
        }
Beispiel #10
0
    public void Fire(Player from, Fish tar, Quaternion dir)
    {
        GameMain gm = GameMain.Singleton;

        if (tar != null)
        {
            mTargetFish   = tar;
            IsLockingFish = true;
            Vector3 targetDir = tar.transform.position - mTs.position;
            targetDir.z = 0F;
            targetDir.Normalize();
            targetDir    = Quaternion.Euler(0F, 0F, Random.Range(-90F, 90F)) * targetDir + from.transform.up;//得出子弹偏向  Random.Range(0,2)==0?-90F:90F
            mTs.rotation = Quaternion.FromToRotation(Vector3.up, targetDir);
        }
        else
        {
            IsLockingFish = false;
            mTs.rotation  = dir;
        }
        mTs.parent = gm.TopLeftTs;

        Text_CoinNum.text = Score.ToString();
        Text_CoinNum.Commit();

        Owner = from;
        ++Owner.GunInst.NumBulletInWorld;

        BackStageSetting bss = gm.BSSetting;

        if (bss.IsBulletCrossWhenScreenNet.Val && gm.IsScreenNet())
        {
            MoveArea = gm.WorldDimension;
        }
        else
        {
            MoveArea = from.AtScreenArea;
        }

        if (mBulletGO == null)
        {
            mBulletGO = Pool_GameObj.GetObj(Prefab_GoAnisprBullet);
            tk2dSpriteAnimator aniSprBullet = mBulletGO.GetComponent <tk2dSpriteAnimator>();
            if (aniSprBullet != null)
            {
                //aniSprBullet.clipId = aniSprBullet.GetClipIdByName(Prefab_SpriteNameSet.Texts[from.Idx % Prefab_SpriteNameSet.Texts.Length]);
                //Debug.Log(Prefab_SpriteNameSet.Texts[from.Idx % Prefab_SpriteNameSet.Texts.Length]);
                aniSprBullet.Play(Prefab_SpriteNameSet.Texts[from.Idx % Prefab_SpriteNameSet.Texts.Length]);
                //aniSprBullet.PlayFrom("1",0.1F);
            }

            mBulletGO.SetActive(true);
            mBulletGO.transform.parent        = mTs;
            mBulletGO.transform.localPosition = Vector3.zero;
            mBulletGO.transform.localRotation = Quaternion.identity;
        }
    }
Beispiel #11
0
 public void Clear()
 {
     if (_shadowObj != null)
     {
         var obj = _shadowObj.gameObject;
         Pool_GameObj.RecycleGO(obj, obj);
         obj.SetActive(false);
     }
     Destroy(this);
 }
Beispiel #12
0
 void Handle_CoinStackDisappear(CoinStack cStack)
 {
     mCoinStacks.Dequeue();
     Pool_GameObj.RecycleGO(null, cStack.gameObject);
     if (mCoinStacks.Count != 0)
     {
         mState_IsMovingStacks = true;
         mElapse_MovingStacks  = 0F;
     }
 }
    IEnumerator _Coro_FlytProcess(Vector3 fishDieWorldPos, FlyingCoinType t, int num, float delay)
    {
        yield return(new WaitForSeconds(delay));

        //播放声音
        if (GameMain.Singleton.SoundMgr.snd_Coin != null && t == FlyingCoinType.Sliver)
        {
            GameMain.Singleton.SoundMgr.PlayOneShot(GameMain.Singleton.SoundMgr.snd_Coin);
        }
        if (GameMain.Singleton.SoundMgr.snd_Gold != null && t == FlyingCoinType.Glod)
        {
            GameMain.Singleton.SoundMgr.PlayOneShot(GameMain.Singleton.SoundMgr.snd_Gold);
        }

        Vector3 fishDielocalPos = transform.InverseTransformPoint(fishDieWorldPos);

        fishDielocalPos.z = 0F;
        FlyingCoin useGoldPrefab = t == FlyingCoinType.Glod ? Prefab_GoldBig : Prefab_Gold;


        //生成币
        FlyingCoin[] golds         = new FlyingCoin[num];
        Vector3      startLocalPos = fishDielocalPos - new Vector3(AppearOffsetX * (num - 1) * 0.5F, AppearOffsetY * (num - 1) * 0.5F, 0F);

        startLocalPos += startLocalPos.normalized * 38.4F;//*1.3F,为延长距离,使得金币更像是鱼中飞出
        float maxTime = 0F;

        for (int i = 0; i != num; ++i)
        {
            //golds[i] = Instantiate(useGoldPrefab) as FlyingCoin;
            golds[i]          = Pool_GameObj.GetObj(useGoldPrefab.gameObject).GetComponent <FlyingCoin>();
            golds[i].FlySpeed = FlySpeed;
            Transform goldTs = golds[i].transform;
            goldTs.parent        = transform;
            goldTs.localRotation = Quaternion.identity;
            goldTs.localPosition = startLocalPos + new Vector3(AppearOffsetX * i, AppearOffsetY * i, 0F);
            float flyNeedTime = golds[i].FlytoPosZero(Curve_Scale);
            if (flyNeedTime > maxTime)
            {
                maxTime = flyNeedTime;
            }

            yield return(new WaitForSeconds(AppearInterval));
        }

        yield return(new WaitForSeconds(maxTime - AppearInterval * num));

        for (int i = 0; i != num; ++i)
        {
            Pool_GameObj.RecycleGO(null, golds[i].gameObject);
            //Destroy(golds[i].gameObject);
        }
    }
Beispiel #14
0
        IEnumerator _Coro_Popup(int num, Vector3 worldPos, Transform tsParent, int odds)
        {
            //tk2dTextMesh digit = Instantiate(Prefab_Digit) as tk2dTextMesh;
            var digit = Pool_GameObj.GetObj(Prefab_Digit.gameObject).GetComponent <tk2dTextMesh>();

            digit.gameObject.SetActive(true);
            digit.text = YxUtiles.GetShowNumberToString(num);
            digit.Commit();

            var ts = digit.transform;

            ts.parent        = tsParent;
            ts.localRotation = Quaternion.identity;

            var scale = Mathf.Min(0.5f + odds / 5f * 0.3f, 1.5f);

            ts.localScale = new Vector3(scale, scale, 1F);

            var oriPos = worldPos;

            oriPos.z    = Defines.GlobleDepth_DieFishPopDigit;
            ts.position = oriPos;

            var elapse = 0F;
            var c      = Prefab_Digit.color;

            while (elapse < Duration)
            {
                yield return(0);

                var prct = elapse / Duration;
                ts.position = oriPos + new Vector3(0F, Curve_OffsetY.Evaluate(prct), 0F);
                digit.Commit();
                elapse += Time.deltaTime;
            }

            yield return(new WaitForSeconds(2));

            elapse = 0;
            while (elapse < Duration)
            {
                var prct = elapse / Duration;
                c.a         = Curve_Alpha.Evaluate(prct);
                digit.color = c;
                digit.Commit();
                elapse += Time.deltaTime;
                yield return(0);
            }
            //Destroy(digit.gameObject);
            digit.gameObject.SetActive(false);
            Pool_GameObj.RecycleGO(Prefab_Digit.gameObject, digit.gameObject);
        }
    IEnumerator _Coro_Popup(int num, Vector3 worldPos, Transform tsParent, int fishTypeIdx)
    {
        //tk2dTextMesh digit = Instantiate(Prefab_Digit) as tk2dTextMesh;
        tk2dTextMesh digit = Pool_GameObj.GetObj(Prefab_Digit.gameObject).GetComponent <tk2dTextMesh>();

        digit.gameObject.SetActive(true);
        digit.text = num.ToString();
        digit.Commit();

        Transform ts = digit.transform;

        ts.parent        = tsParent;
        ts.localRotation = Quaternion.identity;

        float scale = 1F;

        if (mScaleDatasMap.TryGetValue(fishTypeIdx, out scale))
        {
            ts.localScale = new Vector3(scale, scale, 1F);
        }
        else
        {
            ts.localScale = Vector3.one;
        }

        Vector3 oriPos = worldPos;

        oriPos.z    = Defines.GlobleDepth_DieFishPopDigit;
        ts.position = oriPos;


        float elapse = 0F;
        Color c      = Prefab_Digit.color;

        while (elapse < Duration)
        {
            float prct = elapse / Duration;

            ts.position = oriPos + new Vector3(0F, Curve_OffsetY.Evaluate(prct), 0F);
            c.a         = Curve_Alpha.Evaluate(prct);
            digit.color = c;
            digit.Commit();
            elapse += Time.deltaTime;
            yield return(0);
        }

        //Destroy(digit.gameObject);
        digit.gameObject.SetActive(false);
        Pool_GameObj.RecycleGO(Prefab_Digit.gameObject, digit.gameObject);
    }
Beispiel #16
0
    // Use this for initialization
    IEnumerator Start()
    {
        if (Prefab == null)
        {
            Debug.LogError("Prefab ²»ÄÜΪ ¿Õ!!");
            yield break;
        }
        yield return(new WaitForSeconds(delay));

        Pool_GameObj.RecycleGO(Prefab, gameObject);
        gameObject.SetActive(false);
        transform.position = new Vector3(1000F, 1000F, 0F);
        Destroy(this);
    }
Beispiel #17
0
    public void SelfDestroy()
    {
        if (mIsDestroyed)
        {
            return;
        }

        if (GameMain.EvtBulletDestroy != null)
        {
            GameMain.EvtBulletDestroy(this);
        }

        Pool_GameObj.RecycleGO(null, gameObject);
        mIsDestroyed = true;//Destroy不会立即使得OnTrigger失效,防止多次物理碰撞,
    }
Beispiel #18
0
        public void SelfDestroy()
        {
            if (_mIsDestroyed)
            {
                return;
            }
            var gdata = App.GetGameData <FishGameData>();

            if (gdata.EvtBulletDestroy != null)
            {
                gdata.EvtBulletDestroy(this);
            }

            Pool_GameObj.RecycleGO(null, gameObject);
            _mIsDestroyed = true;//Destroy不会立即使得OnTrigger失效,防止多次物理碰撞,
        }
Beispiel #19
0
    public static GameObject GetObj(GameObject prefab)
    {
        if (msPoolsDict == null)
        {
            msPoolsDict = new Dictionary<int, Pool_GameObj>();
        }

        //�ҳ���Ӧ��PoolGameObject
        Pool_GameObj poolGo = null;
        if (!msPoolsDict.TryGetValue(prefab.GetInstanceID(),out poolGo))
        {
            poolGo = new Pool_GameObj(prefab);
            msPoolsDict.Add(prefab.GetInstanceID(), poolGo);
        }

        return poolGo.GetGO();
    }
Beispiel #20
0
    public static GameObject GetObj(GameObject prefab)
    {
        if (msPoolsDict == null)
        {
            msPoolsDict = new Dictionary <int, Pool_GameObj>();
        }

        //????????PoolGameObject
        Pool_GameObj poolGo = null;

        if (!msPoolsDict.TryGetValue(prefab.GetInstanceID(), out poolGo))
        {
            poolGo = new Pool_GameObj(prefab);
            msPoolsDict.Add(prefab.GetInstanceID(), poolGo);
        }

        return(poolGo.GetGO());
    }
Beispiel #21
0
        /// <summary>
        /// 创建锁鱼子弹
        /// </summary>
        /// <param name="p">开枪者</param>
        /// <param name="g">枪</param>
        /// <param name="score">分数</param>
        /// <param name="isLock"></param>
        /// <param name="bulletId">子弹id</param>
        private void Handle_GunFire(Player p, Gun g, int score, bool isLock, int bulletId)
        {
            if (!isLock)
            {
                return;
            }
            var prefabBullet = g.Prefab_BulletNormal;//ModuleBullet.Get_PrefabBullet_Used(g);
            var b            = Pool_GameObj.GetObj(prefabBullet.gameObject).GetComponent <Bullet>();

            b.Id = bulletId;
            b.transform.position = g.local_GunFire.position;
            b.Score = score;

            /*var upToward = mLockedTarget[p.Idx].transform.position - g.TsGun.position;
             * upToward.z = 0F;
             * var targetDir = Quaternion.FromToRotation(Vector3.up, upToward);*/
            b.Fire(p, mLockedTarget[p.Idx], g.TsGun.rotation);
        }
Beispiel #22
0
    //???ио?????
    public static void SetPoolVolume(GameObject prefab, int Volume)
    {
        if (msPoolsDict == null)
        {
            msPoolsDict = new Dictionary <int, Pool_GameObj>();
            return;
        }

        //????????PoolGameObject
        Pool_GameObj poolGo = null;

        if (!msPoolsDict.TryGetValue(prefab.GetInstanceID(), out poolGo))
        {
            poolGo = new Pool_GameObj(prefab);
            msPoolsDict.Add(prefab.GetInstanceID(), poolGo);
        }

        poolGo.mVolume = Volume;
    }
Beispiel #23
0
        /// <summary>
        /// 开枪(创建子弹)
        /// </summary>
        /// <param name="p">开枪者</param>
        /// <param name="g">枪</param>
        /// <param name="score">分数</param>
        /// <param name="isLock"></param>
        /// <param name="bulletId"></param>
        void Handle_GunFire(Player p, Gun g, int score, bool isLock, int bulletId)
        {
            if (isLock)
            {
                return;
            }
            var prefabBullet = g.Prefab_BulletNormal;//Get_PrefabBullet_Used(g);//找到枪对应的子弹   啬

            if (prefabBullet == null)
            {
                return;
            }
            var b = Pool_GameObj.GetObj(prefabBullet.gameObject).GetComponent <Bullet>();

            b.Id = bulletId;
            b.transform.position = g.local_GunFire.position;
            b.Score = score;
            b.Fire(p, null, g.TsGun.rotation);//g.AniSpr_GunPot.transform.rotation);
        }
Beispiel #24
0
    void Handle_GunFire(Player p, Gun g, int score)
    {
        if (!Fireable[p.Idx])
        {
            return;
        }
        Bullet prefabBullet = Get_PrefabBullet_Used(g);

        if (prefabBullet == null)
        {
            return;
        }

        Bullet b = Pool_GameObj.GetObj(prefabBullet.gameObject).GetComponent <Bullet>();

        b.transform.position = g.local_GunFire.position;
        b.Score = score;
        b.Fire(p, null, g.AniSpr_GunPot.transform.rotation);
    }
Beispiel #25
0
    public void On_Recycle()
    {
        gameObject.SetActive(false);
        //gameObject.active = false;
        //gameObject.SetActiveRecursively(false);

        if (mBulletGO != null)
        {
            mBulletGO.SetActive(false);
            Pool_GameObj.RecycleGO(Prefab_GoAnisprBullet, mBulletGO);

            mBulletGO = null;
        }
        --Owner.GunInst.NumBulletInWorld;
        if (Owner.GunInst.NumBulletInWorld < 0)
        {
            Debug.LogError("在场子弹数不能为负" + Owner.GunInst.NumBulletInWorld.ToString());
        }
    }
Beispiel #26
0
        public void Fire(Player from, Fish tar, Quaternion dir)
        {
            GameMain gm = GameMain.Singleton;

            _mTargetFish  = tar;
            IsLockingFish = tar != null;
            _mTs.rotation = dir;
            _mTs.parent   = gm.TopLeftTs;
            var old = _mTs.localPosition;

            old.z = 0;
            _mTs.localPosition = old;
            Text_CoinNum.text  = Score.ToString();
            Text_CoinNum.Commit();

            Owner = from;
            ++Owner.GunInst.NumBulletInWorld;

            BackStageSetting bss = gm.BSSetting;

            MoveArea = gm.WorldDimension;

            if (_mBulletGo == null)
            {
                _mBulletGo = Pool_GameObj.GetObj(Prefab_GoAnisprBullet);
                tk2dSpriteAnimator aniSprBullet = _mBulletGo.GetComponent <tk2dSpriteAnimator>();
                if (aniSprBullet != null)
                {
                    //aniSprBullet.clipId = aniSprBullet.GetClipIdByName(Prefab_SpriteNameSet.Texts[from.Idx % Prefab_SpriteNameSet.Texts.Length]);
                    //YxDebug.Log(Prefab_SpriteNameSet.Texts[from.Idx % Prefab_SpriteNameSet.Texts.Length]);
                    aniSprBullet.Play(Prefab_SpriteNameSet.Texts[from.Idx % Prefab_SpriteNameSet.Texts.Length]);
                    //aniSprBullet.PlayFrom("1",0.1F);
                }

                _mBulletGo.SetActive(true);
                _mBulletGo.transform.parent = _mTs;
                var pos = Vector3.zero;
                _mBulletGo.transform.localPosition = pos;
                pos.z -= 10;
                Text_CoinNum.transform.localPosition = pos;
                _mBulletGo.transform.localRotation   = Quaternion.identity;
            }
        }
Beispiel #27
0
    IEnumerator _Coro_GenerateBubble()
    {
        int     numGenerated = 0;
        Vector3 localPos     = new Vector3(0F, 0F, 0.01F);

        while (numGenerated < NumGenerate)
        {
            //tk2dSprite sprBubble = Instantiate(Prefab_Bubble) as tk2dSprite;
            tk2dSprite sprBubble = Pool_GameObj.GetObj(Prefab_Bubble.gameObject).GetComponent <tk2dSprite>();
            sprBubble.gameObject.SetActive(true);

            sprBubble.transform.parent        = transform;
            sprBubble.transform.localPosition = localPos;
            localPos.z += 0.01F;
            StartCoroutine(_Coro_BubbleScaleUp(sprBubble));
            //sprBubble.
            ++numGenerated;
            yield return(new WaitForSeconds(InttervalBubble));
        }
    }
    void Handle_GunFire(Player p, Gun g, int score)
    {
        if (mLockedTarget[p.Idx] == null)
        {
            return;
        }

        //Debug.Log("Handle_GunFire fire fish = " + mLockedTarget[p.Idx].name+"  p.idx = "+p.Idx);
        Bullet prefabBullet = ModuleBullet.Get_PrefabBullet_Used(g);

        Bullet b = Pool_GameObj.GetObj(prefabBullet.gameObject).GetComponent <Bullet>();

        b.transform.position = g.local_GunFire.position;
        b.Score = score;
        Quaternion targetDir;
        Vector3    upToward = mLockedTarget[p.Idx].transform.position - g.TsGun.position;

        upToward.z = 0F;
        targetDir  = Quaternion.FromToRotation(Vector3.up, upToward);
        b.Fire(p, mLockedTarget[p.Idx], targetDir);
        //Debug.Log("Handle_GunFire fire fish = " + mLockedTarget[p.Idx].name);
    }
Beispiel #29
0
    IEnumerator _Coro_BubbleScaleUp(tk2dSprite spr)
    {
        //设置颜色
        Color c = spr.color;

        c.a       = AlphaStart;
        spr.color = c;

        float elapse = 0F;
        //放大
        Transform tsSpr       = spr.transform;
        float     scaleUpTime = TimeOneBubble * 0.7F;

        while (elapse < scaleUpTime)
        {
            tsSpr.localScale = (ScaleTarget * (0.5F + elapse / scaleUpTime * 0.5F)) * Vector3.one;
            elapse          += Time.deltaTime;
            yield return(0F);
        }
        tsSpr.localScale = Vector3.one * ScaleTarget;
        //渐隐
        elapse = 0F;
        float fadeoutTime = TimeOneBubble * 0.3F;

        while (elapse < fadeoutTime)
        {
            c.a       = (1F - elapse / fadeoutTime) * AlphaStart;
            spr.color = c;
            elapse   += Time.deltaTime;
            yield return(0F);
        }


        //删除
        spr.gameObject.SetActive(false);
        Pool_GameObj.RecycleGO(Prefab_Bubble.gameObject, spr.gameObject);
        //Destroy(spr.gameObject);
    }
Beispiel #30
0
        protected override void DeathAnimation(float delayTotal)
        {
            if (Prefab_GoAniDead == null)
            {
                return;
            }
            foreach (var pos in Positions)
            {
                var goDieAnimation = Pool_GameObj.GetObj(Prefab_GoAniDead);
                goDieAnimation.GetComponent <tk2dSprite>().color = Colour;
                var goDieAniTs = goDieAnimation.transform;
                goDieAnimation.SetActive(true);

                goDieAniTs.parent        = MTs;
                goDieAniTs.localPosition = pos;
                goDieAniTs.rotation      = MTs.rotation;
                goDieAniTs.parent        = GameMain.Singleton.FishGenerator.transform;

                var fishRecycleDelay = goDieAnimation.AddComponent <RecycleDelay>();
                fishRecycleDelay.delay  = delayTotal;
                fishRecycleDelay.Prefab = Prefab_GoAniDead;
            }
        }
Beispiel #31
0
    //private bool mIsCleaned = false;
    /// <summary>
    /// ����,����Ļ����ʧ
    /// </summary>
    public void Clear()
    {
        //if (mIsCleaned)
        //    return;

        //mIsCleaned = true;

        if (GameMain.Singleton != null)
        {
            --GameMain.Singleton.NumFishAlive;
        }

        if (GameMain.EvtFishClear != null)
        {
            GameMain.EvtFishClear(this);
        }

        Attackable = false;

        Pool_GameObj.RecycleGO(Prefab_GoAniSwim, mGoAniSprite);
        mGoAniSprite.SetActive(false);
        Transform tsAniSwim = mGoAniSprite.transform;

        tsAniSwim.position   = new Vector3(1000F, 0F, 0F);
        tsAniSwim.rotation   = Quaternion.identity;
        tsAniSwim.localScale = Vector3.one;

        mGoAniSprite     = null;
        mAnimationSprite = null;

//         if (!Pool_GameObj.RecycleGO(null, gameObject))
//         {
        Destroy(gameObject);


        //}
    }
Beispiel #32
0
    //������
    public static void SetPoolVolume(GameObject prefab,int Volume)
    {
        if (msPoolsDict == null)
        {
            msPoolsDict = new Dictionary<int, Pool_GameObj>();
            return;
        }

        //�ҳ���Ӧ��PoolGameObject
        Pool_GameObj poolGo = null;
        if (!msPoolsDict.TryGetValue(prefab.GetInstanceID(), out poolGo))
        {
            poolGo = new Pool_GameObj(prefab);
            msPoolsDict.Add(prefab.GetInstanceID(), poolGo);
        }

        poolGo.mVolume = Volume;
    }
Beispiel #33
0
        private IEnumerator _Coro_FlytProcess(Vector3 fishDieWorldPos, int num, float delay)
        {
            int numFly;
            var typeCoin = FlyingCoinType.Sliver;

            if (num < 10)
            {
                numFly = num;
            }
            else
            {
                numFly = num / 5 + (num % 5 != 0 ? 1 : 0);
                if (numFly > 11)
                {
                    numFly = 11;              //最大飞11颗
                }
                typeCoin = FlyingCoinType.Glod;
            }
            yield return(new WaitForSeconds(delay));

            //播放声音
            if (PlaySound && GameMain.Singleton != null)
            {
                var musicMgr = Facade.Instance <MusicManager>();
                if (typeCoin == FlyingCoinType.Sliver)
                {
                    musicMgr.Play("getsilver");
                }
                if (typeCoin == FlyingCoinType.Glod)
                {
                    musicMgr.Play("getgold");
                }
            }

            var fishDielocalPos = transform.InverseTransformPoint(fishDieWorldPos);

            fishDielocalPos.z = 0F;
            //var useGoldPrefab = t==FlyingCoinType.Glod ? Prefab_GoldBig : Prefab_Gold;

            FlyingCoin useGoldPrefab;
            float      offy;

            if (typeCoin == FlyingCoinType.Glod)
            {
                useGoldPrefab = Prefab_GoldBig;
                offy          = 12;
            }
            else
            {
                useGoldPrefab = Prefab_Gold;
                offy          = 6.5f;
            }

            //生成币
            var golds         = new FlyingCoin[numFly];
            var startLocalPos = fishDielocalPos;
            // -new Vector3(AppearOffsetX * (num - 1) * 0.5F, AppearOffsetY * (num - 1) * 0.5F, 0F);
            //startLocalPos += startLocalPos.normalized * 38.4F;//*1.3F,为延长距离,使得金币更像是鱼中飞出
            var maxTime = 0F;
            var con     = new GameObject("coins");
            var ts      = con.transform;

            if (coinSpace++ > 50)
            {
                coinSpace = 0;
            }
            ts.parent        = GetCoinsContainer();
            ts.localPosition = new Vector3(0, 0, coinSpace * 0.0001f);
            ts.localRotation = Quaternion.identity;
            var target = Vector3.zero;

            for (var i = 0; i < numFly; ++i)
            {
                var gold = Pool_GameObj.GetObj(useGoldPrefab.gameObject).GetComponent <FlyingCoin>();
                golds[i]      = gold;
                gold.FlySpeed = FlySpeed;
                var goldTs = gold.transform;
                goldTs.parent        = ts;
                goldTs.localRotation = Quaternion.identity;
                var offPos = new Vector3(AppearOffsetX * i, AppearOffsetY * i, 0F);
                offPos = fishDielocalPos.x < transform.localRotation.x ? -offPos : offPos;
                goldTs.localPosition = startLocalPos + offPos;
                var flyNeedTime = gold.FlytoPosZero(Curve_Scale, target);
                target.y += offy;
                if (flyNeedTime > maxTime)
                {
                    maxTime = flyNeedTime;
                }
                yield return(new WaitForSeconds(AppearInterval));
            }

            yield return(new WaitForSeconds(maxTime - AppearInterval * numFly));

            var coinNum = Pool_GameObj.GetObj(CoinNumPerfab.gameObject).GetComponent <tk2dTextMesh>();

            var coinNumTs = coinNum.transform;

            coinNum.text            = num.ToString();
            coinNumTs.parent        = ts;
            coinNumTs.localRotation = Quaternion.identity;
            coinNumTs.localPosition = new Vector3(0, target.y, 10);

            while (_nextStop)
            {
                yield return(new WaitForSeconds(WaitTime));
            }
            _nextStop = true;
            yield return(new WaitForSeconds(WaitTime));

            _nextStop = false;
            var times = 1;
            var pos   = ts.localPosition;

            while (times < MoveCount)
            {
                ts.localPosition = pos;
                pos.x           -= HMoveSpeed;
                times++;
                yield return(new WaitForSeconds(WaitTime));
            }

            //消失
            for (var i = 0; i != numFly; ++i)
            {
                Pool_GameObj.RecycleGO(null, golds[i].gameObject);
                //Destroy(golds[i].gameObject);
            }
            Destroy(con);
        }