Skip to content

Instantly share code, notes, and snippets.

@hiroki-o
Created May 2, 2017 06:31
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiroki-o/74cc3aede197f2ba358dca07d8e2f380 to your computer and use it in GitHub Desktop.
Save hiroki-o/74cc3aede197f2ba358dca07d8e2f380 to your computer and use it in GitHub Desktop.
Addressable Asset Settings Editor Tool (for debug)
using System.Collections.Generic;
using UnityEditorInternal;
using UnityEngine;
using UnityEditor.Hardware;
using UnityEditor.VersionControl;
#if ENABLE_CLOUD_SERVICES_COLLAB
using UnityEditor.Collaboration;
using UnityEditor.Web;
#endif
namespace UnityEditor
{
internal class AddressableAssetSettingEditor : EditorWindow
{
[MenuItem("Window/Edit Asset Address")]
public static void Open () {
var w = GetWindow<AddressableAssetSettingEditor>();
w.titleContent = new GUIContent("Asset Address");
}
public void OnEnable()
{
}
public void OnDisable()
{
}
private void DoEditAddressableAsset() {
EditorGUILayout.HelpBox("Edit Asset Address.", MessageType.Info);
var activeObject = Selection.activeObject;
if (activeObject == null) {
return;
}
var s = AddressableAssetSettings.GetAddressableAssetSetting (activeObject);
using (new EditorGUILayout.VerticalScope(GUI.skin.box))
{
var path = AssetDatabase.GUIDToAssetPath(s.guid);
if (string.IsNullOrEmpty(path))
{
return;
}
var name = System.IO.Path.GetFileName(path);
var attr = System.IO.File.GetAttributes(path);
if ((attr & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory)
{
name = string.Format("{0} (folder)", name);
}
using (new EditorGUILayout.HorizontalScope(GUI.skin.box))
{
GUILayout.Label(name, "BoldLabel");
GUILayout.FlexibleSpace ();
if (GUILayout.Button("Select", GUILayout.Width(50)))
{
EditorGUIUtility.PingObject(activeObject);
}
}
EditorGUILayout.LabelField ("Address", AddressableAssetSettings.GetImplicitAssetAddress(s.guid, false));
EditorGUILayout.LabelField ("Addressable?", AddressableAssetSettings.IsAddressableAsset(s.guid) ? "Yes" : "No");
GUILayout.Space (12);
bool hasSetting = AddressableAssetSettings.HasAddressableAssetSetting(activeObject);
bool editValue = EditorGUILayout.Toggle ("Edit Setting", hasSetting);
if (editValue != hasSetting) {
if (editValue) {
AddressableAssetSettings.ApplyAddressableAssetSetting (s);
} else {
AddressableAssetSettings.RemoveAddressableAssetSetting (s.guid);
}
}
using (new EditorGUI.DisabledScope(!hasSetting)) {
using (new EditorGUILayout.VerticalScope (GUI.skin.box)) {
EditorGUILayout.Space ();
bool isActive = EditorGUILayout.Toggle ("Active", s.isActive);
string newAddress = EditorGUILayout.TextField ("Address", s.address);
GUILayout.Space (20);
if (isActive != s.isActive || newAddress != s.address) {
s.isActive = isActive;
s.address = newAddress;
AddressableAssetSettings.ApplyAddressableAssetSetting (s);
}
}
}
}
}
void OnSelectionChange() {
Repaint();
}
void OnFocus() {
Repaint();
}
public void OnGUI ()
{
DoEditAddressableAsset();
}
}
}
using System.Collections.Generic;
using UnityEditorInternal;
using UnityEngine;
using UnityEditor;
using UnityEditor.Hardware;
using UnityEditor.VersionControl;
#if ENABLE_CLOUD_SERVICES_COLLAB
using UnityEditor.Collaboration;
using UnityEditor.Web;
#endif
internal class AssetSettingsDebugEditor : EditorWindow
{
private Vector2 scrollPos;
private bool getInactive;
[MenuItem("Window/AssetSetting")]
public static void Open () {
var w = GetWindow<AssetSettingsDebugEditor>();
w.titleContent = new GUIContent("AssetSettings");
}
public void OnEnable()
{
}
public void OnDisable()
{
}
private void DoAssetBundleGUI() {
EditorGUILayout.HelpBox("AssetBundle Settings.", MessageType.Info);
var settings = AssetBundleSettings.GetAllAssetBundleSettings();
using (new EditorGUILayout.VerticalScope(GUI.skin.box))
{
int maxNameWidth = 0;
int maxABNameWidth = 0;
int maxVariantWidth = 0;
GUIStyle s1 = new GUIStyle("BoldLabel");
GUIStyle s2 = new GUIStyle("Label");
foreach (var s in settings)
{
var path = AssetDatabase.GUIDToAssetPath(s.guid);
if (string.IsNullOrEmpty(path))
{
continue;
}
var name = System.IO.Path.GetFileName(path);
var attr = System.IO.File.GetAttributes(path);
if ((attr & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory)
{
name = string.Format("{0} (folder)", name);
}
maxNameWidth = Mathf.Max(maxNameWidth, (int)s1.CalcSize(new GUIContent(name)).x);
maxABNameWidth = Mathf.Max(maxABNameWidth, (int)s2.CalcSize(new GUIContent(s.assetBundleName)).x);
maxVariantWidth = Mathf.Max(maxVariantWidth, (int)s2.CalcSize(new GUIContent(s.assetBundleVariant)).x);
}
foreach (var s in settings)
{
using (new EditorGUILayout.HorizontalScope())
{
var path = AssetDatabase.GUIDToAssetPath(s.guid);
if (string.IsNullOrEmpty(path))
{
continue;
}
var name = System.IO.Path.GetFileName(path);
var attr = System.IO.File.GetAttributes(path);
if ((attr & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory)
{
name = string.Format("{0} (folder)", name);
}
GUILayout.Label(name, "BoldLabel", GUILayout.MaxWidth(maxNameWidth));
EditorGUILayout.Space();
GUILayout.Label(s.assetBundleName, GUILayout.MaxWidth(maxABNameWidth));
GUILayout.Space(8);
GUILayout.Label(s.assetBundleVariant, GUILayout.MaxWidth(maxVariantWidth));
if (GUILayout.Button("Select", GUILayout.Width(50)))
{
var o = AssetDatabase.LoadMainAssetAtPath(path);
EditorGUIUtility.PingObject(o);
}
}
}
}
}
private void DoAddressableAssetGUI() {
EditorGUILayout.HelpBox("Addressable Asset Settings.", MessageType.Info);
var settings = AddressableAssetSettings.GetAllAddressableAssetSettings();
using (new EditorGUILayout.VerticalScope(GUI.skin.box))
{
foreach (var s in settings)
{
var path = AssetDatabase.GUIDToAssetPath(s.guid);
if (string.IsNullOrEmpty(path))
{
continue;
}
var name = System.IO.Path.GetFileName(path);
var attr = System.IO.File.GetAttributes(path);
if ((attr & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory)
{
name = string.Format("{0} (folder)", name);
}
using (new EditorGUILayout.HorizontalScope(GUI.skin.box))
{
GUILayout.Label(name, "BoldLabel");
GUILayout.Label("active="+s.isActive.ToString());
GUILayout.Label(s.address);
if (GUILayout.Button("Select", GUILayout.Width(50)))
{
var o = AssetDatabase.LoadMainAssetAtPath(path);
EditorGUIUtility.PingObject(o);
}
}
EditorGUILayout.Space();
}
}
}
private void ListAllAddressableAssetGUI() {
EditorGUILayout.HelpBox("All Addressable Assets.", MessageType.Info);
getInactive = EditorGUILayout.Toggle ("Get Inactive", getInactive);
var settings = AddressableAssetSettings.GetAllImplicitAddressableAssets(getInactive);
using (new EditorGUILayout.VerticalScope(GUI.skin.box))
{
foreach (var s in settings)
{
using (new EditorGUILayout.HorizontalScope(GUI.skin.box))
{
GUILayout.Label(s.address,s.isActive? "BoldLabel" : "Label");
GUILayout.Label(s.isActive? "" : "(inactive)");
if (GUILayout.Button("Select", GUILayout.Width(50)))
{
var path = AssetDatabase.GUIDToAssetPath(s.guid);
var o = AssetDatabase.LoadMainAssetAtPath(path);
EditorGUIUtility.PingObject(o);
}
}
EditorGUILayout.Space();
}
}
}
void OnSelectionChange() {
Repaint();
}
void OnFocus() {
Repaint();
}
public void OnInspectorUpdate()
{
Repaint();
}
public void OnGUI ()
{
using (var scrollScope = new EditorGUILayout.ScrollViewScope (scrollPos)) {
scrollPos = scrollScope.scrollPosition;
DoAssetBundleGUI();
DoAddressableAssetGUI();
ListAllAddressableAssetGUI();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment