Example #1
0
    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();

        //if (forceTouchState != ForceTouchState.IncompatibleOS)
        //	AddCallback ();
    }
Example #2
0
    /*
     * Method that will be called by native end if ForceTouch state changes. You must
     * subscribe to that event by calling AddCallback method. For this method to be called,
     * InputManager component has to be in hierarchy.
     * See AddCallbackMethod in ForceTouchPlugin.cs for more info
     */
    public void UpdateForceTouch(string message)
    {
        if (GetComponent <StatusUI>())        //this is only required for StatusUI.
        {
            GetComponent <StatusUI>().callbackMessage = message;
        }

        forceTouchState = ForceTouchPlugin.GetForceTouchState(Int32.Parse(message));
    }
    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();
        }
    }
Example #4
0
    void OnGUI()
    {
        var           nativeTouchScale = LegacyInputManager.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> " + LegacyInputManager.instance.supportsTouchRadius);

        switch (LegacyInputManager.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 (LegacyInputManager.instance.touches.Count > 0)
        {
            output.AppendLine("<b>Touches:</b>");
            for (int i = 0; i < LegacyInputManager.instance.touches.Count; i++)
            {
                output.AppendLine(LegacyInputManager.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 (LegacyInputManager.instance.useNativeTouches)
        {
            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>"))
            {
                LegacyInputManager.instance.useNativeTouches = false;
            }
        }
        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>"))
            {
                LegacyInputManager.instance.useNativeTouches = true;
            }
        }


        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>"))
        {
            LegacyInputManager.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";
                LegacyInputManager.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";
                LegacyInputManager.instance.AddCallback();
                callbackAdded = true;
            }
        }
    }