Exemplo n.º 1
0
        private void SetUp(Type baseType, Type fallbackType, string actualTypeName, int descriptionIndex)
        {
            if (descriptionIndex == -1)
            {
                Debug.Log("Error descriptionIndex");
                return;
            }
            if (baseType == null || fallbackType == null)
            {
                return;
            }
            if (!VRTK_SharedMethods.IsTypeSubclassOf(baseType, typeof(SDK_Base)))
            {
                VRTK_Logger.Fatal(new ArgumentOutOfRangeException("baseType", baseType, string.Format("'{0}' is not a subclass of the SDK base type '{1}'.", baseType.Name, typeof(SDK_Base).Name)));
                return;
            }

            if (!VRTK_SharedMethods.IsTypeSubclassOf(fallbackType, baseType))
            {
                VRTK_Logger.Fatal(new ArgumentOutOfRangeException("fallbackType", fallbackType, string.Format("'{0}' is not a subclass of the SDK base type '{1}'.", fallbackType.Name, baseType.Name)));
                return;
            }

            baseTypeName     = baseType.FullName;
            fallbackTypeName = fallbackType.FullName;
            typeName         = actualTypeName;

            if (string.IsNullOrEmpty(actualTypeName))
            {
                type = fallbackType;
                originalTypeNameWhenFallbackIsUsed = null;
                this.descriptionIndex = -1;
                description           = new SDK_DescriptionAttribute(typeof(SDK_FallbackSystem));

                return;
            }

            Type actualType = Type.GetType(actualTypeName);

            if (actualType == null)
            {
                type = fallbackType;
                originalTypeNameWhenFallbackIsUsed = actualTypeName;
                this.descriptionIndex = -1;
                description           = new SDK_DescriptionAttribute(typeof(SDK_FallbackSystem));

                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.SDK_NOT_FOUND, actualTypeName, fallbackType.Name));

                return;
            }

            if (!VRTK_SharedMethods.IsTypeSubclassOf(actualType, baseType))
            {
                VRTK_Logger.Fatal(new ArgumentOutOfRangeException("actualTypeName", actualTypeName, string.Format("'{0}' is not a subclass of the SDK base type '{1}'.", actualTypeName, baseType.Name)));
                return;
            }

            SDK_DescriptionAttribute[] descriptions = SDK_DescriptionAttribute.GetDescriptions(actualType);
            if (descriptions.Length <= descriptionIndex)
            {
                VRTK_Logger.Fatal(new ArgumentOutOfRangeException("descriptionIndex", descriptionIndex, string.Format("'{0}' has no '{1}' at that index.", actualTypeName, typeof(SDK_DescriptionAttribute).Name)));
                return;
            }

            type = actualType;
            originalTypeNameWhenFallbackIsUsed = null;
            this.descriptionIndex = descriptionIndex;
            description           = descriptions[descriptionIndex];
        }
