summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Effects
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-09-13 12:00:32 +0800
committerchai <chaifix@163.com>2021-09-13 12:00:32 +0800
commit26b68caaae2804c701c6655f096feb2c5e826ba5 (patch)
treea293cb335d1e221de1d95d48cbdcdc60e2ac160d /Assets/Scripts/Effects
parentc4299d8f353b270018786bfcd1a3344142724559 (diff)
*fxclear
Diffstat (limited to 'Assets/Scripts/Effects')
-rw-r--r--Assets/Scripts/Effects/FxClear.cs167
1 files changed, 49 insertions, 118 deletions
diff --git a/Assets/Scripts/Effects/FxClear.cs b/Assets/Scripts/Effects/FxClear.cs
index 6b26da6c..507da824 100644
--- a/Assets/Scripts/Effects/FxClear.cs
+++ b/Assets/Scripts/Effects/FxClear.cs
@@ -26,7 +26,6 @@ public static class TransformEx
public struct PlayEffectInfo
{
- public int dbId { get; set; }
public string path { get; set; }
public Transform rootTr { get; set; }
public bool bAttached { get; set; }
@@ -34,20 +33,6 @@ public struct PlayEffectInfo
public Vector3 rot { get; set; }
public Vector3 scale { get; set; }
public EffectPlayTypes playEffectType { get; set; }
- public bool bUIEffect { get; set; }
-
- public PlayEffectInfo(string path, EffectPlayTypes type, Transform rootTr, Vector3 posOffset, Vector3 rot, Vector3 scale, int dbId = 0, bool bAttached = false, bool bUIEffect = false)
- {
- this.path = path;
- this.playEffectType = type;
- this.rootTr = rootTr;
- this.rot = rot;
- this.scale = scale;
- this.dbId = dbId;
- this.bAttached = bAttached;
- this.posOffset = posOffset;
- this.bUIEffect = bUIEffect;
- }
}
public class FxClear : MonoBehaviour
@@ -57,25 +42,27 @@ public class FxClear : MonoBehaviour
private EffectPlayTypes m_EffectPlayType = EffectPlayTypes.None;
- public float time { get { return m_curTime; } }
-
- private Transform m_rootTr = null;
- private float m_curTime = 0.0f;
- private bool m_bAttached = false;
+ private Transform m_Root = null; //根节点,可以是角色或者某个骨骼,如果是空,代表是世界空间
+ private bool m_Attached = false; // 跟随根节点运动
- private Vector3 m_offset = Vector3.zero;
- private Vector3 m_rot = Vector3.zero;
- private Vector3 m_scale = Vector3.zero;
+ private Vector3 m_Offset = Vector3.zero;
+ private Vector3 m_Rotation = Vector3.zero;
+ private Vector3 m_Scale = Vector3.one;
+
+ private Quaternion m_RootRot = Quaternion.identity;
+ private Vector3 m_RootPos = Vector3.zero;
#if UNITY_EDITOR
- private double m_prevTime = 0.0f;
- private float m_removeWaitTime = 0.0f;
- private bool m_destroyRequested = false;
+ private double m_PrevTime = 0.0f;
+ private float m_RemoveWaitTime = 0.0f;
+ private bool m_DestroyRequested = false;
#endif
+
+ private float m_CurTime = 0.0f;
+ public float time { get { return m_CurTime; } }
private void Awake()
{
- // 0 이면 무한 루프로 삭제하지 않게 사용하기로 그래픽과 합의함 - 해당 룰 그대로 가져옴(FxClear에서)
if (ClearTime <= float.Epsilon)
m_EffectPlayType = EffectPlayTypes.Loop;
}
@@ -92,13 +79,18 @@ public class FxClear : MonoBehaviour
public void Initialize(PlayEffectInfo info)
{
m_EffectPlayType = info.playEffectType;
- //m_bExistTr = info.rootTr != null;
- m_rootTr = info.rootTr;
- m_curTime = 0.0f;
- m_offset = info.posOffset;
- m_rot = info.rot;
- m_scale = info.scale;
- m_bAttached = info.bAttached;
+ m_Root = info.rootTr;
+ m_CurTime = 0.0f;
+ m_Offset = info.posOffset;
+ m_Rotation = info.rot;
+ m_Scale = info.scale;
+ m_Attached = info.bAttached;
+
+ if(info.rootTr != null)
+ {
+ m_RootPos = info.rootTr.transform.position;
+ m_RootRot = info.rootTr.transform.rotation;
+ }
SyncTr();
gameObject.SetActive(true);
@@ -106,103 +98,42 @@ public class FxClear : MonoBehaviour
public void Release()
{
- m_rootTr = null;
- m_curTime = 0.0f;
- m_bAttached = false;
- m_offset = Vector3.zero;
- m_rot = Vector3.zero;
- m_scale = Vector3.zero;
+ m_Root = null;
+ m_CurTime = 0.0f;
+ m_Attached = false;
+ m_Offset = Vector3.zero;
+ m_Rotation = Vector3.zero;
+ m_Scale = Vector3.zero;
}
+ // 同步特效的缩放、旋转和位置
private void SyncTr()
{
-#if UNITY_EDITOR
if (transform == null || transform.gameObject == null)
return;
- //if (m_runInEditor)
- //{
- // if (m_rootTr == null)
- // {
- // transform.position = m_offset;
- // }
- // else
- // {
-
- // transform.localRotation = m_rootTr.rotation;
-
- // if (m_bAttached)
- // {
- // transform.position = m_rootTr.position + (m_rootTr.rotation * m_offset);
- // }
- // else
- // {
- // transform.position = m_rootTr.position - (m_rootTr.rotation * m_offset);
- // }
- // }
- //}
- //else
- //{
- if (m_rootTr == null)
- {
- transform.position = m_offset;
- }
- else
- {
- if (m_bAttached)
- {
- transform.localRotation = m_rootTr.rotation;// * Quaternion.LookRotation(Vector3.back);
- }
- else
- {
- transform.localRotation = m_rootTr.rotation * Quaternion.LookRotation(Vector3.back);
- }
-
- transform.position = m_rootTr.position + (m_rootTr.rotation * m_offset);
- }
- //}
-#else
- if (m_rootTr == null)
+
+ if (m_Scale != Vector3.zero)
{
- transform.position = m_offset;
+ transform.localScale = m_Scale;
+ }
+
+ if (m_Root == null) // 世界空间
+ {
+ transform.position = m_Offset;
+ transform.rotation = Quaternion.Euler(m_Rotation);
}
else
{
- if (m_bAttached)
+ if (m_Attached)
{
- transform.localRotation = m_rootTr.rotation;// * Quaternion.LookRotation(Vector3.back);
+ transform.rotation = m_Root.rotation * Quaternion.Euler(m_Rotation);
+ transform.position = m_Root.TransformPoint(m_Offset);
}
else
{
- transform.localRotation = m_rootTr.rotation * Quaternion.LookRotation(Vector3.back);
+ transform.rotation = m_RootRot * Quaternion.Euler(m_Rotation);
+ transform.position = m_RootPos + (m_Root.rotation * m_Offset);
}
-
- transform.position = m_rootTr.position + (m_rootTr.rotation * m_offset);
- }
-#endif
-
-#if UNITY_EDITOR
-
- if (m_bAttached && m_rootTr != null)
- {
- transform.SetParent(m_rootTr);
- }
-
-#else
-
- if (m_bAttached && m_rootTr != null)
- {
- transform.SetParent(m_rootTr);
- }
-
-#endif
- if (m_rot != Vector3.zero)
- {
- transform.rotation = Quaternion.Euler(m_rot.x, m_rot.y, m_rot.z);
- }
-
- if (m_scale != Vector3.zero)
- {
- transform.localScale = m_scale;
}
}
@@ -213,9 +144,9 @@ public class FxClear : MonoBehaviour
public void UpdateFunc(float dt)
{
- m_curTime += dt;
+ m_CurTime += dt;
SyncTr();
- if (m_EffectPlayType != EffectPlayTypes.Loop && m_curTime >= ClearTime)
+ if (m_EffectPlayType != EffectPlayTypes.Loop && m_CurTime >= ClearTime)
{
Restore();
return;