Add "cur" anchor.

This commit is contained in:
2022-12-22 14:43:50 +08:00
parent 8175ca7e82
commit ec9b23f797
3 changed files with 82 additions and 53 deletions

View File

@@ -38,6 +38,7 @@ namespace Cryville.Crtr.Event {
public Transform gogroup;
public readonly Dictionary<int, Anchor> Anchors = new Dictionary<int, Anchor>();
protected Transform a_cur;
protected Transform a_head;
protected Transform a_tail;
public Vector3 Position {
@@ -76,12 +77,14 @@ namespace Cryville.Crtr.Event {
public abstract string TypeName {
get;
}
protected readonly static int _a_cur = IdentifierManager.SharedInstance.Request("cur");
protected readonly static int _a_head = IdentifierManager.SharedInstance.Request("head");
protected readonly static int _a_tail = IdentifierManager.SharedInstance.Request("tail");
public virtual void PreInit() {
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);
}

View File

@@ -60,33 +60,44 @@ namespace Cryville.Crtr {
}
public override void Update(ContainerState s, StampedEvent ev) {
base.Update(s, ev);
if (s.CloneType == 1) {
Position = GetFramePoint(bs.Parent, bs.Track);
Rotation = GetFrameRotation(bs.Parent, bs.Track);
if (s.CloneType == 0) {
#if UNITY_5_6_OR_NEWER
a_cur.SetPositionAndRotation(GetFramePoint(s.Parent, s.Track), GetFrameRotation(s.Parent, s.Track));
#else
a_cur.position = GetFramePoint(s.Parent, s.Track);
a_cur.rotation = GetFrameRotation(s.Parent, s.Track);
#endif
OpenAnchor(_a_cur);
base.Update(s, ev);
CloseAnchor(_a_cur);
}
else if (s.CloneType == 2) {
Position = GetFramePoint(ts.Parent, ts.Track);
Rotation = GetFrameRotation(ts.Parent, ts.Track);
if (!gogroup) return;
Chart.Note tev = Event;
if (tev.IsLong) {
foreach (var i in sgos)
i.AppendPoint(Position, Rotation);
else {
base.Update(s, ev);
if (s.CloneType <= 2) {
Position = GetFramePoint(s.Parent, s.Track);
Rotation = GetFrameRotation(s.Parent, s.Track);
}
}
else if (s.CloneType == 16) {
if (ev == null) { }
else if (ev.Unstamped == null) { }
else if (ev.Unstamped is Chart.Judge) {
var tev = (Chart.Judge)ev.Unstamped;
Identifier name = default(Identifier);
ChartPlayer.etor.ContextEvent = tev;
ChartPlayer.etor.ContextState = s;
ChartPlayer.etor.Evaluate(new PropOp.Identifier(v => name = new Identifier(v)), ruleset.judges[tev.Id].input);
judge.Prepare(ev.Time, ev.Time + ev.Duration, name, ruleset.judges[tev.Id], cs);
ChartPlayer.etor.ContextState = null;
ChartPlayer.etor.ContextEvent = null;
if (s.CloneType == 2) {
if (!gogroup) return;
Chart.Note tev = Event;
if (tev.IsLong) {
foreach (var i in sgos)
i.AppendPoint(Position, Rotation);
}
}
else if (s.CloneType == 16) {
if (ev == null) { }
else if (ev.Unstamped == null) { }
else if (ev.Unstamped is Chart.Judge) {
var tev = (Chart.Judge)ev.Unstamped;
Identifier name = default(Identifier);
ChartPlayer.etor.ContextEvent = tev;
ChartPlayer.etor.ContextState = s;
ChartPlayer.etor.Evaluate(new PropOp.Identifier(v => name = new Identifier(v)), ruleset.judges[tev.Id].input);
judge.Prepare(ev.Time, ev.Time + ev.Duration, name, ruleset.judges[tev.Id], cs);
ChartPlayer.etor.ContextState = null;
ChartPlayer.etor.ContextEvent = null;
}
}
}
}

View File

@@ -39,7 +39,6 @@ namespace Cryville.Crtr {
#endif
}
else if (s.CloneType == 3) {
spos = Vector3.zero;
bpos = cpt;
brot = Quaternion.Euler(s.Direction);
}
@@ -61,34 +60,50 @@ namespace Cryville.Crtr {
float length;
public override void Update(ContainerState s, StampedEvent ev) {
base.Update(s, ev);
if (s.CloneType == 2 || s.CloneType == 3) {
var tpt = s.ScreenPoint;
var tsv = s.ScrollVelocity;
Vector3 dpt = (Vector3)tpt - ppt; // Delta 2D point
dpt.z = (float)((s.Time - ptime) * ChartPlayer.sv * tsv); // Delta Z
Quaternion rotq = Quaternion.Euler(s.Direction); // Rotation
var dwp = rotq * dpt; // Delta world point
var nl = length + dwp.magnitude; // New length
var tdist = s.Distance;
if (nl >= tdist) {
s.Break();
return;
}
length = nl;
var wp = pwp + dwp; // World point
pwp = wp;
ppt += dpt;
ptime = s.Time;
if (!gogroup || s.CloneType == 3) return;
var p = GetCurrentWorldPoint();
foreach (var i in sgos)
i.AppendPoint(p, s.QuatDir);
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
OpenAnchor(_a_cur);
base.Update(s, ev);
CloseAnchor(_a_cur);
}
else {
base.Update(s, ev);
if (s.CloneType == 2 || s.CloneType == 3) {
var tpt = s.ScreenPoint;
var tsv = s.ScrollVelocity;
Vector3 dpt = (Vector3)tpt - ppt; // Delta 2D point
dpt.z = (float)((s.Time - ptime) * ChartPlayer.sv * tsv); // Delta Z
Quaternion rotq = Quaternion.Euler(s.Direction); // Rotation
var dwp = rotq * dpt; // Delta world point
var nl = length + dwp.magnitude; // New length
var tdist = s.Distance;
if (nl >= tdist) {
s.Break();
return;
}
length = nl;
var wp = pwp + dwp; // World point
pwp = wp;
ppt += dpt;
ptime = s.Time;
if (!gogroup || s.CloneType == 3) return;
var p = GetCurrentWorldPoint();
foreach (var i in sgos)
i.AppendPoint(p, s.QuatDir);
}
else UpdatePosition(s);
}
else UpdatePosition(s);
}
void UpdatePosition(ContainerState s) {