first commit

This commit is contained in:
SimonSayeBabu
2025-01-17 13:10:20 +01:00
commit bd1057cec0
16967 changed files with 1048699 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f525580684527b147b70cf94aaa70dbc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,71 @@
using UnityEngine;
using UnityEngine.EventSystems;
namespace UnityEditor.EventSystems
{
[CustomEditor(typeof(EventSystem), true)]
/// <summary>
/// Custom Editor for the EventSystem Component.
/// Extend this class to write a custom editor for a component derived from EventSystem.
/// </summary>
public class EventSystemEditor : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
var eventSystem = target as EventSystem;
if (eventSystem == null)
return;
if (eventSystem.GetComponent<BaseInputModule>() != null)
return;
// no input modules :(
if (GUILayout.Button("Add Default Input Modules"))
{
ObjectFactory.AddComponent<StandaloneInputModule>(eventSystem.gameObject);
Undo.RegisterCreatedObjectUndo(eventSystem.gameObject, "Add StandaloneInputModule");
}
}
public override bool HasPreviewGUI()
{
return Application.isPlaying;
}
private GUIStyle m_PreviewLabelStyle;
protected GUIStyle previewLabelStyle
{
get
{
if (m_PreviewLabelStyle == null)
{
m_PreviewLabelStyle = new GUIStyle("PreOverlayLabel")
{
richText = true,
alignment = TextAnchor.UpperLeft,
fontStyle = FontStyle.Normal
};
}
return m_PreviewLabelStyle;
}
}
public override bool RequiresConstantRepaint()
{
return Application.isPlaying;
}
public override void OnPreviewGUI(Rect rect, GUIStyle background)
{
var system = target as EventSystem;
if (system == null)
return;
GUI.Label(rect, system.ToString(), previewLabelStyle);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6f72aa6eab9392548b9e9d92eb6b2ef8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,122 @@
using System;
using UnityEngine;
using UnityEngine.EventSystems;
namespace UnityEditor.EventSystems
{
[CustomEditor(typeof(EventTrigger), true)]
public class EventTriggerEditor : Editor
{
SerializedProperty m_DelegatesProperty;
GUIContent m_IconToolbarMinus;
GUIContent m_EventIDName;
GUIContent[] m_EventTypes;
GUIContent m_AddButonContent;
protected virtual void OnEnable()
{
m_DelegatesProperty = serializedObject.FindProperty("m_Delegates");
m_AddButonContent = EditorGUIUtility.TrTextContent("Add New Event Type");
m_EventIDName = new GUIContent("");
// Have to create a copy since otherwise the tooltip will be overwritten.
m_IconToolbarMinus = new GUIContent(EditorGUIUtility.IconContent("Toolbar Minus"));
m_IconToolbarMinus.tooltip = "Remove all events in this list.";
string[] eventNames = Enum.GetNames(typeof(EventTriggerType));
m_EventTypes = new GUIContent[eventNames.Length];
for (int i = 0; i < eventNames.Length; ++i)
{
m_EventTypes[i] = new GUIContent(eventNames[i]);
}
}
public override void OnInspectorGUI()
{
serializedObject.Update();
int toBeRemovedEntry = -1;
EditorGUILayout.Space();
Vector2 removeButtonSize = GUIStyle.none.CalcSize(m_IconToolbarMinus);
for (int i = 0; i < m_DelegatesProperty.arraySize; ++i)
{
SerializedProperty delegateProperty = m_DelegatesProperty.GetArrayElementAtIndex(i);
SerializedProperty eventProperty = delegateProperty.FindPropertyRelative("eventID");
SerializedProperty callbacksProperty = delegateProperty.FindPropertyRelative("callback");
m_EventIDName.text = eventProperty.enumDisplayNames[eventProperty.enumValueIndex];
EditorGUILayout.PropertyField(callbacksProperty, m_EventIDName);
Rect callbackRect = GUILayoutUtility.GetLastRect();
Rect removeButtonPos = new Rect(callbackRect.xMax - removeButtonSize.x - 8, callbackRect.y + 1, removeButtonSize.x, removeButtonSize.y);
if (GUI.Button(removeButtonPos, m_IconToolbarMinus, GUIStyle.none))
{
toBeRemovedEntry = i;
}
EditorGUILayout.Space();
}
if (toBeRemovedEntry > -1)
{
RemoveEntry(toBeRemovedEntry);
}
Rect btPosition = GUILayoutUtility.GetRect(m_AddButonContent, GUI.skin.button);
const float addButonWidth = 200f;
btPosition.x = btPosition.x + (btPosition.width - addButonWidth) / 2;
btPosition.width = addButonWidth;
if (GUI.Button(btPosition, m_AddButonContent))
{
ShowAddTriggermenu();
}
serializedObject.ApplyModifiedProperties();
}
private void RemoveEntry(int toBeRemovedEntry)
{
m_DelegatesProperty.DeleteArrayElementAtIndex(toBeRemovedEntry);
}
void ShowAddTriggermenu()
{
// Now create the menu, add items and show it
GenericMenu menu = new GenericMenu();
for (int i = 0; i < m_EventTypes.Length; ++i)
{
bool active = true;
// Check if we already have a Entry for the current eventType, if so, disable it
for (int p = 0; p < m_DelegatesProperty.arraySize; ++p)
{
SerializedProperty delegateEntry = m_DelegatesProperty.GetArrayElementAtIndex(p);
SerializedProperty eventProperty = delegateEntry.FindPropertyRelative("eventID");
if (eventProperty.enumValueIndex == i)
{
active = false;
}
}
if (active)
menu.AddItem(m_EventTypes[i], false, OnAddNewSelected, i);
else
menu.AddDisabledItem(m_EventTypes[i]);
}
menu.ShowAsContext();
Event.current.Use();
}
private void OnAddNewSelected(object index)
{
int selected = (int)index;
m_DelegatesProperty.arraySize += 1;
SerializedProperty delegateEntry = m_DelegatesProperty.GetArrayElementAtIndex(m_DelegatesProperty.arraySize - 1);
SerializedProperty eventProperty = delegateEntry.FindPropertyRelative("eventID");
eventProperty.enumValueIndex = selected;
serializedObject.ApplyModifiedProperties();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 37b164a494cd92a498526852ecceedef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
using UnityEngine;
using UnityEngine.EventSystems;
namespace UnityEditor.EventSystems
{
[CustomEditor(typeof(Physics2DRaycaster), true)]
/// <summary>
/// Custom Editor for the EventSystem Component.
/// Extend this class to write a custom editor for a component derived from EventSystem.
/// </summary>
public class Physics2DRaycasterEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
#if !PACKAGE_PHYSICS2D
EditorGUILayout.HelpBox("Physics2D module is not present. This Raycaster will have no effect", MessageType.Warning);
#endif
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1143ae6bb91836f4a8f8ebfaabb9396d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
using UnityEngine.EventSystems;
namespace UnityEditor.EventSystems
{
[CustomEditor(typeof(PhysicsRaycaster), true)]
/// <summary>
/// Custom Editor for the EventSystem Component.
/// Extend this class to write a custom editor for a component derived from EventSystem.
/// </summary>
public class PhysicsRaycasterEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
#if !PACKAGE_PHYSICS
EditorGUILayout.HelpBox("Physics module is not present. This Raycaster will have no effect", MessageType.Warning);
#endif
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e976a5e755c7016418f66e15223c1b90
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: cf97e54bcd5479a46bdbade48da047cc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,38 @@
using System.Reflection;
using System.Runtime.InteropServices;
using UnityEngine;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("UnityEditor.UI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Unity Technologies")]
[assembly: AssemblyProduct("com.unity.ugui")]
[assembly: AssemblyCopyright("Copyright © Unity Technologies 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyIsEditorAssembly]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("ad7418c3-5d25-4670-b468-8e7196596d42")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d51458b261e0ecc4a98904e53924dc1c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 853edc343b78a7c4c81cbb3851d48c0a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,74 @@
using UnityEngine;
using UnityEditor.AnimatedValues;
using UnityEngine.UI;
namespace UnityEditor.UI
{
[CustomEditor(typeof(AspectRatioFitter), true)]
[CanEditMultipleObjects]
/// <summary>
/// Custom Editor for the AspectRatioFitter component.
/// Extend this class to write a custom editor for a component derived from AspectRatioFitter.
/// </summary>
public class AspectRatioFitterEditor : SelfControllerEditor
{
SerializedProperty m_AspectMode;
SerializedProperty m_AspectRatio;
AnimBool m_ModeBool;
private AspectRatioFitter aspectRatioFitter;
protected virtual void OnEnable()
{
m_AspectMode = serializedObject.FindProperty("m_AspectMode");
m_AspectRatio = serializedObject.FindProperty("m_AspectRatio");
aspectRatioFitter = target as AspectRatioFitter;
m_ModeBool = new AnimBool(m_AspectMode.intValue != 0);
m_ModeBool.valueChanged.AddListener(Repaint);
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(m_AspectMode);
m_ModeBool.target = m_AspectMode.intValue != 0;
if (EditorGUILayout.BeginFadeGroup(m_ModeBool.faded))
EditorGUILayout.PropertyField(m_AspectRatio);
EditorGUILayout.EndFadeGroup();
serializedObject.ApplyModifiedProperties();
if (aspectRatioFitter)
{
if (!aspectRatioFitter.IsAspectModeValid())
ShowNoParentWarning();
if (!aspectRatioFitter.IsComponentValidOnObject())
ShowCanvasRenderModeInvalidWarning();
}
base.OnInspectorGUI();
}
protected virtual void OnDisable()
{
aspectRatioFitter = null;
m_ModeBool.valueChanged.RemoveListener(Repaint);
}
private static void ShowNoParentWarning()
{
var text = L10n.Tr("You cannot use this Aspect Mode because this Component's GameObject does not have a parent object.");
EditorGUILayout.HelpBox(text, MessageType.Warning, true);
}
private static void ShowCanvasRenderModeInvalidWarning()
{
var text = L10n.Tr("You cannot use this Aspect Mode because this Component is attached to a Canvas with a fixed width and height.");
EditorGUILayout.HelpBox(text, MessageType.Warning, true);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b5f70efd2f7b286498ca6c00adbb4a13
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,31 @@
using UnityEngine.UI;
namespace UnityEditor.UI
{
[CustomEditor(typeof(Button), true)]
[CanEditMultipleObjects]
/// <summary>
/// Custom Editor for the Button Component.
/// Extend this class to write a custom editor for a component derived from Button.
/// </summary>
public class ButtonEditor : SelectableEditor
{
SerializedProperty m_OnClickProperty;
protected override void OnEnable()
{
base.OnEnable();
m_OnClickProperty = serializedObject.FindProperty("m_OnClick");
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
EditorGUILayout.Space();
serializedObject.Update();
EditorGUILayout.PropertyField(m_OnClickProperty);
serializedObject.ApplyModifiedProperties();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 472a6f18dd2f97c41af72271d22db869
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,184 @@
using UnityEngine;
using UnityEngine.UI;
namespace UnityEditor.UI
{
[CustomEditor(typeof(CanvasScaler), true)]
[CanEditMultipleObjects]
/// <summary>
/// Custom Editor for the CanvasScaler component.
/// Extend this class to write a custom editor for a component derived from CanvasScaler.
/// </summary>
public class CanvasScalerEditor : Editor
{
SerializedProperty m_UiScaleMode;
SerializedProperty m_ScaleFactor;
SerializedProperty m_ReferenceResolution;
SerializedProperty m_ScreenMatchMode;
SerializedProperty m_MatchWidthOrHeight;
SerializedProperty m_PhysicalUnit;
SerializedProperty m_FallbackScreenDPI;
SerializedProperty m_DefaultSpriteDPI;
SerializedProperty m_DynamicPixelsPerUnit;
SerializedProperty m_ReferencePixelsPerUnit;
SerializedProperty m_PresetInfoIsWorld;
const int kSliderEndpointLabelsHeight = 12;
private class Styles
{
public GUIContent matchContent;
public GUIContent widthContent;
public GUIContent heightContent;
public GUIContent uiScaleModeContent;
public GUIStyle leftAlignedLabel;
public GUIStyle rightAlignedLabel;
public Styles()
{
matchContent = EditorGUIUtility.TrTextContent("Match");
widthContent = EditorGUIUtility.TrTextContent("Width");
heightContent = EditorGUIUtility.TrTextContent("Height");
uiScaleModeContent = EditorGUIUtility.TrTextContent("UI Scale Mode");
leftAlignedLabel = new GUIStyle(EditorStyles.label);
rightAlignedLabel = new GUIStyle(EditorStyles.label);
rightAlignedLabel.alignment = TextAnchor.MiddleRight;
}
}
private static Styles s_Styles;
private bool bIsPreset;
protected virtual void OnEnable()
{
m_UiScaleMode = serializedObject.FindProperty("m_UiScaleMode");
m_ScaleFactor = serializedObject.FindProperty("m_ScaleFactor");
m_ReferenceResolution = serializedObject.FindProperty("m_ReferenceResolution");
m_ScreenMatchMode = serializedObject.FindProperty("m_ScreenMatchMode");
m_MatchWidthOrHeight = serializedObject.FindProperty("m_MatchWidthOrHeight");
m_PhysicalUnit = serializedObject.FindProperty("m_PhysicalUnit");
m_FallbackScreenDPI = serializedObject.FindProperty("m_FallbackScreenDPI");
m_DefaultSpriteDPI = serializedObject.FindProperty("m_DefaultSpriteDPI");
m_DynamicPixelsPerUnit = serializedObject.FindProperty("m_DynamicPixelsPerUnit");
m_ReferencePixelsPerUnit = serializedObject.FindProperty("m_ReferencePixelsPerUnit");
m_PresetInfoIsWorld = serializedObject.FindProperty("m_PresetInfoIsWorld");
if (m_SerializedObject == null || m_SerializedObject.targetObject == null)
bIsPreset = false;
else
bIsPreset = m_SerializedObject.targetObject is Component ? ((int)(m_SerializedObject.targetObject as Component).gameObject.hideFlags == 93) : !AssetDatabase.Contains(m_SerializedObject.targetObject);
}
public override void OnInspectorGUI()
{
if (s_Styles == null)
s_Styles = new Styles();
bool allAreRoot = true;
bool showWorldDiffers = false;
bool showWorld = false;
if (bIsPreset)
{
showWorld = m_PresetInfoIsWorld.boolValue;
}
else
{
showWorld = ((target as CanvasScaler).GetComponent<Canvas>().renderMode == RenderMode.WorldSpace);
m_PresetInfoIsWorld.boolValue = showWorld;
serializedObject.ApplyModifiedProperties();
for (int i = 0; i < targets.Length; i++)
{
CanvasScaler scaler = targets[i] as CanvasScaler;
Canvas canvas = scaler.GetComponent<Canvas>();
if (!canvas.isRootCanvas)
{
allAreRoot = false;
break;
}
if (showWorld && canvas.renderMode != RenderMode.WorldSpace || !showWorld && canvas.renderMode == RenderMode.WorldSpace)
{
showWorldDiffers = true;
break;
}
}
if (!allAreRoot)
{
EditorGUILayout.HelpBox("Non-root Canvases will not be scaled.", MessageType.Warning);
return;
}
}
serializedObject.Update();
EditorGUI.showMixedValue = showWorldDiffers;
using (new EditorGUI.DisabledScope(showWorld || showWorldDiffers))
{
if (showWorld || showWorldDiffers)
{
EditorGUILayout.Popup(s_Styles.uiScaleModeContent.text, 0, new[] { "World" });
}
else
{
EditorGUILayout.PropertyField(m_UiScaleMode, s_Styles.uiScaleModeContent);
}
}
EditorGUI.showMixedValue = false;
if (!showWorldDiffers && !(!showWorld && m_UiScaleMode.hasMultipleDifferentValues))
{
EditorGUILayout.Space();
// World Canvas
if (showWorld)
{
EditorGUILayout.PropertyField(m_DynamicPixelsPerUnit);
}
// Constant pixel size
else if (m_UiScaleMode.enumValueIndex == (int)CanvasScaler.ScaleMode.ConstantPixelSize)
{
EditorGUILayout.PropertyField(m_ScaleFactor);
}
// Scale with screen size
else if (m_UiScaleMode.enumValueIndex == (int)CanvasScaler.ScaleMode.ScaleWithScreenSize)
{
EditorGUILayout.PropertyField(m_ReferenceResolution);
EditorGUILayout.PropertyField(m_ScreenMatchMode);
if (m_ScreenMatchMode.enumValueIndex == (int)CanvasScaler.ScreenMatchMode.MatchWidthOrHeight && !m_ScreenMatchMode.hasMultipleDifferentValues)
{
Rect r = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight + kSliderEndpointLabelsHeight);
DualLabeledSlider(r, m_MatchWidthOrHeight, s_Styles.matchContent, s_Styles.widthContent, s_Styles.heightContent);
}
}
// Constant physical size
else if (m_UiScaleMode.enumValueIndex == (int)CanvasScaler.ScaleMode.ConstantPhysicalSize)
{
EditorGUILayout.PropertyField(m_PhysicalUnit);
EditorGUILayout.PropertyField(m_FallbackScreenDPI);
EditorGUILayout.PropertyField(m_DefaultSpriteDPI);
}
EditorGUILayout.PropertyField(m_ReferencePixelsPerUnit);
}
serializedObject.ApplyModifiedProperties();
}
private static void DualLabeledSlider(Rect position, SerializedProperty property, GUIContent mainLabel, GUIContent labelLeft, GUIContent labelRight)
{
position.height = EditorGUIUtility.singleLineHeight;
Rect pos = position;
position.y += 12;
position.xMin += EditorGUIUtility.labelWidth;
position.xMax -= EditorGUIUtility.fieldWidth;
GUI.Label(position, labelLeft, s_Styles.leftAlignedLabel);
GUI.Label(position, labelRight, s_Styles.rightAlignedLabel);
EditorGUI.PropertyField(pos, property, mainLabel);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3bce033ee26244e419b3bb3bba95a37d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,33 @@
using UnityEngine;
using UnityEngine.UI;
namespace UnityEditor.UI
{
[CustomEditor(typeof(ContentSizeFitter), true)]
[CanEditMultipleObjects]
/// <summary>
/// Custom Editor for the ContentSizeFitter Component.
/// Extend this class to write a custom editor for a component derived from ContentSizeFitter.
/// </summary>
public class ContentSizeFitterEditor : SelfControllerEditor
{
SerializedProperty m_HorizontalFit;
SerializedProperty m_VerticalFit;
protected virtual void OnEnable()
{
m_HorizontalFit = serializedObject.FindProperty("m_HorizontalFit");
m_VerticalFit = serializedObject.FindProperty("m_VerticalFit");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(m_HorizontalFit, true);
EditorGUILayout.PropertyField(m_VerticalFit, true);
serializedObject.ApplyModifiedProperties();
base.OnInspectorGUI();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 35d143b352678294ab0f5feb97b67f88
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,55 @@
using UnityEngine.UI;
namespace UnityEditor.UI
{
[CustomEditor(typeof(Dropdown), true)]
[CanEditMultipleObjects]
/// <summary>
/// Custom editor for the Dropdown component
/// Extend this class to write a custom editor for a component derived from Dropdown.
/// </summary>
public class DropdownEditor : SelectableEditor
{
SerializedProperty m_Template;
SerializedProperty m_CaptionText;
SerializedProperty m_CaptionImage;
SerializedProperty m_ItemText;
SerializedProperty m_ItemImage;
SerializedProperty m_OnSelectionChanged;
SerializedProperty m_Value;
SerializedProperty m_Options;
SerializedProperty m_AlphaFadeSpeed;
protected override void OnEnable()
{
base.OnEnable();
m_Template = serializedObject.FindProperty("m_Template");
m_CaptionText = serializedObject.FindProperty("m_CaptionText");
m_CaptionImage = serializedObject.FindProperty("m_CaptionImage");
m_ItemText = serializedObject.FindProperty("m_ItemText");
m_ItemImage = serializedObject.FindProperty("m_ItemImage");
m_OnSelectionChanged = serializedObject.FindProperty("m_OnValueChanged");
m_Value = serializedObject.FindProperty("m_Value");
m_Options = serializedObject.FindProperty("m_Options");
m_AlphaFadeSpeed = serializedObject.FindProperty("m_AlphaFadeSpeed");
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
EditorGUILayout.Space();
serializedObject.Update();
EditorGUILayout.PropertyField(m_Template);
EditorGUILayout.PropertyField(m_CaptionText);
EditorGUILayout.PropertyField(m_CaptionImage);
EditorGUILayout.PropertyField(m_ItemText);
EditorGUILayout.PropertyField(m_ItemImage);
EditorGUILayout.PropertyField(m_Value);
EditorGUILayout.PropertyField(m_AlphaFadeSpeed);
EditorGUILayout.PropertyField(m_Options);
EditorGUILayout.PropertyField(m_OnSelectionChanged);
serializedObject.ApplyModifiedProperties();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 05f582d4fbc8e0c40afccb76bbbe0935
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,215 @@
using System.Linq;
using UnityEditor.AnimatedValues;
using UnityEngine;
using UnityEngine.UI;
namespace UnityEditor.UI
{
/// <summary>
/// Editor class used to edit UI Graphics.
/// Extend this class to write your own graphic editor.
/// </summary>
[CustomEditor(typeof(MaskableGraphic), false)]
[CanEditMultipleObjects]
public class GraphicEditor : Editor
{
protected SerializedProperty m_Script;
protected SerializedProperty m_Color;
protected SerializedProperty m_Material;
protected SerializedProperty m_RaycastTarget;
protected SerializedProperty m_RaycastPadding;
protected SerializedProperty m_Maskable;
private GUIContent m_CorrectButtonContent;
protected AnimBool m_ShowNativeSize;
GUIContent m_PaddingContent;
GUIContent m_LeftContent;
GUIContent m_RightContent;
GUIContent m_TopContent;
GUIContent m_BottomContent;
static private bool m_ShowPadding = false;
protected virtual void OnDisable()
{
Tools.hidden = false;
m_ShowNativeSize.valueChanged.RemoveListener(Repaint);
SceneView.duringSceneGui -= DrawAnchorsOnSceneView;
}
protected virtual void OnEnable()
{
m_CorrectButtonContent = EditorGUIUtility.TrTextContent("Set Native Size", "Sets the size to match the content.");
m_PaddingContent = EditorGUIUtility.TrTextContent("Raycast Padding");
m_LeftContent = EditorGUIUtility.TrTextContent("Left");
m_RightContent = EditorGUIUtility.TrTextContent("Right");
m_TopContent = EditorGUIUtility.TrTextContent("Top");
m_BottomContent = EditorGUIUtility.TrTextContent("Bottom");
m_Script = serializedObject.FindProperty("m_Script");
m_Color = serializedObject.FindProperty("m_Color");
m_Material = serializedObject.FindProperty("m_Material");
m_RaycastTarget = serializedObject.FindProperty("m_RaycastTarget");
m_RaycastPadding = serializedObject.FindProperty("m_RaycastPadding");
m_Maskable = serializedObject.FindProperty("m_Maskable");
m_ShowNativeSize = new AnimBool(false);
m_ShowNativeSize.valueChanged.AddListener(Repaint);
SceneView.duringSceneGui += DrawAnchorsOnSceneView;
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(m_Script);
AppearanceControlsGUI();
RaycastControlsGUI();
MaskableControlsGUI();
serializedObject.ApplyModifiedProperties();
}
void DrawAnchorsOnSceneView(SceneView sceneView)
{
if (!target || targets.Length > 1)
return;
if (!sceneView.drawGizmos || !EditorGUIUtility.IsGizmosAllowedForObject(target))
return;
Graphic graphic = target as Graphic;
RectTransform gui = graphic.rectTransform;
Transform ownSpace = gui.transform;
Rect rectInOwnSpace = gui.rect;
Handles.color = Handles.UIColliderHandleColor;
DrawRect(rectInOwnSpace, ownSpace, graphic.raycastPadding);
}
void DrawRect(Rect rect, Transform space, Vector4 offset)
{
Vector3 p0 = space.TransformPoint(new Vector2(rect.x + offset.x, rect.y + offset.y));
Vector3 p1 = space.TransformPoint(new Vector2(rect.x + offset.x, rect.yMax - offset.w));
Vector3 p2 = space.TransformPoint(new Vector2(rect.xMax - offset.z, rect.yMax - offset.w));
Vector3 p3 = space.TransformPoint(new Vector2(rect.xMax - offset.z, rect.y + offset.y));
Handles.DrawLine(p0, p1);
Handles.DrawLine(p1, p2);
Handles.DrawLine(p2, p3);
Handles.DrawLine(p3, p0);
}
/// <summary>
/// Set if the 'Set Native Size' button should be visible for this editor.
/// </summary>
/// <param name="show">Are we showing or hiding the AnimBool for the size.</param>
/// <param name="instant">Should the size AnimBool change instantly.</param>
protected void SetShowNativeSize(bool show, bool instant)
{
if (instant)
m_ShowNativeSize.value = show;
else
m_ShowNativeSize.target = show;
}
/// <summary>
/// GUI for showing a button that sets the size of the RectTransform to the native size for this Graphic.
/// </summary>
protected void NativeSizeButtonGUI()
{
if (EditorGUILayout.BeginFadeGroup(m_ShowNativeSize.faded))
{
EditorGUILayout.BeginHorizontal();
{
GUILayout.Space(EditorGUIUtility.labelWidth);
if (GUILayout.Button(m_CorrectButtonContent, EditorStyles.miniButton))
{
foreach (Graphic graphic in targets.Select(obj => obj as Graphic))
{
Undo.RecordObject(graphic.rectTransform, "Set Native Size");
graphic.SetNativeSize();
EditorUtility.SetDirty(graphic);
}
}
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndFadeGroup();
}
protected void MaskableControlsGUI()
{
EditorGUILayout.PropertyField(m_Maskable);
}
/// <summary>
/// GUI related to the appearance of the Graphic. Color and Material properties appear here.
/// </summary>
protected void AppearanceControlsGUI()
{
EditorGUILayout.PropertyField(m_Color);
EditorGUILayout.PropertyField(m_Material);
}
/// <summary>
/// GUI related to the Raycasting settings for the graphic.
/// </summary>
protected void RaycastControlsGUI()
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_RaycastTarget);
if (EditorGUI.EndChangeCheck() && target is Graphic graphic)
{
graphic.SetRaycastDirty();
}
float height = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (m_ShowPadding)
height += (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) * 4;
var rect = EditorGUILayout.GetControlRect(true, height);
EditorGUI.BeginProperty(rect, m_PaddingContent, m_RaycastPadding);
rect.height = EditorGUIUtility.singleLineHeight;
using (var check = new EditorGUI.ChangeCheckScope())
{
m_ShowPadding = EditorGUI.Foldout(rect, m_ShowPadding, m_PaddingContent, true);
if (check.changed)
{
SceneView.RepaintAll();
}
}
if (m_ShowPadding)
{
using (var check = new EditorGUI.ChangeCheckScope())
{
EditorGUI.indentLevel++;
Vector4 newPadding = m_RaycastPadding.vector4Value;
rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
newPadding.x = EditorGUI.FloatField(rect, m_LeftContent, newPadding.x);
rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
newPadding.y = EditorGUI.FloatField(rect, m_BottomContent, newPadding.y);
rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
newPadding.z = EditorGUI.FloatField(rect, m_RightContent, newPadding.z);
rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
newPadding.w = EditorGUI.FloatField(rect, m_TopContent, newPadding.w);
if (check.changed)
{
m_RaycastPadding.vector4Value = newPadding;
}
EditorGUI.indentLevel--;
}
}
EditorGUI.EndProperty();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c890977a36bfdc849872b9337ab89098
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,56 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEditorInternal;
using UnityEditor.AnimatedValues;
namespace UnityEditor.UI
{
[CustomEditor(typeof(GridLayoutGroup), true)]
[CanEditMultipleObjects]
/// <summary>
/// Custom Editor for the GridLayout Component.
/// Extend this class to write a custom editor for a component derived from GridLayout.
/// </summary>
public class GridLayoutGroupEditor : Editor
{
SerializedProperty m_Padding;
SerializedProperty m_CellSize;
SerializedProperty m_Spacing;
SerializedProperty m_StartCorner;
SerializedProperty m_StartAxis;
SerializedProperty m_ChildAlignment;
SerializedProperty m_Constraint;
SerializedProperty m_ConstraintCount;
protected virtual void OnEnable()
{
m_Padding = serializedObject.FindProperty("m_Padding");
m_CellSize = serializedObject.FindProperty("m_CellSize");
m_Spacing = serializedObject.FindProperty("m_Spacing");
m_StartCorner = serializedObject.FindProperty("m_StartCorner");
m_StartAxis = serializedObject.FindProperty("m_StartAxis");
m_ChildAlignment = serializedObject.FindProperty("m_ChildAlignment");
m_Constraint = serializedObject.FindProperty("m_Constraint");
m_ConstraintCount = serializedObject.FindProperty("m_ConstraintCount");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(m_Padding, true);
EditorGUILayout.PropertyField(m_CellSize, true);
EditorGUILayout.PropertyField(m_Spacing, true);
EditorGUILayout.PropertyField(m_StartCorner, true);
EditorGUILayout.PropertyField(m_StartAxis, true);
EditorGUILayout.PropertyField(m_ChildAlignment, true);
EditorGUILayout.PropertyField(m_Constraint, true);
if (m_Constraint.enumValueIndex > 0)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_ConstraintCount, true);
EditorGUI.indentLevel--;
}
serializedObject.ApplyModifiedProperties();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6a981cd1456bec84b86e1c66773f57f5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,95 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEditorInternal;
using UnityEditor.AnimatedValues;
namespace UnityEditor.UI
{
[CustomEditor(typeof(HorizontalOrVerticalLayoutGroup), true)]
[CanEditMultipleObjects]
/// <summary>
/// Custom Editor for the HorizontalOrVerticalLayoutGroupEditor Component.
/// Extend this class to write a custom editor for a component derived from HorizontalOrVerticalLayoutGroupEditor.
/// </summary>
public class HorizontalOrVerticalLayoutGroupEditor : Editor
{
SerializedProperty m_Padding;
SerializedProperty m_Spacing;
SerializedProperty m_ChildAlignment;
SerializedProperty m_ChildControlWidth;
SerializedProperty m_ChildControlHeight;
SerializedProperty m_ChildScaleWidth;
SerializedProperty m_ChildScaleHeight;
SerializedProperty m_ChildForceExpandWidth;
SerializedProperty m_ChildForceExpandHeight;
SerializedProperty m_ReverseArrangement;
protected virtual void OnEnable()
{
m_Padding = serializedObject.FindProperty("m_Padding");
m_Spacing = serializedObject.FindProperty("m_Spacing");
m_ChildAlignment = serializedObject.FindProperty("m_ChildAlignment");
m_ChildControlWidth = serializedObject.FindProperty("m_ChildControlWidth");
m_ChildControlHeight = serializedObject.FindProperty("m_ChildControlHeight");
m_ChildScaleWidth = serializedObject.FindProperty("m_ChildScaleWidth");
m_ChildScaleHeight = serializedObject.FindProperty("m_ChildScaleHeight");
m_ChildForceExpandWidth = serializedObject.FindProperty("m_ChildForceExpandWidth");
m_ChildForceExpandHeight = serializedObject.FindProperty("m_ChildForceExpandHeight");
m_ReverseArrangement = serializedObject.FindProperty("m_ReverseArrangement");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(m_Padding, true);
EditorGUILayout.PropertyField(m_Spacing, true);
EditorGUILayout.PropertyField(m_ChildAlignment, true);
EditorGUILayout.PropertyField(m_ReverseArrangement, true);
Rect rect = EditorGUILayout.GetControlRect();
rect = EditorGUI.PrefixLabel(rect, -1, EditorGUIUtility.TrTextContent("Control Child Size"));
rect.width = Mathf.Max(50, (rect.width - 4) / 3);
EditorGUIUtility.labelWidth = 50;
ToggleLeft(rect, m_ChildControlWidth, EditorGUIUtility.TrTextContent("Width"));
rect.x += rect.width + 2;
ToggleLeft(rect, m_ChildControlHeight, EditorGUIUtility.TrTextContent("Height"));
EditorGUIUtility.labelWidth = 0;
rect = EditorGUILayout.GetControlRect();
rect = EditorGUI.PrefixLabel(rect, -1, EditorGUIUtility.TrTextContent("Use Child Scale"));
rect.width = Mathf.Max(50, (rect.width - 4) / 3);
EditorGUIUtility.labelWidth = 50;
ToggleLeft(rect, m_ChildScaleWidth, EditorGUIUtility.TrTextContent("Width"));
rect.x += rect.width + 2;
ToggleLeft(rect, m_ChildScaleHeight, EditorGUIUtility.TrTextContent("Height"));
EditorGUIUtility.labelWidth = 0;
rect = EditorGUILayout.GetControlRect();
rect = EditorGUI.PrefixLabel(rect, -1, EditorGUIUtility.TrTextContent("Child Force Expand"));
rect.width = Mathf.Max(50, (rect.width - 4) / 3);
EditorGUIUtility.labelWidth = 50;
ToggleLeft(rect, m_ChildForceExpandWidth, EditorGUIUtility.TrTextContent("Width"));
rect.x += rect.width + 2;
ToggleLeft(rect, m_ChildForceExpandHeight, EditorGUIUtility.TrTextContent("Height"));
EditorGUIUtility.labelWidth = 0;
serializedObject.ApplyModifiedProperties();
}
void ToggleLeft(Rect position, SerializedProperty property, GUIContent label)
{
bool toggle = property.boolValue;
EditorGUI.BeginProperty(position, label, property);
EditorGUI.BeginChangeCheck();
int oldIndent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
toggle = EditorGUI.ToggleLeft(position, label, toggle);
EditorGUI.indentLevel = oldIndent;
if (EditorGUI.EndChangeCheck())
{
property.boolValue = property.hasMultipleDifferentValues ? true : !property.boolValue;
}
EditorGUI.EndProperty();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cb319974ad8ebd44aa1e1fbb02640b5b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,326 @@
using System.Linq;
using UnityEngine;
using UnityEditor.AnimatedValues;
using UnityEngine.UI;
namespace UnityEditor.UI
{
/// <summary>
/// Editor class used to edit UI Sprites.
/// </summary>
[CustomEditor(typeof(Image), true)]
[CanEditMultipleObjects]
/// <summary>
/// Custom Editor for the Image Component.
/// Extend this class to write a custom editor for a component derived from Image.
/// </summary>
public class ImageEditor : GraphicEditor
{
SerializedProperty m_FillMethod;
SerializedProperty m_FillOrigin;
SerializedProperty m_FillAmount;
SerializedProperty m_FillClockwise;
SerializedProperty m_Type;
SerializedProperty m_FillCenter;
SerializedProperty m_Sprite;
SerializedProperty m_PreserveAspect;
SerializedProperty m_UseSpriteMesh;
SerializedProperty m_PixelsPerUnitMultiplier;
GUIContent m_SpriteContent;
GUIContent m_SpriteTypeContent;
GUIContent m_ClockwiseContent;
AnimBool m_ShowSlicedOrTiled;
AnimBool m_ShowSliced;
AnimBool m_ShowTiled;
AnimBool m_ShowFilled;
AnimBool m_ShowType;
bool m_bIsDriven;
private class Styles
{
public static GUIContent text = EditorGUIUtility.TrTextContent("Fill Origin");
public static GUIContent[] OriginHorizontalStyle =
{
EditorGUIUtility.TrTextContent("Left"),
EditorGUIUtility.TrTextContent("Right")
};
public static GUIContent[] OriginVerticalStyle =
{
EditorGUIUtility.TrTextContent("Bottom"),
EditorGUIUtility.TrTextContent("Top")
};
public static GUIContent[] Origin90Style =
{
EditorGUIUtility.TrTextContent("BottomLeft"),
EditorGUIUtility.TrTextContent("TopLeft"),
EditorGUIUtility.TrTextContent("TopRight"),
EditorGUIUtility.TrTextContent("BottomRight")
};
public static GUIContent[] Origin180Style =
{
EditorGUIUtility.TrTextContent("Bottom"),
EditorGUIUtility.TrTextContent("Left"),
EditorGUIUtility.TrTextContent("Top"),
EditorGUIUtility.TrTextContent("Right")
};
public static GUIContent[] Origin360Style =
{
EditorGUIUtility.TrTextContent("Bottom"),
EditorGUIUtility.TrTextContent("Right"),
EditorGUIUtility.TrTextContent("Top"),
EditorGUIUtility.TrTextContent("Left")
};
}
protected override void OnEnable()
{
base.OnEnable();
m_SpriteContent = EditorGUIUtility.TrTextContent("Source Image");
m_SpriteTypeContent = EditorGUIUtility.TrTextContent("Image Type");
m_ClockwiseContent = EditorGUIUtility.TrTextContent("Clockwise");
m_Sprite = serializedObject.FindProperty("m_Sprite");
m_Type = serializedObject.FindProperty("m_Type");
m_FillCenter = serializedObject.FindProperty("m_FillCenter");
m_FillMethod = serializedObject.FindProperty("m_FillMethod");
m_FillOrigin = serializedObject.FindProperty("m_FillOrigin");
m_FillClockwise = serializedObject.FindProperty("m_FillClockwise");
m_FillAmount = serializedObject.FindProperty("m_FillAmount");
m_PreserveAspect = serializedObject.FindProperty("m_PreserveAspect");
m_UseSpriteMesh = serializedObject.FindProperty("m_UseSpriteMesh");
m_PixelsPerUnitMultiplier = serializedObject.FindProperty("m_PixelsPerUnitMultiplier");
m_ShowType = new AnimBool(m_Sprite.objectReferenceValue != null);
m_ShowType.valueChanged.AddListener(Repaint);
var typeEnum = (Image.Type)m_Type.enumValueIndex;
m_ShowSlicedOrTiled = new AnimBool(!m_Type.hasMultipleDifferentValues && typeEnum == Image.Type.Sliced);
m_ShowSliced = new AnimBool(!m_Type.hasMultipleDifferentValues && typeEnum == Image.Type.Sliced);
m_ShowTiled = new AnimBool(!m_Type.hasMultipleDifferentValues && typeEnum == Image.Type.Tiled);
m_ShowFilled = new AnimBool(!m_Type.hasMultipleDifferentValues && typeEnum == Image.Type.Filled);
m_ShowSlicedOrTiled.valueChanged.AddListener(Repaint);
m_ShowSliced.valueChanged.AddListener(Repaint);
m_ShowTiled.valueChanged.AddListener(Repaint);
m_ShowFilled.valueChanged.AddListener(Repaint);
SetShowNativeSize(true);
m_bIsDriven = false;
}
protected override void OnDisable()
{
base.OnDisable();
m_ShowType.valueChanged.RemoveListener(Repaint);
m_ShowSlicedOrTiled.valueChanged.RemoveListener(Repaint);
m_ShowSliced.valueChanged.RemoveListener(Repaint);
m_ShowTiled.valueChanged.RemoveListener(Repaint);
m_ShowFilled.valueChanged.RemoveListener(Repaint);
}
public override void OnInspectorGUI()
{
serializedObject.Update();
Image image = target as Image;
RectTransform rect = image.GetComponent<RectTransform>();
m_bIsDriven = (rect.drivenByObject as Slider)?.fillRect == rect;
SpriteGUI();
AppearanceControlsGUI();
RaycastControlsGUI();
MaskableControlsGUI();
m_ShowType.target = m_Sprite.objectReferenceValue != null;
if (EditorGUILayout.BeginFadeGroup(m_ShowType.faded))
TypeGUI();
EditorGUILayout.EndFadeGroup();
SetShowNativeSize(false);
if (EditorGUILayout.BeginFadeGroup(m_ShowNativeSize.faded))
{
EditorGUI.indentLevel++;
if ((Image.Type)m_Type.enumValueIndex == Image.Type.Simple)
EditorGUILayout.PropertyField(m_UseSpriteMesh);
EditorGUILayout.PropertyField(m_PreserveAspect);
EditorGUI.indentLevel--;
}
EditorGUILayout.EndFadeGroup();
NativeSizeButtonGUI();
serializedObject.ApplyModifiedProperties();
}
void SetShowNativeSize(bool instant)
{
Image.Type type = (Image.Type)m_Type.enumValueIndex;
bool showNativeSize = (type == Image.Type.Simple || type == Image.Type.Filled) && m_Sprite.objectReferenceValue != null;
base.SetShowNativeSize(showNativeSize, instant);
}
/// <summary>
/// Draw the atlas and Image selection fields.
/// </summary>
protected void SpriteGUI()
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_Sprite, m_SpriteContent);
if (EditorGUI.EndChangeCheck())
{
var newSprite = m_Sprite.objectReferenceValue as Sprite;
if (newSprite)
{
Image.Type oldType = (Image.Type)m_Type.enumValueIndex;
if (newSprite.border.SqrMagnitude() > 0)
{
m_Type.enumValueIndex = (int)Image.Type.Sliced;
}
else if (oldType == Image.Type.Sliced)
{
m_Type.enumValueIndex = (int)Image.Type.Simple;
}
}
(serializedObject.targetObject as Image).DisableSpriteOptimizations();
}
}
/// <summary>
/// Sprites's custom properties based on the type.
/// </summary>
protected void TypeGUI()
{
EditorGUILayout.PropertyField(m_Type, m_SpriteTypeContent);
++EditorGUI.indentLevel;
{
Image.Type typeEnum = (Image.Type)m_Type.enumValueIndex;
bool showSlicedOrTiled = (!m_Type.hasMultipleDifferentValues && (typeEnum == Image.Type.Sliced || typeEnum == Image.Type.Tiled));
if (showSlicedOrTiled && targets.Length > 1)
showSlicedOrTiled = targets.Select(obj => obj as Image).All(img => img.hasBorder);
m_ShowSlicedOrTiled.target = showSlicedOrTiled;
m_ShowSliced.target = (showSlicedOrTiled && !m_Type.hasMultipleDifferentValues && typeEnum == Image.Type.Sliced);
m_ShowTiled.target = (showSlicedOrTiled && !m_Type.hasMultipleDifferentValues && typeEnum == Image.Type.Tiled);
m_ShowFilled.target = (!m_Type.hasMultipleDifferentValues && typeEnum == Image.Type.Filled);
Image image = target as Image;
if (EditorGUILayout.BeginFadeGroup(m_ShowSlicedOrTiled.faded))
{
if (image.hasBorder)
EditorGUILayout.PropertyField(m_FillCenter);
EditorGUILayout.PropertyField(m_PixelsPerUnitMultiplier);
}
EditorGUILayout.EndFadeGroup();
if (EditorGUILayout.BeginFadeGroup(m_ShowSliced.faded))
{
if (image.sprite != null && !image.hasBorder)
EditorGUILayout.HelpBox("This Image doesn't have a border.", MessageType.Warning);
}
EditorGUILayout.EndFadeGroup();
if (EditorGUILayout.BeginFadeGroup(m_ShowTiled.faded))
{
if (image.sprite != null && !image.hasBorder && (image.sprite.texture != null && image.sprite.texture.wrapMode != TextureWrapMode.Repeat || image.sprite.packed))
EditorGUILayout.HelpBox("It looks like you want to tile a sprite with no border. It would be more efficient to modify the Sprite properties, clear the Packing tag and set the Wrap mode to Repeat.", MessageType.Warning);
}
EditorGUILayout.EndFadeGroup();
if (EditorGUILayout.BeginFadeGroup(m_ShowFilled.faded))
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_FillMethod);
if (EditorGUI.EndChangeCheck())
{
m_FillOrigin.intValue = 0;
}
var shapeRect = EditorGUILayout.GetControlRect(true);
switch ((Image.FillMethod)m_FillMethod.enumValueIndex)
{
case Image.FillMethod.Horizontal:
EditorGUI.Popup(shapeRect, m_FillOrigin, Styles.OriginHorizontalStyle, Styles.text);
break;
case Image.FillMethod.Vertical:
EditorGUI.Popup(shapeRect, m_FillOrigin, Styles.OriginVerticalStyle, Styles.text);
break;
case Image.FillMethod.Radial90:
EditorGUI.Popup(shapeRect, m_FillOrigin, Styles.Origin90Style, Styles.text);
break;
case Image.FillMethod.Radial180:
EditorGUI.Popup(shapeRect, m_FillOrigin, Styles.Origin180Style, Styles.text);
break;
case Image.FillMethod.Radial360:
EditorGUI.Popup(shapeRect, m_FillOrigin, Styles.Origin360Style, Styles.text);
break;
}
if (m_bIsDriven)
EditorGUILayout.HelpBox("The Fill amount property is driven by Slider.", MessageType.None);
using (new EditorGUI.DisabledScope(m_bIsDriven))
{
EditorGUILayout.PropertyField(m_FillAmount);
}
if ((Image.FillMethod)m_FillMethod.enumValueIndex > Image.FillMethod.Vertical)
{
EditorGUILayout.PropertyField(m_FillClockwise, m_ClockwiseContent);
}
}
EditorGUILayout.EndFadeGroup();
}
--EditorGUI.indentLevel;
}
/// <summary>
/// All graphics have a preview.
/// </summary>
public override bool HasPreviewGUI() { return true; }
/// <summary>
/// Draw the Image preview.
/// </summary>
public override void OnPreviewGUI(Rect rect, GUIStyle background)
{
Image image = target as Image;
if (image == null) return;
Sprite sf = image.sprite;
if (sf == null) return;
SpriteDrawUtility.DrawSprite(sf, rect, image.canvasRenderer.GetColor());
}
/// <summary>
/// A string containing the Image details to be used as a overlay on the component Preview.
/// </summary>
/// <returns>
/// The Image details.
/// </returns>
public override string GetInfoString()
{
Image image = target as Image;
Sprite sprite = image.sprite;
int x = (sprite != null) ? Mathf.RoundToInt(sprite.rect.width) : 0;
int y = (sprite != null) ? Mathf.RoundToInt(sprite.rect.height) : 0;
return string.Format("Image Size: {0}x{1}", x, y);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b759d61544e231c41bc88530b1d94ee8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,151 @@
using UnityEditor.AnimatedValues;
using UnityEngine;
using UnityEngine.UI;
namespace UnityEditor.UI
{
[CanEditMultipleObjects]
[CustomEditor(typeof(InputField), true)]
/// <summary>
/// Custom Editor for the InputField Component.
/// Extend this class to write a custom editor for a component derived from InputField.
/// </summary>
public class InputFieldEditor : SelectableEditor
{
SerializedProperty m_TextComponent;
SerializedProperty m_Text;
SerializedProperty m_ContentType;
SerializedProperty m_LineType;
SerializedProperty m_InputType;
SerializedProperty m_CharacterValidation;
SerializedProperty m_KeyboardType;
SerializedProperty m_CharacterLimit;
SerializedProperty m_CaretBlinkRate;
SerializedProperty m_CaretWidth;
SerializedProperty m_CaretColor;
SerializedProperty m_CustomCaretColor;
SerializedProperty m_SelectionColor;
SerializedProperty m_HideMobileInput;
SerializedProperty m_Placeholder;
SerializedProperty m_OnValueChanged;
SerializedProperty m_OnSubmit;
SerializedProperty m_OnDidEndEdit;
SerializedProperty m_ReadOnly;
SerializedProperty m_ShouldActivateOnSelect;
AnimBool m_CustomColor;
GUIContent m_EndEditContent = new GUIContent("On End Edit");
protected override void OnEnable()
{
base.OnEnable();
m_TextComponent = serializedObject.FindProperty("m_TextComponent");
m_Text = serializedObject.FindProperty("m_Text");
m_ContentType = serializedObject.FindProperty("m_ContentType");
m_LineType = serializedObject.FindProperty("m_LineType");
m_InputType = serializedObject.FindProperty("m_InputType");
m_CharacterValidation = serializedObject.FindProperty("m_CharacterValidation");
m_KeyboardType = serializedObject.FindProperty("m_KeyboardType");
m_CharacterLimit = serializedObject.FindProperty("m_CharacterLimit");
m_CaretBlinkRate = serializedObject.FindProperty("m_CaretBlinkRate");
m_CaretWidth = serializedObject.FindProperty("m_CaretWidth");
m_CaretColor = serializedObject.FindProperty("m_CaretColor");
m_CustomCaretColor = serializedObject.FindProperty("m_CustomCaretColor");
m_SelectionColor = serializedObject.FindProperty("m_SelectionColor");
m_HideMobileInput = serializedObject.FindProperty("m_HideMobileInput");
m_Placeholder = serializedObject.FindProperty("m_Placeholder");
m_OnValueChanged = serializedObject.FindProperty("m_OnValueChanged");
m_OnSubmit = serializedObject.FindProperty("m_OnSubmit");
m_OnDidEndEdit = serializedObject.FindProperty("m_OnDidEndEdit");
m_ReadOnly = serializedObject.FindProperty("m_ReadOnly");
m_ShouldActivateOnSelect = serializedObject.FindProperty("m_ShouldActivateOnSelect");
m_CustomColor = new AnimBool(m_CustomCaretColor.boolValue);
m_CustomColor.valueChanged.AddListener(Repaint);
}
protected override void OnDisable()
{
base.OnDisable();
m_CustomColor.valueChanged.RemoveListener(Repaint);
}
public override void OnInspectorGUI()
{
serializedObject.Update();
base.OnInspectorGUI();
EditorGUILayout.Space();
EditorGUILayout.PropertyField(m_TextComponent);
if (m_TextComponent != null && m_TextComponent.objectReferenceValue != null)
{
Text text = m_TextComponent.objectReferenceValue as Text;
if (text.supportRichText)
{
EditorGUILayout.HelpBox("Using Rich Text with input is unsupported.", MessageType.Warning);
}
}
using (new EditorGUI.DisabledScope(m_TextComponent == null || m_TextComponent.objectReferenceValue == null))
{
EditorGUILayout.PropertyField(m_Text);
EditorGUILayout.PropertyField(m_CharacterLimit);
EditorGUILayout.Space();
EditorGUILayout.PropertyField(m_ContentType);
if (!m_ContentType.hasMultipleDifferentValues)
{
EditorGUI.indentLevel++;
if (m_ContentType.enumValueIndex == (int)InputField.ContentType.Standard ||
m_ContentType.enumValueIndex == (int)InputField.ContentType.Autocorrected ||
m_ContentType.enumValueIndex == (int)InputField.ContentType.Custom)
EditorGUILayout.PropertyField(m_LineType);
if (m_ContentType.enumValueIndex == (int)InputField.ContentType.Custom)
{
EditorGUILayout.PropertyField(m_InputType);
EditorGUILayout.PropertyField(m_KeyboardType);
EditorGUILayout.PropertyField(m_CharacterValidation);
}
EditorGUI.indentLevel--;
}
EditorGUILayout.Space();
EditorGUILayout.PropertyField(m_Placeholder);
EditorGUILayout.PropertyField(m_CaretBlinkRate);
EditorGUILayout.PropertyField(m_CaretWidth);
EditorGUILayout.PropertyField(m_CustomCaretColor);
m_CustomColor.target = m_CustomCaretColor.boolValue;
if (EditorGUILayout.BeginFadeGroup(m_CustomColor.faded))
{
EditorGUILayout.PropertyField(m_CaretColor);
}
EditorGUILayout.EndFadeGroup();
EditorGUILayout.PropertyField(m_SelectionColor);
EditorGUILayout.PropertyField(m_HideMobileInput);
EditorGUILayout.PropertyField(m_ReadOnly);
EditorGUILayout.PropertyField(m_ShouldActivateOnSelect);
EditorGUILayout.Space();
EditorGUILayout.PropertyField(m_OnValueChanged);
EditorGUILayout.PropertyField(m_OnSubmit);
EditorGUILayout.PropertyField(m_OnDidEndEdit, m_EndEditContent);
}
serializedObject.ApplyModifiedProperties();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 21d2d5d6901f2ca43a8015c60ada4e2c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,270 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.EventSystems;
namespace UnityEditor.Events
{
[CustomPreview(typeof(GameObject))]
/// <summary>
/// Custom preview drawing that will draw the intercepted events of a given object.
/// </summary>
class InterceptedEventsPreview : ObjectPreview
{
protected class ComponentInterceptedEvents
{
public GUIContent componentName;
public int[] interceptedEvents;
}
class Styles
{
public GUIStyle labelStyle = new GUIStyle(EditorStyles.label);
public GUIStyle componentName = new GUIStyle(EditorStyles.boldLabel);
public Styles()
{
Color fontColor = new Color(0.7f, 0.7f, 0.7f);
labelStyle.padding.right += 20;
labelStyle.normal.textColor = fontColor;
labelStyle.active.textColor = fontColor;
labelStyle.focused.textColor = fontColor;
labelStyle.hover.textColor = fontColor;
labelStyle.onNormal.textColor = fontColor;
labelStyle.onActive.textColor = fontColor;
labelStyle.onFocused.textColor = fontColor;
labelStyle.onHover.textColor = fontColor;
componentName.normal.textColor = fontColor;
componentName.active.textColor = fontColor;
componentName.focused.textColor = fontColor;
componentName.hover.textColor = fontColor;
componentName.onNormal.textColor = fontColor;
componentName.onActive.textColor = fontColor;
componentName.onFocused.textColor = fontColor;
componentName.onHover.textColor = fontColor;
}
}
private Dictionary<GameObject, List<ComponentInterceptedEvents>> m_TargetEvents;
private bool m_InterceptsAnyEvent = false;
private GUIContent m_Title;
private Styles m_Styles;
public override void Initialize(UnityEngine.Object[] targets)
{
Profiler.BeginSample("ComponentInterceptedEvents.Initialize");
base.Initialize(targets);
m_TargetEvents = new Dictionary<GameObject, List<ComponentInterceptedEvents>>(targets.Length);
m_InterceptsAnyEvent = false;
for (int i = 0; i < targets.Length; ++i)
{
GameObject go = targets[i] as GameObject;
List<ComponentInterceptedEvents> interceptedEvents = GetEventsInfo(go);
m_TargetEvents.Add(go, interceptedEvents);
if (interceptedEvents.Any())
m_InterceptsAnyEvent = true;
}
Profiler.EndSample();
}
public override GUIContent GetPreviewTitle()
{
if (m_Title == null)
{
m_Title = EditorGUIUtility.TrTextContent("Intercepted Events");
}
return m_Title;
}
public override bool HasPreviewGUI()
{
return m_TargetEvents != null && m_InterceptsAnyEvent;
}
public override void OnPreviewGUI(Rect r, GUIStyle background)
{
if (Event.current.type != EventType.Repaint)
return;
Profiler.BeginSample("InterceptedEventsPreview.OnPreviewGUI");
if (m_Styles == null)
m_Styles = new Styles();
Vector2 maxEventLabelSize = Vector2.zero;
int totalInterceptedEvents = 0;
List<ComponentInterceptedEvents> componentIncerceptedEvents = m_TargetEvents[target as GameObject];
// Find out the maximum size needed for any given label.
foreach (ComponentInterceptedEvents componentInterceptedEvents in componentIncerceptedEvents)
{
foreach (int eventIndex in componentInterceptedEvents.interceptedEvents)
{
GUIContent eventContent = s_PossibleEvents[eventIndex];
++totalInterceptedEvents;
Vector2 labelSize = m_Styles.labelStyle.CalcSize(eventContent);
if (maxEventLabelSize.x < labelSize.x)
{
maxEventLabelSize.x = labelSize.x;
}
if (maxEventLabelSize.y < labelSize.y)
{
maxEventLabelSize.y = labelSize.y;
}
}
}
// Apply padding
RectOffset previewPadding = new RectOffset(-5, -5, -5, -5);
r = previewPadding.Add(r);
// Figure out how many rows and columns we can/should have
int columns = Mathf.Max(Mathf.FloorToInt(r.width / maxEventLabelSize.x), 1);
int rows = Mathf.Max(totalInterceptedEvents / columns, 1) + componentIncerceptedEvents.Count;
// Centering
float initialX = r.x + Mathf.Max(0, (r.width - (maxEventLabelSize.x * columns)) / 2);
float initialY = r.y + Mathf.Max(0, (r.height - (maxEventLabelSize.y * rows)) / 2);
Rect labelRect = new Rect(initialX, initialY, maxEventLabelSize.x, maxEventLabelSize.y);
int currentColumn = 0;
foreach (ComponentInterceptedEvents componentInterceptedEvents in componentIncerceptedEvents)
{
GUI.Label(labelRect, componentInterceptedEvents.componentName, m_Styles.componentName);
labelRect.y += labelRect.height;
labelRect.x = initialX;
foreach (int eventIndex in componentInterceptedEvents.interceptedEvents)
{
GUIContent eventContent = s_PossibleEvents[eventIndex];
GUI.Label(labelRect, eventContent, m_Styles.labelStyle);
if (currentColumn < columns - 1)
{
labelRect.x += labelRect.width;
}
else
{
labelRect.y += labelRect.height;
labelRect.x = initialX;
}
currentColumn = (currentColumn + 1) % columns;
}
if (labelRect.x != initialX)
{
labelRect.y += labelRect.height;
labelRect.x = initialX;
}
}
Profiler.EndSample();
}
//Lookup cache to avoid recalculating which types uses which events:
//Caches all interfaces that inherit from IEventSystemHandler
static List<Type> s_EventSystemInterfaces = null;
//Caches all GUIContents in a single list to avoid creating too much GUIContent and strings.
private static List<GUIContent> s_PossibleEvents = null;
//Caches all events used by each interface
static Dictionary<Type, List<int>> s_InterfaceEventSystemEvents = null;
//Caches each concrete type and it's events
static readonly Dictionary<Type, ComponentInterceptedEvents> s_ComponentEvents2 = new Dictionary<Type, ComponentInterceptedEvents>();
protected static List<ComponentInterceptedEvents> GetEventsInfo(GameObject gameObject)
{
InitializeEvetnsInterfaceCacheIfNeeded();
List<ComponentInterceptedEvents> componentEvents = new List<ComponentInterceptedEvents>();
MonoBehaviour[] mbs = gameObject.GetComponents<MonoBehaviour>();
for (int i = 0, imax = mbs.Length; i < imax; ++i)
{
ComponentInterceptedEvents componentEvent = null;
MonoBehaviour mb = mbs[i];
if (mb == null)
continue;
Type type = mb.GetType();
if (!s_ComponentEvents2.ContainsKey(type))
{
List<int> events = null;
Profiler.BeginSample("ComponentInterceptedEvents.GetEventsInfo.NewType");
if (typeof(IEventSystemHandler).IsAssignableFrom(type))
{
for (int index = 0; index < s_EventSystemInterfaces.Count; index++)
{
var eventInterface = s_EventSystemInterfaces[index];
if (!eventInterface.IsAssignableFrom(type))
continue;
if (events == null)
events = new List<int>();
events.AddRange(s_InterfaceEventSystemEvents[eventInterface]);
}
}
if (events != null)
{
componentEvent = new ComponentInterceptedEvents();
componentEvent.componentName = new GUIContent(type.Name);
componentEvent.interceptedEvents = events.OrderBy(index => s_PossibleEvents[index].text).ToArray();
}
s_ComponentEvents2.Add(type, componentEvent);
Profiler.EndSample();
}
else
{
componentEvent = s_ComponentEvents2[type];
}
if (componentEvent != null)
{
componentEvents.Add(componentEvent);
}
}
return componentEvents;
}
private static void InitializeEvetnsInterfaceCacheIfNeeded()
{
if (s_EventSystemInterfaces != null)
return;
s_EventSystemInterfaces = new List<Type>();
s_PossibleEvents = new List<GUIContent>();
s_InterfaceEventSystemEvents = new Dictionary<Type, List<int>>();
TypeCache.TypeCollection types = TypeCache.GetTypesDerivedFrom<IEventSystemHandler>();
foreach (var type in types)
{
if (!type.IsInterface)
continue;
s_EventSystemInterfaces.Add(type);
List<int> eventIndexList = new List<int>();
MethodInfo[] methodInfos = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
for (int mi = 0; mi < methodInfos.Length; mi++)
{
MethodInfo methodInfo = methodInfos[mi];
eventIndexList.Add(s_PossibleEvents.Count);
s_PossibleEvents.Add(new GUIContent(methodInfo.Name));
}
s_InterfaceEventSystemEvents.Add(type, eventIndexList);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 127023922adddf744b59fa7b0b0c3030
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,106 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEditorInternal;
using UnityEditor.AnimatedValues;
namespace UnityEditor.UI
{
[CustomEditor(typeof(LayoutElement), true)]
[CanEditMultipleObjects]
/// <summary>
/// Custom editor for the LayoutElement component
/// Extend this class to write a custom editor for a component derived from LayoutElement.
/// </summary>
public class LayoutElementEditor : Editor
{
SerializedProperty m_IgnoreLayout;
SerializedProperty m_MinWidth;
SerializedProperty m_MinHeight;
SerializedProperty m_PreferredWidth;
SerializedProperty m_PreferredHeight;
SerializedProperty m_FlexibleWidth;
SerializedProperty m_FlexibleHeight;
SerializedProperty m_LayoutPriority;
protected virtual void OnEnable()
{
m_IgnoreLayout = serializedObject.FindProperty("m_IgnoreLayout");
m_MinWidth = serializedObject.FindProperty("m_MinWidth");
m_MinHeight = serializedObject.FindProperty("m_MinHeight");
m_PreferredWidth = serializedObject.FindProperty("m_PreferredWidth");
m_PreferredHeight = serializedObject.FindProperty("m_PreferredHeight");
m_FlexibleWidth = serializedObject.FindProperty("m_FlexibleWidth");
m_FlexibleHeight = serializedObject.FindProperty("m_FlexibleHeight");
m_LayoutPriority = serializedObject.FindProperty("m_LayoutPriority");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(m_IgnoreLayout);
if (!m_IgnoreLayout.boolValue)
{
EditorGUILayout.Space();
LayoutElementField(m_MinWidth, 0);
LayoutElementField(m_MinHeight, 0);
LayoutElementField(m_PreferredWidth, t => t.rect.width);
LayoutElementField(m_PreferredHeight, t => t.rect.height);
LayoutElementField(m_FlexibleWidth, 1);
LayoutElementField(m_FlexibleHeight, 1);
}
EditorGUILayout.PropertyField(m_LayoutPriority);
serializedObject.ApplyModifiedProperties();
}
void LayoutElementField(SerializedProperty property, float defaultValue)
{
LayoutElementField(property, _ => defaultValue);
}
void LayoutElementField(SerializedProperty property, System.Func<RectTransform, float> defaultValue)
{
Rect position = EditorGUILayout.GetControlRect();
// Label
GUIContent label = EditorGUI.BeginProperty(position, null, property);
// Rects
Rect fieldPosition = EditorGUI.PrefixLabel(position, label);
Rect toggleRect = fieldPosition;
toggleRect.width = 16;
Rect floatFieldRect = fieldPosition;
floatFieldRect.xMin += 16;
// Checkbox
EditorGUI.BeginChangeCheck();
bool enabled = EditorGUI.ToggleLeft(toggleRect, GUIContent.none, property.floatValue >= 0);
if (EditorGUI.EndChangeCheck())
{
// This could be made better to set all of the targets to their initial width, but mimizing code change for now
property.floatValue = (enabled ? defaultValue((target as LayoutElement).transform as RectTransform) : -1);
}
if (!property.hasMultipleDifferentValues && property.floatValue >= 0)
{
// Float field
EditorGUIUtility.labelWidth = 4; // Small invisible label area for drag zone functionality
EditorGUI.BeginChangeCheck();
float newValue = EditorGUI.FloatField(floatFieldRect, new GUIContent(" "), property.floatValue);
if (EditorGUI.EndChangeCheck())
{
property.floatValue = Mathf.Max(0, newValue);
}
EditorGUIUtility.labelWidth = 0;
}
EditorGUI.EndProperty();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7693972390a4ed841a986c0c452c1058
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,127 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
using System.Globalization;
namespace UnityEditor.Events
{
[CustomPreview(typeof(GameObject))]
/// <summary>
/// Custom preview drawing that will draw the layout properties of a given object.
/// </summary>
class LayoutPropertiesPreview : ObjectPreview
{
private const float kLabelWidth = 110;
private const float kValueWidth = 100;
class Styles
{
public GUIStyle labelStyle = new GUIStyle(EditorStyles.label);
public GUIStyle headerStyle = new GUIStyle(EditorStyles.boldLabel);
public Styles()
{
labelStyle.padding.right += 4;
headerStyle.padding.right += 4;
}
}
private GUIContent m_Title;
private Styles m_Styles;
public override void Initialize(UnityEngine.Object[] targets)
{
base.Initialize(targets);
}
public override GUIContent GetPreviewTitle()
{
if (m_Title == null)
{
m_Title = EditorGUIUtility.TrTextContent("Layout Properties");
}
return m_Title;
}
public override bool HasPreviewGUI()
{
GameObject go = target as GameObject;
if (!go)
return false;
// Prevent allocations in the editor by using TryGetComponent
ILayoutElement layoutElement;
return go.TryGetComponent(out layoutElement);
}
public override void OnPreviewGUI(Rect r, GUIStyle background)
{
if (Event.current.type != EventType.Repaint)
return;
if (m_Styles == null)
m_Styles = new Styles();
GameObject go = target as GameObject;
RectTransform rect = go.transform as RectTransform;
if (rect == null)
return;
// Apply padding
RectOffset previewPadding = new RectOffset(-5, -5, -5, -5);
r = previewPadding.Add(r);
// Prepare rects for columns
r.height = EditorGUIUtility.singleLineHeight;
Rect labelRect = r;
Rect valueRect = r;
Rect sourceRect = r;
labelRect.width = kLabelWidth;
valueRect.xMin += kLabelWidth;
valueRect.width = kValueWidth;
sourceRect.xMin += kLabelWidth + kValueWidth;
// Headers
GUI.Label(labelRect, "Property", m_Styles.headerStyle);
GUI.Label(valueRect, "Value", m_Styles.headerStyle);
GUI.Label(sourceRect, "Source", m_Styles.headerStyle);
labelRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
valueRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
sourceRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
// Prepare reusable variable for out argument
ILayoutElement source = null;
// Show properties
ShowProp(ref labelRect, ref valueRect, ref sourceRect, "Min Width", LayoutUtility.GetLayoutProperty(rect, e => e.minWidth, 0, out source).ToString(CultureInfo.InvariantCulture.NumberFormat), source);
ShowProp(ref labelRect, ref valueRect, ref sourceRect, "Min Height", LayoutUtility.GetLayoutProperty(rect, e => e.minHeight, 0, out source).ToString(CultureInfo.InvariantCulture.NumberFormat), source);
ShowProp(ref labelRect, ref valueRect, ref sourceRect, "Preferred Width", LayoutUtility.GetLayoutProperty(rect, e => e.preferredWidth, 0, out source).ToString(CultureInfo.InvariantCulture.NumberFormat), source);
ShowProp(ref labelRect, ref valueRect, ref sourceRect, "Preferred Height", LayoutUtility.GetLayoutProperty(rect, e => e.preferredHeight, 0, out source).ToString(CultureInfo.InvariantCulture.NumberFormat), source);
float flexible = 0;
flexible = LayoutUtility.GetLayoutProperty(rect, e => e.flexibleWidth, 0, out source);
ShowProp(ref labelRect, ref valueRect, ref sourceRect, "Flexible Width", flexible > 0 ? ("enabled (" + flexible.ToString(CultureInfo.InvariantCulture.NumberFormat) + ")") : "disabled", source);
flexible = LayoutUtility.GetLayoutProperty(rect, e => e.flexibleHeight, 0, out source);
ShowProp(ref labelRect, ref valueRect, ref sourceRect, "Flexible Height", flexible > 0 ? ("enabled (" + flexible.ToString(CultureInfo.InvariantCulture.NumberFormat) + ")") : "disabled", source);
if (!rect.GetComponent<LayoutElement>())
{
Rect noteRect = new Rect(labelRect.x, labelRect.y + 10, r.width, EditorGUIUtility.singleLineHeight);
GUI.Label(noteRect, "Add a LayoutElement to override values.", m_Styles.labelStyle);
}
}
private void ShowProp(ref Rect labelRect, ref Rect valueRect, ref Rect sourceRect, string label, string value, ILayoutElement source)
{
GUI.Label(labelRect, label, m_Styles.labelStyle);
GUI.Label(valueRect, value, m_Styles.labelStyle);
GUI.Label(sourceRect, source == null ? "none" : source.GetType().Name, m_Styles.labelStyle);
labelRect.y += EditorGUIUtility.singleLineHeight;
valueRect.y += EditorGUIUtility.singleLineHeight;
sourceRect.y += EditorGUIUtility.singleLineHeight;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 794f3951c48395848920fdb593a2ae38
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,32 @@
using UnityEngine.UI;
namespace UnityEditor.UI
{
[CustomEditor(typeof(Mask), true)]
[CanEditMultipleObjects]
/// <summary>
/// Custom Editor for the Mask component.
/// Extend this class to write a custom editor for a component derived from Mask.
/// </summary>
public class MaskEditor : Editor
{
SerializedProperty m_ShowMaskGraphic;
protected virtual void OnEnable()
{
m_ShowMaskGraphic = serializedObject.FindProperty("m_ShowMaskGraphic");
}
public override void OnInspectorGUI()
{
var graphic = (target as Mask).GetComponent<Graphic>();
if (graphic && !graphic.IsActive())
EditorGUILayout.HelpBox("Masking disabled due to Graphic component being disabled.", MessageType.Warning);
serializedObject.Update();
EditorGUILayout.PropertyField(m_ShowMaskGraphic);
serializedObject.ApplyModifiedProperties();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b10cb8fee5b39014d8a417bf413f5e5c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,434 @@
using System;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace UnityEditor.UI
{
/// <summary>
/// This script adds the UI menu options to the Unity Editor.
/// </summary>
static internal class MenuOptions
{
enum MenuOptionsPriorityOrder {
// 2000 - Text (TMP)
Image = 2001,
RawImage = 2002,
Panel = 2003,
// 2020 - Button (TMP)
Toggle = 2021,
// 2022 - Dropdown (TMP)
// 2023 - Input Field (TMP)
Slider = 2024,
Scrollbar = 2025,
ScrollView = 2026,
Canvas = 2060,
EventSystem = 2061,
Text = 2080,
Button = 2081,
Dropdown = 2082,
InputField = 2083,
};
private const string kUILayerName = "UI";
private const string kStandardSpritePath = "UI/Skin/UISprite.psd";
private const string kBackgroundSpritePath = "UI/Skin/Background.psd";
private const string kInputFieldBackgroundPath = "UI/Skin/InputFieldBackground.psd";
private const string kKnobPath = "UI/Skin/Knob.psd";
private const string kCheckmarkPath = "UI/Skin/Checkmark.psd";
private const string kDropdownArrowPath = "UI/Skin/DropdownArrow.psd";
private const string kMaskPath = "UI/Skin/UIMask.psd";
static private DefaultControls.Resources s_StandardResources;
static private DefaultControls.Resources GetStandardResources()
{
if (s_StandardResources.standard == null)
{
s_StandardResources.standard = AssetDatabase.GetBuiltinExtraResource<Sprite>(kStandardSpritePath);
s_StandardResources.background = AssetDatabase.GetBuiltinExtraResource<Sprite>(kBackgroundSpritePath);
s_StandardResources.inputField = AssetDatabase.GetBuiltinExtraResource<Sprite>(kInputFieldBackgroundPath);
s_StandardResources.knob = AssetDatabase.GetBuiltinExtraResource<Sprite>(kKnobPath);
s_StandardResources.checkmark = AssetDatabase.GetBuiltinExtraResource<Sprite>(kCheckmarkPath);
s_StandardResources.dropdown = AssetDatabase.GetBuiltinExtraResource<Sprite>(kDropdownArrowPath);
s_StandardResources.mask = AssetDatabase.GetBuiltinExtraResource<Sprite>(kMaskPath);
}
return s_StandardResources;
}
private class DefaultEditorFactory : DefaultControls.IFactoryControls
{
public static DefaultEditorFactory Default = new DefaultEditorFactory();
public GameObject CreateGameObject(string name, params Type[] components)
{
return ObjectFactory.CreateGameObject(name, components);
}
}
private class FactorySwapToEditor : IDisposable
{
DefaultControls.IFactoryControls factory;
public FactorySwapToEditor()
{
factory = DefaultControls.factory;
DefaultControls.factory = DefaultEditorFactory.Default;
}
public void Dispose()
{
DefaultControls.factory = factory;
}
}
private static void SetPositionVisibleinSceneView(RectTransform canvasRTransform, RectTransform itemTransform)
{
SceneView sceneView = SceneView.lastActiveSceneView;
// Couldn't find a SceneView. Don't set position.
if (sceneView == null || sceneView.camera == null)
return;
// Create world space Plane from canvas position.
Vector2 localPlanePosition;
Camera camera = sceneView.camera;
Vector3 position = Vector3.zero;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRTransform, new Vector2(camera.pixelWidth / 2, camera.pixelHeight / 2), camera, out localPlanePosition))
{
// Adjust for canvas pivot
localPlanePosition.x = localPlanePosition.x + canvasRTransform.sizeDelta.x * canvasRTransform.pivot.x;
localPlanePosition.y = localPlanePosition.y + canvasRTransform.sizeDelta.y * canvasRTransform.pivot.y;
localPlanePosition.x = Mathf.Clamp(localPlanePosition.x, 0, canvasRTransform.sizeDelta.x);
localPlanePosition.y = Mathf.Clamp(localPlanePosition.y, 0, canvasRTransform.sizeDelta.y);
// Adjust for anchoring
position.x = localPlanePosition.x - canvasRTransform.sizeDelta.x * itemTransform.anchorMin.x;
position.y = localPlanePosition.y - canvasRTransform.sizeDelta.y * itemTransform.anchorMin.y;
Vector3 minLocalPosition;
minLocalPosition.x = canvasRTransform.sizeDelta.x * (0 - canvasRTransform.pivot.x) + itemTransform.sizeDelta.x * itemTransform.pivot.x;
minLocalPosition.y = canvasRTransform.sizeDelta.y * (0 - canvasRTransform.pivot.y) + itemTransform.sizeDelta.y * itemTransform.pivot.y;
Vector3 maxLocalPosition;
maxLocalPosition.x = canvasRTransform.sizeDelta.x * (1 - canvasRTransform.pivot.x) - itemTransform.sizeDelta.x * itemTransform.pivot.x;
maxLocalPosition.y = canvasRTransform.sizeDelta.y * (1 - canvasRTransform.pivot.y) - itemTransform.sizeDelta.y * itemTransform.pivot.y;
position.x = Mathf.Clamp(position.x, minLocalPosition.x, maxLocalPosition.x);
position.y = Mathf.Clamp(position.y, minLocalPosition.y, maxLocalPosition.y);
}
itemTransform.anchoredPosition = position;
itemTransform.localRotation = Quaternion.identity;
itemTransform.localScale = Vector3.one;
}
private static void PlaceUIElementRoot(GameObject element, MenuCommand menuCommand)
{
GameObject parent = menuCommand.context as GameObject;
bool explicitParentChoice = true;
if (parent == null)
{
parent = GetOrCreateCanvasGameObject();
explicitParentChoice = false;
// If in Prefab Mode, Canvas has to be part of Prefab contents,
// otherwise use Prefab root instead.
PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
if (prefabStage != null && !prefabStage.IsPartOfPrefabContents(parent))
parent = prefabStage.prefabContentsRoot;
}
if (parent.GetComponentsInParent<Canvas>(true).Length == 0)
{
// Create canvas under context GameObject,
// and make that be the parent which UI element is added under.
GameObject canvas = MenuOptions.CreateNewUI();
Undo.SetTransformParent(canvas.transform, parent.transform, "");
parent = canvas;
}
GameObjectUtility.EnsureUniqueNameForSibling(element);
SetParentAndAlign(element, parent);
if (!explicitParentChoice) // not a context click, so center in sceneview
SetPositionVisibleinSceneView(parent.GetComponent<RectTransform>(), element.GetComponent<RectTransform>());
// This call ensure any change made to created Objects after they where registered will be part of the Undo.
Undo.RegisterFullObjectHierarchyUndo(parent == null ? element : parent, "");
// We have to fix up the undo name since the name of the object was only known after reparenting it.
Undo.SetCurrentGroupName("Create " + element.name);
Selection.activeGameObject = element;
}
private static void SetParentAndAlign(GameObject child, GameObject parent)
{
if (parent == null)
return;
Undo.SetTransformParent(child.transform, parent.transform, "");
RectTransform rectTransform = child.transform as RectTransform;
if (rectTransform)
{
rectTransform.anchoredPosition = Vector2.zero;
Vector3 localPosition = rectTransform.localPosition;
localPosition.z = 0;
rectTransform.localPosition = localPosition;
}
else
{
child.transform.localPosition = Vector3.zero;
}
child.transform.localRotation = Quaternion.identity;
child.transform.localScale = Vector3.one;
SetLayerRecursively(child, parent.layer);
}
private static void SetLayerRecursively(GameObject go, int layer)
{
go.layer = layer;
Transform t = go.transform;
for (int i = 0; i < t.childCount; i++)
SetLayerRecursively(t.GetChild(i).gameObject, layer);
}
// Graphic elements
[MenuItem("GameObject/UI/Image", false, (int)MenuOptionsPriorityOrder.Image)]
static public void AddImage(MenuCommand menuCommand)
{
GameObject go;
using (new FactorySwapToEditor())
go = DefaultControls.CreateImage(GetStandardResources());
PlaceUIElementRoot(go, menuCommand);
}
[MenuItem("GameObject/UI/Raw Image", false, (int)MenuOptionsPriorityOrder.RawImage)]
static public void AddRawImage(MenuCommand menuCommand)
{
GameObject go;
using (new FactorySwapToEditor())
go = DefaultControls.CreateRawImage(GetStandardResources());
PlaceUIElementRoot(go, menuCommand);
}
[MenuItem("GameObject/UI/Panel", false, (int)MenuOptionsPriorityOrder.Panel)]
static public void AddPanel(MenuCommand menuCommand)
{
GameObject go;
using (new FactorySwapToEditor())
go = DefaultControls.CreatePanel(GetStandardResources());
PlaceUIElementRoot(go, menuCommand);
// Panel is special, we need to ensure there's no padding after repositioning.
RectTransform rect = go.GetComponent<RectTransform>();
rect.anchoredPosition = Vector2.zero;
rect.sizeDelta = Vector2.zero;
}
// Controls
// Toggle is a control you just click on.
[MenuItem("GameObject/UI/Toggle", false, (int)MenuOptionsPriorityOrder.Toggle)]
static public void AddToggle(MenuCommand menuCommand)
{
GameObject go;
using (new FactorySwapToEditor())
go = DefaultControls.CreateToggle(GetStandardResources());
PlaceUIElementRoot(go, menuCommand);
}
// Slider and Scrollbar modify a number
[MenuItem("GameObject/UI/Slider", false, (int)MenuOptionsPriorityOrder.Slider)]
static public void AddSlider(MenuCommand menuCommand)
{
GameObject go;
using (new FactorySwapToEditor())
go = DefaultControls.CreateSlider(GetStandardResources());
PlaceUIElementRoot(go, menuCommand);
}
[MenuItem("GameObject/UI/Scrollbar", false, (int)MenuOptionsPriorityOrder.Scrollbar)]
static public void AddScrollbar(MenuCommand menuCommand)
{
GameObject go;
using (new FactorySwapToEditor())
go = DefaultControls.CreateScrollbar(GetStandardResources());
PlaceUIElementRoot(go, menuCommand);
}
[MenuItem("GameObject/UI/Scroll View", false, (int)MenuOptionsPriorityOrder.ScrollView)]
static public void AddScrollView(MenuCommand menuCommand)
{
GameObject go;
using (new FactorySwapToEditor())
go = DefaultControls.CreateScrollView(GetStandardResources());
PlaceUIElementRoot(go, menuCommand);
}
// Containers
[MenuItem("GameObject/UI/Canvas", false, (int)MenuOptionsPriorityOrder.Canvas)]
static public void AddCanvas(MenuCommand menuCommand)
{
var go = CreateNewUI();
SetParentAndAlign(go, menuCommand.context as GameObject);
if (go.transform.parent as RectTransform)
{
RectTransform rect = go.transform as RectTransform;
rect.anchorMin = Vector2.zero;
rect.anchorMax = Vector2.one;
rect.anchoredPosition = Vector2.zero;
rect.sizeDelta = Vector2.zero;
}
Selection.activeGameObject = go;
}
// Legacy Elements
[MenuItem("GameObject/UI/Legacy/Text", false, (int)MenuOptionsPriorityOrder.Text)]
static public void AddText(MenuCommand menuCommand)
{
GameObject go;
using (new FactorySwapToEditor())
go = DefaultControls.CreateText(GetStandardResources());
PlaceUIElementRoot(go, menuCommand);
}
[MenuItem("GameObject/UI/Legacy/Button", false, (int)MenuOptionsPriorityOrder.Button)]
static public void AddButton(MenuCommand menuCommand)
{
GameObject go;
using (new FactorySwapToEditor())
go = DefaultControls.CreateButton(GetStandardResources());
PlaceUIElementRoot(go, menuCommand);
}
[MenuItem("GameObject/UI/Legacy/Dropdown", false, (int)MenuOptionsPriorityOrder.Dropdown)]
static public void AddDropdown(MenuCommand menuCommand)
{
GameObject go;
using (new FactorySwapToEditor())
go = DefaultControls.CreateDropdown(GetStandardResources());
PlaceUIElementRoot(go, menuCommand);
}
[MenuItem("GameObject/UI/Legacy/Input Field", false, (int)MenuOptionsPriorityOrder.InputField)]
public static void AddInputField(MenuCommand menuCommand)
{
GameObject go;
using (new FactorySwapToEditor())
go = DefaultControls.CreateInputField(GetStandardResources());
PlaceUIElementRoot(go, menuCommand);
}
// Helper methods
static public GameObject CreateNewUI()
{
// Root for the UI
var root = ObjectFactory.CreateGameObject("Canvas", typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster));
root.layer = LayerMask.NameToLayer(kUILayerName);
Canvas canvas = root.GetComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
// Works for all stages.
StageUtility.PlaceGameObjectInCurrentStage(root);
bool customScene = false;
PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
if (prefabStage != null)
{
Undo.SetTransformParent(root.transform, prefabStage.prefabContentsRoot.transform, "");
customScene = true;
}
Undo.SetCurrentGroupName("Create " + root.name);
// If there is no event system add one...
// No need to place event system in custom scene as these are temporary anyway.
// It can be argued for or against placing it in the user scenes,
// but let's not modify scene user is not currently looking at.
if (!customScene)
CreateEventSystem(false);
return root;
}
[MenuItem("GameObject/UI/Event System", false, (int)MenuOptionsPriorityOrder.EventSystem)]
public static void CreateEventSystem(MenuCommand menuCommand)
{
GameObject parent = menuCommand.context as GameObject;
CreateEventSystem(true, parent);
}
private static void CreateEventSystem(bool select)
{
CreateEventSystem(select, null);
}
private static void CreateEventSystem(bool select, GameObject parent)
{
StageHandle stage = parent == null ? StageUtility.GetCurrentStageHandle() : StageUtility.GetStageHandle(parent);
var esys = stage.FindComponentOfType<EventSystem>();
if (esys == null)
{
var eventSystem = ObjectFactory.CreateGameObject("EventSystem");
if (parent == null)
StageUtility.PlaceGameObjectInCurrentStage(eventSystem);
else
SetParentAndAlign(eventSystem, parent);
esys = ObjectFactory.AddComponent<EventSystem>(eventSystem);
ObjectFactory.AddComponent<StandaloneInputModule>(eventSystem);
Undo.RegisterCreatedObjectUndo(eventSystem, "Create " + eventSystem.name);
}
if (select && esys != null)
{
Selection.activeGameObject = esys.gameObject;
}
}
// Helper function that returns a Canvas GameObject; preferably a parent of the selection, or other existing Canvas.
static public GameObject GetOrCreateCanvasGameObject()
{
GameObject selectedGo = Selection.activeGameObject;
// Try to find a gameobject that is the selected GO or one if its parents.
Canvas canvas = (selectedGo != null) ? selectedGo.GetComponentInParent<Canvas>() : null;
if (IsValidCanvas(canvas))
return canvas.gameObject;
// No canvas in selection or its parents? Then use any valid canvas.
// We have to find all loaded Canvases, not just the ones in main scenes.
Canvas[] canvasArray = StageUtility.GetCurrentStageHandle().FindComponentsOfType<Canvas>();
for (int i = 0; i < canvasArray.Length; i++)
if (IsValidCanvas(canvasArray[i]))
return canvasArray[i].gameObject;
// No canvas in the scene at all? Then create a new one.
return MenuOptions.CreateNewUI();
}
static bool IsValidCanvas(Canvas canvas)
{
if (canvas == null || !canvas.gameObject.activeInHierarchy)
return false;
// It's important that the non-editable canvas from a prefab scene won't be rejected,
// but canvases not visible in the Hierarchy at all do. Don't check for HideAndDontSave.
if (EditorUtility.IsPersistent(canvas) || (canvas.hideFlags & HideFlags.HideInHierarchy) != 0)
return false;
return StageUtility.GetStageHandle(canvas.gameObject) == StageUtility.GetCurrentStageHandle();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f867743975592a743a3581ff042bcc25
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,24 @@
using UnityEngine;
using UnityEngine.UI;
namespace UnityEditor.UI
{
[InitializeOnLoad]
internal class PrefabLayoutRebuilder
{
static PrefabLayoutRebuilder()
{
PrefabUtility.prefabInstanceUpdated += OnPrefabInstanceUpdates;
}
static void OnPrefabInstanceUpdates(GameObject instance)
{
if (instance)
{
RectTransform rect = instance.transform as RectTransform;
if (rect)
LayoutRebuilder.MarkLayoutForRebuild(rect);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a62706dc421fc9b4fa368a8050a930f7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bc9aa6d5a7945f34882c442e9e201537
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,69 @@
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
namespace UnityEditor.UI
{
[CustomPropertyDrawer(typeof(AnimationTriggers), true)]
/// <summary>
/// This is a PropertyDrawer for AnimationTriggers. It is implemented using the standard Unity PropertyDrawer framework.
/// </summary>
public class AnimationTriggersDrawer : PropertyDrawer
{
const string kNormalTrigger = "m_NormalTrigger";
const string kHighlightedTrigger = "m_HighlightedTrigger";
const string kPressedTrigger = "m_PressedTrigger";
const string kSelectedTrigger = "m_SelectedTrigger";
const string kDisabledTrigger = "m_DisabledTrigger";
public override void OnGUI(Rect rect, SerializedProperty prop, GUIContent label)
{
Rect drawRect = rect;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty normalTrigger = prop.FindPropertyRelative(kNormalTrigger);
SerializedProperty higlightedTrigger = prop.FindPropertyRelative(kHighlightedTrigger);
SerializedProperty pressedTrigger = prop.FindPropertyRelative(kPressedTrigger);
SerializedProperty selectedTrigger = prop.FindPropertyRelative(kSelectedTrigger);
SerializedProperty disabledTrigger = prop.FindPropertyRelative(kDisabledTrigger);
EditorGUI.PropertyField(drawRect, normalTrigger);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, higlightedTrigger);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, pressedTrigger);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, selectedTrigger);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, disabledTrigger);
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
return 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
}
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
var container = new VisualElement();
var properties = new[]
{
property.FindPropertyRelative(kNormalTrigger),
property.FindPropertyRelative(kHighlightedTrigger),
property.FindPropertyRelative(kPressedTrigger),
property.FindPropertyRelative(kSelectedTrigger),
property.FindPropertyRelative(kDisabledTrigger),
};
foreach (var prop in properties)
{
var field = new PropertyField(prop);
container.Add(field);
}
return container;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c18288a8d31fc9043a807ee8a9f1ae64
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,79 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace UnityEditor.UI
{
[CustomPropertyDrawer(typeof(ColorBlock), true)]
/// <summary>
/// This is a PropertyDrawer for ColorBlock. It is implemented using the standard Unity PropertyDrawer framework..
/// </summary>
public class ColorBlockDrawer : PropertyDrawer
{
const string kNormalColor = "m_NormalColor";
const string kHighlightedColor = "m_HighlightedColor";
const string kPressedColor = "m_PressedColor";
const string kSelectedColor = "m_SelectedColor";
const string kDisabledColor = "m_DisabledColor";
const string kColorMultiplier = "m_ColorMultiplier";
const string kFadeDuration = "m_FadeDuration";
public override void OnGUI(Rect rect, SerializedProperty prop, GUIContent label)
{
Rect drawRect = rect;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty normalColor = prop.FindPropertyRelative(kNormalColor);
SerializedProperty highlighted = prop.FindPropertyRelative(kHighlightedColor);
SerializedProperty pressedColor = prop.FindPropertyRelative(kPressedColor);
SerializedProperty selectedColor = prop.FindPropertyRelative(kSelectedColor);
SerializedProperty disabledColor = prop.FindPropertyRelative(kDisabledColor);
SerializedProperty colorMultiplier = prop.FindPropertyRelative(kColorMultiplier);
SerializedProperty fadeDuration = prop.FindPropertyRelative(kFadeDuration);
EditorGUI.PropertyField(drawRect, normalColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, highlighted);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, pressedColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, selectedColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, disabledColor);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, colorMultiplier);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, fadeDuration);
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
return 7 * EditorGUIUtility.singleLineHeight + 6 * EditorGUIUtility.standardVerticalSpacing;
}
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
VisualElement container = new VisualElement();
var properties = new[]
{
property.FindPropertyRelative(kNormalColor),
property.FindPropertyRelative(kHighlightedColor),
property.FindPropertyRelative(kPressedColor),
property.FindPropertyRelative(kSelectedColor),
property.FindPropertyRelative(kDisabledColor),
property.FindPropertyRelative(kColorMultiplier),
property.FindPropertyRelative(kFadeDuration)
};
foreach (var prop in properties)
{
var field = new PropertyField(prop);
container.Add(field);
}
return container;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b825fd5f27403b84f97726dd9c5a5e6f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Some files were not shown because too many files have changed in this diff Show More