예제 #1
0
        private static void HandleAutoAdd(string assetPath, ref bool modifiedResources)
        {
            if (!configuration.AutoAddScripts)
            {
                return;
            }

            var guid = AssetDatabase.AssetPathToGUID(assetPath);
            var name = Path.GetFileNameWithoutExtension(assetPath);

            // Don't add the script if it's already added.
            if (guid is null || editorResources.GetPathByGuid(guid) != null)
            {
                return;
            }

            // Add only new scripts created via context menu (will always have a @stop at second line).
            var linesEnum  = File.ReadLines(assetPath).GetEnumerator();
            var secondLine = (linesEnum.MoveNext() && linesEnum.MoveNext()) ? linesEnum.Current : null;

            linesEnum.Dispose(); // Release the file.
            if (!secondLine?.EqualsFast(AssetMenuItems.DefaultScriptContent.GetAfterFirst(Environment.NewLine)) ?? true)
            {
                return;
            }

            editorResources.AddRecord(configuration.Loader.PathPrefix, configuration.Loader.PathPrefix, name, guid);
            modifiedResources = true;
        }
예제 #2
0
        private void SaveResources()
        {
            if (!ObjectUtils.IsValid(audioConfig))
            {
                return;
            }

            var category = audioConfig.VoiceLoader.PathPrefix;

            foreach (var kv in map)
            {
                var hash = kv.Key;
                var data = kv.Value;

                editorResources.RemoveAllRecordsWithPath(category, hash, category);
                if (!string.IsNullOrEmpty(data.ClipGuid))
                {
                    editorResources.AddRecord(category, category, hash, data.ClipGuid);
                }
            }

            EditorUtility.SetDirty(editorResources);
            AssetDatabase.SaveAssets();
        }