Exemplo n.º 1
0
        public static void Unlock_GL()
        {
            int eventID = UnityInterfaceAPI.QueueGLEvent(UnityInterfaceAPI.Unlock);

            GL.IssuePluginEvent(UnityInterfaceAPI.UnityRenderEventFunc(), eventID);
            GL.InvalidateState();
        }
Exemplo n.º 2
0
        public static void SceneObjectsAdd(int handle, string name, string type)
        {
            Lock();

            if (!SceneObjectsContains(handle))
            {
                UnityInterfaceAPI.Scene_Objects_Add(handle, name, type);
            }

            Unlock();
        }
Exemplo n.º 3
0
        public static string SceneObjectsGetNameFromHandle(int handle)
        {
            StringBuilder stringBuilder = new StringBuilder(256);

            string name = string.Empty;

            if (UnityInterfaceAPI.Scene_Objects_GetNameFromHandle(handle, stringBuilder, stringBuilder.Capacity))
            {
                name = stringBuilder.ToString();
            }

            return(name);
        }
Exemplo n.º 4
0
        public static bool SceneObjectsContains(int handle)
        {
            int count = SceneObjectsCount();

            bool contains = false;

            for (int i = 0; i < count; i++)
            {
                if (UnityInterfaceAPI.Scene_Objects_GetHandleAtIndex(i) == handle)
                {
                    contains = true;
                }
            }

            return(contains);
        }
Exemplo n.º 5
0
        public static void SceneObjectsRemove(int handle)
        {
            Lock();

            UnityInterfaceAPI.Scene_Objects_Remove(handle);

            // Make sure that if the scene object is deleted if it is the last sceneobject.
            // This may not always be the case as the sceneplayer is only created when an
            // actor is rendered.
            if (SceneObjectsCount() == 1 &&
                HvrScene.ScenePlayerExists())
            {
                HvrScene.DeleteScenePlayer();
            }

            Unlock();
        }
Exemplo n.º 6
0
        public static void Update()
        {
            Lock();

            while (UnityInterfaceAPI.LogBuffer_Get() != IntPtr.Zero)
            {
                try
                {
                    IntPtr ptr = UnityInterfaceAPI.LogBuffer_Get();

                    UnityInterfaceAPI.LogMessage logMessage = Helper.PtrToStruct <UnityInterfaceAPI.LogMessage>(ptr);
                    string message = Marshal.PtrToStringAnsi(logMessage.message);

                    UnityInterfaceAPI.LogBuffer_Pop();

                    switch (logMessage.type)
                    {
                    case HvrPlayerInterfaceAPI.INTERFACE_LOG_TYPE_DEBUG:
                        Debug.Log(message);
                        break;

                    case HvrPlayerInterfaceAPI.INTERFACE_LOG_TYPE_INFO:
#if VERBOSE_LOGGING
                        Debug.Log(message);
#endif
                        break;

                    case HvrPlayerInterfaceAPI.INTERFACE_LOG_TYPE_WARNING:
                        Debug.LogWarning(message);
                        break;

                    case HvrPlayerInterfaceAPI.INTERFACE_LOG_TYPE_ERROR:
                        Debug.LogError(message);
                        break;
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError(e.Message);
                }
            }

            Unlock();
        }
Exemplo n.º 7
0
        public static Type SceneObjectsGetTypeFromHandle(int handle)
        {
            StringBuilder stringBuilder = new StringBuilder(256);

            Type type = null;

            if (UnityInterfaceAPI.Scene_Objects_GetTypeFromHandle(handle, stringBuilder, stringBuilder.Capacity))
            {
                try
                {
                    type = Type.GetType(stringBuilder.ToString(), true);
                }
                catch (Exception e)
                {
                    Debug.LogError(e.Message);
                }
            }

            return(type);
        }
        public void Delete()
        {
            if (handle == Types.INVALID_HANDLE)
            {
                return;
            }

            // TODO: Verify that the below actually works
            // The locking will not be correct, as the Player needs to be deleted on the render thread
            // and the locks need to be executed on the same thread

            try
            {
                UnityInterface.Lock_GL();

#if VERBOSE_LOGGING
                Debug.Log("Delete " + GetType().Name + " Handle:" + handle);
#endif

                int eventID_detach = UnityInterfaceAPI.QueueGLEventI(HvrPlayerInterfaceAPI.Player_Detach, handle);
                GL.IssuePluginEvent(UnityInterfaceAPI.UnityRenderEventFunc(), eventID_detach);

                int eventID_delete = UnityInterfaceAPI.QueueGLEventI(HvrPlayerInterfaceAPI.Player_Delete, handle);
                GL.IssuePluginEvent(UnityInterfaceAPI.UnityRenderEventFunc(), eventID_delete);

                int eventID_remove = UnityInterfaceAPI.QueueGLEventI(UnityInterfaceAPI.Scene_Objects_Remove, handle);
                GL.IssuePluginEvent(UnityInterfaceAPI.UnityRenderEventFunc(), eventID_remove);

                m_handle = Types.INVALID_HANDLE;
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
            }
            finally
            {
                UnityInterface.Unlock_GL();
            }
        }
        private void Create()
        {
#if UNITY_EDITOR
            // The GetUnityRenderDevice and graphicsDeviceType will be Null if the editor is in batch mode
            // TODO: Handle case where user may want the player to be built during batch mode?
            if (InternalEditorUtility.inBatchMode)
            {
                return;
            }
#endif
            if (!HvrHelper.Support.IsApplicationStateSupported())
            {
                return;
            }

            // TODO, correct this by exposing the get native id
            int rendererType = HvrPlayerInterfaceAPI.RENDERER_TYPE_NONE;

            switch (SystemInfo.graphicsDeviceType)
            {
            case GraphicsDeviceType.Direct3D11:
                rendererType = HvrPlayerInterfaceAPI.RENDERER_TYPE_DIRECT3D11;
                break;

#if !UNITY_5_5_OR_NEWER
            case GraphicsDeviceType.OpenGL2:
#endif
            case GraphicsDeviceType.OpenGLCore:
            case GraphicsDeviceType.OpenGLES2:
            case GraphicsDeviceType.OpenGLES3:
                rendererType = HvrPlayerInterfaceAPI.RENDERER_TYPE_OPENGL;
                break;

            case GraphicsDeviceType.Metal:
                rendererType = HvrPlayerInterfaceAPI.RENDERER_TYPE_METAL;
                break;

            default:
                break;
            }

            try
            {
                UnityInterface.Lock();

                if (HvrPlayerInterface.Initialise())
                {
                    m_handle = HvrPlayerInterfaceAPI.Player_Create(rendererType, UnityInterfaceAPI.GetUnityRenderDevice());

#if VERBOSE_LOGGING
                    Debug.Log("Create " + GetType().Name + " Handle:" + handle);
#endif

                    m_graphicsDeviceType = SystemInfo.graphicsDeviceType;
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
            }
            finally
            {
                UnityInterface.Unlock();
            }
        }
Exemplo n.º 10
0
 public static void Unlock()
 {
     UnityInterfaceAPI.Unlock();
 }
Exemplo n.º 11
0
 public static void Lock()
 {
     UnityInterfaceAPI.Lock();
 }
Exemplo n.º 12
0
        public static int SceneObjectsCount()
        {
            int count = UnityInterfaceAPI.Scene_Objects_GetCount();

            return(count);
        }
Exemplo n.º 13
0
        public static int SceneObjectsGetHandleFromName(string name)
        {
            int handle = UnityInterfaceAPI.Scene_Objects_GetHandleFromName(name);

            return(handle);
        }