Beispiel #1
0
        void Update()
        {
            switch (_dataType)
            {
                case DataType.None:
                    while (_bangCount > 0)
                    {
                        _event.Invoke();
                        _bangCount--;
                    }
                    break;

                case DataType.Int:
                    while (_intQueue.Count > 0)
                        _intEvent.Invoke(DequeueInt());
                    break;

                case DataType.Float:
                    while (_floatQueue.Count > 0)
                        _floatEvent.Invoke(DequeueFloat());
                    break;

                case DataType.String:
                    while (_stringQueue.Count > 0)
                        _stringEvent.Invoke(DequeueString());
                    break;

                case DataType.Vector2:
                    while (_floatQueue.Count > 0)
                        _vector2Event.Invoke(DequeueVector2());
                    break;

                case DataType.Vector3:
                    while (_floatQueue.Count > 0)
                        _vector3Event.Invoke(DequeueVector3());
                    break;

                case DataType.Vector4:
                    while (_floatQueue.Count > 0)
                        _vector4Event.Invoke(DequeueVector4());
                    break;

                case DataType.Vector2Int:
                    while (_intQueue.Count > 0)
                        _vector2IntEvent.Invoke(DequeueVector2Int());
                    break;

                case DataType.Vector3Int:
                    while (_intQueue.Count > 0)
                        _vector3IntEvent.Invoke(DequeueVector3Int());
                    break;
            }
        }
Beispiel #2
0
        protected virtual void LateUpdate()
        {
            if (disableWith != null && disableWith.Dragging == true)
            {
                return;
            }

            var anchoredPosition = cachedRectTransform.anchoredPosition;
            var rect             = cachedRectTransform.rect;
            var parentSize       = ParentSize;
            var intervalX        = horizontalIntervalPixel + horizontalIntervalRect * rect.width + horizontalIntervalParent * parentSize.x;
            var intervalY        = verticalIntervalPixel + verticalIntervalRect * rect.width + verticalIntervalParent * parentSize.y;
            var oldPosition      = position;

            if (intervalX != 0.0f)
            {
                position.x = Mathf.RoundToInt((anchoredPosition.x - horizontalOffset) / intervalX);
            }

            if (intervalY != 0.0f)
            {
                position.y = Mathf.RoundToInt((anchoredPosition.y - verticalOffset) / intervalY);
            }

            if (horizontal == true)
            {
                var target = position.x * intervalX + horizontalOffset;
                var factor = LeanHelper.GetDampenFactor(horizontalSpeed, Time.deltaTime);

                anchoredPosition.x = Mathf.Lerp(anchoredPosition.x, target, factor);
            }

            if (vertical == true)
            {
                var target = position.y * intervalY + verticalOffset;
                var factor = LeanHelper.GetDampenFactor(verticalSpeed, Time.deltaTime);

                anchoredPosition.y = Mathf.Lerp(anchoredPosition.y, target, factor);
            }

            cachedRectTransform.anchoredPosition = anchoredPosition;

            if (position != oldPosition)
            {
                if (onPositionChanged != null)
                {
                    onPositionChanged.Invoke(position);
                }
            }
        }
Beispiel #3
0
    public bool MoveToPoint(int x, int y)
    {
        if (mover.IsMoving)
        {
            return(false);
        }

        HexPoint point = parentBoard.GetPoint(x, y);

        if (point == null)
        {
            return(false);
        }

        OnStartMovingFrom.Invoke(positionInBoard.x, positionInBoard.y);

        positionInBoard = point.positionInBoard;
        OnMoving.Invoke(positionInBoard.x, positionInBoard.y);

        mover.MoveTo(point, moveTime, OnMoveDone);

        return(true);
    }
