diff --git a/Assets/Cryville/Crtr/ChartHandler.cs b/Assets/Cryville/Crtr/ChartHandler.cs index 9f515bb..189b5ad 100644 --- a/Assets/Cryville/Crtr/ChartHandler.cs +++ b/Assets/Cryville/Crtr/ChartHandler.cs @@ -40,8 +40,8 @@ namespace Cryville.Crtr { } } - public override void EndUpdate(ContainerState s) { - base.EndUpdate(s); + public override void EndLogicalUpdate(ContainerState s) { + base.EndLogicalUpdate(s); // TODO End of chart } diff --git a/Assets/Cryville/Crtr/ChartPlayer.cs b/Assets/Cryville/Crtr/ChartPlayer.cs index 2189842..34775a2 100644 --- a/Assets/Cryville/Crtr/ChartPlayer.cs +++ b/Assets/Cryville/Crtr/ChartPlayer.cs @@ -148,13 +148,13 @@ namespace Cryville.Crtr { actualRenderStep = step; nbus.ForwardStepByTime(clippingDist, step); - nbus.BroadcastEndUpdate(); + nbus.EndPreGraphicalUpdate(); nbus.Anchor(); tbus.StripTempEvents(); tbus.ForwardStepByTime(clippingDist, step); tbus.ForwardStepByTime(renderDist, step); - tbus.BroadcastEndUpdate(); + tbus.EndGraphicalUpdate(); UnityEngine.Profiling.Profiler.EndSample(); } catch (Exception ex) { diff --git a/Assets/Cryville/Crtr/Event/ContainerHandler.cs b/Assets/Cryville/Crtr/Event/ContainerHandler.cs index 36b9d56..6ea7091 100644 --- a/Assets/Cryville/Crtr/Event/ContainerHandler.cs +++ b/Assets/Cryville/Crtr/Event/ContainerHandler.cs @@ -4,6 +4,7 @@ using Cryville.Crtr.Components; using System; using System.Collections.Generic; using System.Globalization; +using System.Runtime.CompilerServices; using UnityEngine; namespace Cryville.Crtr.Event { @@ -46,8 +47,20 @@ namespace Cryville.Crtr.Event { public Vector3 Position { get; protected set; } public Quaternion Rotation { get; protected set; } public bool Alive { get; private set; } - public bool Awoken { get; private set; } - public bool Disposed { get; private set; } + bool PreGraphicalActive; + public void SetPreGraphicalActive(bool value, ContainerState s) { + if (PreGraphicalActive == value) return; + PreGraphicalActive = value; + if (PreGraphicalActive) StartPreGraphicalUpdate(s); + else EndPreGraphicalUpdate(s); + } + bool GraphicalActive; + public void SetGraphicalActive(bool value, ContainerState s) { + if (GraphicalActive == value) return; + GraphicalActive = value; + if (GraphicalActive) StartGraphicalUpdate(s); + else EndGraphicalUpdate(s); + } public EventContainer Container { get { return cs.Container; } @@ -114,34 +127,27 @@ namespace Cryville.Crtr.Event { gogroup.gameObject.SetActive(false); } #endregion - protected virtual void PreAwake(ContainerState s) { - if (gogroup) { - gogroup.gameObject.SetActive(true); - OpenAnchor(a_head); - } - Awoken = true; Alive = true; + #region Start methods + public virtual void StartPhysicalUpdate(ContainerState s) { + if (s.CloneType < 16) Alive = true; + else if (s.CloneType == 17) Init(); } - protected virtual void Awake(ContainerState s) { - if (gogroup) CloseAnchor(); - } - public virtual void StartUpdate(ContainerState s) { - if (s.CloneType >= 2 && s.CloneType < 16) { - PreAwake(s); - Awake(s); - } - else if (s.CloneType == 17) { - Init(); - } + public virtual void StartLogicalUpdate(ContainerState s) { } + public virtual void StartPreGraphicalUpdate(ContainerState s) { } + public virtual void StartGraphicalUpdate(ContainerState s) { + if (gogroup) gogroup.gameObject.SetActive(true); } + #endregion public virtual void Update(ContainerState s, StampedEvent ev) { - bool flag = !Awoken && s.CloneType >= 2 && s.CloneType < 16; - if (flag) PreAwake(s); - if (gogroup && s.CloneType <= 2) skinContainer.MatchDynamic(s); - if (flag) Awake(s); - } - public virtual void ExUpdate(ContainerState s, StampedEvent ev) { - if (ev is StampedEvent.Anchor) { + if (s.CloneType == 3) SetPreGraphicalActive(true, s); + else if (ev is StampedEvent.Anchor) { var tev = (StampedEvent.Anchor)ev; + if (tev.Target == a_head) { + SetGraphicalActive(true, s); + } + else if (tev.Target == a_tail) { + SetGraphicalActive(false, s); + } if (gogroup) { OpenAnchor(tev.Target); #if UNITY_5_6_OR_NEWER @@ -155,28 +161,31 @@ namespace Cryville.Crtr.Event { } anchorEvPool.Return(tev); } + else if (gogroup && s.CloneType <= 2) skinContainer.MatchDynamic(s); } - public virtual void MotionUpdate(byte ct, Chart.Motion ev) { } - public virtual void EndUpdate(ContainerState s) { - if (s.CloneType < 16) { - Awoken = false; - if (gogroup && s.CloneType <= 2) { - OpenAnchor(a_tail); - skinContainer.MatchDynamic(s); - CloseAnchor(); - } - } - } + #region End methods + public virtual void EndGraphicalUpdate(ContainerState s) { } + public virtual void EndPreGraphicalUpdate(ContainerState s) { } + public virtual void EndLogicalUpdate(ContainerState s) { } + public virtual void EndPhysicalUpdate(ContainerState s) { } public virtual void Dispose() { if (gogroup) GameObject.Destroy(gogroup.gameObject); Alive = false; } public virtual void DisposeAll() { } + #endregion + [MethodImpl(MethodImplOptions.AggressiveInlining)] + protected static bool CanDoGraphicalUpdate(ContainerState s) { return s.CloneType >= 2 && s.CloneType < 16; } #region Anchor public virtual void Anchor() { skinContainer.MatchDynamic(cs); - if (cs.Working) PushAnchorEvent(cs.Time, a_cur); + if (cs.Active) PushAnchorEvent(cs.Time, a_cur); + if (Alive) { + PushAnchorEvent(cs.StampedContainer.Time, a_head, -1, true); + PushAnchorEvent(cs.StampedContainer.Time + cs.StampedContainer.Duration, a_tail, 1, true); + } + } static readonly SimpleObjectPool anchorEvPool = new SimpleObjectPool(1024); public void PushAnchorEvent(double time, int name) { diff --git a/Assets/Cryville/Crtr/Event/ContainerState.cs b/Assets/Cryville/Crtr/Event/ContainerState.cs index 4f69043..48283f8 100644 --- a/Assets/Cryville/Crtr/Event/ContainerState.cs +++ b/Assets/Cryville/Crtr/Event/ContainerState.cs @@ -3,6 +3,7 @@ using Cryville.Common; using System; using System.Collections.Generic; +using System.Runtime.CompilerServices; using UnityEngine; namespace Cryville.Crtr.Event { @@ -16,9 +17,7 @@ namespace Cryville.Crtr.Event { public Dictionary Children = new Dictionary(); - readonly HashSet WorkingChildren - = new HashSet(); - readonly HashSet InvalidatedChildren + HashSet ActiveChildren = new HashSet(); public Dictionary> TypedChildren = new Dictionary>(); @@ -30,26 +29,45 @@ namespace Cryville.Crtr.Event { return Children[ev]; } - void NotifyWorkingChanged(EventContainer key) { - InvalidatedChildren.Add(key); - } - void ValidateChildren() { - foreach (var cev in InvalidatedChildren) - if (Children[cev].Working && !WorkingChildren.Contains(cev)) WorkingChildren.Add(cev); - else if (!Children[cev].Working && WorkingChildren.Contains(cev)) WorkingChildren.Remove(cev); - InvalidatedChildren.Clear(); - } - - public bool Active { get; set; } - private bool m_Working; - public bool Working { - get { return m_Working; } - set { - m_Working = value; - if (Parent != null) Parent.NotifyWorkingChanged(Container); - Bus.NotifyWorkingChanged(this); + private bool m_active; + public bool Active { + get { return m_active; } + private set { + if (m_active == value) return; + m_active = value; + if (!m_active && CloneType == 1) Dispose(); + if (Parent != null) { + if (m_active) Parent.ActiveChildren.Add(Container); + else Parent.ActiveChildren.Remove(Container); + } + Bus.NotifyActiveChanged(this); } } + private bool m_lActive; + public bool LogicalActive { + get { return m_lActive; } + set { + if (m_lActive == value) return; + m_lActive = value; + UpdateActive(); + if (m_lActive) Handler.StartLogicalUpdate(this); + else Handler.EndLogicalUpdate(this); + } + } + private bool m_pActive; + public bool PhysicalActive { + get { return m_pActive; } + set { + if (m_pActive == value) return; + m_pActive = value; + UpdateActive(); + if (m_pActive) Handler.StartPhysicalUpdate(this); + else Handler.EndPhysicalUpdate(this); + } + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + void UpdateActive() { Active = m_lActive || m_pActive; } + public byte CloneType; public ContainerState rootPrototype = null; private ContainerState prototype = null; @@ -112,6 +130,8 @@ namespace Cryville.Crtr.Event { AddChild(child.Key, cc, r); } + r.ActiveChildren = new HashSet(); + var pms = new Dictionary(Math.Max(4, PlayingMotions.Count)); foreach (var m in PlayingMotions) pms.Add(m.Key, m.Value); @@ -128,7 +148,10 @@ namespace Cryville.Crtr.Event { } public void CopyTo(byte ct, ContainerState dest) { - dest.Working = Working; + dest.m_lActive = m_lActive; + dest.m_pActive = m_pActive; + dest.m_active = m_active; + if (dest.m_active) dest.Bus.NotifyActiveChanged(dest); foreach (var mv in Values) { RealtimeMotionValue dv; @@ -145,11 +168,15 @@ namespace Cryville.Crtr.Event { cv.Value.CopyTo(dv); } - if (ct != 1) foreach (var cev in WorkingChildren) + foreach (var cev in dest.ActiveChildren) { + if (!ActiveChildren.Contains(cev)) + Children[cev].CopyTo(ct, dest.Children[cev]); + } + dest.ActiveChildren.Clear(); + foreach (var cev in ActiveChildren) { + dest.ActiveChildren.Add(cev); Children[cev].CopyTo(ct, dest.Children[cev]); - else foreach (var child in Children) - child.Value.CopyTo(ct, dest.Children[child.Key]); - dest.ValidateChildren(); + } dest.PlayingMotions.Clear(); foreach (var m in PlayingMotions) dest.PlayingMotions.Add(m.Key, m.Value); @@ -312,9 +339,9 @@ namespace Cryville.Crtr.Event { bool breakflag = false; public void Break() { - Handler.EndUpdate(this); + // Handler.EndLogicalUpdate(this); breakflag = true; - Working = false; + // LogicalActive = false; } public void Discard(StampedEvent ev) { @@ -339,33 +366,26 @@ namespace Cryville.Crtr.Event { else if (ev.Unstamped is EventContainer) { var cev = (EventContainer)ev.Unstamped; var ccs = GetChild(cev); - ccs.Working = true; - ccs.StartUpdate(); + ccs.LogicalActive = true; UpdateMotions(); if (!cev.IsLong) { - ccs.Working = false; - ccs.BroadcastEndUpdate(); - if (CloneType == 1) ccs.Dispose(); + ccs.LogicalActive = false; } } - else if (ev.Unstamped is InstantEvent) { - var tev = (InstantEvent)ev.Unstamped; - if (tev.IsRelease) { - var nev = tev.Original; - if (nev is Chart.Motion) { - Update(ev); - var mv = PlayingMotions[ev.Origin]; - if (mv.CloneTypeFlag == CloneType) RMVPool.Return(mv); - PlayingMotions.Remove(ev.Origin); - } - else if (nev is EventContainer) { - var cev = (EventContainer)ev.Origin.Unstamped; - var ccs = GetChild(cev); - UpdateMotions(); - ccs.Working = false; - ccs.BroadcastEndUpdate(); - if (CloneType == 1) ccs.Dispose(); - } + else if (ev.Unstamped is ReleaseEvent) { + var tev = (ReleaseEvent)ev.Unstamped; + var nev = tev.Original; + if (nev is Chart.Motion) { + Update(ev); + var mv = PlayingMotions[ev.Origin]; + if (mv.CloneTypeFlag == CloneType) RMVPool.Return(mv); + PlayingMotions.Remove(ev.Origin); + } + else if (nev is EventContainer) { + var cev = (EventContainer)ev.Origin.Unstamped; + var ccs = GetChild(cev); + UpdateMotions(); + ccs.LogicalActive = false; } } Update(ev.Unstamped == null || ev.Unstamped.Priority >= 0 ? ev : null); @@ -373,12 +393,10 @@ namespace Cryville.Crtr.Event { else Update(null); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] void Update(StampedEvent ev) { UpdateMotions(); - if (ev == null || ev.Unstamped != null) Handler.Update(this, ev); - else Handler.ExUpdate(this, ev); - foreach (var m in PlayingMotions) - Handler.MotionUpdate(CloneType, (Chart.Motion)m.Key.Unstamped); + Handler.Update(this, ev); } private void UpdateMotions() { @@ -423,14 +441,17 @@ namespace Cryville.Crtr.Event { } } - public void StartUpdate() { - Handler.StartUpdate(this); + public void EndPreGraphicalUpdate() { + Handler.SetPreGraphicalActive(false, this); + foreach (var ls in ActiveChildren) { + Children[ls].EndPreGraphicalUpdate(); + } } - public void BroadcastEndUpdate() { - Handler.EndUpdate(this); - foreach (var ls in Children.Values) { - if (ls.Working) ls.BroadcastEndUpdate(); + public void EndGraphicalUpdate() { + Handler.SetGraphicalActive(false, this); + foreach (var ls in ActiveChildren) { + Children[ls].EndGraphicalUpdate(); } } diff --git a/Assets/Cryville/Crtr/Event/EventBatcher.cs b/Assets/Cryville/Crtr/Event/EventBatcher.cs index 9667c38..977fcb9 100644 --- a/Assets/Cryville/Crtr/Event/EventBatcher.cs +++ b/Assets/Cryville/Crtr/Event/EventBatcher.cs @@ -84,15 +84,34 @@ namespace Cryville.Crtr.Event { Container = con }; if (ev is EventContainer) { - stateMap[(EventContainer)ev].StampedContainer = sev; + var tev = (EventContainer)ev; + stateMap[tev].StampedContainer = sev; + stampedEvents.Add(new StampedEvent.ClipBehind { + Container = con, + Origin = sev, + Time = etime + tev.Clip.Behind, + }); + if (!ev.IsLong) { + stampedEvents.Add(new StampedEvent.ClipAhead { + Container = con, + Origin = sev, + Time = etime + tev.Clip.Ahead, + }); + } } - if (ev is InstantEvent) { if (ev is ReleaseEvent) { var tev = (ReleaseEvent)ev; var oev = tev.Original; var pev = map[oev]; pev.ReleaseEvent = sev; sev.Origin = pev; + if (oev is EventContainer) { + stampedEvents.Add(new StampedEvent.ClipAhead { + Container = con, + Origin = pev, + Time = etime + ((EventContainer)oev).Clip.Ahead, + }); + } } if (con != null && coevents.Contains(ev)) { List cevs; diff --git a/Assets/Cryville/Crtr/Event/EventBus.cs b/Assets/Cryville/Crtr/Event/EventBus.cs index d1cd2c6..de28fe2 100644 --- a/Assets/Cryville/Crtr/Event/EventBus.cs +++ b/Assets/Cryville/Crtr/Event/EventBus.cs @@ -11,31 +11,27 @@ namespace Cryville.Crtr.Event { Dictionary states = new Dictionary(); - HashSet activeContainers - = new HashSet(); - HashSet workingStates + HashSet activeStates = new HashSet(); HashSet invalidatedStates = new HashSet(); + public int ActiveStateCount { get { return activeStates.Count; } } public EventBus(ContainerState root, List b) : base(b) { RootState = root; Expand(); AttachBus(); - RootState.Working = true; } public EventBus Clone(byte ct, float offsetTime = 0) { var r = (EventBus)MemberwiseClone(); r.prototype = this; r.states = new Dictionary(); - r.activeContainers = new HashSet(); - r.workingStates = new HashSet(); + r.activeStates = new HashSet(); r.invalidatedStates = new HashSet(); - r.tempEvents = new List(); + r.tempEvents = new List(); r.Time += offsetTime; r.RootState = RootState.Clone(ct); - r.RootState.StartUpdate(); r.Expand(); r.AttachBus(); foreach (var s in r.states) r.invalidatedStates.Add(s.Value); @@ -45,18 +41,9 @@ namespace Cryville.Crtr.Event { public void CopyTo(byte ct, EventBus dest) { base.CopyTo(dest); - dest.workingStates.Clear(); + dest.activeStates.Clear(); dest.invalidatedStates.Clear(); RootState.CopyTo(ct, dest.RootState); - if (ct >= 2) { - dest.activeContainers.Clear(); - foreach (var c in activeContainers) { - if (states[c].Working) { - states[c].CopyTo(ct, dest.states[c]); - dest.activeContainers.Add(c); - } - } - } dest.ValidateStates(); } @@ -67,7 +54,7 @@ namespace Cryville.Crtr.Event { RootState.DisposeAll(); } - public void NotifyWorkingChanged(ContainerState state) { + public void NotifyActiveChanged(ContainerState state) { if (!invalidatedStates.Contains(state)) invalidatedStates.Add(state); } @@ -86,22 +73,6 @@ namespace Cryville.Crtr.Event { s.Bus = this; } - void EnsureActivity(EventContainer c) { - if (activeContainers.Contains(c)) return; - var state = states[c]; - if (state.Parent != null) EnsureActivity(state.Parent.Container); - if (RootState.CloneType >= 2) prototype.states[c].CopyTo(RootState.CloneType, state); - state.Active = true; - activeContainers.Add(c); - - if (state.StampedContainer.Coevents == null) return; - foreach (var cev in state.StampedContainer.Coevents) { - if (cev.Container == null) continue; - EnsureActivity(cev.Container); - states[cev.Container].Handle(cev); - } - } - void AttachBus() { foreach (var s in states.Values) s.Bus = this; @@ -145,18 +116,26 @@ namespace Cryville.Crtr.Event { double time0 = Math.Min(time1, time2); if (time0 <= toTime && time0 != double.PositiveInfinity) { Time = time0; - foreach (var s in workingStates) s.Handle(null); + foreach (var s in activeStates) s.Handle(null); ValidateStates(); if (time1 == time0) { var batch = Events[EventId]; for (var i = 0; i < batch.Count; i++) { var ev = batch[i]; - if (ev.Container != null) { - if (ev.Unstamped is EventContainer) EnsureActivity((EventContainer)ev.Unstamped); - else EnsureActivity(ev.Container); + if (ev is StampedEvent.ClipBehind) { + var cevs = ev.Origin.Coevents; + if (cevs != null) foreach (var cev in cevs) { + if (cev.Container == null) continue; + states[cev.Container].Handle(cev); + } + states[(EventContainer)ev.Origin.Unstamped].PhysicalActive = true; + } + else if (ev is StampedEvent.ClipAhead) { + states[(EventContainer)ev.Origin.Unstamped].PhysicalActive = false; + } + else if (ev.Container != null) { states[ev.Container].Handle(ev); } - else if (ev.Coevents != null) EnsureActivity((EventContainer)ev.Unstamped); } EventId++; } @@ -165,25 +144,23 @@ namespace Cryville.Crtr.Event { var ev = tempEvents[0]; if (ev.Time != time0) break; if (ev.Container != null) { - EnsureActivity(ev.Container); states[ev.Container].Handle(ev); } tempEvents.RemoveAt(0); } } - ValidateStates(); } else { Time = toTime; - foreach (var s in workingStates) s.Handle(null); - ValidateStates(); + foreach (var s in activeStates) s.Handle(null); } + ValidateStates(); } private void ValidateStates() { foreach (var s in invalidatedStates) - if (s.Working && !workingStates.Contains(s)) workingStates.Add(s); - else if (!s.Working && workingStates.Contains(s)) workingStates.Remove(s); + if (s.Active && !activeStates.Contains(s)) activeStates.Add(s); + else if (!s.Active && activeStates.Contains(s)) activeStates.Remove(s); invalidatedStates.Clear(); } @@ -194,8 +171,11 @@ namespace Cryville.Crtr.Event { RootState.BroadcastPostInit(); } - public void BroadcastEndUpdate() { - RootState.BroadcastEndUpdate(); + public void EndPreGraphicalUpdate() { + RootState.EndPreGraphicalUpdate(); + } + public void EndGraphicalUpdate() { + RootState.EndGraphicalUpdate(); foreach (var ev in tempEvents) { if (ev.Container != null) { states[ev.Container].Discard(ev); diff --git a/Assets/Cryville/Crtr/NoteHandler.cs b/Assets/Cryville/Crtr/NoteHandler.cs index b0f9dba..1d8df9b 100644 --- a/Assets/Cryville/Crtr/NoteHandler.cs +++ b/Assets/Cryville/Crtr/NoteHandler.cs @@ -59,19 +59,17 @@ namespace Cryville.Crtr { sgos = gogroup.GetComponentsInChildren(); foreach (var judge in judges.Values) judge.InitPropSrcs(); } - protected override void PreAwake(ContainerState s) { - base.PreAwake(s); -#if UNITY_5_6_OR_NEWER - a_head.Transform.SetPositionAndRotation(Position = GetFramePoint(s.Parent, s.Track), Rotation = GetFrameRotation(s.Parent, s.Track)); -#else - a_head.Transform.position = Position = GetFramePoint(s.Parent, s.Track); - a_head.Transform.rotation = Rotation = GetFrameRotation(s.Parent, s.Track); -#endif - } - protected override void Awake(ContainerState s) { - base.Awake(s); + + public override void StartPhysicalUpdate(ContainerState s) { + base.StartPhysicalUpdate(s); if (s.CloneType == 2) { - if (!gogroup) return; + TransformAwake(s); + } + } + public override void StartGraphicalUpdate(ContainerState s) { + base.StartGraphicalUpdate(s); + TransformAwake(s); + if (gogroup) { if (Event.IsLong) { foreach (var i in sgos) { i.Reset(); @@ -88,17 +86,18 @@ namespace Cryville.Crtr { } } } + void TransformAwake(ContainerState s) { + Position = GetFramePoint(s.Parent, s.Track); + Rotation = GetFrameRotation(s.Parent, s.Track); + } public override void Update(ContainerState s, StampedEvent ev) { base.Update(s, ev); if (s.CloneType <= 2) { Position = GetFramePoint(s.Parent, s.Track); Rotation = GetFrameRotation(s.Parent, s.Track); - } - if (s.CloneType == 2) { - if (!gogroup) return; - Chart.Note tev = Event; - if (tev.IsLong) { + if (s.CloneType == 2) { + if (!gogroup || !Event.IsLong) return; foreach (var i in sgos) i.AppendPoint(Position, Rotation); } @@ -116,22 +115,11 @@ namespace Cryville.Crtr { } } - public override void Anchor() { - base.Anchor(); - // TODO Push Dynamic Anchor Events - } - - public override void EndUpdate(ContainerState s) { - if (s.CloneType == 2 && gogroup) { + public override void EndGraphicalUpdate(ContainerState s) { + if (gogroup) { foreach (var i in sgos) i.Seal(); -#if UNITY_5_6_OR_NEWER - a_tail.Transform.SetPositionAndRotation(GetFramePoint(ts.Parent, ts.Track), Quaternion.Euler(ts.Direction)); -#else - a_tail.Transform.position = GetFramePoint(ts.Parent, ts.Track); - a_tail.Transform.rotation = Quaternion.Euler(ts.Direction); -#endif } - base.EndUpdate(s); + base.EndGraphicalUpdate(s); } Vector3 GetFramePoint(ContainerState state, float track) { diff --git a/Assets/Cryville/Crtr/StampedEvent.cs b/Assets/Cryville/Crtr/StampedEvent.cs index ace588b..f6465f0 100644 --- a/Assets/Cryville/Crtr/StampedEvent.cs +++ b/Assets/Cryville/Crtr/StampedEvent.cs @@ -39,8 +39,16 @@ namespace Cryville.Crtr { public override int Priority { get { return m_priority; } } public void SetPriority(int value) { m_priority = value; } } + + public class ClipBehind : StampedEvent { public override int Priority { - get { return 0; } + get { return Origin.Priority - 0x8000; } + } + } + + public class ClipAhead : StampedEvent { + public override int Priority { + get { return 0x7fff - Origin.Priority; } } } diff --git a/Assets/Cryville/Crtr/TrackHandler.cs b/Assets/Cryville/Crtr/TrackHandler.cs index c6db0fb..9b03beb 100644 --- a/Assets/Cryville/Crtr/TrackHandler.cs +++ b/Assets/Cryville/Crtr/TrackHandler.cs @@ -21,34 +21,37 @@ namespace Cryville.Crtr { SectionalGameObject[] sgos; Vector3 bpos; Quaternion brot; Vector3 spos; - protected override void PreAwake(ContainerState s) { - base.PreAwake(s); + public override void StartPhysicalUpdate(ContainerState s) { + base.StartPhysicalUpdate(s); + if (CanDoGraphicalUpdate(s)) { + TransformAwake(s); + } + } + public override void StartPreGraphicalUpdate(ContainerState s) { + base.StartPreGraphicalUpdate(s); + TransformAwake(s); + } + public override void StartGraphicalUpdate(ContainerState s) { + base.StartGraphicalUpdate(s); + if (gogroup) { + TransformAwake(s); + var p = GetCurrentWorldPoint(); + foreach (var i in sgos) { + i.Reset(); + i.AppendPoint(p, s.QuatDir); + } + } + } + void TransformAwake(ContainerState s) { pwp = Vector3.zero; cpt = s.ScreenPoint; ptime = s.Time; - if (s.CloneType == 2) { -#if UNITY_5_6_OR_NEWER - a_head.Transform.SetPositionAndRotation(GetCurrentWorldPoint(), Quaternion.Euler(s.Direction)); -#else - a_head.Transform.position = GetCurrentWorldPoint(); - a_head.Transform.rotation = Quaternion.Euler(s.Direction); -#endif - } - else if (s.CloneType == 3) { + if (s.CloneType == 3) { spos = Vector3.zero; bpos = cpt; brot = Quaternion.Euler(s.Direction); } } - protected override void Awake(ContainerState s) { - base.Awake(s); - if (!gogroup) return; - var p = GetCurrentWorldPoint(); - foreach (var i in sgos) { - i.Reset(); - i.AppendPoint(p, s.QuatDir); - } - } Vector3 cpt; // Current point Vector3 ppt = Vector3.zero; // Previous point @@ -58,7 +61,7 @@ namespace Cryville.Crtr { public override void Update(ContainerState s, StampedEvent ev) { base.Update(s, ev); - if (s.CloneType == 2 || s.CloneType == 3) { + if (CanDoGraphicalUpdate(s)) { var tpt = s.ScreenPoint; var tsv = s.ScrollVelocity; @@ -102,24 +105,14 @@ namespace Cryville.Crtr { spos = bpos - GetCurrentWorldPoint(); } - public override void EndUpdate(ContainerState s) { - base.EndUpdate(s); - if (s.CloneType == 0 || s.CloneType == 2) { - EndUpdatePosition(ts); - var p = GetCurrentWorldPoint(); - foreach (var i in sgos) { - i.AppendPoint(p, s.QuatDir); - i.Seal(); - } -#if UNITY_5_6_OR_NEWER - a_tail.Transform.SetPositionAndRotation(GetCurrentWorldPoint(), Quaternion.Euler(ts.Direction)); -#else - a_tail.Transform.position = GetCurrentWorldPoint(); - a_tail.Transform.rotation = Quaternion.Euler(ts.Direction); -#endif + public override void EndGraphicalUpdate(ContainerState s) { + base.EndGraphicalUpdate(s); + EndUpdatePosition(s); + var p = GetCurrentWorldPoint(); + foreach (var i in sgos) { + i.AppendPoint(p, s.QuatDir); + i.Seal(); } - else if (s.CloneType == 3) EndUpdatePosition(ns); - else if (s.CloneType >= 16) EndUpdatePosition(ps); } void EndUpdatePosition(ContainerState s) {