Exemple #1
0
        private static void Update()
        {
            if (modifiedScriptPaths.Count == 0)
            {
                return;
            }
            if (!modifiedScriptPaths.TryDequeue(out var fullPath))
            {
                return;
            }
            if (!File.Exists(fullPath))
            {
                return;
            }

            var assetPath = PathUtils.AbsoluteToAssetPath(fullPath);

            AssetDatabase.ImportAsset(assetPath);
            OnModified?.Invoke(assetPath);

            // Required to rebuild script when editor is not in focus, because script view
            // delays rebuild, but delayed call is not invoked while editor is not in focus.
            if (!InternalEditorUtility.isApplicationActive)
            {
                EditorApplication.delayCall?.Invoke();
            }
        }
Exemple #2
0
        static ScriptView()
        {
            var styleSheetPath = PathUtils.AbsoluteToAssetPath(PathUtils.Combine(PackagePath.EditorResourcesPath, "ScriptEditor.uss"));

            StyleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>(styleSheetPath);
            var darkStyleSheetPath = PathUtils.AbsoluteToAssetPath(PathUtils.Combine(PackagePath.EditorResourcesPath, "ScriptEditorDark.uss"));

            DarkStyleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>(darkStyleSheetPath);
        }
        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();
        }
Exemple #4
0
        private static void UpgradeUniTaskv1Tov2()
        {
            if (!EditorUtility.DisplayDialog("Perform upgrade?",
                                             "Are you sure you want to modify this Unity project to migrate from UniTask v1 to v2?\n\nAll the C# script files in the project containing 'UniRx.Async' will be modified and 'ThirdParty/UniTask' folder inside Naninovel package will be removed. The effect of the upgrade is permanent and can't be undone, so make sure to backup the project before confirming.\n\nAfter the upgrade is complete, install UniTask v2 via UPM (other installation scenarios are not supported).", "Upgrade", "Cancel"))
            {
                return;
            }

            const string title   = "Upgrading to UniTask v2";
            const string v1Using = "UniRx.Async";
            const string v2Using = "Cysharp.Threading.Tasks";

            try
            {
                var uniTaskPath = PathUtils.Combine(PackagePath.PackageRootPath, "ThirdParty/UniTask");
                if (Directory.Exists(uniTaskPath))
                {
                    EditorUtility.DisplayProgressBar(title, $"Deleting `{PathUtils.AbsoluteToAssetPath(uniTaskPath)}`...", 0f);
                    AssetDatabase.DeleteAsset(PathUtils.AbsoluteToAssetPath(uniTaskPath));
                }

                var scriptPaths = AssetDatabase.GetAllAssetPaths().Where(p => Path.GetExtension(p) == ".cs").ToArray();
                for (int i = 0; i < scriptPaths.Length; i++)
                {
                    var path = scriptPaths[i];
                    if (path.EndsWithFast("Upgrader.cs") || !File.Exists(path))
                    {
                        continue;
                    }
                    var scriptText = File.ReadAllText(path);
                    if (!scriptText.Contains(v1Using))
                    {
                        continue;
                    }
                    EditorUtility.DisplayProgressBar(title, $"Modifying `{PathUtils.AbsoluteToAssetPath(path)}`...", i / (float)scriptPaths.Length);
                    scriptText = scriptText.Replace(v1Using, v2Using);
                    File.WriteAllText(path, scriptText);
                }

                AssetDatabase.Refresh();
                AssetDatabase.SaveAssets();
            }
            catch (Exception e) { UnityEngine.Debug.LogError($"Failed upgrading to UniTask v2: {e.Message}"); }
            finally { EditorUtility.ClearProgressBar(); }
        }
Exemple #5
0
        /// <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);
        }
Exemple #6
0
        /// <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);
        }
