2019-03-17 23:43:20 +01:00
|
|
|
using System;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace UnityAtoms.Mobile
|
|
|
|
{
|
|
|
|
[Serializable]
|
2019-06-02 19:48:03 +02:00
|
|
|
public struct TouchUserInput : IEquatable<TouchUserInput>
|
2019-03-17 23:43:20 +01:00
|
|
|
{
|
|
|
|
public enum State
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
Down,
|
|
|
|
Drag,
|
|
|
|
Up
|
|
|
|
};
|
|
|
|
|
|
|
|
public State InputState;
|
|
|
|
public Vector2 InputPos;
|
|
|
|
public Vector2 InputPosLastFrame;
|
|
|
|
public Vector2 InputPosLastDown;
|
|
|
|
public Vector2 InputWorldPos { get { return Camera.main.ScreenToWorldPoint(InputPos); } }
|
|
|
|
public Vector2 InputWorldPosLastFrame { get { return Camera.main.ScreenToWorldPoint(InputPosLastFrame); } }
|
|
|
|
public Vector2 InputWorldPosLastDown { get { return Camera.main.ScreenToWorldPoint(InputPosLastDown); } }
|
|
|
|
|
|
|
|
public TouchUserInput(State inputState, Vector2 inputPos, Vector2 inputPosLastFrame, Vector2 inputPosLastDown)
|
|
|
|
{
|
|
|
|
this.InputState = inputState;
|
|
|
|
this.InputPos = inputPos;
|
|
|
|
this.InputPosLastFrame = inputPosLastFrame;
|
|
|
|
this.InputPosLastDown = inputPosLastDown;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Equals(TouchUserInput other)
|
|
|
|
{
|
|
|
|
return this.InputState == other.InputState && this.InputWorldPos == other.InputWorldPos && this.InputWorldPosLastFrame == other.InputWorldPosLastFrame;
|
|
|
|
}
|
2019-06-02 19:48:03 +02:00
|
|
|
|
2019-06-02 22:51:28 +02:00
|
|
|
public override bool Equals(object obj)
|
|
|
|
{
|
|
|
|
TouchUserInput tui = (TouchUserInput)obj;
|
|
|
|
return Equals(tui);
|
|
|
|
}
|
|
|
|
|
2019-06-02 19:48:03 +02:00
|
|
|
public override int GetHashCode()
|
|
|
|
{
|
2019-09-25 21:05:06 +02:00
|
|
|
var hash = 17;
|
|
|
|
hash = hash * 23 + this.InputState.GetHashCode();
|
|
|
|
hash = hash * 23 + this.InputPos.GetHashCode();
|
|
|
|
hash = hash * 23 + this.InputPosLastFrame.GetHashCode();
|
2019-06-02 19:48:03 +02:00
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool operator ==(TouchUserInput touch1, TouchUserInput touch2)
|
|
|
|
{
|
|
|
|
return touch1.Equals(touch2);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool operator !=(TouchUserInput touch1, TouchUserInput touch2)
|
|
|
|
{
|
|
|
|
return !touch1.Equals(touch2);
|
|
|
|
}
|
2019-03-17 23:43:20 +01:00
|
|
|
}
|
|
|
|
}
|