2021-04-08 20:09:59 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using ET;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using System.IO;
|
2021-04-11 19:50:39 +08:00
|
|
|
|
using Object = UnityEngine.Object;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
|
|
|
|
|
namespace ETEditor
|
|
|
|
|
{
|
|
|
|
|
[InitializeOnLoad]
|
|
|
|
|
public class AssetBundleMark
|
|
|
|
|
{
|
|
|
|
|
public const string AssetBundlesOutputPath = "AssetBundles";
|
|
|
|
|
private static int mSimulateAssetBundleInEditor = -1;
|
|
|
|
|
private const string kSimulateAssetBundles = "SimulateAssetBundles";
|
|
|
|
|
|
|
|
|
|
// Flag to indicate if we want to simulate assetBundles in Editor without building them actually.
|
|
|
|
|
public static bool SimulateAssetBundleInEditor
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (mSimulateAssetBundleInEditor == -1)
|
|
|
|
|
mSimulateAssetBundleInEditor = EditorPrefs.GetBool(kSimulateAssetBundles, true) ? 1 : 0;
|
|
|
|
|
|
|
|
|
|
return mSimulateAssetBundleInEditor != 0;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
int newValue = value ? 1 : 0;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (newValue != mSimulateAssetBundleInEditor)
|
|
|
|
|
{
|
|
|
|
|
mSimulateAssetBundleInEditor = newValue;
|
|
|
|
|
EditorPrefs.SetBool(kSimulateAssetBundles, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private const string Mark_AssetBundle = "Assets/标记 - AssetBundle";
|
|
|
|
|
|
|
|
|
|
static AssetBundleMark()
|
|
|
|
|
{
|
|
|
|
|
Selection.selectionChanged = OnSelectionChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void OnSelectionChanged()
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
string path = GetSelectedPathOrFallback();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(path))
|
|
|
|
|
{
|
|
|
|
|
Menu.SetChecked(Mark_AssetBundle, Marked(path));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool Marked(string path)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
AssetImporter ai = AssetImporter.GetAtPath(path);
|
|
|
|
|
DirectoryInfo dir = new DirectoryInfo(path);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
return string.Equals(ai.assetBundleName, $"{dir.Name.Split('.')[0]}.unity3d".ToLower());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MarkPTAB(string path)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(path))
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
AssetImporter ai = AssetImporter.GetAtPath(path);
|
|
|
|
|
DirectoryInfo dir = new DirectoryInfo(path);
|
2021-04-08 20:09:59 +08:00
|
|
|
|
|
|
|
|
|
if (Marked(path))
|
|
|
|
|
{
|
|
|
|
|
Menu.SetChecked(Mark_AssetBundle, false);
|
|
|
|
|
ai.assetBundleName = null;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Menu.SetChecked(Mark_AssetBundle, true);
|
|
|
|
|
ai.assetBundleName = $"{dir.Name.Split('.')[0]}.unity3d".ToLower();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AssetDatabase.RemoveUnusedAssetBundleNames();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[MenuItem(Mark_AssetBundle, false, 10000)]
|
|
|
|
|
public static void MarkPTABDir()
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
string path = GetSelectedPathOrFallback();
|
2021-04-08 20:09:59 +08:00
|
|
|
|
MarkPTAB(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[MenuItem(Mark_AssetBundle, true, 10000)]
|
|
|
|
|
public static bool MarkPTABDir_Check()
|
|
|
|
|
{
|
|
|
|
|
string path = GetSelectedPathOrFallback();
|
|
|
|
|
if (string.IsNullOrEmpty(path) == false)
|
|
|
|
|
{
|
|
|
|
|
if (path.Split('.').Length == 1)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else if (path.EndsWith(".cs"))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetSelectedPathOrFallback()
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
string path = string.Empty;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (Object obj in Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets))
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
path = AssetDatabase.GetAssetPath(obj);
|
|
|
|
|
if (!string.IsNullOrEmpty(path) && File.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Debug.Log ("path ***** :"+path);
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|