/// <summary> /// Sets the level (above threshold : remap one, under threshold : remap zero) /// </summary> /// <param name="receiver"></param> /// <param name="property"></param> /// <param name="level"></param> public override void SetLevel(MMPropertyReceiver receiver, MMProperty property, float level) { base.SetLevel(receiver, property, level); _newValue = (level > receiver.Threshold) ? receiver.StringRemapOne : receiver.StringRemapZero; SetValueOptimized(property, _newValue); }
/// <summary> /// Returns this property link's level between 0 and 1 /// </summary> /// <param name="receiver"></param> /// <param name="property"></param> /// <param name="level"></param> /// <returns></returns> public override float GetLevel(MMPropertyEmitter emitter, MMProperty property) { _vector2 = _getterSetterInitialized ? GetVector2Delegate() : (Vector2)GetPropertyValue(property); float newValue = 0f; switch (emitter.Vector2Option) { case MMPropertyEmitter.Vector2Options.X: newValue = _vector2.x; break; case MMPropertyEmitter.Vector2Options.Y: newValue = _vector2.y; break; } float returnValue = newValue; returnValue = MMMaths.Clamp(returnValue, emitter.FloatRemapMinToZero, emitter.FloatRemapMaxToOne, emitter.ClampMin, emitter.ClampMax); returnValue = MMMaths.Remap(returnValue, emitter.FloatRemapMinToZero, emitter.FloatRemapMaxToOne, 0f, 1f); emitter.Level = returnValue; return(returnValue); }
/// <summary> /// Returns this property link's level between 0 and 1 /// </summary> /// <param name="receiver"></param> /// <param name="property"></param> /// <param name="level"></param> /// <returns></returns> public override float GetLevel(MMPropertyEmitter emitter, MMProperty property) { float axisValue = 0f; Quaternion propertyQuaternion = GetValueOptimized(property); switch (emitter.Vector3Option) { case MMPropertyEmitter.Vector3Options.X: axisValue = propertyQuaternion.eulerAngles.x; break; case MMPropertyEmitter.Vector3Options.Y: axisValue = propertyQuaternion.eulerAngles.y; break; case MMPropertyEmitter.Vector3Options.Z: axisValue = propertyQuaternion.eulerAngles.z; break; } axisValue = MMMaths.Clamp(axisValue, emitter.QuaternionRemapMinToZero, emitter.QuaternionRemapMaxToOne, emitter.ClampMin, emitter.ClampMax); float returnValue = MMMaths.Remap(axisValue, emitter.QuaternionRemapMinToZero, emitter.QuaternionRemapMaxToOne, 0f, 1f); emitter.Level = returnValue; return(returnValue); }
/// <summary> /// Returns this property link's level between 0 and 1 /// </summary> /// <param name="receiver"></param> /// <param name="property"></param> /// <param name="level"></param> /// <returns></returns> public override float GetLevel(MMPropertyEmitter emitter, MMProperty property) { _vector3 = GetValueOptimized(property); float newValue = 0f; switch (emitter.Vector3Option) { case MMPropertyEmitter.Vector3Options.X: newValue = _vector3.x; break; case MMPropertyEmitter.Vector3Options.Y: newValue = _vector3.y; break; case MMPropertyEmitter.Vector3Options.Z: newValue = _vector3.z; break; } float returnValue = newValue; returnValue = MMMaths.Clamp(returnValue, emitter.FloatRemapMinToZero, emitter.FloatRemapMaxToOne, emitter.ClampMin, emitter.ClampMax); returnValue = MMMaths.Remap(returnValue, emitter.FloatRemapMinToZero, emitter.FloatRemapMaxToOne, 0f, 1f); emitter.Level = returnValue; return(returnValue); }
/// <summary> /// Sets the level, based on remap zero and remap one, angles in degree /// </summary> /// <param name="receiver"></param> /// <param name="property"></param> /// <param name="level"></param> public override void SetLevel(MMPropertyReceiver receiver, MMProperty property, float level) { base.SetLevel(receiver, property, level); _newValue = (receiver.RelativeValue) ? _initialValue : Quaternion.identity; if (receiver.ModifyX) { float newX = MMMaths.Remap(level, 0f, 1f, receiver.QuaternionRemapZero.x, receiver.QuaternionRemapOne.x); _newValue = _newValue * Quaternion.AngleAxis(newX, Vector3.right); } if (receiver.ModifyY) { float newY = MMMaths.Remap(level, 0f, 1f, receiver.QuaternionRemapZero.y, receiver.QuaternionRemapOne.y); _newValue = _newValue * Quaternion.AngleAxis(newY, Vector3.up); } if (receiver.ModifyZ) { float newZ = MMMaths.Remap(level, 0f, 1f, receiver.QuaternionRemapZero.z, receiver.QuaternionRemapOne.z); _newValue = _newValue * Quaternion.AngleAxis(newZ, Vector3.forward); } SetValueOptimized(property, _newValue); }
/// <summary> /// Returns this property link's level between 0 and 1 /// </summary> /// <param name="receiver"></param> /// <param name="property"></param> /// <param name="level"></param> /// <returns></returns> public override float GetLevel(MMPropertyEmitter emitter, MMProperty property) { bool boolValue = GetValueOptimized(property); float returnValue = (boolValue == true) ? emitter.BoolRemapTrue : emitter.BoolRemapFalse; emitter.Level = returnValue; return(returnValue); }
/// <summary> /// Returns this property link's level between 0 and 1 /// </summary> /// <param name="receiver"></param> /// <param name="property"></param> /// <param name="level"></param> /// <returns></returns> public override float GetLevel(MMPropertyEmitter emitter, MMProperty property) { float returnValue = GetValueOptimized(property); returnValue = MMMaths.Clamp(returnValue, emitter.IntRemapMinToZero, emitter.IntRemapMaxToOne, emitter.ClampMin, emitter.ClampMax); returnValue = MMMaths.Remap(returnValue, emitter.IntRemapMinToZero, emitter.IntRemapMaxToOne, 0f, 1f); emitter.Level = returnValue; return(returnValue); }
/// <summary> /// Sets either the cached value or the raw value /// </summary> /// <param name="property"></param> /// <param name="newValue"></param> protected virtual void SetValueOptimized(MMProperty property, int newValue) { if (_getterSetterInitialized) { SetIntDelegate(_newValue); } else { SetPropertyValue(property, _newValue); } }
/// <summary> /// Sets the value of the selected property /// </summary> /// <param name="newValue"></param> protected virtual void SetPropertyValue(MMProperty property, object newValue) { object target = (property.TargetScriptableObject == null) ? (object)property.TargetComponent : (object)property.TargetScriptableObject; if (property.MemberType == MMProperty.MemberTypes.Property) { property.MemberPropertyInfo.SetValue(target, newValue); } else if (property.MemberType == MMProperty.MemberTypes.Field) { property.MemberFieldInfo.SetValue(target, newValue); } }
/// <summary> /// Sets the specified level /// </summary> /// <param name="receiver"></param> /// <param name="property"></param> /// <param name="level"></param> public override void SetLevel(MMPropertyReceiver receiver, MMProperty property, float level) { base.SetLevel(receiver, property, level); _newValue = (int)MMMaths.Remap(level, 0f, 1f, receiver.IntRemapZero, receiver.IntRemapOne); if (receiver.RelativeValue) { _newValue = _initialValue + _newValue; } SetValueOptimized(property, _newValue); }
/// <summary> /// Sets the level, lerping between ColorRemapZero and One /// </summary> /// <param name="receiver"></param> /// <param name="property"></param> /// <param name="level"></param> public override void SetLevel(MMPropertyReceiver receiver, MMProperty property, float level) { base.SetLevel(receiver, property, level); _newValue = Color.LerpUnclamped(receiver.ColorRemapZero, receiver.ColorRemapOne, level); if (receiver.RelativeValue) { _newValue = _initialValue + _newValue; } SetValueOptimized(property, _newValue); }
/// <summary> /// Returns the value of the selected property /// </summary> /// <returns></returns> protected virtual object GetPropertyValue(MMProperty property) { object target = (property.TargetScriptableObject == null) ? (object)property.TargetComponent : (object)property.TargetScriptableObject; if (property.MemberType == MMProperty.MemberTypes.Property) { return(property.MemberPropertyInfo.GetValue(target)); } else if (property.MemberType == MMProperty.MemberTypes.Field) { return(property.MemberFieldInfo.GetValue(target)); } return(0f); }
/// <summary> /// Sets the level /// </summary> /// <param name="receiver"></param> /// <param name="property"></param> /// <param name="level"></param> public override void SetLevel(MMPropertyReceiver receiver, MMProperty property, float level) { base.SetLevel(receiver, property, level); _newValue.x = receiver.ModifyX ? MMMaths.Remap(level, 0f, 1f, receiver.Vector3RemapZero.x, receiver.Vector3RemapOne.x) : 0f; _newValue.y = receiver.ModifyY ? MMMaths.Remap(level, 0f, 1f, receiver.Vector3RemapZero.y, receiver.Vector3RemapOne.y) : 0f; _newValue.z = receiver.ModifyZ ? MMMaths.Remap(level, 0f, 1f, receiver.Vector3RemapZero.z, receiver.Vector3RemapOne.z) : 0f; if (receiver.RelativeValue) { _newValue = _initialValue + _newValue; } SetValueOptimized(property, _newValue); }
protected virtual Type GetPropertyType(SerializedProperty property) { if (_selectedPropertyIndex == 0) { return(null); } MMProperty tempProperty; tempProperty = MMProperty.FindProperty(_propertiesList[_selectedPropertyIndex], property.FindPropertyRelative("TargetComponent").objectReferenceValue as Component, null, property.FindPropertyRelative("TargetObject").objectReferenceValue as ScriptableObject); if (tempProperty != null) { return(tempProperty.PropertyType); } else { return(null); } }
/// <summary> /// Sets the specified level /// </summary> /// <param name="receiver"></param> /// <param name="property"></param> /// <param name="level"></param> public override void SetLevel(MMPropertyReceiver receiver, MMProperty property, float level) { base.SetLevel(receiver, property, level); _newValue.x = receiver.ModifyX ? MMMaths.Remap(level, 0f, 1f, receiver.Vector2RemapZero.x, receiver.Vector2RemapOne.x) : 0f; _newValue.y = receiver.ModifyY ? MMMaths.Remap(level, 0f, 1f, receiver.Vector2RemapZero.y, receiver.Vector2RemapOne.y) : 0f; if (receiver.RelativeValue) { _newValue = _initialValue + _newValue; } if (_getterSetterInitialized) { SetVector2Delegate(_newValue); } else { SetPropertyValue(property, _newValue); } }
/// <summary> /// Creates cached getter and setters for properties /// </summary> /// <param name="property"></param> public override void CreateGettersAndSetters(MMProperty property) { base.CreateGettersAndSetters(property); if (property.MemberType == MMProperty.MemberTypes.Property) { object firstArgument = (property.TargetScriptableObject == null) ? (object)property.TargetComponent : (object)property.TargetScriptableObject; if (property.MemberPropertyInfo.GetGetMethod() != null) { GetVector3Delegate = (Func <Vector3>)Delegate.CreateDelegate(typeof(Func <Vector3>), firstArgument, property.MemberPropertyInfo.GetGetMethod()); } if (property.MemberPropertyInfo.GetSetMethod() != null) { SetVector3Delegate = (Action <Vector3>)Delegate.CreateDelegate(typeof(Action <Vector3>), firstArgument, property.MemberPropertyInfo.GetSetMethod()); } _getterSetterInitialized = true; } }
/// <summary> /// A method used to cache getter and setter for properties, not fields (sadly) /// </summary> /// <param name="property"></param> public virtual void CreateGettersAndSetters(MMProperty property) { }
/// <summary> /// Gets either the cached value or the raw value /// </summary> /// <param name="property"></param> /// <returns></returns> protected virtual string GetValueOptimized(MMProperty property) { return(_getterSetterInitialized ? GetStringDelegate() : (string)GetPropertyValue(property)); }
/// <summary> /// Gets either the cached value or the raw value /// </summary> /// <param name="property"></param> /// <returns></returns> protected virtual int GetValueOptimized(MMProperty property) { return(_getterSetterInitialized ? GetIntDelegate() : (int)GetPropertyValue(property)); }
/// <summary> /// Gets either the cached value or the raw value /// </summary> /// <param name="property"></param> /// <returns></returns> protected virtual bool GetValueOptimized(MMProperty property) { return(_getterSetterInitialized ? GetBoolDelegate() : (bool)GetPropertyValue(property)); }
/// <summary> /// When the property picker gets initialized, it grabs the stored property or field /// and initializes a MMProperty and MMPropertyLink /// </summary> /// <param name="source"></param> public virtual void Initialization(GameObject source) { if ((TargetComponent == null) && (TargetScriptableObject == null)) { PropertyFound = false; return; } _targetMMProperty = MMProperty.FindProperty(TargetPropertyName, TargetComponent, source, TargetScriptableObject); if (_targetMMProperty == null) { PropertyFound = false; return; } if ((_targetMMProperty.TargetComponent == null) && (_targetMMProperty.TargetScriptableObject == null)) { PropertyFound = false; return; } if ((_targetMMProperty.MemberPropertyInfo == null) && (_targetMMProperty.MemberFieldInfo == null)) { PropertyFound = false; return; } PropertyFound = true; _initialized = true; // if succession because pattern matching isn't supported before C# 7 if (_targetMMProperty.PropertyType == typeof(string)) { _propertySetter = new MMPropertyLinkString(); _propertySetter.Initialization(_targetMMProperty); return; } if (_targetMMProperty.PropertyType == typeof(float)) { _propertySetter = new MMPropertyLinkFloat(); _propertySetter.Initialization(_targetMMProperty); return; } if (_targetMMProperty.PropertyType == typeof(Vector2)) { _propertySetter = new MMPropertyLinkVector2(); _propertySetter.Initialization(_targetMMProperty); return; } if (_targetMMProperty.PropertyType == typeof(Vector3)) { _propertySetter = new MMPropertyLinkVector3(); _propertySetter.Initialization(_targetMMProperty); return; } if (_targetMMProperty.PropertyType == typeof(Vector4)) { _propertySetter = new MMPropertyLinkVector4(); _propertySetter.Initialization(_targetMMProperty); return; } if (_targetMMProperty.PropertyType == typeof(Quaternion)) { _propertySetter = new MMPropertyLinkQuaternion(); _propertySetter.Initialization(_targetMMProperty); return; } if (_targetMMProperty.PropertyType == typeof(int)) { _propertySetter = new MMPropertyLinkInt(); _propertySetter.Initialization(_targetMMProperty); return; } if (_targetMMProperty.PropertyType == typeof(bool)) { _propertySetter = new MMPropertyLinkBool(); _propertySetter.Initialization(_targetMMProperty); return; } if (_targetMMProperty.PropertyType == typeof(Color)) { _propertySetter = new MMPropertyLinkColor(); _propertySetter.Initialization(_targetMMProperty); return; } }
/// <summary> /// Sets the raw property value, float normalized, caching the operation if possible /// </summary> /// <param name="receiver"></param> /// <param name="property"></param> /// <param name="level"></param> public virtual void SetValue(MMPropertyReceiver receiver, MMProperty property, object newValue) { }
/// <summary> /// Gets the raw value of the property, a normalized float value, caching the operation if possible /// </summary> /// <param name="emitter"></param> /// <param name="property"></param> /// <returns></returns> public virtual object GetValue(MMPropertyEmitter emitter, MMProperty property) { return(0f); }
/// <summary> /// Gets either the cached value or the raw value /// </summary> /// <param name="property"></param> /// <returns></returns> protected virtual Vector3 GetValueOptimized(MMProperty property) { return(_getterSetterInitialized ? GetVector3Delegate() : (Vector3)GetPropertyValue(property)); }
/// <summary> /// Sets the raw property value, float normalized, caching the operation if possible /// </summary> /// <param name="receiver"></param> /// <param name="property"></param> /// <param name="level"></param> public override void SetValue(MMPropertyReceiver receiver, MMProperty property, object newValue) { SetValueOptimized(property, (int)newValue); }
/// <summary> /// On init we grab our initial value /// </summary> /// <param name="property"></param> public override void Initialization(MMProperty property) { base.Initialization(property); _initialValue = (int)GetPropertyValue(property); }
/// <summary> /// Gets the raw value of the property, a normalized float value, caching the operation if possible /// </summary> /// <param name="emitter"></param> /// <param name="property"></param> /// <returns></returns> public override object GetValue(MMPropertyEmitter emitter, MMProperty property) { return(GetValueOptimized(property)); }
/// <summary> /// Gets the "level" of the property, a normalized float value, caching the operation if possible /// </summary> /// <param name="emitter"></param> /// <param name="property"></param> /// <returns></returns> public virtual float GetLevel(MMPropertyEmitter emitter, MMProperty property) { return(0f); }
/// <summary> /// Initialization method /// </summary> /// <param name="property"></param> public virtual void Initialization(MMProperty property) { CreateGettersAndSetters(property); }
/// <summary> /// Sets the property's level, float normalized, caching the operation if possible /// </summary> /// <param name="receiver"></param> /// <param name="property"></param> /// <param name="level"></param> public virtual void SetLevel(MMPropertyReceiver receiver, MMProperty property, float level) { receiver.Level = level; }