Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: jeanfabre on August 28, 2012, 03:03:47 AM

Title: Get Screen size ratio
Post by: jeanfabre on August 28, 2012, 03:03:47 AM
Hi,

 Following a request, please find a get screensize ratio action ( width/height)

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

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Application)]
[Tooltip("Gets the Screen size ratio (width/height).")]
public class GetScreenSizeRatio : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("The Screen size ratio (width/height).")]
public FsmFloat storeScreenSizeRatio;

public override void Reset()
{
storeScreenSizeRatio = null;
}

public override void OnEnter()
{
storeScreenSizeRatio.Value = 1f*Screen.height/Screen.width;
Finish();
}

}
}

 bye,

 Jean
Title: Re: Get Screen size ratio
Post by: amaranth on August 28, 2012, 11:25:03 AM
Woot! Thank you, Jean! :D
Title: Re: Get Screen size ratio
Post by: SubZero on August 30, 2012, 05:53:26 AM
Thanks! But how can I now use this to scale the GUI?
Title: Re: Get Screen size ratio
Post by: Dev_Sebas on August 30, 2012, 11:31:04 AM
Thank you Jean! :)
Bye
Title: Re: Get Screen size ratio
Post by: jeanfabre on August 31, 2012, 03:46:22 AM
Hi,

 scaling GUI : what gui system are you using and what kind of scaling you are after. do you need layout modifications or a true scaling completly tight to the screensize? It would be good if you can provide more precision on that so that we can answer something useful.

bye,

 Jean
Title: Re: Get Screen size ratio
Post by: SubZero on August 31, 2012, 06:28:48 PM
Sure! Basically just using the built in OnGUI system provided by Playmaker and Unity.

Might be the case that I still don't have a clue how this all works (regarding the UI) but I did the following:

I setup an FSM to display a variety of buttons and labels to populate the main menu of my game. The hole setup was done in full hd resolution, however if I now switch the resolution to something lower than full hd the whole UI (Buttons, Labels and Sliders) kind of loose their screen positions and in rare cases are off screen.

I have to admit that I am a littlebit alone in the dark when it comes to GUI scripting and setup.

bye,
Sub
Title: Re: Get Screen size ratio
Post by: reedomatic on September 02, 2012, 10:00:32 AM
Nice, this is an action I was just getting to needing, thx Jean!
Title: Re: Get Screen size ratio
Post by: markinjapan on September 02, 2012, 12:26:27 PM
Very useful for Android  :)

Thanks!