private void OnDestroy()
 {
     if (s_instance == this)
     {
         s_instance = null;
     }
 }
        public static void LoadFromResource(string path = null)
        {
            if (path == null)
            {
                path = DEFAULT_RESOURCE_PATH;
            }

            if ((s_instance = Resources.Load <VIUSettings>(path)) == null)
            {
                s_instance = CreateInstance <VIUSettings>();
                s_instance.m_bindingInterfaceObjectSource = Resources.Load <GameObject>(BINDING_INTERFACE_PREFAB_DEFAULT_RESOURCE_PATH);
            }
        }
Пример #3
0
        public void UpdateModel()
        {
            if (m_isQuiting)
            {
                return;
            }

            if (m_updateModelLock)
            {
                Debug.LogWarning("Recursive UpdateModel call is not supported");
                return;
            }

            m_updateModelLock = true;

            var deviceState = VRModule.GetDeviceState(GetModelDeviceIndex());

            var lastActiveCustomModelNum      = m_activeCustomModel;
            var lastActiveCustomModelObj      = m_customModelObjs[m_activeCustomModel];
            var lastCustomModelActive         = m_isCustomModelActivated;
            var shouldActiveCustomModelNum    = deviceState.deviceModel;
            var shouldActiveCustomModelPrefab = m_customModels[shouldActiveCustomModelNum];

            if (shouldActiveCustomModelPrefab == null)
            {
                shouldActiveCustomModelPrefab = VIUSettings.GetOverrideDeviceModel(shouldActiveCustomModelNum);
            }
            var shouldActiveCustomModel = enabled && deviceState.isConnected && shouldActiveCustomModelPrefab != null;

            var lastCreatorActive        = m_activeCreatorIndex >= 0;
            var shouldActiveCreator      = enabled && !shouldActiveCustomModel;
            var shouldActiveCreatorIndex = -1;

            if (shouldActiveCreator)
            {
                // determin which creator should be activated
                shouldActiveCreatorIndex = m_defaultCreatorIndex;
                if (m_overrideModel == OverrideModelEnum.DontOverride)
                {
                    for (int i = 0, imax = m_creators.Length; i < imax; ++i)
                    {
                        if (m_creators[i].shouldActive)
                        {
                            shouldActiveCreatorIndex = i;
                            break;
                        }
                    }
                }
            }

            if (lastCustomModelActive)
            {
                if (!shouldActiveCustomModel || lastActiveCustomModelNum != shouldActiveCustomModelNum)
                {
                    // deactivate custom override model
                    if (lastActiveCustomModelObj != null && SendBeforeModelDeactivatedMessage(lastActiveCustomModelObj, this))
                    {
                        lastActiveCustomModelObj.gameObject.SetActive(false);
                    }
                    m_isCustomModelActivated = false;
                }
            }

            if (lastCreatorActive)
            {
                if (!shouldActiveCreator || m_activeCreatorIndex != shouldActiveCreatorIndex)
                {
                    // clean up old creator
                    m_creators[m_activeCreatorIndex].CleanUpRenderModel();
                    m_activeCreatorIndex = -1;
                }
            }

            if (shouldActiveCustomModel)
            {
                var shouldActiveCustomModelObj = m_customModelObjs[shouldActiveCustomModelNum];
                if (shouldActiveCustomModelObj == null)
                {
                    // instantiate custom override model
                    shouldActiveCustomModelObj = Instantiate(shouldActiveCustomModelPrefab);
                    shouldActiveCustomModelObj.transform.position = Vector3.zero;
                    shouldActiveCustomModelObj.transform.rotation = Quaternion.identity;
                    shouldActiveCustomModelObj.transform.SetParent(transform, false);
                    m_activeCustomModel = shouldActiveCustomModelNum;
                    m_customModelObjs[shouldActiveCustomModelNum] = shouldActiveCustomModelObj;
                    m_isCustomModelActivated = false;
                    SendAfterModelCreatedMessage(shouldActiveCustomModelObj, this);
                }

                if (!m_isCustomModelActivated)
                {
                    // active custom override model
                    if (SendBeforeModelActivatedMessage(shouldActiveCustomModelObj, this))
                    {
                        shouldActiveCustomModelObj.gameObject.SetActive(true);
                    }
                    m_isCustomModelActivated = true;
                }
            }

            if (shouldActiveCreator)
            {
                m_activeCreatorIndex = shouldActiveCreatorIndex;
                // update active creator
                m_creators[m_activeCreatorIndex].UpdateRenderModel();
            }

            m_updateModelLock = false;
        }