Restructure event/container system.
This commit is contained in:
@@ -4,6 +4,7 @@ using Cryville.Crtr.Components;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr.Event {
|
||||
@@ -46,8 +47,20 @@ namespace Cryville.Crtr.Event {
|
||||
public Vector3 Position { get; protected set; }
|
||||
public Quaternion Rotation { get; protected set; }
|
||||
public bool Alive { get; private set; }
|
||||
public bool Awoken { get; private set; }
|
||||
public bool Disposed { get; private set; }
|
||||
bool PreGraphicalActive;
|
||||
public void SetPreGraphicalActive(bool value, ContainerState s) {
|
||||
if (PreGraphicalActive == value) return;
|
||||
PreGraphicalActive = value;
|
||||
if (PreGraphicalActive) StartPreGraphicalUpdate(s);
|
||||
else EndPreGraphicalUpdate(s);
|
||||
}
|
||||
bool GraphicalActive;
|
||||
public void SetGraphicalActive(bool value, ContainerState s) {
|
||||
if (GraphicalActive == value) return;
|
||||
GraphicalActive = value;
|
||||
if (GraphicalActive) StartGraphicalUpdate(s);
|
||||
else EndGraphicalUpdate(s);
|
||||
}
|
||||
|
||||
public EventContainer Container {
|
||||
get { return cs.Container; }
|
||||
@@ -114,34 +127,27 @@ namespace Cryville.Crtr.Event {
|
||||
gogroup.gameObject.SetActive(false);
|
||||
}
|
||||
#endregion
|
||||
protected virtual void PreAwake(ContainerState s) {
|
||||
if (gogroup) {
|
||||
gogroup.gameObject.SetActive(true);
|
||||
OpenAnchor(a_head);
|
||||
}
|
||||
Awoken = true; Alive = true;
|
||||
#region Start methods
|
||||
public virtual void StartPhysicalUpdate(ContainerState s) {
|
||||
if (s.CloneType < 16) Alive = true;
|
||||
else if (s.CloneType == 17) Init();
|
||||
}
|
||||
protected virtual void Awake(ContainerState s) {
|
||||
if (gogroup) CloseAnchor();
|
||||
}
|
||||
public virtual void StartUpdate(ContainerState s) {
|
||||
if (s.CloneType >= 2 && s.CloneType < 16) {
|
||||
PreAwake(s);
|
||||
Awake(s);
|
||||
}
|
||||
else if (s.CloneType == 17) {
|
||||
Init();
|
||||
}
|
||||
public virtual void StartLogicalUpdate(ContainerState s) { }
|
||||
public virtual void StartPreGraphicalUpdate(ContainerState s) { }
|
||||
public virtual void StartGraphicalUpdate(ContainerState s) {
|
||||
if (gogroup) gogroup.gameObject.SetActive(true);
|
||||
}
|
||||
#endregion
|
||||
public virtual void Update(ContainerState s, StampedEvent ev) {
|
||||
bool flag = !Awoken && s.CloneType >= 2 && s.CloneType < 16;
|
||||
if (flag) PreAwake(s);
|
||||
if (gogroup && s.CloneType <= 2) skinContainer.MatchDynamic(s);
|
||||
if (flag) Awake(s);
|
||||
}
|
||||
public virtual void ExUpdate(ContainerState s, StampedEvent ev) {
|
||||
if (ev is StampedEvent.Anchor) {
|
||||
if (s.CloneType == 3) SetPreGraphicalActive(true, s);
|
||||
else if (ev is StampedEvent.Anchor) {
|
||||
var tev = (StampedEvent.Anchor)ev;
|
||||
if (tev.Target == a_head) {
|
||||
SetGraphicalActive(true, s);
|
||||
}
|
||||
else if (tev.Target == a_tail) {
|
||||
SetGraphicalActive(false, s);
|
||||
}
|
||||
if (gogroup) {
|
||||
OpenAnchor(tev.Target);
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
@@ -155,28 +161,31 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
anchorEvPool.Return(tev);
|
||||
}
|
||||
else if (gogroup && s.CloneType <= 2) skinContainer.MatchDynamic(s);
|
||||
}
|
||||
public virtual void MotionUpdate(byte ct, Chart.Motion ev) { }
|
||||
public virtual void EndUpdate(ContainerState s) {
|
||||
if (s.CloneType < 16) {
|
||||
Awoken = false;
|
||||
if (gogroup && s.CloneType <= 2) {
|
||||
OpenAnchor(a_tail);
|
||||
skinContainer.MatchDynamic(s);
|
||||
CloseAnchor();
|
||||
}
|
||||
}
|
||||
}
|
||||
#region End methods
|
||||
public virtual void EndGraphicalUpdate(ContainerState s) { }
|
||||
public virtual void EndPreGraphicalUpdate(ContainerState s) { }
|
||||
public virtual void EndLogicalUpdate(ContainerState s) { }
|
||||
public virtual void EndPhysicalUpdate(ContainerState s) { }
|
||||
public virtual void Dispose() {
|
||||
if (gogroup)
|
||||
GameObject.Destroy(gogroup.gameObject);
|
||||
Alive = false;
|
||||
}
|
||||
public virtual void DisposeAll() { }
|
||||
#endregion
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected static bool CanDoGraphicalUpdate(ContainerState s) { return s.CloneType >= 2 && s.CloneType < 16; }
|
||||
#region Anchor
|
||||
public virtual void Anchor() {
|
||||
skinContainer.MatchDynamic(cs);
|
||||
if (cs.Working) PushAnchorEvent(cs.Time, a_cur);
|
||||
if (cs.Active) PushAnchorEvent(cs.Time, a_cur);
|
||||
if (Alive) {
|
||||
PushAnchorEvent(cs.StampedContainer.Time, a_head, -1, true);
|
||||
PushAnchorEvent(cs.StampedContainer.Time + cs.StampedContainer.Duration, a_tail, 1, true);
|
||||
}
|
||||
}
|
||||
static readonly SimpleObjectPool<StampedEvent.Anchor> anchorEvPool
|
||||
= new SimpleObjectPool<StampedEvent.Anchor>(1024);
|
||||
public void PushAnchorEvent(double time, int name) {
|
||||
|
Reference in New Issue
Block a user