Beispiel #1
0
    void Update()
    {
        Vector3 right   = camera.transform.right;
        Vector3 forward = camera.transform.forward;
        Vector3 up      = camera.transform.up;

        //Vector3 position = transform.position;
        //Debug.DrawLine(position - right * 10f, position + right * 10f);
        //Debug.DrawLine(position - forward * 10f, position + forward * 10f);
        //Debug.DrawLine(position - up * 10f, position + up * 10f);

        if (TouchUtility.Enabled && TouchUtility.TouchCount > 0)
        {
            Touch touch = TouchUtility.GetTouch(0);

            if (touch.phase == TouchPhase.Moved)
            {
                Vector2 delta           = touch.deltaPosition;
                Vector2 deltaNormalized = delta.normalized;
                float   deltaLength     = delta.magnitude;

                Vector3 direction = right * deltaNormalized.x + up * deltaNormalized.y;


                Vector3 axis = Vector3.Cross(direction, forward);

                transform.Rotate(axis, deltaLength * magnitude, Space.World);
            }
        }
    }
Beispiel #2
0
    private void UpdateVirtualInput()
    {
        if (EventSystem.current.IsPointerOverGameObject() || EventSystem.current.IsPointerOverGameObject(0))
        {
            return;
        }

        switch (TouchUtility.GetTouch())
        {
        case TouchInfo.Began:     //タッチ初めにスクリーン上の位置を記憶
            touchStartPos  = TouchUtility.GetTouchPosition();
            touchingScreen = true;
            uiManager.SetActiveVirtualPad(true);
            uiManager.UpdateMovavbleAreaImage(touchStartPos);
            break;

        case TouchInfo.Moved:     //タッチ中にスクリーン上の位置を記憶①
            touchCurrentPos = TouchUtility.GetTouchPosition();
            uiManager.UpdateCurrentTouchPosImage(touchCurrentPos);
            break;

        case TouchInfo.Stationary:     //タッチ中にスクリーン上の位置を記憶②
            touchCurrentPos = TouchUtility.GetTouchPosition();
            uiManager.UpdateCurrentTouchPosImage(touchCurrentPos);
            break;

        case TouchInfo.Ended:     //タッチ終了後にタッチ位置をリセット
            touchStartPos   = Vector2.zero;
            touchCurrentPos = Vector2.zero;
            touchingScreen  = false;
            uiManager.SetActiveVirtualPad(false);
            break;
        }
    }
Beispiel #3
0
        public void AddBlock(Vector2 screenPos)
        {
            blockPreview.enabled = false;

            var pos = TouchUtility.HitPosition(screenPos, gameObject);

            var block = Instantiate(blockPrefab, pos, Quaternion.identity);
        }
    private void Update()
    {
        var touch = TouchUtility.GetTouch(0);

        switch (touch)
        {
        case TouchInfo.Began:
            GenerateBlock("TEST");
            break;
        }
    }
Beispiel #5
0
    public override void Update()
    {
        if (TouchUtility.Enabled && TouchUtility.TouchCount > 0)
        {
            Touch touch = TouchUtility.GetTouch(0);
            if (touch.phase == TouchPhase.Began && !TouchUtility.TouchedUI(touch.fingerId))
            {
                painter.Paint();
            }
        }

        targetTransform.Rotate(new Vector3(80f * Time.deltaTime, 0f, 0f));
    }
    void Update()
    {
        if (TouchUtility.Enabled && TouchUtility.TouchCount > 0)
        {
            Touch touch = TouchUtility.GetTouch(0);
            if (touch.phase == TouchPhase.Began)
            {
                if (TouchUtility.TouchedUI(touch.fingerId))
                {
                    touched = false;
                    return;
                }

                Vector2 currentTouchPoint = mainCamera.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, -mainCameraZPos));
                if ((currentTouchPoint.ToVector3() - transform.position).sqrMagnitude < dragRadius * dragRadius)
                {
                    touched            = true;
                    previousTouchPoint = currentTouchPoint;
                }
                else
                {
                    touched = false;
                }
            }

            if (touched == true && (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Ended))
            {
                Vector2 currentTouchPoint = mainCamera.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, -mainCameraZPos));
                Vector2 delta             = (currentTouchPoint - previousTouchPoint).LimitLength(maxDragSpeed);

                if (delta.sqrMagnitude > 0f)
                {
                    Vector3 chiselPosition = transform.localPosition + delta.ToVector3();

                    if (chiselPosition.y > clampPositionY)
                    {
                        chiselPosition.y = clampPositionY;
                    }

                    transform.localPosition = chiselPosition;

                    previousTouchPoint = currentTouchPoint;
                }

                if (touch.phase == TouchPhase.Ended)
                {
                    touched = false;
                }
            }
        }
    }
    private Vector3 GetChopStickPos(int fingerId)
    {
        Vector3    pos = Vector3.zero;
        Ray        ray = Camera.main.ScreenPointToRay(TouchUtility.GetTouchPosition(fingerId));
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, 1 << LayerMask.NameToLayer(GameSystemManager.ChopstickMovableLayer)))
        {
            pos.x = hit.point.x;
            pos.z = hit.point.z;
        }

        return(pos);
    }
Beispiel #8
0
    public void StartStroke(Vector2 screenPos)
    {
        var hitPos = TouchUtility.HitPosition(screenPos, gameObject, true);

        currentY = hitPos.y;

        var pos = transform.position;

        pos.y = currentY;
        transform.position = pos;

        isPainting = true;

        currentRow.Clear();
    }
