UnityEditor简单加密资源asset

前提:项目的scriptobject资源不想被别人用工具提取
设计:修改asset的yaml文件

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Linq;
using System.IO;

public class EditorUtils
{
    
    
  [MenuItem("CONTEXT/ScriptableObject/Sync")]
  public static void SyncScriptableObject(MenuCommand command)
  {
    
    
      AssetDatabase.SaveAssets();

      var path = AssetDatabase.GetAssetPath(command.context);

      SyncAsset(path);

      AssetDatabase.Refresh();
  }


  [MenuItem("Utils/Sync ScriptableObjects")]
  public static void SyncScriptableObjects()
  {
    
    
      AssetDatabase.SaveAssets();

      var paths = AssetDatabase.GetAllAssetPaths().Where(x=>x.EndsWith(".asset")).ToArray();

      for(int p = 0; p<paths.Length; p++)
      {
    
    
          var path = paths[p];
          SyncAsset(path);

          if (EditorUtility.DisplayCancelableProgressBar("Syncing ScriptableObjects...", path, (float)p / (float)paths.Length))
          {
    
    
              break;
          }
      }

      EditorUtility.ClearProgressBar();

      AssetDatabase.Refresh();
  }



    static public void SyncAsset(string path)
  {
    
    
      var yaml = File.ReadAllText(path);
      File.WriteAllText(path, yaml + " ");
      AssetDatabase.ImportAsset(path);
      File.WriteAllText(path, yaml);
  }
}

猜你喜欢

转载自blog.csdn.net/qq_41179365/article/details/119413089