Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        //penの座標変更処理
        transform.position = targetAnimator.GetBoneTransform(HumanBodyBones.RightHand).position;
        //https://qiita.com/edo_m18/items/c8808f318f5abfa8af1e
        var n  = -notePos;
        var x  = notePos;
        var x0 = transform.position;
        var m  = transform.forward;
        var h  = Vector3.Dot(n, x);

        var intersectPoint = x0 + ((h - Vector3.Dot(n, x0)) / (Vector3.Dot(n, m))) * m;

        markObj.transform.position = intersectPoint;

        //文字認識系統
        if (Input.GetKeyDown(KeyCode.Return) || Input.GetMouseButtonDown(1)) //enterで文字判定処理、ライン消去
        {
            Vector3 statusVec = statusCube.transform.localPosition;
            statusVec.y += 1;
            statusCube.transform.localPosition = statusVec;
            foreach (Transform child in note.transform)//ライン消去
            {
                if (child.tag == "Lines")
                {
                    Destroy(child.gameObject);
                }
            }
            if (CamTex != null)
            {//文字判定処理
                //文字画像(string)データ取得
                Texture2D tex = new Texture2D(CamTex.width, CamTex.height, TextureFormat.RGB24, false);
                RenderTexture.active = CamTex;
                tex.ReadPixels(new Rect(0, 0, CamTex.width, CamTex.height), 0, 0);
                tex.Apply();

                byte[] bytes = tex.EncodeToPNG();
                string str   = Convert.ToBase64String(bytes);//PNG画像データの文字列
                //Debug.Log(str);

                /*
                 #if UNITY_EDITOR
                 * string path = Directory.GetCurrentDirectory();
                 #else
                 * string path = Application.persistentDataPath;
                 #endif
                 * File.WriteAllBytes(path + "/picture.png", bytes);//pngファイルの保存*/

                //判定
                StartCoroutine(OCR.GetCharOfImage(str, (r => word = r)));
                //word = "火";
                //word =
                //Debug.Log("認識文字:" + word);
                //各文字に応じた処理
                //effectManager.EffectSelect(word);
            }
        }
        if (word.Length >= 1)
        {
            effectManager.EffectSelect(word);
            word = "";
        }


        //線を書く処理
        if (Input.GetMouseButtonDown(0))
        {
            GameObject objBuff = Instantiate(oneline, transform.position, Quaternion.identity);
            objBuff.transform.parent = note.transform;
            Vector3 statusVec = statusCube.transform.localPosition;
            statusVec.x = 1;
            statusCube.transform.localPosition = statusVec;
        }
        else if (Input.GetMouseButton(0))
        {
            Vector3 vec = markObj.transform.position;
            foreach (Transform child in note.transform)
            {
                if (child.tag == "Lines")
                {
                    if (debugMode)
                    {
                        Vector3 mousePos = Input.mousePosition;
                        mousePos.z = notePos.z;
                        vec        = Camera.main.ScreenToWorldPoint(mousePos);
                    }
                    child.GetComponent <Line>().Writing(vec);
                }
            }
            Vector3 statusVec = statusCube.transform.localPosition;
            statusVec.x = 2;
            statusCube.transform.localPosition = statusVec;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            foreach (Transform child in note.transform)
            {
                if (child.tag == "Lines")
                {
                    child.GetComponent <Line>().WriteEnd();
                }
            }
            Vector3 statusVec = statusCube.transform.localPosition;
            statusVec.x = 0;
            statusCube.transform.localPosition = statusVec;
        }
    }