예제 #1
0
    void OnMouseDown()
    {
        Debug.Log("print funct start");
        //1. get canvas image (Texture2D)
        GameObject   canvas       = GameObject.Find("canvas");
        drawingOnGUI canvasScript = canvas.GetComponent <drawingOnGUI> ();
        Texture2D    canvasTex;

        if (canvasScript == null)
        {
            Sandart sandartCanvasScript = canvas.GetComponent <Sandart> ();
            canvasTex = sandartCanvasScript.GetCanvasTex();
        }
        else
        {
            canvasTex = canvasScript.GetCanvasTex();
        }

        byte[] canvasPng = canvasTex.EncodeToPNG();

        string galleryPath = Application.dataPath + "/galleryData/";

        File.WriteAllBytes(galleryPath + "temp.png", canvasPng);

        fnPrint_PngFilePrint(galleryPath + "temp.png");

        File.Delete(galleryPath + "temp.png");

        Debug.Log("Print Ok!");
    }
예제 #2
0
    void OnMouseDown()
    {
        /*step
         * 1. get canvas image (Texture2D)
         * 2. encode the image to png file
         * 3. save file to specific directory
         */

        //1. get canvas image (Texture2D)
        GameObject   canvas       = GameObject.Find("canvas");
        drawingOnGUI canvasScript = canvas.GetComponent <drawingOnGUI> ();
        Texture2D    canvasTex;

        if (canvasScript == null)
        {
            Sandart sandartCanvasScript = canvas.GetComponent <Sandart> ();
            canvasTex = sandartCanvasScript.GetCanvasTex();
        }
        else
        {
            canvasTex = canvasScript.GetCanvasTex();
        }

        //2. encode the image to png file
        byte[] canvasPng = canvasTex.EncodeToPNG();

        string galleryPath = Application.dataPath + "/galleryData/";
        //3. save file to specific directory
        int fcount = Directory.GetFiles(galleryPath, "*.png", SearchOption.AllDirectories).Length;       // Count the number of file(파일개수)

        string[] files = Directory.GetFiles(galleryPath, "*.png", SearchOption.AllDirectories);          // String array(save screenshot file)
        int      limit = 6;

        // if file number reached at limit number, then delete the oldest file
        if (fcount == limit)
        {
            string filename = files[0].Substring(files[0].Length - 18, 14);              // 'a.png' -> 'a'

            File.Delete(files [0]);

            if (File.Exists(galleryPath + filename + ".data"))
            {
                string[] data = Directory.GetFiles(galleryPath, filename + ".data", SearchOption.AllDirectories);
                string[] buf  = Directory.GetFiles(galleryPath, filename + ".buf", SearchOption.AllDirectories);

                File.Delete(data [0]);
                File.Delete(buf [0]);
            }
        }

        File.WriteAllBytes(galleryPath + System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".png", canvasPng);
    }
예제 #3
0
    // Use this for initialization
    void Start()
    {
        string dataname = PlayerPrefs.GetString("art");          // Receive datafile's name

        /* If datafile's name is not empty, load datafile to wateroil scene  */
        if (PlayerPrefs.HasKey("art"))
        {
            Debug.Log("dataname : " + dataname);
            GameObject canvas = GameObject.Find("canvas");

            Sandart canvasScript = canvas.GetComponent <Sandart>();

            canvasScript.init(dataname + ".buf");
        }

        PlayerPrefs.DeleteKey("art");
    }
예제 #4
0
    void OnMouseDown()
    {
        if (sandOption == ToolType.sand)
        {
            sandOption = ToolType.sandEraser;
            this.gameObject.renderer.material.mainTexture = sandEraserTex;
        }
        else
        {
            sandOption = ToolType.sand;
            this.gameObject.renderer.material.mainTexture = sandSpreadTex;
        }

        GameObject sandCanvas       = GameObject.Find("canvas");
        Sandart    sandCanvasScript = sandCanvas.GetComponent <Sandart> ();

        sandCanvasScript.OnToolChange(sandOption);
    }
예제 #5
0
파일: DMTD.cs 프로젝트: christyyoon/SGBG
    private void callGameObjByKinect(StSendData kinectInput)
    {
        if (isDetected == false)        // for canvas up event
        {
            isDetected = true;
        }

        float x, y;

        //find x,y ratio
        x = kinectInput.fSymbolPosX;
        y = kinectInput.fSymbolPosY;

        // coordinates transformation from kinect to unity
        y = 1 - y;

        // adjust calibration manually
        //y -= 0.03f;

        //real valid input
        Vector2 worldPoint = new Vector2(Screen.width * x, Screen.height * y);

        //2. find game object by kinect input(2D coordinates)
        GameObject gameObject    = findGameObject(worldPoint.x, worldPoint.y);
        GameObject colorSelector = findColorSelector(worldPoint.x, worldPoint.y);

        //Debug.Log (gameObject.name);

        //3. call the onSpandexDown method
        if (gameObject != null)
        {
            if (gameObject.name == "canvas")
            {
                isOnCanvas = true;
                //TODO Sandart
                drawingOnGUI canvasScript = gameObject.GetComponent <drawingOnGUI>();
                if (canvasScript != null)
                {
                    canvasScript.OnCanvasDown(worldPoint, (short)kinectInput.fSymbolDepth);                    // TODO complete params
                }
                else
                {
                    Sandart sandScript = gameObject.GetComponent <Sandart>();
                    sandScript.OnCanvasDown(worldPoint, (short)kinectInput.fSymbolDepth);
                }
            }
            else if (colorSelector != null)
            {
                GameObject.Find("Control - Circular Color Picker").SendMessage("OnCanvasDown", worldPoint);
                if (isOnCanvas == true)
                {
                    isOnCanvas = false;
                    GameObject.Find("canvas").SendMessage("OnCanvasUp");
                }
            }
            else
            {
                if (isOnCanvas == true)
                {
                    isOnCanvas = false;
                    GameObject.Find("canvas").SendMessage("OnCanvasUp");
                }
                gameObject.SendMessage("OnCanvasDown");
            }
            Debug.Log("gameobject found : " + gameObject.name);
        }

        prevMinPtr = worldPoint;         // for canvas up event

        //		else if(pointCount == 2 && minDepth < errorRange && isDetected == true){ // End of canvas down
        //			isDetected = false;
        //
        //			if(findGameObject(prevMinPtr.x,prevMinPtr.y).name == "canvas") // 'spandex canvas up' on 'drawing canvas'
        //				GameObject.Find("canvas").SendMessage("OnCanvasUp");
        //
        //			prevMinPtr.Set (0,0);
        //		}
    }
예제 #6
0
    void OnMouseDown()
    {
        // file : screenshot, paint + scene, drawing data

        /* Step
         * 1. sence name
         * 2. paint
         * 3.
         */
        GameObject canvas       = GameObject.Find("canvas");
        Sandart    canvasScript = canvas.GetComponent <Sandart> ();

        if (canvasScript.isCanvasChange() == false)        // no change in canvas
        {
            return;
        }

        string galleryPath = Application.dataPath + "/galleryData/";

        string canvasID = canvasScript.getCanvasID();

        string fileName = string.Empty;

        if (canvasID == string.Empty)       // new art space
        {
            fileName = galleryPath + System.DateTime.Now.ToString("yyyyMMddHHmmss");
        }
        else                                                    // old art space
        {
            fileName = galleryPath + canvasID;
        }


        // screenshot
        int fcount = Directory.GetFiles(galleryPath, "*.png", SearchOption.AllDirectories).Length;       // Count the number of file(파일개수)

        string[] files = Directory.GetFiles(galleryPath, "*.png", SearchOption.AllDirectories);          // String array(save screenshot file)

        int limit = 6;

        // if file number reached at limit number, then delete the oldest file
        if (fcount == limit && canvasID == string.Empty)
        {
            string filename = files[0].Substring(files[0].Length - 18, 14); // 'C:\user\20140512123123.png' -> '20140512123123'

            File.Delete(files [0]);                                         // delete png

            if (File.Exists(galleryPath + filename + ".data"))
            {
                string[] data = Directory.GetFiles(galleryPath, filename + ".data", SearchOption.AllDirectories);
                string[] buf  = Directory.GetFiles(galleryPath, filename + ".buf", SearchOption.AllDirectories);

                File.Delete(data [0]);
                File.Delete(buf [0]);
            }
        }

        Application.CaptureScreenshot(fileName + ".png");

        // scence
        StreamWriter sw = new StreamWriter(File.Open(fileName + ".data", FileMode.Create));

        sw.WriteLine("sandart");
        sw.Close();

        // drawing data

        short[] canvasBuf = canvasScript.getCanvasBuf();

        using (BinaryWriter writer = new BinaryWriter(File.Open(fileName + ".buf", FileMode.Create))){
            foreach (short elem in canvasBuf)
            {
                writer.Write(elem);
            }
        }
        Debug.Log("working spaced saved!");
    }