Exemplo n.º 2
0
        /// <summary>
        /// Manages (i.e. adds and removes) the scripting define symbols of the <see cref="PlayerSettings"/> for the currently set SDK infos.
        /// This method is only available in the editor, so usage of the method needs to be surrounded by `#if UNITY_EDITOR` and `#endif` when used
        /// in a type that is also compiled for a standalone build.
        /// </summary>
        /// <param name="ignoreAutoManageScriptDefines">Whether to ignore <see cref="autoManageScriptDefines"/> while deciding to manage.</param>
        /// <param name="ignoreIsActiveAndEnabled">Whether to ignore <see cref="Behaviour.isActiveAndEnabled"/> while deciding to manage.</param>
        /// <returns>Whether the <see cref="PlayerSettings"/>' scripting define symbols were changed.</returns>
        public bool ManageScriptingDefineSymbols(bool ignoreAutoManageScriptDefines, bool ignoreIsActiveAndEnabled)
        {
            if (!((ignoreAutoManageScriptDefines || autoManageScriptDefines) && (ignoreIsActiveAndEnabled || isActiveAndEnabled)))
            {
                return(false);
            }

            //get valid BuildTargetGroups
            BuildTargetGroup[] targetGroups = VRTK_SharedMethods.GetValidBuildTargetGroups();
            Dictionary <BuildTargetGroup, HashSet <string> > newSymbolsByTargetGroup = new Dictionary <BuildTargetGroup, HashSet <string> >(targetGroups.Length);

            //get current non-removable scripting define symbols
            foreach (BuildTargetGroup targetGroup in targetGroups)
            {
                IEnumerable <string> nonSDKSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup)
                                                     .Split(';')
                                                     .Where(symbol => !symbol.StartsWith(SDK_ScriptingDefineSymbolPredicateAttribute.RemovableSymbolPrefix, StringComparison.Ordinal));
                newSymbolsByTargetGroup[targetGroup] = new HashSet <string>(nonSDKSymbols);
            }

            VRTK_SDKInfo[] availableSDKInfos = AvailableSystemSDKInfos
                                               .Concat(AvailableBoundariesSDKInfos)
                                               .Concat(AvailableHeadsetSDKInfos)
                                               .Concat(AvailableControllerSDKInfos)
                                               .ToArray();

            HashSet <SDK_DescriptionAttribute> descriptions = new HashSet <SDK_DescriptionAttribute>(
                availableSDKInfos.Select(info => info.description)
                .Where(description => !description.describesFallbackSDK)
                );
            HashSet <string> activeSymbols = new HashSet <string>(activeScriptingDefineSymbolsWithoutSDKClasses.Select(attribute => attribute.symbol));

            //get scripting define symbols and check whether the predicates allow us to add the symbols
            foreach (ScriptingDefineSymbolPredicateInfo predicateInfo in AvailableScriptingDefineSymbolPredicateInfos)
            {
                SDK_ScriptingDefineSymbolPredicateAttribute predicateAttribute = predicateInfo.attribute;
                string symbol = predicateAttribute.symbol;
                if (!activeSymbols.Contains(symbol) &&
                    !descriptions.Any(description => description.symbol == symbol &&
                                      description.buildTargetGroup == predicateAttribute.buildTargetGroup))
                {
                    continue;
                }

                MethodInfo methodInfo = predicateInfo.methodInfo;
                if (!(bool)methodInfo.Invoke(null, null))
                {
                    continue;
                }

                //add symbols from all predicate attributes on the method since multiple ones are allowed
                SDK_ScriptingDefineSymbolPredicateAttribute[] allAttributes = (SDK_ScriptingDefineSymbolPredicateAttribute[])methodInfo.GetCustomAttributes(typeof(SDK_ScriptingDefineSymbolPredicateAttribute), false);
                foreach (SDK_ScriptingDefineSymbolPredicateAttribute attribute in allAttributes)
                {
                    BuildTargetGroup buildTargetGroup = attribute.buildTargetGroup;
                    HashSet <string> newSymbols;
                    if (!newSymbolsByTargetGroup.TryGetValue(buildTargetGroup, out newSymbols))
                    {
                        newSymbols = new HashSet <string>();
                        newSymbolsByTargetGroup[buildTargetGroup] = newSymbols;
                    }

                    newSymbols.Add(attribute.symbol);
                }
            }

            bool changedSymbols = false;

            //apply new set of scripting define symbols
            foreach (KeyValuePair <BuildTargetGroup, HashSet <string> > keyValuePair in newSymbolsByTargetGroup)
            {
                BuildTargetGroup targetGroup    = keyValuePair.Key;
                string[]         currentSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup)
                                                  .Split(';')
                                                  .Distinct()
                                                  .OrderBy(symbol => symbol, StringComparer.Ordinal)
                                                  .ToArray();
                string[] newSymbols = keyValuePair.Value.OrderBy(symbol => symbol, StringComparer.Ordinal).ToArray();

                if (currentSymbols.SequenceEqual(newSymbols))
                {
                    continue;
                }

                PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, string.Join(";", newSymbols));

                string[] removedSymbols = currentSymbols.Except(newSymbols).ToArray();
                if (removedSymbols.Length > 0)
                {
                    VRTK_Logger.Info(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.SCRIPTING_DEFINE_SYMBOLS_REMOVED, targetGroup, string.Join(", ", removedSymbols)));
                }

                string[] addedSymbols = newSymbols.Except(currentSymbols).ToArray();
                if (addedSymbols.Length > 0)
                {
                    VRTK_Logger.Info(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.SCRIPTING_DEFINE_SYMBOLS_ADDED, targetGroup, string.Join(", ", addedSymbols)));
                }

                if (!changedSymbols)
                {
                    changedSymbols = removedSymbols.Length > 0 || addedSymbols.Length > 0;
                }
            }

            return(changedSymbols);
        }
        protected virtual IEnumerator AutoGrab()
        {
            yield return(new WaitForEndOfFrame());

            interactTouch = (interactTouch != null ? interactTouch : GetComponentInParent <VRTK_InteractTouch>());
            interactGrab  = (interactGrab != null ? interactGrab : GetComponentInParent <VRTK_InteractGrab>());

            if (interactTouch == null)
            {
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.REQUIRED_COMPONENT_MISSING_NOT_INJECTED, "VRTK_ObjectAutoGrab", "VRTK_InteractTouch", "interactTouch", "the same or parent"));
            }

            if (interactGrab == null)
            {
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.REQUIRED_COMPONENT_MISSING_NOT_INJECTED, "VRTK_ObjectAutoGrab", "VRTK_InteractGrab", "interactGrab", "the same or parent"));
            }

            if (objectToGrab == null)
            {
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.NOT_DEFINED, "objectToGrab"));
                yield break;
            }

            while (interactGrab.controllerAttachPoint == null)
            {
                yield return(true);
            }

            bool grabbableObjectDisableState = objectToGrab.disableWhenIdle;

            if (objectIsPrefab)
            {
                objectToGrab.disableWhenIdle = false;
            }

            VRTK_InteractableObject grabbableObject = objectToGrab;

            if (alwaysCloneOnEnable)
            {
                ClearPreviousClone();
            }

            if (!interactGrab.GetGrabbedObject())
            {
                if (cloneGrabbedObject)
                {
                    if (previousClonedObject == null)
                    {
                        grabbableObject      = Instantiate(objectToGrab);
                        previousClonedObject = grabbableObject;
                    }
                    else
                    {
                        grabbableObject = previousClonedObject;
                    }
                }

                if (grabbableObject.isGrabbable && !grabbableObject.IsGrabbed())
                {
                    grabbableObject.transform.position = transform.position;
                    interactTouch.ForceStopTouching();
                    interactTouch.ForceTouch(grabbableObject.gameObject);
                    interactGrab.AttemptGrab();
                    OnObjectAutoGrabCompleted();
                }
            }
            objectToGrab.disableWhenIdle    = grabbableObjectDisableState;
            grabbableObject.disableWhenIdle = grabbableObjectDisableState;
        }
