Beispiel #1
0
        public static void PreprocessBuild(BuildPlayerOptions options)
        {
            config = Configuration.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();
        }
Beispiel #2
0
 private void OnEnable()
 {
     editorResources = EditorResources.LoadOrDefault();
     audioConfig     = ProjectConfigurationProvider.LoadOrDefault <AudioConfiguration>();
     UpdateSelectedScript();
 }
Beispiel #3
0
        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();
        }
Beispiel #4
0
        protected override Dictionary <string, Action <SerializedProperty> > OverrideConfigurationDrawers()
        {
            var drawers = base.OverrideConfigurationDrawers();

            drawers[nameof(ScriptsConfiguration.ScriptParser)]         = p => DrawImplementationDropdown(p, parserImplementations, parserImplementationLabels);
            drawers[nameof(ScriptsConfiguration.InitializationScript)] = p => EditorResources.DrawPathPopup(p, ResourcesCategoryId, ResourcesPathPrefix, "None (disabled)");
            drawers[nameof(ScriptsConfiguration.TitleScript)]          = p => EditorResources.DrawPathPopup(p, ResourcesCategoryId, ResourcesPathPrefix, "None (disabled)");
            drawers[nameof(ScriptsConfiguration.StartGameScript)]      = p => EditorResources.DrawPathPopup(p, ResourcesCategoryId, ResourcesPathPrefix);
            drawers[nameof(ScriptsConfiguration.WatchedDirectory)]     = p => { if (Configuration.WatchScripts)
                                                                                {
                                                                                    EditorUtils.FolderField(p);
                                                                                }
            };
            drawers[nameof(ScriptsConfiguration.ExternalLoader)] = p => { if (Configuration.EnableCommunityModding)
                                                                          {
                                                                              EditorGUILayout.PropertyField(p);
                                                                          }
            };
            drawers[nameof(ScriptsConfiguration.ShowNavigatorOnInit)] = p => { if (Configuration.EnableNavigator)
                                                                               {
                                                                                   EditorGUILayout.PropertyField(p);
                                                                               }
            };
            drawers[nameof(ScriptsConfiguration.NavigatorSortOrder)] = p => { if (Configuration.EnableNavigator)
                                                                              {
                                                                                  EditorGUILayout.PropertyField(p);
                                                                              }
            };
            drawers[nameof(ScriptsConfiguration.HideUnusedParameters)] = p => { if (Configuration.EnableVisualEditor)
                                                                                {
                                                                                    EditorGUILayout.PropertyField(p);
                                                                                }
            };
            drawers[nameof(ScriptsConfiguration.InsertLineKey)] = p => { if (Configuration.EnableVisualEditor)
                                                                         {
                                                                             EditorGUILayout.PropertyField(p);
                                                                         }
            };
            drawers[nameof(ScriptsConfiguration.InsertLineModifier)] = p => { if (Configuration.EnableVisualEditor)
                                                                              {
                                                                                  EditorGUILayout.PropertyField(p);
                                                                              }
            };
            drawers[nameof(ScriptsConfiguration.SaveScriptKey)] = p => { if (Configuration.EnableVisualEditor)
                                                                         {
                                                                             EditorGUILayout.PropertyField(p);
                                                                         }
            };
            drawers[nameof(ScriptsConfiguration.SaveScriptModifier)] = p => { if (Configuration.EnableVisualEditor)
                                                                              {
                                                                                  EditorGUILayout.PropertyField(p);
                                                                              }
            };
            drawers[nameof(ScriptsConfiguration.EditorPageLength)] = p => { if (Configuration.EnableVisualEditor)
                                                                            {
                                                                                EditorGUILayout.PropertyField(p);
                                                                            }
            };
            drawers[nameof(ScriptsConfiguration.EditorCustomStyleSheet)] = p => { if (Configuration.EnableVisualEditor)
                                                                                  {
                                                                                      EditorGUILayout.PropertyField(p);
                                                                                  }
            };
            return(drawers);
        }
