public void Start()
    {
        //during awake of first scene force touch state is not yet available. If InputManager is initialized later it's ok to call this in Awake.
        //For platforms other than iOS ForceTouchState.IncompatibleOS will be returned.
        forceTouchState = ForceTouchPlugin.GetForceTouchState();

        //it would be best to only start tracking if forceTouchState is Available or if supportsTouchRadius is true.
        //If native touches are used on old ios devices or devices that have force touch disabled it's a performance penalty that could be avoided.
        //if (forceTouchState == ForceTouchState.Available)
        {
            ForceTouchPlugin.StartTracking();              //won't be executed on anything but iOS so no need to add compiler conditionals
            //AddCallback();
        }
    }
Esempio n. 2
0
    void OnGUI()
    {
        var           nativeTouchScale = InputManager.instance.nativeTouchScale;
        StringBuilder output           = new StringBuilder();

        switch (currentInput)
        {
        case 1:
            output.AppendLine("<b>Input:</b> Native Touch");
            break;

        case 2:
            output.AppendLine("<b>Input:</b> Unity Touch");
            break;

        case 3:
            output.AppendLine("<b>Input:</b> Mouse");
            break;

        default:
            output.AppendLine("<b>Input:</b> Undefined (Mouse / Unity Touch)");
            break;
        }

        output.AppendLine("<b>Supports Touch Radius:</b> " + InputManager.instance.supportsTouchRadius);

        switch (InputManager.instance.forceTouchState)
        {
        case ForceTouchState.Available:
            output.AppendLine("<b>Force Touch State:</b> Available");
            break;

        case ForceTouchState.Unknown:
            output.AppendLine("<b>Force Touch State:</b> Unknown");
            break;

        case ForceTouchState.IncompatibleOS:
            output.AppendLine("<b>Force Touch State:</b> Incompatible OS");
            break;

        case ForceTouchState.Unavailable:
            output.AppendLine("<b>Force Touch State:</b> Unavailable");
            break;
        }

        output.AppendLine("<b>Callback Message:</b> " + callbackMessage);


        if (InputManager.instance.touches.Count > 0)
        {
            output.AppendLine("<b>Touches:</b>");
            for (int i = 0; i < InputManager.instance.touches.Count; i++)
            {
                output.AppendLine(InputManager.instance.touches [i].ToString());
            }
        }
        else
        {
            output.AppendLine("<b>Touches:</b> No touches available");
        }



        GUI.skin.label.alignment = TextAnchor.UpperLeft;
        GUI.color = Color.black;
        GUI.Label(new Rect(10 * nativeTouchScale, 10 * nativeTouchScale, Screen.width - 20 * nativeTouchScale, Screen.height - 20 * nativeTouchScale), "<size=" + 16 * nativeTouchScale + ">" + output.ToString() + "</size>");



        GUI.color = Color.white;

        if (ForceTouchPlugin.IsTracking())
        {
            if (GUI.Button(new Rect(10 * nativeTouchScale, Screen.height - ((10 + 40) * nativeTouchScale), Screen.width / 2 - 15 * nativeTouchScale, 40 * nativeTouchScale), "<size=" + 16 * nativeTouchScale + ">Switch Unity Input</size>"))
            {
                ForceTouchPlugin.StopTracking();
            }
        }
        else
        {
            if (GUI.Button(new Rect(10 * nativeTouchScale, Screen.height - ((10 + 40) * nativeTouchScale), Screen.width / 2 - 15 * nativeTouchScale, 40 * nativeTouchScale), "<size=" + 16 * nativeTouchScale + ">Switch Native Input</size>"))
            {
                //it would be best to only start tracking if forceTouchState is Available
                ForceTouchPlugin.StartTracking();
            }
        }

        if (GUI.Button(new Rect(Screen.width / 2 + 5 * nativeTouchScale, Screen.height - ((10 + 40) * nativeTouchScale), Screen.width / 2 - 15 * nativeTouchScale, 40 * nativeTouchScale), "<size=" + 16 * nativeTouchScale + ">Request FT State</size>"))
        {
            InputManager.instance.forceTouchState = ForceTouchPlugin.GetForceTouchState();
        }


        if (callbackAdded)
        {
            if (GUI.Button(new Rect(10 * nativeTouchScale, Screen.height - (100 * nativeTouchScale), Screen.width - 20 * nativeTouchScale, 40 * nativeTouchScale), "<size=" + 16 * nativeTouchScale + ">Remove FT State Change Callback</size>"))
            {
                callbackMessage = "No message received";
                InputManager.instance.RemoveCallback();
                callbackAdded = false;
            }
        }
        else
        {
            if (GUI.Button(new Rect(10 * nativeTouchScale, Screen.height - (100 * nativeTouchScale), Screen.width - 20 * nativeTouchScale, 40 * nativeTouchScale), "<size=" + 16 * nativeTouchScale + ">Add FT State Change Callback</size>"))
            {
                callbackMessage = "No message received";
                InputManager.instance.AddCallback();
                callbackAdded = true;
            }
        }
    }