Exemplo n.º 4
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            VRTK_SDKManager sdkManager = (VRTK_SDKManager)target;

            EditorGUILayout.PropertyField(serializedObject.FindProperty("persistOnLoad"));

            const string manageNowButtonText = "Manage Now";

            using (new EditorGUILayout.VerticalScope("Box"))
            {
                VRTK_EditorUtilities.AddHeader("Scripting Define Symbols", false);

                using (new EditorGUILayout.HorizontalScope())
                {
                    EditorGUI.BeginChangeCheck();
                    bool autoManage = EditorGUILayout.Toggle(
                        VRTK_EditorUtilities.BuildGUIContent <VRTK_SDKManager>("autoManageScriptDefines", "Auto Manage"),
                        sdkManager.autoManageScriptDefines,
                        GUILayout.ExpandWidth(false)
                        );
                    if (EditorGUI.EndChangeCheck())
                    {
                        serializedObject.FindProperty("autoManageScriptDefines").boolValue = autoManage;
                        serializedObject.ApplyModifiedProperties();
                        sdkManager.ManageScriptingDefineSymbols(false, true);
                    }

                    using (new EditorGUI.DisabledGroupScope(sdkManager.autoManageScriptDefines))
                    {
                        GUIContent manageNowGUIContent = new GUIContent(
                            manageNowButtonText,
                            "Manage the scripting define symbols defined by the installed SDKs."
                            + (sdkManager.autoManageScriptDefines
                                   ? "\n\nThis button is disabled because the SDK Manager is set up to manage the scripting define symbols automatically."
                               + " Disable the checkbox on the left to allow managing them manually instead."
                                   : "")
                            );
                        if (GUILayout.Button(manageNowGUIContent, GUILayout.MaxHeight(GUI.skin.label.CalcSize(manageNowGUIContent).y)))
                        {
                            sdkManager.ManageScriptingDefineSymbols(true, true);
                        }
                    }
                }

                using (new EditorGUILayout.VerticalScope("Box"))
                {
                    VRTK_EditorUtilities.AddHeader("Active Symbols Without SDK Classes", false);

                    VRTK_SDKInfo[] availableSDKInfos = VRTK_SDKManager
                                                       .AvailableSystemSDKInfos
                                                       .Concat(VRTK_SDKManager.AvailableBoundariesSDKInfos)
                                                       .Concat(VRTK_SDKManager.AvailableHeadsetSDKInfos)
                                                       .Concat(VRTK_SDKManager.AvailableControllerSDKInfos)
                                                       .ToArray();
                    HashSet <string> sdkSymbols = new HashSet <string>(availableSDKInfos.Select(info => info.description.symbol));
                    IGrouping <BuildTargetGroup, VRTK_SDKManager.ScriptingDefineSymbolPredicateInfo>[] availableGroupedPredicateInfos = VRTK_SDKManager
                                                                                                                                        .AvailableScriptingDefineSymbolPredicateInfos
                                                                                                                                        .GroupBy(info => info.attribute.buildTargetGroup)
                                                                                                                                        .ToArray();
                    foreach (IGrouping <BuildTargetGroup, VRTK_SDKManager.ScriptingDefineSymbolPredicateInfo> grouping in availableGroupedPredicateInfos)
                    {
                        VRTK_SDKManager.ScriptingDefineSymbolPredicateInfo[] possibleActiveInfos = grouping
                                                                                                   .Where(info => !sdkSymbols.Contains(info.attribute.symbol) &&
                                                                                                          grouping.Except(new[] { info })
                                                                                                          .All(predicateInfo => !(predicateInfo.methodInfo == info.methodInfo &&
                                                                                                                                  sdkSymbols.Contains(predicateInfo.attribute.symbol))))
                                                                                                   .OrderBy(info => info.attribute.symbol)
                                                                                                   .ToArray();
                        if (possibleActiveInfos.Length == 0)
                        {
                            continue;
                        }

                        EditorGUI.indentLevel++;

                        BuildTargetGroup targetGroup = grouping.Key;
                        isBuildTargetActiveSymbolsFoldOut[targetGroup] = EditorGUI.Foldout(
                            EditorGUILayout.GetControlRect(),
                            isBuildTargetActiveSymbolsFoldOut[targetGroup],
                            targetGroup.ToString(),
                            true
                            );

                        if (isBuildTargetActiveSymbolsFoldOut[targetGroup])
                        {
                            foreach (VRTK_SDKManager.ScriptingDefineSymbolPredicateInfo predicateInfo in possibleActiveInfos)
                            {
                                int symbolIndex = sdkManager
                                                  .activeScriptingDefineSymbolsWithoutSDKClasses
                                                  .FindIndex(attribute => attribute.symbol == predicateInfo.attribute.symbol);
                                string symbolLabel = predicateInfo.attribute.symbol.Remove(
                                    0,
                                    SDK_ScriptingDefineSymbolPredicateAttribute.RemovableSymbolPrefix.Length
                                    );

                                if (!(bool)predicateInfo.methodInfo.Invoke(null, null))
                                {
                                    symbolLabel += " (not installed)";
                                }

                                EditorGUI.BeginChangeCheck();
                                bool isSymbolActive = EditorGUILayout.ToggleLeft(symbolLabel, symbolIndex != -1);
                                if (EditorGUI.EndChangeCheck())
                                {
                                    Undo.RecordObject(sdkManager, "Active Symbol Change");
                                    if (isSymbolActive)
                                    {
                                        sdkManager.activeScriptingDefineSymbolsWithoutSDKClasses.Add(predicateInfo.attribute);
                                    }
                                    else
                                    {
                                        sdkManager.activeScriptingDefineSymbolsWithoutSDKClasses.RemoveAt(symbolIndex);
                                    }
                                    sdkManager.ManageScriptingDefineSymbols(false, true);
                                }
                            }
                        }

                        EditorGUI.indentLevel--;
                    }
                }

                VRTK_EditorUtilities.DrawUsingDestructiveStyle(GUI.skin.button, style =>
                {
                    GUIContent clearSymbolsGUIContent = new GUIContent(
                        "Remove All Symbols",
                        "Remove all scripting define symbols of VRTK. This is handy if you removed the SDK files from your project but still have"
                        + " the symbols defined which results in compile errors."
                        + "\nIf you have the above checkbox enabled the symbols will be managed automatically after clearing them. Otherwise hit the"
                        + " '" + manageNowButtonText + "' button to add the symbols for the currently installed SDKs again."
                        );

                    if (GUILayout.Button(clearSymbolsGUIContent, style))
                    {
                        BuildTargetGroup[] targetGroups = VRTK_SharedMethods.GetValidBuildTargetGroups();

                        foreach (BuildTargetGroup targetGroup in targetGroups)
                        {
                            string[] currentSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup)
                                                      .Split(';')
                                                      .Distinct()
                                                      .OrderBy(symbol => symbol, StringComparer.Ordinal)
                                                      .ToArray();
                            string[] newSymbols = currentSymbols
                                                  .Where(symbol => !symbol.StartsWith(SDK_ScriptingDefineSymbolPredicateAttribute.RemovableSymbolPrefix, StringComparison.Ordinal))
                                                  .ToArray();

                            if (currentSymbols.SequenceEqual(newSymbols))
                            {
                                continue;
                            }

                            PlayerSettings.SetScriptingDefineSymbolsForGroup(targetGroup, string.Join(";", newSymbols));

                            string[] removedSymbols = currentSymbols.Except(newSymbols).ToArray();
                            if (removedSymbols.Length > 0)
                            {
                                VRTK_Logger.Info(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.SCRIPTING_DEFINE_SYMBOLS_REMOVED, targetGroup, string.Join(", ", removedSymbols)));
                            }
                        }
                    }
                });
            }

            using (new EditorGUILayout.VerticalScope("Box"))
            {
                VRTK_EditorUtilities.AddHeader("Script Aliases", false);
                EditorGUILayout.PropertyField(
                    serializedObject.FindProperty("scriptAliasLeftController"),
                    VRTK_EditorUtilities.BuildGUIContent <VRTK_SDKManager>("scriptAliasLeftController", "Left Controller")
                    );
                EditorGUILayout.PropertyField(
                    serializedObject.FindProperty("scriptAliasRightController"),
                    VRTK_EditorUtilities.BuildGUIContent <VRTK_SDKManager>("scriptAliasRightController", "Right Controller")
                    );
            }

            using (new EditorGUILayout.VerticalScope("Box"))
            {
                VRTK_EditorUtilities.AddHeader("Setups", false);

                using (new EditorGUILayout.HorizontalScope())
                {
                    EditorGUI.BeginChangeCheck();
                    bool autoManage = EditorGUILayout.Toggle(
                        VRTK_EditorUtilities.BuildGUIContent <VRTK_SDKManager>("autoManageVRSettings"),
                        sdkManager.autoManageVRSettings,
                        GUILayout.ExpandWidth(false)
                        );
                    if (EditorGUI.EndChangeCheck())
                    {
                        serializedObject.FindProperty("autoManageVRSettings").boolValue = autoManage;
                        serializedObject.ApplyModifiedProperties();
                        sdkManager.ManageVRSettings(false);
                    }

                    using (new EditorGUI.DisabledGroupScope(sdkManager.autoManageVRSettings))
                    {
                        GUIContent manageNowGUIContent = new GUIContent(
                            manageNowButtonText,
                            "Manage the VR settings of the Player Settings to allow for all the installed SDKs."
                            + (sdkManager.autoManageVRSettings
                                   ? "\n\nThis button is disabled because the SDK Manager is set up to manage the VR Settings automatically."
                               + " Disable the checkbox on the left to allow managing them manually instead."
                                   : "")
                            );
                        if (GUILayout.Button(manageNowGUIContent, GUILayout.MaxHeight(GUI.skin.label.CalcSize(manageNowGUIContent).y)))
                        {
                            sdkManager.ManageVRSettings(true);
                        }
                    }
                }

                EditorGUILayout.PropertyField(
                    serializedObject.FindProperty("autoLoadSetup"),
                    VRTK_EditorUtilities.BuildGUIContent <VRTK_SDKManager>("autoLoadSetup", "Auto Load")
                    );

                setupsList.DoLayoutList();

                GUIContent autoPopulateGUIContent = new GUIContent("Auto Populate", "Automatically populates the list of SDK Setups with Setups in the scene.");
                if (GUILayout.Button(autoPopulateGUIContent))
                {
                    SerializedProperty serializedProperty = setupsList.serializedProperty;
                    serializedProperty.ClearArray();
                    VRTK_SDKSetup[] setups = sdkManager.GetComponentsInChildren <VRTK_SDKSetup>(true)
                                             .Concat(VRTK_SharedMethods.FindEvenInactiveComponents <VRTK_SDKSetup>())
                                             .Distinct()
                                             .ToArray();

                    for (int index = 0; index < setups.Length; index++)
                    {
                        VRTK_SDKSetup setup = setups[index];
                        serializedProperty.InsertArrayElementAtIndex(index);
                        serializedProperty.GetArrayElementAtIndex(index).objectReferenceValue = setup;
                    }
                }

                if (sdkManager.setups.Length > 1)
                {
                    EditorGUILayout.HelpBox("Duplicated setups are removed automatically.", MessageType.Info);
                }

                if (Enumerable.Range(0, sdkManager.setups.Length).Any(IsSDKSetupNeverUsed))
                {
                    EditorGUILayout.HelpBox("Gray setups will never be loaded because either the SDK Setup isn't valid or there"
                                            + " is a valid Setup before it that uses any non-VR SDK.",
                                            MessageType.Warning);
                }
            }

            using (new EditorGUILayout.VerticalScope("Box"))
            {
                VRTK_EditorUtilities.AddHeader("Target Platform Group Exclusions", false);
                SerializedProperty excludeTargetGroups = serializedObject.FindProperty("excludeTargetGroups");
                excludeTargetGroups.arraySize = EditorGUILayout.IntField("Size", excludeTargetGroups.arraySize);
                for (int i = 0; i < excludeTargetGroups.arraySize; i++)
                {
                    EditorGUILayout.PropertyField(excludeTargetGroups.GetArrayElementAtIndex(i));
                }
            }

            serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 5
