Browse Source

Added RandomInt and RandomFloat commands

master
chrisgregan 10 years ago
parent
commit
ca575dd4bc
  1. 48
      Assets/Fungus/FungusScript/Editor/RandomFloatEditor.cs
  2. 8
      Assets/Fungus/FungusScript/Editor/RandomFloatEditor.cs.meta
  3. 48
      Assets/Fungus/FungusScript/Editor/RandomIntegerEditor.cs
  4. 8
      Assets/Fungus/FungusScript/Editor/RandomIntegerEditor.cs.meta
  5. 51
      Assets/Fungus/FungusScript/Scripts/Commands/RandomFloat.cs
  6. 8
      Assets/Fungus/FungusScript/Scripts/Commands/RandomFloat.cs.meta
  7. 51
      Assets/Fungus/FungusScript/Scripts/Commands/RandomInteger.cs
  8. 8
      Assets/Fungus/FungusScript/Scripts/Commands/RandomInteger.cs.meta

48
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();
}
}
}

8
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:

48
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();
}
}
}

8
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:

51
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);
}
}
}

8
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:

51
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);
}
}
}

8
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:
Loading…
Cancel
Save