FRVariables & FRAttributes

You are here:
  • Main
  • API
  • FRVariables & FRAttributes
< All Topics
Table of Contents

FRFloatRange

Draws a float slider with custom min, max values instead of a float field.

//
[FRFloatRange(0f, 10f)]
public FRFloat myFloat;
//

FRIntRange

Draws an int slider with custom min, max values instead of a int field.

//
[FRIntRange(0f, 10f)]
public FRInt myInt;
//

Draw methods

FRVariable class has two Draw methods for drawing the actual variable ui element.

// used to draw variable in inspector
public virtual void Draw(bool _allowSceneObject, object[] _attributes){}
// used to draw variable in blackboard list
public virtual void Draw(Rect rect){}

FRFloat example of drawing the float field. The additional _attributes parameter can be used for passing custom field attributes. FRFloatRange is a custom attribute which enables the drawing of a gui slider instead of a float field.

public override void Draw(bool _allowSceneObject, object[] _attributes)
{
			#if UNITY_EDITOR

			if (_attributes != null)
			{
				var _att = _attributes.FirstOrDefault(x => x.GetType() == typeof(FRFloatRange));
				
				if (_att != null)
				{
					var _a = _att as FRFloatRange;
					Value = EditorGUILayout.Slider(Value, _a.min, _a.max);
				}
				else
				{
					Value = EditorGUILayout.FloatField(Value);	
				}
			}
			else
			{
				Value = EditorGUILayout.FloatField(Value);	
			}
			#endif
}
		
public override void Draw(Rect _rect)
{
	#if UNITY_EDITOR
	Value = EditorGUI.FloatField(_rect, Value);
	#endif
}

Custom attributes

FlowReactor supports custom FRVariable attributes. This can be quite handy if you want to create your own custom GUI drawing like a custom slider, button or dropdown. See the FRFloatRange attribute for example.

The custom attribute is being passed to the Draw method of a FRVariable.

Example custom FRAttribute:


[System.AttributeUsage(System.AttributeTargets.Field)]
public class FRFloatRange : Attribute
{
	public float min;
	public float max;
		
	public FRFloatRange (float _min, float _max)
	{
		min = _min;
		max = _max;
	}
}

Attribute can be used like this:

//
[FRFloatRange(0f, 10f)]
public FRFloat myFloat;
//
Privacy Settings
We use cookies to enhance your experience while using our website. If you are using our Services via a browser you can restrict, block or remove cookies through your web browser settings. We also use content and scripts from third parties that may use tracking technologies. You can selectively provide your consent below to allow such third party embeds. For complete information about the cookies we use, data we collect and how we process them, please check our Privacy Policy
Youtube
Consent to display content from Youtube
Vimeo
Consent to display content from Vimeo
Google Maps
Consent to display content from Google