0
        // Token: 0x060016BB RID: 5819 RVA: 0x0007AA4A File Offset: 0x00078C4A
        protected virtual IEnumerator AutoGrab()
        {
            yield return(new WaitForEndOfFrame());

            this.interactTouch = ((this.interactTouch != null) ? this.interactTouch : base.GetComponentInParent <VRTK_InteractTouch>());
            this.interactGrab  = ((this.interactGrab != null) ? this.interactGrab : base.GetComponentInParent <VRTK_InteractGrab>());
            if (this.interactTouch == null)
            {
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.REQUIRED_COMPONENT_MISSING_NOT_INJECTED, new object[]
                {
                    "VRTK_ObjectAutoGrab",
                    "VRTK_InteractTouch",
                    "interactTouch",
                    "the same or parent"
                }));
            }
            if (this.interactGrab == null)
            {
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.REQUIRED_COMPONENT_MISSING_NOT_INJECTED, new object[]
                {
                    "VRTK_ObjectAutoGrab",
                    "VRTK_InteractGrab",
                    "interactGrab",
                    "the same or parent"
                }));
            }
            if (this.objectToGrab == null)
            {
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.NOT_DEFINED, new object[]
                {
                    "objectToGrab"
                }));
                yield break;
            }
            while (this.interactGrab.controllerAttachPoint == null)
            {
                yield return(true);
            }
            bool disableWhenIdle = this.objectToGrab.disableWhenIdle;

            if (this.objectIsPrefab)
            {
                this.objectToGrab.disableWhenIdle = false;
            }
            VRTK_InteractableObject vrtk_InteractableObject = this.objectToGrab;

            if (this.alwaysCloneOnEnable)
            {
                this.ClearPreviousClone();
            }
            if (!this.interactGrab.GetGrabbedObject())
            {
                if (this.cloneGrabbedObject)
                {
                    if (this.previousClonedObject == null)
                    {
                        vrtk_InteractableObject   = Object.Instantiate <VRTK_InteractableObject>(this.objectToGrab);
                        this.previousClonedObject = vrtk_InteractableObject;
                    }
                    else
                    {
                        vrtk_InteractableObject = this.previousClonedObject;
                    }
                }
                if (vrtk_InteractableObject.isGrabbable && !vrtk_InteractableObject.IsGrabbed(null))
                {
                    vrtk_InteractableObject.transform.position = base.transform.position;
                    this.interactTouch.ForceStopTouching();
                    this.interactTouch.ForceTouch(vrtk_InteractableObject.gameObject);
                    this.interactGrab.AttemptGrab();
                    this.OnObjectAutoGrabCompleted();
                }
            }
            this.objectToGrab.disableWhenIdle       = disableWhenIdle;
            vrtk_InteractableObject.disableWhenIdle = disableWhenIdle;
            yield break;
        }
