Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Krileon on July 13, 2014, 12:11:12 PM

Title: OnPostRender
Post by: Krileon on July 13, 2014, 12:11:12 PM
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.

Code: [Select]
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 );
}
}
}
}
Title: Re: OnPostRender
Post by: Alex Chouls on July 13, 2014, 01:30:33 PM
FsmStateAction doesn't currently implement OnPostRender.

You could handle OnPostRender in the RTSysPreviewContext MonoBehaviour and forward an event to the FSM, i.e., Fsm.Event("OnPostRender");
Title: Re: OnPostRender
Post by: Krileon on July 13, 2014, 02:20:55 PM
Yeah, did some digging and came to same conclusion. Thank you! Will just go ahead with keeping my post process as a separate script and pass variables to it from my FSM, which is working fine now.
Title: Re: OnPostRender
Post by: Pondnetic on December 17, 2014, 03:30:16 PM
Will OnPostRender be available in 1.8?