//设置光效行为类型 public void setEffectBehaviourType(EEffectBehaviour eType) { _eBehavourType = eType; if (_effectGameObj == null) { return; } EffectDefaultBehaviour pBhScript = null; switch (eType) { case EEffectBehaviour.eLineTrack: pBhScript = _effectGameObj.AddComponent <EffectLineBehaviour>(); break; case EEffectBehaviour.eParabolaTrack: pBhScript = _effectGameObj.AddComponent <EffectDefaultBehaviour>(); break; default: pBhScript = _effectGameObj.AddComponent <EffectDefaultBehaviour>(); break; } }
/////////////////////////////////////////////////////////////////////////////////// public EffectObject(string strEffectName, bool bAutoDestroy = true, EEffectBehaviour eBehaviour = EEffectBehaviour.eDefault) { _eBehavourType = eBehaviour; _effectName = strEffectName; _bIsAutoDestroy = bAutoDestroy; EffectManager.getInstance().addList(this); // string strEffectPath = EffectManager.getEffectFilePath(_effectName); // if (strEffectName.Contains("Effects/")) { // strEffectPath = _effectName.Substring(0, _effectName.LastIndexOf('.')); // } if (!strEffectName.Contains("Effects/") && !strEffectName.Contains("effect/"))//“Effects/”下才是光效 { return; } //if (AssetManager.getInstance().IsFirstUseStreamingAssets) if (AssetManager.getInstance().IsStreamingAssets(_effectName)) { _loading = true; //加载StreamingAssets下资源 _effectName = UtilTools.PathCheck(_effectName); AssetBundleLoadTask task = new AssetBundleLoadTask(_effectName); task.EventFinished += (manual, currentTask) => { _loading = false; AssetManager.getInstance().minusAssetbundleRefCount(_effectName); if (_bDestroy) { return; } Object assetObj = ((AssetBundleLoadTask)currentTask).getTargetAsset(); if (assetObj == null) { return; } _effectGameObj = UnityEngine.Object.Instantiate(assetObj) as GameObject; if (_effectGameObj == null) { //Utils.LogSys.Log("Effect game object is NULL"); return; } UtilTools.UpdateShaders(_effectGameObj); InitEffect(); if (_loadComplete != null) { _loadComplete(this); } }; } else { /* * string strEffectPath = _effectName;// EffectManager.getEffectFilePath(_effectName); * if (strEffectName.Contains("Effects/"))//“Effects/”下才是光效 * { * strEffectPath = _effectName.Substring(0, _effectName.LastIndexOf('.')); * if (strEffectPath.IndexOf("Resources/") == 0)//有“Resources/”就去掉 * { * strEffectPath = strEffectPath.Substring(10); * } * * UnityEngine.Object objRes = Resources.Load(strEffectPath); * if (objRes) * { * _effectGameObj = UnityEngine.Object.Instantiate(objRes) as GameObject; * if (_effectGameObj == null) * { * Utils.LogSys.Log("Effect game object is NULL"); * return; * } * InitEffect(); * if (_loadComplete != null) * _loadComplete(this); * } * }*/ _loading = true; AssetManager.getInstance().loadAssetAsync(_effectName, (bool manual, TaskBase currentTask) => { _loading = false; AssetManager.getInstance().minusAssetbundleRefCount(_effectName); if (_bDestroy) { return; } Object assetObj = AssetManager.getInstance().getAsset(_effectName); if (assetObj == null) { return; } _effectGameObj = UnityEngine.Object.Instantiate(assetObj) as GameObject; if (_effectGameObj == null) { //Utils.LogSys.Log("Effect game object is NULL"); return; } UtilTools.UpdateShaders(_effectGameObj); InitEffect(); if (_loadComplete != null) { _loadComplete(this); } }); } }