public override void Setup() { base.Setup(); _originalMaterials = IFX_MaterialUtil.GetOriginalMaterials(gameObject); IFX_MaterialUtil.ReplaceMaterial(gameObject, Material); }
private void GetMaterialsAndFillCollection(GameObject targetGo) { var rendToMaterials = IFX_MaterialUtil.GetOriginalMaterials(targetGo); foreach (var rToMat in rendToMaterials) { _rendToMaterialsMap[rToMat.Key] = rToMat.Value; } IFX_MaterialUtil.AddMaterial(targetGo, Material); }
public static void MakeClone(GameObject target, float CloneLifeTime, Material CloneMaterial, IFX_AnimationModule CloneOpacityAnimation, Component[] componentsWithRequirements) { var targetPosition = target.transform.position; var clone = Object.Instantiate(target, targetPosition, target.transform.rotation); var idxInOrder = 0; bool needToUseOrder = componentsWithRequirements != null && componentsWithRequirements.Length > 0; foreach (var comp in clone.GetComponentsInChildren <Component>()) { if (!needToUseOrder || comp.GetType() != componentsWithRequirements[idxInOrder].GetType()) { continue; } Object.Destroy(comp); idxInOrder++; if (idxInOrder >= componentsWithRequirements.Length) { needToUseOrder = false; } } foreach (var comp in clone.GetComponentsInChildren <Component>()) { if (!(comp is Renderer) && !(comp is Transform) && !(comp is MeshFilter)) { Object.Destroy(comp); } } var cloneDestroyer = clone.AddComponent <IFX_SelfDestroyer>(); cloneDestroyer.LifeTime = CloneLifeTime; cloneDestroyer.Run(); IFX_MaterialUtil.RemoveAllMaterials(clone); IFX_MaterialUtil.AddMaterial(clone, CloneMaterial); var opacityAnimator = clone.AddComponent <IFX_ShaderAnimator>(); opacityAnimator.DynamicShaderParameters = new[] { new IFX_DynamicShaderParameter { AnimationModule = CloneOpacityAnimation, ParameterName = "_TintColor", Type = IFX_DynamicShaderParameter.ParameterType.ColorAlpha } }; opacityAnimator.Setup(); opacityAnimator.RunWithDelay(); }
public override void Run() { base.Run(); //Revert IFX_InvokeUtil.RunLater(this, delegate { IFX_MaterialUtil.ReplaceMaterial(_originalMaterials); _originalMaterials.Clear(); }, LifeTime); }
public override void Stop() { base.Stop(); var timeDiff = Time.time - _addedTime; if (timeDiff < LifeTime) { //call again IFX_InvokeUtil.RunLater(this, Stop, LifeTime - timeDiff); return; } IFX_MaterialUtil.ReplaceMaterial(_rendToMaterialsMap); _rendToMaterialsMap.Clear(); _isMaterialAdded = false; }
private void MakeClone() { var targetPosition = _target.transform.position; var clone = Instantiate(_target, targetPosition, _target.transform.rotation); var idxInOrder = 0; bool needToUseOrder = ComponentsWithRequirements != null && ComponentsWithRequirements.Length > 0; foreach (var comp in clone.GetComponentsInChildren <Component>()) { if (!needToUseOrder || comp.GetType() != ComponentsWithRequirements[idxInOrder].GetType()) { continue; } Destroy(comp); idxInOrder++; if (idxInOrder >= ComponentsWithRequirements.Length) { needToUseOrder = false; } } foreach (var comp in clone.GetComponentsInChildren <Component>()) { if (!(comp is Renderer) && !(comp is Transform) && !(comp is MeshFilter)) { Destroy(comp); } } var cloneDestroyer = clone.AddComponent <IFX_SelfDestroyer>(); cloneDestroyer.LifeTime = CloneLifeTime; cloneDestroyer.Run(); IFX_MaterialUtil.RemoveAllMaterials(clone); IFX_MaterialUtil.AddMaterial(clone, CloneMaterial); var opacityAnimator = clone.AddComponent <IFX_ShaderAnimator>(); opacityAnimator.DynamicShaderParameters = new[] { new IFX_DynamicShaderParameter { AnimationModule = CloneOpacityAnimation, ParameterName = "_TintColor", Type = IFX_DynamicShaderParameter.ParameterType.ColorAlpha } }; opacityAnimator.Setup(); opacityAnimator.RunWithDelay(); var lerpMotion = clone.AddComponent <IFX_LerpMotion>(); lerpMotion.LaunchPosition = targetPosition; if (!IsRandomOffsetEnabled) { lerpMotion.TargetPosition = targetPosition + transform.forward * CloneOffset; } else { var randomSphere = Random.insideUnitSphere * RandomSphereSize; lerpMotion.TargetPosition = targetPosition + randomSphere; } lerpMotion.ChangeRotation = false; lerpMotion.Speed = CloneSpeed; lerpMotion.Run(); }