playMaker

Author Topic: DebugDrawShape  (Read 4103 times)

giyomu

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 108
    • View Profile
    • blog
DebugDrawShape
« on: June 28, 2011, 03:35:56 AM »
a quickie one , that may be useful for your visual debug on the fly ( I use quite a bit in my project )
so i did not see them already in action debug , so i added that.

this just take the available debug shape from unity gizmos..no more than that

Code: [Select]
using UnityEngine;
using HutongGames.PlayMaker;

[ActionCategory(ActionCategory.Debug)]
[Tooltip("Draw gizmos shape")]
public class DebugDrawShape : FsmStateAction
{
public enum ShapeType {Sphere, Cube, WireSphere, WireCube}

[RequiredField]
public FsmOwnerDefault gameObject;
public ShapeType shape;
public FsmColor color;
[Tooltip("Use this for sphere gizmos")]
public FsmFloat radius;
[Tooltip("Use this for cube gizmos")]
public FsmVector3 size;

public override void Reset ()
{
gameObject = null;
shape = ShapeType.Sphere;
color = Color.grey;
radius = 1f;
size = new Vector3(1f, 1f, 1f);
}

public override void OnDrawGizmos ()
{

var ownerTransform = Fsm.GetOwnerDefaultTarget(gameObject).transform;
if(ownerTransform == null)
return;

Gizmos.color = color.Value;

switch(shape)
{
case ShapeType.Sphere:
Gizmos.DrawSphere(ownerTransform.position, radius.Value);
break;
case ShapeType.WireSphere:
Gizmos.DrawWireSphere(ownerTransform.position, radius.Value);
break;
case ShapeType.Cube:
Gizmos.DrawCube(ownerTransform.position,size.Value);
break;
case ShapeType.WireCube:
Gizmos.DrawWireCube(ownerTransform.position, size.Value);
break;
default:
break;
}
}
}



that'S possible you see a null ref , like when switching from your code editor onto unity..but nothing alarming , this is just the OnDrawGizmos that get lost when recompiling..

giyomu

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 108
    • View Profile
    • blog
Re: DebugDrawShape
« Reply #1 on: June 28, 2011, 05:47:25 PM »
hmm bad one , the object ref goes away when hitting play ..if someone has clue on how to use correctly Gizmos fct inside playmaker I take it  ;D