protected virtual void ToggleObject()
 {
     if (target is GameObject)
     {
         ToggleGameObject();
     }
     else if (VRTK_SharedMethods.IsTypeSubclassOf(target.GetType(), typeof(Component)))
     {
         ToggleComponent();
     }
 }
Exemplo n.º 2
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];
        }