/// <summary> /// Constructs a new instance with the specified predicate attribute and associated method info. /// </summary> /// <param name="attribute">The predicate attribute.</param> /// <param name="methodInfo">The method info of the method the attribute is defined on.</param> public ScriptingDefineSymbolPredicateInfo(SDK_ScriptingDefineSymbolPredicateAttribute attribute, MethodInfo methodInfo) { this.attribute = attribute; this.methodInfo = methodInfo; }
/// <summary> /// Creates a new attribute by copying an existing one. /// </summary> /// <param name="attributeToCopy">The attribute to copy.</param> public SDK_ScriptingDefineSymbolPredicateAttribute(SDK_ScriptingDefineSymbolPredicateAttribute attributeToCopy) { symbol = attributeToCopy.symbol; SetBuildTarget(attributeToCopy.buildTargetGroupName); }
/// <summary> /// Manages (i.e. adds and removes) the scripting define symbols of the 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 `autoManageScriptDefines` while deciding to manage.</param> /// <param name="ignoreIsActiveAndEnabled">Whether to ignore `Behaviour.isActiveAndEnabled` while deciding to manage.</param> /// <returns>Whether the 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); }
} // 0x0000000180289A80-0x0000000180289A90 public SDK_ScriptingDefineSymbolPredicateAttribute(SDK_ScriptingDefineSymbolPredicateAttribute attributeToCopy) { } // 0x0000000181BA6390-0x0000000181BA63E0