diff --git a/Assembly-CSharp.csproj b/Assembly-CSharp.csproj index 336c28d..2974fcd 100644 --- a/Assembly-CSharp.csproj +++ b/Assembly-CSharp.csproj @@ -51,15 +51,16 @@ - + + diff --git a/Assets/IsoTools/Examples/Scenes/Scene07.unity b/Assets/IsoTools/Examples/Scenes/Scene07.unity index 886be9b..322f4d7 100644 --- a/Assets/IsoTools/Examples/Scenes/Scene07.unity +++ b/Assets/IsoTools/Examples/Scenes/Scene07.unity @@ -102,7 +102,7 @@ Prefab: objectReference: {fileID: 0} - target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2} propertyPath: m_LocalPosition.z - value: 1.4000001 + value: 5 objectReference: {fileID: 0} - target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2} propertyPath: m_LocalRotation.x @@ -179,7 +179,7 @@ MonoBehaviour: _tileRatio: 0.5 _tileAngle: 45 _tileHeight: 16 - _stepDepth: 0.1 + _stepDepth: 1 _startDepth: 1 --- !u!81 &600542279 AudioListener: @@ -676,6 +676,7 @@ MonoBehaviour: colorIndex: 0 actionData: actionNames: + - IsoTools.PlayMaker.Actions.IsoSetWorldProps - IsoTools.PlayMaker.Actions.IsoSetMode - IsoTools.PlayMaker.Actions.IsoSetPosition - HutongGames.PlayMaker.Actions.Wait @@ -683,13 +684,22 @@ MonoBehaviour: - - - - actionEnabled: 010101 - actionIsOpen: 010101 - actionStartIndex: 00000000020000000a000000 - actionHashCodes: 672cde03ac9f610448c01101 + - + actionEnabled: 01010101 + actionIsOpen: 01010101 + actionStartIndex: 00000000070000000900000011000000 + actionHashCodes: 7607ca02672cde03ac9f610448c01101 unityObjectParams: [] fsmGameObjectParams: [] fsmOwnerDefaultParams: + - ownerOption: 1 + gameObject: + useVariable: 0 + name: + tooltip: + showInInspector: 0 + networkSync: 0 + value: {fileID: 600542277} - ownerOption: 0 gameObject: useVariable: 0 @@ -725,6 +735,42 @@ MonoBehaviour: enumName: IsoTools.IsoObject+Mode intValue: 1 fsmFloatParams: + - useVariable: 1 + name: + tooltip: + showInInspector: 0 + networkSync: 0 + value: 32 + - useVariable: 1 + name: + tooltip: + showInInspector: 0 + networkSync: 0 + value: 1 + - useVariable: 1 + name: + tooltip: + showInInspector: 0 + networkSync: 0 + value: 90.58 + - useVariable: 1 + name: + tooltip: + showInInspector: 0 + networkSync: 0 + value: 0 + - useVariable: 1 + name: + tooltip: + showInInspector: 0 + networkSync: 0 + value: 0 + - useVariable: 1 + name: + tooltip: + showInInspector: 0 + networkSync: 0 + value: 6.1 - useVariable: 0 name: tooltip: @@ -769,9 +815,16 @@ MonoBehaviour: arrayParamTypes: [] customTypeSizes: customTypeNames: [] - paramDataType: 140000002a000000140000001c0000000f0000000f0000000f0000000100000001000000010000000f0000001700000001000000 + paramDataType: 140000000f0000000f0000000f0000000f0000000f0000000f000000140000002a000000140000001c0000000f0000000f0000000f0000000100000001000000010000000f0000001700000001000000 paramName: - gameObject + - tileSize + - tileRatio + - tileAngle + - tileHeight + - stepDepth + - startDepth + - gameObject - mode - gameObject - vector @@ -784,8 +837,8 @@ MonoBehaviour: - time - finishEvent - realTime - paramDataPos: 00000000000000000100000000000000000000000100000002000000000000000100000002000000030000000000000003000000 - paramByteDataSize: 00000000000000000000000000000000000000000000000000000000010000000100000001000000000000000000000001000000 + paramDataPos: 0000000000000000010000000200000003000000040000000500000001000000000000000200000000000000060000000700000008000000000000000100000002000000090000000000000003000000 + paramByteDataSize: 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000100000001000000000000000000000001000000 events: - name: FINISHED isSystemEvent: 1 @@ -894,7 +947,7 @@ Prefab: objectReference: {fileID: 0} - target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2} propertyPath: m_LocalPosition.z - value: 1.3000001 + value: 4 objectReference: {fileID: 0} - target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2} propertyPath: m_LocalRotation.x @@ -952,7 +1005,7 @@ Prefab: objectReference: {fileID: 0} - target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2} propertyPath: m_LocalPosition.z - value: 1.2 + value: 3 objectReference: {fileID: 0} - target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2} propertyPath: m_LocalRotation.x @@ -1111,7 +1164,7 @@ Prefab: objectReference: {fileID: 0} - target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2} propertyPath: m_LocalPosition.z - value: 1.1 + value: 2 objectReference: {fileID: 0} - target: {fileID: 453404, guid: d10e5320df9f84d4186bda0ba98db9ff, type: 2} propertyPath: m_LocalRotation.x diff --git a/Assets/IsoTools/PlayMaker/Actions/IsoChangeWorld.cs b/Assets/IsoTools/PlayMaker/Actions/IsoChangeWorld.cs deleted file mode 100644 index 11bdbb8..0000000 --- a/Assets/IsoTools/PlayMaker/Actions/IsoChangeWorld.cs +++ /dev/null @@ -1,54 +0,0 @@ -using UnityEngine; -using HutongGames.PlayMaker; - -namespace IsoTools.PlayMaker.Actions { - [ActionCategory("IsoTools")] - [HutongGames.PlayMaker.Tooltip("Change IsoWorld options.")] - public class IsoChangeWorld : FsmStateAction { - - public FsmFloat tileSize; - public FsmFloat tileRatio; - public FsmFloat tileAngle; - public FsmFloat tileHeight; - public FsmFloat stepDepth; - public FsmFloat startDepth; - - public override void Reset() { - tileSize = new FsmFloat{UseVariable = true}; - tileRatio = new FsmFloat{UseVariable = true}; - tileAngle = new FsmFloat{UseVariable = true}; - tileHeight = new FsmFloat{UseVariable = true}; - stepDepth = new FsmFloat{UseVariable = true}; - startDepth = new FsmFloat{UseVariable = true}; - } - - public override void OnEnter() { - DoAction(); - Finish(); - } - - void DoAction() { - var iso_world = GameObject.FindObjectOfType(); - if ( iso_world ) { - if ( !tileSize.IsNone ) { - iso_world.tileSize = tileSize.Value; - } - if ( !tileRatio.IsNone ) { - iso_world.tileRatio = tileRatio.Value; - } - if ( !tileAngle.IsNone ) { - iso_world.tileAngle = tileAngle.Value; - } - if ( !tileHeight.IsNone ) { - iso_world.tileHeight = tileHeight.Value; - } - if ( !stepDepth.IsNone ) { - iso_world.stepDepth = stepDepth.Value; - } - if ( !startDepth.IsNone ) { - iso_world.startDepth = startDepth.Value; - } - } - } - } -} // IsoTools.PlayMaker.Actions \ No newline at end of file diff --git a/Assets/IsoTools/PlayMaker/Actions/IsoComponentAction.cs b/Assets/IsoTools/PlayMaker/Actions/IsoComponentAction.cs index dd9384c..056cf48 100644 --- a/Assets/IsoTools/PlayMaker/Actions/IsoComponentAction.cs +++ b/Assets/IsoTools/PlayMaker/Actions/IsoComponentAction.cs @@ -45,5 +45,15 @@ namespace IsoTools.PlayMaker.Actions { } return _cachedComponent != null; } + + protected bool IsErrorVarClamp(float v, float min, float max) { + return v < min || v > max; + } + + protected string ErrorVarClampMsg(string name, float min, float max) { + return string.Format( + "{0} must be greater than {1} and less than {2}", + name, min, max); + } } } // IsoTools.PlayMaker.Actions \ No newline at end of file diff --git a/Assets/IsoTools/PlayMaker/Actions/IsoGetWorldProps.cs b/Assets/IsoTools/PlayMaker/Actions/IsoGetWorldProps.cs new file mode 100644 index 0000000..bdddc0b --- /dev/null +++ b/Assets/IsoTools/PlayMaker/Actions/IsoGetWorldProps.cs @@ -0,0 +1,67 @@ +using UnityEngine; +using HutongGames.PlayMaker; + +namespace IsoTools.PlayMaker.Actions { + [ActionCategory("IsoTools")] + [HutongGames.PlayMaker.Tooltip( + "Gets an options of a IsoWorld.")] + public class IsoGetWorldProps : IsoComponentAction { + [RequiredField] + [CheckForComponent(typeof(IsoWorld))] + public FsmOwnerDefault gameObject; + + [UIHint(UIHint.Variable)] + public FsmFloat tileSize; + + [UIHint(UIHint.Variable)] + public FsmFloat tileRatio; + + [UIHint(UIHint.Variable)] + public FsmFloat tileAngle; + + [UIHint(UIHint.Variable)] + public FsmFloat tileHeight; + + [UIHint(UIHint.Variable)] + public FsmFloat stepDepth; + + [UIHint(UIHint.Variable)] + public FsmFloat startDepth; + + public bool everyFrame; + + public override void Reset() { + gameObject = null; + tileSize = null; + tileRatio = null; + tileAngle = null; + tileHeight = null; + stepDepth = null; + startDepth = null; + everyFrame = false; + } + + public override void OnEnter() { + DoAction(); + if ( !everyFrame ) { + Finish(); + } + } + + public override void OnUpdate() { + DoAction(); + } + + void DoAction() { + var go = Fsm.GetOwnerDefaultTarget(gameObject); + if ( UpdateCache(go) ) { + tileSize.Value = isoWorld.tileSize; + tileRatio.Value = isoWorld.tileRatio; + tileAngle.Value = isoWorld.tileAngle; + tileHeight.Value = isoWorld.tileHeight; + stepDepth.Value = isoWorld.stepDepth; + startDepth.Value = isoWorld.startDepth; + } + } + } +} // IsoTools.PlayMaker.Actions \ No newline at end of file diff --git a/Assets/IsoTools/PlayMaker/Actions/IsoGetWorldProps.cs.meta b/Assets/IsoTools/PlayMaker/Actions/IsoGetWorldProps.cs.meta new file mode 100644 index 0000000..f9652f1 --- /dev/null +++ b/Assets/IsoTools/PlayMaker/Actions/IsoGetWorldProps.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 571909e63f3954244b08fd7338e68605 +timeCreated: 1450110259 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/IsoTools/PlayMaker/Actions/IsoSetWorldProps.cs b/Assets/IsoTools/PlayMaker/Actions/IsoSetWorldProps.cs new file mode 100644 index 0000000..afa67cc --- /dev/null +++ b/Assets/IsoTools/PlayMaker/Actions/IsoSetWorldProps.cs @@ -0,0 +1,70 @@ +using UnityEngine; +using HutongGames.PlayMaker; + +namespace IsoTools.PlayMaker.Actions { + [ActionCategory("IsoTools")] + [HutongGames.PlayMaker.Tooltip( + "Sets an options of a IsoWorld.")] + public class IsoSetWorldProps : IsoComponentAction { + [RequiredField] + [CheckForComponent(typeof(IsoWorld))] + [HutongGames.PlayMaker.Tooltip("The IsoWorld to props.")] + public FsmOwnerDefault gameObject; + + public FsmFloat tileSize; + public FsmFloat tileRatio; + public FsmFloat tileAngle; + public FsmFloat tileHeight; + public FsmFloat stepDepth; + public FsmFloat startDepth; + + public override void Reset() { + gameObject = null; + tileSize = new FsmFloat{UseVariable = true}; + tileRatio = new FsmFloat{UseVariable = true}; + tileAngle = new FsmFloat{UseVariable = true}; + tileHeight = new FsmFloat{UseVariable = true}; + stepDepth = new FsmFloat{UseVariable = true}; + startDepth = new FsmFloat{UseVariable = true}; + } + + public override string ErrorCheck() { + if ( !tileSize.IsNone && IsErrorVarClamp(tileSize.Value, IsoWorld.MinTileSize, IsoWorld.MaxTileSize) ) { + return ErrorVarClampMsg("TileSize", IsoWorld.MinTileSize, IsoWorld.MaxTileSize); + } + if ( !tileRatio.IsNone && IsErrorVarClamp(tileRatio.Value, IsoWorld.MinTileRatio, IsoWorld.MaxTileRatio) ) { + return ErrorVarClampMsg("TileRation", IsoWorld.MinTileRatio, IsoWorld.MaxTileRatio); + } + if ( !tileAngle.IsNone && IsErrorVarClamp(tileAngle.Value, IsoWorld.MinTileAngle, IsoWorld.MaxTileAngle)) { + return ErrorVarClampMsg("TileAngle", IsoWorld.MinTileAngle, IsoWorld.MaxTileAngle); + } + if ( !tileHeight.IsNone && IsErrorVarClamp(tileHeight.Value, IsoWorld.MinTileHeight, IsoWorld.MaxTileHeight) ) { + return ErrorVarClampMsg("TileHeight", IsoWorld.MinTileHeight, IsoWorld.MaxTileHeight); + } + if ( !stepDepth.IsNone && IsErrorVarClamp(stepDepth.Value, IsoWorld.MinStepDepth, IsoWorld.MaxStepDepth) ) { + return ErrorVarClampMsg("StepDepth", IsoWorld.MinStepDepth, IsoWorld.MaxStepDepth); + } + if ( !startDepth.IsNone && IsErrorVarClamp(startDepth.Value, IsoWorld.MinStartDepth, IsoWorld.MaxStartDepth) ) { + return ErrorVarClampMsg("StartDepth", IsoWorld.MinStartDepth, IsoWorld.MaxStartDepth); + } + return ""; + } + + public override void OnEnter() { + DoAction(); + Finish(); + } + + void DoAction() { + var go = Fsm.GetOwnerDefaultTarget(gameObject); + if ( UpdateCache(go) ) { + if ( !tileSize .IsNone ) { isoWorld.tileSize = tileSize .Value; } + if ( !tileRatio .IsNone ) { isoWorld.tileRatio = tileRatio .Value; } + if ( !tileAngle .IsNone ) { isoWorld.tileAngle = tileAngle .Value; } + if ( !tileHeight.IsNone ) { isoWorld.tileHeight = tileHeight.Value; } + if ( !stepDepth .IsNone ) { isoWorld.stepDepth = stepDepth .Value; } + if ( !startDepth.IsNone ) { isoWorld.startDepth = startDepth.Value; } + } + } + } +} // IsoTools.PlayMaker.Actions \ No newline at end of file diff --git a/Assets/IsoTools/PlayMaker/Actions/IsoChangeWorld.cs.meta b/Assets/IsoTools/PlayMaker/Actions/IsoSetWorldProps.cs.meta similarity index 100% rename from Assets/IsoTools/PlayMaker/Actions/IsoChangeWorld.cs.meta rename to Assets/IsoTools/PlayMaker/Actions/IsoSetWorldProps.cs.meta diff --git a/Assets/IsoTools/Scripts/IsoWorld.cs b/Assets/IsoTools/Scripts/IsoWorld.cs index fd1ab45..f3a924f 100644 --- a/Assets/IsoTools/Scripts/IsoWorld.cs +++ b/Assets/IsoTools/Scripts/IsoWorld.cs @@ -31,7 +31,37 @@ namespace IsoTools { Vector2 _sectorsMinNumPos = Vector2.zero; Vector2 _sectorsMaxNumPos = Vector2.zero; Vector2 _sectorsNumPosCount = Vector2.zero; - + + // ------------------------------------------------------------------------ + // + // Constants + // + // ------------------------------------------------------------------------ + + public static readonly float DefTileSize = 32.0f; + public static readonly float MinTileSize = Mathf.Epsilon; + public static readonly float MaxTileSize = float.MaxValue; + + public static readonly float DefTileRatio = 0.5f; + public static readonly float MinTileRatio = 0.25f; + public static readonly float MaxTileRatio = 1.0f; + + public static readonly float DefTileAngle = 45.0f; + public static readonly float MinTileAngle = 0.0f; + public static readonly float MaxTileAngle = 90.0f; + + public static readonly float DefTileHeight = DefTileSize; + public static readonly float MinTileHeight = MinTileSize; + public static readonly float MaxTileHeight = MaxTileSize; + + public static readonly float DefStepDepth = 0.1f; + public static readonly float MinStepDepth = Mathf.Epsilon; + public static readonly float MaxStepDepth = float.MaxValue; + + public static readonly float DefStartDepth = 1.0f; + public static readonly float MinStartDepth = float.MinValue; + public static readonly float MaxStartDepth = float.MaxValue; + // ------------------------------------------------------------------------ // // Sorting properties @@ -39,61 +69,61 @@ namespace IsoTools { // ------------------------------------------------------------------------ [SerializeField] - public float _tileSize = 32.0f; + public float _tileSize = DefTileSize; public float tileSize { get { return _tileSize; } set { - _tileSize = Mathf.Max(value, Mathf.Epsilon); + _tileSize = Mathf.Clamp(value, MinTileSize, MaxTileSize); ChangeSortingProperty(); } } [SerializeField] - public float _tileRatio = 0.5f; + public float _tileRatio = DefTileRatio; public float tileRatio { get { return _tileRatio; } set { - _tileRatio = Mathf.Clamp(value, 0.25f, 1.0f); + _tileRatio = Mathf.Clamp(value, MinTileRatio, MaxTileRatio); ChangeSortingProperty(); } } [SerializeField] - public float _tileAngle = 45.0f; + public float _tileAngle = DefTileAngle; public float tileAngle { get { return _tileAngle; } set { - _tileAngle = Mathf.Clamp(value, 0.0f, 90.0f); + _tileAngle = Mathf.Clamp(value, MinTileAngle, MaxTileAngle); ChangeSortingProperty(); } } [SerializeField] - public float _tileHeight = 32.0f; + public float _tileHeight = DefTileHeight; public float tileHeight { get { return _tileHeight; } set { - _tileHeight = Mathf.Max(value, Mathf.Epsilon); + _tileHeight = Mathf.Clamp(value, MinTileHeight, MaxTileHeight); ChangeSortingProperty(); } } [SerializeField] - public float _stepDepth = 0.1f; + public float _stepDepth = DefStepDepth; public float stepDepth { get { return _stepDepth; } set { - _stepDepth = value; + _stepDepth = Mathf.Clamp(value, MinStepDepth, MaxStepDepth); ChangeSortingProperty(); } } [SerializeField] - public float _startDepth = 1.0f; + public float _startDepth = DefStartDepth; public float startDepth { get { return _startDepth; } set { - _startDepth = value; + _startDepth = Mathf.Clamp(value, MinStartDepth, MaxStartDepth); ChangeSortingProperty(); } } @@ -631,12 +661,12 @@ namespace IsoTools { #if UNITY_EDITOR void Reset() { - tileSize = 32.0f; - tileRatio = 0.5f; - tileAngle = 45.0f; - tileHeight = 32.0f; - stepDepth = 0.1f; - startDepth = 1.0f; + tileSize = DefTileSize; + tileRatio = DefTileRatio; + tileAngle = DefTileAngle; + tileHeight = DefTileHeight; + stepDepth = DefStepDepth; + startDepth = DefStartDepth; } void OnValidate() {