playMaker

Author Topic: Set 'Size' value on Orthographic camera  (Read 5270 times)

markinjapan

  • Full Member
  • ***
  • Posts: 103
Set 'Size' value on Orthographic camera
« on: April 02, 2012, 07:22:57 PM »
Hi,

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

Thanks

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Set 'Size' value on Orthographic camera
« Reply #1 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

markinjapan

  • Full Member
  • ***
  • Posts: 103
Re: Set 'Size' value on Orthographic camera
« Reply #2 on: April 05, 2012, 08:02:53 PM »
Awesome, thanks.

amaranth

  • Full Member
  • ***
  • Posts: 172
Re: Set 'Size' value on Orthographic camera
« Reply #3 on: April 19, 2012, 04:49:03 PM »
I needed this too. Thanks, Jean!

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Set 'Size' value on Orthographic camera
« Reply #4 on: April 06, 2013, 04:18:31 PM »
thanks man, need this for my graduation project :)
Remember, you don't fail unless you give up trying to succeed!