Esempio n. 1
0
    static public EffectData PlayEffect(EFFECT_ID id, Vector3 createPosition, Vector3 targetPosition, float power, bool isAutoDestroy = false)
    {
        for (int i = 0; i < effectDataList.Count; i++)
        {
            var data = effectDataList[i];

            if (data.effectID != id)
            {
                continue;
            }
            if (data.isActive)
            {
                continue;
            }

            data.isActive = true;

            data.effectObject.transform.position = createPosition;
            data.effectMove.SetTargetPosition(targetPosition, power);
            data.particleSystemData.particleSystem.Play();

            data.effectObject.SetActive(true);
            data.isAutoDestroy = isAutoDestroy;

            return(data);
        }

        return(null);
    }
Esempio n. 2
0
        /// <summary>
        /// The add effect.
        /// </summary>
        /// <param name="ID">
        /// The id.
        /// </param>
        /// <param name="effectName">
        /// The effect name.
        /// </param>
        /// <param name="game">
        /// The game.
        /// </param>
        /// <exception cref="Exception">
        /// </exception>
        public static void AddEffect(EFFECT_ID ID, string effectName, Microsoft.Xna.Framework.Game game)
        {
            if (effectDictionary == null)
            {
                effectDictionary = new Dictionary <EFFECT_ID, Effect>();
            }

            if (effectDictionary.ContainsKey(ID))
            {
                return;
            }

            bool found = Enum.GetValues(typeof(EFFECT_ID)).Cast <EFFECT_ID>().Any(i => i == ID);

            if (!found)
            {
                throw new Exception("Effect ID (" + ID + ") not found in EFFECT_IDS enum");
            }

            if (!effectName.StartsWith("Effects\\"))
            {
                effectName = "Effects\\" + effectName;
            }

            Effect e = game.Content.Load <Effect>(effectName);

            effectDictionary.Add(ID, e);
        }
Esempio n. 3
0
    public static int PlayEffect(EFFECT_ID id, ref Vector3 pos)
    {
        if (!IsLoaded())
        {
            return(ERROR_HANDLE);
        }

        if (IsInstance)
        {
            var effects = Instance.effectTable[(int)id];
            for (int i = 0; i < effects.Length; i++)
            {
                var effect = effects[i];
                if (effect.gameObject.activeInHierarchy)
                {
                    continue;
                }

                Instance.playEffects.Add(new EffectPlayData()
                {
                    effect   = effect,
                    index    = i,
                    effectId = id,
                    time     = 0.0f
                });

                effect.gameObject.SetActive(true);
                effect.transform.localPosition = pos;
                effect.Play();
                return(i);
            }
        }

        return(ERROR_HANDLE);
    }
Esempio n. 4
0
        public static void AddEffect(EFFECT_ID ID, Effect effect)
        {
            if (effectDictionary == null)
            {
                effectDictionary = new Dictionary <EFFECT_ID, Effect>();
            }

            if (effectDictionary.ContainsKey(ID))
            {
                return;
            }

            bool found = Enum.GetValues(typeof(EFFECT_ID)).Cast <EFFECT_ID>().Any(i => i == ID);

            if (!found)
            {
                throw new Exception("Effect ID (" + ID.ToString() + ") not found in EFFECT_IDS enum");
            }

            if (effect == null)
            {
                throw new ArgumentNullException("Effect must not be null");
            }

            effectDictionary.Add(ID, effect);
        }
Esempio n. 5
0
    static public bool LoadAsset(EFFECT_ID ID, AssetLoader.AssetLoadCallback CallBack, ParamData paramData)
    {
        // id to name
        string AssetsName = GlobalInstanceFunction.Instance.GetAssetsName((int)ID, AssetLoader.EAssetType.ASSET_EFFECT);

        if (!GlobalInstanceFunction.Instance.IsValidName(AssetsName))
        {
            return(false);
        }

        string[]      depFiles = EffectDepedenceData.GetRefAssets(AssetsName);
        EffectLoadReq info     = new EffectLoadReq();

        info.name_     = AssetsName;
        info.callback_ = CallBack;
        info.pdata_    = paramData;
        if (depFiles != null)
        {
            info.status_ = new Dictionary <string, EffectDepLoader.EffectDepStatus>();
            EffectDepLoader.EffectDepStatus[] refStatus = EffectDepLoader.Instance.LoadAtlas(depFiles);
            for (int i = 0; i < depFiles.Length; ++i)
            {
                info.status_.Add(depFiles[i], refStatus[i]);
            }
            if (!LoadCheck(info))
            {
                loadLst.Add(info);
            }
        }
        else
        {
            if (pdRefDic_.ContainsKey(AssetsName))
            {
                if (pdRefDic_[AssetsName].hasBundle)
                {
                    CallBack(pdRefDic_[AssetsName].Open(), paramData);
                }
                else
                {
                    pdRefDic_[AssetsName].Set(CallBack, paramData);
                    AssetLoader.LoadAssetBundle(AssetsName, AssetLoader.EAssetType.ASSET_EFFECT, LoadEffectCallback, paramData);
                }
            }
            else
            {
                EffectBundleRef bundleRef = new EffectBundleRef();
                bundleRef.Set(CallBack, paramData);
                pdRefDic_.Add(AssetsName, bundleRef);
                pdRef4For_.Add(bundleRef);
                AssetLoader.LoadAssetBundle(AssetsName, AssetLoader.EAssetType.ASSET_EFFECT, LoadEffectCallback, paramData);
            }
        }

        return(true);
    }
