UIMenuItemHelper.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.IO;
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace YIUIFramework.Editor
  5. {
  6. public static class UIMenuItemHelper
  7. {
  8. /// <summary>
  9. /// 克隆对象 根据传入的路径
  10. /// </summary>
  11. /// <param name="path"></param>
  12. /// <param name="parent"></param>
  13. /// <returns></returns>
  14. public static GameObject CloneGameObjectByPath(string path, Transform parent = null)
  15. {
  16. var loadSource = (GameObject)AssetDatabase.LoadAssetAtPath(path, typeof(Object));
  17. if (loadSource == null)
  18. {
  19. UnityTipsHelper.ShowError($"未知错误 没有加载到源数据 请检查 {path}");
  20. return null;
  21. }
  22. var newGameObj = Object.Instantiate(loadSource, parent, false);
  23. if (newGameObj.name.EndsWith("(Clone)"))
  24. newGameObj.name = newGameObj.name.Replace("(Clone)", "");
  25. EditorUtility.SetDirty(parent != null ? parent : newGameObj);
  26. return newGameObj;
  27. }
  28. public static GameObject CopyGameObject(GameObject obj)
  29. {
  30. var newGameObj = Object.Instantiate(obj);
  31. if (newGameObj.name.EndsWith("(Clone)"))
  32. newGameObj.name = newGameObj.name.Replace("(Clone)", "");
  33. return newGameObj;
  34. }
  35. internal static GameObject SelectAssetAtPath(string savePath)
  36. {
  37. return UIPanelSplitData.SelectAssetAtPath(savePath);
  38. }
  39. internal static string GetOnlyPrefabAssetsPath(string assetName, bool tips = true)
  40. {
  41. return UIPanelSplitData.GetOnlyPrefabAssetsPath(assetName, tips);
  42. }
  43. }
  44. }