PlayMaker: cache action component

This commit is contained in:
2015-12-13 21:10:19 +06:00
parent 93740f5a3c
commit c50a105368
11 changed files with 154 additions and 40 deletions

View File

@@ -443,16 +443,18 @@ MonoBehaviour:
- IsoTools.PlayMaker.Actions.IsoTranslate
- HutongGames.PlayMaker.Actions.Wait
- IsoTools.PlayMaker.Actions.IsoGetPosition
- IsoTools.PlayMaker.Actions.IsoGetSize
- PlayMaker.ConditionalExpression.ConditionalExpression
customNames:
-
-
-
-
actionEnabled: 01010101
actionIsOpen: 01010101
actionStartIndex: 00000000090000000c00000012000000
actionHashCodes: 8ef8760048c011017ebd0202490c8701
-
actionEnabled: 0101010101
actionIsOpen: 0000000000
actionStartIndex: 00000000090000000c0000001200000018000000
actionHashCodes: 8ef8760048c011017ebd02027ebd0202490c8701
unityObjectParams: []
fsmGameObjectParams: []
fsmOwnerDefaultParams:
@@ -472,6 +474,14 @@ MonoBehaviour:
showInInspector: 0
networkSync: 0
value: {fileID: 0}
- ownerOption: 0
gameObject:
useVariable: 0
name:
tooltip:
showInInspector: 0
networkSync: 0
value: {fileID: 0}
animationCurveParams: []
functionCallParams: []
fsmTemplateControlParams: []
@@ -532,6 +542,24 @@ MonoBehaviour:
showInInspector: 0
networkSync: 0
value: 0
- useVariable: 1
name: iso_w
tooltip:
showInInspector: 1
networkSync: 0
value: 0
- useVariable: 1
name:
tooltip:
showInInspector: 0
networkSync: 0
value: 0
- useVariable: 1
name:
tooltip:
showInInspector: 0
networkSync: 0
value: 0
fsmIntParams: []
fsmBoolParams:
- useVariable: 1
@@ -554,6 +582,12 @@ MonoBehaviour:
showInInspector: 1
networkSync: 0
value: {x: 0, y: 0, z: 0}
- useVariable: 1
name: iso_size
tooltip:
showInInspector: 1
networkSync: 0
value: {x: 0, y: 0, z: 0}
fsmColorParams: []
fsmRectParams: []
fsmQuaternionParams: []
@@ -561,12 +595,12 @@ MonoBehaviour:
- FINISHED
- TO_RESET_POSITION
-
byteData: 0000000001000000
byteData: 000000000100000000
arrayParamSizes:
arrayParamTypes: []
customTypeSizes:
customTypeNames: []
paramDataType: 140000001c0000000f0000000f0000000f000000010000000100000001000000010000000f0000001700000001000000140000001c0000000f0000000f0000000f00000001000000120000001700000017000000010000000100000011000000
paramDataType: 140000001c0000000f0000000f0000000f000000010000000100000001000000010000000f0000001700000001000000140000001c0000000f0000000f0000000f00000001000000140000001c0000000f0000000f0000000f00000001000000120000001700000017000000010000000100000011000000
paramName:
- gameObject
- vector
@@ -586,14 +620,20 @@ MonoBehaviour:
- y
- z
- everyFrame
- gameObject
- vector
- x
- y
- z
- everyFrame
- expression
- isTrueEvent
- isFalseEvent
- everyFrame
- rawResult
- storeResult
paramDataPos: 000000000000000000000000010000000200000000000000010000000200000003000000030000000000000004000000010000000100000004000000050000000600000005000000000000000100000002000000060000000700000000000000
paramByteDataSize: 000000000000000000000000000000000000000001000000010000000100000001000000000000000000000001000000000000000000000000000000000000000000000001000000000000000000000000000000010000000100000000000000
paramDataPos: 000000000000000000000000010000000200000000000000010000000200000003000000030000000000000004000000010000000100000004000000050000000600000005000000020000000200000007000000080000000900000006000000000000000100000002000000070000000800000000000000
paramByteDataSize: 000000000000000000000000000000000000000001000000010000000100000001000000000000000000000001000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000001000000000000000000000000000000010000000100000000000000
- name: State 3
description:
colorIndex: 0
@@ -725,6 +765,12 @@ MonoBehaviour:
colorIndex: 0
variables:
floatVariables:
- useVariable: 1
name: iso_w
tooltip:
showInInspector: 1
networkSync: 0
value: 0
- useVariable: 1
name: iso_x
tooltip:
@@ -742,6 +788,12 @@ MonoBehaviour:
showInInspector: 1
networkSync: 0
value: {x: 0, y: 0, z: 0}
- useVariable: 1
name: iso_size
tooltip:
showInInspector: 1
networkSync: 0
value: {x: 0, y: 0, z: 0}
colorVariables: []
rectVariables: []
quaternionVariables: []
@@ -753,7 +805,7 @@ MonoBehaviour:
enumVariables: []
categories:
-
variableCategoryIDs: 0000000000000000
variableCategoryIDs: 00000000000000000000000000000000
description:
docUrl:
showStateLabel: 1

