public static FunctionUpdater CreateMouseClickFromToAction(int mouseButton, int cancelMouseButton, Action <Vector3, Vector3> onMouseClickFromTo, Action <Vector3, Vector3> onWaitingForToPosition) { int state = 0; Vector3 from = Vector3.zero; return(FunctionUpdater.Create(() => { if (state == 1) { if (onWaitingForToPosition != null) { onWaitingForToPosition(from, UtilsClass.GetMouseWorldPosition()); } } if (state == 1 && Input.GetMouseButtonDown(cancelMouseButton)) { // Cancel state = 0; } if (Input.GetMouseButtonDown(mouseButton) && !UtilsClass.IsPointerOverUI()) { if (state == 0) { state = 1; from = UtilsClass.GetMouseWorldPosition(); } else { state = 0; onMouseClickFromTo(from, UtilsClass.GetMouseWorldPosition()); } } return false; })); }
// Creates a Text Mesh in the World and constantly updates it public static FunctionUpdater CreateWorldTextUpdater(Func <string> GetTextFunc, Vector3 localPosition, Transform parent = null) { TextMesh textMesh = CreateWorldText(GetTextFunc(), parent, localPosition); return(FunctionUpdater.Create(() => { textMesh.text = GetTextFunc(); return false; }, "WorldTextUpdater")); }
// Create Text Updater in UI public static FunctionUpdater CreateUITextUpdater(Func <string> GetTextFunc, Vector2 anchoredPosition) { Text text = DrawTextUI(GetTextFunc(), anchoredPosition, 20, GetDefaultFont()); return(FunctionUpdater.Create(() => { text.text = GetTextFunc(); return false; }, "UITextUpdater")); }
public static FunctionUpdater CreateKeyCodeAction(KeyCode keyCode, Action onKeyDown) { return(FunctionUpdater.Create(() => { if (Input.GetKeyDown(keyCode)) { onKeyDown(); } return false; })); }
public static FunctionUpdater CreateMouseClickAction(int mouseButton, Action <Vector3> onMouseClick) { return(FunctionUpdater.Create(() => { if (Input.GetMouseButtonDown(mouseButton)) { onMouseClick(GetWorldPositionFromUI()); } return false; })); }
// Screen Shake public static void ShakeCamera(float intensity, float timer) { Vector3 lastCameraMovement = Vector3.zero; FunctionUpdater.Create(delegate() { timer -= Time.unscaledDeltaTime; Vector3 randomMovement = new Vector3(UnityEngine.Random.Range(-1f, 1f), UnityEngine.Random.Range(-1f, 1f)).normalized *intensity; Camera.main.transform.position = Camera.main.transform.position - lastCameraMovement + randomMovement; lastCameraMovement = randomMovement; return(timer <= 0f); }, "CAMERA_SHAKE"); }
// Debug DrawLine to draw a projectile, turn Gizmos On public static void DebugProjectile(Vector3 from, Vector3 to, float speed, float projectileSize) { Vector3 dir = (to - from).normalized; Vector3 pos = from; FunctionUpdater.Create(() => { Debug.DrawLine(pos, pos + dir * projectileSize); float distanceBefore = Vector3.Distance(pos, to); pos += dir * speed * Time.deltaTime; float distanceAfter = Vector3.Distance(pos, to); if (distanceBefore < distanceAfter) { return(true); } return(false); }); }
public static FunctionUpdater CreateMouseDraggingAction(int mouseButton, Action <Vector3> onMouseDragging) { bool dragging = false; return(FunctionUpdater.Create(() => { if (Input.GetMouseButtonDown(mouseButton)) { dragging = true; } if (Input.GetMouseButtonUp(mouseButton)) { dragging = false; } if (dragging) { onMouseDragging(UtilsClass.GetMouseWorldPosition()); } return false; })); }
// Create a Text Popup in the World public static void CreateWorldTextPopup(Transform parent, string text, Vector3 localPosition, int fontSize, Color color, Vector3 finalPopupPosition, float popupTime) { TextMesh textMesh = CreateWorldText(parent, text, localPosition, fontSize, color, TextAnchor.LowerLeft, TextAlignment.Left, sortingOrderDefault); Transform transform = textMesh.transform; Vector3 moveAmount = (finalPopupPosition - localPosition) / popupTime; FunctionUpdater.Create(delegate() { transform.position += moveAmount * Time.deltaTime; popupTime -= Time.deltaTime; if (popupTime <= 0f) { UnityEngine.Object.Destroy(transform.gameObject); return(true); } else { return(false); } }, "WorldTextPopup"); }
public void SetPosition(Func <Vector3> getLocalPosition) { FunctionUpdater.Create(() => { transform.localPosition = getLocalPosition(); }); }