Allow dynamic anchor reset.
This commit is contained in:
@@ -76,7 +76,7 @@ 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 readonly Dictionary<int, double> DynamicAnchorSetTime = new Dictionary<int, double>();
|
||||
Anchor a_cur;
|
||||
Anchor a_head;
|
||||
Anchor a_tail;
|
||||
@@ -94,7 +94,7 @@ namespace Cryville.Crtr.Event {
|
||||
if (DynamicAnchors.ContainsKey(name))
|
||||
throw new ArgumentException(string.Format("The anchor \"{0}\" already exists", strname));
|
||||
DynamicAnchors.Add(name, result);
|
||||
DynamicAnchorSet.Add(name, false);
|
||||
DynamicAnchorSetTime.Add(name, double.NaN);
|
||||
}
|
||||
List<Anchor> list;
|
||||
if (!Anchors.TryGetValue(name, out list))
|
||||
@@ -201,16 +201,23 @@ namespace Cryville.Crtr.Event {
|
||||
#region Anchor
|
||||
public virtual void Anchor() {
|
||||
foreach (var p in PropSrcs.Values) p.Invalidate();
|
||||
foreach (var a in DynamicAnchors.Keys) DynamicAnchorSet[a] = false;
|
||||
foreach (var a in DynamicAnchors.Keys) DynamicAnchorSetTime[a] = double.NaN;
|
||||
atime_head = cs.StampedContainer.Time;
|
||||
atime_tail = atime_head + cs.StampedContainer.Duration;
|
||||
MatchDynamic(cs, 0);
|
||||
if (cs.Active) PushAnchorEvent(cs.Time, a_cur);
|
||||
if (Alive) {
|
||||
if (!DynamicAnchorSet[_a_head]) PushAnchorEvent(atime_head, a_head, -1, true);
|
||||
if (!DynamicAnchorSet[_a_tail]) PushAnchorEvent(atime_tail, a_tail, 1, true);
|
||||
foreach (var anchors in Anchors.Values) foreach (var anchor in anchors) anchor.Transform.gameObject.SetActive(false);
|
||||
if (double.IsNaN(DynamicAnchorSetTime[_a_head])) DynamicAnchorSetTime[_a_head] = atime_head;
|
||||
if (double.IsNaN(DynamicAnchorSetTime[_a_tail])) DynamicAnchorSetTime[_a_tail] = atime_tail;
|
||||
foreach (var t in DynamicAnchorSetTime) {
|
||||
if (double.IsNaN(t.Value)) continue;
|
||||
int priority = 0;
|
||||
bool forced = true;
|
||||
if (t.Key == _a_head) { priority = -1; }
|
||||
else if (t.Key == _a_tail) { priority = 1; }
|
||||
else forced = false;
|
||||
PushAnchorEvent(t.Value, DynamicAnchors[t.Key], priority, forced);
|
||||
}
|
||||
foreach (var anchors in Anchors.Values) foreach (var anchor in anchors) anchor.Transform.gameObject.SetActive(false);
|
||||
}
|
||||
static readonly SimpleObjectPool<StampedEvent.Anchor> anchorEvPool
|
||||
= new SimpleObjectPool<StampedEvent.Anchor>(1024);
|
||||
@@ -245,18 +252,11 @@ namespace Cryville.Crtr.Event {
|
||||
RegisterAnchor(name, true);
|
||||
}
|
||||
public void PushAnchorEvent(double time, int name) {
|
||||
Anchor anchor;
|
||||
if (!DynamicAnchors.TryGetValue(name, out anchor))
|
||||
if (!DynamicAnchors.ContainsKey(name))
|
||||
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;
|
||||
if (name == _a_head) atime_head = time;
|
||||
else if (name == _a_tail) atime_tail = time;
|
||||
DynamicAnchorSetTime[name] = time;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
Reference in New Issue
Block a user