Exemplo n.º 6
0
        private void SetUp(Type baseType, Type fallbackType, string actualTypeName)
        {
#if NETFX_CORE
            if (!baseType.GetTypeInfo().IsSubclassOf(typeof(SDK_Base)))
#else
            if (!baseType.IsSubclassOf(typeof(SDK_Base)))
#endif
            {
                throw new ArgumentOutOfRangeException("baseType", baseType, string.Format("'{0}' is not a subclass of the SDK base type '{1}'.", baseType.Name, typeof(SDK_Base).Name));
            }

#if NETFX_CORE
            if (!fallbackType.GetTypeInfo().IsSubclassOf(baseType))
#else
            if (!fallbackType.IsSubclassOf(baseType))
#endif
            {
                throw new ArgumentOutOfRangeException("fallbackType", fallbackType, string.Format("'{0}' is not a subclass of the SDK base type '{1}'.", fallbackType.Name, baseType.Name));
            }

            baseTypeName = baseType.FullName;
            fallbackTypeName = fallbackType.FullName;
            typeName = actualTypeName;

            if (string.IsNullOrEmpty(actualTypeName))
            {
                type = fallbackType;
                originalTypeNameWhenFallbackIsUsed = null;
                description = SDK_DescriptionAttribute.Fallback;

                return;
            }

            Type actualType = Type.GetType(actualTypeName);
            if (actualType == null)
            {
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.SDK_NOT_FOUND, new string[] { actualTypeName, fallbackType.Name }));

                type = fallbackType;
                originalTypeNameWhenFallbackIsUsed = actualTypeName;
                description = SDK_DescriptionAttribute.Fallback;

                return;
            }
