123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- using System;
- using UnityEngine;
- using Object = System.Object;
- namespace UnityTest
- {
- public abstract class ComparerBase : ActionBase
- {
- public enum CompareToType
- {
- CompareToObject,
- CompareToConstantValue,
- CompareToNull
- }
- public CompareToType compareToType = CompareToType.CompareToObject;
- public GameObject other;
- public string otherPropertyPath = "";
-
- protected abstract bool Compare (object a, object b);
- protected override bool Compare(object objVal)
- {
- object objOtherVal;
- if (compareToType == CompareToType.CompareToConstantValue)
- {
- objOtherVal = ConstValue;
- }
- else if (compareToType == CompareToType.CompareToNull)
- {
- objOtherVal = null;
- }
- else
- {
- if (other == null)
- objOtherVal = null;
- else
- objOtherVal = GetPropertyValue (other,
- otherPropertyPath,
- GetAccepatbleTypesForB ());
- }
- return Compare (objVal,
- objOtherVal);
- }
- public virtual Type[] GetAccepatbleTypesForB()
- {
- return null;
- }
- #region Const value
- public virtual object ConstValue { get; set; }
- public virtual object GetDefaultConstValue()
- {
- throw new NotImplementedException();
- }
- #endregion
- public virtual Type GetSecondParameterType() { return typeof(object); }
- public object GetOtherPropertyValue ()
- {
- switch (compareToType)
- {
- case CompareToType.CompareToObject:
- return PropertyResolver.GetPropertyValueFromString(other,
- otherPropertyPath);
- case CompareToType.CompareToConstantValue:
- return ConstValue;
- case CompareToType.CompareToNull:
- default:
- return null;
- }
- }
- }
- [Serializable]
- public abstract class ComparerBaseGeneric<T> : ComparerBaseGeneric<T,T>
- {
- }
- [Serializable]
- public abstract class ComparerBaseGeneric<T1, T2> : ComparerBase
- {
- public T2 constantValueGeneric = default(T2);
- public override Object ConstValue
- {
- get
- {
- return constantValueGeneric;
- }
- set
- {
- constantValueGeneric = (T2) value;
- }
- }
- public override Object GetDefaultConstValue()
- {
- return default(T2);
- }
- protected override bool Compare(object a, object b)
- {
- var type = typeof(T2);
- if (b == null && type.IsValueType)
- {
- throw new ArgumentException("Null was passed to a value-type argument");
- }
- return Compare((T1)a, (T2)b);
- }
- protected abstract bool Compare(T1 a, T2 b);
- public override Type[] GetAccepatbleTypesForA()
- {
- return new[] { typeof(T1) };
- }
- public override Type[] GetAccepatbleTypesForB ()
- {
- return new[] {typeof (T2)};
- }
- public override Type GetParameterType()
- {
- return typeof(T1);
- }
- public override Type GetSecondParameterType()
- {
- return typeof(T2);
- }
- }
- }
|