浏览代码

Added Globals

/main
Thomas ICHÉ 5 年前
当前提交
31a1ce73
共有 12 个文件被更改,包括 535 次插入0 次删除
  1. 5
      CHANGELOG.md
  2. 1
      Runtime/Managers/Implementations/GameManager.cs
  3. 8
      Runtime/Managers/Globals.meta
  4. 250
      Runtime/Managers/Globals/Globals.cs
  5. 11
      Runtime/Managers/Globals/Globals.cs.meta
  6. 148
      Runtime/Managers/Globals/OnGlobalLogic.cs
  7. 11
      Runtime/Managers/Globals/OnGlobalLogic.cs.meta
  8. 25
      Runtime/Managers/Globals/ResetGlobalAction.cs
  9. 11
      Runtime/Managers/Globals/ResetGlobalAction.cs.meta
  10. 54
      Runtime/Managers/Globals/SetGlobalAction.cs
  11. 11
      Runtime/Managers/Globals/SetGlobalAction.cs.meta

5
CHANGELOG.md


* Added Timer Component
* Added TimerAction to control Timer
* Added TimerDisplayRig
* Added Global Variables (Globals + Local Scope)
* Added Global Variable Set Action
* Added Global Variable Logic
* Added Global Variables Reset Action
- GameManager Resets Global Variables Local Scope on Level Load
#### Fixed

1
Runtime/Managers/Implementations/GameManager.cs