Beispiel #9
0
    private void UpdateBoostInAir()
    {
        if (isParalyzed)
        {
            if (boostParticle.isEmitting)
            {
                SetBoostParticleActive(false);
            }
            return;
        }

        if ((TouchUtility.GetTouch() == TouchInfo.Moved || TouchUtility.GetTouch() == TouchInfo.Stationary) && currentBoostRemain > 0)
        {
            currentBoostRemain -= boostCost * Time.deltaTime;
            if (currentBoostRemain < 0)
            {
                currentBoostRemain = 0;
            }

            if (isBurst)
            {
                currentBoostRemain = boostMax;
            }
            else
            {
                var l    = Mathf.InverseLerp(0, boostMax, currentBoostRemain);
                var main = boostParticle.main;
                var c    = main.startColor.color;
                c.r = Mathf.Lerp(boostOverHeatColor.r, boostNormalColor.r, l);
                c.g = Mathf.Lerp(boostOverHeatColor.g, boostNormalColor.g, l);
                c.b = Mathf.Lerp(boostOverHeatColor.b, boostNormalColor.b, l);
                c.a = Mathf.Lerp(boostOverHeatColor.a, boostNormalColor.a, l);

                main.startColor      = c;
                boostGaugeFill.color = c;
            }

            if (!boostParticle.isEmitting)
            {
                SetBoostParticleActive(true);
            }
        }
        else if (boostParticle.isEmitting)
        {
            SetBoostParticleActive(false);
        }
    }
Beispiel #10
0
    public void EndStroke(Vector2 screenPos)
    {
        isPainting = false;

        int layer = LayerMask.NameToLayer("Block");

        currentRow.ForEach((block) => {
            block.gameObject.layer = layer;
        });

        var hitPos = TouchUtility.HitPosition(screenPos, gameObject);

        if (target == null)
        {
            target = Instantiate(targetPrefab, hitPos + Vector3.up * 0.5f, Quaternion.identity).transform;
        }
    }
Beispiel #11
0
    public void MoveStroke(Vector2 screenPos)
    {
        var hitPos = TouchUtility.HitPosition(screenPos, gameObject);

        if (currentY != hitPos.y)
        {
            return;
        }

        var spaceTaken = currentRow.Exists((Transform oldBlock) => {
            return(oldBlock.position == hitPos);
        });

        if (
            currentRow.Count > 1 &&
            currentRow[currentRow.Count - 2].position == hitPos
            )
        {
            var lastBlock = currentRow[currentRow.Count - 1];
            currentRow.RemoveAt(currentRow.Count - 1);
            Destroy(lastBlock.gameObject);

            return;
        }

        if (spaceTaken)
        {
            return;
        }

        var block = Instantiate(blockPrefab, hitPos, Quaternion.identity);

        block.gameObject.layer = LayerMask.NameToLayer("maker.newBlock");

        currentRow.Add(block);

        if (cubeBoy == null)
        {
            cubeBoy = Instantiate(cubeBoyPrefab, hitPos + Vector3.up * 0.5f, Quaternion.identity).transform;

            cubeBoy.RotateAround(cubeBoy.position, Vector3.up, 180.0f);
        }
    }
    /// <summary>
    /// タッチポジションを取得(エディタと実機を考慮)
    /// </summary>
    /// <returns>タッチポジション。タッチされていない場合は (0, 0, 0)</returns>
    public static Vector3 GetTouchPosition(int fingerId = 0)
    {
        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(fingerId);
            TouchPosition.x = touch.position.x;
            TouchPosition.y = touch.position.y;
            return(TouchPosition);
        }
        else
        {
            TouchInfo touch = TouchUtility.GetTouch();
            if (touch != TouchInfo.None)
            {
                return(Input.mousePosition);
            }
        }

        return(Vector3.zero);
    }
    void UpdateTouch()
    {
        if (TouchUtility.TouchCount > 0)
        {
            Touch   touch         = TouchUtility.GetTouch(0);
            Vector2 touchPosition = touch.position;

            touchPhase = touch.phase;
            if (touch.phase == TouchPhase.Began)
            {
                Vector2 XOYPlaneLocation = mainCamera.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, -cameraZPos));
                currentTouchPoint = XOYPlaneLocation - terrain.GetPositionOffset();

                BuildVertices(currentTouchPoint);

                terrain.ExecuteClip(this);

                previousTouchPoint = currentTouchPoint;
            }
            else if (touch.phase == TouchPhase.Moved)
            {
                Vector2 XOYPlaneLocation = mainCamera.ScreenToWorldPoint(new Vector3(touchPosition.x, touchPosition.y, -cameraZPos));
                currentTouchPoint = XOYPlaneLocation - terrain.GetPositionOffset();

                if ((currentTouchPoint - previousTouchPoint).sqrMagnitude <= touchMoveDistance * touchMoveDistance)
                {
                    return;
                }

                BuildVertices(previousTouchPoint, currentTouchPoint);

                terrain.ExecuteClip(this);

                previousTouchPoint = currentTouchPoint;
            }
        }
    }
Beispiel #14
0
    private void UpdateBoost()
    {
        if (isParalyzed)
        {
            return;
        }

        isBoosted = (TouchUtility.GetTouch() == TouchInfo.Moved || TouchUtility.GetTouch() == TouchInfo.Stationary);


        if (currentBoostRemain <= 0)
        {
            isBoosted = false;
        }

        if (isBoosted != isBoostedOld)
        {
            isBoostedOld = isBoosted;
            if (!SystemManager.GetIsGrounded())
            {
                RB.useGravity = !isBoosted;
            }
        }
    }
Beispiel #15
0
 public void MoveBlockPreview(Vector2 screenPos)
 {
     blockPreview.transform.position = TouchUtility.HitPosition(screenPos, gameObject);
 }
Beispiel #16
0
 public void StartBlockPreview(Vector2 screenPos)
 {
     blockPreview.transform.position = TouchUtility.HitPosition(screenPos, gameObject);
     blockPreview.enabled            = true;
 }