Beispiel #5
0
        protected override Dictionary <string, Action <SerializedProperty> > OverrideMetaDrawers()
        {
            var drawers = base.OverrideMetaDrawers();

            drawers[nameof(CharacterMetadata.CustomShader)] = p => { if (ResourcesTypeConstraint != null && ResourcesTypeConstraint != typeof(GenericCharacterBehaviour))
                                                                     {
                                                                         EditorGUILayout.PropertyField(p);
                                                                     }
            };
            drawers[nameof(CharacterMetadata.RenderTexture)] = p => { if (ResourcesTypeConstraint != null && ResourcesTypeConstraint != typeof(GenericCharacterBehaviour))
                                                                      {
                                                                          EditorGUILayout.PropertyField(p);
                                                                      }
            };
            drawers[nameof(CharacterMetadata.CorrectRenderAspect)] = p => { if (ResourcesTypeConstraint != typeof(GenericCharacterBehaviour) && EditedMetadata.RenderTexture)
                                                                            {
                                                                                EditorGUILayout.PropertyField(p);
                                                                            }
            };
            drawers[nameof(CharacterMetadata.BakedLookDirection)] = p => { if (ResourcesTypeConstraint != null)
                                                                           {
                                                                               EditorGUILayout.PropertyField(p);
                                                                           }
            };
            drawers[nameof(CharacterMetadata.NameColor)] = p => { if (EditedMetadata.UseCharacterColor)
                                                                  {
                                                                      EditorGUILayout.PropertyField(p);
                                                                  }
            };
            drawers[nameof(CharacterMetadata.MessageColor)] = p => { if (EditedMetadata.UseCharacterColor)
                                                                     {
                                                                         EditorGUILayout.PropertyField(p);
                                                                     }
            };
            drawers[nameof(CharacterMetadata.HighlightWhenSpeaking)] = p => { if (ResourcesTypeConstraint != null)
                                                                              {
                                                                                  EditorGUILayout.PropertyField(p);
                                                                              }
            };
            drawers[nameof(CharacterMetadata.HighlightCharacterCount)] = p => { if (EditedMetadata.HighlightWhenSpeaking)
                                                                                {
                                                                                    EditorGUILayout.PropertyField(p);
                                                                                }
            };
            drawers[nameof(CharacterMetadata.SpeakingTint)] = p => { if (EditedMetadata.HighlightWhenSpeaking)
                                                                     {
                                                                         EditorGUILayout.PropertyField(p);
                                                                     }
            };
            drawers[nameof(CharacterMetadata.NotSpeakingTint)] = p => { if (EditedMetadata.HighlightWhenSpeaking)
                                                                        {
                                                                            EditorGUILayout.PropertyField(p);
                                                                        }
            };
            drawers[nameof(CharacterMetadata.PlaceOnTop)] = p => { if (EditedMetadata.HighlightWhenSpeaking)
                                                                   {
                                                                       EditorGUILayout.PropertyField(p);
                                                                   }
            };
            drawers[nameof(CharacterMetadata.HighlightDuration)] = p => { if (EditedMetadata.HighlightWhenSpeaking)
                                                                          {
                                                                              EditorGUILayout.PropertyField(p);
                                                                          }
            };
            drawers[nameof(CharacterMetadata.HighlightEasing)] = p => { if (EditedMetadata.HighlightWhenSpeaking)
                                                                        {
                                                                            EditorGUILayout.PropertyField(p);
                                                                        }
            };
            drawers[nameof(CharacterMetadata.MessageSound)]     = p => EditorResources.DrawPathPopup(p, AudioConfiguration.DefaultAudioPathPrefix, AudioConfiguration.DefaultAudioPathPrefix, "None (disabled)");
            drawers[nameof(CharacterMetadata.ClipMessageSound)] = p => { if (!string.IsNullOrEmpty(EditedMetadata.MessageSound))
                                                                         {
                                                                             EditorGUILayout.PropertyField(p);
                                                                         }
            };
            drawers[nameof(CharacterMetadata.LinkedPrinter)] = p => EditorResources.DrawPathPopup(p, $"{TextPrintersConfiguration.DefaultPathPrefix}/*", "*", "None (disabled)");
            drawers[nameof(CharacterMetadata.Poses)]         = p => { if (ResourcesTypeConstraint != null)
                                                                      {
                                                                          EditorGUILayout.PropertyField(p);
                                                                      }
            };
            return(drawers);
        }