Browse Source
Added custom property drawer for Variable properties. Updated If, Set Variable, etc. to use new property drawer. Added new Set Save Profile, Save Variable, Load Variable & Delete Save Key commands.master
20 changed files with 355 additions and 179 deletions
@ -1,48 +0,0 @@
|
||||
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(); |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,48 +0,0 @@
|
||||
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,50 @@
|
||||
using UnityEngine; |
||||
using System; |
||||
using System.Collections; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
[CommandInfo("Scripting", |
||||
"Delete Save Key", |
||||
"Deletes a saved value from permanent storage.")] |
||||
[AddComponentMenu("")] |
||||
public class DeleteSaveKey : Command |
||||
{ |
||||
[Tooltip("Name of the saved value. Supports variable substition e.g. \"player_{$PlayerNumber}")] |
||||
public string key = ""; |
||||
|
||||
public override void OnEnter() |
||||
{ |
||||
if (key == "") |
||||
{ |
||||
Continue(); |
||||
return; |
||||
} |
||||
|
||||
FungusScript fungusScript = GetFungusScript(); |
||||
|
||||
// Prepend the current save profile (if any) |
||||
string prefsKey = SetSaveProfile.saveProfile + "_" + fungusScript.SubstituteVariables(key); |
||||
|
||||
PlayerPrefs.DeleteKey(prefsKey); |
||||
|
||||
Continue(); |
||||
} |
||||
|
||||
public override string GetSummary() |
||||
{ |
||||
if (key.Length == 0) |
||||
{ |
||||
return "Error: No stored value key selected"; |
||||
} |
||||
|
||||
return key; |
||||
} |
||||
|
||||
public override Color GetButtonColor() |
||||
{ |
||||
return new Color32(235, 191, 217, 255); |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2 |
||||
guid: e1674366d369d428eac4568d9f0dae19 |
||||
guid: e1205d6641f2146b19d496037f937ba0 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
@ -1,33 +0,0 @@
|
||||
using UnityEngine; |
||||
using System; |
||||
using System.Collections; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
[CommandInfo("Scripting", |
||||
"Load Globals", |
||||
"Loads a set of global variables previously saved using the Save Globals command.")] |
||||
[AddComponentMenu("")] |
||||
public class LoadGlobals : Command |
||||
{ |
||||
[Tooltip("Save Name of saved global variable values")] |
||||
public string saveName = ""; |
||||
|
||||
public override void OnEnter() |
||||
{ |
||||
//GlobalVariables.Load(saveName); |
||||
Continue(); |
||||
} |
||||
|
||||
public override string GetSummary() |
||||
{ |
||||
return saveName; |
||||
} |
||||
|
||||
public override Color GetButtonColor() |
||||
{ |
||||
return new Color32(235, 191, 217, 255); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,97 @@
|
||||
using UnityEngine; |
||||
using System; |
||||
using System.Collections; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
[CommandInfo("Scripting", |
||||
"Load Variable", |
||||
"Loads a saved value and stores it in a Boolean, Integer, Float or String variable. If the key is not found then the variable is not modified.")] |
||||
[AddComponentMenu("")] |
||||
public class LoadVariable : Command |
||||
{ |
||||
[Tooltip("Name of the saved value. Supports variable substition e.g. \"player_{$PlayerNumber}\"")] |
||||
public string key = ""; |
||||
|
||||
[Tooltip("Variable to store the value in.")] |
||||
[VariableProperty(typeof(BooleanVariable), |
||||
typeof(IntegerVariable), |
||||
typeof(FloatVariable), |
||||
typeof(StringVariable))] |
||||
public Variable variable; |
||||
|
||||
public override void OnEnter() |
||||
{ |
||||
if (key == "" || |
||||
variable == null) |
||||
{ |
||||
Continue(); |
||||
return; |
||||
} |
||||
|
||||
FungusScript fungusScript = GetFungusScript(); |
||||
|
||||
// Prepend the current save profile (if any) |
||||
string prefsKey = SetSaveProfile.saveProfile + "_" + fungusScript.SubstituteVariables(key); |
||||
|
||||
System.Type variableType = variable.GetType(); |
||||
|
||||
if (variableType == typeof(BooleanVariable)) |
||||
{ |
||||
BooleanVariable booleanVariable = variable as BooleanVariable; |
||||
if (booleanVariable != null) |
||||
{ |
||||
// PlayerPrefs does not have bool accessors, so just use int |
||||
booleanVariable.value = (PlayerPrefs.GetInt(prefsKey) == 1); |
||||
} |
||||
} |
||||
else if (variableType == typeof(IntegerVariable)) |
||||
{ |
||||
IntegerVariable integerVariable = variable as IntegerVariable; |
||||
if (integerVariable != null) |
||||
{ |
||||
integerVariable.value = PlayerPrefs.GetInt(prefsKey); |
||||
} |
||||
} |
||||
else if (variableType == typeof(FloatVariable)) |
||||
{ |
||||
FloatVariable floatVariable = variable as FloatVariable; |
||||
if (floatVariable != null) |
||||
{ |
||||
floatVariable.value = PlayerPrefs.GetFloat(prefsKey); |
||||
} |
||||
} |
||||
else if (variableType == typeof(StringVariable)) |
||||
{ |
||||
StringVariable stringVariable = variable as StringVariable; |
||||
if (stringVariable != null) |
||||
{ |
||||
stringVariable.value = PlayerPrefs.GetString(prefsKey); |
||||
} |
||||
} |
||||
|
||||
Continue(); |
||||
} |
||||
|
||||
public override string GetSummary() |
||||
{ |
||||
if (key.Length == 0) |
||||
{ |
||||
return "Error: No stored value key selected"; |
||||
} |
||||
|
||||
if (variable == null) |
||||
{ |
||||
return "Error: No variable selected"; |
||||
} |
||||
|
||||
return "'" + key + "' into " + variable.key; |
||||
} |
||||
|
||||
public override Color GetButtonColor() |
||||
{ |
||||
return new Color32(235, 191, 217, 255); |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,33 +0,0 @@
|
||||
using UnityEngine; |
||||
using System; |
||||
using System.Collections; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
[CommandInfo("Scripting", |
||||
"Save Globals", |
||||
"Saves all current global variables to persistent storage. These can be loaded back in again in future using the LoadGlobals command. This provides a basic save game system.")] |
||||
[AddComponentMenu("")] |
||||
public class SaveGlobals : Command |
||||
{ |
||||
[Tooltip("Save Name of saved global variable values")] |
||||
public string saveName = ""; |
||||
|
||||
public override void OnEnter() |
||||
{ |
||||
//GlobalVariables.Save(saveName); |
||||
Continue(); |
||||
} |
||||
|
||||
public override string GetSummary() |
||||
{ |
||||
return saveName; |
||||
} |
||||
|
||||
public override Color GetButtonColor() |
||||
{ |
||||
return new Color32(235, 191, 217, 255); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,99 @@
|
||||
using UnityEngine; |
||||
using System; |
||||
using System.Collections; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
[CommandInfo("Scripting", |
||||
"Save Variable", |
||||
"Save an Boolean, Integer, Float or String variable to persistent storage using a string key. " + |
||||
"The value can be loaded again later using the Load Variable command. You can also " + |
||||
"use the Set Save Profile command to manage separate save profiles for multiple players.")] |
||||
[AddComponentMenu("")] |
||||
public class SaveVariable : Command |
||||
{ |
||||
[Tooltip("Name of the saved value. Supports variable substition e.g. \"player_{$PlayerNumber}")] |
||||
public string key = ""; |
||||
|
||||
[Tooltip("Variable to read the value from. Only Boolean, Integer, Float and String are supported.")] |
||||
[VariableProperty(typeof(BooleanVariable), |
||||
typeof(IntegerVariable), |
||||
typeof(FloatVariable), |
||||
typeof(StringVariable))] |
||||
public Variable variable; |
||||
|
||||
public override void OnEnter() |
||||
{ |
||||
if (key == "" || |
||||
variable == null) |
||||
{ |
||||
Continue(); |
||||
return; |
||||
} |
||||
|
||||
FungusScript fungusScript = GetFungusScript(); |
||||
|
||||
// Prepend the current save profile (if any) |
||||
string prefsKey = SetSaveProfile.saveProfile + "_" + fungusScript.SubstituteVariables(key); |
||||
|
||||
System.Type variableType = variable.GetType(); |
||||
|
||||
if (variableType == typeof(BooleanVariable)) |
||||
{ |
||||
BooleanVariable booleanVariable = variable as BooleanVariable; |
||||
if (booleanVariable != null) |
||||
{ |
||||
// PlayerPrefs does not have bool accessors, so just use int |
||||
PlayerPrefs.SetInt(prefsKey, booleanVariable.value ? 1 : 0); |
||||
} |
||||
} |
||||
else if (variableType == typeof(IntegerVariable)) |
||||
{ |
||||
IntegerVariable integerVariable = variable as IntegerVariable; |
||||
if (integerVariable != null) |
||||
{ |
||||
PlayerPrefs.SetInt(prefsKey, integerVariable.value); |
||||
} |
||||
} |
||||
else if (variableType == typeof(FloatVariable)) |
||||
{ |
||||
FloatVariable floatVariable = variable as FloatVariable; |
||||
if (floatVariable != null) |
||||
{ |
||||
PlayerPrefs.SetFloat(prefsKey, floatVariable.value); |
||||
} |
||||
} |
||||
else if (variableType == typeof(StringVariable)) |
||||
{ |
||||
StringVariable stringVariable = variable as StringVariable; |
||||
if (stringVariable != null) |
||||
{ |
||||
PlayerPrefs.SetString(prefsKey, stringVariable.value); |
||||
} |
||||
} |
||||
|
||||
Continue(); |
||||
} |
||||
|
||||
public override string GetSummary() |
||||
{ |
||||
if (key.Length == 0) |
||||
{ |
||||
return "Error: No stored value key selected"; |
||||
} |
||||
|
||||
if (variable == null) |
||||
{ |
||||
return "Error: No variable selected"; |
||||
} |
||||
|
||||
return variable.key + " into '" + key + "'"; |
||||
} |
||||
|
||||
public override Color GetButtonColor() |
||||
{ |
||||
return new Color32(235, 191, 217, 255); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,39 @@
|
||||
using UnityEngine; |
||||
using System; |
||||
using System.Collections; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
[CommandInfo("Scripting", |
||||
"Set Save Profile", |
||||
"Sets the active profile that the Save Variable and Load Variable commands will use. This is useful to crete multiple player save games. Once set, the profile applies across all Fungus Scripts and will also persist across scene loads.")] |
||||
[AddComponentMenu("")] |
||||
public class SetSaveProfile : Command |
||||
{ |
||||
/** |
||||
* Shared save profile name used by SaveVariable and LoadVariable. |
||||
*/ |
||||
public static string saveProfile = ""; |
||||
|
||||
[Tooltip("Name of save profile to make active.")] |
||||
public string saveProfileName = ""; |
||||
|
||||
public override void OnEnter() |
||||
{ |
||||
saveProfile = saveProfileName; |
||||
|
||||
Continue(); |
||||
} |
||||
|
||||
public override string GetSummary() |
||||
{ |
||||
return saveProfileName; |
||||
} |
||||
|
||||
public override Color GetButtonColor() |
||||
{ |
||||
return new Color32(235, 191, 217, 255); |
||||
} |
||||
} |
||||
|
||||
} |
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 61c5d800d9a7e4e18864b9c00b0b2fe9 |
||||
guid: 9a240aa44597844f89e6d1ba15a96b04 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
Loading…
Reference in new issue