playMaker

Author Topic: Get Mouse XY[SOLVED]  (Read 2375 times)

Andrew.Lukasik

  • Full Member
  • ***
  • Posts: 134
    • View Profile
    • my twitter @andrewlukasik
Get Mouse XY[SOLVED]
« on: July 26, 2012, 01: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;
}

}
}
}
« Last Edit: January 01, 2013, 07:14:57 AM by jeanfabre »

Andrew.Lukasik

  • Full Member
  • ***
  • Posts: 134
    • View Profile
    • my twitter @andrewlukasik
Re: Get Mouse XY
« Reply #1 on: July 26, 2012, 01:21:37 AM »
(PS: If someone have better action handling this please share it here)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15373
  • Official Playmaker Support
    • View Profile
Re: Get Mouse XY
« Reply #2 on: July 26, 2012, 01: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

Andrew.Lukasik

  • Full Member
  • ***
  • Posts: 134
    • View Profile
    • my twitter @andrewlukasik
Re: Get Mouse XY
« Reply #3 on: July 27, 2012, 04:42:12 AM »
(Thanks you Jeanfabre, fixed)