Esempio n. 6
0
 bool HasEffect(EFFECT_ID effID)
 {
     for (int i = 0; i < effectLst_.Count; ++i)
     {
         if (effectLst_[i].id_.Equals(effID))
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 7
0
    public static void StopEffect(EFFECT_ID id, ref int index, bool force = false)
    {
        if (!IsLoaded())
        {
            return;
        }

        if (IsInstance)
        {
            var effects = Instance.effectTable[(int)id];
            if (index >= 0)
            {
                var effect = effects[index];
                if (!effect.gameObject.activeInHierarchy)
                {
                    index = ERROR_HANDLE;
                    return;
                }

                effect.Stop();

                for (int i = 0; i < Instance.playEffects.Count; i++)
                {
                    var playData = Instance.playEffects[i];
                    if (playData.effectId == id && playData.index == index)
                    {
                        Instance.playEffects.RemoveAt(i);
                        break;
                    }
                }

                if (force)
                {
                    effect.gameObject.SetActive(false);
                }
                else
                {
                    Instance.stopEffects.Add(new EffectStopData()
                    {
                        effect   = effect,
                        effectId = id,
                        time     = 0.0f
                    });
                }
            }

            index = ERROR_HANDLE;
        }
    }
Esempio n. 8
0
 public void DeleteRef(EFFECT_ID id)
 {
     for (int i = 0; i < effectLst_.Count; ++i)
     {
         if (effectLst_[i].id_.Equals(id))
         {
             effectLst_[i].refCount_ -= 1;
             if (effectLst_[i].refCount_ <= 0)
             {
                 effectLst_[i].DestoryAsset(false);
                 //effectLst_.RemoveAt(i);
             }
             break;
         }
     }
 }
Esempio n. 9
0
    public void LoadEffect(EFFECT_ID effID, InstanceCallBack callback, EffectAPI.MetaData metadata)
    {
        if (EffectAssetsData.GetData((int)effID) == null)
        {
            return;
        }
        GameObject eff = GetEffect(effID);

        if (eff != null)
        {
            EffectInst ei = eff.AddComponent <EffectInst> ();
            ei.ID = effID;
            callback(ei, metadata);
            return;
        }

        requestQue_.Enqueue(new LoadRequest(effID, callback, metadata));
    }
Esempio n. 10
0
 GameObject GetEffect(EFFECT_ID effID)
 {
     for (int i = 0; i < effectLst_.Count; ++i)
     {
         if (effectLst_[i].id_.Equals(effID))
         {
             if (effectLst_[i].bundle_ == null)
             {
                 effectLst_.RemoveAt(i);
                 break;
             }
             else
             {
                 effectLst_[i].refCount_ += 1;
                 return((GameObject)GameObject.Instantiate(effectLst_[i].bundle_.mainAsset) as GameObject);
             }
         }
     }
     return(null);
 }
Esempio n. 11
0
    public static void StopEffect(EFFECT_ID id, bool force = false)
    {
        if (!IsLoaded())
        {
            return;
        }

        if (IsInstance)
        {
            var effects = Instance.effectTable[(int)id];
            for (int i = 0; i < effects.Length; i++)
            {
                var effect = effects[i];
                effect.Stop();

                for (int k = 0; k < Instance.playEffects.Count; k++)
                {
                    var playData = Instance.playEffects[k];
                    if (playData.effectId == id && playData.index == i)
                    {
                        Instance.playEffects.RemoveAt(k);
                        break;
                    }
                }

                if (force)
                {
                    effect.gameObject.SetActive(false);
                }
                else
                {
                    Instance.stopEffects.Add(new EffectStopData()
                    {
                        effect   = effect,
                        effectId = id,
                        time     = 0.0f
                    });
                }
            }
        }
    }
Esempio n. 12
0
    public static void PlayUIEffect(EFFECT_ID id, Transform parent = null, Destroy.FinishCallBack finishEvent = null, InstCallBack instCallBack = null)
    {
        EffectMgr.UIEffectInfo uiei = new EffectMgr.UIEffectInfo();
        uiei.parent_       = parent;
        uiei.instCallBack_ = instCallBack;
        uiei.finCallBack_  = finishEvent;
        uiei.finished_     = false;

        EffectAssetMgr.LoadAsset(id, (AssetBundle bundle, ParamData data) =>
        {
            if (bundle.mainAsset == null)
            {
                ClientLog.Instance.LogError("Effect bundle is broken.   ID : " + id);
                return;
            }
            data.uiEffectInfo_.bundle_ = bundle;
            Transform tParent          = data.uiEffectInfo_.parent_;
            if (tParent.Equals(ApplicationEntry.Instance.uiRoot.transform))
            {
                EffectMgr.Instance.uiEffectQue_.Enqueue(data.uiEffectInfo_);
            }
            else
            {
                GameObject effObj = (GameObject)GameObject.Instantiate(bundle.mainAsset);
                EffectAssetMgr.DeleteAsset(bundle, false);
                effObj.transform.parent     = data.uiEffectInfo_.parent_;
                effObj.transform.localScale = Vector3.one;
                if (data.uiEffectInfo_.instCallBack_ != null)
                {
                    data.uiEffectInfo_.instCallBack_(effObj);
                }
                Destroy de = effObj.GetComponent <Destroy>();
                if (de == null)
                {
                    de          = effObj.AddComponent <Destroy>();
                    de.lifetime = 3f;
                }
                de.OnPlayFinish += data.uiEffectInfo_.finCallBack_;
            }
        }, new ParamData(uiei));
    }
Esempio n. 13
0
 public void PreLoadEffect(EFFECT_ID effID, InstanceCallBack callback)
 {
     if (EffectAssetsData.GetData((int)effID) == null)
     {
         if (callback != null)
         {
             callback(null, null);
         }
         return;
     }
     if (HasEffect(effID))
     {
         if (callback != null)
         {
             callback(null, null);
         }
     }
     else
     {
         requestQue_.Enqueue(new LoadRequest(effID, callback, null));
     }
 }
Esempio n. 14
0
 public static void PlaySceneEffect(EFFECT_ID id, Vector3 localPos, Transform parent = null, InstCallBack callback = null, bool billboard = false, float offsetY = 0f)
 {
     EffectAssetMgr.LoadAsset(id, (AssetBundle bundle, ParamData data) =>
     {
         if (bundle.mainAsset == null)
         {
             ClientLog.Instance.LogError("Effect bundle is broken.   ID : " + id);
             return;
         }
         GameObject effObj = (GameObject)GameObject.Instantiate(bundle.mainAsset);
         EffectAssetMgr.DeleteAsset(bundle, false);
         effObj.transform.parent        = data.tTransform_;
         effObj.transform.localPosition = new Vector3(localPos.x, localPos.y + offsetY, localPos.z);
         if (billboard)
         {
             effObj.AddComponent <Billboard>();
         }
         if (callback != null)
         {
             callback(effObj);
         }
     }, new ParamData(parent));
 }
Esempio n. 15
0
 public void PlayEffect(EFFECT_ID ID)
 {
     PlayEffect((int)(ID));
 }
Esempio n. 16
0
 public LoadRequest(EFFECT_ID id, EffectMgr.InstanceCallBack callback, EffectAPI.MetaData metadata)
 {
     id_        = id;
     callback_  = callback;
     meta_data_ = metadata;
 }
Esempio n. 17
0
    public static void Play(EFFECT_ID id,
                            GameObject caster,
                            GameObject[] aims = null,
                            TakeDmgCallBackPack takedmagepack             = null,
                            EffectInst.FinishCallBack finishcallback      = null,
                            EffectInstanceCallBack effectinstancecallback = null,
                            ParamData data = null)
    {
        EffectAssetsData ead = EffectAssetsData.GetData((int)id);

        if (ead == null)
        {
            return;
        }
        EffectBehaviourData ebd = EffectBehaviourData.GetData(ead.behaviour_id_);

        Vector3 vcaster = new Vector3(0f, 0f, 0f);

        Vector3[] vaims = null;
        if (null != aims)
        {
            vaims = new Vector3[aims.Length];
        }

        if (ebd.effect_positionType == EffectBehaviourData.EffectPositionType.Up)
        {
            if (caster != null)
            {
                vcaster = new Vector3(caster.collider.bounds.center.x, caster.collider.bounds.center.y + caster.collider.bounds.size.y / 2, caster.collider.bounds.center.z);
            }
            if (aims != null)
            {
                for (int iCount = 0; iCount < aims.Length; ++iCount)
                {
                    vaims[iCount] = new Vector3(aims[iCount].collider.bounds.center.x, aims[iCount].collider.bounds.center.y + aims[iCount].collider.bounds.size.y / 2, aims[iCount].collider.bounds.center.z);
                }
            }
        }
        else if (ebd.effect_positionType == EffectBehaviourData.EffectPositionType.Center)
        {
            if (caster != null)
            {
                vcaster = caster.collider.bounds.center;
            }
            if (aims != null)
            {
                for (int iCount = 0; iCount < aims.Length; ++iCount)
                {
                    vaims[iCount] = aims[iCount].collider.bounds.center;
                }
            }
        }
        else if (ebd.effect_positionType == EffectBehaviourData.EffectPositionType.Down)
        {
            if (caster != null)
            {
                vcaster = new Vector3(caster.collider.bounds.center.x, caster.collider.bounds.center.y - caster.collider.bounds.size.y / 2, caster.collider.bounds.center.z);
            }
            if (aims != null)
            {
                for (int iCount = 0; iCount < aims.Length; ++iCount)
                {
                    vaims[iCount] = new Vector3(aims[iCount].collider.bounds.center.x, aims[iCount].collider.bounds.center.y - aims[iCount].collider.bounds.size.y / 2, aims[iCount].collider.bounds.center.z);
                }
            }
        }
        else
        {
        }

        Play(id, vcaster, vaims, takedmagepack, finishcallback, effectinstancecallback, data);
    }
Esempio n. 18
0
    public static void Play(EFFECT_ID id, Vector3 caster, Vector3[] aims = null, TakeDmgCallBackPack takedmagepack = null, EffectInst.FinishCallBack finishcallback = null, EffectInstanceCallBack effectinstancecallback = null, ParamData data = null, Transform[] parents = null)
    {
        EffectAssetsData ead = EffectAssetsData.GetData((int)id);

        if (ead == null)
        {
            ClientLog.Instance.LogError("could not find the effect asset by id: " + id + "  caster position is " + caster);
            return;
        }

        int SoundId = EffectAssetsData.GetData((int)id).SoundID;

        SoundTools.PlaySound((SOUND_ID)SoundId);

        //////////////////////////////////////////////////////////////////////////
        // aims 有可能是null
        // 但在进场景那一刻 有可能会出现 需要有目标的特效没有目标 可能会导致卡死
        // 考虑是否加一个完成回调

        EffectBehaviourData ebd = EffectBehaviourData.GetData(ead.behaviour_id_);

        if (ebd != null)
        {
            EffectBehaviourData.CASTTYPE castType = ebd.cast_type_;
            int maxCount = (aims == null? 0: aims.Length);
//			int maxCount = aims.Length;
            if (castType.Equals(EffectBehaviourData.CASTTYPE.SameTime) ||
                castType.Equals(EffectBehaviourData.CASTTYPE.OneByOne))
            {
                if (aims != null)
                {
                    for (int i = 0; i < maxCount; ++i)
                    {
                        EffectMgr.Instance.LoadEffect(
                            id, EffectInstCallBack,
                            new MetaData(takedmagepack == null? null: takedmagepack.hit_1,
                                         takedmagepack == null? null: takedmagepack.hit_2,
                                         takedmagepack == null? null: takedmagepack.effect,
                                         takedmagepack == null? null: takedmagepack.changeVal,
                                         i == aims.Length - 1? finishcallback: null,
                                         caster,
                                         new Vector3[] { aims[i] }, data == null? i: data.iParam, effectinstancecallback, data == null? new ParamData(i): data, parents));
                    }
                }
                else
                {
                    EffectMgr.Instance.LoadEffect(id, EffectInstCallBack,
                                                  new MetaData(takedmagepack == null? null: takedmagepack.hit_1,
                                                               takedmagepack == null? null: takedmagepack.hit_2,
                                                               takedmagepack == null? null: takedmagepack.effect,
                                                               takedmagepack == null ? null : takedmagepack.changeVal, finishcallback, caster, aims, 0, effectinstancecallback, data, parents));
                }
            }
            else if (castType.Equals(EffectBehaviourData.CASTTYPE.OnlyOne))
            {
                EffectMgr.Instance.LoadEffect(id, EffectInstCallBack,
                                              new MetaData(takedmagepack == null? null: takedmagepack.hit_1,
                                                           takedmagepack == null? null: takedmagepack.hit_2,
                                                           takedmagepack == null? null: takedmagepack.effect,
                                                           takedmagepack == null ? null : takedmagepack.changeVal, finishcallback, caster, aims, 0, effectinstancecallback, data, parents));
            }
        }
        else
        {
            EffectMgr.Instance.LoadEffect(id, EffectInstCallBack,
                                          new MetaData(takedmagepack == null? null: takedmagepack.hit_1,
                                                       takedmagepack == null? null: takedmagepack.hit_2,
                                                       takedmagepack == null? null: takedmagepack.effect,
                                                       takedmagepack == null ? null : takedmagepack.changeVal, finishcallback, caster, aims, 0, effectinstancecallback, data, parents));
        }
    }
Esempio n. 19
0
 /// <summary>
 /// The set current effect.
 /// </summary>
 /// <param name="ID">
 /// The id.
 /// </param>
 public static void SetCurrentEffect(EFFECT_ID ID)
 {
     currentEffect = ID == EFFECT_ID.NONE ? null : effectDictionary[ID];
 }
Esempio n. 20
0
 /// <summary>
 /// The get effect.
 /// </summary>
 /// <param name="ID">
 /// The id.
 /// </param>
 /// <returns>
 /// </returns>
 public static Effect GetEffect(EFFECT_ID ID)
 {
     return(effectDictionary[ID]);
 }
Esempio n. 21
0
    public void Catch(COM_ReportAction action, CatchCallBack callback)
    {
        callBack_ = callback;
        aim_      = Battle.Instance.GetActorByIdx(action.target_);
        master_   = Battle.Instance.GetActorByInstId(action.casterId_);

        if (aim_ == null)
        {
            return;
        }

        if (master_ == null)
        {
            return;
        }

        master_.ControlEntity.SetAnimationParam(GlobalValue.TCast, AnimatorParamType.APT_Trigger);
        EFFECT_ID id = (EFFECT_ID)SkillData.GetMinxiLevelData(action.skill_)._Cast_effectID;

        if (aim_.ControlEntity == null || aim_.ControlEntity.ActorObj == null)
        {
            return;
        }

        EffectAPI.Play(id, aim_.ControlEntity.ActorObj);
        GlobalInstanceFunction.Instance.ScaleLerp(aim_.ControlEntity.ActorObj.transform, 1f, 0.3f, 0.5f, () =>
        {
            if (aim_.ControlEntity == null || aim_.ControlEntity.ActorObj == null)
            {
                return;
            }
            GlobalInstanceFunction.Instance.ScaleLerp(aim_.ControlEntity.ActorObj.transform, 0.3f, 1f, 0.5f, () =>
            {
                if (aim_.ControlEntity == null || aim_.ControlEntity.ActorObj == null)
                {
                    return;
                }
                GlobalInstanceFunction.Instance.ScaleLerp(aim_.ControlEntity.ActorObj.transform, 1f, 0.3f, 0.5f, () =>
                {
                    if (aim_.ControlEntity == null || aim_.ControlEntity.ActorObj == null)
                    {
                        return;
                    }
                    GlobalInstanceFunction.Instance.ScaleLerp(aim_.ControlEntity.ActorObj.transform, 0.3f, 1f, 0.5f, () =>
                    {
                        if (aim_.ControlEntity == null || aim_.ControlEntity.ActorObj == null)
                        {
                            return;
                        }
                        if (action.zhuachongOk_)
                        {
                            if (aim_.ControlEntity == null || aim_.ControlEntity.ActorObj == null)
                            {
                                return;
                            }
                            GlobalInstanceFunction.Instance.ScaleLerp(aim_.ControlEntity.ActorObj.transform, 1f, 0f, 0.5f, () =>
                            {
                                Transform pos = Battle.Instance.GetStagePointByIndex(aim_.BattlePos);
                                if (pos == null)
                                {
                                    return;
                                }
                                EffectAPI.PlaySceneEffect(EFFECT_ID.EFFECT_Fengyinchenggong, Vector3.zero, pos, null, true);
                                Battle.Instance.DeleteBattleEntityItem(aim_.InstId);
                                Battle.Instance.DeleteDeadEntity(aim_.InstId);
                                GlobalInstanceFunction.Instance.Invoke(() =>
                                {
                                    if (callBack_ != null)
                                    {
                                        callBack_();
                                    }
                                }, 1f);
                            });
                        }
                        else
                        {
                            if (callBack_ != null)
                            {
                                callBack_();
                            }
                        }
                    });
                });
            });
        });
    }