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,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:

View File

@@ -0,0 +1,121 @@
using System;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
using UnityEditor;
using UnityEditor.UIElements;
namespace UnityEditor.UI
{
[CustomPropertyDrawer(typeof(Dropdown.OptionDataList), true)]
/// <summary>
/// This is a PropertyDrawer for Dropdown.OptionDataList. It is implemented using the standard Unity PropertyDrawer framework.
/// </summary>
class DropdownOptionListDrawer : PropertyDrawer
{
const string kOptionsPath = "m_Options";
const string kTextPath = "m_Text";
const string kImagePath = "m_Image";
const string kHeader = "Options";
const string kListViewUssName = "unity-list-view__header";
const string kVisualElementName = "DropdownOptionDataList";
// Offset for fixed size list items, so it wouldn't look tight or overlap each other
const float itemOffset = 4;
private ReorderableList m_ReorderableList;
private void Init(SerializedProperty property)
{
if (m_ReorderableList != null && m_ReorderableList.serializedProperty.serializedObject.m_NativeObjectPtr != IntPtr.Zero)
{
return;
}
SerializedProperty array = property.FindPropertyRelative(kOptionsPath);
m_ReorderableList = new ReorderableList(property.serializedObject, array);
m_ReorderableList.drawElementCallback = DrawOptionData;
m_ReorderableList.drawHeaderCallback = DrawHeader;
m_ReorderableList.elementHeight += 16;
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
Init(property);
m_ReorderableList.DoList(position);
}
private void DrawHeader(Rect rect)
{
GUI.Label(rect, kHeader);
}
private void DrawOptionData(Rect rect, int index, bool isActive, bool isFocused)
{
SerializedProperty itemData = m_ReorderableList.serializedProperty.GetArrayElementAtIndex(index);
SerializedProperty itemText = itemData.FindPropertyRelative(kTextPath);
SerializedProperty itemImage = itemData.FindPropertyRelative(kImagePath);
RectOffset offset = new RectOffset(0, 0, -1, -3);
rect = offset.Add(rect);
rect.height = EditorGUIUtility.singleLineHeight;
EditorGUI.PropertyField(rect, itemText, GUIContent.none);
rect.y += EditorGUIUtility.singleLineHeight;
EditorGUI.PropertyField(rect, itemImage, GUIContent.none);
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
Init(property);
return m_ReorderableList.GetHeight();
}
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
var root = new VisualElement();
root.name = kVisualElementName;
Init(property);
var headerElement = new VisualElement();
headerElement.AddToClassList(kListViewUssName);
var header = new Label(kHeader);
headerElement.Add(header);
root.Add(headerElement);
var listView = CreateListView(property);
root.Add(listView);
return root;
}
ListView CreateListView(SerializedProperty property)
{
var listView = new ListView
{
showAddRemoveFooter = true,
reorderMode = ListViewReorderMode.Animated,
showBorder = true,
showFoldoutHeader = false,
showBoundCollectionSize = false,
showAlternatingRowBackgrounds = AlternatingRowBackground.None,
fixedItemHeight = m_ReorderableList.elementHeight + itemOffset,
horizontalScrollingEnabled = false,
name = kHeader
};
var propertyRelative = property.FindPropertyRelative(kOptionsPath);
listView.bindingPath = propertyRelative.propertyPath;
listView.makeItem += () => new DropdownOptionListItem(kTextPath, kImagePath);
return listView;
}
}
}

View File

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

View File

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

View File

