1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using UnityEngine;
- using UnityEditor;
- using Object = UnityEngine.Object;
- public class MapAB_SetTool : EditorWindow
- {
- public string abName;
- public Object selectObj;
- public int rowCount = 0;
- [MenuItem("Plugins/MapSet")]
- static void Init()
- {
- MapAB_SetTool abSetTool = EditorWindow.CreateWindow<MapAB_SetTool>();
- abSetTool.Show();
- }
- public void OnGUI()
- {
- abName = EditorGUILayout.TextField("AB包名", abName);
- rowCount = int.Parse(EditorGUILayout.TextField("几X几", rowCount.ToString()));
- EditorGUILayout.LabelField($"设置包名:{abName}_(下标)");
- selectObj = Selection.activeObject;
- if (GUILayout.Button("设置ab包名"))
- {
- if (selectObj == null)
- {
- Debug.LogError("没选择文件夹!");
- return;
- }
- int tempCount = 0;
- int abIndex = 0;
- string path = AssetDatabase.GetAssetPath(selectObj);
- string[] guids = AssetDatabase.FindAssets("t:Object", new[] { path });
- for (int i = 0; i < guids.Length; i++)
- {
- AssetImporter importer = AssetImporter.GetAtPath(AssetDatabase.GUIDToAssetPath(guids[i]));
- if (importer != null)
- {
- importer.SetAssetBundleNameAndVariant($"{abName}_{abIndex}", "");
- //importer.SaveAndReimport();
- }
- tempCount++;
- if (tempCount >= rowCount)
- {
- tempCount = 0;
- abIndex++;
- }
- }
- AssetDatabase.SaveAssets();
- }
- EditorGUILayout.LabelField("选中文件:");
- EditorGUILayout.ObjectField(selectObj, typeof(Object));
- if (selectObj != null)
- {
- string tpath = AssetDatabase.GetAssetPath(selectObj);
- string[] tguids = AssetDatabase.FindAssets("t:Object", new[] { tpath });
- EditorGUILayout.LabelField($"选中文件:{tguids.Length}");
- int forCount = 0;
- int t_abIndex = 0;
- EditorGUILayout.LabelField($"包名:{abName}_{t_abIndex}");
- for (int i = 0; i < tguids.Length; i++)
- {
- EditorGUILayout.LabelField($"{AssetDatabase.GUIDToAssetPath(tguids[i])}");
- forCount++;
- if (forCount >= rowCount)
- {
- forCount = 0;
- t_abIndex++;
- EditorGUILayout.LabelField($"包名:{abName}_{t_abIndex}");
- }
- }
- }
- }
- }
|