//returns a sprite string for use in TextMesh Pro
    static string GetSpriteStringForControlElement(NCGameControllerUnity.NCControlElementID element)
    {
        // find texture if it exists
        var result = "";

        if (!customGlyphs.ContainsKey(element))
        {
            var rawGlyphTexture   = NCGameControllerUnity.GetGlyph(element);
            var fixedGlyphTexture = FixGlyphTexture(rawGlyphTexture);
            customGlyphs.Add(element, fixedGlyphTexture);
        }

        // put texture into spriteasset
        var glyphTexture = customGlyphs[element];

        customSpriteAssets[_currentIndex].material.mainTexture = glyphTexture;

        var metrics = customSpriteAssets[_currentIndex].spriteGlyphTable[0].metrics;

        metrics.width  = 256f * (glyphTexture.width / (float)glyphTexture.height);
        metrics.height = 256f;
        customSpriteAssets[_currentIndex].spriteGlyphTable[0].metrics = metrics;

        // return tmpro valid string
        result = "<sprite=\"customGlyph" + (_currentIndex) + "\" name=\"customGlyph0\" tint>";

        // move onto the next spriteasset
        _currentIndex++;
        if (_currentIndex >= customSpriteAssets.Length)
        {
            _currentIndex = 0;
        }

        return(result);
    }
    static int _currentIndex;   // loops through all glyphs

    public static void Init()
    {
#if (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
        if (_init)
        {
            return;
        }
        _init = true;

        var go = new GameObject();

        //Set the style of your glyph here
        NCGameControllerUnity.SetGlyphStyle(128, NCGameControllerUnity.NCSymbolWeight.Regular, true, false, 1, 1, 1);

        customGlyphs = new Dictionary <NCGameControllerUnity.NCControlElementID, Texture2D>();

        var spriteAssetCount = 11;
        customSpriteAssets = new TMP_SpriteAsset[spriteAssetCount];

        for (int i = 0; i < spriteAssetCount; i++)
        {
            customSpriteAssets[i] = Resources.Load <TMP_SpriteAsset>("TMPCustomSprites/customGlyph" + i);
        }

        emptyTexture = Resources.Load <Texture2D>("TMPCustomSprites/emptyTexture");
#endif
    }
Exemple #3
0
 private static void ControllerConnectedTest()
 {
     if (!Application.isPlaying)
     {
         return;
     }
     Debug.Log("Controller Connected!");
     Debug.Log("Register Input Callback: " + NCGameControllerUnity.RegisterControllerInputCallback(ControllerInputTest));
 }
Exemple #4
0
    void Start()
    {
        if (ReInput.userDataStore != null)
        {
            ReInput.userDataStore.Load();
        }

#if (UNITY_IOS || UNITY_TVOS || UNITY_STANDALONE_OSX)
        inputHelperInstance = this;
        NCGameControllerUnity.RegisterControllerConnectedCallback(OnAppleControllerConnected);
        NCGameControllerUnity.RegisterControllerDisconnectedCallback(OnAppleControllerDisconnected);
        appleVirtualController = null;
#endif
    }
Exemple #5
0
    void Start()
    {
        _spriteRenderer = gameObject.AddComponent <SpriteRenderer>() as SpriteRenderer;

        try {
            testWrapper = this;

            Debug.Log("Controller Connected: " + NCGameControllerUnity.DeviceHasControllerConnected());
            Debug.Log("Has Extended Profile: " + NCGameControllerUnity.DeviceHasExtendedControllerConnected());

            Debug.Log("Register Input Callback: " + NCGameControllerUnity.RegisterControllerInputCallback(ControllerInputTest));
            Debug.Log("Register Connected Callback: " + NCGameControllerUnity.RegisterControllerConnectedCallback(ControllerConnectedTest));
            Debug.Log("Register Disconnected Callback: " + NCGameControllerUnity.RegisterControllerDisconnectedCallback(ControllerDisonnectedTest));

            SetGlyphStyle(100, NCSymbolWeight.Light, true, true, 0.0f, 1.0f, 1.0f);
        } catch (Exception e) {
            Debug.Log("NCGameControllerUnity Error: " + e);
        }
    }
Exemple #6
0
    private void ConnectAppleController()
    {
        if (!Application.isPlaying)
        {
            return;
        }

        //NOTE: You can probably chage this to "DeviceHasControllerConnected()" if your game can support a mini controller (2 buttons + dpad)
        if (NCGameControllerUnity.DeviceHasExtendedControllerConnected())
        {
            if (appleVirtualController == null || !appleVirtualController.enabled)
            {
                //NOTE: this assumes that your custom controller is index 1 in your list of custom controllers in the rewired editor
                appleVirtualController = ReInput.controllers.CreateCustomController(1, "apple");

                NCGameControllerUnity.RegisterControllerInputCallback(OnAppleControllerInput);
            }

            player.controllers.AddController(appleVirtualController, true);
        }
    }