private static string GetThemeName(AssetSwapUtility.Theme theme, int index) { return(string.IsNullOrEmpty(theme.Name) ? $"Unnamed {index}" : theme.Name); }
private static void SwapObjectReferences(GameObject gameObject, AssetSwapUtility utility, AssetSwapUtility.Theme selectedTheme) { var components = gameObject.GetComponents <Component>(); foreach (var component in components) { if (component == null) { continue; } SerializedObject serializedObject = new SerializedObject(component); SerializedProperty property = serializedObject.GetIterator(); bool modified = false; while (property.NextVisible(true)) { if (property.propertyType == SerializedPropertyType.ObjectReference && property.objectReferenceValue != null) { Object currentAsset = property.objectReferenceValue; // Does the current asset match any non-selected theme(s) asset(s)? if (currentAsset != null) { foreach (var theme in utility.Themes) { if (theme == selectedTheme) { continue; } int assetIndex = 0; foreach (var asset in theme.Assets) { if (asset == currentAsset) { property.objectReferenceValue = selectedTheme.Assets[assetIndex]; modified = true; } ++assetIndex; } } } } } if (modified == true) { property.serializedObject.ApplyModifiedProperties(); } } }
private static void SwapObjectReferencesRecurse(GameObject gameObject, AssetSwapUtility utility, AssetSwapUtility.Theme selectedTheme) { SwapObjectReferences(gameObject, utility, selectedTheme); foreach (Transform child in gameObject.transform) { SwapObjectReferencesRecurse(child.gameObject, utility, selectedTheme); } }
private static void Apply(GameObject[] gameObjects, AssetSwapUtility utility, AssetSwapUtility.Theme selectedTheme, bool recurse) { int progress = 0; foreach (var gameObject in gameObjects) { EditorUtility.DisplayProgressBar("Applying Theme Change", "Please wait...", (float)progress / gameObjects.Length); if (recurse) { SwapObjectReferencesRecurse(gameObject, utility, selectedTheme); } else { SwapObjectReferences(gameObject, utility, selectedTheme); } ++progress; } EditorUtility.ClearProgressBar(); }