diff --git a/Assets/Fungus/FungusScript/Editor/RandomFloatEditor.cs b/Assets/Fungus/FungusScript/Editor/RandomFloatEditor.cs new file mode 100644 index 00000000..c54cd937 --- /dev/null +++ b/Assets/Fungus/FungusScript/Editor/RandomFloatEditor.cs @@ -0,0 +1,48 @@ +using UnityEditor; +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using System.Reflection; + +namespace Fungus +{ + + [CustomEditor (typeof(RandomFloat))] + public class RandomFloatEditor : CommandEditor + { + protected SerializedProperty variableProp; + protected SerializedProperty minValueProp; + protected SerializedProperty maxValueProp; + + protected virtual void OnEnable() + { + variableProp = serializedObject.FindProperty("variable"); + minValueProp = serializedObject.FindProperty("minValue"); + maxValueProp = serializedObject.FindProperty("maxValue"); + } + + public override void DrawCommandGUI() + { + serializedObject.Update(); + + RandomFloat t = target as RandomFloat; + + FungusScript fungusScript = t.GetFungusScript(); + if (fungusScript == null) + { + return; + } + + VariableEditor.VariableField(variableProp, + new GUIContent("Variable", "Variable to use in operation"), + t.GetFungusScript(), + (v) => (v.GetType() == typeof(FloatVariable))); + + EditorGUILayout.PropertyField(minValueProp); + EditorGUILayout.PropertyField(maxValueProp); + + serializedObject.ApplyModifiedProperties(); + } + } + +} diff --git a/Assets/Fungus/FungusScript/Editor/RandomFloatEditor.cs.meta b/Assets/Fungus/FungusScript/Editor/RandomFloatEditor.cs.meta new file mode 100644 index 00000000..9302a7c4 --- /dev/null +++ b/Assets/Fungus/FungusScript/Editor/RandomFloatEditor.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e1674366d369d428eac4568d9f0dae19 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Fungus/FungusScript/Editor/RandomIntegerEditor.cs b/Assets/Fungus/FungusScript/Editor/RandomIntegerEditor.cs new file mode 100644 index 00000000..0e95cceb --- /dev/null +++ b/Assets/Fungus/FungusScript/Editor/RandomIntegerEditor.cs @@ -0,0 +1,48 @@ +using UnityEditor; +using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using System.Reflection; + +namespace Fungus +{ + + [CustomEditor (typeof(RandomInteger))] + public class RandomIntegerEditor : CommandEditor + { + protected SerializedProperty variableProp; + protected SerializedProperty minValueProp; + protected SerializedProperty maxValueProp; + + protected virtual void OnEnable() + { + variableProp = serializedObject.FindProperty("variable"); + minValueProp = serializedObject.FindProperty("minValue"); + maxValueProp = serializedObject.FindProperty("maxValue"); + } + + public override void DrawCommandGUI() + { + serializedObject.Update(); + + RandomInteger t = target as RandomInteger; + + FungusScript fungusScript = t.GetFungusScript(); + if (fungusScript == null) + { + return; + } + + VariableEditor.VariableField(variableProp, + new GUIContent("Variable", "Variable to use in operation"), + t.GetFungusScript(), + (v) => (v.GetType() == typeof(IntegerVariable))); + + EditorGUILayout.PropertyField(minValueProp); + EditorGUILayout.PropertyField(maxValueProp); + + serializedObject.ApplyModifiedProperties(); + } + } + +} diff --git a/Assets/Fungus/FungusScript/Editor/RandomIntegerEditor.cs.meta b/Assets/Fungus/FungusScript/Editor/RandomIntegerEditor.cs.meta new file mode 100644 index 00000000..3f9c6c91 --- /dev/null +++ b/Assets/Fungus/FungusScript/Editor/RandomIntegerEditor.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 61c5d800d9a7e4e18864b9c00b0b2fe9 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Fungus/FungusScript/Scripts/Commands/RandomFloat.cs b/Assets/Fungus/FungusScript/Scripts/Commands/RandomFloat.cs new file mode 100644 index 00000000..9aa9f904 --- /dev/null +++ b/Assets/Fungus/FungusScript/Scripts/Commands/RandomFloat.cs @@ -0,0 +1,51 @@ +using UnityEngine; +using System.Collections; + +namespace Fungus +{ + [CommandInfo("Scripting", + "Random Float", + "Sets an float variable to a random value in the defined range.")] + public class RandomFloat : Command + { + [Tooltip("The variable whos value will be set")] + public FloatVariable variable; + + [Tooltip("Minimum value for random range")] + public FloatData minValue; + + [Tooltip("Maximum value for random range")] + public FloatData maxValue; + + public override void OnEnter() + { + if (variable != null) + { + variable.Value = Random.Range(minValue.Value, maxValue.Value); + } + + Continue(); + } + + public override string GetSummary() + { + if (variable == null) + { + return "Error: Variable not selected"; + } + + return variable.key; + } + + public override bool HasReference(Variable variable) + { + return (variable == this.variable); + } + + public override Color GetButtonColor() + { + return new Color32(253, 253, 150, 255); + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/FungusScript/Scripts/Commands/RandomFloat.cs.meta b/Assets/Fungus/FungusScript/Scripts/Commands/RandomFloat.cs.meta new file mode 100644 index 00000000..74be332a --- /dev/null +++ b/Assets/Fungus/FungusScript/Scripts/Commands/RandomFloat.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0ce1a662ad70c46f4b2de306ed2627a2 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Fungus/FungusScript/Scripts/Commands/RandomInteger.cs b/Assets/Fungus/FungusScript/Scripts/Commands/RandomInteger.cs new file mode 100644 index 00000000..073114d5 --- /dev/null +++ b/Assets/Fungus/FungusScript/Scripts/Commands/RandomInteger.cs @@ -0,0 +1,51 @@ +using UnityEngine; +using System.Collections; + +namespace Fungus +{ + [CommandInfo("Scripting", + "Random Integer", + "Sets an integer variable to a random value in the defined range.")] + public class RandomInteger : Command + { + [Tooltip("The variable whos value will be set")] + public IntegerVariable variable; + + [Tooltip("Minimum value for random range")] + public IntegerData minValue; + + [Tooltip("Maximum value for random range")] + public IntegerData maxValue; + + public override void OnEnter() + { + if (variable != null) + { + variable.Value = Random.Range(minValue.Value, maxValue.Value); + } + + Continue(); + } + + public override string GetSummary() + { + if (variable == null) + { + return "Error: Variable not selected"; + } + + return variable.key; + } + + public override bool HasReference(Variable variable) + { + return (variable == this.variable); + } + + public override Color GetButtonColor() + { + return new Color32(253, 253, 150, 255); + } + } + +} \ No newline at end of file diff --git a/Assets/Fungus/FungusScript/Scripts/Commands/RandomInteger.cs.meta b/Assets/Fungus/FungusScript/Scripts/Commands/RandomInteger.cs.meta new file mode 100644 index 00000000..6bee06ff --- /dev/null +++ b/Assets/Fungus/FungusScript/Scripts/Commands/RandomInteger.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6af5dac98b0624702b476c1eac319eab +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: