예제 #1
0
파일: MyTouch.cs 프로젝트: zhouy546/-
 /// <summary>
 /// 显示相关高度数据
 /// </summary>
 void OnGUI()
 {
     GUILayout.Label("支持的手指的数量:" + MyFinger.Fingers.Count);
     GUILayout.BeginHorizontal(GUILayout.Width(Screen.width));
     for (int i = 0; i < MyFinger.Fingers.Count; i++)
     {
         GUILayout.BeginVertical();
         MyFinger mf = MyFinger.Fingers[i];
         GUILayout.Label("手指" + i.ToString());
         if (mf.id != -1)
         {
             GUILayout.Label("Id: " + mf.id);
             GUILayout.Label("状态: " + mf.touch.phase.ToString());
         }
         else
         {
             GUILayout.Label("没有发现!");
         }
         GUILayout.EndVertical();
     }
     GUILayout.EndHorizontal();
 }
예제 #2
0
파일: MyTouch.cs 프로젝트: zhouy546/-
    // Update is called once per frame
    void Update()
    {
        Touch[] touches = Input.touches;

        // 遍历所有的已经记录的手指
        // --掦除已经不存在的手指
        foreach (MyFinger mf in MyFinger.Fingers)
        {
            if (mf.id == -1)
            {
                continue;
            }
            bool stillExit = false;
            foreach (Touch t in touches)
            {
                if (mf.id == t.fingerId)
                {
                    stillExit = true;
                    break;
                }
            }
            // 掦除
            if (stillExit == false)
            {
                mf.id = -1;
            }
        }
        // 遍历当前的touches
        // --并检查它们在是否已经记录在AllFinger中
        // --是的话更新对应手指的状态,不是的放放加进去
        foreach (Touch t in touches)
        {
            bool stillExit = false;
            // 存在--更新对应的手指
            foreach (MyFinger mf in MyFinger.Fingers)
            {
                if (t.fingerId == mf.id)
                {
                    stillExit = true;
                    mf.touch  = t;
                    break;
                }
            }
            // 不存在--添加新记录
            if (!stillExit)
            {
                foreach (MyFinger mf in MyFinger.Fingers)
                {
                    if (mf.id == -1)
                    {
                        mf.id    = t.fingerId;
                        mf.touch = t;
                        break;
                    }
                }
            }
        }

        // 记录完手指信息后,就是响应相应和状态记录了
        for (int i = 0; i < MyFinger.Fingers.Count; i++)
        {
            MyFinger mf = MyFinger.Fingers[i];
            if (mf.id != -1)
            {
                if (mf.touch.phase == TouchPhase.Began)
                {
                    marks[i].SetActive(true);
                    marks[i].transform.position = GetWorldPos(mf.touch.position);

                    particles[i].transform.position = GetWorldPos(mf.touch.position);
                }
                else if (mf.touch.phase == TouchPhase.Moved)
                {
                    marks[i].transform.position = GetWorldPos(mf.touch.position);

                    if (!particles[i].isPlaying)
                    {
                        particles[i].loop = true;
                        particles[i].Play();
                    }
                    particles[i].transform.position = GetWorldPos(mf.touch.position);
                }
                else if (mf.touch.phase == TouchPhase.Ended)
                {
                    marks[i].SetActive(false);
                    marks[i].transform.position = GetWorldPos(mf.touch.position);

                    particles[i].loop = false;
                    particles[i].Play();
                    particles[i].transform.position = GetWorldPos(mf.touch.position);
                }
                else if (mf.touch.phase == TouchPhase.Stationary)
                {
                    if (particles[i].isPlaying)
                    {
                        particles[i].Pause();
                    }
                    particles[i].transform.position = GetWorldPos(mf.touch.position);
                }
            }
            else
            {
                ;
            }
        }

        // exit
        if (Input.GetKeyDown(KeyCode.Home) || Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }

        //      // test
        //      if(Input.GetMouseButtonDown(0))
        //      {
        //          GameObject mark = Instantiate(markPerfab, Vector3.zero, Quaternion.identity) as GameObject;
        //          mark.transform.parent = this.transform;
        //          mark.transform.position = GetWorldPos(Input.mousePosition);
        //
        //          ParticleSystem particle = Instantiate(particlePerfab, Vector3.zero, Quaternion.identity) as ParticleSystem;
        //          particle.transform.parent = this.transform;
        //          particle.transform.position = GetWorldPos(Input.mousePosition);
        //          particle.loop = false;
        //          particle.Play();
        //      }
    }
예제 #3
0
    void Update()
    {
        Touch[] touches = Input.touches;

        foreach (MyFinger mf in MyFinger.Fingers)
        {
            if (mf.id == -1)
            {
                continue;
            }

            bool stillExit = false;

            foreach (Touch t in touches)
            {
                if (mf.id == t.fingerId)
                {
                    stillExit = true;
                    break;
                }
            }

            if (stillExit == false)
            {
                mf.id = -1;
            }
        }

        foreach (Touch t in touches)
        {
            bool stillExit = false;

            foreach (MyFinger mf in MyFinger.Fingers)
            {
                if (t.fingerId == mf.id)
                {
                    stillExit = true;
                    mf.touch  = t;
                    break;
                }
            }

            if (!stillExit)
            {
                foreach (MyFinger mf in MyFinger.Fingers)
                {
                    if (mf.id == -1)
                    {
                        mf.id    = t.fingerId;
                        mf.touch = t;
                        break;
                    }
                }
            }
        }

        for (int i = 0; i < MyFinger.Fingers.Count; i++)
        {
            MyFinger mf = MyFinger.Fingers[i];
            if (mf.id != -1)
            {
                switch (mf.touch.phase)
                {
                case TouchPhase.Began:
                    //To-DO

                    break;

                case TouchPhase.Moved:
                    //To-DO

                    break;

                case TouchPhase.Ended:
                    //To-DO

                    break;

                case TouchPhase.Stationary:
                    //To-DO

                    break;

                default:
                    //To-DO

                    break;
                }
            }
        }
    }