MapAB_SetTool.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using UnityEngine;
  7. using UnityEditor;
  8. using Object = UnityEngine.Object;
  9. public class MapAB_SetTool : EditorWindow
  10. {
  11. public string abName;
  12. public Object selectObj;
  13. public int rowCount = 0;
  14. [MenuItem("Plugins/MapSet")]
  15. static void Init()
  16. {
  17. MapAB_SetTool abSetTool = EditorWindow.CreateWindow<MapAB_SetTool>();
  18. abSetTool.Show();
  19. }
  20. public void OnGUI()
  21. {
  22. abName = EditorGUILayout.TextField("AB包名", abName);
  23. rowCount = int.Parse(EditorGUILayout.TextField("几X几", rowCount.ToString()));
  24. EditorGUILayout.LabelField($"设置包名:{abName}_(下标)");
  25. selectObj = Selection.activeObject;
  26. if (GUILayout.Button("设置ab包名"))
  27. {
  28. if (selectObj == null)
  29. {
  30. Debug.LogError("没选择文件夹!");
  31. return;
  32. }
  33. int tempCount = 0;
  34. int abIndex = 0;
  35. string path = AssetDatabase.GetAssetPath(selectObj);
  36. string[] guids = AssetDatabase.FindAssets("t:Object", new[] { path });
  37. for (int i = 0; i < guids.Length; i++)
  38. {
  39. AssetImporter importer = AssetImporter.GetAtPath(AssetDatabase.GUIDToAssetPath(guids[i]));
  40. if (importer != null)
  41. {
  42. importer.SetAssetBundleNameAndVariant($"{abName}_{abIndex}", "");
  43. //importer.SaveAndReimport();
  44. }
  45. tempCount++;
  46. if (tempCount >= rowCount)
  47. {
  48. tempCount = 0;
  49. abIndex++;
  50. }
  51. }
  52. AssetDatabase.SaveAssets();
  53. }
  54. EditorGUILayout.LabelField("选中文件:");
  55. EditorGUILayout.ObjectField(selectObj, typeof(Object));
  56. if (selectObj != null)
  57. {
  58. string tpath = AssetDatabase.GetAssetPath(selectObj);
  59. string[] tguids = AssetDatabase.FindAssets("t:Object", new[] { tpath });
  60. EditorGUILayout.LabelField($"选中文件:{tguids.Length}");
  61. int forCount = 0;
  62. int t_abIndex = 0;
  63. EditorGUILayout.LabelField($"包名:{abName}_{t_abIndex}");
  64. for (int i = 0; i < tguids.Length; i++)
  65. {
  66. EditorGUILayout.LabelField($"{AssetDatabase.GUIDToAssetPath(tguids[i])}");
  67. forCount++;
  68. if (forCount >= rowCount)
  69. {
  70. forCount = 0;
  71. t_abIndex++;
  72. EditorGUILayout.LabelField($"包名:{abName}_{t_abIndex}");
  73. }
  74. }
  75. }
  76. }
  77. }