chrisgregan
10 years ago
8 changed files with 230 additions and 0 deletions
@ -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(); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: e1674366d369d428eac4568d9f0dae19 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -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(); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 61c5d800d9a7e4e18864b9c00b0b2fe9 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -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); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 0ce1a662ad70c46f4b2de306ed2627a2 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -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); |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue