浏览代码

Feature/counters (#9)

* Base work

* Updated Counters + ChangeLog
/main
GitHub 5 年前
当前提交
d8f98e90
共有 11 个文件被更改,包括 494 次插入0 次删除
  1. 3
      CHANGELOG.md
  2. 6
      Icons/Misc/ic-counter.png
  3. 115
      Icons/Misc/ic-counter.png.meta
  4. 8
      Runtime/Ingredients/Counter.meta
  5. 85
      Runtime/Ingredients/Counter/Counter.cs
  6. 11
      Runtime/Ingredients/Counter/Counter.cs.meta
  7. 123
      Runtime/Ingredients/Counter/CounterAction.cs
  8. 11
      Runtime/Ingredients/Counter/CounterAction.cs.meta
  9. 121
      Runtime/Ingredients/Counter/CounterLogic.cs
  10. 11
      Runtime/Ingredients/Counter/CounterLogic.cs.meta

3
CHANGELOG.md


## 2019.3.2
#### Added
- Added Counters : Integer counters stored in the scene
- Added CounterAction and CounterLogic
- Added Create State button to StateMachines
- Added State Machine templates in the GameObject Creation Menu

6
Icons/Misc/ic-counter.png

之前 之后
宽度: 16  |  高度: 16  |  大小: 524 B

115
Icons/Misc/ic-counter.png.meta


fileFormatVersion: 2
guid: e27512d2419d958409c74f73ebab5bb1
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 10
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: 1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: -1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 2
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: PS4
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

8
Runtime/Ingredients/Counter.meta


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

85
Runtime/Ingredients/Counter/Counter.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using NaughtyAttributes;
namespace GameplayIngredients
{
public class Counter : MonoBehaviour
{
public enum ValueSourceType
{
Property,
GlobalVariable,
GameSave,
}
[BoxGroup("Default Value")]
public ValueSourceType ValueSource = ValueSourceType.Property;
[BoxGroup("Default Value"),ShowIf("isValueProperty")]
public int Value = 1;
[BoxGroup("Default Value"), ShowIf("isValueGameSave")]
public string GameSaveVariableName = "Variable";
[BoxGroup("Default Value"), ShowIf("isValueGameSave")]
public GameSaveManager.Location GameSaveLocation = GameSaveManager.Location.System;
[BoxGroup("Default Value"), ShowIf("isValueGlobal")]
public string GlobalVariableName = "Variable";
[BoxGroup("Default Value"), ShowIf("isValueGlobal")]
public Globals.Scope GlobalScope = Globals.Scope.Global;
public int CurrentValue { get; private set; }
[ReorderableList]
public Callable[] OnValueChanged;
bool isValueProperty() { return ValueSource == ValueSourceType.Property; }
bool isValueGameSave() { return ValueSource == ValueSourceType.GameSave; }
bool isValueGlobal() { return ValueSource == ValueSourceType.GlobalVariable; }
void Awake()
{
int value;
switch (ValueSource)
{
default:
case ValueSourceType.Property:
value = Value;
break;
case ValueSourceType.GlobalVariable:
if (Globals.HasInt(GlobalVariableName, GlobalScope))
value = Globals.GetInt(GlobalVariableName, GlobalScope);
else
{
Debug.LogWarning($"CounterLogic ({name}) : Could not find Global integer {GlobalVariableName}({GlobalScope})");
value = 0;
}
break;
case ValueSourceType.GameSave:
var gsm = Manager.Get<GameSaveManager>();
if (gsm.HasInt(GameSaveVariableName, GameSaveLocation))
value = gsm.GetInt(GameSaveVariableName, GameSaveLocation);
else
{
Debug.LogWarning($"CounterLogic ({name}) : Could not find Game Save integer {GameSaveVariableName}({GameSaveLocation})");
value = 0;
}
break;
}
CurrentValue = value;
}
public void SetValue(int newValue, GameObject instigator = null)
{
if(newValue != CurrentValue)
{
CurrentValue = newValue;
Callable.Call(OnValueChanged, instigator);
}
}
}
}

11
Runtime/Ingredients/Counter/Counter.cs.meta


fileFormatVersion: 2
guid: 077e23926c603de49adf6739db6d1532
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: e27512d2419d958409c74f73ebab5bb1, type: 3}
userData:
assetBundleName:
assetBundleVariant:

123
Runtime/Ingredients/Counter/CounterAction.cs


using NaughtyAttributes;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients.Actions
{
public class CounterAction : ActionBase
{
public enum CounterOperation
{
Set,
Add,
Subtract,
Multiply,
Divide,
Modulo
}
public enum ValueSourceType
{
Property,
GlobalVariable,
GameSave,
}
[ReorderableList]
public Counter[] Counters;
public CounterOperation Operation = CounterOperation.Set;
public ValueSourceType ValueSource = ValueSourceType.Property;
[ShowIf("isValueProperty")]
public int Value = 1;
[ShowIf("isValueGameSave")]
public string GameSaveVariableName = "Variable";
[ShowIf("isValueGameSave")]
public GameSaveManager.Location GameSaveLocation = GameSaveManager.Location.System;
[ShowIf("isValueGlobal")]
public string GlobalVariableName = "Variable";
[ShowIf("isValueGlobal")]
public Globals.Scope GlobalScope = Globals.Scope.Global;
bool isValueProperty() { return ValueSource == ValueSourceType.Property; }
bool isValueGameSave() { return ValueSource == ValueSourceType.GameSave; }
bool isValueGlobal() { return ValueSource == ValueSourceType.GlobalVariable; }
public override void Execute(GameObject instigator = null)
{
int value;
switch (ValueSource)
{
default:
case ValueSourceType.Property:
value = Value;
break;
case ValueSourceType.GlobalVariable:
if (Globals.HasInt(GlobalVariableName, GlobalScope))
value = Globals.GetInt(GlobalVariableName, GlobalScope);
else
{
Debug.LogWarning($"CounterAction ({name}) : Could not find Global integer {GlobalVariableName}({GlobalScope})");
value = 0;
}
break;
case ValueSourceType.GameSave:
var gsm = Manager.Get<GameSaveManager>();
if (gsm.HasInt(GameSaveVariableName, GameSaveLocation))
value = gsm.GetInt(GameSaveVariableName, GameSaveLocation);
else
{
Debug.LogWarning($"CounterAction ({name}) : Could not find Game Save integer {GameSaveVariableName}({GameSaveLocation})");
value = 0;
}
break;
}
foreach(var counter in Counters)
{
if (counter == null)
continue;
switch (Operation)
{
default:
case CounterOperation.Set:
break;
case CounterOperation.Add:
value = counter.CurrentValue + value;
break;
case CounterOperation.Subtract:
value = counter.CurrentValue - value;
break;
case CounterOperation.Multiply:
value = counter.CurrentValue * value;
break;
case CounterOperation.Divide:
if (value != 0)
value = counter.CurrentValue / value;
else
{
Debug.LogWarning($"{this.name} : Division by zero");
continue;
}
break;
case CounterOperation.Modulo:
if (value != 0)
value = counter.CurrentValue % value;
else
{
Debug.LogWarning($"{this.name} : Modulo by zero");
continue;
}
break;
}
counter.SetValue(value, instigator);
}
}
}
}

11
Runtime/Ingredients/Counter/CounterAction.cs.meta


fileFormatVersion: 2
guid: ab79e2911fffbfe40b571ae41c8be893
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: e27512d2419d958409c74f73ebab5bb1, type: 3}
userData:
assetBundleName:
assetBundleVariant:

121
Runtime/Ingredients/Counter/CounterLogic.cs


using NaughtyAttributes;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GameplayIngredients.Logic
{
public class CounterLogic : LogicBase
{
public enum ValueSourceType
{
Property,
GlobalVariable,
GameSave,
}
public enum Evaluation
{
Equal,
NotEqual,
Greater,
GreaterOrEqual,
Less,
LessOrEqual
}
[NonNullCheck]
public Counter Counter;
public Evaluation evaluation = Evaluation.Equal;
public ValueSourceType ValueSource = ValueSourceType.Property;
[ShowIf("isValueProperty")]
public int Value = 1;
[ShowIf("isValueGameSave")]
public string GameSaveVariableName = "Variable";
[ShowIf("isValueGameSave")]
public GameSaveManager.Location GameSaveLocation = GameSaveManager.Location.System;
[ShowIf("isValueGlobal")]
public string GlobalVariableName = "Variable";
[ShowIf("isValueGlobal")]
public Globals.Scope GlobalScope = Globals.Scope.Global;
[ReorderableList]
public Callable[] OnTestSuccess;
[ReorderableList]
public Callable[] OnTestFail;
bool isValueProperty() { return ValueSource == ValueSourceType.Property; }
bool isValueGameSave() { return ValueSource == ValueSourceType.GameSave; }
bool isValueGlobal() { return ValueSource == ValueSourceType.GlobalVariable; }
public override void Execute(GameObject instigator = null)
{
int value;
switch (ValueSource)
{
default:
case ValueSourceType.Property:
value = Value;
break;
case ValueSourceType.GlobalVariable:
if (Globals.HasInt(GlobalVariableName, GlobalScope))
value = Globals.GetInt(GlobalVariableName, GlobalScope);
else
{
Debug.LogWarning($"CounterLogic ({name}) : Could not find Global integer {GlobalVariableName}({GlobalScope})");
value = 0;
}
break;
case ValueSourceType.GameSave:
var gsm = Manager.Get<GameSaveManager>();
if (gsm.HasInt(GameSaveVariableName, GameSaveLocation))
value = gsm.GetInt(GameSaveVariableName, GameSaveLocation);
else
{
Debug.LogWarning($"CounterLogic ({name}) : Could not find Game Save integer {GameSaveVariableName}({GameSaveLocation})");
value = 0;
}
break;
}
bool test = false;
switch (evaluation)
{
case Evaluation.Equal:
test = Counter.CurrentValue == value;
break;
case Evaluation.NotEqual:
test = Counter.CurrentValue != value;
break;
case Evaluation.Greater:
test = Counter.CurrentValue > value;
break;
case Evaluation.GreaterOrEqual:
test = Counter.CurrentValue >= value;
break;
case Evaluation.Less:
test = Counter.CurrentValue < value;
break;
case Evaluation.LessOrEqual:
test = Counter.CurrentValue <= value;
break;
default:
break;
}
if (test)
Callable.Call(OnTestSuccess, instigator);
else
Callable.Call(OnTestFail, instigator);
}
}
}

11
Runtime/Ingredients/Counter/CounterLogic.cs.meta


fileFormatVersion: 2
guid: 45c9a74f9a6dea7498f1b76c297ea5be
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: e27512d2419d958409c74f73ebab5bb1, type: 3}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存