public void Stop() { if (this == null) { return; //可能已经被销毁 } if (!m_isPlaying) //防止死锁 { return; } //1 必须先把这个值设置正确,不然可能造成死锁 m_isPlaying = false; //Remove和stop可能会互相调用,内部已经防止死锁,这里不用判断 m_handle.mgr.Remove(m_handle); //DoDestroy和stop可能会互相调用,内部已经防止死锁,这里不用判断 FxDestroy.DoDestroy(this.gameObject); m_handle = null; foreach (CameraAni a in m_anis) { a.OnStop(); } }
public void Play() { if (m_isPlaying) { Debuger.Log("还没结束就重新播放了"); Stop();//先结束老的 } //先找到对应的脚本 m_fx = GetComponent <PostEffectsBase>(); if (m_fx == null) { Debuger.Log("没有找到后期处理特效"); FxDestroy.DoDestroy(this.gameObject); return; } GetComponent <Camera>().enabled = false;//隐藏相机,如果没有隐藏的话 Type t = m_fx.GetType(); m_method = t.GetMethod("OnRenderImage", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (m_method == null) { Debuger.Log("没有找到OnRenderImage方法:{0}", t.Name); FxDestroy.DoDestroy(this.gameObject); return; } //添加到相机特效管理器 Camera c = null; #if ART_DEBUG c = Camera.main; #else c = CameraMgr.instance == null?null:CameraMgr.instance.CurCamera; #endif if (c == null) { Debuger.LogError("找不到相机"); FxDestroy.DoDestroy(this.gameObject); return; } CameraFxMgr camFxMgr = c.AddComponentIfNoExist <CameraFxMgr>(); m_handle = camFxMgr.Add(t.Name, this); m_isPlaying = true; m_beginTime = Util.time; m_destroyTime = -1; GameObjectPoolObject po = this.AddComponentIfNoExist <GameObjectPoolObject>(); if (po != null)//为了实现延迟销毁机制,要用到对象池 { po.m_onIngoreDestroy = IngorePoolDestroy; } foreach (CameraAni a in m_anis) { a.OnBegin(m_fx); } }
static void AddFxDestroy() { if (UnityEditor.Selection.activeGameObject != null) { FxDestroy fx = UnityEditor.Selection.activeGameObject.AddComponentIfNoExist <FxDestroy>(); fx.m_delay = 1; EditorUtil.SetDirty(fx); } }
// Update is called once per frame void Update() { //判断下结束 if (m_isPlaying && !m_needDestroy && (m_duration > 0 && (Util.time - m_beginTime) > m_duration)) { m_needDestroy = true; FxDestroy.DoDestroy(this.gameObject); } }
//有没永久的或者运行时的延迟销毁 public static bool HasDelay(GameObject go) { FxDestroy fd = go.GetComponent <FxDestroy>(); if (fd == null) { return(false); } return(fd.m_delay != -1 || fd.RunTimeDelay != -1); }
public static float GetRunTimeDelayIfExist(GameObject go) { FxDestroy fd = go.GetComponent <FxDestroy>(); if (fd == null) { return(-1); } return(fd.RunTimeDelay); }
public static void Add(GameObject go, float delay) { FxDestroy fd = go.AddComponentIfNoExist <FxDestroy>(); if (!fd.gameObject.activeSelf) { return; } fd.RunTimeDelay = delay; }
//销毁全部 public void Destroy(bool checkIngoreDestroy = true) { for (int i = 0; i < fxs.Count; ++i) { if (fxs[i] != null) { FxDestroy.DoDestroy(fxs[i], checkIngoreDestroy); } } fxs.Clear(); }
//由CameraFxMgr调用,外部不要调用 public void OnUpdateCamera(RenderTexture source, RenderTexture destination) { if (m_method == null || m_fx == null) { FxDestroy.DoDestroy(this.gameObject); return; } foreach (CameraAni a in m_anis) { a.OnUpdateCamera(m_fx, Util.time - m_beginTime); } m_method.Invoke(m_fx, new System.Object[] { source, destination }); }
private void settingCallBack(GameObject obj, float time) { if (obj == null) { return; } FxDestroy fxDestroy = obj.GetComponent <FxDestroy>(); if (fxDestroy == null) { fxDestroy = obj.AddComponent <FxDestroy>(); fxDestroy.destroytm = time; } fxDestroy.disposeCallback = disposeCallBack; fxDestroy.startCount(); }
void OnDisable() { if (m_isApplicationQuit) { return; } Stop(); #if UNITY_EDITOR //如果是编辑器没有运行查看要手动调用下FxDestroy的update if (Application.isEditor && !Application.isPlaying) { FxDestroy fxDestroy = this.GetComponent <FxDestroy>(); if (fxDestroy != null) { fxDestroy.Invoke("OnDisable", 0); } } #endif }
public void PlayRadialBlur(float strength, Transform t, float duration, Vector3 offset, float beginSmooth, float endSmooth) { GameObject go = GameObjectPool.GetPool(GameObjectPool.enPool.Fx).GetImmediately("fx_camera_blur_internal", false); CameraFx cameraFx = go.GetComponent <CameraFx>(); CameraAni cameraAni = cameraFx.m_anis[0]; cameraAni.m_endFloat = strength; cameraAni.m_beginDuration = beginSmooth; cameraAni.m_endDuration = endSmooth; RadialBlur blur = go.GetComponent <RadialBlur>(); blur.target = t; blur.offset = offset; go.SetActive(true); FxDestroy.Add(go, duration); }
void OnEnable() { #if UNITY_EDITOR //如果是编辑器没有运行查看要手动调用下FxDestroy的update if (Application.isEditor && !Application.isPlaying) { FxDestroy fxDestroy = this.GetComponent <FxDestroy>(); if (fxDestroy != null) { fxDestroy.Invoke("OnEnable", 0); } } #endif //判断IsPreloading是因为对象池预加载的时候不需要play if (!GameObjectPool.IsPreloading() && !m_isPlaying) { Play(); } }
// Update is called once per frame void Update() { //判断下结束 if (m_isPlaying && m_destroyTime != -1 && Util.time > m_destroyTime) { FxDestroy.DoDestroy(this.gameObject, false); m_destroyTime = -1; } #if UNITY_EDITOR //如果是编辑器没有运行查看要手动调用下FxDestroy的update if (m_isPlaying && Application.isEditor && !Application.isPlaying) { FxDestroy fxDestroy = this.GetComponent <FxDestroy>(); if (fxDestroy != null) { fxDestroy.Invoke("Update", 0); } } #endif }
public void Stop() { if (this == null) { return; //可能已经被销毁 } if (!m_isPlaying) //防止死锁 { return; } //1 必须先把这个值设置正确,不然可能造成死锁 m_isPlaying = false; //Remove和stop可能会互相调用,内部已经防止死锁,这里不用判断 m_handle.Release(); m_handle = null; //DoDestroy和stop可能会互相调用,内部已经防止死锁,这里不用判断 FxDestroy.DoDestroy(this.gameObject); }
public void Play() { if (m_isPlaying) { Debuger.Log("还没结束就重新播放了"); Stop();//先结束老的 } if (CameraMgr.instance == null) { Debuger.Log("没有找到相机管理器"); FxDestroy.DoDestroy(this.gameObject); return; } m_handle = CameraMgr.instance.Add(m_info); m_isPlaying = true; m_beginTime = Util.time; m_needDestroy = false; }
//每一帧有且只有一次被更新 //frame 当前帧 //loopCount 当前第几次动作循环 //trueframe 真实达到第几帧的 //end 真实是不是结束 //root 用于创建的时候计算位置用 public void UpdateFrame(int frame, int loop, bool isEnd, Transform root) { //检查销毁 if (endFrame > 0 && beginFrame + endFrame == frame && fxs.Count != 0) { Destroy(); } if (frame != beginFrame) { return; //不是这一帧 } if (prefab == null) { return; } if (loop > 0 && !loopCreate) { return; //已经循环过一次就不用创建了 } if (isEnd && (destroyIfAniEnd)) { return; //如果是动作结束销毁的,那么就不用创建了 } #if !ART_DEBUG //调试 if (onRuntimeCreate == null && canHide && !QualityMgr.instance.roleAniFx) { return; } #endif //不同元素属性创建不同特效 GameObject curPrefab = prefab; switch (this.parent.RuntimeElement) { case enAniFxElement.none: curPrefab = prefab; break; case enAniFxElement.fire: curPrefab = prefabFire; break; case enAniFxElement.ice: curPrefab = prefabIce; break; case enAniFxElement.thunder: curPrefab = prefabThunder; break; case enAniFxElement.dark: curPrefab = prefabDark; break; default: Debuger.LogError("动作特效 未知的元素类型:{0}", this.parent.RuntimeElement); break; } if (curPrefab == null) { curPrefab = prefab; } //1 创建特效 GameObject go = GameObjectPool.GetPool(GameObjectPool.enPool.Fx).GetImmediately(curPrefab.name, false); if (go == null) { //Debuger.LogError("逻辑错误动作绑定特效加载后为空");//这里只支持预加载,不支持异步加载,没有预加载过报错 return; } //2 设置位置和方向 Transform t = go.transform; if (type == enCreateType.bone)//绑定骨骼 { Transform target = GetTarget(root); if (follow) { t.SetParent(target, false); //t.localScale = Vector3.one; t.localPosition = offset; t.localEulerAngles = euler; } else { t.position = target.TransformPoint(offset); t.rotation = target.rotation * Quaternion.Euler(euler); } } else if (type == enCreateType.matrial)//绑定材质 { Transform target = root.Find("model/body_mesh"); if (target != null) { t.SetParent(target, false); //t.localScale = Vector3.one; t.localPosition = Vector3.zero; t.localEulerAngles = Vector3.zero; } target = root.Find("model/weapon_mesh"); if (target != null) { GameObject go2 = GameObjectPool.GetPool(GameObjectPool.enPool.Fx).GetImmediately(prefab.name, false); Transform t2 = go2.transform; t2.SetParent(target, false); t2.localPosition = Vector3.zero; t2.localEulerAngles = Vector3.zero; go2.SetActive(true);//设好了父节点了,这个时候再SetActive fxs.Add(go2); } } else { Debuger.LogError("未知的类型:{0}", type); } go.SetActive(true);//设好了父节点了,这个时候再SetActive //如果飞出物上没有任何销毁的脚本,那么提示下 if (!destroyIfAniEnd && endFrame <= 0 && !FxDestroy.HasDelay(go)) { Debuger.LogError("动作特效上没有绑销毁脚本,动作上也没有指定结束帧.特效名:{0}", go.name); } //加到列表中,方便管理 fxs.Add(go); //运行时创建回调 if (onRuntimeCreate != null) { onRuntimeCreate(go, onRuntimeCreateParam); } }