Ejemplo n.º 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;
            }));
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 4
0
 public static FunctionUpdater CreateKeyCodeAction(KeyCode keyCode, Action onKeyDown)
 {
     return(FunctionUpdater.Create(() => {
         if (Input.GetKeyDown(keyCode))
         {
             onKeyDown();
         }
         return false;
     }));
 }
Ejemplo n.º 5
0
 public static FunctionUpdater CreateMouseClickAction(int mouseButton, Action <Vector3> onMouseClick)
 {
     return(FunctionUpdater.Create(() => {
         if (Input.GetMouseButtonDown(mouseButton))
         {
             onMouseClick(GetWorldPositionFromUI());
         }
         return false;
     }));
 }
Ejemplo n.º 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");
        }
Ejemplo n.º 7
0
        // 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);
            });
        }
Ejemplo n.º 8
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;
            }));
        }
Ejemplo n.º 9
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");
        }
Ejemplo n.º 10
0
 public void SetPosition(Func <Vector3> getLocalPosition)
 {
     FunctionUpdater.Create(() => {
         transform.localPosition = getLocalPosition();
     });
 }