Exemple #7
0
        static ScriptView()
        {
            var styleSheetPath = PathUtils.AbsoluteToAssetPath(PathUtils.Combine(PackagePath.EditorResourcesPath, "VisualEditor.uss"));

            StyleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>(styleSheetPath);

            var commentItem     = new SearcherItem("Comment");
            var labelItem       = new SearcherItem("Label");
            var genericTextItem = new SearcherItem("Generic Text");
            var defineItem      = new SearcherItem("Define");
            var commandsItem    = new SearcherItem("Commands");

            foreach (var commandId in Commands.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, defineItem
            };
        }
Exemple #8
0
 public static void PathField(SerializedProperty property, Func <string, string, string> openPanel,
                              bool local = false, string title = default, string defaultPath = default)
 {
     if (title is null)
     {
         title = property.displayName;
     }
     if (defaultPath is null)
     {
         defaultPath = Application.dataPath;
     }
     EditorGUILayout.BeginHorizontal();
     EditorGUILayout.PropertyField(property);
     if (GUILayout.Button("Select", EditorStyles.miniButton, GUILayout.Width(65)))
     {
         var path = openPanel(title, defaultPath);
         if (local)
         {
             path = PathUtils.AbsoluteToAssetPath(path);
         }
         property.stringValue = path;
     }
     EditorGUILayout.EndHorizontal();
 }