@@ -0,0 +1,152 @@
using System;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.UIElements;
namespace UnityEditor.UI
{
[CustomPropertyDrawer(typeof(Navigation), true)]
/// <summary>
/// This is a PropertyDrawer for Navigation. It is implemented using the standard Unity PropertyDrawer framework.
/// </summary>
public class NavigationDrawer : PropertyDrawer
{
const string kNavigation = "Navigation";
const string kModeProp = "m_Mode";
const string kWrapAroundProp = "m_WrapAround";
const string kSelectOnUpProp = "m_SelectOnUp";
const string kSelectOnDownProp = "m_SelectOnDown";
const string kSelectOnLeftProp = "m_SelectOnLeft";
const string kSelectOnRightProp = "m_SelectOnRight";
const string kHiddenClass = "unity-ui-navigation-hidden";
private class Styles
{
readonly public GUIContent navigationContent;
public Styles()
{
navigationContent = EditorGUIUtility.TrTextContent(kNavigation);
}
}
private static Styles s_Styles = null;
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
{
if (s_Styles == null)
s_Styles = new Styles();
Rect drawRect = pos;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty navigation = prop.FindPropertyRelative(kModeProp);
SerializedProperty wrapAround = prop.FindPropertyRelative(kWrapAroundProp);
Navigation.Mode navMode = GetNavigationMode(navigation);
EditorGUI.PropertyField(drawRect, navigation, s_Styles.navigationContent);
++EditorGUI.indentLevel;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
switch (navMode)
{
case Navigation.Mode.Horizontal:
case Navigation.Mode.Vertical:
{
EditorGUI.PropertyField(drawRect, wrapAround);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
break;
case Navigation.Mode.Explicit:
{
SerializedProperty selectOnUp = prop.FindPropertyRelative(kSelectOnUpProp);
SerializedProperty selectOnDown = prop.FindPropertyRelative(kSelectOnDownProp);
SerializedProperty selectOnLeft = prop.FindPropertyRelative(kSelectOnLeftProp);
SerializedProperty selectOnRight = prop.FindPropertyRelative(kSelectOnRightProp);
EditorGUI.PropertyField(drawRect, selectOnUp);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, selectOnDown);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, selectOnLeft);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, selectOnRight);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
break;
}
--EditorGUI.indentLevel;
}
static Navigation.Mode GetNavigationMode(SerializedProperty navigation)
{
return (Navigation.Mode)navigation.enumValueIndex;
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
SerializedProperty navigation = prop.FindPropertyRelative(kModeProp);
if (navigation == null)
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
Navigation.Mode navMode = GetNavigationMode(navigation);
switch (navMode)
{
case Navigation.Mode.None:
return EditorGUIUtility.singleLineHeight;
case Navigation.Mode.Horizontal:
case Navigation.Mode.Vertical:
return 2 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
case Navigation.Mode.Explicit:
return 5 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing;
default:
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
}
PropertyField PrepareField(VisualElement parent, string propertyPath, bool hideable = true, string label = null)
{
var field = new PropertyField(null, label) { bindingPath = propertyPath };
if (hideable) field.AddToClassList(kHiddenClass);
parent.Add(field);
return field;
}
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
var container = new VisualElement() { name = kNavigation };
var indented = new VisualElement() { name = "Indent" };
indented.AddToClassList("unity-ui-navigation-indent");
var navigation = PrepareField(container, kModeProp, false, kNavigation);
var wrapAround = PrepareField(indented, kWrapAroundProp);
var selectOnUp = PrepareField(indented, kSelectOnUpProp);
var selectOnDown = PrepareField(indented, kSelectOnDownProp);
var selectOnLeft = PrepareField(indented, kSelectOnLeftProp);
var selectOnRight = PrepareField(indented, kSelectOnRightProp);
Action<Navigation.Mode> callback = (value) =>
{
wrapAround.EnableInClassList(kHiddenClass, value != Navigation.Mode.Vertical && value != Navigation.Mode.Horizontal);
selectOnUp.EnableInClassList(kHiddenClass, value != Navigation.Mode.Explicit);
selectOnDown.EnableInClassList(kHiddenClass, value != Navigation.Mode.Explicit);
selectOnLeft.EnableInClassList(kHiddenClass, value != Navigation.Mode.Explicit);
selectOnRight.EnableInClassList(kHiddenClass, value != Navigation.Mode.Explicit);
};
navigation.RegisterValueChangeCallback((e) => callback.Invoke((Navigation.Mode)e.changedProperty.enumValueIndex));
callback.Invoke((Navigation.Mode)property.FindPropertyRelative(kModeProp).enumValueFlag);
container.Add(indented);
return container;
}
}
}

View File

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

View File

@@ -0,0 +1,65 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace UnityEditor.UI
{
[CustomPropertyDrawer(typeof(SpriteState), true)]
/// <summary>
/// This is a PropertyDrawer for SpriteState. It is implemented using the standard Unity PropertyDrawer framework.
/// </summary>
public class SpriteStateDrawer : PropertyDrawer
{
const string kHighlightedSprite = "m_HighlightedSprite";
const string kPressedSprite = "m_PressedSprite";
const string kSelectedSprite = "m_SelectedSprite";
const string kDisabledSprite = "m_DisabledSprite";
const string kVisualElementName = "SpriteState";
public override void OnGUI(Rect rect, SerializedProperty prop, GUIContent label)
{
Rect drawRect = rect;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty highlightedSprite = prop.FindPropertyRelative(kHighlightedSprite);
SerializedProperty pressedSprite = prop.FindPropertyRelative(kPressedSprite);
SerializedProperty selectedSprite = prop.FindPropertyRelative(kSelectedSprite);
SerializedProperty disabledSprite = prop.FindPropertyRelative(kDisabledSprite);
EditorGUI.PropertyField(drawRect, highlightedSprite);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, pressedSprite);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, selectedSprite);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, disabledSprite);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{
return 4 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing;
}
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
var container = new VisualElement();
container.name = kVisualElementName;
var properties = new[]
{
property.FindPropertyRelative(kHighlightedSprite),
property.FindPropertyRelative(kPressedSprite),
property.FindPropertyRelative(kSelectedSprite),
property.FindPropertyRelative(kDisabledSprite)
};
foreach (var prop in properties)
{
container.Add(new PropertyField(prop));
}
return container;
}
}
}

