// PRAGMA MARK - ICommandLoader public ICommand[] Load() { List <T> assets = AssetDatabaseUtil.AllAssetsOfType <T>(); List <ICommand> objects = new List <ICommand>(); foreach (var asset in assets) { objects.Add(new AssetCommand <T>(asset, HandleAssetExecuted)); } return(objects.ToArray()); }
private void SaveDataToEditor() { editArena_.SaveDynamicArenaDataJson(dynamicArenaData_.Serialize()); // if UNITY_EDITOR, check that the asset already exists - use editorUtility to save changes instead #if UNITY_EDITOR string assetsBasedDirectoryPath = "Assets/CustomArenas"; List <ArenaConfig> arenaConfigs = AssetDatabaseUtil.AllAssetsOfType <ArenaConfig>(); if (arenaConfigs.Any(ac => ac == editArena_)) { EditorUtility.SetDirty(editArena_); AssetDatabase.SaveAssets(); return; } // if not new asset, save to new asset int index = 0; string path; do { path = Path.Combine(assetsBasedDirectoryPath, string.Format(kDefaultNameFormat, index)); index++; } while (AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object)) != null); string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path); AssetDatabase.CreateAsset(editArena_, assetPathAndName); AssetDatabase.SaveAssets(); #else string directoryPath = Path.Combine(Application.dataPath, "CustomArenas"); Directory.CreateDirectory(directoryPath); var filenames = new HashSet <string>(Directory.GetFiles(directoryPath)); string filename = editArena_.name; bool findDefaultName = string.IsNullOrEmpty(filename); if (findDefaultName) { int index = 1; do { filename = string.Format("CustomArena{0}", index); index++; } while (filenames.Contains(filename + ".asset")); } File.WriteAllText(Path.Combine(directoryPath, filename + ".asset"), JsonUtility.ToJson(editArena_)); #endif }
// PRAGMA MARK - Static Public Interface public static GoogleTranslate FindAndCreate() { var sources = AssetDatabaseUtil.AllAssetsOfType <GoogleTranslateSource>(); if (sources.Count <= 0) { Debug.LogWarning("No GoogleTranslateSources found in project!"); return(null); } if (sources.Count > 1) { Debug.LogWarning("Multiple GoogleTranslateSources found in project - choosing first!"); } return(sources[0].Create()); }
private void ShowLoadMenu() { MenuView.Hide(); var levelOpenActions = new Dictionary <string, Action>(); #if UNITY_EDITOR var arenaConfigs = AssetDatabaseUtil.AllAssetsOfType <ArenaConfig>(); foreach (var arenaConfig in arenaConfigs) { levelOpenActions[arenaConfig.name] = () => { editArenaCallback_.Invoke(arenaConfig); HideMenu(); }; } #endif // TODO (darren): support loading from custom levels saved outside of editor MenuView.Show(new InputWrapperDevice(inputDevice_), "LOAD LEVEL TO EDIT", levelOpenActions); }
public static void DownloadAndBakeAllUsedLocalizationCharactersIntoFonts() { var charSet = new HashSet <char>(); LocalizationTable[] allTables = UnityEngine.Object.FindObjectsOfType <LocalizationConfiguration>().SelectMany(config => config.TableSources).Select(s => s.LoadTable()).ToArray(); foreach (var table in allTables) { foreach (var culture in table.AllCultures) { var textMap = table.GetTextMapFor(culture); foreach (string translatedText in textMap.Values) { charSet.UnionWith(translatedText); } } } string charactersString = new String(charSet.ToArray()); var bakedFontConfigurations = AssetDatabaseUtil.AllAssetsOfType <BakedLocalizedFontConfiguration>(); if (bakedFontConfigurations.Count <= 0) { Debug.LogWarning("Cannot bake used localization characters without any BakedLocalizedFontConfigurations in the project!"); return; } foreach (var config in bakedFontConfigurations) { // No need to bake a font that already contains all the characters if (TMP_FontAssetUtil.DoesFontContainAllCharacters(config.OutputFontAsset, charactersString)) { continue; } string outputFilePath = AssetDatabase.GetAssetPath(config.OutputFontAsset); TMPFontAssetBaker.Bake(config.Font, config.useAutoSizing, config.FontSize, config.CharacterPadding, config.FontPackingMode, config.AtlasWidth, config.AtlasHeight, config.FontStyle, config.FontStyleMod, config.FontRenderMode, charactersString, outputFilePath); } }
public static IList <ValidationError> Validate(GameObject gameObject) { if (gameObject == null) { return(null); } List <ValidationError> validationErrors = null; Queue <GameObject> queue = new Queue <GameObject>(); queue.Enqueue(gameObject); while (queue.Count > 0) { GameObject current = queue.Dequeue(); Component[] components = current.GetComponents <Component>(); if (components == null) { continue; } foreach (Component c in components) { if (c == null) { continue; } Type componentType = c.GetType(); // allow user defined ignores for namespaces bool inIgnoredNamespace = false; foreach (var validatorIgnoredNamespace in AssetDatabaseUtil.AllAssetsOfType <ValidatorIgnoredNamespace>()) { if (validatorIgnoredNamespace == null) { Debug.LogWarning("Bad state - validatorIgnoredNamespace is null!"); continue; } if (componentType.Namespace == null) { continue; } if (componentType.Namespace.Contains(validatorIgnoredNamespace.Namespace)) { inIgnoredNamespace = true; break; } } if (inIgnoredNamespace) { continue; } foreach (FieldInfo fieldInfo in TypeUtil.GetInspectorFields(componentType) .Where(f => typeof(UnityEventBase).IsAssignableFrom(f.FieldType)) .Where(f => !Attribute.IsDefined(f, typeof(OptionalAttribute)) && !Attribute.IsDefined(f, typeof(HideInInspector)))) { // NOTE (darren): check UnityEvents for all classes UnityEventBase unityEvent = (UnityEventBase)fieldInfo.GetValue(c); if (unityEvent == null) { Debug.LogError("Unexpected null UnityEvent in GameObjectValidator!"); continue; } for (int i = 0; i < unityEvent.GetPersistentEventCount(); i++) { UnityEngine.Object target = unityEvent.GetPersistentTarget(i); string targetMethod = unityEvent.GetPersistentMethodName(i); if (target == null || string.IsNullOrEmpty(targetMethod) || target.GetType().GetMethod(targetMethod) == null) { validationErrors = validationErrors ?? new List <ValidationError>(); validationErrors.Add(new ValidationError(c, componentType, fieldInfo)); break; } } } if (kUnityAssemblies.Contains(componentType.Assembly)) { continue; } foreach (FieldInfo fieldInfo in TypeUtil.GetInspectorFields(componentType) .Where(f => !Attribute.IsDefined(f, typeof(OptionalAttribute)) && !Attribute.IsDefined(f, typeof(HideInInspector)))) { // NOTE (darren): this is to ignore fields that declared in super-classes out of our control (Unity) if (kUnityAssemblies.Contains(fieldInfo.DeclaringType.Assembly)) { continue; } bool isInvalid = fieldInfo.GetUnityEngineObjects(c).Any(o => o == null); if (isInvalid) { validationErrors = validationErrors ?? new List <ValidationError>(); validationErrors.Add(new ValidationError(c, componentType, fieldInfo)); } } } foreach (GameObject child in current.GetChildren()) { queue.Enqueue(child); } } return(validationErrors); }