void UpdateButton(ref ButtonState button, EventBase.Flags buttonFlag, int flags)
 {
     //Debug.Log((int)buttonFlag + " " + flags + " " + (int)(flags & (int)buttonFlag));
     if (button == ButtonState.Idle && (int)(flags & (int)buttonFlag) != 0)
     {
         button = ButtonState.Down;
         //Debug.Log("Button " + buttonFlag + " DOWN");
     }
     else if (button == ButtonState.Down && (int)(flags & (int)buttonFlag) != 0)
     {
         button = ButtonState.Held;
         //Debug.Log("Button " + buttonFlag + " HELD");
     }
     else if (button == ButtonState.Down && (int)(flags & (int)buttonFlag) == 0)
     {
         button = ButtonState.Up;
         //Debug.Log("Button " + buttonFlag + " UP");
     }
     else if (button == ButtonState.Held && (int)(flags & (int)buttonFlag) == 0)
     {
         button = ButtonState.Up;
         //Debug.Log("Button " + buttonFlag + " UP");
     }
     else if (button == ButtonState.Up && (int)(flags & (int)buttonFlag) == 0)
     {
         button = ButtonState.Idle;
         //Debug.Log("Button " + buttonFlag + " IDLE");
     }
 }
Exemple #2
0
    public override void OnEvent(EventData e)
    {
        if (e.serviceType == EventBase.ServiceType.ServiceTypePointer)
        {
            int             id        = (int)e.sourceId;
            Vector2         pos       = new Vector2(e.posx, e.posy);
            EventBase.Type  eventType = (EventBase.Type)e.type;
            EventBase.Flags flags     = (EventBase.Flags)e.flags;

            pos = TouchPosToScreenPos(pos);

            int touchListSize = (int)e.getExtraDataFloat(4);

            if (eventType == EventBase.Type.Down)
            {
                AddTouchpoint(pos, id);
            }
            else if (eventType == EventBase.Type.Move)
            {
                if (touchPoints.ContainsKey(id))
                {
                    TouchPoint tp          = (TouchPoint)touchPoints[id];
                    GameObject touchObject = ((TouchPoint)touchPoints[id]).GetGameObject();

                    string text = id.ToString();

                    touchObject.GetComponentInChildren <UnityEngine.UI.Text>().text = text;
                    touchObject.transform.localPosition = pos;

                    for (int i = 0; i < touchListSize; i++)
                    {
                        int     sub_id  = (int)e.getExtraDataFloat(5 + i * 3);
                        Vector2 sub_pos = new Vector2(e.getExtraDataFloat(6 + i * 3), e.getExtraDataFloat(7 + i * 3));
                        sub_pos = TouchPosToScreenPos(sub_pos);
                        if (touchPoints.ContainsKey(sub_id))
                        {
                            TouchPoint sub_tp          = (TouchPoint)touchPoints[sub_id];
                            GameObject sub_touchObject = ((TouchPoint)touchPoints[sub_id]).GetGameObject();

                            string sub_text = sub_id.ToString();
                            sub_text += " (" + sub_tp.GetRootID() + ")";

                            sub_touchObject.GetComponentInChildren <UnityEngine.UI.Text>().text = sub_text;
                            sub_touchObject.transform.localPosition = sub_pos;
                        }
                        else
                        {
                            AddTouchpoint(sub_pos, sub_id, id);
                        }
                    }
                }
            }
            else if (eventType == EventBase.Type.Up)
            {
                Debug.Log("Up event for ID: " + id);
                Debug.Log(touchPoints.ContainsKey(id));
                if (touchPoints.ContainsKey(id))
                {
                    GameObject touchObject = ((TouchPoint)touchPoints[id]).GetGameObject();
                    Destroy(touchObject);
                    touchPoints.Remove(id);

                    for (int i = 0; i < touchListSize; i++)
                    {
                        int sub_id = (int)e.getExtraDataFloat(5 + i * 3);
                        if (touchPoints.ContainsKey(sub_id))
                        {
                            GameObject sub_touchObject = ((TouchPoint)touchPoints[sub_id]).GetGameObject();
                            Destroy(sub_touchObject);
                            touchPoints.Remove(sub_id);
                        }
                    }
                }
            }
        }
    }