Beispiel #1
0
        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();
        }
Beispiel #2
0
        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 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;
        }
Beispiel #4
0
        public override void OnActivate(string searchContext, VisualElement rootElement)
        {
            base.OnActivate(searchContext, rootElement);

            EditorResources = EditorResources.LoadOrDefault();
            ResourcesEditor = new EditorResourcesEditor(EditorResources);
        }
Beispiel #5
0
        public override void OnActivate(string searchContext, VisualElement rootElement)
        {
            base.OnActivate(searchContext, rootElement);

            ToResourcesButtonContent = new GUIContent($"Manage {EditorTitle} Resources");
            EditorResources          = EditorResources.LoadOrDefault();
            ResourcesEditor          = new EditorResourcesEditor(EditorResources);
        }
Beispiel #6
0
        public ScriptView(ScriptsConfiguration config, Action drawHackGuiAction, Action saveAssetAction)
        {
            ScriptModified = false;

            this.config          = config;
            this.saveAssetAction = saveAssetAction;
            editorResources      = EditorResources.LoadOrDefault();
            ViewRange            = new IntRange(0, config.EditorPageLength - 1);

            styleSheets.Add(StyleSheet);
            if (EditorGUIUtility.isProSkin)
            {
                styleSheets.Add(DarkStyleSheet);
            }
            CustomStyleSheet = config.EditorCustomStyleSheet;
            if (CustomStyleSheet)
            {
                styleSheets.Add(CustomStyleSheet);
            }

            var commentItem     = new SearcherItem("Comment");
            var labelItem       = new SearcherItem("Label");
            var genericTextItem = new SearcherItem("Generic Text", config.InsertLineKey != KeyCode.None
                ? $"{(config.InsertLineModifier != EventModifiers.None ? $"{config.InsertLineModifier}+" : string.Empty)}{config.InsertLineKey}"
                : null);
            var commandsItem = new SearcherItem("Commands");

            foreach (var commandId in Command.CommandTypes.Keys.OrderBy(k => k))
            {
                commandsItem.AddChild(new SearcherItem(char.ToLowerInvariant(commandId[0]) + commandId.Substring(1)));
            }
            searchItems = new List <SearcherItem> {
                commandsItem, genericTextItem, labelItem, commentItem
            };

            Add(new IMGUIContainer(drawHackGuiAction));
            Add(new IMGUIContainer(() => HandleKeyDownEvent(null)));

            linesContainer = new VisualElement();
            Add(linesContainer);

            paginationView = new PaginationView(SelectNextPage, SelectPreviousPage);
            paginationView.style.display = DisplayStyle.None;
            Add(paginationView);

            infoLabel      = new Label("Loading, please wait...");
            infoLabel.name = "InfoLabel";
            ColorUtility.TryParseHtmlString(EditorGUIUtility.isProSkin ? "#cccccc" : "#555555", out var color);
            infoLabel.style.color = color;
            Add(infoLabel);

            RegisterCallback <KeyDownEvent>(HandleKeyDownEvent, TrickleDown.TrickleDown);
            RegisterCallback <MouseDownEvent>(HandleMouseDownEvent, TrickleDown.TrickleDown);

            new ContextualMenuManipulator(ContextMenu).target = this;
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (!editorResources)
            {
                editorResources = EditorResources.LoadOrDefault();
            }

            var attr = attribute as ResourcesPopupAttribute;

            editorResources.DrawPathPopup(position, property, attr.Category, attr.PathPrefix, attr.EmptyOption);
        }
Beispiel #8
0
        private static void Upgrade112To113()
        {
            if (!EditorUtility.DisplayDialog("Perform upgrade?",
                                             "Are you sure you want to perform v1.12-v1.13 upgrade? Configuration assets will be modified. Make sure to perform a backup before confirming.",
                                             "Upgrade", "Cancel"))
            {
                return;
            }

            // Handle LayeredActorBehaviour replaced with LayeredBackgroundBehaviour and LayeredCharacterBehaviour.
            try
            {
                const string layeredBehaviourComponentGuid  = "0ed8eaa5eef74e849a7f97276a748279";
                const string layeredCharacterComponentGuid  = "3645880df9c1965479dfe05f712a1711";
                const string layeredBackgroundComponentGuid = "5fd416f37425423409b956ac79ed74bc";
                var          editorResources = EditorResources.LoadOrDefault();
                var          records         = editorResources.GetAllRecords().ToArray();
                for (int i = 0; i < records.Length; i++)
                {
                    var resourcePath = records[i].Key;
                    var resourceGuid = records[i].Value;
                    var assetPath    = AssetDatabase.GUIDToAssetPath(resourceGuid);
                    if (string.IsNullOrEmpty(assetPath) || !File.Exists(assetPath))
                    {
                        continue;
                    }
                    if (AssetDatabase.GetMainAssetTypeAtPath(assetPath) != typeof(GameObject))
                    {
                        continue;
                    }
                    EditorUtility.DisplayProgressBar("Upgrading project to Naninovel v1.13", $"Processing `{assetPath}`", i / (float)records.Length);
                    var assetText = File.ReadAllText(assetPath);
                    if (!assetText.Contains(layeredBehaviourComponentGuid))
                    {
                        continue;
                    }
                    var isCharacter  = resourcePath.Contains(CharactersConfiguration.DefaultPathPrefix);
                    var isBackground = resourcePath.Contains(BackgroundsConfiguration.DefaultPathPrefix);
                    if (!isCharacter && !isBackground)
                    {
                        continue;
                    }
                    assetText = assetText.Replace(layeredBehaviourComponentGuid, isCharacter ? layeredCharacterComponentGuid : layeredBackgroundComponentGuid);
                    File.WriteAllText(assetPath, assetText);
                    Debug.Log($"Upgrader: Replaced `LayeredActorBehaviour` component on `{assetPath}`.");
                }
            }
            finally { EditorUtility.ClearProgressBar(); }

            AssetDatabase.Refresh();
            AssetDatabase.SaveAssets();
        }
Beispiel #9
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 #10
0
 private void OnEnable()
 {
     editorResources = EditorResources.LoadOrDefault();
     audioConfig     = ProjectConfigurationProvider.LoadOrDefault <AudioConfiguration>();
     UpdateSelectedScript();
 }
Beispiel #11
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();
        }