View File

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

View File

@@ -0,0 +1,110 @@
using UnityEngine;
using UnityEngine.UI;
namespace UnityEditor.UI
{
[CustomEditor(typeof(RawImage), true)]
[CanEditMultipleObjects]
/// <summary>
/// Custom editor for RawImage.
/// Extend this class to write a custom editor for a component derived from RawImage.
/// </summary>
public class RawImageEditor : GraphicEditor
{
SerializedProperty m_Texture;
SerializedProperty m_UVRect;
GUIContent m_UVRectContent;
protected override void OnEnable()
{
base.OnEnable();
// Note we have precedence for calling rectangle for just rect, even in the Inspector.
// For example in the Camera component's Viewport Rect.
// Hence sticking with Rect here to be consistent with corresponding property in the API.
m_UVRectContent = EditorGUIUtility.TrTextContent("UV Rect");
m_Texture = serializedObject.FindProperty("m_Texture");
m_UVRect = serializedObject.FindProperty("m_UVRect");
SetShowNativeSize(true);
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(m_Texture);
AppearanceControlsGUI();
RaycastControlsGUI();
MaskableControlsGUI();
EditorGUILayout.PropertyField(m_UVRect, m_UVRectContent);
SetShowNativeSize(false);
NativeSizeButtonGUI();
serializedObject.ApplyModifiedProperties();
}
void SetShowNativeSize(bool instant)
{
base.SetShowNativeSize(m_Texture.objectReferenceValue != null, instant);
}
private static Rect Outer(RawImage rawImage)
{
Rect outer = rawImage.uvRect;
outer.xMin *= rawImage.rectTransform.rect.width;
outer.xMax *= rawImage.rectTransform.rect.width;
outer.yMin *= rawImage.rectTransform.rect.height;
outer.yMax *= rawImage.rectTransform.rect.height;
return outer;
}
/// <summary>
/// Allow the texture to be previewed.
/// </summary>
public override bool HasPreviewGUI()
{
RawImage rawImage = target as RawImage;
if (rawImage == null)
return false;
var outer = Outer(rawImage);
return outer.width > 0 && outer.height > 0;
}
/// <summary>
/// Draw the Image preview.
/// </summary>
public override void OnPreviewGUI(Rect rect, GUIStyle background)
{
RawImage rawImage = target as RawImage;
Texture tex = rawImage.mainTexture;
if (tex == null)
return;
var outer = Outer(rawImage);
SpriteDrawUtility.DrawSprite(tex, rect, outer, rawImage.uvRect, rawImage.canvasRenderer.GetColor());
}
/// <summary>
/// Info String drawn at the bottom of the Preview
/// </summary>
public override string GetInfoString()
{
RawImage rawImage = target as RawImage;
// Image size Text
string text = string.Format("RawImage Size: {0}x{1}",
Mathf.RoundToInt(Mathf.Abs(rawImage.rectTransform.rect.width)),
Mathf.RoundToInt(Mathf.Abs(rawImage.rectTransform.rect.height)));
return text;
}
}
}

View File

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

View File

