コード例 #1
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            var pos = GetRealMousePos();
            if (pos != Vector2.zero)
            {
                pos1 = pos;
            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            var pos = GetRealMousePos();
            if (pos != Vector2.zero)
            {
                pos2 = pos;
                AddLine();
            }
        }
        else if (Input.GetMouseButtonDown(2))
        {
            var pos = GetMousePos(true);
            Utils.Animate(Vector3.zero, pos, 0.3f, (v) => Lines.AddOffset(v));

            Utils.Animate(Lines.Zoom, Lines.Zoom * 0.5f, 0.3f, (v) => Lines.SetZoom(v), true);
        }

        if (Input.GetMouseButtonDown(1))
        {
            var pos = GetMousePos(true) * Lines.Zoom;
            _dragStart   = pos;
            _offsetStart = Lines.Offset;
            _dragging    = true;
        }
        else if (Input.GetMouseButtonUp(1))
        {
            _dragging = false;
        }

        if (_dragging)
        {
            var pos = GetMousePos(true) * Lines.Zoom;
            Lines.SetOffset(_offsetStart + _dragStart - pos);
        }


        if (Input.GetKeyDown(KeyCode.T))
        {
            Lines.ClearOffset();
            Lines.ClearZoom();
        }
        if (Input.GetKeyDown(KeyCode.R))
        {
            RandomLines();
        }
        if (Input.GetKeyDown(KeyCode.C))
        {
            Lines.Clear();
            Lines.UpdateShader();
        }
        if (Input.GetKey(KeyCode.A))
        {
            Lines.AddLine(new Vector2(UnityEngine.Random.value, UnityEngine.Random.value), new Vector2(UnityEngine.Random.value, UnityEngine.Random.value));
            Lines.UpdateShader();
        }
    }