#if NETFX_CORE
            if (!actualType.GetTypeInfo().IsSubclassOf(baseType))
#else
            if (!actualType.IsSubclassOf(baseType))
#endif
            {
                throw new ArgumentOutOfRangeException("actualTypeName", actualTypeName, string.Format("'{0}' is not a subclass of the SDK base type '{1}'.", actualTypeName, baseType.Name));
            }

            string fallbackNamespace = typeof(SDK_FallbackSystem).Namespace;
            string fallbackNamePrefix = typeof(SDK_FallbackSystem).Name.Replace("System", "");
            if (actualType.Namespace == fallbackNamespace && actualType.Name.StartsWith(fallbackNamePrefix, StringComparison.Ordinal))
            {
                type = actualType;
                originalTypeNameWhenFallbackIsUsed = null;
                description = SDK_DescriptionAttribute.Fallback;

                return;
            }

#if NETFX_CORE
            // https://stackoverflow.com/a/12814920
            var actualDescription = (SDK_DescriptionAttribute)actualType.GetTypeInfo().GetCustomAttributes<SDK_DescriptionAttribute>().FirstOrDefault();
#else
            var actualDescription = (SDK_DescriptionAttribute)actualType.GetCustomAttributes(typeof(SDK_DescriptionAttribute), false).FirstOrDefault();
