I'm trying to attach an FSM to the main camera that has OnPostRender within it and some variables are set from PM. However, OnPostRender doesn't seam to work at all when inside of the action. Any suggests on getting this to work in an FSM? The below is my current code.
using UnityEngine;
using Rotorz.Tile;
namespace HutongGames.PlayMaker.Actions {
public class RTSysPreviewContext : MonoBehaviour, IBrushContext {
public TileSystem TileSystem;
public int Row;
public int Column;
public Brush Brush;
TileSystem IBrushContext.TileSystem {
get { return TileSystem; }
}
int IBrushContext.Row {
get { return Row; }
}
int IBrushContext.Column {
get { return Column; }
}
Brush IBrushContext.Brush {
get { return Brush; }
}
}
[ActionCategory("Rotorz Tile System")]
public class RTSysPreview : FsmStateAction {
[ObjectType(typeof(TileSystem)), Tooltip("The Tile System component. Not needed if System GameObject is used.")]
public FsmObject systemObject;
[Tooltip("Game Object reference to Tile System. Not needed if System Object is used.")]
public FsmOwnerDefault systemGameObject;
[RequiredField, ObjectType(typeof(Brush))]
public FsmObject brushObject;
[RequiredField]
public FsmInt row;
[RequiredField]
public FsmInt column;
[RequiredField]
public FsmMaterial material;
private Object previousOSystem;
private GameObject previousGoSystem;
private TileSystem system;
private Brush brush;
public override void Reset() {
systemObject = new FsmObject { UseVariable = true };
systemGameObject = null;
brushObject = new FsmObject { UseVariable = true };
row = new FsmInt { UseVariable = true };
column = new FsmInt { UseVariable = true };
material = new FsmMaterial { UseVariable = true };
}
public override void OnUpdate() {
if ( systemObject.Value == null ) {
var goSystem = Fsm.GetOwnerDefaultTarget( systemGameObject );
if ( goSystem == null ) {
return;
}
if ( goSystem != previousGoSystem ) {
system = goSystem.GetComponent<TileSystem>();
previousGoSystem = goSystem;
}
} else {
if ( systemObject.Value != previousOSystem ) {
system = systemObject.Value as TileSystem;
previousOSystem = systemObject.Value;
}
}
if ( system == null ) {
return;
}
if ( brushObject.Value == null ) {
return;
}
brush = brushObject.Value as Brush;
}
void OnPostRender() {
if ( brush != null ) {
ImmediatePreviewUtility.Matrix = system.transform.localToWorldMatrix;
RTSysPreviewContext context = new RTSysPreviewContext();
context.Brush = brush;
context.Column = column.Value;
context.Row = row.Value;
context.TileSystem = system;
TileData tile = system.GetTile( row.Value, column.Value );
brush.OnDrawImmediatePreview( context, tile, material.Value, brush );
}
}
}
}