/// <summary> /// 在uuid的玩家身上播放物品gid对应的烟火特效资源 /// </summary> /// <param name="uuid"></param> /// <param name="gid"></param> public void Ignite(uint uuid, uint gid) { var info = DBMarryFirework.Instance.GetInfo(gid); if (info == null) { GameDebug.LogError("[Ignite]get firework info failed, id:" + gid); return; } /*var actor = ActorManager.Instance.GetActor(uuid); * if (actor == null || actor.IsDestroy) * { * GameDebug.LogError("[Ignite]get actor info failed, id:" + uuid); * return; * }*/ var isLocalPlayer = uuid == LocalPlayerManager.Instance.LocalActorAttribute.UnitId.obj_idx; if (isLocalPlayer) { // 停止之前正在播放的特效 if (mEmitInfo != null && !mEmitInfo.IsFinish) { mEmitInfo.Stop(); } } else { // 如果当前有正在播放的特效,则直接返回 if (mEmitInfo != null && !mEmitInfo.IsFinish) { return; } } if (mEmitId == 0) { mEmitId++; } mCurEmitId = mEmitId; if (mEmitInfo == null) { mEmitInfo = new EmitInfo(mCurEmitId, info.Time, info.AssetPath); } else { mEmitInfo.Reset(mCurEmitId, info.Time, info.AssetPath); } MainGame.HeartBehavior.StartCoroutine(PlayEffect(info.AssetPath, mEmitInfo, mCurEmitId)); MainGame.HeartBehavior.StartCoroutine(PlayAudio("Assets/Res/" + info.AudioPath, mEmitInfo, mCurEmitId)); mEmitId++; }
/// <summary> /// 在指定位置播放特效 /// </summary> /// <param name="effectPath"></param> /// <param name="pos"></param> /// <returns></returns> public IEnumerator PlayEffect(string effectPath, EmitInfo emitInfo, uint emitId) { var objectWrapper = new ObjectWrapper(); yield return(MainGame.HeartBehavior.StartCoroutine(ObjCachePoolMgr.Instance.LoadPrefab(effectPath, ObjCachePoolType.SFX, effectPath, objectWrapper))); if (objectWrapper.obj == null) { yield break; } var effectObject = objectWrapper.obj as GameObject; if (effectObject == null) { yield break; } GameDebug.Log("emit:" + emitInfo.EmitID + "," + emitId); // 如果当前ID发生变化,说明之前的特效播放已经被终止 if (emitId != mCurEmitId) { ObjCachePoolMgr.Instance.RecyclePrefab(effectObject, ObjCachePoolType.SFX, effectPath); yield break; } emitInfo.SetObject(effectObject); // 如果找不到当前主相机,则停止特效的播放 Camera mainCam = Camera.main; if (mainCam == null) { if (!emitInfo.IsFinish) { emitInfo.Stop(); } yield break; } var effectTrans = effectObject.transform; effectTrans.parent = mainCam.transform; effectTrans.localPosition = Vector3.zero; effectTrans.localScale = Vector3.one; effectTrans.localRotation = Quaternion.identity; }