158 lines
5.5 KiB
C#
158 lines
5.5 KiB
C#
using CaoCao.XAsset;
|
||
using System.IO;
|
||
using UnityEditor;
|
||
using UnityEngine;
|
||
|
||
namespace CaoCao.Editor
|
||
{
|
||
public static class MenuItems
|
||
{
|
||
private const string kSimulationMode = "CaoCao/XAsset/Simulation Mode";
|
||
|
||
[MenuItem("CaoCao/XAsset/About xasset", false, 1)]
|
||
public static void OpenAbout()
|
||
{
|
||
Application.OpenURL("https://xasset.cc");
|
||
}
|
||
|
||
[MenuItem("Assets/CaoCao/XAsset/Find References In Build", false, 20)]
|
||
public static void FindReferencesInBuild()
|
||
{
|
||
Settings.FindReferencesInBuild();
|
||
}
|
||
|
||
[MenuItem(kSimulationMode, false, 80)]
|
||
public static void SwitchSimulationMode()
|
||
{
|
||
var settings = Settings.GetDefaultSettings();
|
||
settings.simulationMode = !settings.simulationMode;
|
||
EditorUtility.SetDirty(settings);
|
||
AssetDatabase.SaveAssets();
|
||
}
|
||
|
||
[MenuItem(kSimulationMode, true, 80)]
|
||
public static bool RefreshSimulationMode()
|
||
{
|
||
var settings = Settings.GetDefaultSettings();
|
||
Menu.SetChecked(kSimulationMode, settings.simulationMode);
|
||
return true;
|
||
}
|
||
|
||
[MenuItem("CaoCao/XAsset/Open/Settings", false, 100)]
|
||
public static void PingSettings()
|
||
{
|
||
Selection.activeObject = Settings.GetDefaultSettings();
|
||
EditorGUIUtility.PingObject(Selection.activeObject);
|
||
EditorUtility.FocusProjectWindow();
|
||
}
|
||
|
||
[MenuItem("CaoCao/XAsset/Build References", false, 100)]
|
||
public static void BuildReferences()
|
||
{
|
||
Builder.BuildReferences();
|
||
}
|
||
|
||
[MenuItem("CaoCao/XAsset/Build Bundles", false, 100)]
|
||
public static void BuildBundles()
|
||
{
|
||
Builder.BuildBundles(Selection.GetFiltered<Build>(SelectionMode.DeepAssets));
|
||
}
|
||
|
||
[MenuItem("CaoCao/XAsset/Build Hotfix", false, 100)]
|
||
public static void BuildHotfix()
|
||
{
|
||
Builder.BuildHotfix(Selection.GetFiltered<Build>(SelectionMode.DeepAssets));
|
||
}
|
||
|
||
[MenuItem("CaoCao/XAsset/Build Bundles with Last Build", false, 100)]
|
||
public static void BuildBundlesWithLastBuild()
|
||
{
|
||
Builder.BuildBundlesWithLastBuild(Selection.GetFiltered<Build>(SelectionMode.DeepAssets));
|
||
}
|
||
|
||
[MenuItem("CaoCao/XAsset/<2F><><EFBFBD><EFBFBD>", false, 100)]
|
||
public static void BuildPlayer()
|
||
{
|
||
Editor.BuildPlayer.Build();
|
||
}
|
||
|
||
[MenuItem("CaoCao/XAsset/Build Player Assets", false, 100)]
|
||
public static void BuildPlayerAssetsWithSelection()
|
||
{
|
||
var path = EditorUtility.OpenFilePanelWithFilters("Select", Settings.PlatformDataPath,
|
||
new[] {"versions", "json"});
|
||
|
||
if (string.IsNullOrEmpty(path))
|
||
return;
|
||
|
||
var versions = XAsset.Utility.LoadFromFile<Versions>(path);
|
||
BuildPlayerAssets.CustomBuilder = null;
|
||
BuildPlayerAssets.StartNew(versions);
|
||
}
|
||
|
||
[MenuItem("CaoCao/XAsset/Build Update Info", false, 100)]
|
||
public static void BuildUpdateInfo()
|
||
{
|
||
var path = EditorUtility.OpenFilePanelWithFilters("Select", Settings.PlatformDataPath,
|
||
new[] {"versions", "json"});
|
||
if (string.IsNullOrEmpty(path)) return;
|
||
|
||
var versions = CaoCao.XAsset.Utility.LoadFromFile<Versions>(path);
|
||
var file = new FileInfo(path);
|
||
var hash = CaoCao.XAsset.Utility.ComputeHash(path);
|
||
Builder.BuildUpdateInfo(versions, hash, file.Length);
|
||
}
|
||
|
||
[MenuItem("CaoCao/XAsset/Print Changes with Selection", false, 150)]
|
||
public static void PrintChangesFromSelection()
|
||
{
|
||
var path = EditorUtility.OpenFilePanelWithFilters("Select", Settings.PlatformDataPath,
|
||
new[] {"versions", "json"});
|
||
if (string.IsNullOrEmpty(path)) return;
|
||
var versions = CaoCao.XAsset.Utility.LoadFromFile<Versions>(path);
|
||
var filename = versions.GetFilename();
|
||
var records = CaoCao.XAsset.Utility.LoadFromFile<BuildRecords>(Settings.GetCachePath(BuildRecords.Filename));
|
||
if (records.TryGetValue(filename, out var value)) Builder.GetChanges(value.changes, filename);
|
||
}
|
||
|
||
[MenuItem("CaoCao/XAsset/Clear Download", false, 200)]
|
||
public static void ClearDownload()
|
||
{
|
||
var directory = Assets.DownLoadPath;
|
||
if (Directory.Exists(directory))
|
||
Directory.Delete(directory, true);
|
||
}
|
||
|
||
[MenuItem("CaoCao/XAsset/Clear Bundles", false, 200)]
|
||
public static void ClearBundles()
|
||
{
|
||
var directory = Settings.PlatformDataPath;
|
||
if (Directory.Exists(directory))
|
||
Directory.Delete(directory, true);
|
||
}
|
||
|
||
[MenuItem("CaoCao/XAsset/Clear History", false, 200)]
|
||
public static void ClearHistory()
|
||
{
|
||
Editor.ClearHistory.Start();
|
||
}
|
||
|
||
|
||
[MenuItem("CaoCao/XAsset/Check for Updates", false, 300)]
|
||
public static void CheckForUpdates()
|
||
{
|
||
Application.OpenURL("https://xasset.cc/docs/next/change-log");
|
||
}
|
||
|
||
|
||
[MenuItem("Assets/CaoCao/XAsset/To Json")]
|
||
public static void ToJson()
|
||
{
|
||
var activeObject = Selection.activeObject;
|
||
var json = JsonUtility.ToJson(activeObject);
|
||
var path = AssetDatabase.GetAssetPath(activeObject);
|
||
var ext = Path.GetExtension(path);
|
||
File.WriteAllText(path.Replace(ext, ".json"), json);
|
||
}
|
||
}
|
||
} |