示例#1
0
        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;
            }));
        }
示例#2
0
        // 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"));
        }
示例#3
0
        // 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"));
        }
示例#4
0
 public static FunctionUpdater CreateKeyCodeAction(KeyCode keyCode, Action onKeyDown)
 {
     return(FunctionUpdater.Create(() => {
         if (Input.GetKeyDown(keyCode))
         {
             onKeyDown();
         }
         return false;
     }));
 }
示例#5
0
 public static FunctionUpdater CreateMouseClickAction(int mouseButton, Action <Vector3> onMouseClick)
 {
     return(FunctionUpdater.Create(() => {
         if (Input.GetMouseButtonDown(mouseButton))
         {
             onMouseClick(GetWorldPositionFromUI());
         }
         return false;
     }));
 }
示例#6
0
        // 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");
        }
示例#7
0
        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;
            }));
        }
示例#8
0
        // 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");
        }