private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { if (BuildProcessor.Building) { return; } var modifiedResources = false; foreach (string assetPath in importedAssets) { if (AssetDatabase.GetMainAssetTypeAtPath(assetPath) != typeof(Script)) { continue; } if (configuration is null) { configuration = ProjectConfigurationProvider.LoadOrDefault <ScriptsConfiguration>(); } if (editorResources is null) { editorResources = EditorResources.LoadOrDefault(); } HandleAutoAdd(assetPath, ref modifiedResources); } if (modifiedResources) { EditorUtility.SetDirty(editorResources); AssetDatabase.SaveAssets(); } }
private void OnEnable() { var config = ProjectConfigurationProvider.LoadOrDefault <ScriptsConfiguration>(); var state = ScriptGraphState.LoadOrDefault(); var resources = EditorResources.LoadOrDefault(); var records = resources.GetAllRecords(config.Loader.PathPrefix).ToArray(); var scripts = new List <Script>(); for (int i = 0; i < records.Length; i++) { var record = records[i]; var progress = i / (float)records.Length; EditorUtility.DisplayProgressBar(ScriptGraphView.ProgressBarTitle, $"Loading `{record.Key}` script...", progress); var guid = record.Value; var path = AssetDatabase.GUIDToAssetPath(guid); if (string.IsNullOrEmpty(path)) { continue; } var script = AssetDatabase.LoadAssetAtPath <Script>(path); if (!ObjectUtils.IsValid(script)) { continue; } scripts.Add(script); } graphView = new ScriptGraphView(config, state, scripts); graphView.name = "Script Graph"; rootVisualElement.Add(graphView); graphView.StretchToParentSize(); }
private static void HandleEngineInitialized() { if (!(Engine.Behaviour is RuntimeBehaviour)) { return; } if (configuration is null) { configuration = ProjectConfigurationProvider.LoadOrDefault <ScriptsConfiguration>(); } if (editorResources is null) { editorResources = EditorResources.LoadOrDefault(); } if (!configuration.HotReloadScripts) { return; } scriptManager = Engine.GetService <IScriptManager>(); player = Engine.GetService <IScriptPlayer>(); stateManager = Engine.GetService <IStateManager>(); player.OnPlay += HandleStartPlaying; }
public override void OnEnable() { base.OnEnable(); if (config is null) { config = ProjectConfigurationProvider.LoadOrDefault <ScriptsConfiguration>(); } ScriptAsset = assetTarget as Script; scriptText = File.ReadAllText(AssetDatabase.GetAssetPath(ScriptAsset)); if (config.EnableVisualEditor) { VisualEditor = new ScriptView(config, ApplyRevertHackGUI, ApplyAndImportChecked); VisualEditor.GenerateForScript(scriptText, ScriptAsset); ScriptAssetPostprocessor.OnModified += HandleScriptModified; return; } previewContent = scriptText; if (previewContent.Length > previewLengthLimit) { previewContent = previewContent.Substring(0, previewLengthLimit); previewContent += $"{System.Environment.NewLine}<...>"; } labelTags = ScriptAsset.Lines.OfType <LabelScriptLine>().Select(l => new GUIContent($"# {l.LabelText}")).ToArray(); gotoTags = ScriptAsset.ExtractCommands().OfType <Commands.Goto>() .Where(c => !string.IsNullOrEmpty(c.Path.Name)) .Select(c => new GUIContent($"@goto {c.Path.ToString().Replace(".null", "")}")).ToArray(); }
private static void OnApplicationLoaded() { var engineConfig = ProjectConfigurationProvider.LoadOrDefault <EngineConfiguration>(); if (engineConfig.InitializeOnApplicationLoad) { InitializeAsync().Forget(); } }
private static void Initialize() { if (ProjectConfigurationProvider.LoadOrDefault <ResourceProviderConfiguration>().EnableBuildProcessing) { BuildPlayerWindow.RegisterBuildPlayerHandler(BuildHandler); } ProjectResourcesBuildProcessor.TempFolderPath = TempResourcesPath; }
/// <summary> /// Providers configuration of the requested type either via configuration provider /// (when engine is initialized) or by loading the asset from default resources folder. /// </summary> public static T GetOrDefault <T> () where T : Configuration { if (Engine.Initialized) { return(Engine.GetConfiguration <T>()); } else { return(ProjectConfigurationProvider.LoadOrDefault <T>()); } }
private static void SaveConfigurationObject(Configuration configuration) { var generatedDataPath = ProjectConfigurationProvider.LoadOrDefault <EngineConfiguration>().GeneratedDataPath; var dirPath = PathUtils.Combine(Application.dataPath, $"{generatedDataPath}/Resources/{ProjectConfigurationProvider.DefaultResourcesPath}"); var assetPath = PathUtils.AbsoluteToAssetPath(PathUtils.Combine(dirPath, $"{configuration.GetType().Name}.asset")); System.IO.Directory.CreateDirectory(dirPath); AssetDatabase.CreateAsset(configuration, assetPath); AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); }
public static TConfig LoadOrDefaultAndSave <TConfig> () where TConfig : Configuration, new() { var configuration = ProjectConfigurationProvider.LoadOrDefault <TConfig>(); if (!AssetDatabase.Contains(configuration)) { SaveConfigurationObject(configuration); } return(configuration); }
private static void Initialize() { var config = ProjectConfigurationProvider.LoadOrDefault <ScriptsConfiguration>(); if (!config.WatchScripts) { return; } EditorApplication.update += Update; var dataPath = string.IsNullOrEmpty(config.WatchedDirectory) || !Directory.Exists(config.WatchedDirectory) ? Application.dataPath : config.WatchedDirectory; Task.Run(() => StartWatcher(dataPath)) .ContinueWith(StopWatcher, TaskScheduler.FromCurrentSynchronizationContext()); }
public override void OnActivate(string searchContext, VisualElement rootElement) { Configuration = ProjectConfigurationProvider.LoadOrDefault(ConfigurationType); SerializedObject = new SerializedObject(Configuration); keywords = GetSearchKeywordsFromSerializedObject(SerializedObject); // Save the asset in case it was just generated. if (!AssetDatabase.Contains(Configuration)) { SaveConfigurationObject(Configuration); } assetTargets = new[] { Configuration }; }
private static IReadOnlyCollection <Type> GetEngineTypes() { var engineTypes = new List <Type>(1000); var engineConfig = ProjectConfigurationProvider.LoadOrDefault <EngineConfiguration>(); var domainAssemblies = ReflectionUtils.GetDomainAssemblies(true, true, true); foreach (var assemblyName in engineConfig.TypeAssemblies) { var assembly = domainAssemblies.FirstOrDefault(a => a.FullName.StartsWithFast($"{assemblyName},")); if (assembly is null) { continue; } engineTypes.AddRange(assembly.GetExportedTypes()); } return(engineTypes); }
private static void Upgrade198To110() { if (!EditorUtility.DisplayDialog("Perform upgrade?", "Are you sure you want to perform v1.9.8-v1.10 upgrade? Configuration assets will be modified. Make sure to perform a backup before confirming.", "Upgrade", "Cancel")) { return; } var stateConfig = ProjectConfigurationProvider.LoadOrDefault <StateConfiguration>(); stateConfig.GameStateHandler = typeof(IOGameStateSlotManager).AssemblyQualifiedName; stateConfig.GlobalStateHandler = typeof(IOGlobalStateSlotManager).AssemblyQualifiedName; stateConfig.SettingsStateHandler = typeof(IOSettingsSlotManager).AssemblyQualifiedName; EditorUtility.SetDirty(stateConfig); AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); }
/// <summary> /// Loads an existing asset from package data folder or creates a new default instance. /// </summary> public static ScriptGraphState LoadOrDefault() { var generatedDataPath = ProjectConfigurationProvider.LoadOrDefault <EngineConfiguration>().GeneratedDataPath; var directoryPath = PathUtils.Combine(Application.dataPath, generatedDataPath); var assetPath = PathUtils.AbsoluteToAssetPath(PathUtils.Combine(directoryPath, $"{nameof(ScriptGraphState)}.asset")); var obj = AssetDatabase.LoadAssetAtPath <ScriptGraphState>(assetPath); if (!ObjectUtils.IsValid(obj)) { obj = CreateInstance <ScriptGraphState>(); System.IO.Directory.CreateDirectory(directoryPath); AssetDatabase.CreateAsset(obj, assetPath); AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); } return(obj); }
/// <summary> /// Loads an existing asset from package data folder or creates a new default instance. /// </summary> public static EditorResources LoadOrDefault() { var generatedDataPath = ProjectConfigurationProvider.LoadOrDefault <EngineConfiguration>().GeneratedDataPath; var directoryPath = PathUtils.Combine(Application.dataPath, generatedDataPath); var assetPath = PathUtils.AbsoluteToAssetPath(PathUtils.Combine(directoryPath, $"{nameof(EditorResources)}.asset")); var obj = AssetDatabase.LoadAssetAtPath <EditorResources>(assetPath); if (!ObjectUtils.IsValid(obj)) { obj = CreateInstance <EditorResources>(); obj.AddBuiltinAssets(); Directory.CreateDirectory(directoryPath); AssetDatabase.CreateAsset(obj, assetPath); AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); } return(obj); }
private static void Initialize() { ScriptAssetPostprocessor.OnModified += HandleScriptModifiedAsync; Engine.OnInitializationFinished += HandleEngineInitialized; void HandleEngineInitialized() { if (!(Engine.Behaviour is RuntimeBehaviour)) { return; } if (configuration is null) { configuration = ProjectConfigurationProvider.LoadOrDefault <ScriptsConfiguration>(); } scriptManager = Engine.GetService <IScriptManager>(); player = Engine.GetService <IScriptPlayer>(); stateManager = Engine.GetService <IStateManager>(); player.OnPlay += HandleStartPlaying; } }
private static void Upgrade195To196() { if (!EditorUtility.DisplayDialog("Perform upgrade?", "Are you sure you want to perform v1.9.5-v1.9.6 upgrade? Configuration assets will be modified. Make sure to perform a backup before confirming.", "Upgrade", "Cancel")) { return; } // Remove `Naninovel/` path prefixes from config and metadata. var configTypes = ReflectionUtils.ExportedDomainTypes .Where(type => typeof(Configuration).IsAssignableFrom(type) && type.IsClass && !type.IsAbstract); foreach (var configType in configTypes) { var configAsset = ProjectConfigurationProvider.LoadOrDefault(configType); // Root loaders. var rootLoadersInfo = configAsset.GetType().GetFields() .Where(f => f.FieldType == typeof(ResourceLoaderConfiguration)).ToList(); foreach (var rootLoaderInfo in rootLoadersInfo) { ProcessLoader(rootLoaderInfo, rootLoaderInfo.GetValue(configAsset)); } // Default metadata. var defaultMatadataPropertyInfo = configAsset.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance) .Where(p => p.Name == "DefaultActorMetadata").FirstOrDefault(); if (defaultMatadataPropertyInfo != null) { var meta = defaultMatadataPropertyInfo.GetValue(configAsset) as ActorMetadata; var loaderFieldInfo = meta.GetType().GetField(nameof(ActorMetadata.Loader)); ProcessLoader(loaderFieldInfo, meta.Loader); } // Actor metadata. var actorMatadataMapPropertyInfo = configAsset.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance) .Where(p => p.Name == "ActorMetadataMap").FirstOrDefault(); if (actorMatadataMapPropertyInfo != null) { var actorMatadataMap = actorMatadataMapPropertyInfo.GetValue(configAsset); var metasFieldInfo = actorMatadataMap.GetType().GetFieldWithInheritence("metas", BindingFlags.NonPublic | BindingFlags.Instance); var metas = metasFieldInfo.GetValue(actorMatadataMap) as Array; for (int i = 0; i < metas.Length; i++) { var meta = metas.GetValue(i) as ActorMetadata; var loaderFieldInfo = meta.GetType().GetField(nameof(ActorMetadata.Loader)); ProcessLoader(loaderFieldInfo, meta.Loader); } } void ProcessLoader(FieldInfo loaderFieldInfo, object loaderObject) { var prefixFieldInfo = loaderFieldInfo.FieldType.GetField(nameof(ResourceLoaderConfiguration.PathPrefix)); var currentValue = prefixFieldInfo.GetValue(loaderObject) as string; if (!currentValue.Contains("Naninovel/")) { return; } var newValue = currentValue.GetAfter("Naninovel/"); prefixFieldInfo.SetValue(loaderObject, newValue); } EditorUtility.SetDirty(configAsset); } // Remove `Naninovel/` path prefixes from editor resources. var editorResources = EditorResources.LoadOrDefault(); var editorResourcesPath = AssetDatabase.GetAssetPath(editorResources); var editorResourcesText = File.ReadAllText(editorResourcesPath, Encoding.UTF8); editorResourcesText = editorResourcesText.Replace("Naninovel/", string.Empty); File.WriteAllText(editorResourcesPath, editorResourcesText, Encoding.UTF8); AssetDatabase.ImportAsset(editorResourcesPath, ImportAssetOptions.ForceUpdate); AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); }
public static void PreprocessBuild(BuildPlayerOptions options) { config = ProjectConfigurationProvider.LoadOrDefault <ResourceProviderConfiguration>(); useAddressables = AddressableHelper.Available && config.UseAddressables; if (!useAddressables) { Debug.Log("Consider installing the Addressable Asset System (via Unity's package manager) and enabling `Use Addressables` in the Naninovel's `Resource Provider` configuration menu. When the system is not available, all the assets assigned as Naninovel resources and not stored in `Resources` folders will be copied and re-imported when building the player, which could significantly increase the build time."); } if (useAddressables) { AddressableHelper.RemovePreviousEntries(); } EditorUtils.CreateFolderAsset(TempResourcesPath); var records = EditorResources.LoadOrDefault().GetAllRecords(); var projectResources = ProjectResources.Get(); var progress = 0; foreach (var record in records) { progress++; var resourcePath = record.Key; var assetGuid = record.Value; var resourceAssetPath = AssetDatabase.GUIDToAssetPath(assetGuid); if (string.IsNullOrEmpty(resourceAssetPath) || !EditorUtils.AssetExistsByPath(resourceAssetPath)) { Debug.LogWarning($"Failed to resolve `{resourcePath}` asset path from GUID stored in `EditorResources` asset. The resource won't be included to the build."); continue; } var resourceAsset = AssetDatabase.LoadAssetAtPath <Object>(resourceAssetPath); if (string.IsNullOrEmpty(resourceAssetPath)) { Debug.LogWarning($"Failed to load `{resourcePath}` asset. The resource won't be included to the build."); continue; } if (EditorUtility.DisplayCancelableProgressBar("Processing Naninovel Resources", $"Processing '{resourceAssetPath}' asset...", progress / (float)records.Count)) { PostprocessBuild(); // Remove temporary assets. throw new System.OperationCanceledException("Build was cancelled by the user."); } if (resourceAsset is SceneAsset) { ProcessSceneResource(resourcePath, resourceAsset as SceneAsset); } else if (resourceAsset is UnityEngine.Video.VideoClip && options.target == BuildTarget.WebGL) { ProcessVideoResourceForWebGL(resourcePath, resourceAsset); } else { ProcessResourceAsset(assetGuid, resourcePath, resourceAsset, projectResources); } } AssetDatabase.SaveAssets(); if (useAddressables && config.AutoBuildBundles) { EditorUtility.DisplayProgressBar("Processing Naninovel Resources", "Building asset bundles...", 1f); AddressableHelper.RebuildPlayerContent(); } EditorUtility.ClearProgressBar(); }
public ScenePositionPropertyDrawer() { cameraConfiguration = ProjectConfigurationProvider.LoadOrDefault <CameraConfiguration>(); }
private void OnEnable() { editorResources = EditorResources.LoadOrDefault(); audioConfig = ProjectConfigurationProvider.LoadOrDefault <AudioConfiguration>(); UpdateSelectedScript(); }