using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; namespace RimWorldAnimationStudio { public class InputManager : Singleton { public Transform dialogBoxes; public GameObject keyframeSelector; private float lastUpdate = -1f; private float largeStep = 0.1f; private float smallStep = 0.03f; private bool isDragging; private Vector2 v0; public bool CanRepeatThisUpdate() { if (Time.unscaledTime > lastUpdate + Constants.actionRepeatSpeed) { lastUpdate = Time.unscaledTime; return true; } return false; } public bool IsModifierKeyHeld() { if (Input.GetKey(KeyCode.LeftShift)) return true; if (Input.GetKey(KeyCode.LeftControl)) return true; if (Input.GetKey(KeyCode.LeftAlt)) return true; if (Input.GetKey(KeyCode.LeftCommand)) return true; if (Input.GetKey(KeyCode.RightShift)) return true; if (Input.GetKey(KeyCode.RightControl)) return true; if (Input.GetKey(KeyCode.RightAlt)) return true; if (Input.GetKey(KeyCode.RightCommand)) return true; return false; } public bool IsDialogBoxIsActive() { foreach (Transform child in dialogBoxes) { if (child.gameObject.activeSelf) return true; } return false; } public void Update() { if (IsDialogBoxIsActive()) return; if (EventSystem.current.currentSelectedGameObject?.GetComponent()?.isFocused == true) return; bool canRepeatThisUpdate = CanRepeatThisUpdate(); // Check keybinds foreach (Keybind keybind in KeybindConfig.Instance.GetAllKeybinds()) { if (IsModifierKeyHeld() && keybind.keyModifiers.NullOrEmpty()) goto nextKeybind; foreach (KeyCode modKeyCode in keybind.keyModifiers) { if (Input.GetKey(modKeyCode) == false) goto nextKeybind; } if (keybind.repeatable && canRepeatThisUpdate) { if (Input.GetKey(keybind.keyCode) == false) goto nextKeybind; } else { if (Input.GetKeyDown(keybind.keyCode) == false) goto nextKeybind; } //Debug.Log(keybind.command); Invoke(keybind.command, 0f); return; nextKeybind:; } // Drag selection if (Input.GetMouseButtonDown(0)) { StartKeyframeSelectionDrag(); } else if (Input.GetMouseButtonUp(0)) { EndKeyframeSelectionDrag(); } else if (isDragging) { UpdateKeyframeSelector(); } else { HideKeyframeSelector(); } } public void StartKeyframeSelectionDrag() { PointerEventData pointer = new PointerEventData(EventSystem.current); pointer.position = Input.mousePosition; List raycastResults = new List(); EventSystem.current.RaycastAll(pointer, raycastResults); if (raycastResults.Count > 0) { foreach (var go in raycastResults) { //Debug.Log(go.gameObject); if (go.gameObject?.GetComponent