Add "emit effect on self" annotation.
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
using System;
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
using Logger = Cryville.Common.Logger;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Components {
|
namespace Cryville.Crtr.Components {
|
||||||
public class SkinAnimation : SkinComponent {
|
public class SkinAnimation : SkinComponent {
|
||||||
@@ -13,6 +15,7 @@ namespace Cryville.Crtr.Components {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SkinContext _skinContext;
|
SkinContext _skinContext;
|
||||||
|
Transform _writeTransform;
|
||||||
|
|
||||||
AnimationSpan _anim;
|
AnimationSpan _anim;
|
||||||
int _name;
|
int _name;
|
||||||
@@ -45,8 +48,10 @@ namespace Cryville.Crtr.Components {
|
|||||||
public override void Init() {
|
public override void Init() {
|
||||||
_skinContext = new SkinContext(transform);
|
_skinContext = new SkinContext(transform);
|
||||||
}
|
}
|
||||||
public override void Rewind(double time) {
|
public override void Rewind(double time, Transform target) {
|
||||||
_startTime = time;
|
_startTime = time;
|
||||||
|
if (target == null) target = transform;
|
||||||
|
_writeTransform = target;
|
||||||
}
|
}
|
||||||
public override void Tick(SkinContainer c, double time) {
|
public override void Tick(SkinContainer c, double time) {
|
||||||
float _rtime = (float)(time - _startTime - Delay) / Duration;
|
float _rtime = (float)(time - _startTime - Delay) / Duration;
|
||||||
@@ -71,7 +76,7 @@ namespace Cryville.Crtr.Components {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Direction.HasFlag(AnimationDirection.reverse)) _rtime = 1 - _rtime;
|
if (Direction.HasFlag(AnimationDirection.reverse)) _rtime = 1 - _rtime;
|
||||||
if (_anim != null) c.MatchAnimation(_anim, _rtime, new RuntimeSkinContext(_skinContext));
|
if (_anim != null) c.MatchAnimation(_anim, _rtime, new RuntimeSkinContext(_skinContext, _writeTransform));
|
||||||
}
|
}
|
||||||
protected override void OnDestroy() { }
|
protected override void OnDestroy() { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace Cryville.Crtr.Components {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Init() { }
|
public virtual void Init() { }
|
||||||
public virtual void Rewind(double time) { }
|
public virtual void Rewind(double time, Transform target) { }
|
||||||
public virtual void Tick(SkinContainer c, double time) { }
|
public virtual void Tick(SkinContainer c, double time) { }
|
||||||
protected abstract void OnDestroy();
|
protected abstract void OnDestroy();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Cryville.Common.Buffers;
|
using Cryville.Common.Buffers;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
public class EffectGroup {
|
public class EffectGroup {
|
||||||
@@ -40,6 +41,7 @@ namespace Cryville.Crtr {
|
|||||||
QueueInstance(item);
|
QueueInstance(item);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
item.Tick(time);
|
||||||
_instances.Remove(item.Index);
|
_instances.Remove(item.Index);
|
||||||
_pool.Return(item);
|
_pool.Return(item);
|
||||||
}
|
}
|
||||||
@@ -48,7 +50,7 @@ namespace Cryville.Crtr {
|
|||||||
instance.Value.Tick(time);
|
instance.Value.Tick(time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void Emit(float index) {
|
public void Emit(float index, Transform target = null) {
|
||||||
EffectInstance instance;
|
EffectInstance instance;
|
||||||
bool flag = _instances.TryGetValue(index, out instance);
|
bool flag = _instances.TryGetValue(index, out instance);
|
||||||
if (!flag) _instances.Add(index, instance = _pool.Rent());
|
if (!flag) _instances.Add(index, instance = _pool.Rent());
|
||||||
@@ -58,7 +60,7 @@ namespace Cryville.Crtr {
|
|||||||
var i = _endQueue.BinarySearch(instance);
|
var i = _endQueue.BinarySearch(instance);
|
||||||
_endQueue.RemoveAt(i);
|
_endQueue.RemoveAt(i);
|
||||||
}
|
}
|
||||||
instance.OnEmit(_time);
|
instance.OnEmit(_time, target);
|
||||||
QueueInstance(instance);
|
QueueInstance(instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ namespace Cryville.Crtr {
|
|||||||
_indexSrc = new PropSrc.Float(() => Index);
|
_indexSrc = new PropSrc.Float(() => Index);
|
||||||
_durationOp = new PropOp.Float(v => _duration = v);
|
_durationOp = new PropOp.Float(v => _duration = v);
|
||||||
}
|
}
|
||||||
public void Rewind(double time) {
|
public void Rewind(double time, Transform target) {
|
||||||
_startTime = time;
|
_startTime = time;
|
||||||
foreach (var i in _comps) i.Rewind(time);
|
foreach (var i in _comps) i.Rewind(time, target);
|
||||||
}
|
}
|
||||||
private float m_index;
|
private float m_index;
|
||||||
public float Index {
|
public float Index {
|
||||||
@@ -38,6 +38,7 @@ namespace Cryville.Crtr {
|
|||||||
_indexSrc.Invalidate();
|
_indexSrc.Invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Transform _currentTarget;
|
||||||
Identifier _currentStateName = Identifier.Empty;
|
Identifier _currentStateName = Identifier.Empty;
|
||||||
EffectState _currentState;
|
EffectState _currentState;
|
||||||
ChartEvent _ctxev;
|
ChartEvent _ctxev;
|
||||||
@@ -54,21 +55,22 @@ namespace Cryville.Crtr {
|
|||||||
public bool CanEmit() {
|
public bool CanEmit() {
|
||||||
return _currentStateName.Key == 0 || _currentState.rewind.Key != 0;
|
return _currentStateName.Key == 0 || _currentState.rewind.Key != 0;
|
||||||
}
|
}
|
||||||
public void OnEmit(double time) {
|
public void OnEmit(double time, Transform target) {
|
||||||
|
_currentTarget = target;
|
||||||
_ctxev = ChartPlayer.etor.ContextEvent;
|
_ctxev = ChartPlayer.etor.ContextEvent;
|
||||||
_ctxstate = ChartPlayer.etor.ContextState;
|
_ctxstate = ChartPlayer.etor.ContextState;
|
||||||
if (_currentStateName.Key == 0) {
|
if (_currentStateName.Key == 0) {
|
||||||
EnterState(_def.init, time, true);
|
EnterState(_def.init, time, _currentTarget, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (_currentState.rewind.Key == 0) throw new InvalidOperationException("Cannot rewind");
|
if (_currentState.rewind.Key == 0) throw new InvalidOperationException("Cannot rewind");
|
||||||
EnterState(_currentState.rewind, time, true);
|
EnterState(_currentState.rewind, time, _currentTarget, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void EnterState(Identifier name, double time, bool emitting) {
|
void EnterState(Identifier name, double time, Transform target, bool emitting) {
|
||||||
_currentStateName = name;
|
_currentStateName = name;
|
||||||
_currentState = _def.states[name];
|
_currentState = _def.states[name];
|
||||||
Rewind(time);
|
Rewind(time, target);
|
||||||
RootTransform.gameObject.SetActive(true);
|
RootTransform.gameObject.SetActive(true);
|
||||||
ChartPlayer.etor.ContextCascadeInsert();
|
ChartPlayer.etor.ContextCascadeInsert();
|
||||||
ChartPlayer.etor.ContextCascadeUpdate(_VAR_EFFECT_INDEX, _indexSrc);
|
ChartPlayer.etor.ContextCascadeUpdate(_VAR_EFFECT_INDEX, _indexSrc);
|
||||||
@@ -87,7 +89,7 @@ namespace Cryville.Crtr {
|
|||||||
else {
|
else {
|
||||||
ChartPlayer.etor.ContextEvent = _ctxev;
|
ChartPlayer.etor.ContextEvent = _ctxev;
|
||||||
ChartPlayer.etor.ContextState = _ctxstate;
|
ChartPlayer.etor.ContextState = _ctxstate;
|
||||||
EnterState(_currentState.next, EndTime, false);
|
EnterState(_currentState.next, EndTime, _currentTarget, false);
|
||||||
ChartPlayer.etor.ContextEvent = null;
|
ChartPlayer.etor.ContextEvent = null;
|
||||||
ChartPlayer.etor.ContextState = null;
|
ChartPlayer.etor.ContextState = null;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
public class EffectManager {
|
public class EffectManager {
|
||||||
@@ -15,6 +16,9 @@ namespace Cryville.Crtr {
|
|||||||
public void Emit(int id, float index) {
|
public void Emit(int id, float index) {
|
||||||
_groups[id].Emit(index);
|
_groups[id].Emit(index);
|
||||||
}
|
}
|
||||||
|
public void EmitSelf(int id, float index, Transform target) {
|
||||||
|
_groups[id].Emit(index, target);
|
||||||
|
}
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
foreach (var g in _groups) g.Value.Dispose();
|
foreach (var g in _groups) g.Value.Dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ namespace Cryville.Crtr {
|
|||||||
if (k.Count != 1) throw new FormatException("Invalid effect name");
|
if (k.Count != 1) throw new FormatException("Invalid effect name");
|
||||||
return new EmitEffect(a, IdentifierManager.SharedInstance.Request(k[0]));
|
return new EmitEffect(a, IdentifierManager.SharedInstance.Request(k[0]));
|
||||||
}
|
}
|
||||||
|
else if (a.Remove("emit_self")) {
|
||||||
|
if (k.Count != 1) throw new FormatException("Invalid effect name");
|
||||||
|
return new EmitEffect(a, IdentifierManager.SharedInstance.Request(k[0]), true);
|
||||||
|
}
|
||||||
else if (a.Remove("var")) {
|
else if (a.Remove("var")) {
|
||||||
if (k.Count != 1) throw new FormatException("Invalid variable name");
|
if (k.Count != 1) throw new FormatException("Invalid variable name");
|
||||||
return new SetVariable(a, IdentifierManager.SharedInstance.Request(k[0]));
|
return new SetVariable(a, IdentifierManager.SharedInstance.Request(k[0]));
|
||||||
@@ -147,12 +151,14 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
public class EmitEffect : SkinPropertyKey {
|
public class EmitEffect : SkinPropertyKey {
|
||||||
public int Name { get; private set; }
|
public int Name { get; private set; }
|
||||||
public EmitEffect(IEnumerable<string> a, int name) : base(a) {
|
public bool IsSelf { get; private set; }
|
||||||
|
public EmitEffect(IEnumerable<string> a, int name, bool isSelf = false) : base(a) {
|
||||||
Name = name;
|
Name = name;
|
||||||
|
IsSelf = isSelf;
|
||||||
_op = new PropOp.Float(v => _index = v);
|
_op = new PropOp.Float(v => _index = v);
|
||||||
}
|
}
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
return string.Format("@emit {0}", IdentifierManager.SharedInstance.Retrieve(Name));
|
return string.Format(IsSelf ? "@emit_self {0}" : "@emit {0}", IdentifierManager.SharedInstance.Retrieve(Name));
|
||||||
}
|
}
|
||||||
public override bool IsValueRequired { get { return true; } }
|
public override bool IsValueRequired { get { return true; } }
|
||||||
public override void ExecuteStatic(ISkinnableGroup group, RuntimeSkinContext ctx, PdtExpression exp, Dictionary<int, SkinVariable> vars) {
|
public override void ExecuteStatic(ISkinnableGroup group, RuntimeSkinContext ctx, PdtExpression exp, Dictionary<int, SkinVariable> vars) {
|
||||||
@@ -162,7 +168,8 @@ namespace Cryville.Crtr {
|
|||||||
readonly PropOp _op;
|
readonly PropOp _op;
|
||||||
public override void ExecuteDynamic(ISkinnableGroup group, RuntimeSkinContext ctx, PdtExpression exp, Dictionary<int, SkinVariable> vars, int dl) {
|
public override void ExecuteDynamic(ISkinnableGroup group, RuntimeSkinContext ctx, PdtExpression exp, Dictionary<int, SkinVariable> vars, int dl) {
|
||||||
ChartPlayer.etor.Evaluate(_op, exp);
|
ChartPlayer.etor.Evaluate(_op, exp);
|
||||||
ChartPlayer.effectManager.Emit(Name, _index);
|
if (IsSelf) ChartPlayer.effectManager.EmitSelf(Name, _index, ctx.WriteTransform);
|
||||||
|
else ChartPlayer.effectManager.Emit(Name, _index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public class SetVariable : SkinPropertyKey {
|
public class SetVariable : SkinPropertyKey {
|
||||||
|
|||||||
Reference in New Issue
Block a user