static void OnServoWindowCreated(int uid, int windowIndex, int widthPixels, int heightPixels, int formatNative)
    {
        TextureFormat format = ServoUnityTextureUtils.GetTextureFormatFromNativeTextureFormat(formatNative);

        if (widthPixels == 0 || heightPixels == 0 || format == (TextureFormat)0)
        {
            Debug.LogError("OnServoWindowCreated got invalid format.");
            return;
        }

        // If we initiated the creation of the new window, this find operation will succeed. But
        // if Servo initiated the creation, then there isn't yet a Unity object backing it, so
        // we'll need to create one.
        ServoUnityWindow window = ServoUnityWindow.FindWindowWithUID(uid);

        if (window == null)
        {
            ServoUnityController suc = FindObjectOfType <ServoUnityController>(); // Create it on the same gameobject holding the ServoUnityController.
            if (!suc)
            {
                Debug.LogError("ServoUnityController.OnServoWindowCreated: Couldn't find a ServoUnityController.");
                return;
            }
            window = ServoUnityWindow.CreateNewInParent(suc.transform.parent.gameObject);
        }

        window.WasCreated(windowIndex, widthPixels, heightPixels, format);
    }
示例#2
0
    void OnServoWindowCreated(int uid, int windowIndex, int widthPixels, int heightPixels, int formatNative)
    {
        ServoUnityWindow window = ServoUnityWindow.FindWindowWithUID(uid);

        if (window == null)
        {
            window = ServoUnityWindow.CreateNewInParent(transform.parent.gameObject);
        }
        NavbarWindow = window; // Switch to newly created window.

        /*
         * Enum values from Source/ServoUnityPlugin/servo_unity_c.h
         * enum  {
         *          ServoUnityTextureFormat_Invalid = 0,
         *          ServoUnityTextureFormat_RGBA32 = 1,
         *          ServoUnityTextureFormat_BGRA32 = 2,
         *          ServoUnityTextureFormat_ARGB32 = 3,
         *          ServoUnityTextureFormat_ABGR32 = 4,
         *          ServoUnityTextureFormat_RGB24 = 5,
         *          ServoUnityTextureFormat_BGR24 = 6,
         *          ServoUnityTextureFormat_RGBA4444 = 7,
         *          ServoUnityTextureFormat_RGBA5551 = 8,
         *          ServoUnityTextureFormat_RGB565 = 9
         *  };
         */
        TextureFormat format;

        switch (formatNative)
        {
        case 1:
            format = TextureFormat.RGBA32;
            break;

        case 2:
            format = TextureFormat.BGRA32;
            break;

        case 3:
            format = TextureFormat.ARGB32;
            break;

        case 5:
            format = TextureFormat.RGB24;
            break;

        case 7:
            format = TextureFormat.RGBA4444;
            break;

        case 9:
            format = TextureFormat.RGB565;
            break;

        default:
            format = (TextureFormat)0;
            break;
        }

        window.WasCreated(windowIndex, widthPixels, heightPixels, format);
    }