B:BD[
2.8545] → [
2.8545:24694]
∅:D[
2.24694] → [
4.65669:65904]
B:BD[
4.65669] → [
4.65669:65904]
ce]
public IResourceStatLensCreator ResourceLensCreator; // Current/Capacity
public Lens<Transform, int> Create() {
return ResourceLensVisitor.VisitTransform(this);
}
public Lens<Transform, int> CreateSpecific<TResource, TUnitType>()
where TResource : Resource<TUnitType>
where TUnitType : IUnitType {
var resource = new Lens<Transform, TResource>(t => t.GetComponent<TResource>(), (t, r) => t);
var statLens = ResourceLensCreator.Create<TResource, TUnitType>();
var valueLens = new Lens<Unit<TUnitType>, int>(u => u.AsPrimitive(), (u, v) => u = (Unit<TUnitType>)v);
var lens = resource.Compose(statLens).Compose(valueLens);
return lens;
}
}
public interface IContextAccessor
{
public Lens<EffectContext, int> Create();
public Lens<EffectContext, int> CreateSpecific<TResource, TUnitType>() where TResource : Resource<TUnitType> where TUnitType : IUnitType;
}
public class ContextAccessor : IContextAccessor
{
// Resource/UnitType
[SerializeReference, ShowSerializeReference]
public IOpticsVisitor ResourceLensVisitor;
// Register
[SerializeReference, ShowSerializeReference]
public IRegisterTypeLensCreator RegisterTypeLensCreator;
public Lens<EffectContext, int> Create() {
return ResourceLensVisitor.VisitContext(this);
}
public Lens<EffectContext, int> CreateSpecific<TResource, TUnitType>()
where TResource : Resource<TUnitType>
where TUnitType : IUnitType {
var registerLens = RegisterTypeLensCreator.Create<TResource, TUnitType>();
var valueLens = new Lens<Unit<TUnitType>, int>(u => u.AsPrimitive(), (u, v) => u = (Unit<TUnitType>)v);
return registerLens.Compose(valueLens);
}
}
public interface IEffectInputLensCreator
{
public Lens<EffectContext, Unit<TUnitType>> LensContext<TResource, TUnitType>(IRegisterTypeLensCreator register)
where TResource : Resource<TUnitType>
where TUnitType : IUnitType;
public Lens<Transform, Unit<TUnitType>> CreateLensTransform<TResource, TUnitType>(IResourceStatLensCreator stat)
where TResource : Resource<TUnitType>
where TUnitType : IUnitType;
}
public class EffectInputLensCreator : IEffectInputLensCreator
{
public Lens<EffectContext, Unit<TUnitType>> LensContext<TResource, TUnitType>(IRegisterTypeLensCreator register)
where TResource : Resource<TUnitType>
where TUnitType : IUnitType {
return register.Create<TResource, TUnitType>();
}
public Lens<Transform, Unit<TUnitType>> CreateLensTransform<TResource, TUnitType>(IResourceStatLensCreator stat)
where TResource : Resource<TUnitType>
where TUnitType : IUnitType {
var transformLen = new Lens<Transform, TResource>(t => t.GetComponent<TResource>(), (t, r) => t);
var statLens = stat.Create<TResource, TUnitType>();
return transformLen.Compose(statLens);
}
}
public interface IRegisterTypeLensCreator
{
public Lens<EffectContext, Unit<TUnitType>> Create<TResource, TUnitType>()
where TResource : Resource<TUnitType>
where TUnitType : IUnitType;
}
public class CurrentRegisterTypeLensCreator : IRegisterTypeLensCreator
{
public Lens<EffectContext, Unit<TUnitType>> Create<TResource, TUnitType>()
where TResource : Resource<TUnitType>
where TUnitType : IUnitType {
return new Lens<EffectContext, Unit<TUnitType>>(
context => context.GetResource<TResource, TUnitType, Current>(),
(context, v) => {
context.SetResource<TResource, TUnitType, Current>(v);
return context;
}
);
}
}
[Serializable]
public class OpticsTester
{
[SerializeField] Transform _transform;
[SerializeReference, ShowSerializeReference] IPawnAccessor _accessor;
//object BuildResourceLens(Type resourceType) {
// var lensType = typeof(Lens<,>).MakeGenericType(typeof(Transform), resourceType);
// var lensCtor = lensType.GetConstructors().First();
// ParameterExpression t = Expression.Parameter(typeof(Transform), "t");
// Expression call = Expression.Call(t, "GetComponent", new Type[] { resourceType });
// var lambda1 = Expression.Lambda(call, new ParameterExpression[] { t }).Compile();
// ParameterExpression r = Expression.Parameter(resourceType, "r");
// LabelTarget returnTarget = Expression.Label(typeof(Transform));
// var returnExpression = Expression.Return(returnTarget, t, typeof(Transform));
// LabelExpression returnLabel = Expression.Label(returnTarget, t);
// var block = Expression.Block(returnExpression, returnLabel);
// var lambda2 = Expression.Lambda(block, new ParameterExpression[] { t, r, }).Compile();
// var resourceLens = lensCtor.Invoke(new object[] { lambda1, lambda2 });
// return resourceLens;
//}
//object BuildStatLens(Type resourceType, Type unitType) {
// var lensType = typeof(Lens<,>).MakeGenericType(resourceType, unitType);
// var lensCtor = lensType.GetConstructors().First();
// ParameterExpression r = Expression.Parameter(resourceType, "r");
// Expression call = Expression.Call(r, "GetCurrent", Type.EmptyTypes);
// var lambda1 = Expression.Lambda(call, new ParameterExpression[] { r }).Compile();
// ParameterExpression u = Expression.Parameter(unitType, "u");
// LabelTarget returnTarget = Expression.Label(resourceType);
// var returnExpression = Expression.Return(returnTarget, r, resourceType);
// LabelExpression returnLabel = Expression.Label(returnTarget, r);
// var block = Expression.Block(returnExpression, returnLabel);
// var lambda2 = Expression.Lambda(block, new ParameterExpression[] { r, u }).Compile();
// var statLens = lensCtor.Invoke(new object[] { lambda1, lambda2 });
// return statLens;
//}
//object BuildValueLens(Type unitType) {
// var lensType = typeof(Lens<,>).MakeGenericType(unitType, typeof(int));
// var lensCtor = lensType.GetConstructors().First();
// ParameterExpression u = Expression.Parameter(unitType, "u");
// Expression call = Expression.Call(u, "AsPrimitive", Type.EmptyTypes);
// var lambda1 = Expression.Lambda(call, new ParameterExpression[] { u }).Compile();
// ParameterExpression v = Expression.Parameter(typeof(int), "v");
// Expression assignValueExpression = Expression.Assign(u, Expression.ConvertChecked(v, unitType));
// LabelTarget returnTarget = Expression.Label(unitType);
// var returnExpression = Expression.Return(returnTarget, u, unitType);
// LabelExpression returnLabel = Expression.Label(returnTarget, u);
// var block = Expression.Block(assignValueExpression, returnExpression, returnLabel);
// var lambda2 = Expression.Lambda(block, new ParameterExpression[] { u, v }).Compile();
// var valueLens = lensCtor.Invoke(new object[] { lambda1, lambda2 });
// return valueLens;
//}
//object ComposeDynamicLens(object parent, object child, Type TWhole, Type TPart) {
// ParameterExpression whole = Expression.Parameter(TWhole, "whole");
// var parentGet = Expression.Call(Expression.Constant(parent), "Get", Type.EmptyTypes, whole);
// var childGet = Expression.Call(Expression.Constant(child), "Get", Type.EmptyTypes, parentGet);
// var lambda1 = Expression.Lambda(childGet, new ParameterExpression[] { whole }).Compile();
// //(whole, part) => parent.Set(whole, child.Set(parent.Get(whole), part)));
// ParameterExpression part = Expression.Parameter(TPart, "part");
// var childSet = Expression.Call(Expression.Constant(child), "Set", Type.EmptyTypes, parentGet, part);
// var parentSet = Expression.Call(Expression.Constant(parent), "Set", Type.EmptyTypes, whole, childSet);
// var lambda2 = Expression.Lambda(parentSet, new ParameterExpression[] { whole, part }).Compile();
// var composedLensType = typeof(Lens<,>).MakeGenericType(TWhole, TPart);
// var lensCtor = composedLensType.GetConstructors().First();
// var composedLens = lensCtor.Invoke(new object[] { lambda1, lambda2 });
// return composedLens;
//}
Lens<Transform, int> CreateDynamicResourceLens(Type TResource, Type TUnit) {
var lensType = typeof(Lens<,>).MakeGenericType(typeof(Transform), typeof(int));
var lensCtor = lensType.GetConstructors().First();
ParameterExpression t = Expression.Parameter(typeof(Transform), "t");
Expression getResource = Expression.Call(t, "GetComponent", new Type[] { TResource });
Expression getCurrent = Expression.Call(getResource, "GetCurrent", Type.EmptyTypes);
Expression asPrimitive = Expression.Call(getCurrent, "AsPrimitive", Type.EmptyTypes);
var getterLambda = Expression.Lambda(asPrimitive, new ParameterExpression[] { t }).Compile();
ParameterExpression v = Expression.Parameter(typeof(int), "v");
//Expression assignValueExpression = Expression.Assign(getCurrent, Expression.ConvertChecked(v, TUnit));
LabelTarget returnTarget = Expression.Label(typeof(Transform));
var returnExpression = Expression.Return(returnTarget, t, typeof(Transform));
LabelExpression returnLabel = Expression.Label(returnTarget, t);
var block = Expression.Block(
//assignValueExpression,
returnExpression,
returnLabel
);
var setterLambda = Expression.Lambda(block, new ParameterExpression[] { t, v }).Compile();
var resourceLens = lensCtor.Invoke(new object[] { getterLambda, setterLambda });
return (Lens<Transform, int>)resourceLens;
}
public void TestAll() {
var TResource = typeof(GreenTag);
var TUnitInner = TResource.BaseType.GetGenericArguments()[0];
var TUnit = typeof(Unit<>).MakeGenericType(TUnitInner);
//var resource = new Lens<Transform, GreenTag>(t => t.GetComponent<GreenTag>(), (t, r) => t);
//var resource = (Lens<Transform, GreenTag>)BuildResourceLens(TResource);
//var statLens = new Lens<GreenTag, Unit<GreenTagUnit>>(r => r.GetCurrent(), (r, u) => r);
//var statLens = (Lens<GreenTag, Unit<GreenTagUnit>>)BuildStatLens(TResource, TUnit);
//var valueLens = new Lens<Unit<GreenTagUnit>, int>(u => u.AsPrimitive(), (u, v) => u = (Unit<GreenTagUnit>)v);
//var valueLens = (Lens<Unit<GreenTagUnit>, int>)BuildValueLens(TUnit);
//var lens = resource.Compose(statLens).Compose(valueLens);
//var lens = ComposeDynamicLens(resource, statLens, valueLens, typeof(GreenTag), typeof(Unit<GreenTagUnit>));
//var lens = (Lens<Transform, int>)ComposeDynamicLens(ComposeDynamicLens(resource, statLens, typeof(Transform), TUnit), valueLens, typeof(Transform), typeof(int));
var lens = CreateDynamicResourceLens(TResource, TUnit);
Debug.Log(lens.Get(_transform));
}
}
}
namespace Testing.Actions
{
[Serializable]
public class ActionsTester
{
[SerializeField] Weaver _weaver;
[SerializeField] Transform _transform1;
[SerializeField] Transform _transform2;
public void TestAll() {
TestFollowActionConcreteEqual();
TestFollowActionInterfaceEqual();
TestActionInterfaceNotEqual();
TestMoveToActionConcreteEqual();
TestMoveToActionInterfaceEqual();
}
public void TestFollowActionConcreteEqual() {
var testName = System.Reflection.MethodBase.GetCurrentMethod().Name;
var action1 = new FollowAction(_weaver, _transform1);
var action2 = new FollowAction(_weaver, _transform1);
if (action1.IsSimilarAction(action2)) {
Debug.Log($"<color=green>PASSED: {testName}</color>");
}
else {
Debug.Log($"<color=red>FAILED: {testName}</color>");
}
}
public void TestFollowActionInterfaceEqual() {
var testName = System.Reflection.MethodBase.GetCurrentMethod().Name;
IAction action1 = new FollowAction(_weaver, _transform1);
IAction action2 = new FollowAction(_weaver, _transform1);
if (action1.IsSimilarAction(action2)) {
Debug.Log($"<color=green>PASSED: {testName}</color>");
}
else {
Debug.Log($"<color=red>FAILED: {testName}</color>");
}
}
public void TestActionInterfaceNotEqual() {
var testName = System.Reflection.MethodBase.GetCurrentMethod().Name;
IAction action1 = new FollowAction(_weaver, _transform1);
IAction action2 = new MoveToAction(_weaver, _transform1.position);
if (!action1.IsSimilarAction(action2)) {
Debug.Log($"<color=green>PASSED: {testName}</color>");
}
else {
Debug.Log($"<color=red>FAILED: {testName}</color>");
}
}
public void TestMoveToActionConcreteEqual() {
var testName = System.Reflection.MethodBase.GetCurrentMethod().Name;
var action1 = new MoveToAction(_weaver, _transform1.position);
var action2 = new MoveToAction(_weaver, _transform1.position);
if (action1.IsSimilarAction(action2)) {
Debug.Log($"<color=green>PASSED: {testName}</color>");
}
else {
Debug.Log($"<color=red>FAILED: {testName}</color>");
}
}
public void TestMoveToActionInterfaceEqual() {
var testName = System.Reflection.MethodBase.GetCurrentMethod().Name;
IAction action1 = new MoveToAction(_weaver, _transform1.position);
IAction action2 = new MoveToAction(_weaver, _transform1.position);
if (action1.IsSimilarAction(action2)) {
Debug.Log($"<color=green>PASSED: {testName}</color>");
}
else {
Debug.Log($"<color=red>FAILED: {testName}</color>");
}
}
}
}
namespace Testing.TimeDialation
{
public class TimeDialationTester
{
EventAggregator _eventAggregator;
public TimeDialationTester(EventAggregator eventAggregator) {
_eventAggregator = eventAggregator;
}
public void TestAll() {
TestTimeDialationSpeedUp();
TestTimeDialationSpeedDown();
TestTimeDialationSpeedPause();
TestTimeDialationSpeedReset();
}
public void TestTimeDialationSpeedUp() {
var currentTimeScale = Time.timeScale;
var testName = System.Reflection.MethodBase.GetCurrentMethod().Name;
_eventAggregator.OnTimeDilationSpeedUp(this, System.EventArgs.Empty);
if (Time.timeScale > currentTimeScale) {
Debug.Log($"<color=green>PASSED: {testName}</color>");
}
else {
Debug.Log($"<color=red>FAILED: {testName}</color>");
ce]
public IResourceStatLensCreator ResourceLensCreator; // Current/Capacity
[TypeFilter(derivedFrom: typeof(IWatchableResource))]
[SerializeField]
public CareBoo.Serially.SerializableType Watch;
public Lens<Transform, int> Create() {
Type TResource = Watch.Type;
var TUnitInner = TResource.BaseType.GetGenericArguments()[0];
var TUnit = typeof(Unit<>).MakeGenericType(TUnitInner);
MethodInfo mi = typeof(PawnAccessor).GetMethod($"CreateSpecific");
MethodInfo miConstructed = mi.MakeGenericMethod(TResource, TUnitInner);
var lens = miConstructed.Invoke(this, null);
return (Lens<Transform, int>)lens;
//Debug.Log($"{TResource}, {TUnitInner}, {TUnit}, {miConstructed}");
//return ResourceLensVisitor.VisitTransform(this);
}
public Lens<Transform, int> CreateSpecific<TResource, TUnitType>()
where TResource : Resource<TUnitType>
where TUnitType : IUnitType {
var resource = new Lens<Transform, TResource>(t => t.GetComponent<TResource>(), (t, r) => t);
var statLens = ResourceLensCreator.Create<TResource, TUnitType>();
var valueLens = new Lens<Unit<TUnitType>, int>(u => u.AsPrimitive(), (u, v) => u = (Unit<TUnitType>)v);
var lens = resource.Compose(statLens).Compose(valueLens);
return lens;
}
}
public interface IContextAccessor
{
public Lens<EffectContext, int> Create();
public Lens<EffectContext, int> CreateSpecific<TResource, TUnitType>() where TResource : Resource<TUnitType> where TUnitType : IUnitType;
}
public class ContextAccessor : IContextAccessor
{
// Resource/UnitType
[SerializeReference, ShowSerializeReference]
public IOpticsVisitor ResourceLensVisitor;
// Register
[SerializeReference, ShowSerializeReference]
public IRegisterTypeLensCreator RegisterTypeLensCreator;
public Lens<EffectContext, int> Create() {
return ResourceLensVisitor.VisitContext(this);
}
public Lens<EffectContext, int> CreateSpecific<TResource, TUnitType>()
where TResource : Resource<TUnitType>
where TUnitType : IUnitType {
var registerLens = RegisterTypeLensCreator.Create<TResource, TUnitType>();
var valueLens = new Lens<Unit<TUnitType>, int>(u => u.AsPrimitive(), (u, v) => u = (Unit<TUnitType>)v);
return registerLens.Compose(valueLens);
}
}
public interface IEffectInputLensCreator
{
public Lens<EffectContext, Unit<TUnitType>> LensContext<TResource, TUnitType>(IRegisterTypeLensCreator register)
where TResource : Resource<TUnitType>
where TUnitType : IUnitType;
public Lens<Transform, Unit<TUnitType>> CreateLensTransform<TResource, TUnitType>(IResourceStatLensCreator stat)
where TResource : Resource<TUnitType>
where TUnitType : IUnitType;
}
public class EffectInputLensCreator : IEffectInputLensCreator
{
public Lens<EffectContext, Unit<TUnitType>> LensContext<TResource, TUnitType>(IRegisterTypeLensCreator register)
where TResource : Resource<TUnitType>
where TUnitType : IUnitType {
return register.Create<TResource, TUnitType>();
}
public Lens<Transform, Unit<TUnitType>> CreateLensTransform<TResource, TUnitType>(IResourceStatLensCreator stat)
where TResource : Resource<TUnitType>
where TUnitType : IUnitType {
var transformLen = new Lens<Transform, TResource>(t => t.GetComponent<TResource>(), (t, r) => t);
var statLens = stat.Create<TResource, TUnitType>();
return transformLen.Compose(statLens);
}
}
public interface IRegisterTypeLensCreator
{
public Lens<EffectContext, Unit<TUnitType>> Create<TResource, TUnitType>()
where TResource : Resource<TUnitType>
where TUnitType : IUnitType;
}
public class CurrentRegisterTypeLensCreator : IRegisterTypeLensCreator
{
public Lens<EffectContext, Unit<TUnitType>> Create<TResource, TUnitType>()
where TResource : Resource<TUnitType>
where TUnitType : IUnitType {
return new Lens<EffectContext, Unit<TUnitType>>(
context => context.GetResource<TResource, TUnitType, Current>(),
(context, v) => {
context.SetResource<TResource, TUnitType, Current>(v);
return context;
}
);
}
}
[Serializable]
public class OpticsTester
{
[SerializeField] Transform _transform;
[SerializeReference, ShowSerializeReference] IPawnAccessor _accessor;
//object BuildResourceLens(Type resourceType) {
// var lensType = typeof(Lens<,>).MakeGenericType(typeof(Transform), resourceType);
// var lensCtor = lensType.GetConstructors().First();
// ParameterExpression t = Expression.Parameter(typeof(Transform), "t");
// Expression call = Expression.Call(t, "GetComponent", new Type[] { resourceType });
// var lambda1 = Expression.Lambda(call, new ParameterExpression[] { t }).Compile();
// ParameterExpression r = Expression.Parameter(resourceType, "r");
// LabelTarget returnTarget = Expression.Label(typeof(Transform));
// var returnExpression = Expression.Return(returnTarget, t, typeof(Transform));
// LabelExpression returnLabel = Expression.Label(returnTarget, t);
// var block = Expression.Block(returnExpression, returnLabel);
// var lambda2 = Expression.Lambda(block, new ParameterExpression[] { t, r, }).Compile();
// var resourceLens = lensCtor.Invoke(new object[] { lambda1, lambda2 });
// return resourceLens;
//}
//object BuildStatLens(Type resourceType, Type unitType) {
// var lensType = typeof(Lens<,>).MakeGenericType(resourceType, unitType);
// var lensCtor = lensType.GetConstructors().First();
// ParameterExpression r = Expression.Parameter(resourceType, "r");
// Expression call = Expression.Call(r, "GetCurrent", Type.EmptyTypes);
// var lambda1 = Expression.Lambda(call, new ParameterExpression[] { r }).Compile();
// ParameterExpression u = Expression.Parameter(unitType, "u");
// LabelTarget returnTarget = Expression.Label(resourceType);
// var returnExpression = Expression.Return(returnTarget, r, resourceType);
// LabelExpression returnLabel = Expression.Label(returnTarget, r);
// var block = Expression.Block(returnExpression, returnLabel);
// var lambda2 = Expression.Lambda(block, new ParameterExpression[] { r, u }).Compile();
// var statLens = lensCtor.Invoke(new object[] { lambda1, lambda2 });
// return statLens;
//}
//object BuildValueLens(Type unitType) {
// var lensType = typeof(Lens<,>).MakeGenericType(unitType, typeof(int));
// var lensCtor = lensType.GetConstructors().First();
// ParameterExpression u = Expression.Parameter(unitType, "u");
// Expression call = Expression.Call(u, "AsPrimitive", Type.EmptyTypes);
// var lambda1 = Expression.Lambda(call, new ParameterExpression[] { u }).Compile();
// ParameterExpression v = Expression.Parameter(typeof(int), "v");
// Expression assignValueExpression = Expression.Assign(u, Expression.ConvertChecked(v, unitType));
// LabelTarget returnTarget = Expression.Label(unitType);
// var returnExpression = Expression.Return(returnTarget, u, unitType);
// LabelExpression returnLabel = Expression.Label(returnTarget, u);
// var block = Expression.Block(assignValueExpression, returnExpression, returnLabel);
// var lambda2 = Expression.Lambda(block, new ParameterExpression[] { u, v }).Compile();
// var valueLens = lensCtor.Invoke(new object[] { lambda1, lambda2 });
// return valueLens;
//}
//object ComposeDynamicLens(object parent, object child, Type TWhole, Type TPart) {
// ParameterExpression whole = Expression.Parameter(TWhole, "whole");
// var parentGet = Expression.Call(Expression.Constant(parent), "Get", Type.EmptyTypes, whole);
// var childGet = Expression.Call(Expression.Constant(child), "Get", Type.EmptyTypes, parentGet);
// var lambda1 = Expression.Lambda(childGet, new ParameterExpression[] { whole }).Compile();
// //(whole, part) => parent.Set(whole, child.Set(parent.Get(whole), part)));
// ParameterExpression part = Expression.Parameter(TPart, "part");
// var childSet = Expression.Call(Expression.Constant(child), "Set", Type.EmptyTypes, parentGet, part);
// var parentSet = Expression.Call(Expression.Constant(parent), "Set", Type.EmptyTypes, whole, childSet);
// var lambda2 = Expression.Lambda(parentSet, new ParameterExpression[] { whole, part }).Compile();
// var composedLensType = typeof(Lens<,>).MakeGenericType(TWhole, TPart);
// var lensCtor = composedLensType.GetConstructors().First();
// var composedLens = lensCtor.Invoke(new object[] { lambda1, lambda2 });
// return composedLens;
//}
Lens<Transform, int> CreateDynamicResourceLens(Type TResource, Type TUnit) {
var lensType = typeof(Lens<,>).MakeGenericType(typeof(Transform), typeof(int));
var lensCtor = lensType.GetConstructors().First();
ParameterExpression t = Expression.Parameter(typeof(Transform), "t");
Expression getResource = Expression.Call(t, "GetComponent", new Type[] { TResource });
Expression getCurrent = Expression.Call(getResource, "GetCurrent", Type.EmptyTypes);
Expression asPrimitive = Expression.Call(getCurrent, "AsPrimitive", Type.EmptyTypes);
var getterLambda = Expression.Lambda(asPrimitive, new ParameterExpression[] { t }).Compile();
ParameterExpression v = Expression.Parameter(typeof(int), "v");
//Expression assignValueExpression = Expression.Assign(getCurrent, Expression.ConvertChecked(v, TUnit));
LabelTarget returnTarget = Expression.Label(typeof(Transform));
var returnExpression = Expression.Return(returnTarget, t, typeof(Transform));
LabelExpression returnLabel = Expression.Label(returnTarget, t);
var block = Expression.Block(
//assignValueExpression,
returnExpression,
returnLabel
);
var setterLambda = Expression.Lambda(block, new ParameterExpression[] { t, v }).Compile();
var resourceLens = lensCtor.Invoke(new object[] { getterLambda, setterLambda });
return (Lens<Transform, int>)resourceLens;
}
public void TestAll() {
var TResource = typeof(GreenTag);
var TUnitInner = TResource.BaseType.GetGenericArguments()[0];
var TUnit = typeof(Unit<>).MakeGenericType(TUnitInner);
//var resource = new Lens<Transform, GreenTag>(t => t.GetComponent<GreenTag>(), (t, r) => t);
//var resource = (Lens<Transform, GreenTag>)BuildResourceLens(TResource);
//var statLens = new Lens<GreenTag, Unit<GreenTagUnit>>(r => r.GetCurrent(), (r, u) => r);
//var statLens = (Lens<GreenTag, Unit<GreenTagUnit>>)BuildStatLens(TResource, TUnit);
//var valueLens = new Lens<Unit<GreenTagUnit>, int>(u => u.AsPrimitive(), (u, v) => u = (Unit<GreenTagUnit>)v);
//var valueLens = (Lens<Unit<GreenTagUnit>, int>)BuildValueLens(TUnit);
//var lens = resource.Compose(statLens).Compose(valueLens);
//var lens = ComposeDynamicLens(resource, statLens, valueLens, typeof(GreenTag), typeof(Unit<GreenTagUnit>));
//var lens = (Lens<Transform, int>)ComposeDynamicLens(ComposeDynamicLens(resource, statLens, typeof(Transform), TUnit), valueLens, typeof(Transform), typeof(int));
//var lens = CreateDynamicResourceLens(TResource, TUnit);
var lens = _accessor.Create();
Debug.Log(lens.Get(_transform));
}
}
}
namespace Testing.Actions
{
[Serializable]
public class ActionsTester
{
[SerializeField] Weaver _weaver;
[SerializeField] Transform _transform1;
[SerializeField] Transform _transform2;
public void TestAll() {
TestFollowActionConcreteEqual();
TestFollowActionInterfaceEqual();
TestActionInterfaceNotEqual();
TestMoveToActionConcreteEqual();
TestMoveToActionInterfaceEqual();
}
public void TestFollowActionConcreteEqual() {
var testName = System.Reflection.MethodBase.GetCurrentMethod().Name;
var action1 = new FollowAction(_weaver, _transform1);
var action2 = new FollowAction(_weaver, _transform1);
if (action1.IsSimilarAction(action2)) {
Debug.Log($"<color=green>PASSED: {testName}</color>");
}
else {
Debug.Log($"<color=red>FAILED: {testName}</color>");
}
}
public void TestFollowActionInterfaceEqual() {
var testName = System.Reflection.MethodBase.GetCurrentMethod().Name;
IAction action1 = new FollowAction(_weaver, _transform1);
IAction action2 = new FollowAction(_weaver, _transform1);
if (action1.IsSimilarAction(action2)) {
Debug.Log($"<color=green>PASSED: {testName}</color>");
}
else {
Debug.Log($"<color=red>FAILED: {testName}</color>");
}
}
public void TestActionInterfaceNotEqual() {
var testName = System.Reflection.MethodBase.GetCurrentMethod().Name;
IAction action1 = new FollowAction(_weaver, _transform1);
IAction action2 = new MoveToAction(_weaver, _transform1.position);
if (!action1.IsSimilarAction(action2)) {
Debug.Log($"<color=green>PASSED: {testName}</color>");
}
else {
Debug.Log($"<color=red>FAILED: {testName}</color>");
}
}
public void TestMoveToActionConcreteEqual() {
var testName = System.Reflection.MethodBase.GetCurrentMethod().Name;
var action1 = new MoveToAction(_weaver, _transform1.position);
var action2 = new MoveToAction(_weaver, _transform1.position);
if (action1.IsSimilarAction(action2)) {
Debug.Log($"<color=green>PASSED: {testName}</color>");
}
else {
Debug.Log($"<color=red>FAILED: {testName}</color>");
}
}
public void TestMoveToActionInterfaceEqual() {
var testName = System.Reflection.MethodBase.GetCurrentMethod().Name;
IAction action1 = new MoveToAction(_weaver, _transform1.position);
IAction action2 = new MoveToAction(_weaver, _transform1.position);
if (action1.IsSimilarAction(action2)) {
Debug.Log($"<color=green>PASSED: {testName}</color>");
}
else {
Debug.Log($"<color=red>FAILED: {testName}</color>");
}
}
}
}
namespace Testing.TimeDialation
{
public class TimeDialationTester
{
EventAggregator _eventAggregator;
public TimeDialationTester(EventAggregator eventAggregator) {
_eventAggregator = eventAggregator;
}
public void TestAll() {
TestTimeDialationSpeedUp();
TestTimeDialationSpeedDown();
TestTimeDialationSpeedPause();
TestTimeDialationSpeedReset();
}
public void TestTimeDialationSpeedUp() {
var currentTimeScale = Time.timeScale;
var testName = System.Reflection.MethodBase.GetCurrentMethod().Name;
_eventAggregator.OnTimeDilationSpeedUp(this, System.EventArgs.Empty);
if (Time.timeScale > currentTimeScale) {
Debug.Log($"<color=green>PASSED: {testName}</color>");
}
else {
Debug.Log($"<color=red>FAILED: {testName}</color>");