if (m_CurrentLevelSwitch == null)
{
var call = GetCurrentLevelSwitch(nextLevel, showUI, onComplete);
Globals.ResetLocals();
call.Execute();
currentLevel = nextLevel;

8
Runtime/Managers/Globals.meta


fileFormatVersion: 2
guid: dd67ebd332bbf1d46af6bd1930423da1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

250
Runtime/Managers/Globals/Globals.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class Globals
{
static Dictionary<string, bool> globalBooleans;
static Dictionary<string, int> globalInts;
static Dictionary<string, string> globalStrings;
static Dictionary<string, float> globalFloats;
static Dictionary<string, GameObject> globalObjects;
static Dictionary<string, bool> localBooleans;
static Dictionary<string, int> localInts;
static Dictionary<string, string> localStrings;
static Dictionary<string, float> localFloats;
static Dictionary<string, GameObject> localObjects;
public enum Scope
{
Local,
Global
}
public enum Type
{
Boolean,
Integer,
String,
Float,
GameObject
}
static Globals()
{
globalBooleans = new Dictionary<string, bool>();
globalInts = new Dictionary<string, int>();
globalStrings = new Dictionary<string, string>();
globalFloats = new Dictionary<string, float>();
globalObjects = new Dictionary<string, GameObject>();
localBooleans = new Dictionary<string, bool>();
localInts = new Dictionary<string, int>();
localStrings = new Dictionary<string, string>();
localFloats = new Dictionary<string, float>();
localObjects = new Dictionary<string, GameObject>();
}
public static void ResetLocals()
{
localBooleans.Clear();
localInts.Clear();
localStrings.Clear();
localFloats.Clear();
localObjects.Clear();
}
public static void ResetGlobals()
{
globalBooleans.Clear();
globalInts.Clear();
globalStrings.Clear();
globalFloats.Clear();
globalObjects.Clear();
}
#region Has()
public static bool HasBool(string name, Scope scope)
{
switch (scope)
{
default:
case Scope.Local:
return localBooleans.ContainsKey(name);
case Scope.Global:
return globalBooleans.ContainsKey(name);
}
}
public static bool HasInt(string name, Scope scope)
{
switch (scope)
{
default:
case Scope.Local:
return localInts.ContainsKey(name);
case Scope.Global:
return globalInts.ContainsKey(name);
}
}
public static bool HasString(string name, Scope scope)
{
switch (scope)
{
default:
case Scope.Local:
return localStrings.ContainsKey(name);
case Scope.Global:
return globalStrings.ContainsKey(name);
}
}
public static bool HasFloat(string name, Scope scope)
{
switch (scope)
{
default:
case Scope.Local:
return localFloats.ContainsKey(name);
case Scope.Global:
return globalFloats.ContainsKey(name);
}
}
public static bool HasObject(string name, Scope scope)
{
switch (scope)
{
default:
case Scope.Local:
return localObjects.ContainsKey(name);
case Scope.Global:
return globalObjects.ContainsKey(name);
}
}
#endregion
#region Get()
public static bool GetBool(string name, Scope scope)
{
switch (scope)
{
default:
case Scope.Local:
return localBooleans[name];
case Scope.Global:
return globalBooleans[name];
}
}
public static int GetInt(string name, Scope scope)
{
switch (scope)
{
default:
case Scope.Local:
return localInts[name];
case Scope.Global:
return globalInts[name];
}
}
public static string GetString(string name, Scope scope)
{
switch (scope)
{
default:
case Scope.Local:
return localStrings[name];
case Scope.Global:
return globalStrings[name];
}
}
public static float GetFloat(string name, Scope scope)
{
switch (scope)
{
default:
case Scope.Local:
return localFloats[name];
case Scope.Global:
return globalFloats[name];
}
}
public static bool GetObject(string name, Scope scope)
{
switch (scope)
{
default:
case Scope.Local:
return localObjects[name];
case Scope.Global:
return globalObjects[name];
}
}
#endregion
#region Set()
static void SetValue<T>(Dictionary<string, T> dict, string name, T value)
{
if (dict.ContainsKey(name))
dict[name] = value;
else
dict.Add(name, value);
}
public static void SetBool(string name, bool value, Scope scope)
{
switch (scope)
{
default:
case Scope.Local:
SetValue(localBooleans, name, value); return;
case Scope.Global:
SetValue(globalBooleans, name, value); return;
}
}
public static void SetInt(string name, int value, Scope scope)
{
switch (scope)
{
default:
case Scope.Local:
SetValue(localInts, name, value); return;
case Scope.Global:
SetValue(globalInts, name, value); return;
}
}
public static void SetString(string name, string value, Scope scope)
{
switch (scope)
{
default:
case Scope.Local:
SetValue(localStrings, name, value); return;
case Scope.Global:
SetValue(globalStrings, name, value); return;
}
}
public static void SetFloat(string name, float value, Scope scope)
{
switch (scope)
{
default:
case Scope.Local:
SetValue(localFloats, name, value); return;
case Scope.Global:
SetValue(globalFloats, name, value); return;
}
}
public static void SetObject(string name, GameObject value, Scope scope)
{
switch (scope)
{
default:
case Scope.Local:
SetValue(localObjects, name, value); return;
case Scope.Global:
SetValue(globalObjects, name, value); return;
}
}
#endregion
}

11
Runtime/Managers/Globals/Globals.cs.meta


fileFormatVersion: 2
guid: e66f575592d1e4a4d8d48b182204a4ac
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

148
Runtime/Managers/Globals/OnGlobalLogic.cs


using NaughtyAttributes;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients.Logic
{
public class OnGlobalLogic : LogicBase
{
public Globals.Scope scope = Globals.Scope.Global;
public Globals.Type type = Globals.Type.Boolean;
public string Variable = "SomeVariable";
public Evaluation evaluation = Evaluation.Equal;
[ShowIf("isBool")]
public bool boolValue = true;
[ShowIf("isInt")]
public int intValue = 1;
[ShowIf("isString")]
public string stringValue = "Value";
[ShowIf("isFloat")]
public float floatValue = 1.0f;
[ShowIf("isGameObject")]
public GameObject gameObjectValue;
public enum Evaluation
{
Equal,
NotEqual,
Greater,
GreaterOrEqual,
Less,
LessOrEqual,
Exists
}
bool isBool() { return type == Globals.Type.Boolean; }
bool isInt() { return type == Globals.Type.Integer; }
bool isFloat() { return type == Globals.Type.Float; }
bool isString() { return type == Globals.Type.String; }
bool isGameObject() { return type == Globals.Type.GameObject; }
[ReorderableList]
public Callable[] OnTestSuccess;
[ReorderableList]
public Callable[] OnTestFail;
public override void Execute(GameObject instigator = null)
{
bool result = false;
if (evaluation == Evaluation.Exists)
{
switch (type)
{
case Globals.Type.Boolean: result = Globals.HasBool(Variable, scope); break;
case Globals.Type.Float: result = Globals.HasFloat(Variable, scope); break;
case Globals.Type.Integer: result = Globals.HasInt(Variable, scope); break;
case Globals.Type.String: result = Globals.HasString(Variable, scope); break;
}
}
else
{
switch (type)
{
case Globals.Type.Boolean:
if (!Globals.HasBool(Variable, scope))
{
WarnNotExist(Variable, type, scope);
}
else
{
result = TestValue(Globals.GetBool(Variable, scope), boolValue);
}
break;
case Globals.Type.Integer:
if (!Globals.HasInt(Variable, scope))
{
WarnNotExist(Variable, type, scope);
}
else
{
result = TestValue(Globals.GetInt(Variable, scope), intValue);
}
break;
case Globals.Type.Float:
if (!Globals.HasFloat(Variable, scope))
{
WarnNotExist(Variable, type, scope);
}
else
{
result = TestValue(Globals.GetFloat(Variable, scope), floatValue);
}
break;
case Globals.Type.String:
if (!Globals.HasString(Variable, scope))
{
WarnNotExist(Variable, type, scope);
}
else
{
result = TestValue(Globals.GetString(Variable, scope), stringValue);
}
break;
case Globals.Type.GameObject:
if (!Globals.HasObject(Variable, scope))
{
WarnNotExist(Variable, type, scope);
}
else
{
result = TestValue(Globals.GetObject(Variable, scope), gameObjectValue);
}
break;
}
}
if (result)
Callable.Call(OnTestSuccess, instigator);
else
Callable.Call(OnTestFail, instigator);
}
bool TestValue<T>(T value, T other) where T : System.IComparable<T>
{
switch (evaluation)
{
case Evaluation.Equal: return value.CompareTo(other) == 0;
case Evaluation.NotEqual: return value.CompareTo(other) != 0;
case Evaluation.Greater: return value.CompareTo(other) > 0;
case Evaluation.GreaterOrEqual: return value.CompareTo(other) >= 0;
case Evaluation.Less: return value.CompareTo(other) < 0;
case Evaluation.LessOrEqual: return value.CompareTo(other) <= 0;
}
return false;
}
void WarnNotExist(string name,Globals.Type type, Globals.Scope location)
{
Debug.LogWarning(string.Format("Save Data Logic: Trying to get {0} value to non existent {1} data in {2} save.", type, name, location));
}
}
}

11
Runtime/Managers/Globals/OnGlobalLogic.cs.meta


fileFormatVersion: 2
guid: dfb539acc174ff046a34b6bee7ad48de
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

25
Runtime/Managers/Globals/ResetGlobalAction.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients.Actions
{
public class ResetGlobalAction : ActionBase
{
public ResetType resetType = ResetType.Locals;
public enum ResetType
{
Locals = 1,
Globals = 2,
All = Locals | Globals,
}
public override void Execute(GameObject instigator = null)
{
if (resetType == ResetType.Locals || resetType == ResetType.All)
Globals.ResetLocals();
if (resetType == ResetType.Globals || resetType == ResetType.All)
Globals.ResetGlobals();
}
}
}

11
Runtime/Managers/Globals/ResetGlobalAction.cs.meta


fileFormatVersion: 2
guid: 99d0858ab4f2a4b408c989c71c3d9083
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

54
Runtime/Managers/Globals/SetGlobalAction.cs


using NaughtyAttributes;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients.Actions
{
public class SetGlobalAction : ActionBase
{
public Globals.Scope scope = Globals.Scope.Global;
public Globals.Type type = Globals.Type.Boolean;
public string Variable = "SomeVariable";
[ShowIf("isBool")]
public bool boolValue = true;
[ShowIf("isInt")]
public int intValue = 1;
[ShowIf("isString")]
public string stringValue = "Value";
[ShowIf("isFloat")]
public float floatValue = 1.0f;
[ShowIf("isGameObject")]
public GameObject gameObjectValue;
bool isBool() { return type == Globals.Type.Boolean; }
bool isInt() { return type == Globals.Type.Integer; }
bool isFloat() { return type == Globals.Type.Float; }
bool isString() { return type == Globals.Type.String; }
bool isGameObject() { return type == Globals.Type.GameObject; }
public override void Execute(GameObject instigator = null)
{
switch (type)
{
default:
case Globals.Type.Boolean:
Globals.SetBool(Variable, boolValue, scope);
break;
case Globals.Type.Integer:
Globals.SetInt(Variable, intValue, scope);
break;
case Globals.Type.String:
Globals.SetString(Variable, stringValue, scope);
break;
case Globals.Type.Float:
Globals.SetFloat(Variable, floatValue, scope);
break;
case Globals.Type.GameObject:
Globals.SetObject(Variable, gameObjectValue, scope);
break;
}
}
}
}

11
Runtime/Managers/Globals/SetGlobalAction.cs.meta


fileFormatVersion: 2
guid: b74e258e1b854de4db77e924a4a2e459
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存