示例#1
0
 //    public Vector2 Size {
 //        get {
 //            //return GetComponent<MeshFilter>().mesh.bounds.size;
 //            return gameObject.GetComponent<MeshCollider> ().bounds.size;
 //        }
 //    }
 void Update()
 {
     if (Input.GetKeyUp(KeyCode.N))
     {
         operation = CanvasOperationType.Erase;
     }
     else if (Input.GetKeyUp(KeyCode.Y))
     {
         operation = CanvasOperationType.Draw;
     }
 }
示例#2
0
    void DrawPath(CanvasOperationType op)
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;
        // Debug.DrawRay(ray.origin, ray.direction);
        //Debug.DrawLine(ray.origin, new Vector3(ray.origin.x, ray.origin.y, ray.origin.z + 100), Color.green);

        RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction);
        //RaycastHit2D hit2 = Physics2D.GetRayIntersection (ray, 1000);

        if (hit.transform != null)
        {
            //Debug.Log("hit:" + hit.transform.gameObject.name);
        }

        if (collider.Raycast(ray, out hitInfo, 100))
        {
            Debug.DrawLine(ray.origin, hitInfo.point, Color.red);

            if (!Physics.Raycast(ray, hitInfo.distance - 0.01f))
            {
                Vector2 texCoord = hitInfo.textureCoord;
                if (hitInfo.textureCoord.x >= 0 && hitInfo.textureCoord.x <= 1.0f
                    && hitInfo.textureCoord.y >= 0 && hitInfo.textureCoord.y <= 1.0f)
                {
                    int drawPosX = Convert.ToInt32(hitInfo.textureCoord.x * _drawingBoard.width + penOffsetX);
                    int drawPosY = Convert.ToInt32(hitInfo.textureCoord.y * _drawingBoard.height + penOffsetY);
                    /*
                    _canvas.SetPixels( drawPosX, drawPosY, penSizeX, penSizeY, penPixels );
                    _canvas.Apply();
                    */
                    for (int i = 0; i < penSizeX; i++)
                    {
                        for (int k = 0; k < penSizeY; k++)
                        {
                            Color sc = _drawingBoard.GetPixel(drawPosX + i, drawPosY + k);
                            Color dc = penTexture.GetPixel(i, k);
                            if (op == CanvasOperationType.Draw)
                            {
                                if (sc.a < 0.9f && dc.a > 0.9f)
                                {
                                    _drawingBoard.SetPixel(drawPosX + i, drawPosY + k, dc);
                                }
                            }
                            else
                            {
                                if (sc.a > 0.9f && dc.a > 0.9f)
                                {
                                    _drawingBoard.SetPixel(drawPosX + i, drawPosY + k, Color.clear);
                                }
                            }
                        }
                    }
                    _drawingBoard.Apply();
                }
            }
        }
    }