void OnEnable() { if (_FxOneComp == null) { _FxOneComp = gameObject.GetComponent <CFxOne>(); } }
private void OnFxStop(CFxOne fxone) { if (_IsLoading) { _DeferedGotFx.Remove(fxone); } --_ActiveFxCount; if (_ActiveFxCount == 0) { DeactiveTime = Time.time; } // 将干净的RealFxGameObject缓存处理 // 自身清理在CFxOne的OnStop var fx = fxone.GetFxGameObject(); if (fx != null) { fx.transform.parent = CachedFxsRoot; fx.transform.localPosition = Vector3.zero; _CachedFxs.Add(fx); fxone.SetFxGameObject(null); } // 清理FxOne,回收FxOne组件 CFxCacheMan.Instance.RecycleFx(fxone); }
// 此接口慎用,非正常清理方式 public void RemoveFxOneUsingTheWrongWay(CFxOne fxone) { if (_ActiveFxs.Contains(fxone)) { _ActiveFxs.Remove(fxone); } }
private CFxOne GetEmptyFxOne() { CFxOne fxone = null; for (var i = _CachedFxOnes.Count - 1; i >= 0; i--) { fxone = _CachedFxOnes[i]; if (fxone != null && fxone.gameObject != null) { _CachedFxOnes.RemoveAt(i); #if UNITY_EDITOR fxone.gameObject.name = "gfx"; #endif //fxone.gameObject.SetActive(true); return(fxone); } else { _CachedFxOnes.RemoveAt(i); } } GameObject go = new GameObject("gfx"); fxone = go.AddComponent <CFxOne>(); return(fxone); }
private void OnFxPlay(CFxOne fxone) { if (LoadAssetButNotPlay) { return; } if (_IsLoading) { _DeferedGotFx.Add(fxone); } else { GameObject fx = null; if (_CachedFxs.Count > 0) { fx = _CachedFxs[0]; _CachedFxs.RemoveAt(0); } else { fx = UnityEngine.Object.Instantiate(_Asset) as GameObject; } Transform trans = fx.transform; trans.parent = fxone.transform; trans.localPosition = Vector3.zero; trans.localRotation = Quaternion.identity; trans.localScale = Vector3.one; //Util.SetLayerRecursively(fx, LayerMask.NameToLayer("Fx")); Util.SetLayerRecursively(fx, fxone.gameObject.layer); fxone.SetFxGameObject(fx); } }
static int Stop(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 1); CFxOne obj = (CFxOne)LuaScriptMgr.GetUnityObjectSelf(L, 1, "CFxOne"); obj.Stop(); return(0); }
static int Play(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 2); CFxOne obj = (CFxOne)LuaScriptMgr.GetUnityObjectSelf(L, 1, "CFxOne"); float arg0 = (float)LuaScriptMgr.GetNumber(L, 2); obj.Play(arg0); return(0); }
public CFxOne RequestUncachedFx(string fxName, bool isSingleton = true) { CFxOne fxone = null; if (!isSingleton || !_UncachedFxs.TryGetValue(fxName, out fxone) || fxone == null || fxone.gameObject == null) //被清理 { fxone = new GameObject("UncachedFx").AddComponent <CFxOne>(); fxone.Priority = -1; fxone.IsCached = false; Action <UnityEngine.Object> callback = (asset) => { if (asset != null && fxone != null && fxone.gameObject != null) { GameObject fx = GameObject.Instantiate(asset) as GameObject; if (fx != null) { Transform fxTrans = fx.transform; fxTrans.parent = fxone.transform; fxTrans.localPosition = Vector3.zero; fxTrans.localRotation = Quaternion.identity; fxTrans.localScale = Vector3.one; Util.SetLayerRecursively(fx, fxone.gameObject.layer); fxone.SetFxGameObject(fx); fxone.Active(true); fxone.SetScale(fxone.RealScale); } else { HobaDebuger.LogWarningFormat("RequestUncachedFx asset is not GameObject!: {0}", fxName); } } }; CAssetBundleManager.AsyncLoadResource(fxName, callback, false, "sfx"); if (isSingleton) { fxone.transform.parent = _UncachedFxsRootTrans; if (!_UncachedFxs.ContainsKey(fxName)) { _UncachedFxs.Add(fxName, fxone); } else { _UncachedFxs[fxName] = fxone; } } } else { fxone.Active(true); fxone.SetScale(fxone.RealScale); } return(fxone); }
private static int PlayEarlyWarningGfx(IntPtr L) { int count = LuaDLL.lua_gettop(L); const int nRet = 2; if (count == 6 && LuaScriptMgr.CheckTypes(L, 1, typeof(string), typeof(LuaTable), typeof(LuaTable), typeof(LuaTable), typeof(float), typeof(bool))) { float lifeTime = (float)LuaScriptMgr.GetNumber(L, 5); if (lifeTime < 0.01f) { LuaDLL.lua_pushnil(L); LuaScriptMgr.Push(L, 0); return(CheckReturnNum(L, count, nRet)); } string gfxName = LuaScriptMgr.GetString(L, 1); int fxId = 0; CFxOne fx = CFxCacheMan.Instance.RequestFxOne(gfxName, -1, out fxId); if (fx == null) { LuaDLL.lua_pushnil(L); LuaScriptMgr.Push(L, 0); return(CheckReturnNum(L, count, nRet)); } Vector3 pos = LuaScriptMgr.GetVector3(L, 2); Vector3 dir = LuaScriptMgr.GetVector3(L, 3); Vector3 scale = LuaScriptMgr.GetVector3(L, 4); bool doNotUseProjector = LuaScriptMgr.GetBoolean(L, 6); Transform trans = fx.transform; trans.position = pos; trans.rotation = CMapUtil.GetMapNormalRotationWithDistance(pos, dir, Math.Max(scale.x, scale.z)); //法线为地面法线 trans.localScale = Vector3.one; fx.IsFixRot = false; if (fx.EarlyWarning == null) { fx.EarlyWarning = new EarlyWarningInfo(); } fx.EarlyWarning.Set(Time.time, lifeTime, scale, doNotUseProjector); fx.Play(lifeTime + 0.2f); LuaScriptMgr.Push(L, fx.gameObject); LuaScriptMgr.Push(L, fx.ID); } else { LogParamError("PlaySkillIndicatorGfx", count); LuaDLL.lua_pushnil(L); LuaScriptMgr.Push(L, 0); } return(CheckReturnNum(L, count, nRet)); }
public static int RequestArcFx(IntPtr L) { int count = LuaDLL.lua_gettop(L); const int nRet = 2; if (LuaDLL.lua_isstring(L, 1) == false) { HobaDebuger.LogError("GetArcFx: param 1 must be string"); LuaDLL.lua_pushnil(L); LuaScriptMgr.Push(L, 0); return(CheckReturnNum(L, count, nRet)); } string name = LuaScriptMgr.GetString(L, 1); var owner = LuaScriptMgr.GetUnityObject <GameObject>(L, 2); var target = LuaScriptMgr.GetUnityObject <GameObject>(L, 3); if (owner == null || target == null) { HobaDebuger.LogError("GetArcFx: param 2 or 3 is null"); LuaDLL.lua_pushnil(L); LuaScriptMgr.Push(L, 0); return(CheckReturnNum(L, count, nRet)); } int priority = 0; if (count > 3) { priority = (int)LuaScriptMgr.GetNumber(L, 4); } int fxId = 0; CFxOne fxone = CFxCacheMan.Instance.RequestFxOne(name, priority, out fxId); if (fxone != null) { fxone.IsFixRot = false; if (fxone.ArcReactor == null) { fxone.ArcReactor = new ArcReactorInfo(); } fxone.ArcReactor.Set(owner.transform, target.transform); LuaScriptMgr.Push(L, fxone.gameObject); LuaScriptMgr.Push(L, fxId); } else { LuaDLL.lua_pushnil(L); LuaScriptMgr.Push(L, fxId); } return(CheckReturnNum(L, count, nRet)); }
public bool Touch(CFxOne fxone) { fxone.OnPlay = null; fxone.OnStop = null; if (!_IsLoading && _Asset == null) { return(false); } ++_ActiveFxCount; DeactiveTime = -1; fxone.OnPlay = OnFxPlay; fxone.OnStop = OnFxStop; return(true); }
public static int RequestFx(IntPtr L) { int count = LuaDLL.lua_gettop(L); const int nRet = 2; if (LuaDLL.lua_isstring(L, 1) == false) { HobaDebuger.LogError("RequestFx: param 1 must be string"); LuaDLL.lua_pushnil(L); LuaScriptMgr.Push(L, 0); return(CheckReturnNum(L, count, nRet)); } if (LuaDLL.lua_isboolean(L, 2) == false) { HobaDebuger.LogError("RequestFx: param 2 must be boolean"); LuaDLL.lua_pushnil(L); LuaScriptMgr.Push(L, 0); return(CheckReturnNum(L, count, nRet)); } string name = LuaScriptMgr.GetString(L, 1); bool fixRot = (bool)LuaScriptMgr.GetBoolean(L, 2); int priority = 50; if (count > 2) { priority = (int)LuaScriptMgr.GetNumber(L, 3); } int fxId = 0; CFxOne fxone = CFxCacheMan.Instance.RequestFxOne(name, priority, out fxId); if (fxone != null) { fxone.IsFixRot = fixRot; LuaScriptMgr.Push(L, fxone.gameObject); LuaScriptMgr.Push(L, fxId); } else { LuaDLL.lua_pushnil(L); LuaScriptMgr.Push(L, fxId); } return(CheckReturnNum(L, count, nRet)); }
static int get_IsPlaying(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); CFxOne obj = (CFxOne)o; if (obj == null) { LuaTypes types = LuaDLL.lua_type(L, 1); if (types == LuaTypes.LUA_TTABLE) { LuaDLL.luaL_error(L, "unknown member name IsPlaying"); } else { LuaDLL.luaL_error(L, "attempt to index IsPlaying on a nil value"); } } LuaScriptMgr.Push(L, obj.IsPlaying); return(1); }
public void RecycleFx(CFxOne fxone) { _ActiveFxs.Remove(fxone); var ms = fxone.gameObject.GetComponents <CMotor>(); if (ms != null && ms.Length > 0) { for (var i = 0; i < ms.Length; i++) { UnityEngine.Object.Destroy(ms[i]); } } #if UNITY_EDITOR fxone.gameObject.name = "gfx_one_unused"; #endif fxone.transform.position = Vector3.zero; fxone.transform.parent = _CachedFxOnesRootTrans; //fxone.DontUseL3 = false; //fxone.gameObject.SetActive(false); _CachedFxOnes.Add(fxone); }
public CFxOne RequestFxOne(string fxName, int priority, out int fxId) { // 超出上限,先关掉优先级最低的 #region 存量检查 if (_ActiveFxs.Count >= _MaxActiveFxCount) { int maxPriority = -1; int realCount = 0; for (int i = 0; i < _ActiveFxs.Count; ++i) { CFxOne fx = _ActiveFxs[i]; //-1 常驻 不参与计算 if (fx.Priority != -1) { if (fx.Priority > maxPriority) { maxPriority = fx.Priority; } ++realCount; } } if (realCount > _MaxActiveFxCount) { if (priority >= maxPriority) { fxId = 0; return(null); } // 关闭一个最低优先级的特效 for (int i = 0; i < _ActiveFxs.Count; ++i) { CFxOne fx1 = _ActiveFxs[i]; if (fx1.Priority == maxPriority) { fx1.Stop(); _ActiveFxs.Remove(fx1); break; } } } } #endregion // 检查资源缓存池 CFxCache fxcache = null; #region FxAssetCache_Area if (!_FxAssetCaches.TryGetValue(fxName, out fxcache)) { fxcache = new CFxCache(); fxcache.Init(fxName); _FxAssetCaches[fxName] = fxcache; } #endregion CFxOne fxone = GetEmptyFxOne(); #region GetFxOne_Area fxone.IsCached = true; fxone.ID = NewID(); //fxone.DontUseL3 = dontUseL3; var fxoneTrans = fxone.transform; fxoneTrans.parent = _ActiveFxsRootTrans; fxoneTrans.localPosition = Vector3.zero; fxoneTrans.localScale = Vector3.one; fxoneTrans.rotation = Quaternion.identity; #if UNITY_EDITOR fxone.Name = fxName; #endif fxone.Priority = priority; _ActiveFxs.Add(fxone); #endregion fxId = fxone.ID; if (!fxcache.Touch(fxone)) { RecycleFx(fxone); return(null); } return(fxone); }
public static GameObject PlayFx(Transform hook, Transform anchor, GameObject clipper, string fx_path, float life_time, bool is_ui, int order_offset = 0) { if (!is_ui) { #if ART_USE && UNITY_EDITOR GameObject obj = UnityEditor.AssetDatabase.LoadAssetAtPath(fx_path, typeof(GameObject)) as GameObject; if (obj != null) { obj = Object.Instantiate <GameObject>(obj); Transform t = obj.transform; t.SetParent(hook, false); obj.SetActive(true); Util.SetLayerRecursively(obj, LayerMask.NameToLayer("UIScene")); //re-position if (anchor != null && anchor != hook) { t.position = anchor.position; } if (life_time < 0.0001f) { FxDuration fxd = obj.GetComponent <FxDuration>(); if (fxd != null) { life_time = fxd.duration; } } Object.Destroy(obj, life_time > 0.0001f ? life_time : 5); Debug.Log("PlayFx " + hook.name + ", " + fx_path + ", " + life_time); } return(obj); #else //Debug.Log("TODO: PlayFx"); #if IN_GAME int fxId = 0; CFxOne fxOne = CFxCacheMan.Instance.RequestFxOne(fx_path, -1, out fxId); if (fxOne != null) { Transform t_fx = fxOne.transform; GameObject g_fx = fxOne.gameObject; t_fx.SetParent(hook, false); //re-position if (anchor != null && anchor != hook) { t_fx.position = anchor.position; } //g_fx.SetActive(true); Util.SetLayerRecursively(g_fx, LayerMask.NameToLayer("UIScene")); fxOne.Play(life_time); return(fxOne.gameObject); } return(null); #else return(null); #endif #endif } else { return(UISfxBehaviour.Play(fx_path, anchor.gameObject, hook.gameObject, clipper, life_time, 20, order_offset)); } }