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