Playmaker Forum

PlayMaker Feedback => Action Requests => Topic started by: markinjapan on April 02, 2012, 07:22:57 PM

Title: Set 'Size' value on Orthographic camera
Post by: markinjapan on April 02, 2012, 07:22:57 PM
Hi,

I think this would be useful for anyone making 2D games :)

Thanks
Title: Re: Set 'Size' value on Orthographic camera
Post by: jeanfabre on April 04, 2012, 03:40:15 AM
Hi,

 Here we go:

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2012. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Camera)]
[Tooltip("Set the size of an Ortho camera")]
public class CameraSetOrthographicSize : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(Camera))]
[Tooltip("The orthographic camera.")]
public FsmOwnerDefault camera;

[RequiredField]
[Tooltip("Size")]
public FsmFloat size;

[Tooltip("Repeat every frame.")]
public bool everyFrame;

private Camera cam;

public override void Reset()
{
camera = null;
size = 100f;

}

public override void OnEnter()
{
var go = Fsm.GetOwnerDefaultTarget(camera);
if (go == null)
{
return;
}

cam = go.camera;
if (cam==null)
{
return;

}

if (!cam.isOrthoGraphic)
{
return;
}

DoSetSize();

if (!everyFrame)
{
Finish();
}
}

public override void OnUpdate()
{
DoSetSize();
}

void DoSetSize()
{
cam.orthographicSize = size.Value;
}

public override string ErrorCheck()
{
var go = Fsm.GetOwnerDefaultTarget(camera);
if (go != null)
{
cam = go.camera;
if (cam!=null)
{
if (!cam.isOrthoGraphic)
{
return "Camera needs to be Orthographic";
}
}
}
return "";
}

}
}



Bye,

 Jean
Title: Re: Set 'Size' value on Orthographic camera
Post by: markinjapan on April 05, 2012, 08:02:53 PM
Awesome, thanks.
Title: Re: Set 'Size' value on Orthographic camera
Post by: amaranth on April 19, 2012, 04:49:03 PM
I needed this too. Thanks, Jean!
Title: Re: Set 'Size' value on Orthographic camera
Post by: KozTheBoss on April 06, 2013, 04:18:31 PM
thanks man, need this for my graduation project :)