Exemple #9
0
        private void AddBuiltinAssets()
        {
            var config = default(ActorManagerConfiguration);

            config = ConfigurationSettings.LoadOrDefaultAndSave <TextPrintersConfiguration>();
            AddActorAsset(config, "Prefabs/TextPrinters/Dialogue.prefab");
            AddActorAsset(config, "Prefabs/TextPrinters/Fullscreen.prefab");
            AddActorAsset(config, "Prefabs/TextPrinters/Wide.prefab");
            AddActorAsset(config, "Prefabs/TextPrinters/Chat.prefab");
            AddActorAsset(config, "Prefabs/TextPrinters/Bubble.prefab");
            AddActorAsset(config, "Prefabs/TextPrinters/TMProDialogue.prefab");
            AddActorAsset(config, "Prefabs/TextPrinters/TMProFullscreen.prefab");
            AddActorAsset(config, "Prefabs/TextPrinters/TMProWide.prefab");
            AddActorAsset(config, "Prefabs/TextPrinters/TMProBubble.prefab");

            config = ConfigurationSettings.LoadOrDefaultAndSave <ChoiceHandlersConfiguration>();
            AddActorAsset(config, "Prefabs/ChoiceHandlers/ButtonList.prefab");
            AddActorAsset(config, "Prefabs/ChoiceHandlers/ButtonArea.prefab");

            AddAsset(SpawnConfiguration.DefaultPathPrefix, "Prefabs/FX/Animate.prefab");
            AddAsset(SpawnConfiguration.DefaultPathPrefix, "Prefabs/FX/DepthOfField.prefab");
            AddAsset(SpawnConfiguration.DefaultPathPrefix, "Prefabs/FX/DigitalGlitch.prefab");
            AddAsset(SpawnConfiguration.DefaultPathPrefix, "Prefabs/FX/Rain.prefab");
            AddAsset(SpawnConfiguration.DefaultPathPrefix, "Prefabs/FX/ShakeBackground.prefab");
            AddAsset(SpawnConfiguration.DefaultPathPrefix, "Prefabs/FX/ShakeCamera.prefab");
            AddAsset(SpawnConfiguration.DefaultPathPrefix, "Prefabs/FX/ShakeCharacter.prefab");
            AddAsset(SpawnConfiguration.DefaultPathPrefix, "Prefabs/FX/ShakePrinter.prefab");
            AddAsset(SpawnConfiguration.DefaultPathPrefix, "Prefabs/FX/Snow.prefab");
            AddAsset(SpawnConfiguration.DefaultPathPrefix, "Prefabs/FX/SunShafts.prefab");

            AddAsset(UIConfiguration.DefaultPathPrefix, "Prefabs/DefaultUI/ClickThroughPanel.prefab");
            AddAsset(UIConfiguration.DefaultPathPrefix, "Prefabs/DefaultUI/BacklogUI.prefab");
            AddAsset(UIConfiguration.DefaultPathPrefix, "Prefabs/DefaultUI/CGGalleryUI.prefab");
            AddAsset(UIConfiguration.DefaultPathPrefix, "Prefabs/DefaultUI/ConfirmationUI.prefab");
            AddAsset(UIConfiguration.DefaultPathPrefix, "Prefabs/DefaultUI/ContinueInputUI.prefab");
            AddAsset(UIConfiguration.DefaultPathPrefix, "Prefabs/DefaultUI/ExternalScriptsUI.prefab");
            AddAsset(UIConfiguration.DefaultPathPrefix, "Prefabs/DefaultUI/LoadingUI.prefab");
            AddAsset(UIConfiguration.DefaultPathPrefix, "Prefabs/DefaultUI/MovieUI.prefab");
            AddAsset(UIConfiguration.DefaultPathPrefix, "Prefabs/DefaultUI/RollbackUI.prefab");
            AddAsset(UIConfiguration.DefaultPathPrefix, "Prefabs/DefaultUI/SaveLoadUI.prefab");
            AddAsset(UIConfiguration.DefaultPathPrefix, "Prefabs/DefaultUI/SceneTransitionUI.prefab");
            AddAsset(UIConfiguration.DefaultPathPrefix, "Prefabs/DefaultUI/SettingsUI.prefab");
            AddAsset(UIConfiguration.DefaultPathPrefix, "Prefabs/DefaultUI/TipsUI.prefab");
            AddAsset(UIConfiguration.DefaultPathPrefix, "Prefabs/DefaultUI/TitleUI.prefab");
            AddAsset(UIConfiguration.DefaultPathPrefix, "Prefabs/DefaultUI/VariableInputUI.prefab");
            AddAsset(UIConfiguration.DefaultPathPrefix, "Prefabs/DefaultUI/PauseUI.prefab");

            void AddActorAsset(ActorManagerConfiguration managerConfig, string relativeAssetPath)
            {
                var actorId    = Path.GetFileNameWithoutExtension(relativeAssetPath);
                var actorMeta  = managerConfig.GetMetadataOrDefault(actorId);
                var category   = $"{actorMeta.Loader.PathPrefix}/{actorMeta.Guid}";
                var pathPrefix = actorMeta.Loader.PathPrefix;
                var assetPath  = $"{PathUtils.AbsoluteToAssetPath(PackagePath.PackageRootPath)}/{relativeAssetPath}";
                var assetGuid  = AssetDatabase.AssetPathToGUID(assetPath);

                AddRecord(category, pathPrefix, actorId, assetGuid);
            }

            void AddAsset(string categoryId, string relativeAssetPath)
            {
                var resourceName = Path.GetFileNameWithoutExtension(relativeAssetPath);
                var assetPath    = $"{PathUtils.AbsoluteToAssetPath(PackagePath.PackageRootPath)}/{relativeAssetPath}";
                var assetGuid    = AssetDatabase.AssetPathToGUID(assetPath);

                AddRecord(categoryId, categoryId, resourceName, assetGuid);
            }
        }
Exemple #10
0
        private static void CreatePrefabCopy(string prefabPath, string copyName)
        {
            var assetPath = PathUtils.AbsoluteToAssetPath(PathUtils.Combine(PackagePath.PrefabsPath, $"{prefabPath}.prefab"));

            CreateAssetCopy(assetPath, copyName);
        }
Exemple #11
0
        private static void CreateResourceCopy(string resourcePath, string copyName)
        {
            var assetPath = PathUtils.AbsoluteToAssetPath(PathUtils.Combine(PackagePath.RuntimeResourcesPath, $"{resourcePath}.prefab"));

            CreateAssetCopy(assetPath, copyName);
        }