IndieGame/client/Assets/ParadoxNotion/NodeCanvas/Tasks/Actions/Input/WaitMousePick2D.cs
DOBEST\zhaoyingjie f242607587 初始化工程
2024-10-11 10:12:15 +08:00

47 lines
1.4 KiB
C#

using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.Tasks.Actions
{
[Category("Input (Legacy System)")]
public class WaitMousePick2D : ActionTask
{
public enum ButtonKeys
{
Left = 0,
Right = 1,
Middle = 2
}
public ButtonKeys buttonKey;
public LayerMask mask = -1;
[BlackboardOnly] public BBParameter<GameObject> saveObjectAs;
[BlackboardOnly] public BBParameter<float> saveDistanceAs;
[BlackboardOnly] public BBParameter<Vector3> savePositionAs;
private int buttonID;
private RaycastHit2D hit;
protected override string info {
get { return string.Format("Wait Object '{0}' Click. Save As {1}", buttonKey, saveObjectAs); }
}
protected override void OnUpdate() {
buttonID = (int)buttonKey;
if ( Input.GetMouseButtonDown(buttonID) ) {
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
hit = Physics2D.Raycast(ray.origin, ray.direction, Mathf.Infinity, mask);
if ( hit.collider != null ) {
savePositionAs.value = hit.point;
saveObjectAs.value = hit.collider.gameObject;
saveDistanceAs.value = hit.distance;
EndAction(true);
}
}
}
}
}