@ -9,6 +9,23 @@ namespace Fungus.Script
[CustomEditor (typeof(SetVariable))]
[CustomEditor (typeof(SetVariable))]
public class SetVariableEditor : FungusCommandEditor
public class SetVariableEditor : FungusCommandEditor
{
{
SerializedProperty variableProp ;
SerializedProperty setOperatorProp ;
SerializedProperty booleanDataProp ;
SerializedProperty integerDataProp ;
SerializedProperty floatDataProp ;
SerializedProperty stringDataProp ;
void OnEnable ( )
{
variableProp = serializedObject . FindProperty ( "variable" ) ;
setOperatorProp = serializedObject . FindProperty ( "setOperator" ) ;
booleanDataProp = serializedObject . FindProperty ( "booleanData" ) ;
integerDataProp = serializedObject . FindProperty ( "integerData" ) ;
floatDataProp = serializedObject . FindProperty ( "floatData" ) ;
stringDataProp = serializedObject . FindProperty ( "stringData" ) ;
}
public override void DrawCommandGUI ( )
public override void DrawCommandGUI ( )
{
{
serializedObject . Update ( ) ;
serializedObject . Update ( ) ;
@ -21,29 +38,28 @@ namespace Fungus.Script
return ;
return ;
}
}
FungusVariable variable = FungusVariable Editor . VariableField ( new GUIContent ( "Variable" , "Variable to set" ) ,
FungusVariableEditor . VariableField ( variableProp ,
fungusScript ,
new GUIContent ( "Variable" , "Variable to set" ) ,
t . variable ) ;
fungusScript ) ;
if ( variable ! = t . variable )
{
Undo . RecordObject ( t , "Set Variable Key" ) ;
t . variable = variable ;
}
if ( t . variabl e = = null )
if ( variableProp . objectReferenceValue = = null )
{
{
serializedObject . ApplyModifiedProperties ( ) ;
return ;
return ;
}
}
FungusVariable selectedVariable = variableProp . objectReferenceValue as FungusVariable ;
System . Type variableType = selectedVariable . GetType ( ) ;
List < GUIContent > operatorsList = new List < GUIContent > ( ) ;
List < GUIContent > operatorsList = new List < GUIContent > ( ) ;
operatorsList . Add ( new GUIContent ( "=" ) ) ;
operatorsList . Add ( new GUIContent ( "=" ) ) ;
if ( variable . GetType ( ) = = typeof ( BooleanVariable ) )
if ( variableType = = typeof ( BooleanVariable ) )
{
{
operatorsList . Add ( new GUIContent ( "!" ) ) ;
operatorsList . Add ( new GUIContent ( "!" ) ) ;
}
}
else if ( variable . Get Type( ) = = typeof ( IntegerVariable ) | |
else if ( variableType = = typeof ( IntegerVariable ) | |
variable . Get Type( ) = = typeof ( FloatVariable ) )
variableType = = typeof ( FloatVariable ) )
{
{
operatorsList . Add ( new GUIContent ( "+=" ) ) ;
operatorsList . Add ( new GUIContent ( "+=" ) ) ;
operatorsList . Add ( new GUIContent ( "-=" ) ) ;
operatorsList . Add ( new GUIContent ( "-=" ) ) ;
@ -78,8 +94,8 @@ namespace Fungus.Script
selectedIndex = EditorGUILayout . Popup ( new GUIContent ( "Operator" , "Arithmetic operator to use" ) , selectedIndex , operatorsList . ToArray ( ) ) ;
selectedIndex = EditorGUILayout . Popup ( new GUIContent ( "Operator" , "Arithmetic operator to use" ) , selectedIndex , operatorsList . ToArray ( ) ) ;
SetVariable . SetOperator setOperator = SetVariable . SetOperator . Assign ;
SetVariable . SetOperator setOperator = SetVariable . SetOperator . Assign ;
if ( variable . Get Type( ) = = typeof ( BooleanVariable ) | |
if ( variableType = = typeof ( BooleanVariable ) | |
variable . Get Type( ) = = typeof ( StringVariable ) )
variableType = = typeof ( StringVariable ) )
{
{
switch ( selectedIndex )
switch ( selectedIndex )
{
{
@ -92,8 +108,8 @@ namespace Fungus.Script
break ;
break ;
}
}
}
}
else if ( variable . Get Type( ) = = typeof ( IntegerVariable ) | |
else if ( variableType = = typeof ( IntegerVariable ) | |
variable . Get Type( ) = = typeof ( FloatVariable ) )
variableType = = typeof ( FloatVariable ) )
{
{
switch ( selectedIndex )
switch ( selectedIndex )
{
{
@ -116,27 +132,23 @@ namespace Fungus.Script
}
}
}
}
if ( setOperator ! = t . setOperator )
setOperatorProp . enumValueIndex = ( int ) setOperator ;
{
Undo . RecordObject ( t , "Set Operator" ) ;
t . setOperator = setOperator ;
}
if ( variable . Get Type( ) = = typeof ( BooleanVariable ) )
if ( variableType = = typeof ( BooleanVariable ) )
{
{
EditorGUILayout . PropertyField ( serializedObject . FindProperty ( "booleanData" ) ) ;
EditorGUILayout . PropertyField ( booleanDataProp ) ;
}
}
else if ( variable . Get Type( ) = = typeof ( IntegerVariable ) )
else if ( variableType = = typeof ( IntegerVariable ) )
{
{
EditorGUILayout . PropertyField ( serializedObject . FindProperty ( "integerData" ) ) ;
EditorGUILayout . PropertyField ( integerDataProp ) ;
}
}
else if ( variable . Get Type( ) = = typeof ( FloatVariable ) )
else if ( variableType = = typeof ( FloatVariable ) )
{
{
EditorGUILayout . PropertyField ( serializedObject . FindProperty ( "floatData" ) ) ;
EditorGUILayout . PropertyField ( floatDataProp ) ;
}
}
else if ( variable . Get Type( ) = = typeof ( StringVariable ) )
else if ( variableType = = typeof ( StringVariable ) )
{
{
EditorGUILayout . PropertyField ( serializedObject . FindProperty ( "stringData" ) ) ;
EditorGUILayout . PropertyField ( stringDataProp ) ;
}
}
serializedObject . ApplyModifiedProperties ( ) ;
serializedObject . ApplyModifiedProperties ( ) ;