@@ -0,0 +1,67 @@
using UnityEngine;
using UnityEngine.UI;
namespace UnityEditor.UI
{
[CustomEditor(typeof(RectMask2D), true)]
[CanEditMultipleObjects]
/// <summary>
/// Custom editor for the RectMask2d component.
/// Extend this class to write a custom editor for a component derived from Mask.
/// </summary>
public class RectMask2DEditor : Editor
{
SerializedProperty m_Padding;
SerializedProperty m_Softness;
GUIContent m_PaddingContent;
GUIContent m_LeftContent;
GUIContent m_RightContent;
GUIContent m_TopContent;
GUIContent m_BottomContent;
static private bool m_ShowOffsets = false;
protected virtual void OnEnable()
{
m_PaddingContent = EditorGUIUtility.TrTextContent("Padding");
m_LeftContent = EditorGUIUtility.TrTextContent("Left");
m_RightContent = EditorGUIUtility.TrTextContent("Right");
m_TopContent = EditorGUIUtility.TrTextContent("Top");
m_BottomContent = EditorGUIUtility.TrTextContent("Bottom");
m_Padding = serializedObject.FindProperty("m_Padding");
m_Softness = serializedObject.FindProperty("m_Softness");
}
public override void OnInspectorGUI()
{
m_ShowOffsets = EditorGUILayout.Foldout(m_ShowOffsets, m_PaddingContent, true);
if (m_ShowOffsets)
OffsetGUI();
EditorGUILayout.PropertyField(m_Softness);
serializedObject.ApplyModifiedProperties();
}
void OffsetGUI()
{
using (var check = new EditorGUI.ChangeCheckScope())
{
EditorGUI.indentLevel++;
Vector4 newPadding = m_Padding.vector4Value;
newPadding.x = EditorGUILayout.FloatField(m_LeftContent, newPadding.x);
newPadding.z = EditorGUILayout.FloatField(m_RightContent, newPadding.z);
newPadding.w = EditorGUILayout.FloatField(m_TopContent, newPadding.w);
newPadding.y = EditorGUILayout.FloatField(m_BottomContent, newPadding.y);
if (check.changed)
{
m_Padding.vector4Value = newPadding;
}
EditorGUI.indentLevel--;
}
}
}
}

View File

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

View File

