public FXData getFXData(string key) { FXData data = null; dataMap.TryGetValue(key, out data); return(data); }
/// <summary> /// 处理特效动画播放 /// </summary> /// <param name="fx"></param> private void HandleAnim(FXData fx) { if (!string.IsNullOrEmpty(fx.anim)) { if (!gameObject.animation) { gameObject.AddComponent <Animation>(); } //如果包含的话就直接播放动画 if (m_animationClips.ContainsKey(fx.anim)) { gameObject.animation.AddClip(m_animationClips[fx.anim], fx.anim); gameObject.animation.Play(fx.anim); } //否则就加载然后播放动画 else { ResourceManager.singleton.LoadEffect(fx.resourcePath, new AssetRequestFinishedEventHandler((_assetRequest) => { m_animationClips[fx.anim] = _assetRequest.AssetResource.MainAsset as AnimationClip; gameObject.animation.AddClip(m_animationClips[fx.anim], fx.anim); gameObject.animation.Play(fx.anim); }), AssetPRI.DownloadPRI_Low); } } }
private void HandleDissonFx(FXData fx) { orgShader = GetMatShader(); AssetCacheMgr.GetResource(fx.dissonShader, (shader) => { SetMatShader(shader as Shader); currentShaderFx = fx.id; AssetCacheMgr.GetResource(fx.nosieTexture, (nosieTexture) => { SetMatTexture("_NosieTex", nosieTexture as Texture); float nosieOffset = fx.nosieOffetFrom; SetMatFloat("_NosieOffset", nosieOffset); TimerHeap.AddTimer((uint)fx.dissonDelay, 0, () => { //Debug.Log("begin HandleDissonFx"); var duration = fx.dissonDuration; var loopTimer = TimerHeap.AddTimer(0, 100, () => { SetMatFloat("_NosieOffset", nosieOffset); nosieOffset = nosieOffset + (fx.nosieOffetTo - fx.nosieOffetFrom) * 100 / duration; //Debug.Log("nosieOffset: " + nosieOffset); }); TimerHeap.AddTimer((uint)duration, 0, () => { //Debug.Log("DelTimer HandleDissonFx"); TimerHeap.DelTimer(loopTimer); }); }); }); }); //Debug.Log("HandleDissonFx: " + fx.actionID); }
///// <summary> ///// 处理刀光 ///// </summary> ///// <param name="fx"></param> //private void HandleWeaponTrial(FXData fx) //{ // if (!string.IsNullOrEmpty(fx.weaponTailMaterial)) // { // if (m_weaponTrailsDic.ContainsKey(fx.weaponTailSlot)) // { // var item = m_weaponTrailsDic[fx.weaponTailSlot]; // if (m_weaponTrailMaterial.ContainsKey(fx.weaponTailMaterial)) // { // item.Material = m_weaponTrailMaterial[fx.weaponTailMaterial]; // item.subdivisions = fx.weaponTailSubdivisions; // item._lifeTime = fx.weaponTailLeftTime; // FrameFrameTimerHeap.AddTimer((uint)fx.weaponTailEmitTime, 0, () => { item.Emit = true; }); // FrameFrameTimerHeap.AddTimer((uint)(fx.weaponTailEmitTime + fx.weaponTailDurationTime), 0, () => { item.Emit = false; }); // } // else // { // //to do: 资源释放 // AssetCacheMgr.GetResource(fx.weaponTailMaterial, (go) => // { // m_weaponTrailMaterial[fx.weaponTailMaterial] = go as Material; // item.Material = m_weaponTrailMaterial[fx.weaponTailMaterial]; // item.subdivisions = fx.weaponTailSubdivisions; // item._lifeTime = fx.weaponTailLeftTime; // FrameFrameTimerHeap.AddTimer((uint)fx.weaponTailEmitTime, 0, () => { item.Emit = true; }); // FrameFrameTimerHeap.AddTimer((uint)(fx.weaponTailEmitTime + fx.weaponTailDurationTime), 0, () => { item.Emit = false; }); // }); // } // } // } //} /// <summary> /// 处理动画播放 /// </summary> /// <param name="fx"></param> private void HandleAnim(FXData fx) { if (!String.IsNullOrEmpty(fx.anim)) { if (!gameObject.GetComponent <Animation>()) { gameObject.AddComponent <Animation>(); } if (m_animationClip.ContainsKey(fx.anim)) { gameObject.GetComponent <Animation>().AddClip(m_animationClip[fx.anim], fx.anim); gameObject.GetComponent <Animation>().Play(fx.anim); } else { //to do: 资源释放 AssetCacheMgr.GetResourceAutoRelease(fx.anim, (go) => { m_animationClip[fx.anim] = go as AnimationClip; gameObject.GetComponent <Animation>().AddClip(m_animationClip[fx.anim], fx.anim); gameObject.GetComponent <Animation>().Play(fx.anim); }); } } }
protected override void OnCreate() { base.OnCreate(); _appConfig = ClientBootstrapper.Container.Resolve <AppConfig>(); _config = ClientBootstrapper.Container.Resolve <MainConfig>(); _fxData = ClientBootstrapper.Container.Resolve <FXData>(); _uiController = ClientBootstrapper.Container.Resolve <UIController>(); _group = GetEntityQuery( ComponentType.ReadWrite <CharacterPresenter>(), ComponentType.ReadOnly <GameObject>(), ComponentType.ReadOnly <CharactersBindData>(), ComponentType.ReadOnly <Translation>(), ComponentType.ReadOnly <Attack>(), ComponentType.ReadOnly <Damage>(), ComponentType.ReadOnly <PlayerData>(), ComponentType.Exclude <DEAD>() ); _otherPlayers = GetEntityQuery( ComponentType.ReadWrite <PlayerData>(), ComponentType.ReadOnly <Damage>(), ComponentType.ReadOnly <Translation>(), ComponentType.Exclude <PlayerInput>(), ComponentType.Exclude <DEAD>() ); }
FXUnit spawnInternal(FXData data) { FXUnit unit = (FXUnit)Instantiate(data.prefab); unit.Init(data, namedTransformsMap[data.spawnPoint].t); if (data.persist) { instantiatedPrefabs[data.key] = unit; } return(unit); }
public void Init(FXData data, Transform t) { if (data.spawnMode == SpawnMode.Global) { Init(t); } else { InitLocal(t); } }
private void HandleShaderFX(FXData fx) { //Debug.LogError("HandleShaderFX"); orgShader = GetMatShader(); AssetCacheMgr.GetResource(fx.shader, (shader) => { //Debug.LogError("SetMatShader: " + shader.name); SetMatShader(shader as Shader); currentShaderFx = fx.id; updatingShader = true; StartCoroutine(UpdateShader(fx)); }); //SetMatShader(Shader.Find("Mogo/FakeLight")); //Debug.Log("HandleShaderFX: " + fx.actionID); }
/// <summary> /// 处理淡入淡出 /// </summary> /// <param name="fx"></param> private void HandleFade(FXData fx) { if (fx.fadeStart != fx.fadeEnd) { try { if (m_mat != null) { var color = GetMatColor("_Color"); if (color.a == fx.fadeEnd) { if (m_randerer != null && fx.fadeEnd == 0) { SetRanderEnable(false); } return; } } } catch (System.Exception ex) { Debug.LogException(ex); } var startTime = Time.realtimeSinceStartup; Debug.Log("startTime: " + startTime); var repeatTimer = FrameTimerHeap.AddTimer((uint)fx.fadeDelay, 100, () => { if (m_mat != null) { var deltaTime = Time.realtimeSinceStartup - startTime; //Debug.Log("deltaTime: " + deltaTime); var target = fx.fadeStart + ((fx.fadeEnd - fx.fadeStart) * deltaTime * 1000 / fx.fadeDulation); Debug.Log("target: " + target); SetMatColor("_Color", new Color(1, 1, 1, target)); } }); FrameTimerHeap.AddTimer((uint)(fx.fadeDelay + fx.fadeDulation), 0, () => { FrameTimerHeap.DelTimer(repeatTimer); if (m_randerer != null && fx.fadeEnd == 0) { SetRanderEnable(false); } }); } }
/// <summary> /// 处理淡入淡出 /// </summary> /// <param name="fx"></param> private void HandleFade(FXData fx) { if (fx.fadeStart != fx.fadeEnd) { try { if (this.m_mat != null) { var color = GetMatColor("_Color"); if (color.a == fx.fadeEnd)//如果淡出的alpha为0,就隐藏renderer { if (this.m_renderer != null && fx.fadeEnd == 0) { this.SetRendererEnable(false); } return; } } } catch (Exception e) { Debug.LogException(e); } var startTime = Time.realtimeSinceStartup; var repeatTimer = FrameTimerHeap.AddTimer((uint)fx.fadeDelay, 100, () => { if (this.m_mat != null) { var deltaTime = Time.realtimeSinceStartup - startTime; //偏移的时间 var target = fx.fadeStart + ((fx.fadeStart - fx.fadeEnd) * deltaTime * 1000 / fx.fadeDuration); this.SetMatColor("_Color", new Color(1, 1, 1, target)); //设置成白色 } }); FrameTimerHeap.AddTimer((uint)fx.fadeDelay + (uint)fx.fadeDuration, 0, () => { FrameTimerHeap.DelTimer(repeatTimer); if (this.m_renderer != null && fx.fadeEnd == 0) { this.SetRendererEnable(false); } }); } }
/// <summary> /// 发射弓箭或火球等 /// </summary> /// <param name="shootSfxId">飞行物</param> /// <param name="boomSfxId">碰撞后特效,-1代表无</param> /// <param name="target">目标</param> /// <param name="speed">速度</param> /// <param name="distance">如果目标为null时,到前方一定距离后就消失</param> public void Shoot(FXData fx, Transform target, float speed = 10, float distance = 30) { PlayFX(fx.id, fx, (go, guid) => { //加上bullet脚本,设置参数 var bullet = go.AddComponent <ActorBullet>(); bullet.OnDestroy = () => { RemoveFX(fx.id, guid); }; Vector3 targetPosition = Vector3.zero; if (target == null) { targetPosition = go.transform.position + transform.forward * distance; } bullet.Setup(target, speed, targetPosition); }); }
private IEnumerator UpdateShader(FXData fx) { while (updatingShader) { var ci = currentShaderIndex; var ni = nextShaderIndex; if (curFrame < fx.shaderDuration[ci]) { var rimWidth = fx.rimWidth[ci] + ((fx.rimWidth[ni] - fx.rimWidth[ci]) * curFrame / fx.shaderDuration[ci]); var rimPower = fx.rimPower[ci] + ((fx.rimPower[ni] - fx.rimPower[ci]) * curFrame / fx.shaderDuration[ci]); var finalPower = fx.finalPower[ci] + ((fx.finalPower[ni] - fx.finalPower[ci]) * curFrame / fx.shaderDuration[ci]); var r = fx.r[ci] + ((fx.r[ni] - fx.r[ci]) * curFrame / fx.shaderDuration[ci]); var g = fx.g[ci] + ((fx.g[ni] - fx.g[ci]) * curFrame / fx.shaderDuration[ci]); var b = fx.b[ci] + ((fx.b[ni] - fx.b[ci]) * curFrame / fx.shaderDuration[ci]); var a = fx.a[ci] + ((fx.a[ni] - fx.a[ci]) * curFrame / fx.shaderDuration[ci]); SetMatColor("_RimColor", new Color(r, g, b, a)); SetMatFloat("_RimWidth", rimWidth); SetMatFloat("_RimPower", rimPower); SetMatFloat("_FinalPower", finalPower); curFrame++; } else { curFrame = 0; currentShaderIndex++; if (currentShaderIndex >= fx.rimWidth.Count) { currentShaderIndex = 0; } nextShaderIndex = currentShaderIndex + 1; if (nextShaderIndex >= fx.rimWidth.Count) { nextShaderIndex = 0; } } yield return(null); } }
public FXUnit Spawn(string key) { if (m == null) { m = Managers.Get(); } // todo: stop multiple spawns? FXData data = getFXData(key); if (data == null && this != m.units.baseFX) { data = m.units.baseFX.getFXData(key); if (data != null) { return(spawnInternal(data)); } // FXUnit unit = (FXUnit)Instantiate(data.prefab); // unit.Init(data); // if(data.persist) // { // instantiatedPrefabs[data.key] = unit; // } // return unit; } else { //we have data return(spawnInternal(data)); } Debug.Log("[FXSpawner] Attempted to spawn fx with key:" + key + " but no fx unit found!", gameObject); foreach (FXData fx in dataMap.Values) { Debug.Log("[FXSpawner] we have:" + fx.key); } return(null); }
private void AttachObjects(AttachmentPointLogic point1, AttachmentPointLogic point2, Item ungrabbedItem, Interactor interactor) { //ungrabbed item definition ItemDefinition ungrabbedItemDefinition = point1.GetComponentInParent <ItemDefinition>(); ItemDefinition point2ItemDefinition = point2.GetComponentInParent <ItemDefinition>(); // Getting item position Transform point1ItemTransform = point1.GetComponentInParent <ItemDefinition>().transform; Transform point2ItemTransform = point2.GetComponentInParent <ItemDefinition>().transform; Item point2Item = point2ItemTransform.GetComponent <Item>(); ItemData point2ItemData = point2Item.data; point1ItemTransform.MoveAlign(point1.transform, point2.transform); // -------------------------------------------------------------------- // // Renderes and BladeMeshes // // -------------------------------------------------------------------- // foreach (Renderer renderer in ungrabbedItemDefinition.renderers) { renderer.gameObject.transform.parent = point2ItemTransform; point2ItemDefinition.renderers.Add(renderer); if (point1.partType == "blade") { bladeRenderes.Add(renderer); //Debug.Log("ADDED BLADE " + "Total " + bladeRenderes.Count); } } //Debug.Log("Total blades " + bladeRenderes.Count); // -------------------------------------------------------------------- // // Damagers // // -------------------------------------------------------------------- // foreach (ItemData.Damager damager1 in point2ItemData.damagers.ToList()) { if (ungrabbedItem.data.damagers.Contains(damager1)) { point2ItemData.damagers.Remove(damager1); //Debug.Log("Removed damager"); } } //Debug.Log(point2ItemData.damagers.Count); point2ItemData.damagers.AddRange(ungrabbedItem.data.damagers); //Debug.Log(point2ItemData.damagers.Count); foreach (DamagerDefinition damagerDefinition in ungrabbedItem.GetComponentsInChildren <DamagerDefinition>()) { damagerDefinition.colliderGroup.transform.parent = point2ItemTransform; //Debug.Log("ColliderGroup Name " + damagerDefinition.colliderGroup.name); damagerDefinition.transform.parent = point2ItemTransform; //Debug.Log("damagerDefinition " + damagerDefinition.name); } point2ItemDefinition.colliderGroups.AddRange(ungrabbedItemDefinition.colliderGroups); point2Item.damagers.Clear(); foreach (ItemData.Damager damager in point2ItemData.damagers) { foreach (DamagerDefinition damagerDefinition in point2.GetComponentInParent <ItemDefinition>().GetComponentsInChildren <DamagerDefinition>()) { if (damagerDefinition.name == damager.transformName) { Damager[] components2 = damagerDefinition.GetComponents <Damager>(); for (int j = 0; j < components2.Length; j++) { UnityEngine.Object.Destroy(components2[j]); } if (damagerDefinition.colliderGroup == null) { Debug.LogError("colliderGroup on DamagerDefinition is null"); } else { Damager damager2 = damagerDefinition.gameObject.AddComponent <Damager>(); damager2.Load(Catalog.current.GetData <DamagerData>(damager.damagerID, true)); point2Item.damagers.Add(damager2); } } } } // -------------------------------------------------------------------- // // CustomReference // // -------------------------------------------------------------------- // //Debug.Log("Custom ref start"); foreach (CustomReference customReference in ungrabbedItemDefinition.customReferences) { if (customReference.transform != null) { customReference.transform.parent = point2ItemTransform; point2ItemDefinition.customReferences.Add(customReference); } else { Debug.LogError("Customreference transform" + customReference.name + " on item " + ungrabbedItemDefinition.itemId + " is not set?"); } } // -------------------------------------------------------------------- // // Reset Mass and stuff // // -------------------------------------------------------------------- // point2Item.rb.ResetCenterOfMass(); Vector3 CoM = point2Item.rb.centerOfMass; this.itemCoM = CoM; point2Item.rb.mass = (point2Item.rb.mass + ungrabbedItem.rb.mass); this.itemMass = point2Item.rb.mass; point2Item.rb.angularDrag = 0f; this.itemAngularDrag = point2Item.rb.angularDrag; point2Item.rb.drag = 0f; this.itemDrag = point2Item.rb.drag; point2Item.OnGrabEvent += this.fixItemInfo; // -------------------------------------------------------------------- // // Whooshs // // -------------------------------------------------------------------- // foreach (ItemData.Whoosh whoosh in point2ItemData.whooshs.ToList()) { if (ungrabbedItem.data.whooshs.Contains(whoosh)) { point2ItemData.whooshs.Remove(whoosh); } } foreach (WhooshPoint whooshPoint in ungrabbedItemDefinition.whooshPoints) { whooshPoint.transform.parent = point2ItemTransform; } point2ItemDefinition.whooshPoints.AddRange(ungrabbedItemDefinition.whooshPoints); point2ItemData.whooshs.AddRange(ungrabbedItem.data.whooshs); foreach (ItemData.Whoosh whoosh in point2ItemData.whooshs.ToList()) { foreach (WhooshPoint whooshPoint in point2ItemDefinition.whooshPoints) { if (whooshPoint.name == whoosh.transformName) { FXData data = Catalog.current.GetData <FXData>(whoosh.fxId, true); if (data != null) { Whoosh whoosh2 = whooshPoint.gameObject.GetComponent <Whoosh>(); if (!whoosh2) { whoosh2 = whooshPoint.gameObject.AddComponent <Whoosh>(); } whoosh2.Load(data, whoosh.trigger, whoosh.minVelocity, whoosh.maxVelocity); } } } } // -------------------------------------------------------------------- // // Modules WIP // // -------------------------------------------------------------------- // foreach (ItemModule itemModule in ungrabbedItem.data.modules) { //Debug.Log(itemModule.type.Name); if (itemModule.type.Name != "ItemModuleAI" && itemModule.type.Name != "ItemModulePart") { addedModules.Add(itemModule); } } //Debug.Log("Total modules added " + addedModules.Count); // Get all modules on the new item and find all added modules List <ItemModule> totalAddedModules = new List <ItemModule>(); foreach (CustomReference customReference1 in point2ItemDefinition.customReferences) { if (customReference1.transform.GetComponent <AttachmentPointLogic>()) { AttachmentPointLogic apl = customReference1.transform.GetComponent <AttachmentPointLogic>(); if (apl.addedModules.Count > 0) { totalAddedModules.AddRange(apl.addedModules); } } } //Debug.Log("Total added modules to item " + totalAddedModules.Count); foreach (ItemModule itemModule1 in totalAddedModules) { point2ItemData.modules.Add(itemModule1); itemModule1.OnItemLoaded(point2Item); point2ItemData.modules.Remove(itemModule1); } // -------------------------------------------------------------------- // // Despawn // // -------------------------------------------------------------------- // ungrabbedItem.ResetObjectCollision(); ungrabbedItem.SetColliderAndMeshLayer(VRManager.GetLayer(LayerName.MovingObject)); ungrabbedItem.Despawn(); point2Item.RefreshCollision(); item = point2Item; }
///// <param name="bone_path">绑特效的骨骼,默认为空(即使用xml里面指定的骨骼)</param> //private void HandleNormalFX(int id, string bone_path = "") //{ // if (!FXData.dataMap.ContainsKey(id)) // { // Debug.LogWarning(string.Format("Can not find fx {0}", id)); // return; // } // HandleFX(id, FXData.dataMap[id], bone_path); //} /// <param name="bone_path">绑特效的骨骼,默认为空(即使用xml里面指定的骨骼)</param> private void PlayFX(int id, FXData fx, Action <GameObject, int> action = null, string bone_path = "") { //HandleWeaponTrial(fx); HandleAnim(fx); HandleFade(fx); if (!string.IsNullOrEmpty(fx.shader)) { HandleShaderFX(fx); } if (!string.IsNullOrEmpty(fx.dissonShader)) { HandleDissonFx(fx); } if (string.IsNullOrEmpty(fx.resourcePath)) { return; } //销毁自身冲突 if (fx.isConflict == FXConflict.Conflict && m_fxDic.ContainsKey(id)) { RemoveFXs(id); } //去除组内冲突 if (fx.group != 0) { RemoveFXByGroup(fx.group); } //AssetCacheMgr.GetResourceAutoRelease(fx.resourcePath, (obj) => AssetCacheMgr.GetNoCacheInstance(fx.resourcePath, (prefab, guid, obj) => { m_loadedFX.Add(fx.resourcePath); //Debug.LogError("m_loadedFX.Add: " + fx.resourcePath + " " + m_loadedFX.Count); //var go = GameObject.Instantiate(obj) as GameObject; //var guid = go.GetInstanceID(); var go = obj as GameObject; if (!go || !this) { AssetCacheMgr.SynReleaseInstance(go); return; } if (!m_fxDic.ContainsKey(id)) { m_fxDic[id] = new Dictionary <int, GameObject>(); } m_fxDic[id].Add(guid, go); //处理音效 var audio = go.GetComponent <AudioSource>(); if (audio != null) { if (SettingsUIViewManager.Instance != null) { audio.volume = SoundManager.SoundVolume; } FrameTimerHeap.AddTimer((uint)fx.soundDelay, 0, () => { if (audio != null) { audio.enabled = true; } }); } switch (fx.locationType) { case FXLocationType.SelfSlot: // 判断输入路径是否指定,若未指定则绑在预设的骨上 if (bone_path == "") { if (!m_locationDic.ContainsKey(fx.slot)) { m_locationDic.Add(fx.slot, GetBone(transform, fx.slot)); } go.transform.parent = m_locationDic[fx.slot]; } // 若已经指定则绑在指定的骨上 else { if (!m_locationDic.ContainsKey(bone_path)) { m_locationDic.Add(bone_path, GetBone(transform, bone_path)); } go.transform.parent = m_locationDic[bone_path]; // 记下index,以便删除 slotCueHandler.SetFxList(id, bone_path, guid); } go.transform.localPosition = go.transform.position; go.transform.localRotation = go.transform.rotation; break; case FXLocationType.World: go.transform.position = fx.location; break; case FXLocationType.SelfLocal: go.transform.parent = transform; //Debug.Log(go.transform.position.x + " " + go.transform.position.y + " " + go.transform.position.z); go.transform.localPosition = go.transform.position; go.transform.localRotation = go.transform.rotation; go.transform.forward = transform.forward; break; case FXLocationType.SelfWorld: go.transform.localPosition = transform.localPosition; go.transform.localRotation = go.transform.rotation; go.transform.position = transform.position; go.transform.forward = transform.forward; break; case FXLocationType.SlotWorld: if (!m_locationDic.ContainsKey(fx.slot)) { m_locationDic.Add(fx.slot, GetBone(transform, fx.slot)); } var solt = m_locationDic[fx.slot]; go.transform.localPosition = solt.transform.localPosition; go.transform.position = solt.transform.position; go.transform.localRotation = solt.transform.rotation; break; default: break; } if (fx.isStatic == FXStatic.NotStatic) { Action actRemove = () => { if (this) { RemoveFX(id, guid, fx.group); } }; if (fx.duration > 0) { FrameTimerHeap.AddTimer((uint)(fx.duration * 1000), 0, actRemove); } else { FrameTimerHeap.AddTimer(3000, 0, actRemove); } } else { //如果技能为静态技能,分组标记非0,而且特效绑定到自身 if (fx.group != 0 && (fx.locationType == FXLocationType.SelfSlot || fx.locationType == FXLocationType.SelfLocal)) { if (!m_groupFXList.ContainsKey(fx.group)) { m_groupFXList.Add(fx.group, new List <int>()); } m_groupFXList[fx.group].Add(id); } } if (action != null) { action(go, guid); } }); // m_fxDic.Add(id, new Dictionary<int, GameObject>()); //return go; }
/// <summary> /// 发射弓箭或火球等 /// </summary> /// <param name="shootSfxId">飞行物</param> /// <param name="boomSfxId">碰撞后特效,-1代表无</param> /// <param name="target">目标</param> /// <param name="speed">速度</param> /// <param name="distance">如果目标为null时,到前方一定距离后就消失</param> public void Shoot(FXData fx, Transform target, float speed = 10, float distance = 30) { PlayFX(fx.id, fx, (go, guid) => { //加上bullet脚本,设置参数 var bullet = go.AddComponent<ActorBullet>(); bullet.OnDestroy = () => { RemoveFX(fx.id, guid); }; Vector3 targetPosition = Vector3.zero; if (target == null) targetPosition = go.transform.position + transform.forward * distance; bullet.Setup(target, speed, targetPosition); }); }
private IEnumerator UpdateShader(FXData fx) { while (updatingShader) { var ci = currentShaderIndex; var ni = nextShaderIndex; if (curFrame < fx.shaderDuration[ci]) { var rimWidth = fx.rimWidth[ci] + ((fx.rimWidth[ni] - fx.rimWidth[ci]) * curFrame / fx.shaderDuration[ci]); var rimPower = fx.rimPower[ci] + ((fx.rimPower[ni] - fx.rimPower[ci]) * curFrame / fx.shaderDuration[ci]); var finalPower = fx.finalPower[ci] + ((fx.finalPower[ni] - fx.finalPower[ci]) * curFrame / fx.shaderDuration[ci]); var r = fx.r[ci] + ((fx.r[ni] - fx.r[ci]) * curFrame / fx.shaderDuration[ci]); var g = fx.g[ci] + ((fx.g[ni] - fx.g[ci]) * curFrame / fx.shaderDuration[ci]); var b = fx.b[ci] + ((fx.b[ni] - fx.b[ci]) * curFrame / fx.shaderDuration[ci]); var a = fx.a[ci] + ((fx.a[ni] - fx.a[ci]) * curFrame / fx.shaderDuration[ci]); SetMatColor("_RimColor", new Color(r, g, b, a)); SetMatFloat("_RimWidth", rimWidth); SetMatFloat("_RimPower", rimPower); SetMatFloat("_FinalPower", finalPower); curFrame++; } else { curFrame = 0; currentShaderIndex++; if (currentShaderIndex >= fx.rimWidth.Count) currentShaderIndex = 0; nextShaderIndex = currentShaderIndex + 1; if (nextShaderIndex >= fx.rimWidth.Count) nextShaderIndex = 0; } yield return null; } }
private void HandleShaderFX(FXData fx) { //LoggerHelper.Error("HandleShaderFX"); orgShader = GetMatShader(); AssetCacheMgr.GetResource(fx.shader, (shader) => { //LoggerHelper.Error("SetMatShader: " + shader.name); SetMatShader(shader as Shader); currentShaderFx = fx.id; updatingShader = true; StartCoroutine(UpdateShader(fx)); }); //SetMatShader(Shader.Find("Mogo/FakeLight")); //Debug.Log("HandleShaderFX: " + fx.actionID); }
/// <summary> /// 处理淡入淡出 /// </summary> /// <param name="fx"></param> private void HandleFade(FXData fx) { if (fx.fadeStart != fx.fadeEnd) { try { if (m_mat != null) { var color = GetMatColor("_Color"); if (color.a == fx.fadeEnd) { if (m_randerer != null && fx.fadeEnd == 0) SetRanderEnable(false); return; } } } catch (System.Exception ex) { LoggerHelper.Except(ex); } var startTime = Time.realtimeSinceStartup; Debug.Log("startTime: " + startTime); var repeatTimer = FrameTimerHeap.AddTimer((uint)fx.fadeDelay, 100, () => { if (m_mat != null) { var deltaTime = Time.realtimeSinceStartup - startTime; //Debug.Log("deltaTime: " + deltaTime); var target = fx.fadeStart + ((fx.fadeEnd - fx.fadeStart) * deltaTime * 1000 / fx.fadeDulation); Debug.Log("target: " + target); SetMatColor("_Color", new Color(1, 1, 1, target)); } }); FrameTimerHeap.AddTimer((uint)(fx.fadeDelay + fx.fadeDulation), 0, () => { FrameTimerHeap.DelTimer(repeatTimer); if (m_randerer != null && fx.fadeEnd == 0) SetRanderEnable(false); }); } }
///// <summary> ///// 处理刀光 ///// </summary> ///// <param name="fx"></param> //private void HandleWeaponTrial(FXData fx) //{ // if (!string.IsNullOrEmpty(fx.weaponTailMaterial)) // { // if (m_weaponTrailsDic.ContainsKey(fx.weaponTailSlot)) // { // var item = m_weaponTrailsDic[fx.weaponTailSlot]; // if (m_weaponTrailMaterial.ContainsKey(fx.weaponTailMaterial)) // { // item.Material = m_weaponTrailMaterial[fx.weaponTailMaterial]; // item.subdivisions = fx.weaponTailSubdivisions; // item._lifeTime = fx.weaponTailLeftTime; // FrameFrameTimerHeap.AddTimer((uint)fx.weaponTailEmitTime, 0, () => { item.Emit = true; }); // FrameFrameTimerHeap.AddTimer((uint)(fx.weaponTailEmitTime + fx.weaponTailDurationTime), 0, () => { item.Emit = false; }); // } // else // { // //to do: 资源释放 // AssetCacheMgr.GetResource(fx.weaponTailMaterial, (go) => // { // m_weaponTrailMaterial[fx.weaponTailMaterial] = go as Material; // item.Material = m_weaponTrailMaterial[fx.weaponTailMaterial]; // item.subdivisions = fx.weaponTailSubdivisions; // item._lifeTime = fx.weaponTailLeftTime; // FrameFrameTimerHeap.AddTimer((uint)fx.weaponTailEmitTime, 0, () => { item.Emit = true; }); // FrameFrameTimerHeap.AddTimer((uint)(fx.weaponTailEmitTime + fx.weaponTailDurationTime), 0, () => { item.Emit = false; }); // }); // } // } // } //} /// <summary> /// 处理动画播放 /// </summary> /// <param name="fx"></param> private void HandleAnim(FXData fx) { if (!String.IsNullOrEmpty(fx.anim)) { if (!gameObject.animation) gameObject.AddComponent<Animation>(); if (m_animationClip.ContainsKey(fx.anim)) { gameObject.animation.AddClip(m_animationClip[fx.anim], fx.anim); gameObject.animation.Play(fx.anim); } else { //to do: 资源释放 AssetCacheMgr.GetResourceAutoRelease(fx.anim, (go) => { m_animationClip[fx.anim] = go as AnimationClip; gameObject.animation.AddClip(m_animationClip[fx.anim], fx.anim); gameObject.animation.Play(fx.anim); }); } } }
///// <param name="bone_path">绑特效的骨骼,默认为空(即使用xml里面指定的骨骼)</param> //private void HandleNormalFX(int id, string bone_path = "") //{ // if (!FXData.dataMap.ContainsKey(id)) // { // LoggerHelper.Warning(string.Format("Can not find fx {0}", id)); // return; // } // HandleFX(id, FXData.dataMap[id], bone_path); //} /// <param name="bone_path">绑特效的骨骼,默认为空(即使用xml里面指定的骨骼)</param> private void PlayFX(int id, FXData fx, Action<GameObject, int> action = null, string bone_path = "") { //HandleWeaponTrial(fx); HandleAnim(fx); HandleFade(fx); if (!string.IsNullOrEmpty(fx.shader)) HandleShaderFX(fx); if (!string.IsNullOrEmpty(fx.dissonShader)) HandleDissonFx(fx); if (string.IsNullOrEmpty(fx.resourcePath)) return; //销毁自身冲突 if (fx.isConflict == FXConflict.Conflict && m_fxDic.ContainsKey(id)) RemoveFXs(id); //去除组内冲突 if (fx.group != 0) { RemoveFXByGroup(fx.group); } //AssetCacheMgr.GetResourceAutoRelease(fx.resourcePath, (obj) => AssetCacheMgr.GetNoCacheInstance(fx.resourcePath, (prefab, guid, obj) => { m_loadedFX.Add(fx.resourcePath); //Debug.LogError("m_loadedFX.Add: " + fx.resourcePath + " " + m_loadedFX.Count); //var go = GameObject.Instantiate(obj) as GameObject; //var guid = go.GetInstanceID(); var go = obj as GameObject; if (!go || !this) { AssetCacheMgr.SynReleaseInstance(go); return; } if (!m_fxDic.ContainsKey(id)) { m_fxDic[id] = new Dictionary<int, GameObject>(); } m_fxDic[id].Add(guid, go); //处理音效 var audio = go.GetComponent<AudioSource>(); if (audio != null) { if (SettingsUIViewManager.Instance != null) audio.volume = SoundManager.SoundVolume; FrameTimerHeap.AddTimer((uint)fx.soundDelay, 0, () => { if (audio != null) audio.enabled = true; }); } switch (fx.locationType) { case FXLocationType.SelfSlot: // 判断输入路径是否指定,若未指定则绑在预设的骨上 if (bone_path == "") { if (!m_locationDic.ContainsKey(fx.slot)) { m_locationDic.Add(fx.slot, GetBone(transform, fx.slot)); } go.transform.parent = m_locationDic[fx.slot]; } // 若已经指定则绑在指定的骨上 else { if (!m_locationDic.ContainsKey(bone_path)) { m_locationDic.Add(bone_path, GetBone(transform, bone_path)); } go.transform.parent = m_locationDic[bone_path]; // 记下index,以便删除 slotCueHandler.SetFxList(id, bone_path, guid); } go.transform.localPosition = go.transform.position; go.transform.localRotation = go.transform.rotation; break; case FXLocationType.World: go.transform.position = fx.location; break; case FXLocationType.SelfLocal: go.transform.parent = transform; //LoggerHelper.Debug(go.transform.position.x + " " + go.transform.position.y + " " + go.transform.position.z); go.transform.localPosition = go.transform.position; go.transform.localRotation = go.transform.rotation; go.transform.forward = transform.forward; break; case FXLocationType.SelfWorld: go.transform.localPosition = transform.localPosition; go.transform.localRotation = go.transform.rotation; go.transform.position = transform.position; go.transform.forward = transform.forward; break; case FXLocationType.SlotWorld: if (!m_locationDic.ContainsKey(fx.slot)) { m_locationDic.Add(fx.slot, GetBone(transform, fx.slot)); } var solt = m_locationDic[fx.slot]; go.transform.localPosition = solt.transform.localPosition; go.transform.position = solt.transform.position; go.transform.localRotation = solt.transform.rotation; break; default: break; } if (fx.isStatic == FXStatic.NotStatic) { Action actRemove = () => { if (this) RemoveFX(id, guid, fx.group); }; if (fx.duration > 0) FrameTimerHeap.AddTimer((uint)(fx.duration * 1000), 0, actRemove); else FrameTimerHeap.AddTimer(3000, 0, actRemove); } else { //如果技能为静态技能,分组标记非0,而且特效绑定到自身 if (fx.group != 0 && (fx.locationType == FXLocationType.SelfSlot || fx.locationType == FXLocationType.SelfLocal)) { if (!m_groupFXList.ContainsKey(fx.group)) m_groupFXList.Add(fx.group, new List<int>()); m_groupFXList[fx.group].Add(id); } } if (action != null) action(go, guid); }); // m_fxDic.Add(id, new Dictionary<int, GameObject>()); //return go; }
/// <summary> /// 插入飞行特效 /// </summary> /// <param name="fx"></param> /// <param name="target"></param> /// <param name="speed"></param> /// <param name="distance"></param> public void Shoot(FXData fx, Transform target, float speed = 10, float distance = 30) { }
public void Initialize(FXData _data) { data = _data; CreatePool(); }
/// <summary> /// 插入特效 /// </summary> /// <param name="id"></param> /// <param name="fx"></param> /// <param name="action"></param> /// <param name="bone_path"></param> private void PlayFx(int id, FXData fx, Action <GameObject, int> action = null, string bone_path = "") { }