Beispiel #4
0
    protected IEnumerator moveTo(HexPoint destination, float time, Vector2IntEvent moveDoneCallback)
    {
        isMoving = true;

        Vector2 moveDirection = destination.worldPosition - (Vector2)transform.position;
        float   speed         = moveDirection.magnitude / time;

        moveDirection = moveDirection.normalized;

        while (time > 0)
        {
            time -= Time.deltaTime;
            transform.position += (Vector3)(moveDirection * speed * Time.deltaTime);
            yield return(new WaitForFixedUpdate());
        }

        if (moveDoneCallback != null)
        {
            moveDoneCallback.Invoke(destination.positionInBoard.x, destination.positionInBoard.y);
        }

        isMoving = false;
    }
Beispiel #5
0
        private void Update()
        {
            switch (_dataType)
            {
            case DataType.None:
                while (_bangCount > 0)
                {
                    _event.Invoke();
                    _bangCount--;
                }
                break;

            case DataType.Int:
                while (_intQueue.Count > 0)
                {
                    _intEvent.Invoke(DequeueInt());
                }
                break;

            case DataType.Float:
                while (_floatQueue.Count > 0)
                {
                    _floatEvent.Invoke(DequeueFloat());
                }
                break;

            case DataType.String:
                while (_stringQueue.Count > 0)
                {
                    _stringEvent.Invoke(DequeueString());
                }
                break;

            case DataType.Vector2:
                while (_floatQueue.Count > 0)
                {
                    _vector2Event.Invoke(DequeueVector2());
                }
                break;

            case DataType.Vector3:
                while (_floatQueue.Count > 0)
                {
                    _vector3Event.Invoke(DequeueVector3());
                }
                break;

            case DataType.Vector4:
                while (_floatQueue.Count > 0)
                {
                    _vector4Event.Invoke(DequeueVector4());
                }
                break;

            case DataType.Vector2Int:
                while (_intQueue.Count > 0)
                {
                    _vector2IntEvent.Invoke(DequeueVector2Int());
                }
                break;

            case DataType.Vector3Int:
                while (_intQueue.Count > 0)
                {
                    _vector3IntEvent.Invoke(DequeueVector3Int());
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Beispiel #6
0
        private void SetPropValue(bool endEdit)
        {
            string _x = string.IsNullOrWhiteSpace(xField.text) ? "0" : xField.text;
            string _y = string.IsNullOrWhiteSpace(yField.text) ? "0" : yField.text;

            if (IsInt)
            {
                if (!int.TryParse(_x, out int x))
                {
                    x = 0;
                }

                if (!int.TryParse(_y, out int y))
                {
                    y = 0;
                }

                Vector2Int value = new Vector2Int(x, y);
                switch (type)
                {
                case VectorTypes.Vector3Int:
                    ModifyPropertyValue(new Vector3Int(value.x, value.y, 0), true);
                    break;

                default:
                    ModifyPropertyValue(value, true);
                    break;
                }

                if (endEdit)
                {
                    onIntEndEdit.Invoke(value);
                    EndEdit();
                }
                else
                {
                    onIntValueChanged.Invoke(value);
                }
            }
            else
            {
                if (!float.TryParse(_x, out float x))
                {
                    x = 0;
                }

                if (!float.TryParse(_y, out float y))
                {
                    y = 0;
                }

                Vector2 value = new Vector2(x, y);
                switch (type)
                {
                case VectorTypes.Vector3:
                    ModifyPropertyValue(new Vector3(value.x, value.y, 0), true);
                    break;

                case VectorTypes.Vector4:
                    ModifyPropertyValue(new Vector4(value.x, value.y, 0, 0), true);
                    break;

                default:
                    ModifyPropertyValue(value, true);
                    break;
                }

                if (endEdit)
                {
                    onValueEndEdit.Invoke(value);
                    EndEdit();
                }
                else
                {
                    onValueChanged.Invoke(value);
                }
            }
        }
Beispiel #7
0
 private void OnMouseDown()
 {
     OnTouched.Invoke(positionInBoard.x, positionInBoard.y);
 }