Playmaker Forum
PlayMaker Updates & Downloads => Share New Actions => Topic started by: jeanfabre on August 09, 2012, 04:39:07 PM
-
Hi,
following a thread, please find a beginArea action that follows the mouse.
http://hutonggames.com/playmakerforum/index.php?topic=2055.msg9186#msg9186 (http://hutonggames.com/playmakerforum/index.php?topic=2055.msg9186#msg9186)
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
using UnityEngine;
using System.Collections.Generic;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GUILayout)]
[Tooltip("Begin a GUILayout area that follows the mouse. Useful for overlays (e.g., playerName). NOTE: Block must end with a corresponding GUILayoutEndArea.")]
public class GUILayoutBeginAreaFollowMouse : FsmStateAction
{
[RequiredField]
public FsmFloat offsetLeft;
[RequiredField]
public FsmFloat offsetTop;
[RequiredField]
public FsmFloat width;
[RequiredField]
public FsmFloat height;
[Tooltip("Use normalized screen coordinates (0-1).")]
public FsmBool normalized;
[Tooltip("Optional named style in the current GUISkin")]
public FsmString style;
public override void Reset()
{
offsetLeft = 0f;
offsetTop = 0f;
width = 1f;
height = 1f;
normalized = true;
style = "";
}
public override void OnGUI()
{
// get screen position
Vector2 screenPos = Input.mousePosition;
var left = screenPos.x + (normalized.Value ? offsetLeft.Value * Screen.width : offsetLeft.Value);
var top = screenPos.y + (normalized.Value ? offsetTop.Value * Screen.width : offsetTop.Value);
var rect = new Rect(left, top, width.Value, height.Value);
if (normalized.Value)
{
rect.width *= Screen.width;
rect.height *= Screen.height;
}
// convert screen coordinates
rect.y = Screen.height - rect.y;
GUILayout.BeginArea(rect, style.Value);
}
}
}
bye,
Jean
-
Thanks for this! It works awesome, too!