Cleanup anchor related code.

This commit is contained in:
2023-01-01 19:01:34 +08:00
parent e8f74399f2
commit 4d7773a2ac
3 changed files with 21 additions and 35 deletions

View File

@@ -70,15 +70,16 @@ namespace Cryville.Crtr.Event {
gogroup = new GameObject(TypeName + ":" + Container.GetHashCode().ToString(CultureInfo.InvariantCulture)).transform;
if (cs.Parent != null)
gogroup.SetParent(cs.Parent.Handler.gogroup, false);
a_cur = RegisterAnchor(_a_cur);
a_head = RegisterAnchor(_a_head);
a_tail = RegisterAnchor(_a_tail);
a_cur = RegisterAnchor(_a_cur).Transform;
a_head = RegisterAnchor(_a_head).Transform;
a_tail = RegisterAnchor(_a_tail).Transform;
}
protected Transform RegisterAnchor(int name) {
protected Anchor RegisterAnchor(int name) {
var go = new GameObject("." + IdentifierManager.SharedInstance.Retrieve(name)).transform;
go.SetParent(gogroup, false);
Anchors.Add(name, new Anchor() { Transform = go });
return go;
var result = new Anchor() { Transform = go };
Anchors.Add(name, result);
return result;
}
/// <summary>
@@ -120,24 +121,25 @@ namespace Cryville.Crtr.Event {
}
static readonly SimpleObjectPool<StampedEvent.Anchor> anchorEvPool
= new SimpleObjectPool<StampedEvent.Anchor>(1024);
protected void PushAnchorEvent(int name, double time) {
var tev = anchorEvPool.Rent();
tev.Time = time;
tev.Container = Container;
tev.Name = name;
ts.Bus.PushTempEvent(tev);
}
public virtual void Update(ContainerState s, StampedEvent ev) {
bool flag = !Awoken && s.CloneType >= 2 && s.CloneType < 16;
if (flag) PreAwake(s);
if (s.CloneType <= 2) if (gogroup) skinContainer.MatchDynamic(s);
if (flag) Awake(s);
if (s.CloneType == 0) {
var tev = anchorEvPool.Rent();
tev.Time = s.Time;
tev.Container = s.Container;
tev.Name = _a_cur;
ts.Bus.PushTempEvent(tev);
}
}
public virtual void ExUpdate(ContainerState s, StampedEvent ev) {
if (ev is StampedEvent.Anchor) {
var tev = (StampedEvent.Anchor)ev;
if (gogroup) {
OpenAnchor(tev.Name);
Anchors[tev.Name].Transform.SetPositionAndRotation(Position, Rotation);
skinContainer.MatchDynamic(s);
CloseAnchor(tev.Name);
}
@@ -151,7 +153,9 @@ namespace Cryville.Crtr.Event {
if (gogroup && s.CloneType <= 2) skinContainer.MatchDynamic(s);
}
}
public virtual void Anchor() { }
public virtual void Anchor() {
if (cs.Working) PushAnchorEvent(_a_cur, cs.Time);
}
protected void OpenAnchor(int name) {
if (Anchors.ContainsKey(name)) Anchors[name].Open();
}

View File

@@ -90,15 +90,7 @@ namespace Cryville.Crtr {
Position = GetFramePoint(s.Parent, s.Track);
Rotation = GetFrameRotation(s.Parent, s.Track);
}
if (s.CloneType == 0) {
#if UNITY_5_6_OR_NEWER
a_cur.SetPositionAndRotation(Position, Rotation);
#else
a_cur.position = Position;
a_cur.rotation = Rotation;
#endif
}
else if (s.CloneType == 2) {
if (s.CloneType == 2) {
if (!gogroup) return;
Chart.Note tev = Event;
if (tev.IsLong) {

View File

@@ -39,6 +39,7 @@ namespace Cryville.Crtr {
#endif
}
else if (s.CloneType == 3) {
spos = Vector3.zero;
bpos = cpt;
brot = Quaternion.Euler(s.Direction);
}
@@ -61,18 +62,7 @@ namespace Cryville.Crtr {
public override void Update(ContainerState s, StampedEvent ev) {
base.Update(s, ev);
if (s.CloneType == 0) {
pwp = Vector3.zero;
cpt = s.ScreenPoint;
spos = Vector3.zero;
#if UNITY_5_6_OR_NEWER
a_cur.SetPositionAndRotation(s.ScreenPoint, Quaternion.Euler(s.Direction));
#else
a_cur.position = s.ScreenPoint;
a_cur.rotation = Quaternion.Euler(s.Direction);
#endif
}
else if (s.CloneType == 2 || s.CloneType == 3) {
if (s.CloneType == 2 || s.CloneType == 3) {
var tpt = s.ScreenPoint;
var tsv = s.ScrollVelocity;