View File

@@ -0,0 +1,49 @@
using UnityEngine;
using HutongGames.PlayMaker;
namespace IsoTools.PlayMaker.Actions {
public abstract class IsoComponentAction<T> : FsmStateAction where T : Component {
T _cachedComponent;
GameObject _cachedGameObject;
protected IsoWorld isoWorld {
get { return _cachedComponent as IsoWorld; }
}
protected IsoObject isoObject {
get { return _cachedComponent as IsoObject; }
}
protected IsoRigidbody isoRigidbody {
get { return _cachedComponent as IsoRigidbody; }
}
protected IsoCollider isoCollider {
get { return _cachedComponent as IsoCollider; }
}
protected IsoBoxCollider isoBoxCollider {
get { return _cachedComponent as IsoBoxCollider; }
}
protected IsoSphereCollider isoSphereCollider {
get { return _cachedComponent as IsoSphereCollider; }
}
protected bool UpdateCache(GameObject go) {
if ( go ) {
if ( _cachedComponent == null || _cachedGameObject != go ) {
_cachedComponent = go.GetComponent<T>();
_cachedGameObject = go;
if ( !_cachedComponent ) {
LogWarning("Missing component: " + typeof(T).FullName + " on: " + go.name);
}
}
} else {
_cachedComponent = null;
_cachedGameObject = null;
}
return _cachedComponent != null;
}
}
} // IsoTools.PlayMaker.Actions

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 063a1435f504a41b691d2cecde558bc9
timeCreated: 1450018514
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -4,8 +4,9 @@ using HutongGames.PlayMaker;
namespace IsoTools.PlayMaker.Actions {
[ActionCategory("IsoTools")]
[HutongGames.PlayMaker.Tooltip("Gets the Position of a IsoObject and stores it in a Vector3 Variable or each Axis in a Float Variable")]
public class IsoGetPosition : FsmStateAction {
public class IsoGetPosition : IsoComponentAction<IsoObject> {
[RequiredField]
[CheckForComponent(typeof(IsoObject))]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.Variable)]
@@ -44,9 +45,8 @@ namespace IsoTools.PlayMaker.Actions {
void DoGetPosition() {
var go = Fsm.GetOwnerDefaultTarget(gameObject);
var iso_object = go ? go.GetComponent<IsoObject>() : null;
if ( iso_object ) {
var position = iso_object.position;
if ( UpdateCache(go) ) {
var position = isoObject.position;
vector.Value = position;
x.Value = position.x;
y.Value = position.y;

View File

@@ -4,8 +4,9 @@ using HutongGames.PlayMaker;
namespace IsoTools.PlayMaker.Actions {
[ActionCategory("IsoTools")]
[HutongGames.PlayMaker.Tooltip("Gets the Size of a IsoObject and stores it in a Vector3 Variable or each Axis in a Float Variable")]
public class IsoGetSize : FsmStateAction {
public class IsoGetSize : IsoComponentAction<IsoObject> {
[RequiredField]
[CheckForComponent(typeof(IsoObject))]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.Variable)]
@@ -44,9 +45,8 @@ namespace IsoTools.PlayMaker.Actions {
void DoGetSize() {
var go = Fsm.GetOwnerDefaultTarget(gameObject);
var iso_object = go ? go.GetComponent<IsoObject>() : null;
if ( iso_object ) {
var size = iso_object.size;
if ( UpdateCache(go) ) {
var size = isoObject.size;
vector.Value = size;
x.Value = size.x;
y.Value = size.y;

View File

@@ -4,8 +4,9 @@ using HutongGames.PlayMaker;
namespace IsoTools.PlayMaker.Actions {
[ActionCategory("IsoTools")]
[HutongGames.PlayMaker.Tooltip("Gets the TilePosition of a IsoObject and stores it in a Vector3 Variable or each Axis in a Float Variable")]
public class IsoGetTilePosition : FsmStateAction {
public class IsoGetTilePosition : IsoComponentAction<IsoObject> {
[RequiredField]
[CheckForComponent(typeof(IsoObject))]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.Variable)]
@@ -44,9 +45,8 @@ namespace IsoTools.PlayMaker.Actions {
void DoGetPosition() {
var go = Fsm.GetOwnerDefaultTarget(gameObject);
var iso_object = go ? go.GetComponent<IsoObject>() : null;
if ( iso_object ) {
var position = iso_object.tilePosition;
if ( UpdateCache(go) ) {
var position = isoObject.tilePosition;
vector.Value = position;
x.Value = position.x;
y.Value = position.y;

View File

@@ -4,8 +4,9 @@ using HutongGames.PlayMaker;
namespace IsoTools.PlayMaker.Actions {
[ActionCategory("IsoTools")]
[HutongGames.PlayMaker.Tooltip("Sets the Position of a IsoObject. To leave any axis unchanged, set variable to 'None'.")]
public class IsoSetPosition : FsmStateAction {
public class IsoSetPosition : IsoComponentAction<IsoObject> {
[RequiredField]
[CheckForComponent(typeof(IsoObject))]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.Variable)]
@@ -52,10 +53,9 @@ namespace IsoTools.PlayMaker.Actions {
void DoSetPosition() {
var go = Fsm.GetOwnerDefaultTarget(gameObject);
var iso_object = go ? go.GetComponent<IsoObject>() : null;
if ( iso_object ) {
if ( UpdateCache(go) ) {
var position = vector.IsNone
? iso_object.position
? isoObject.position
: vector.Value;
if ( !x.IsNone ) {
@@ -68,7 +68,7 @@ namespace IsoTools.PlayMaker.Actions {
position.z = z.Value;
}
iso_object.position = position;
isoObject.position = position;
}
}
}

View File

@@ -4,8 +4,9 @@ using HutongGames.PlayMaker;
namespace IsoTools.PlayMaker.Actions {
[ActionCategory("IsoTools")]
[HutongGames.PlayMaker.Tooltip("Sets the Size of a IsoObject. To leave any axis unchanged, set variable to 'None'.")]
public class IsoSetSize : FsmStateAction {
public class IsoSetSize : IsoComponentAction<IsoObject> {
[RequiredField]
[CheckForComponent(typeof(IsoObject))]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.Variable)]
@@ -52,10 +53,9 @@ namespace IsoTools.PlayMaker.Actions {
void DoSetSize() {
var go = Fsm.GetOwnerDefaultTarget(gameObject);
var iso_object = go ? go.GetComponent<IsoObject>() : null;
if ( iso_object ) {
if ( UpdateCache(go) ) {
var size = vector.IsNone
? iso_object.size
? isoObject.size
: vector.Value;
if ( !x.IsNone ) {
@@ -68,7 +68,7 @@ namespace IsoTools.PlayMaker.Actions {
size.z = z.Value;
}
iso_object.size = size;
isoObject.size = size;
}
}
}

View File

@@ -4,8 +4,9 @@ using HutongGames.PlayMaker;
namespace IsoTools.PlayMaker.Actions {
[ActionCategory("IsoTools")]
[HutongGames.PlayMaker.Tooltip("Sets the TilePosition of a IsoObject. To leave any axis unchanged, set variable to 'None'.")]
public class IsoSetTilePosition : FsmStateAction {
public class IsoSetTilePosition : IsoComponentAction<IsoObject> {
[RequiredField]
[CheckForComponent(typeof(IsoObject))]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.Variable)]
@@ -52,10 +53,9 @@ namespace IsoTools.PlayMaker.Actions {
void DoSetTilePosition() {
var go = Fsm.GetOwnerDefaultTarget(gameObject);
var iso_object = go ? go.GetComponent<IsoObject>() : null;
if ( iso_object ) {
if ( UpdateCache(go) ) {
var tile_position = vector.IsNone
? iso_object.tilePosition
? isoObject.tilePosition
: vector.Value;
if ( !x.IsNone ) {
@@ -68,7 +68,7 @@ namespace IsoTools.PlayMaker.Actions {
tile_position.z = z.Value;
}
iso_object.tilePosition = tile_position;
isoObject.tilePosition = tile_position;
}
}
}

View File

@@ -4,8 +4,9 @@ using HutongGames.PlayMaker;
namespace IsoTools.PlayMaker.Actions {
[ActionCategory("IsoTools")]
[HutongGames.PlayMaker.Tooltip("Translates a IsoObject. Use a Vector3 variable and/or XYZ components. To leave any axis unchanged, set variable to 'None'.")]
public class IsoTranslate : FsmStateAction {
public class IsoTranslate : IsoComponentAction<IsoObject> {
[RequiredField]
[CheckForComponent(typeof(IsoObject))]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.Variable)]
@@ -69,8 +70,7 @@ namespace IsoTools.PlayMaker.Actions {
void DoTranlate() {
var go = Fsm.GetOwnerDefaultTarget(gameObject);
var iso_object = go ? go.GetComponent<IsoObject>() : null;
if ( iso_object ) {
if ( UpdateCache(go) ) {
var translate = vector.IsNone
? new Vector3(x.Value, y.Value, z.Value)
: vector.Value;
@@ -85,7 +85,7 @@ namespace IsoTools.PlayMaker.Actions {
translate.z = z.Value;
}
iso_object.position +=
isoObject.position +=
translate * (perSecond ? Time.deltaTime : 1.0f);
}
}