@@ -0,0 +1,176 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEditor.AnimatedValues;
namespace UnityEditor.UI
{
[CustomEditor(typeof(ScrollRect), true)]
[CanEditMultipleObjects]
/// <summary>
/// Custom Editor for the ScrollRect Component.
/// Extend this class to write a custom editor for a component derived from ScrollRect.
/// </summary>
public class ScrollRectEditor : Editor
{
SerializedProperty m_Content;
SerializedProperty m_Horizontal;
SerializedProperty m_Vertical;
SerializedProperty m_MovementType;
SerializedProperty m_Elasticity;
SerializedProperty m_Inertia;
SerializedProperty m_DecelerationRate;
SerializedProperty m_ScrollSensitivity;
SerializedProperty m_Viewport;
SerializedProperty m_HorizontalScrollbar;
SerializedProperty m_VerticalScrollbar;
SerializedProperty m_HorizontalScrollbarVisibility;
SerializedProperty m_VerticalScrollbarVisibility;
SerializedProperty m_HorizontalScrollbarSpacing;
SerializedProperty m_VerticalScrollbarSpacing;
SerializedProperty m_OnValueChanged;
AnimBool m_ShowElasticity;
AnimBool m_ShowDecelerationRate;
bool m_ViewportIsNotChild, m_HScrollbarIsNotChild, m_VScrollbarIsNotChild;
static string s_HError = "For this visibility mode, the Viewport property and the Horizontal Scrollbar property both needs to be set to a Rect Transform that is a child to the Scroll Rect.";
static string s_VError = "For this visibility mode, the Viewport property and the Vertical Scrollbar property both needs to be set to a Rect Transform that is a child to the Scroll Rect.";
protected virtual void OnEnable()
{
m_Content = serializedObject.FindProperty("m_Content");
m_Horizontal = serializedObject.FindProperty("m_Horizontal");
m_Vertical = serializedObject.FindProperty("m_Vertical");
m_MovementType = serializedObject.FindProperty("m_MovementType");
m_Elasticity = serializedObject.FindProperty("m_Elasticity");
m_Inertia = serializedObject.FindProperty("m_Inertia");
m_DecelerationRate = serializedObject.FindProperty("m_DecelerationRate");
m_ScrollSensitivity = serializedObject.FindProperty("m_ScrollSensitivity");
m_Viewport = serializedObject.FindProperty("m_Viewport");
m_HorizontalScrollbar = serializedObject.FindProperty("m_HorizontalScrollbar");
m_VerticalScrollbar = serializedObject.FindProperty("m_VerticalScrollbar");
m_HorizontalScrollbarVisibility = serializedObject.FindProperty("m_HorizontalScrollbarVisibility");
m_VerticalScrollbarVisibility = serializedObject.FindProperty("m_VerticalScrollbarVisibility");
m_HorizontalScrollbarSpacing = serializedObject.FindProperty("m_HorizontalScrollbarSpacing");
m_VerticalScrollbarSpacing = serializedObject.FindProperty("m_VerticalScrollbarSpacing");
m_OnValueChanged = serializedObject.FindProperty("m_OnValueChanged");
m_ShowElasticity = new AnimBool(Repaint);
m_ShowDecelerationRate = new AnimBool(Repaint);
SetAnimBools(true);
}
protected virtual void OnDisable()
{
m_ShowElasticity.valueChanged.RemoveListener(Repaint);
m_ShowDecelerationRate.valueChanged.RemoveListener(Repaint);
}
void SetAnimBools(bool instant)
{
SetAnimBool(m_ShowElasticity, !m_MovementType.hasMultipleDifferentValues && m_MovementType.enumValueIndex == (int)ScrollRect.MovementType.Elastic, instant);
SetAnimBool(m_ShowDecelerationRate, !m_Inertia.hasMultipleDifferentValues && m_Inertia.boolValue == true, instant);
}
void SetAnimBool(AnimBool a, bool value, bool instant)
{
if (instant)
a.value = value;
else
a.target = value;
}
void CalculateCachedValues()
{
m_ViewportIsNotChild = false;
m_HScrollbarIsNotChild = false;
m_VScrollbarIsNotChild = false;
if (targets.Length == 1)
{
Transform transform = ((ScrollRect)target).transform;
if (m_Viewport.objectReferenceValue == null || ((RectTransform)m_Viewport.objectReferenceValue).transform.parent != transform)
m_ViewportIsNotChild = true;
if (m_HorizontalScrollbar.objectReferenceValue == null || ((Scrollbar)m_HorizontalScrollbar.objectReferenceValue).transform.parent != transform)
m_HScrollbarIsNotChild = true;
if (m_VerticalScrollbar.objectReferenceValue == null || ((Scrollbar)m_VerticalScrollbar.objectReferenceValue).transform.parent != transform)
m_VScrollbarIsNotChild = true;
}
}
public override void OnInspectorGUI()
{
SetAnimBools(false);
serializedObject.Update();
// Once we have a reliable way to know if the object changed, only re-cache in that case.
CalculateCachedValues();
EditorGUILayout.PropertyField(m_Content);
EditorGUILayout.PropertyField(m_Horizontal);
EditorGUILayout.PropertyField(m_Vertical);
EditorGUILayout.PropertyField(m_MovementType);
if (EditorGUILayout.BeginFadeGroup(m_ShowElasticity.faded))
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_Elasticity);
EditorGUI.indentLevel--;
}
EditorGUILayout.EndFadeGroup();
EditorGUILayout.PropertyField(m_Inertia);
if (EditorGUILayout.BeginFadeGroup(m_ShowDecelerationRate.faded))
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_DecelerationRate);
EditorGUI.indentLevel--;
}
EditorGUILayout.EndFadeGroup();
EditorGUILayout.PropertyField(m_ScrollSensitivity);
EditorGUILayout.Space();
EditorGUILayout.PropertyField(m_Viewport);
EditorGUILayout.PropertyField(m_HorizontalScrollbar);
if (m_HorizontalScrollbar.objectReferenceValue && !m_HorizontalScrollbar.hasMultipleDifferentValues)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_HorizontalScrollbarVisibility, EditorGUIUtility.TrTextContent("Visibility"));
if ((ScrollRect.ScrollbarVisibility)m_HorizontalScrollbarVisibility.enumValueIndex == ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport
&& !m_HorizontalScrollbarVisibility.hasMultipleDifferentValues)
{
if (m_ViewportIsNotChild || m_HScrollbarIsNotChild)
EditorGUILayout.HelpBox(s_HError, MessageType.Error);
EditorGUILayout.PropertyField(m_HorizontalScrollbarSpacing, EditorGUIUtility.TrTextContent("Spacing"));
}
EditorGUI.indentLevel--;
}
EditorGUILayout.PropertyField(m_VerticalScrollbar);
if (m_VerticalScrollbar.objectReferenceValue && !m_VerticalScrollbar.hasMultipleDifferentValues)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_VerticalScrollbarVisibility, EditorGUIUtility.TrTextContent("Visibility"));
if ((ScrollRect.ScrollbarVisibility)m_VerticalScrollbarVisibility.enumValueIndex == ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport
&& !m_VerticalScrollbarVisibility.hasMultipleDifferentValues)
{
if (m_ViewportIsNotChild || m_VScrollbarIsNotChild)
EditorGUILayout.HelpBox(s_VError, MessageType.Error);
EditorGUILayout.PropertyField(m_VerticalScrollbarSpacing, EditorGUIUtility.TrTextContent("Spacing"));
}
EditorGUI.indentLevel--;
}
EditorGUILayout.Space();
EditorGUILayout.PropertyField(m_OnValueChanged);
serializedObject.ApplyModifiedProperties();
}
}
}

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