Revise anchor data structure.
This commit is contained in:
@@ -38,10 +38,6 @@ namespace Cryville.Crtr.Event {
|
||||
/// </summary>
|
||||
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 { get; protected set; }
|
||||
public Quaternion Rotation { get; protected set; }
|
||||
public bool Alive { get; private set; }
|
||||
@@ -63,6 +59,11 @@ namespace Cryville.Crtr.Event {
|
||||
public abstract string TypeName {
|
||||
get;
|
||||
}
|
||||
public readonly Dictionary<int, List<Anchor>> Anchors = new Dictionary<int, List<Anchor>>();
|
||||
public readonly Dictionary<int, Anchor> OpenAnchors = new Dictionary<int, Anchor>();
|
||||
protected Anchor a_cur;
|
||||
protected Anchor a_head;
|
||||
protected Anchor a_tail;
|
||||
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");
|
||||
@@ -70,15 +71,18 @@ 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).Transform;
|
||||
a_head = RegisterAnchor(_a_head).Transform;
|
||||
a_tail = RegisterAnchor(_a_tail).Transform;
|
||||
a_cur = RegisterAnchor(_a_cur);
|
||||
a_head = RegisterAnchor(_a_head);
|
||||
a_tail = RegisterAnchor(_a_tail);
|
||||
}
|
||||
protected Anchor RegisterAnchor(int name) {
|
||||
var go = new GameObject("." + IdentifierManager.SharedInstance.Retrieve(name)).transform;
|
||||
go.SetParent(gogroup, false);
|
||||
var result = new Anchor() { Transform = go };
|
||||
Anchors.Add(name, result);
|
||||
var result = new Anchor(name, go);
|
||||
List<Anchor> list;
|
||||
if (!Anchors.TryGetValue(name, out list))
|
||||
Anchors.Add(name, list = new List<Anchor>());
|
||||
list.Add(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -102,12 +106,14 @@ namespace Cryville.Crtr.Event {
|
||||
Alive = false;
|
||||
}
|
||||
protected virtual void PreAwake(ContainerState s) {
|
||||
if (gogroup) gogroup.gameObject.SetActive(true);
|
||||
if (gogroup) {
|
||||
gogroup.gameObject.SetActive(true);
|
||||
OpenAnchor(a_head);
|
||||
}
|
||||
Awoken = true; Alive = true;
|
||||
OpenAnchor(_a_head);
|
||||
}
|
||||
protected virtual void Awake(ContainerState s) {
|
||||
CloseAnchor(_a_head);
|
||||
if (gogroup) CloseAnchor(a_head);
|
||||
}
|
||||
protected virtual void GetPosition(ContainerState s) { }
|
||||
public virtual void StartUpdate(ContainerState s) {
|
||||
@@ -121,11 +127,11 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
static readonly SimpleObjectPool<StampedEvent.Anchor> anchorEvPool
|
||||
= new SimpleObjectPool<StampedEvent.Anchor>(1024);
|
||||
protected void PushAnchorEvent(int name, double time) {
|
||||
protected void PushAnchorEvent(double time, Anchor anchor) {
|
||||
var tev = anchorEvPool.Rent();
|
||||
tev.Time = time;
|
||||
tev.Container = Container;
|
||||
tev.Name = name;
|
||||
tev.Target = anchor;
|
||||
ts.Bus.PushTempEvent(tev);
|
||||
}
|
||||
public virtual void Update(ContainerState s, StampedEvent ev) {
|
||||
@@ -138,10 +144,15 @@ namespace Cryville.Crtr.Event {
|
||||
if (ev is StampedEvent.Anchor) {
|
||||
var tev = (StampedEvent.Anchor)ev;
|
||||
if (gogroup) {
|
||||
OpenAnchor(tev.Name);
|
||||
Anchors[tev.Name].Transform.SetPositionAndRotation(Position, Rotation);
|
||||
OpenAnchor(tev.Target);
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
tev.Target.Transform.SetPositionAndRotation(Position, Rotation);
|
||||
#else
|
||||
tev.Target.Transform.position = GetCurrentWorldPoint();
|
||||
tev.Target.Transform.rotation = Quaternion.Euler(s.Direction);
|
||||
#endif
|
||||
skinContainer.MatchDynamic(s);
|
||||
CloseAnchor(tev.Name);
|
||||
CloseAnchor(tev.Target);
|
||||
}
|
||||
anchorEvPool.Return(tev);
|
||||
}
|
||||
@@ -154,13 +165,13 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
}
|
||||
public virtual void Anchor() {
|
||||
if (cs.Working) PushAnchorEvent(_a_cur, cs.Time);
|
||||
if (cs.Working) PushAnchorEvent(cs.Time, a_cur);
|
||||
}
|
||||
protected void OpenAnchor(int name) {
|
||||
if (Anchors.ContainsKey(name)) Anchors[name].Open();
|
||||
protected void OpenAnchor(Anchor anchor) {
|
||||
OpenAnchors.Add(anchor.Name, anchor);
|
||||
}
|
||||
protected void CloseAnchor(int name) {
|
||||
if (Anchors.ContainsKey(name)) Anchors[name].Close();
|
||||
protected void CloseAnchor(Anchor anchor) {
|
||||
OpenAnchors.Remove(anchor.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user