| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using JC.Unity;
- public class SB_EventSystem : MonoBehaviour
- {
- public static SB_EventSystem ins;
- void Awake()
- {
- if (ins) {
- Destroy(this.gameObject);
- } else {
- ins = this;
- DontDestroyOnLoad(this.gameObject);
- AwakenSimulateMouse();
- }
- }
-
- [SerializeField] SimulateMouse simulateMouse;
- [System.NonSerialized] public bool simulateMouseIsAwaked;
- public void AwakenSimulateMouse() {
- simulateMouseIsAwaked = !simulateMouse.gameObject.activeSelf;
- simulateMouse.gameObject.SetActive(simulateMouseIsAwaked);
- hasAxisQuat = false;
- }
- Quaternion targetAxisQuat;
- Quaternion nowAxisQuat;
- bool hasAxisQuat;
- Vector2 deltaVectorForMouse;
- public void MoveSimulateMouse(Quaternion axisQuat) {
- if (hasAxisQuat) {
- Vector3 lastAngle = nowAxisQuat.eulerAngles;
- targetAxisQuat = axisQuat;
- nowAxisQuat = Quaternion.Lerp(nowAxisQuat, targetAxisQuat, Time.deltaTime * 15f);
- Vector3 curAngle = nowAxisQuat.eulerAngles;
- float dx = FormatDeltaAngleY(curAngle.y - lastAngle.y) / 72f * simulateMouse.GetScaleScreenWidth();
- float dy = -FormatDeltaAngleX(curAngle.x - lastAngle.x) / 72f * simulateMouse.GetScaleScreenHeight();
- deltaVectorForMouse.x = dx;
- deltaVectorForMouse.y = dy;
- simulateMouse.MoveMousePointer(deltaVectorForMouse);
- } else {
- nowAxisQuat = targetAxisQuat = axisQuat;
- hasAxisQuat = true;
- }
- }
- public void ClickMouse() {
- simulateMouse.ClickMousePointer();
- }
- float FormatDeltaAngleX(float value)
- {
- return FormatDeltaAngleY(value);
- }
- float FormatDeltaAngleY(float value)
- {
- if (Mathf.Abs(value) > 180) {
- if (value < 0) {
- return 360f + value;
- }
- if (value > 0) {
- return value - 360f;
- }
- }
- return value;
- }
- }
|