#endif
            if (actualDescription == null)
            {
                throw new ArgumentException(string.Format("'{0}' doesn't specify an SDK description via '{1}'.", actualTypeName, typeof(SDK_DescriptionAttribute).Name), "actualTypeName");
            }

            type = actualType;
            originalTypeNameWhenFallbackIsUsed = null;
            description = actualDescription;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Returns an error description in case any of these are true for the current SDK info:
        /// <list type="bullet">
        /// <item> <description>Its type doesn't exist anymore.</description> </item>
        /// <item> <description>It's a fallback SDK.</description> </item>
        /// <item> <description>It doesn't have its scripting define symbols added.</description> </item>
        /// <item> <description>It's missing its vendor SDK.</description> </item>
        /// </list>
        /// </summary>
        /// <typeparam name="BaseType">The SDK base type of which to return the error description for. Must be a subclass of SDK_Base.</typeparam>
        /// <param name="prettyName">The pretty name of the base SDK to use when returning error descriptions.</param>
        /// <param name="info">The SDK info of which to return the error description for.</param>
        /// <param name="installedInfos">The installed SDK infos.</param>
        /// <returns>An error description if there is one, else `null`.</returns>
        private static string GetSDKErrorDescription <BaseType>(string prettyName, VRTK_SDKInfo info, IEnumerable <VRTK_SDKInfo> installedInfos) where BaseType : SDK_Base
        {
            Type selectedType = info.type;
            Type baseType     = typeof(BaseType);
            Type fallbackType = VRTK_SDKManager.SDKFallbackTypesByBaseType[baseType];

            if (selectedType == fallbackType)
            {
                return(string.Format("The fallback {0} SDK is being used because there is no other {0} SDK set in the SDK Setup.", prettyName));
            }

            if (!VRTK_SharedMethods.IsTypeAssignableFrom(baseType, selectedType) || VRTK_SharedMethods.IsTypeAssignableFrom(fallbackType, selectedType))
            {
                string description = string.Format("The fallback {0} SDK is being used despite being set to '{1}'.", prettyName, selectedType.Name);

                if (installedInfos.Select(installedInfo => installedInfo.type).Contains(selectedType))
                {
                    return(description + " Its needed scripting define symbols are not added. You can click the GameObject with the `VRTK_SDKManager` script attached to it in Edit Mode and choose to automatically let the manager handle the scripting define symbols." + VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.SCRIPTING_DEFINE_SYMBOLS_NOT_FOUND));
                }

                return(description + " The needed vendor SDK isn't installed.");
            }

            return(null);
        }
        private void Start()
        {
            if (GetComponent <VRTK_ControllerEvents> () == null)
            {
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.REQUIRED_COMPONENT_MISSING_FROM_GAMEOBJECT, "VRTK_ControllerEvents_ListenerExample", "VRTK_ControllerEvents", "the same"));
                return;
            }

            //Setup controller event listeners
            GetComponent <VRTK_ControllerEvents> ().TriggerPressed  += new ControllerInteractionEventHandler(DoTriggerPressed);
            GetComponent <VRTK_ControllerEvents> ().TriggerReleased += new ControllerInteractionEventHandler(DoTriggerReleased);

            GetComponent <VRTK_ControllerEvents> ().TriggerTouchStart += new ControllerInteractionEventHandler(DoTriggerTouchStart);
            GetComponent <VRTK_ControllerEvents> ().TriggerTouchEnd   += new ControllerInteractionEventHandler(DoTriggerTouchEnd);

            GetComponent <VRTK_ControllerEvents> ().TriggerHairlineStart += new ControllerInteractionEventHandler(DoTriggerHairlineStart);
            GetComponent <VRTK_ControllerEvents> ().TriggerHairlineEnd   += new ControllerInteractionEventHandler(DoTriggerHairlineEnd);

            GetComponent <VRTK_ControllerEvents> ().TriggerClicked   += new ControllerInteractionEventHandler(DoTriggerClicked);
            GetComponent <VRTK_ControllerEvents> ().TriggerUnclicked += new ControllerInteractionEventHandler(DoTriggerUnclicked);

            GetComponent <VRTK_ControllerEvents> ().TriggerAxisChanged += new ControllerInteractionEventHandler(DoTriggerAxisChanged);

            GetComponent <VRTK_ControllerEvents> ().GripPressed  += new ControllerInteractionEventHandler(DoGripPressed);
            GetComponent <VRTK_ControllerEvents> ().GripReleased += new ControllerInteractionEventHandler(DoGripReleased);

            GetComponent <VRTK_ControllerEvents> ().GripTouchStart += new ControllerInteractionEventHandler(DoGripTouchStart);
            GetComponent <VRTK_ControllerEvents> ().GripTouchEnd   += new ControllerInteractionEventHandler(DoGripTouchEnd);

            GetComponent <VRTK_ControllerEvents> ().GripHairlineStart += new ControllerInteractionEventHandler(DoGripHairlineStart);
            GetComponent <VRTK_ControllerEvents> ().GripHairlineEnd   += new ControllerInteractionEventHandler(DoGripHairlineEnd);

            GetComponent <VRTK_ControllerEvents> ().GripClicked   += new ControllerInteractionEventHandler(DoGripClicked);
            GetComponent <VRTK_ControllerEvents> ().GripUnclicked += new ControllerInteractionEventHandler(DoGripUnclicked);

            GetComponent <VRTK_ControllerEvents> ().GripAxisChanged += new ControllerInteractionEventHandler(DoGripAxisChanged);

            GetComponent <VRTK_ControllerEvents> ().TouchpadPressed  += new ControllerInteractionEventHandler(DoTouchpadPressed);
            GetComponent <VRTK_ControllerEvents> ().TouchpadReleased += new ControllerInteractionEventHandler(DoTouchpadReleased);

            GetComponent <VRTK_ControllerEvents> ().TouchpadTouchStart += new ControllerInteractionEventHandler(DoTouchpadTouchStart);
            GetComponent <VRTK_ControllerEvents> ().TouchpadTouchEnd   += new ControllerInteractionEventHandler(DoTouchpadTouchEnd);

            GetComponent <VRTK_ControllerEvents> ().TouchpadAxisChanged += new ControllerInteractionEventHandler(DoTouchpadAxisChanged);

            GetComponent <VRTK_ControllerEvents> ().ButtonOnePressed  += new ControllerInteractionEventHandler(DoButtonOnePressed);
            GetComponent <VRTK_ControllerEvents> ().ButtonOneReleased += new ControllerInteractionEventHandler(DoButtonOneReleased);

            GetComponent <VRTK_ControllerEvents> ().ButtonOneTouchStart += new ControllerInteractionEventHandler(DoButtonOneTouchStart);
            GetComponent <VRTK_ControllerEvents> ().ButtonOneTouchEnd   += new ControllerInteractionEventHandler(DoButtonOneTouchEnd);

            GetComponent <VRTK_ControllerEvents> ().ButtonTwoPressed  += new ControllerInteractionEventHandler(DoButtonTwoPressed);
            GetComponent <VRTK_ControllerEvents> ().ButtonTwoReleased += new ControllerInteractionEventHandler(DoButtonTwoReleased);

            GetComponent <VRTK_ControllerEvents> ().ButtonTwoTouchStart += new ControllerInteractionEventHandler(DoButtonTwoTouchStart);
            GetComponent <VRTK_ControllerEvents> ().ButtonTwoTouchEnd   += new ControllerInteractionEventHandler(DoButtonTwoTouchEnd);

            GetComponent <VRTK_ControllerEvents> ().StartMenuPressed  += new ControllerInteractionEventHandler(DoStartMenuPressed);
            GetComponent <VRTK_ControllerEvents> ().StartMenuReleased += new ControllerInteractionEventHandler(DoStartMenuReleased);

            GetComponent <VRTK_ControllerEvents> ().ControllerEnabled  += new ControllerInteractionEventHandler(DoControllerEnabled);
            GetComponent <VRTK_ControllerEvents> ().ControllerDisabled += new ControllerInteractionEventHandler(DoControllerDisabled);

            GetComponent <VRTK_ControllerEvents> ().ControllerIndexChanged += new ControllerInteractionEventHandler(DoControllerIndexChanged);
        }