Add project files.

This commit is contained in:
2022-09-30 17:32:21 +08:00
parent df69e65c88
commit e8e36b83bd
561 changed files with 40626 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
using System;
using UnityEngine;
using unity = UnityEngine;
namespace Cryville.Common.Unity.Input {
public class UnityMouseHandler : InputHandler {
GameObject receiver;
public UnityMouseHandler() {
if (!unity::Input.mousePresent) {
throw new NotSupportedException("Unity mouse is not supported on this device");
}
}
public override void Activate() {
receiver = new GameObject("__mouserecv__");
receiver.AddComponent<UnityMouseReceiver>().SetHandler(this);
}
public override void Deactivate() {
if (receiver) GameObject.Destroy(receiver);
}
public override void Dispose(bool disposing) {
if (disposing) {
Deactivate();
}
}
public override bool IsNullable(int type) {
if (type != 0) throw new ArgumentOutOfRangeException(nameof(type));
return false;
}
public override byte GetDimension(int type) {
if (type != 0) throw new ArgumentOutOfRangeException(nameof(type));
return 2;
}
public override string GetTypeName(int type) {
switch (type) {
case 0: return "Unity Mouse";
default: throw new ArgumentOutOfRangeException(nameof(type));
}
}
public override double GetCurrentTimestamp() {
return Time.timeAsDouble;
}
public class UnityMouseReceiver : MonoBehaviour {
UnityMouseHandler handler;
public void SetHandler(UnityMouseHandler h) {
handler = h;
}
void Update() {
double time = Time.timeAsDouble;
Vector2 pos = unity::Input.mousePosition;
pos.y = Screen.height - pos.y;
handler.OnInput(0, 0, new InputVector(time, pos));
}
}
}
}