Remove some dedicated properties on ISkinnableGroup.

This commit is contained in:
2023-02-17 18:10:46 +08:00
parent 88d35e4eaf
commit 9c08cbf0d2
5 changed files with 72 additions and 78 deletions

View File

@@ -8,10 +8,9 @@ using System.Runtime.CompilerServices;
using UnityEngine;
namespace Cryville.Crtr.Event {
public abstract class ContainerHandler {
public abstract class ContainerHandler : ISkinnableGroup {
#region Struct
public ContainerHandler() { }
public abstract string TypeName { get; }
/// <summary>
/// Prehandling <see cref="ContainerState"/>, prehandling the events.
@@ -42,7 +41,6 @@ namespace Cryville.Crtr.Event {
/// <see cref="GameObject"/> group, the <see cref="Transform"/> containing all the generated elements in the <see cref="ContainerHandler"/>.
/// </summary>
protected Transform gogroup;
public SkinContext SkinContext;
public Vector3 Position { get; protected set; }
public Quaternion Rotation { get; protected set; }
@@ -79,7 +77,6 @@ namespace Cryville.Crtr.Event {
public readonly Dictionary<int, List<Anchor>> Anchors = new Dictionary<int, List<Anchor>>();
public readonly Dictionary<int, Anchor> DynamicAnchors = new Dictionary<int, Anchor>();
public readonly Dictionary<int, bool> DynamicAnchorSet = new Dictionary<int, bool>();
public Anchor OpenedAnchor;
Anchor a_cur;
Anchor a_head;
Anchor a_tail;
@@ -127,7 +124,11 @@ namespace Cryville.Crtr.Event {
a_tail = RegisterAnchor(_a_tail, true);
}
public virtual void Init() {
skinContainer.MatchStatic(ps);
ChartPlayer.etor.ContextState = ps;
ChartPlayer.etor.ContextEvent = Container;
skinContainer.MatchStatic(this);
ChartPlayer.etor.ContextEvent = null;
ChartPlayer.etor.ContextState = null;
foreach (var i in gogroup.GetComponentsInChildren<SkinComponent>())
i.Init();
}
@@ -160,7 +161,7 @@ namespace Cryville.Crtr.Event {
tev.Target.Transform.position = Position;
tev.Target.Transform.rotation = Rotation;
#endif
skinContainer.MatchDynamic(s);
MatchDynamic(s, 1);
CloseAnchor();
}
if (tev.Target == a_head) {
@@ -171,7 +172,7 @@ namespace Cryville.Crtr.Event {
}
anchorEvPool.Return(tev);
}
else if (gogroup && s.CloneType == 2) skinContainer.MatchDynamic(s);
else if (gogroup && s.CloneType == 2) MatchDynamic(s, 1);
}
#region End methods
public virtual void EndGraphicalUpdate(ContainerState s) { }
@@ -185,15 +186,25 @@ namespace Cryville.Crtr.Event {
}
public virtual void DisposeAll() { }
#endregion
#region Utils
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected static bool CanDoGraphicalUpdate(ContainerState s) { return s.CloneType >= 2 && s.CloneType < 16; }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void MatchDynamic(ContainerState s, int dl) {
ChartPlayer.etor.ContextState = s;
ChartPlayer.etor.ContextEvent = Container;
skinContainer.MatchDynamic(this, dl);
ChartPlayer.etor.ContextEvent = null;
ChartPlayer.etor.ContextState = null;
}
#endregion
#region Anchor
public virtual void Anchor() {
foreach (var p in PropSrcs.Values) p.Invalidate();
foreach (var a in DynamicAnchors.Keys) DynamicAnchorSet[a] = false;
atime_head = cs.StampedContainer.Time;
atime_tail = atime_head + cs.StampedContainer.Duration;
skinContainer.MatchDynamic(cs);
MatchDynamic(cs, 0);
if (cs.Active) PushAnchorEvent(cs.Time, a_cur);
if (Alive) {
if (!DynamicAnchorSet[_a_head]) PushAnchorEvent(atime_head, a_head, -1, true);
@@ -203,20 +214,6 @@ namespace Cryville.Crtr.Event {
}
static readonly SimpleObjectPool<StampedEvent.Anchor> anchorEvPool
= new SimpleObjectPool<StampedEvent.Anchor>(1024);
public void PushAnchorEvent(double time, int name) {
Anchor anchor;
if (!DynamicAnchors.TryGetValue(name, out anchor))
throw new ArgumentException(string.Format("Specified anchor \"{0}\" not found", IdentifierManager.SharedInstance.Retrieve(name)));
if (DynamicAnchorSet[name])
throw new InvalidOperationException(string.Format("Specified anchor \"{0}\" has been set", IdentifierManager.SharedInstance.Retrieve(name)));
int priority = 0;
bool forced = true;
if (name == _a_head) { priority = -1; atime_head = time; }
else if (name == _a_tail) { priority = 1; atime_tail = time; }
else forced = false;
PushAnchorEvent(time, anchor, priority, forced);
DynamicAnchorSet[name] = true;
}
void PushAnchorEvent(double time, Anchor anchor, int priority = 0, bool forced = false) {
var tev = anchorEvPool.Rent();
tev.Time = time;
@@ -233,5 +230,34 @@ namespace Cryville.Crtr.Event {
}
#endregion
#endregion
#region ISkinnableGroup
public abstract string TypeName { get; }
public SkinContext SkinContext { get; set; }
public Anchor OpenedAnchor { get; set; }
public bool TryGetAnchorsByName(int name, out IReadOnlyCollection<Anchor> result) {
List<Anchor> anchors;
var ret = Anchors.TryGetValue(name, out anchors);
result = anchors;
return ret;
}
void ISkinnableGroup.RegisterAnchor(int name) {
RegisterAnchor(name, true);
}
public void PushAnchorEvent(double time, int name) {
Anchor anchor;
if (!DynamicAnchors.TryGetValue(name, out anchor))
throw new ArgumentException(string.Format("Specified anchor \"{0}\" not found", IdentifierManager.SharedInstance.Retrieve(name)));
if (DynamicAnchorSet[name])
throw new InvalidOperationException(string.Format("Specified anchor \"{0}\" has been set", IdentifierManager.SharedInstance.Retrieve(name)));
int priority = 0;
bool forced = true;
if (name == _a_head) { priority = -1; atime_head = time; }
else if (name == _a_tail) { priority = 1; atime_tail = time; }
else forced = false;
PushAnchorEvent(time, anchor, priority, forced);
DynamicAnchorSet[name] = true;
}
#endregion
}
}