cvr-props/Assets/ABI.CCK/Scripts/Editor/CCK_CVRAssetInfoEditor.cs

92 lines
3.2 KiB
C#
Raw Permalink Normal View History

2023-01-22 16:38:23 +01:00
using ABI.CCK.Components;
using UnityEditor;
using UnityEngine;
namespace ABI.CCK.Scripts.Editor
{
[CanEditMultipleObjects]
[CustomEditor(typeof(CVRAssetInfo))]
2023-01-22 16:38:23 +01:00
public class CCK_CVRAssetInfoEditor : UnityEditor.Editor
{
private SerializedProperty _objectIdProperty;
private string _newGUID;
#region Unity Events
private void OnEnable()
{
if (target == null)
return;
_objectIdProperty = serializedObject.FindProperty("objectId");
}
2023-01-22 16:38:23 +01:00
public override void OnInspectorGUI()
{
serializedObject.Update();
DrawHeaderInfo();
if (!string.IsNullOrEmpty(_objectIdProperty.stringValue))
DrawDetachGUID();
else
DrawAttachGUID();
serializedObject.ApplyModifiedProperties();
}
#endregion
2023-01-22 16:38:23 +01:00
#region GUI Drawing
private void DrawHeaderInfo()
{
2023-01-22 16:38:23 +01:00
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_HEADER_INFORMATION"), MessageType.Info);
}
2023-01-22 16:38:23 +01:00
private void DrawDetachGUID()
{
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_GUID_LABEL") + _objectIdProperty.stringValue, MessageType.Info);
2023-01-22 16:38:23 +01:00
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_DETACH_BUTTON")))
{
bool shouldDetach = EditorUtility.DisplayDialog(
CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_DETACH_BUTTON_DIALOG_TITLE"),
CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_DETACH_BUTTON_DIALOG_BODY"),
CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_DETACH_BUTTON_DIALOG_ACCEPT"),
CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_DETACH_BUTTON_DIALOG_DENY"));
2023-01-22 16:38:23 +01:00
if (shouldDetach)
2023-01-22 16:38:23 +01:00
{
_newGUID = _objectIdProperty.stringValue;
_objectIdProperty.stringValue = string.Empty;
2023-01-22 16:38:23 +01:00
}
}
if (GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_COPY_BUTTON")))
2023-01-22 16:38:23 +01:00
{
if (!string.IsNullOrEmpty(_objectIdProperty.stringValue))
GUIUtility.systemCopyBuffer = _objectIdProperty.stringValue;
2023-01-22 16:38:23 +01:00
}
EditorGUILayout.EndHorizontal();
2023-01-22 16:38:23 +01:00
}
private void DrawAttachGUID()
2023-01-22 16:38:23 +01:00
{
_newGUID = EditorGUILayout.TextField(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_ATTACH_LABEL"), _newGUID);
EditorGUILayout.HelpBox(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_ATTACH_INFO"), MessageType.Warning);
if (!GUILayout.Button(CCKLocalizationProvider.GetLocalizedText("ABI_UI_ASSET_INFO_ATTACH_BUTTON")))
return;
if (System.Guid.TryParse(_newGUID, out _))
_objectIdProperty.stringValue = _newGUID;
2023-01-22 16:38:23 +01:00
}
#endregion
2023-01-22 16:38:23 +01:00
}
}