Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: Andrew.Lukasik on July 26, 2012, 04:19:17 AM

Title: Get Mouse XY[SOLVED]
Post by: Andrew.Lukasik on July 26, 2012, 04:19:17 AM
GetMouseXY.cs

Description: It combines "GetMouseX.cs" and "GetMouseY.cs" into one action, and adds useful "everyFrame" flag.





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

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Input)]
[Tooltip("Gets the XY Positions of the mouse and stores it in a Float Variables.")]
public class GetMouseXY : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmFloat storeResultX;
[UIHint(UIHint.Variable)]
public FsmFloat storeResultY;
public bool normalize;
public bool everyFrame;

public override void Reset()
{
storeResultX = null;
storeResultY = null;
normalize = true;
everyFrame = false;
}


public override void OnEnter()
{
DoGetMouseXY();

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


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


void DoGetMouseXY()
{
if (storeResultX != null)
{
float xpos = Input.mousePosition.x;
if (normalize)
xpos /= Screen.width;
storeResultX.Value = xpos;
}

if (storeResultY != null)
{
float ypos = Input.mousePosition.y;
if (normalize)
ypos /= Screen.height;
storeResultY.Value = ypos;
}

}
}
}
Title: Re: Get Mouse XY
Post by: Andrew.Lukasik on July 26, 2012, 04:21:37 AM
(PS: If someone have better action handling this please share it here)
Title: Re: Get Mouse XY
Post by: jeanfabre on July 26, 2012, 04:53:42 AM
hi,

 I think you did a great job here actually. thos there is slight copy paste error for storeResultY, You are checking twice for storeResultX, where the second time you want to check for storeResultY and if not null, deal with it.

bye,

 Jean
Title: Re: Get Mouse XY
Post by: Andrew.Lukasik on July 27, 2012, 07:42:12 AM
(Thanks you Jeanfabre, fixed)