Add example Unity Project

This commit is contained in:
Michał Gdula 2023-04-26 01:55:33 +01:00
parent fda7ff28dd
commit e3acdb9d6b
7122 changed files with 505543 additions and 2 deletions

View file

@ -0,0 +1,8 @@
# Changelog
All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [1.0.0] - 2019-01-08
This is the first release of Unity UI as a built in package.

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c851bee4305bddf438cc6ffc515991ce
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -0,0 +1,33 @@
using UnityEngine;
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;
protected virtual void OnEnable()
{
m_AspectMode = serializedObject.FindProperty("m_AspectMode");
m_AspectRatio = serializedObject.FindProperty("m_AspectRatio");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(m_AspectMode);
EditorGUILayout.PropertyField(m_AspectRatio);
serializedObject.ApplyModifiedProperties();
base.OnInspectorGUI();
}
}
}

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,164 @@
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;
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;
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");
}
public override void OnInspectorGUI()
{
if (s_Styles == null)
s_Styles = new Styles();
bool allAreRoot = true;
bool showWorldDiffers = false;
bool showWorld = ((target as CanvasScaler).GetComponent<Canvas>().renderMode == RenderMode.WorldSpace);
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,116 @@
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_Maskable;
private GUIContent m_CorrectButtonContent;
protected AnimBool m_ShowNativeSize;
protected virtual void OnDisable()
{
Tools.hidden = false;
m_ShowNativeSize.valueChanged.RemoveListener(Repaint);
}
protected virtual void OnEnable()
{
m_CorrectButtonContent = EditorGUIUtility.TrTextContent("Set Native Size", "Sets the size to match the content.");
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_Maskable = serializedObject.FindProperty("m_Maskable");
m_ShowNativeSize = new AnimBool(false);
m_ShowNativeSize.valueChanged.AddListener(Repaint);
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(m_Script);
AppearanceControlsGUI();
RaycastControlsGUI();
MaskableControlsGUI();
serializedObject.ApplyModifiedProperties();
}
/// <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()
{
EditorGUILayout.PropertyField(m_RaycastTarget);
}
}
}

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,92 @@
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;
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");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(m_Padding, true);
EditorGUILayout.PropertyField(m_Spacing, true);
EditorGUILayout.PropertyField(m_ChildAlignment, 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.showMixedValue = property.hasMultipleDifferentValues;
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.showMixedValue = false;
}
}
}

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,269 @@
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;
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);
}
protected override void 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();
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.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;
}
switch ((Image.FillMethod)m_FillMethod.enumValueIndex)
{
case Image.FillMethod.Horizontal:
m_FillOrigin.intValue = (int)(Image.OriginHorizontal)EditorGUILayout.EnumPopup("Fill Origin", (Image.OriginHorizontal)m_FillOrigin.intValue);
break;
case Image.FillMethod.Vertical:
m_FillOrigin.intValue = (int)(Image.OriginVertical)EditorGUILayout.EnumPopup("Fill Origin", (Image.OriginVertical)m_FillOrigin.intValue);
break;
case Image.FillMethod.Radial90:
m_FillOrigin.intValue = (int)(Image.Origin90)EditorGUILayout.EnumPopup("Fill Origin", (Image.Origin90)m_FillOrigin.intValue);
break;
case Image.FillMethod.Radial180:
m_FillOrigin.intValue = (int)(Image.Origin180)EditorGUILayout.EnumPopup("Fill Origin", (Image.Origin180)m_FillOrigin.intValue);
break;
case Image.FillMethod.Radial360:
m_FillOrigin.intValue = (int)(Image.Origin360)EditorGUILayout.EnumPopup("Fill Origin", (Image.Origin360)m_FillOrigin.intValue);
break;
}
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,146 @@
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_OnEndEdit;
SerializedProperty m_ReadOnly;
SerializedProperty m_ShouldActivateOnSelect;
AnimBool m_CustomColor;
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_OnEndEdit = serializedObject.FindProperty("m_OnEndEdit");
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_OnEndEdit);
}
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 = new Styles();
public override void Initialize(UnityEngine.Object[] targets)
{
Profiler.BeginSample("ComponentInterceptedEvents.Initialize");
base.Initialize(targets);
m_TargetEvents = new Dictionary<GameObject, List<ComponentInterceptedEvents>>(targets.Count());
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()
{
Color fontColor = new Color(0.7f, 0.7f, 0.7f);
labelStyle.padding.right += 4;
labelStyle.normal.textColor = fontColor;
headerStyle.padding.right += 4;
headerStyle.normal.textColor = fontColor;
}
}
private GUIContent m_Title;
private Styles m_Styles = new 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;
return go.GetComponent(typeof(ILayoutElement)) != null;
}
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,419 @@
using System;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using UnityEditor.Experimental.SceneManagement;
namespace UnityEditor.UI
{
/// <summary>
/// This script adds the UI menu options to the Unity Editor.
/// </summary>
static internal class MenuOptions
{
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/Text", false, 2000)]
static public void AddText(MenuCommand menuCommand)
{
GameObject go;
using (new FactorySwapToEditor())
go = DefaultControls.CreateText(GetStandardResources());
PlaceUIElementRoot(go, menuCommand);
}
[MenuItem("GameObject/UI/Image", false, 2001)]
static public void AddImage(MenuCommand menuCommand)
{
GameObject go;
using (new FactorySwapToEditor())
go = DefaultControls.CreateImage(GetStandardResources());
PlaceUIElementRoot(go, menuCommand);
}
[MenuItem("GameObject/UI/Raw Image", false, 2002)]
static public void AddRawImage(MenuCommand menuCommand)
{
GameObject go;
using (new FactorySwapToEditor())
go = DefaultControls.CreateRawImage(GetStandardResources());
PlaceUIElementRoot(go, menuCommand);
}
// Controls
// Button and toggle are controls you just click on.
[MenuItem("GameObject/UI/Button", false, 2030)]
static public void AddButton(MenuCommand menuCommand)
{
GameObject go;
using (new FactorySwapToEditor())
go = DefaultControls.CreateButton(GetStandardResources());
PlaceUIElementRoot(go, menuCommand);
}
[MenuItem("GameObject/UI/Toggle", false, 2031)]
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, 2033)]
static public void AddSlider(MenuCommand menuCommand)
{
GameObject go;
using (new FactorySwapToEditor())
go = DefaultControls.CreateSlider(GetStandardResources());
PlaceUIElementRoot(go, menuCommand);
}
[MenuItem("GameObject/UI/Scrollbar", false, 2034)]
static public void AddScrollbar(MenuCommand menuCommand)
{
GameObject go;
using (new FactorySwapToEditor())
go = DefaultControls.CreateScrollbar(GetStandardResources());
PlaceUIElementRoot(go, menuCommand);
}
// More advanced controls below
[MenuItem("GameObject/UI/Dropdown", false, 2035)]
static public void AddDropdown(MenuCommand menuCommand)
{
GameObject go;
using (new FactorySwapToEditor())
go = DefaultControls.CreateDropdown(GetStandardResources());
PlaceUIElementRoot(go, menuCommand);
}
[MenuItem("GameObject/UI/Input Field", false, 2036)]
public static void AddInputField(MenuCommand menuCommand)
{
GameObject go;
using (new FactorySwapToEditor())
go = DefaultControls.CreateInputField(GetStandardResources());
PlaceUIElementRoot(go, menuCommand);
}
// Containers
[MenuItem("GameObject/UI/Canvas", false, 2060)]
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;
}
[MenuItem("GameObject/UI/Panel", false, 2061)]
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;
}
[MenuItem("GameObject/UI/Scroll View", false, 2062)]
static public void AddScrollView(MenuCommand menuCommand)
{
GameObject go;
using (new FactorySwapToEditor())
go = DefaultControls.CreateScrollView(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, 2100)]
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;
if (StageUtility.GetStageHandle(canvas.gameObject) != StageUtility.GetCurrentStageHandle())
return false;
return true;
}
}
}

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,39 @@
using UnityEngine;
using UnityEngine.UI;
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
{
public override void OnGUI(Rect rect, SerializedProperty prop, GUIContent label)
{
Rect drawRect = rect;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty normalTrigger = prop.FindPropertyRelative("m_NormalTrigger");
SerializedProperty higlightedTrigger = prop.FindPropertyRelative("m_HighlightedTrigger");
SerializedProperty pressedTrigger = prop.FindPropertyRelative("m_PressedTrigger");
SerializedProperty selectedTrigger = prop.FindPropertyRelative("m_SelectedTrigger");
SerializedProperty disabledTrigger = prop.FindPropertyRelative("m_DisabledTrigger");
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;
}
}
}

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,45 @@
using UnityEngine;
using UnityEngine.UI;
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
{
public override void OnGUI(Rect rect, SerializedProperty prop, GUIContent label)
{
Rect drawRect = rect;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty normalColor = prop.FindPropertyRelative("m_NormalColor");
SerializedProperty highlighted = prop.FindPropertyRelative("m_HighlightedColor");
SerializedProperty pressedColor = prop.FindPropertyRelative("m_PressedColor");
SerializedProperty selectedColor = prop.FindPropertyRelative("m_SelectedColor");
SerializedProperty disabledColor = prop.FindPropertyRelative("m_DisabledColor");
SerializedProperty colorMultiplier = prop.FindPropertyRelative("m_ColorMultiplier");
SerializedProperty fadeDuration = prop.FindPropertyRelative("m_FadeDuration");
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;
}
}
}

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,62 @@
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.UI;
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
{
private ReorderableList m_ReorderableList;
private void Init(SerializedProperty property)
{
if (m_ReorderableList != null)
return;
SerializedProperty array = property.FindPropertyRelative("m_Options");
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, "Options");
}
private void DrawOptionData(Rect rect, int index, bool isActive, bool isFocused)
{
SerializedProperty itemData = m_ReorderableList.serializedProperty.GetArrayElementAtIndex(index);
SerializedProperty itemText = itemData.FindPropertyRelative("m_Text");
SerializedProperty itemImage = itemData.FindPropertyRelative("m_Image");
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();
}
}
}

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,514 @@
using UnityEngine;
using UnityEngine.UI;
namespace UnityEditor.UI
{
[CustomPropertyDrawer(typeof(FontData), true)]
/// <summary>
/// This is a PropertyDrawer for FontData. It is implemented using the standard Unity PropertyDrawer framework
/// </summary>
public class FontDataDrawer : PropertyDrawer
{
static private class Styles
{
public static GUIStyle alignmentButtonLeft = new GUIStyle(EditorStyles.miniButtonLeft);
public static GUIStyle alignmentButtonMid = new GUIStyle(EditorStyles.miniButtonMid);
public static GUIStyle alignmentButtonRight = new GUIStyle(EditorStyles.miniButtonRight);
public static GUIContent m_EncodingContent;
public static GUIContent m_LeftAlignText;
public static GUIContent m_CenterAlignText;
public static GUIContent m_RightAlignText;
public static GUIContent m_TopAlignText;
public static GUIContent m_MiddleAlignText;
public static GUIContent m_BottomAlignText;
public static GUIContent m_LeftAlignTextActive;
public static GUIContent m_CenterAlignTextActive;
public static GUIContent m_RightAlignTextActive;
public static GUIContent m_TopAlignTextActive;
public static GUIContent m_MiddleAlignTextActive;
public static GUIContent m_BottomAlignTextActive;
static Styles()
{
m_EncodingContent = EditorGUIUtility.TrTextContent("Rich Text", "Use emoticons and colors");
// Horizontal Alignment Icons
m_LeftAlignText = EditorGUIUtility.IconContent(@"GUISystem/align_horizontally_left", "Left Align");
m_CenterAlignText = EditorGUIUtility.IconContent(@"GUISystem/align_horizontally_center", "Center Align");
m_RightAlignText = EditorGUIUtility.IconContent(@"GUISystem/align_horizontally_right", "Right Align");
m_LeftAlignTextActive = EditorGUIUtility.IconContent(@"GUISystem/align_horizontally_left_active", "Left Align");
m_CenterAlignTextActive = EditorGUIUtility.IconContent(@"GUISystem/align_horizontally_center_active", "Center Align");
m_RightAlignTextActive = EditorGUIUtility.IconContent(@"GUISystem/align_horizontally_right_active", "Right Align");
// Vertical Alignment Icons
m_TopAlignText = EditorGUIUtility.IconContent(@"GUISystem/align_vertically_top", "Top Align");
m_MiddleAlignText = EditorGUIUtility.IconContent(@"GUISystem/align_vertically_center", "Middle Align");
m_BottomAlignText = EditorGUIUtility.IconContent(@"GUISystem/align_vertically_bottom", "Bottom Align");
m_TopAlignTextActive = EditorGUIUtility.IconContent(@"GUISystem/align_vertically_top_active", "Top Align");
m_MiddleAlignTextActive = EditorGUIUtility.IconContent(@"GUISystem/align_vertically_center_active", "Middle Align");
m_BottomAlignTextActive = EditorGUIUtility.IconContent(@"GUISystem/align_vertically_bottom_active", "Bottom Align");
FixAlignmentButtonStyles(alignmentButtonLeft, alignmentButtonMid, alignmentButtonRight);
}
static void FixAlignmentButtonStyles(params GUIStyle[] styles)
{
foreach (GUIStyle style in styles)
{
style.padding.left = 2;
style.padding.right = 2;
}
}
}
private enum VerticalTextAligment
{
Top,
Middle,
Bottom
}
private enum HorizontalTextAligment
{
Left,
Center,
Right
}
private const int kAlignmentButtonWidth = 20;
static int s_TextAlignmentHash = "DoTextAligmentControl".GetHashCode();
private SerializedProperty m_SupportEncoding;
private SerializedProperty m_Font;
private SerializedProperty m_FontSize;
private SerializedProperty m_LineSpacing;
private SerializedProperty m_FontStyle;
private SerializedProperty m_ResizeTextForBestFit;
private SerializedProperty m_ResizeTextMinSize;
private SerializedProperty m_ResizeTextMaxSize;
private SerializedProperty m_HorizontalOverflow;
private SerializedProperty m_VerticalOverflow;
private SerializedProperty m_Alignment;
private SerializedProperty m_AlignByGeometry;
private float m_FontFieldfHeight = 0f;
private float m_FontStyleHeight = 0f;
private float m_FontSizeHeight = 0f;
private float m_LineSpacingHeight = 0f;
private float m_EncodingHeight = 0f;
private float m_ResizeTextForBestFitHeight = 0f;
private float m_ResizeTextMinSizeHeight = 0f;
private float m_ResizeTextMaxSizeHeight = 0f;
private float m_HorizontalOverflowHeight = 0f;
private float m_VerticalOverflowHeight = 0f;
private float m_AlignByGeometryHeight = 0f;
protected void Init(SerializedProperty property)
{
m_SupportEncoding = property.FindPropertyRelative("m_RichText");
m_Font = property.FindPropertyRelative("m_Font");
m_FontSize = property.FindPropertyRelative("m_FontSize");
m_LineSpacing = property.FindPropertyRelative("m_LineSpacing");
m_FontStyle = property.FindPropertyRelative("m_FontStyle");
m_ResizeTextForBestFit = property.FindPropertyRelative("m_BestFit");
m_ResizeTextMinSize = property.FindPropertyRelative("m_MinSize");
m_ResizeTextMaxSize = property.FindPropertyRelative("m_MaxSize");
m_HorizontalOverflow = property.FindPropertyRelative("m_HorizontalOverflow");
m_VerticalOverflow = property.FindPropertyRelative("m_VerticalOverflow");
m_Alignment = property.FindPropertyRelative("m_Alignment");
m_AlignByGeometry = property.FindPropertyRelative("m_AlignByGeometry");
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
Init(property);
m_FontFieldfHeight = EditorGUI.GetPropertyHeight(m_Font);
m_FontStyleHeight = EditorGUI.GetPropertyHeight(m_FontStyle);
m_FontSizeHeight = EditorGUI.GetPropertyHeight(m_FontSize);
m_LineSpacingHeight = EditorGUI.GetPropertyHeight(m_LineSpacing);
m_EncodingHeight = EditorGUI.GetPropertyHeight(m_SupportEncoding);
m_ResizeTextForBestFitHeight = EditorGUI.GetPropertyHeight(m_ResizeTextForBestFit);
m_ResizeTextMinSizeHeight = EditorGUI.GetPropertyHeight(m_ResizeTextMinSize);
m_ResizeTextMaxSizeHeight = EditorGUI.GetPropertyHeight(m_ResizeTextMaxSize);
m_HorizontalOverflowHeight = EditorGUI.GetPropertyHeight(m_HorizontalOverflow);
m_VerticalOverflowHeight = EditorGUI.GetPropertyHeight(m_VerticalOverflow);
m_AlignByGeometryHeight = EditorGUI.GetPropertyHeight(m_AlignByGeometry);
var height = m_FontFieldfHeight
+ m_FontStyleHeight
+ m_FontSizeHeight
+ m_LineSpacingHeight
+ m_EncodingHeight
+ m_ResizeTextForBestFitHeight
+ m_HorizontalOverflowHeight
+ m_VerticalOverflowHeight
+ EditorGUIUtility.singleLineHeight * 3
+ EditorGUIUtility.standardVerticalSpacing * 10
+ m_AlignByGeometryHeight;
if (m_ResizeTextForBestFit.boolValue)
{
height += m_ResizeTextMinSizeHeight
+ m_ResizeTextMaxSizeHeight
+ EditorGUIUtility.standardVerticalSpacing * 2;
}
return height;
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
Init(property);
Rect rect = position;
rect.height = EditorGUIUtility.singleLineHeight;
EditorGUI.LabelField(rect, "Character", EditorStyles.boldLabel);
rect.y += rect.height + EditorGUIUtility.standardVerticalSpacing;
++EditorGUI.indentLevel;
{
Font font = m_Font.objectReferenceValue as Font;
rect.height = m_FontFieldfHeight;
EditorGUI.BeginChangeCheck();
EditorGUI.PropertyField(rect, m_Font);
if (EditorGUI.EndChangeCheck())
{
font = m_Font.objectReferenceValue as Font;
if (font != null && !font.dynamic)
m_FontSize.intValue = font.fontSize;
}
rect.y += rect.height + EditorGUIUtility.standardVerticalSpacing;
rect.height = m_FontStyleHeight;
using (new EditorGUI.DisabledScope(!m_Font.hasMultipleDifferentValues && font != null && !font.dynamic))
{
EditorGUI.PropertyField(rect, m_FontStyle);
}
rect.y += rect.height + EditorGUIUtility.standardVerticalSpacing;
rect.height = m_FontSizeHeight;
EditorGUI.PropertyField(rect, m_FontSize);
rect.y += rect.height + EditorGUIUtility.standardVerticalSpacing;
rect.height = m_LineSpacingHeight;
EditorGUI.PropertyField(rect, m_LineSpacing);
rect.y += rect.height + EditorGUIUtility.standardVerticalSpacing;
rect.height = m_EncodingHeight;
EditorGUI.PropertyField(rect, m_SupportEncoding, Styles.m_EncodingContent);
}
--EditorGUI.indentLevel;
rect.y += rect.height + EditorGUIUtility.standardVerticalSpacing;
rect.height = EditorGUIUtility.singleLineHeight;
EditorGUI.LabelField(rect, "Paragraph", EditorStyles.boldLabel);
rect.y += rect.height + EditorGUIUtility.standardVerticalSpacing;
++EditorGUI.indentLevel;
{
rect.height = EditorGUIUtility.singleLineHeight;
DoTextAligmentControl(rect, m_Alignment);
rect.y += rect.height + EditorGUIUtility.standardVerticalSpacing;
rect.height = m_HorizontalOverflowHeight;
EditorGUI.PropertyField(rect, m_AlignByGeometry);
rect.y += rect.height + EditorGUIUtility.standardVerticalSpacing;
rect.height = m_HorizontalOverflowHeight;
EditorGUI.PropertyField(rect, m_HorizontalOverflow);
rect.y += rect.height + EditorGUIUtility.standardVerticalSpacing;
rect.height = m_VerticalOverflowHeight;
EditorGUI.PropertyField(rect, m_VerticalOverflow);
rect.y += rect.height + EditorGUIUtility.standardVerticalSpacing;
rect.height = m_ResizeTextMaxSizeHeight;
EditorGUI.PropertyField(rect, m_ResizeTextForBestFit);
if (m_ResizeTextForBestFit.boolValue)
{
rect.y += rect.height + EditorGUIUtility.standardVerticalSpacing;
rect.height = m_ResizeTextMinSizeHeight;
EditorGUI.PropertyField(rect, m_ResizeTextMinSize);
rect.y += rect.height + EditorGUIUtility.standardVerticalSpacing;
rect.height = m_ResizeTextMaxSizeHeight;
EditorGUI.PropertyField(rect, m_ResizeTextMaxSize);
}
}
--EditorGUI.indentLevel;
}
private void DoTextAligmentControl(Rect position, SerializedProperty alignment)
{
GUIContent alingmentContent = EditorGUIUtility.TrTextContent("Alignment");
int id = EditorGUIUtility.GetControlID(s_TextAlignmentHash, FocusType.Keyboard, position);
EditorGUIUtility.SetIconSize(new Vector2(15, 15));
EditorGUI.BeginProperty(position, alingmentContent, alignment);
{
Rect controlArea = EditorGUI.PrefixLabel(position, id, alingmentContent);
float width = kAlignmentButtonWidth * 3;
float spacing = Mathf.Clamp(controlArea.width - width * 2, 2, 10);
Rect horizontalAligment = new Rect(controlArea.x, controlArea.y, width, controlArea.height);
Rect verticalAligment = new Rect(horizontalAligment.xMax + spacing, controlArea.y, width, controlArea.height);
DoHorizontalAligmentControl(horizontalAligment, alignment);
DoVerticalAligmentControl(verticalAligment, alignment);
}
EditorGUI.EndProperty();
EditorGUIUtility.SetIconSize(Vector2.zero);
}
private static void DoHorizontalAligmentControl(Rect position, SerializedProperty alignment)
{
TextAnchor ta = (TextAnchor)alignment.intValue;
HorizontalTextAligment horizontalAlignment = GetHorizontalAlignment(ta);
bool leftAlign = (horizontalAlignment == HorizontalTextAligment.Left);
bool centerAlign = (horizontalAlignment == HorizontalTextAligment.Center);
bool rightAlign = (horizontalAlignment == HorizontalTextAligment.Right);
if (alignment.hasMultipleDifferentValues)
{
foreach (var obj in alignment.serializedObject.targetObjects)
{
Text text = obj as Text;
horizontalAlignment = GetHorizontalAlignment(text.alignment);
leftAlign = leftAlign || (horizontalAlignment == HorizontalTextAligment.Left);
centerAlign = centerAlign || (horizontalAlignment == HorizontalTextAligment.Center);
rightAlign = rightAlign || (horizontalAlignment == HorizontalTextAligment.Right);
}
}
position.width = kAlignmentButtonWidth;
EditorGUI.BeginChangeCheck();
EditorToggle(position, leftAlign, leftAlign ? Styles.m_LeftAlignTextActive : Styles.m_LeftAlignText, Styles.alignmentButtonLeft);
if (EditorGUI.EndChangeCheck())
{
SetHorizontalAlignment(alignment, HorizontalTextAligment.Left);
}
position.x += position.width;
EditorGUI.BeginChangeCheck();
EditorToggle(position, centerAlign, centerAlign ? Styles.m_CenterAlignTextActive : Styles.m_CenterAlignText, Styles.alignmentButtonMid);
if (EditorGUI.EndChangeCheck())
{
SetHorizontalAlignment(alignment, HorizontalTextAligment.Center);
}
position.x += position.width;
EditorGUI.BeginChangeCheck();
EditorToggle(position, rightAlign, rightAlign ? Styles.m_RightAlignTextActive : Styles.m_RightAlignText, Styles.alignmentButtonRight);
if (EditorGUI.EndChangeCheck())
{
SetHorizontalAlignment(alignment, HorizontalTextAligment.Right);
}
}
private static void DoVerticalAligmentControl(Rect position, SerializedProperty alignment)
{
TextAnchor ta = (TextAnchor)alignment.intValue;
VerticalTextAligment verticalTextAligment = GetVerticalAlignment(ta);
bool topAlign = (verticalTextAligment == VerticalTextAligment.Top);
bool middleAlign = (verticalTextAligment == VerticalTextAligment.Middle);
bool bottomAlign = (verticalTextAligment == VerticalTextAligment.Bottom);
if (alignment.hasMultipleDifferentValues)
{
foreach (var obj in alignment.serializedObject.targetObjects)
{
Text text = obj as Text;
TextAnchor textAlignment = text.alignment;
verticalTextAligment = GetVerticalAlignment(textAlignment);
topAlign = topAlign || (verticalTextAligment == VerticalTextAligment.Top);
middleAlign = middleAlign || (verticalTextAligment == VerticalTextAligment.Middle);
bottomAlign = bottomAlign || (verticalTextAligment == VerticalTextAligment.Bottom);
}
}
position.width = kAlignmentButtonWidth;
// position.x += position.width;
EditorGUI.BeginChangeCheck();
EditorToggle(position, topAlign, topAlign ? Styles.m_TopAlignTextActive : Styles.m_TopAlignText, Styles.alignmentButtonLeft);
if (EditorGUI.EndChangeCheck())
{
SetVerticalAlignment(alignment, VerticalTextAligment.Top);
}
position.x += position.width;
EditorGUI.BeginChangeCheck();
EditorToggle(position, middleAlign, middleAlign ? Styles.m_MiddleAlignTextActive : Styles.m_MiddleAlignText, Styles.alignmentButtonMid);
if (EditorGUI.EndChangeCheck())
{
SetVerticalAlignment(alignment, VerticalTextAligment.Middle);
}
position.x += position.width;
EditorGUI.BeginChangeCheck();
EditorToggle(position, bottomAlign, bottomAlign ? Styles.m_BottomAlignTextActive : Styles.m_BottomAlignText, Styles.alignmentButtonRight);
if (EditorGUI.EndChangeCheck())
{
SetVerticalAlignment(alignment, VerticalTextAligment.Bottom);
}
}
private static bool EditorToggle(Rect position, bool value, GUIContent content, GUIStyle style)
{
int hashCode = "AlignToggle".GetHashCode();
int id = EditorGUIUtility.GetControlID(hashCode, FocusType.Keyboard, position);
Event evt = Event.current;
// Toggle selected toggle on space or return key
if (EditorGUIUtility.keyboardControl == id && evt.type == EventType.KeyDown && (evt.keyCode == KeyCode.Space || evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter))
{
value = !value;
evt.Use();
GUI.changed = true;
}
if (evt.type == EventType.KeyDown && Event.current.button == 0 && position.Contains(Event.current.mousePosition))
{
GUIUtility.keyboardControl = id;
EditorGUIUtility.editingTextField = false;
HandleUtility.Repaint();
}
bool returnValue = GUI.Toggle(position, id, value, content, style);
return returnValue;
}
private static HorizontalTextAligment GetHorizontalAlignment(TextAnchor ta)
{
switch (ta)
{
case TextAnchor.MiddleCenter:
case TextAnchor.UpperCenter:
case TextAnchor.LowerCenter:
return HorizontalTextAligment.Center;
case TextAnchor.UpperRight:
case TextAnchor.MiddleRight:
case TextAnchor.LowerRight:
return HorizontalTextAligment.Right;
case TextAnchor.UpperLeft:
case TextAnchor.MiddleLeft:
case TextAnchor.LowerLeft:
return HorizontalTextAligment.Left;
}
return HorizontalTextAligment.Left;
}
private static VerticalTextAligment GetVerticalAlignment(TextAnchor ta)
{
switch (ta)
{
case TextAnchor.UpperLeft:
case TextAnchor.UpperCenter:
case TextAnchor.UpperRight:
return VerticalTextAligment.Top;
case TextAnchor.MiddleLeft:
case TextAnchor.MiddleCenter:
case TextAnchor.MiddleRight:
return VerticalTextAligment.Middle;
case TextAnchor.LowerLeft:
case TextAnchor.LowerCenter:
case TextAnchor.LowerRight:
return VerticalTextAligment.Bottom;
}
return VerticalTextAligment.Top;
}
// We can't go through serialized properties here since we're showing two controls for a single SerializzedProperty.
private static void SetHorizontalAlignment(SerializedProperty alignment, HorizontalTextAligment horizontalAlignment)
{
foreach (var obj in alignment.serializedObject.targetObjects)
{
Text text = obj as Text;
VerticalTextAligment currentVerticalAligment = GetVerticalAlignment(text.alignment);
Undo.RecordObject(text, "Horizontal Alignment");
text.alignment = GetAnchor(currentVerticalAligment, horizontalAlignment);
EditorUtility.SetDirty(obj);
}
}
private static void SetVerticalAlignment(SerializedProperty alignment, VerticalTextAligment verticalAlignment)
{
foreach (var obj in alignment.serializedObject.targetObjects)
{
Text text = obj as Text;
HorizontalTextAligment currentHorizontalAligment = GetHorizontalAlignment(text.alignment);
Undo.RecordObject(text, "Vertical Alignment");
text.alignment = GetAnchor(verticalAlignment, currentHorizontalAligment);
EditorUtility.SetDirty(obj);
}
}
private static TextAnchor GetAnchor(VerticalTextAligment verticalTextAligment, HorizontalTextAligment horizontalTextAligment)
{
TextAnchor ac = TextAnchor.UpperLeft;
switch (horizontalTextAligment)
{
case HorizontalTextAligment.Left:
switch (verticalTextAligment)
{
case VerticalTextAligment.Bottom:
ac = TextAnchor.LowerLeft;
break;
case VerticalTextAligment.Middle:
ac = TextAnchor.MiddleLeft;
break;
default:
ac = TextAnchor.UpperLeft;
break;
}
break;
case HorizontalTextAligment.Center:
switch (verticalTextAligment)
{
case VerticalTextAligment.Bottom:
ac = TextAnchor.LowerCenter;
break;
case VerticalTextAligment.Middle:
ac = TextAnchor.MiddleCenter;
break;
default:
ac = TextAnchor.UpperCenter;
break;
}
break;
default:
switch (verticalTextAligment)
{
case VerticalTextAligment.Bottom:
ac = TextAnchor.LowerRight;
break;
case VerticalTextAligment.Middle:
ac = TextAnchor.MiddleRight;
break;
default:
ac = TextAnchor.UpperRight;
break;
}
break;
}
return ac;
}
}
}

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,86 @@
using UnityEngine;
using UnityEngine.UI;
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
{
private class Styles
{
readonly public GUIContent navigationContent;
public Styles()
{
navigationContent = EditorGUIUtility.TrTextContent("Navigation");
}
}
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("m_Mode");
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.Explicit:
{
SerializedProperty selectOnUp = prop.FindPropertyRelative("m_SelectOnUp");
SerializedProperty selectOnDown = prop.FindPropertyRelative("m_SelectOnDown");
SerializedProperty selectOnLeft = prop.FindPropertyRelative("m_SelectOnLeft");
SerializedProperty selectOnRight = prop.FindPropertyRelative("m_SelectOnRight");
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("m_Mode");
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.Explicit: return 5 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing;
default: return EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
}
}
}
}

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,36 @@
using UnityEngine;
using UnityEngine.UI;
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
{
public override void OnGUI(Rect rect, SerializedProperty prop, GUIContent label)
{
Rect drawRect = rect;
drawRect.height = EditorGUIUtility.singleLineHeight;
SerializedProperty highlightedSprite = prop.FindPropertyRelative("m_HighlightedSprite");
SerializedProperty pressedSprite = prop.FindPropertyRelative("m_PressedSprite");
SerializedProperty selectedSprite = prop.FindPropertyRelative("m_SelectedSprite");
SerializedProperty disabledSprite = prop.FindPropertyRelative("m_DisabledSprite");
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;
}
}
}

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);
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();
}
}
}

View file

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

View file

@ -0,0 +1,106 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace UnityEditor.UI
{
[CustomEditor(typeof(Scrollbar), true)]
[CanEditMultipleObjects]
/// <summary>
/// Custom Editor for the Scrollbar Component.
/// Extend this class to write a custom editor for a component derived from Scrollbar.
/// </summary>
public class ScrollbarEditor : SelectableEditor
{
SerializedProperty m_HandleRect;
SerializedProperty m_Direction;
SerializedProperty m_Value;
SerializedProperty m_Size;
SerializedProperty m_NumberOfSteps;
SerializedProperty m_OnValueChanged;
protected override void OnEnable()
{
base.OnEnable();
m_HandleRect = serializedObject.FindProperty("m_HandleRect");
m_Direction = serializedObject.FindProperty("m_Direction");
m_Value = serializedObject.FindProperty("m_Value");
m_Size = serializedObject.FindProperty("m_Size");
m_NumberOfSteps = serializedObject.FindProperty("m_NumberOfSteps");
m_OnValueChanged = serializedObject.FindProperty("m_OnValueChanged");
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
EditorGUILayout.Space();
serializedObject.Update();
// EditorGUILayout.PropertyField(m_HandleRect);
EditorGUI.BeginChangeCheck();
RectTransform newRectTransform = EditorGUILayout.ObjectField("Handle Rect", m_HandleRect.objectReferenceValue, typeof(RectTransform), true) as RectTransform;
if (EditorGUI.EndChangeCheck())
{
// Handle Rect will modify its GameObject RectTransform drivenBy, so we need to Record the old and new RectTransform.
List<Object> modifiedObjects = new List<Object>();
modifiedObjects.Add(newRectTransform);
foreach (var target in m_HandleRect.serializedObject.targetObjects)
{
MonoBehaviour mb = target as MonoBehaviour;
if (mb == null)
continue;
modifiedObjects.Add(mb);
modifiedObjects.Add(mb.GetComponent<RectTransform>());
}
Undo.RecordObjects(modifiedObjects.ToArray(), "Change Handle Rect");
m_HandleRect.objectReferenceValue = newRectTransform;
}
if (m_HandleRect.objectReferenceValue != null)
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_Direction);
if (EditorGUI.EndChangeCheck())
{
Scrollbar.Direction direction = (Scrollbar.Direction)m_Direction.enumValueIndex;
foreach (var obj in serializedObject.targetObjects)
{
Scrollbar scrollbar = obj as Scrollbar;
scrollbar.SetDirection(direction, true);
}
}
EditorGUILayout.PropertyField(m_Value);
EditorGUILayout.PropertyField(m_Size);
EditorGUILayout.PropertyField(m_NumberOfSteps);
bool warning = false;
foreach (var obj in serializedObject.targetObjects)
{
Scrollbar scrollbar = obj as Scrollbar;
Scrollbar.Direction dir = scrollbar.direction;
if (dir == Scrollbar.Direction.LeftToRight || dir == Scrollbar.Direction.RightToLeft)
warning = (scrollbar.navigation.mode != Navigation.Mode.Automatic && (scrollbar.FindSelectableOnLeft() != null || scrollbar.FindSelectableOnRight() != null));
else
warning = (scrollbar.navigation.mode != Navigation.Mode.Automatic && (scrollbar.FindSelectableOnDown() != null || scrollbar.FindSelectableOnUp() != null));
}
if (warning)
EditorGUILayout.HelpBox("The selected scrollbar direction conflicts with navigation. Not all navigation options may work.", MessageType.Warning);
EditorGUILayout.Space();
// Draw the event notification options
EditorGUILayout.PropertyField(m_OnValueChanged);
}
else
{
EditorGUILayout.HelpBox("Specify a RectTransform for the scrollbar handle. It must have a parent RectTransform that the handle can slide within.", MessageType.Info);
}
serializedObject.ApplyModifiedProperties();
}
}
}

View file

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

View file

@ -0,0 +1,380 @@
using System.Collections.Generic;
using System.Text;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor.AnimatedValues;
namespace UnityEditor.UI
{
[CustomEditor(typeof(Selectable), true)]
/// <summary>
/// Custom Editor for the Selectable Component.
/// Extend this class to write a custom editor for a component derived from Selectable.
/// </summary>
public class SelectableEditor : Editor
{
SerializedProperty m_Script;
SerializedProperty m_InteractableProperty;
SerializedProperty m_TargetGraphicProperty;
SerializedProperty m_TransitionProperty;
SerializedProperty m_ColorBlockProperty;
SerializedProperty m_SpriteStateProperty;
SerializedProperty m_AnimTriggerProperty;
SerializedProperty m_NavigationProperty;
GUIContent m_VisualizeNavigation = EditorGUIUtility.TrTextContent("Visualize", "Show navigation flows between selectable UI elements.");
AnimBool m_ShowColorTint = new AnimBool();
AnimBool m_ShowSpriteTrasition = new AnimBool();
AnimBool m_ShowAnimTransition = new AnimBool();
private static List<SelectableEditor> s_Editors = new List<SelectableEditor>();
private static bool s_ShowNavigation = false;
private static string s_ShowNavigationKey = "SelectableEditor.ShowNavigation";
// Whenever adding new SerializedProperties to the Selectable and SelectableEditor
// Also update this guy in OnEnable. This makes the inherited classes from Selectable not require a CustomEditor.
private string[] m_PropertyPathToExcludeForChildClasses;
protected virtual void OnEnable()
{
m_Script = serializedObject.FindProperty("m_Script");
m_InteractableProperty = serializedObject.FindProperty("m_Interactable");
m_TargetGraphicProperty = serializedObject.FindProperty("m_TargetGraphic");
m_TransitionProperty = serializedObject.FindProperty("m_Transition");
m_ColorBlockProperty = serializedObject.FindProperty("m_Colors");
m_SpriteStateProperty = serializedObject.FindProperty("m_SpriteState");
m_AnimTriggerProperty = serializedObject.FindProperty("m_AnimationTriggers");
m_NavigationProperty = serializedObject.FindProperty("m_Navigation");
m_PropertyPathToExcludeForChildClasses = new[]
{
m_Script.propertyPath,
m_NavigationProperty.propertyPath,
m_TransitionProperty.propertyPath,
m_ColorBlockProperty.propertyPath,
m_SpriteStateProperty.propertyPath,
m_AnimTriggerProperty.propertyPath,
m_InteractableProperty.propertyPath,
m_TargetGraphicProperty.propertyPath,
};
var trans = GetTransition(m_TransitionProperty);
m_ShowColorTint.value = (trans == Selectable.Transition.ColorTint);
m_ShowSpriteTrasition.value = (trans == Selectable.Transition.SpriteSwap);
m_ShowAnimTransition.value = (trans == Selectable.Transition.Animation);
m_ShowColorTint.valueChanged.AddListener(Repaint);
m_ShowSpriteTrasition.valueChanged.AddListener(Repaint);
s_Editors.Add(this);
RegisterStaticOnSceneGUI();
s_ShowNavigation = EditorPrefs.GetBool(s_ShowNavigationKey);
}
protected virtual void OnDisable()
{
m_ShowColorTint.valueChanged.RemoveListener(Repaint);
m_ShowSpriteTrasition.valueChanged.RemoveListener(Repaint);
s_Editors.Remove(this);
RegisterStaticOnSceneGUI();
}
private void RegisterStaticOnSceneGUI()
{
SceneView.duringSceneGui -= StaticOnSceneGUI;
if (s_Editors.Count > 0)
SceneView.duringSceneGui += StaticOnSceneGUI;
}
static Selectable.Transition GetTransition(SerializedProperty transition)
{
return (Selectable.Transition)transition.enumValueIndex;
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(m_InteractableProperty);
var trans = GetTransition(m_TransitionProperty);
var graphic = m_TargetGraphicProperty.objectReferenceValue as Graphic;
if (graphic == null)
graphic = (target as Selectable).GetComponent<Graphic>();
var animator = (target as Selectable).GetComponent<Animator>();
m_ShowColorTint.target = (!m_TransitionProperty.hasMultipleDifferentValues && trans == Button.Transition.ColorTint);
m_ShowSpriteTrasition.target = (!m_TransitionProperty.hasMultipleDifferentValues && trans == Button.Transition.SpriteSwap);
m_ShowAnimTransition.target = (!m_TransitionProperty.hasMultipleDifferentValues && trans == Button.Transition.Animation);
EditorGUILayout.PropertyField(m_TransitionProperty);
++EditorGUI.indentLevel;
{
if (trans == Selectable.Transition.ColorTint || trans == Selectable.Transition.SpriteSwap)
{
EditorGUILayout.PropertyField(m_TargetGraphicProperty);
}
switch (trans)
{
case Selectable.Transition.ColorTint:
if (graphic == null)
EditorGUILayout.HelpBox("You must have a Graphic target in order to use a color transition.", MessageType.Warning);
break;
case Selectable.Transition.SpriteSwap:
if (graphic as Image == null)
EditorGUILayout.HelpBox("You must have a Image target in order to use a sprite swap transition.", MessageType.Warning);
break;
}
if (EditorGUILayout.BeginFadeGroup(m_ShowColorTint.faded))
{
EditorGUILayout.PropertyField(m_ColorBlockProperty);
}
EditorGUILayout.EndFadeGroup();
if (EditorGUILayout.BeginFadeGroup(m_ShowSpriteTrasition.faded))
{
EditorGUILayout.PropertyField(m_SpriteStateProperty);
}
EditorGUILayout.EndFadeGroup();
if (EditorGUILayout.BeginFadeGroup(m_ShowAnimTransition.faded))
{
EditorGUILayout.PropertyField(m_AnimTriggerProperty);
if (animator == null || animator.runtimeAnimatorController == null)
{
Rect buttonRect = EditorGUILayout.GetControlRect();
buttonRect.xMin += EditorGUIUtility.labelWidth;
if (GUI.Button(buttonRect, "Auto Generate Animation", EditorStyles.miniButton))
{
var controller = GenerateSelectableAnimatorContoller((target as Selectable).animationTriggers, target as Selectable);
if (controller != null)
{
if (animator == null)
animator = (target as Selectable).gameObject.AddComponent<Animator>();
Animations.AnimatorController.SetAnimatorController(animator, controller);
}
}
}
}
EditorGUILayout.EndFadeGroup();
}
--EditorGUI.indentLevel;
EditorGUILayout.Space();
EditorGUILayout.PropertyField(m_NavigationProperty);
EditorGUI.BeginChangeCheck();
Rect toggleRect = EditorGUILayout.GetControlRect();
toggleRect.xMin += EditorGUIUtility.labelWidth;
s_ShowNavigation = GUI.Toggle(toggleRect, s_ShowNavigation, m_VisualizeNavigation, EditorStyles.miniButton);
if (EditorGUI.EndChangeCheck())
{
EditorPrefs.SetBool(s_ShowNavigationKey, s_ShowNavigation);
SceneView.RepaintAll();
}
// We do this here to avoid requiring the user to also write a Editor for their Selectable-derived classes.
// This way if we are on a derived class we dont draw anything else, otherwise draw the remaining properties.
ChildClassPropertiesGUI();
serializedObject.ApplyModifiedProperties();
}
// Draw the extra SerializedProperties of the child class.
// We need to make sure that m_PropertyPathToExcludeForChildClasses has all the Selectable properties and in the correct order.
// TODO: find a nicer way of doing this. (creating a InheritedEditor class that automagically does this)
private void ChildClassPropertiesGUI()
{
if (IsDerivedSelectableEditor())
return;
DrawPropertiesExcluding(serializedObject, m_PropertyPathToExcludeForChildClasses);
}
private bool IsDerivedSelectableEditor()
{
return GetType() != typeof(SelectableEditor);
}
private static Animations.AnimatorController GenerateSelectableAnimatorContoller(AnimationTriggers animationTriggers, Selectable target)
{
if (target == null)
return null;
// Where should we create the controller?
var path = GetSaveControllerPath(target);
if (string.IsNullOrEmpty(path))
return null;
// figure out clip names
var normalName = string.IsNullOrEmpty(animationTriggers.normalTrigger) ? "Normal" : animationTriggers.normalTrigger;
var highlightedName = string.IsNullOrEmpty(animationTriggers.highlightedTrigger) ? "Highlighted" : animationTriggers.highlightedTrigger;
var pressedName = string.IsNullOrEmpty(animationTriggers.pressedTrigger) ? "Pressed" : animationTriggers.pressedTrigger;
var selectedName = string.IsNullOrEmpty(animationTriggers.selectedTrigger) ? "Selected" : animationTriggers.selectedTrigger;
var disabledName = string.IsNullOrEmpty(animationTriggers.disabledTrigger) ? "Disabled" : animationTriggers.disabledTrigger;
// Create controller and hook up transitions.
var controller = Animations.AnimatorController.CreateAnimatorControllerAtPath(path);
GenerateTriggerableTransition(normalName, controller);
GenerateTriggerableTransition(highlightedName, controller);
GenerateTriggerableTransition(pressedName, controller);
GenerateTriggerableTransition(selectedName, controller);
GenerateTriggerableTransition(disabledName, controller);
AssetDatabase.ImportAsset(path);
return controller;
}
private static string GetSaveControllerPath(Selectable target)
{
var defaultName = target.gameObject.name;
var message = string.Format("Create a new animator for the game object '{0}':", defaultName);
return EditorUtility.SaveFilePanelInProject("New Animation Contoller", defaultName, "controller", message);
}
private static void SetUpCurves(AnimationClip highlightedClip, AnimationClip pressedClip, string animationPath)
{
string[] channels = { "m_LocalScale.x", "m_LocalScale.y", "m_LocalScale.z" };
var highlightedKeys = new[] { new Keyframe(0f, 1f), new Keyframe(0.5f, 1.1f), new Keyframe(1f, 1f) };
var highlightedCurve = new AnimationCurve(highlightedKeys);
foreach (var channel in channels)
AnimationUtility.SetEditorCurve(highlightedClip, EditorCurveBinding.FloatCurve(animationPath, typeof(Transform), channel), highlightedCurve);
var pressedKeys = new[] { new Keyframe(0f, 1.15f) };
var pressedCurve = new AnimationCurve(pressedKeys);
foreach (var channel in channels)
AnimationUtility.SetEditorCurve(pressedClip, EditorCurveBinding.FloatCurve(animationPath, typeof(Transform), channel), pressedCurve);
}
private static string BuildAnimationPath(Selectable target)
{
// if no target don't hook up any curves.
var highlight = target.targetGraphic;
if (highlight == null)
return string.Empty;
var startGo = highlight.gameObject;
var toFindGo = target.gameObject;
var pathComponents = new Stack<string>();
while (toFindGo != startGo)
{
pathComponents.Push(startGo.name);
// didn't exist in hierarchy!
if (startGo.transform.parent == null)
return string.Empty;
startGo = startGo.transform.parent.gameObject;
}
// calculate path
var animPath = new StringBuilder();
if (pathComponents.Count > 0)
animPath.Append(pathComponents.Pop());
while (pathComponents.Count > 0)
animPath.Append("/").Append(pathComponents.Pop());
return animPath.ToString();
}
private static AnimationClip GenerateTriggerableTransition(string name, Animations.AnimatorController controller)
{
// Create the clip
var clip = Animations.AnimatorController.AllocateAnimatorClip(name);
AssetDatabase.AddObjectToAsset(clip, controller);
// Create a state in the animatior controller for this clip
var state = controller.AddMotion(clip);
// Add a transition property
controller.AddParameter(name, AnimatorControllerParameterType.Trigger);
// Add an any state transition
var stateMachine = controller.layers[0].stateMachine;
var transition = stateMachine.AddAnyStateTransition(state);
transition.AddCondition(Animations.AnimatorConditionMode.If, 0, name);
return clip;
}
private static void StaticOnSceneGUI(SceneView view)
{
if (!s_ShowNavigation)
return;
Selectable[] selectables = Selectable.allSelectablesArray;
for (int i = 0; i < selectables.Length; i++)
{
Selectable s = selectables[i];
if (SceneManagement.StageUtility.IsGameObjectRenderedByCamera(s.gameObject, Camera.current))
DrawNavigationForSelectable(s);
}
}
private static void DrawNavigationForSelectable(Selectable sel)
{
if (sel == null)
return;
Transform transform = sel.transform;
bool active = Selection.transforms.Any(e => e == transform);
Handles.color = new Color(1.0f, 0.9f, 0.1f, active ? 1.0f : 0.4f);
DrawNavigationArrow(-Vector2.right, sel, sel.FindSelectableOnLeft());
DrawNavigationArrow(Vector2.right, sel, sel.FindSelectableOnRight());
DrawNavigationArrow(Vector2.up, sel, sel.FindSelectableOnUp());
DrawNavigationArrow(-Vector2.up, sel, sel.FindSelectableOnDown());
}
const float kArrowThickness = 2.5f;
const float kArrowHeadSize = 1.2f;
private static void DrawNavigationArrow(Vector2 direction, Selectable fromObj, Selectable toObj)
{
if (fromObj == null || toObj == null)
return;
Transform fromTransform = fromObj.transform;
Transform toTransform = toObj.transform;
Vector2 sideDir = new Vector2(direction.y, -direction.x);
Vector3 fromPoint = fromTransform.TransformPoint(GetPointOnRectEdge(fromTransform as RectTransform, direction));
Vector3 toPoint = toTransform.TransformPoint(GetPointOnRectEdge(toTransform as RectTransform, -direction));
float fromSize = HandleUtility.GetHandleSize(fromPoint) * 0.05f;
float toSize = HandleUtility.GetHandleSize(toPoint) * 0.05f;
fromPoint += fromTransform.TransformDirection(sideDir) * fromSize;
toPoint += toTransform.TransformDirection(sideDir) * toSize;
float length = Vector3.Distance(fromPoint, toPoint);
Vector3 fromTangent = fromTransform.rotation * direction * length * 0.3f;
Vector3 toTangent = toTransform.rotation * -direction * length * 0.3f;
Handles.DrawBezier(fromPoint, toPoint, fromPoint + fromTangent, toPoint + toTangent, Handles.color, null, kArrowThickness);
Handles.DrawAAPolyLine(kArrowThickness, toPoint, toPoint + toTransform.rotation * (-direction - sideDir) * toSize * kArrowHeadSize);
Handles.DrawAAPolyLine(kArrowThickness, toPoint, toPoint + toTransform.rotation * (-direction + sideDir) * toSize * kArrowHeadSize);
}
private static Vector3 GetPointOnRectEdge(RectTransform rect, Vector2 dir)
{
if (rect == null)
return Vector3.zero;
if (dir != Vector2.zero)
dir /= Mathf.Max(Mathf.Abs(dir.x), Mathf.Abs(dir.y));
dir = rect.rect.center + Vector2.Scale(rect.rect.size, dir * 0.5f);
return dir;
}
}
}

View file

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

View file

@ -0,0 +1,38 @@
using UnityEngine;
using UnityEngine.UI;
namespace UnityEditor.UI
{
/// <summary>
/// Base class for custom editors that are for components that implement the SelfControllerEditor interface.
/// </summary>
public class SelfControllerEditor : Editor
{
static string s_Warning = "Parent has a type of layout group component. A child of a layout group should not have a {0} component, since it should be driven by the layout group.";
public override void OnInspectorGUI()
{
bool anyHaveLayoutParent = false;
for (int i = 0; i < targets.Length; i++)
{
Component comp = (targets[i] as Component);
ILayoutIgnorer ignorer = comp.GetComponent(typeof(ILayoutIgnorer)) as ILayoutIgnorer;
if (ignorer != null && ignorer.ignoreLayout)
continue;
RectTransform parent = comp.transform.parent as RectTransform;
if (parent != null)
{
Behaviour layoutGroup = parent.GetComponent(typeof(ILayoutGroup)) as Behaviour;
if (layoutGroup != null && layoutGroup.enabled)
{
anyHaveLayoutParent = true;
break;
}
}
}
if (anyHaveLayoutParent)
EditorGUILayout.HelpBox(string.Format(s_Warning, ObjectNames.NicifyVariableName(target.GetType().Name)), MessageType.Warning);
}
}
}

View file

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

View file

@ -0,0 +1,105 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace UnityEditor.UI
{
[CustomEditor(typeof(Slider), true)]
[CanEditMultipleObjects]
/// <summary>
/// Custom Editor for the Slider Component.
/// Extend this class to write a custom editor for a component derived from Slider.
/// </summary>
public class SliderEditor : SelectableEditor
{
SerializedProperty m_Direction;
SerializedProperty m_FillRect;
SerializedProperty m_HandleRect;
SerializedProperty m_MinValue;
SerializedProperty m_MaxValue;
SerializedProperty m_WholeNumbers;
SerializedProperty m_Value;
SerializedProperty m_OnValueChanged;
protected override void OnEnable()
{
base.OnEnable();
m_FillRect = serializedObject.FindProperty("m_FillRect");
m_HandleRect = serializedObject.FindProperty("m_HandleRect");
m_Direction = serializedObject.FindProperty("m_Direction");
m_MinValue = serializedObject.FindProperty("m_MinValue");
m_MaxValue = serializedObject.FindProperty("m_MaxValue");
m_WholeNumbers = serializedObject.FindProperty("m_WholeNumbers");
m_Value = serializedObject.FindProperty("m_Value");
m_OnValueChanged = serializedObject.FindProperty("m_OnValueChanged");
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
EditorGUILayout.Space();
serializedObject.Update();
EditorGUILayout.PropertyField(m_FillRect);
EditorGUILayout.PropertyField(m_HandleRect);
if (m_FillRect.objectReferenceValue != null || m_HandleRect.objectReferenceValue != null)
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_Direction);
if (EditorGUI.EndChangeCheck())
{
Slider.Direction direction = (Slider.Direction)m_Direction.enumValueIndex;
foreach (var obj in serializedObject.targetObjects)
{
Slider slider = obj as Slider;
slider.SetDirection(direction, true);
}
}
EditorGUI.BeginChangeCheck();
float newMin = EditorGUILayout.FloatField("Min Value", m_MinValue.floatValue);
if (EditorGUI.EndChangeCheck() && newMin <= m_MaxValue.floatValue)
{
m_MinValue.floatValue = newMin;
}
EditorGUI.BeginChangeCheck();
float newMax = EditorGUILayout.FloatField("Max Value", m_MaxValue.floatValue);
if (EditorGUI.EndChangeCheck() && newMax >= m_MinValue.floatValue)
{
m_MaxValue.floatValue = newMax;
}
EditorGUILayout.PropertyField(m_WholeNumbers);
EditorGUILayout.Slider(m_Value, m_MinValue.floatValue, m_MaxValue.floatValue);
bool warning = false;
foreach (var obj in serializedObject.targetObjects)
{
Slider slider = obj as Slider;
Slider.Direction dir = slider.direction;
if (dir == Slider.Direction.LeftToRight || dir == Slider.Direction.RightToLeft)
warning = (slider.navigation.mode != Navigation.Mode.Automatic && (slider.FindSelectableOnLeft() != null || slider.FindSelectableOnRight() != null));
else
warning = (slider.navigation.mode != Navigation.Mode.Automatic && (slider.FindSelectableOnDown() != null || slider.FindSelectableOnUp() != null));
}
if (warning)
EditorGUILayout.HelpBox("The selected slider direction conflicts with navigation. Not all navigation options may work.", MessageType.Warning);
// Draw the event notification options
EditorGUILayout.Space();
EditorGUILayout.PropertyField(m_OnValueChanged);
}
else
{
EditorGUILayout.HelpBox("Specify a RectTransform for the slider fill or the slider handle or both. Each must have a parent RectTransform that it can slide within.", MessageType.Info);
}
serializedObject.ApplyModifiedProperties();
}
}
}

View file

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

View file

@ -0,0 +1,201 @@
using System.Collections.Generic;
using UnityEngine;
namespace UnityEditor.UI
{
/// <summary>
/// PropertyDrawer for [[SpriteState]].
/// This is a PropertyDrawer for SpriteState it is implemented using the standard unity PropertyDrawer framework.
/// </summary>
internal class SpriteDrawUtility
{
static Texture2D s_ContrastTex;
// Returns a usable texture that looks like a high-contrast checker board.
static Texture2D contrastTexture
{
get
{
if (s_ContrastTex == null)
s_ContrastTex = CreateCheckerTex(
new Color(0f, 0.0f, 0f, 0.5f),
new Color(1f, 1f, 1f, 0.5f));
return s_ContrastTex;
}
}
// Create a checker-background texture.
static Texture2D CreateCheckerTex(Color c0, Color c1)
{
Texture2D tex = new Texture2D(16, 16);
tex.name = "[Generated] Checker Texture";
tex.hideFlags = HideFlags.DontSave;
for (int y = 0; y < 8; ++y) for (int x = 0; x < 8; ++x) tex.SetPixel(x, y, c1);
for (int y = 8; y < 16; ++y) for (int x = 0; x < 8; ++x) tex.SetPixel(x, y, c0);
for (int y = 0; y < 8; ++y) for (int x = 8; x < 16; ++x) tex.SetPixel(x, y, c0);
for (int y = 8; y < 16; ++y) for (int x = 8; x < 16; ++x) tex.SetPixel(x, y, c1);
tex.Apply();
tex.filterMode = FilterMode.Point;
return tex;
}
// Create a gradient texture.
static Texture2D CreateGradientTex()
{
Texture2D tex = new Texture2D(1, 16);
tex.name = "[Generated] Gradient Texture";
tex.hideFlags = HideFlags.DontSave;
Color c0 = new Color(1f, 1f, 1f, 0f);
Color c1 = new Color(1f, 1f, 1f, 0.4f);
for (int i = 0; i < 16; ++i)
{
float f = Mathf.Abs((i / 15f) * 2f - 1f);
f *= f;
tex.SetPixel(0, i, Color.Lerp(c0, c1, f));
}
tex.Apply();
tex.filterMode = FilterMode.Bilinear;
return tex;
}
// Draws the tiled texture. Like GUI.DrawTexture() but tiled instead of stretched.
static void DrawTiledTexture(Rect rect, Texture tex)
{
float u = rect.width / tex.width;
float v = rect.height / tex.height;
Rect texCoords = new Rect(0, 0, u, v);
TextureWrapMode originalMode = tex.wrapMode;
tex.wrapMode = TextureWrapMode.Repeat;
GUI.DrawTextureWithTexCoords(rect, tex, texCoords);
tex.wrapMode = originalMode;
}
// Draw the specified Image.
public static void DrawSprite(Sprite sprite, Rect drawArea, Color color)
{
if (sprite == null)
return;
Texture2D tex = sprite.texture;
if (tex == null)
return;
Rect outer = sprite.rect;
Rect inner = outer;
inner.xMin += sprite.border.x;
inner.yMin += sprite.border.y;
inner.xMax -= sprite.border.z;
inner.yMax -= sprite.border.w;
Vector4 uv4 = UnityEngine.Sprites.DataUtility.GetOuterUV(sprite);
Rect uv = new Rect(uv4.x, uv4.y, uv4.z - uv4.x, uv4.w - uv4.y);
Vector4 padding = UnityEngine.Sprites.DataUtility.GetPadding(sprite);
padding.x /= outer.width;
padding.y /= outer.height;
padding.z /= outer.width;
padding.w /= outer.height;
DrawSprite(tex, drawArea, padding, outer, inner, uv, color, null);
}
// Draw the specified Image.
public static void DrawSprite(Texture tex, Rect drawArea, Rect outer, Rect uv, Color color)
{
DrawSprite(tex, drawArea, Vector4.zero, outer, outer, uv, color, null);
}
// Draw the specified Image.
private static void DrawSprite(Texture tex, Rect drawArea, Vector4 padding, Rect outer, Rect inner, Rect uv, Color color, Material mat)
{
// Create the texture rectangle that is centered inside rect.
Rect outerRect = drawArea;
outerRect.width = Mathf.Abs(outer.width);
outerRect.height = Mathf.Abs(outer.height);
if (outerRect.width > 0f)
{
float f = drawArea.width / outerRect.width;
outerRect.width *= f;
outerRect.height *= f;
}
if (drawArea.height > outerRect.height)
{
outerRect.y += (drawArea.height - outerRect.height) * 0.5f;
}
else if (outerRect.height > drawArea.height)
{
float f = drawArea.height / outerRect.height;
outerRect.width *= f;
outerRect.height *= f;
}
if (drawArea.width > outerRect.width)
outerRect.x += (drawArea.width - outerRect.width) * 0.5f;
// Draw the background
EditorGUI.DrawTextureTransparent(outerRect, null, ScaleMode.ScaleToFit, outer.width / outer.height);
// Draw the Image
GUI.color = color;
Rect paddedTexArea = new Rect(
outerRect.x + outerRect.width * padding.x,
outerRect.y + outerRect.height * padding.w,
outerRect.width - (outerRect.width * (padding.z + padding.x)),
outerRect.height - (outerRect.height * (padding.w + padding.y))
);
if (mat == null)
{
GUI.DrawTextureWithTexCoords(paddedTexArea, tex, uv, true);
}
else
{
// NOTE: There is an issue in Unity that prevents it from clipping the drawn preview
// using BeginGroup/EndGroup, and there is no way to specify a UV rect...
EditorGUI.DrawPreviewTexture(paddedTexArea, tex, mat);
}
// Draw the border indicator lines
GUI.BeginGroup(outerRect);
{
tex = contrastTexture;
GUI.color = Color.white;
if (inner.xMin != outer.xMin)
{
float x = (inner.xMin - outer.xMin) / outer.width * outerRect.width - 1;
DrawTiledTexture(new Rect(x, 0f, 1f, outerRect.height), tex);
}
if (inner.xMax != outer.xMax)
{
float x = (inner.xMax - outer.xMin) / outer.width * outerRect.width - 1;
DrawTiledTexture(new Rect(x, 0f, 1f, outerRect.height), tex);
}
if (inner.yMin != outer.yMin)
{
// GUI.DrawTexture is top-left based rather than bottom-left
float y = (inner.yMin - outer.yMin) / outer.height * outerRect.height - 1;
DrawTiledTexture(new Rect(0f, outerRect.height - y, outerRect.width, 1f), tex);
}
if (inner.yMax != outer.yMax)
{
float y = (inner.yMax - outer.yMin) / outer.height * outerRect.height - 1;
DrawTiledTexture(new Rect(0f, outerRect.height - y, outerRect.width, 1f), tex);
}
}
GUI.EndGroup();
}
}
}

View file

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

View file

@ -0,0 +1,37 @@
using UnityEngine;
using UnityEngine.UI;
namespace UnityEditor.UI
{
[CustomEditor(typeof(Text), true)]
[CanEditMultipleObjects]
/// <summary>
/// Custom Editor for the Text Component.
/// Extend this class to write a custom editor for a component derived from Text.
/// </summary>
public class TextEditor : GraphicEditor
{
SerializedProperty m_Text;
SerializedProperty m_FontData;
protected override void OnEnable()
{
base.OnEnable();
m_Text = serializedObject.FindProperty("m_Text");
m_FontData = serializedObject.FindProperty("m_FontData");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.PropertyField(m_Text);
EditorGUILayout.PropertyField(m_FontData);
AppearanceControlsGUI();
RaycastControlsGUI();
MaskableControlsGUI();
serializedObject.ApplyModifiedProperties();
}
}
}

View file

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

View file

@ -0,0 +1,76 @@
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.UI;
namespace UnityEditor.UI
{
[CustomEditor(typeof(Toggle), true)]
[CanEditMultipleObjects]
/// <summary>
/// Custom Editor for the Toggle Component.
/// Extend this class to write a custom editor for a component derived from Toggle.
/// </summary>
public class ToggleEditor : SelectableEditor
{
SerializedProperty m_OnValueChangedProperty;
SerializedProperty m_TransitionProperty;
SerializedProperty m_GraphicProperty;
SerializedProperty m_GroupProperty;
SerializedProperty m_IsOnProperty;
protected override void OnEnable()
{
base.OnEnable();
m_TransitionProperty = serializedObject.FindProperty("toggleTransition");
m_GraphicProperty = serializedObject.FindProperty("graphic");
m_GroupProperty = serializedObject.FindProperty("m_Group");
m_IsOnProperty = serializedObject.FindProperty("m_IsOn");
m_OnValueChangedProperty = serializedObject.FindProperty("onValueChanged");
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
EditorGUILayout.Space();
serializedObject.Update();
Toggle toggle = serializedObject.targetObject as Toggle;
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_IsOnProperty);
if (EditorGUI.EndChangeCheck())
{
EditorSceneManager.MarkSceneDirty(toggle.gameObject.scene);
ToggleGroup group = m_GroupProperty.objectReferenceValue as ToggleGroup;
toggle.isOn = m_IsOnProperty.boolValue;
if (group != null && toggle.IsActive())
{
if (toggle.isOn || (!group.AnyTogglesOn() && !group.allowSwitchOff))
{
toggle.isOn = true;
group.NotifyToggleOn(toggle);
}
}
}
EditorGUILayout.PropertyField(m_TransitionProperty);
EditorGUILayout.PropertyField(m_GraphicProperty);
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(m_GroupProperty);
if (EditorGUI.EndChangeCheck())
{
EditorSceneManager.MarkSceneDirty(toggle.gameObject.scene);
ToggleGroup group = m_GroupProperty.objectReferenceValue as ToggleGroup;
toggle.group = group;
}
EditorGUILayout.Space();
// Draw the event notification options
EditorGUILayout.PropertyField(m_OnValueChangedProperty);
serializedObject.ApplyModifiedProperties();
}
}
}

View file

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

View file

@ -0,0 +1,28 @@
{
"name": "UnityEditor.UI",
"references": [
"UnityEngine.UI"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"versionDefines": [
{
"name": "com.unity.modules.physics",
"expression": "1.0.0",
"define": "PACKAGE_PHYSICS"
},
{
"name": "com.unity.modules.physics2d",
"expression": "1.0.0",
"define": "PACKAGE_PHYSICS2D"
},
{
"name": "com.unity.modules.animation",
"expression": "1.0.0",
"define": "PACKAGE_ANIMATION"
}
]
}

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 343deaaf83e0cee4ca978e7df0b80d21
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,31 @@
**Unity Companion Package License v1.0 ("_License_")**
Copyright © 2019 Unity Technologies ApS ("**_Unity_**")
Unity hereby grants to you a worldwide, non-exclusive, no-charge, and royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute the software that is made available with this License ("**_Software_**"), subject to the following terms and conditions:
1. *Unity Companion Use Only*. Exercise of the license granted herein is limited to exercise for the creation, use, and/or distribution of applications, software, or other content pursuant to a valid Unity development engine software license ("**_Engine License_**"). That means while use of the Software is not limited to use in the software licensed under the Engine License, the Software may not be used for any purpose other than the creation, use, and/or distribution of Engine License-dependent applications, software, or other content. No other exercise of the license granted herein is permitted.
1. *No Modification of Engine License*. Neither this License nor any exercise of the license granted herein modifies the Engine License in any way.
1. *Ownership & Grant Back to You*.
3.1. You own your content. In this License, "derivative works" means derivatives of the Software itself--works derived only from the Software by you under this License (for example, modifying the code of the Software itself to improve its efficacy); “derivative works” of the Software do not include, for example, games, apps, or content that you create using the Software. You keep all right, title, and interest to your own content.
3.2. Unity owns its content. While you keep all right, title, and interest to your own content per the above, as between Unity and you, Unity will own all right, title, and interest to all intellectual property rights (including patent, trademark, and copyright) in the Software and derivative works of the Software, and you hereby assign and agree to assign all such rights in those derivative works to Unity.
3.3. You have a license to those derivative works. Subject to this License, Unity grants to you the same worldwide, non-exclusive, no-charge, and royalty-free copyright license to derivative works of the Software you create as is granted to you for the Software under this License.
1. *Trademarks*. You are not granted any right or license under this License to use any trademarks, service marks, trade names, products names, or branding of Unity or its affiliates ("**_Trademarks_**"). Descriptive uses of Trademarks are permitted; see, for example, Unitys Branding Usage Guidelines at [https://unity3d.com/public-relations/brand](https://unity3d.com/public-relations/brand).
1. *Notices & Third-Party Rights*. This License, including the copyright notice above, must be provided in all substantial portions of the Software and derivative works thereof (or, if that is impracticable, in any other location where such notices are customarily placed). Further, if the Software is accompanied by a Unity "third-party notices" or similar file, you acknowledge and agree that software identified in that file is governed by those separate license terms.
1. *DISCLAIMER, LIMITATION OF LIABILITY*. THE SOFTWARE AND ANY DERIVATIVE WORKS THEREOF IS PROVIDED ON AN "AS IS" BASIS, AND IS PROVIDED WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR NONINFRINGEMENT. IN NO EVENT SHALL ANY COPYRIGHT HOLDER OR AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES (WHETHER DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL, INCLUDING PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF USE, DATA, OR PROFITS, AND BUSINESS INTERRUPTION), OR OTHER LIABILITY WHATSOEVER, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM OR OUT OF, OR IN CONNECTION WITH, THE SOFTWARE OR ANY DERIVATIVE WORKS THEREOF OR THE USE OF OR OTHER DEALINGS IN SAME, EVEN WHERE ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1. *USE IS ACCEPTANCE and License Versions*. Your receipt and use of the Software constitutes your acceptance of this License and its terms and conditions. Software released by Unity under this License may be modified or updated and the License with it; upon any such modification or update, you will comply with the terms of the updated License for any use of any of the Software under the updated License.
1. *Use in Compliance with Law and Termination*. Your exercise of the license granted herein will at all times be in compliance with applicable law and will not infringe any proprietary rights (including intellectual property rights); this License will terminate immediately on any breach by you of this License.
1. *Severability*. If any provision of this License is held to be unenforceable or invalid, that provision will be enforced to the maximum extent possible and the other provisions will remain in full force and effect.
1. *Governing Law and Venue*. This License is governed by and construed in accordance with the laws of Denmark, except for its conflict of laws rules; the United Nations Convention on Contracts for the International Sale of Goods will not apply. If you reside (or your principal place of business is) within the United States, you and Unity agree to submit to the personal and exclusive jurisdiction of and venue in the state and federal courts located in San Francisco County, California concerning any dispute arising out of this License ("**_Dispute_**"). If you reside (or your principal place of business is) outside the United States, you and Unity agree to submit to the personal and exclusive jurisdiction of and venue in the courts located in Copenhagen, Denmark concerning any Dispute.

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 4d3d51749e989f747b2674e0b4d9b3d7
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,9 @@
# Unity UI
The Unity UI package allows you to create in-game user interfaces fast and intuitively.
## Prerequisites
### Unity 2019.2
This package is in development, and requires Unity 2019.2.
## Getting Started
The Unity UI user manual can be found [here](https://docs.unity3d.com/Manual/UISystem.html).

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e0ae6629cc70b514889df37fccb76832
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

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

View file

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

View file

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

View file

@ -0,0 +1,25 @@
namespace UnityEngine.EventSystems
{
/// <summary>
/// Event Data associated with Axis Events (Controller / Keyboard).
/// </summary>
public class AxisEventData : BaseEventData
{
/// <summary>
/// Raw input vector associated with this event.
/// </summary>
public Vector2 moveVector { get; set; }
/// <summary>
/// MoveDirection for this event.
/// </summary>
public MoveDirection moveDir { get; set; }
public AxisEventData(EventSystem eventSystem)
: base(eventSystem)
{
moveVector = Vector2.zero;
moveDir = MoveDirection.None;
}
}
}

View file

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

View file

@ -0,0 +1,66 @@
namespace UnityEngine.EventSystems
{
/// <summary>
/// A class that can be used for sending simple events via the event system.
/// </summary>
public abstract class AbstractEventData
{
protected bool m_Used;
/// <summary>
/// Reset the event.
/// </summary>
public virtual void Reset()
{
m_Used = false;
}
/// <summary>
/// Use the event.
/// </summary>
/// <remarks>
/// Internally sets a flag that can be checked via used to see if further processing should happen.
/// </remarks>
public virtual void Use()
{
m_Used = true;
}
/// <summary>
/// Is the event used?
/// </summary>
public virtual bool used
{
get { return m_Used; }
}
}
/// <summary>
/// A class that contains the base event data that is common to all event types in the new EventSystem.
/// </summary>
public class BaseEventData : AbstractEventData
{
private readonly EventSystem m_EventSystem;
public BaseEventData(EventSystem eventSystem)
{
m_EventSystem = eventSystem;
}
/// <summary>
/// >A reference to the BaseInputModule that sent this event.
/// </summary>
public BaseInputModule currentInputModule
{
get { return m_EventSystem.currentInputModule; }
}
/// <summary>
/// The object currently considered selected by the EventSystem.
/// </summary>
public GameObject selectedObject
{
get { return m_EventSystem.currentSelectedGameObject; }
set { m_EventSystem.SetSelectedGameObject(value, this); }
}
}
}

View file

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

View file

@ -0,0 +1,267 @@
using System;
using System.Text;
using System.Collections.Generic;
namespace UnityEngine.EventSystems
{
/// <summary>
/// Each touch event creates one of these containing all the relevant information.
/// </summary>
public class PointerEventData : BaseEventData
{
/// <summary>
/// Input press tracking.
/// </summary>
public enum InputButton
{
/// <summary>
/// Left button
/// </summary>
Left = 0,
/// <summary>
/// Right button.
/// </summary>
Right = 1,
/// <summary>
/// Middle button
/// </summary>
Middle = 2
}
/// <summary>
/// The state of a press for the given frame.
/// </summary>
public enum FramePressState
{
/// <summary>
/// Button was pressed this frame.
/// </summary>
Pressed,
/// <summary>
/// Button was released this frame.
/// </summary>
Released,
/// <summary>
/// Button was pressed and released this frame.
/// </summary>
PressedAndReleased,
/// <summary>
/// Same as last frame.
/// </summary>
NotChanged
}
/// <summary>
/// The object that received 'OnPointerEnter'.
/// </summary>
public GameObject pointerEnter { get; set; }
// The object that received OnPointerDown
private GameObject m_PointerPress;
/// <summary>
/// The raw GameObject for the last press event. This means that it is the 'pressed' GameObject even if it can not receive the press event itself.
/// </summary>
public GameObject lastPress { get; private set; }
/// <summary>
/// The object that the press happened on even if it can not handle the press event.
/// </summary>
public GameObject rawPointerPress { get; set; }
/// <summary>
/// The object that is receiving 'OnDrag'.
/// </summary>
public GameObject pointerDrag { get; set; }
/// <summary>
/// RaycastResult associated with the current event.
/// </summary>
public RaycastResult pointerCurrentRaycast { get; set; }
/// <summary>
/// RaycastResult associated with the pointer press.
/// </summary>
public RaycastResult pointerPressRaycast { get; set; }
public List<GameObject> hovered = new List<GameObject>();
/// <summary>
/// Is it possible to click this frame
/// </summary>
public bool eligibleForClick { get; set; }
/// <summary>
/// Id of the pointer (touch id).
/// </summary>
public int pointerId { get; set; }
/// <summary>
/// Current pointer position.
/// </summary>
public Vector2 position { get; set; }
/// <summary>
/// Pointer delta since last update.
/// </summary>
public Vector2 delta { get; set; }
/// <summary>
/// Position of the press.
/// </summary>
public Vector2 pressPosition { get; set; }
/// <summary>
/// World-space position where a ray cast into the screen hits something
/// </summary>
[Obsolete("Use either pointerCurrentRaycast.worldPosition or pointerPressRaycast.worldPosition")]
public Vector3 worldPosition { get; set; }
/// <summary>
/// World-space normal where a ray cast into the screen hits something
/// </summary>
[Obsolete("Use either pointerCurrentRaycast.worldNormal or pointerPressRaycast.worldNormal")]
public Vector3 worldNormal { get; set; }
/// <summary>
/// The last time a click event was sent. Used for double click
/// </summary>
public float clickTime { get; set; }
/// <summary>
/// Number of clicks in a row.
/// </summary>
/// <example>
/// <code>
/// using UnityEngine;
/// using System.Collections;
/// using UnityEngine.UI;
/// using UnityEngine.EventSystems;// Required when using Event data.
///
/// public class ExampleClass : MonoBehaviour, IPointerDownHandler
/// {
/// public void OnPointerDown(PointerEventData eventData)
/// {
/// //Grab the number of consecutive clicks and assign it to an integer varible.
/// int i = eventData.clickCount;
/// //Display the click count.
/// Debug.Log(i);
/// }
/// }
/// </code>
/// </example>
public int clickCount { get; set; }
/// <summary>
/// The amount of scroll since the last update.
/// </summary>
public Vector2 scrollDelta { get; set; }
/// <summary>
/// Should a drag threshold be used?
/// </summary>
/// <remarks>
/// If you do not want a drag threshold set this to false in IInitializePotentialDragHandler.OnInitializePotentialDrag.
/// </remarks>
public bool useDragThreshold { get; set; }
/// <summary>
/// Is a drag operation currently occuring.
/// </summary>
public bool dragging { get; set; }
/// <summary>
/// The EventSystems.PointerEventData.InputButton for this event.
/// </summary>
public InputButton button { get; set; }
public PointerEventData(EventSystem eventSystem) : base(eventSystem)
{
eligibleForClick = false;
pointerId = -1;
position = Vector2.zero; // Current position of the mouse or touch event
delta = Vector2.zero; // Delta since last update
pressPosition = Vector2.zero; // Delta since the event started being tracked
clickTime = 0.0f; // The last time a click event was sent out (used for double-clicks)
clickCount = 0; // Number of clicks in a row. 2 for a double-click for example.
scrollDelta = Vector2.zero;
useDragThreshold = true;
dragging = false;
button = InputButton.Left;
}
/// <summary>
/// Is the pointer moving.
/// </summary>
public bool IsPointerMoving()
{
return delta.sqrMagnitude > 0.0f;
}
/// <summary>
/// Is scroll being used on the input device.
/// </summary>
public bool IsScrolling()
{
return scrollDelta.sqrMagnitude > 0.0f;
}
/// <summary>
/// The camera associated with the last OnPointerEnter event.
/// </summary>
public Camera enterEventCamera
{
get { return pointerCurrentRaycast.module == null ? null : pointerCurrentRaycast.module.eventCamera; }
}
/// <summary>
/// The camera associated with the last OnPointerPress event.
/// </summary>
public Camera pressEventCamera
{
get { return pointerPressRaycast.module == null ? null : pointerPressRaycast.module.eventCamera; }
}
/// <summary>
/// The GameObject that received the OnPointerDown.
/// </summary>
public GameObject pointerPress
{
get { return m_PointerPress; }
set
{
if (m_PointerPress == value)
return;
lastPress = m_PointerPress;
m_PointerPress = value;
}
}
public override string ToString()
{
var sb = new StringBuilder();
sb.AppendLine("<b>Position</b>: " + position);
sb.AppendLine("<b>delta</b>: " + delta);
sb.AppendLine("<b>eligibleForClick</b>: " + eligibleForClick);
sb.AppendLine("<b>pointerEnter</b>: " + pointerEnter);
sb.AppendLine("<b>pointerPress</b>: " + pointerPress);
sb.AppendLine("<b>lastPointerPress</b>: " + lastPress);
sb.AppendLine("<b>pointerDrag</b>: " + pointerDrag);
sb.AppendLine("<b>Use Drag Threshold</b>: " + useDragThreshold);
sb.AppendLine("<b>Current Raycast:</b>");
sb.AppendLine(pointerCurrentRaycast.ToString());
sb.AppendLine("<b>Press Raycast:</b>");
sb.AppendLine(pointerPressRaycast.ToString());
return sb.ToString();
}
}
}

View file

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

View file

@ -0,0 +1,14 @@
using System;
namespace UnityEngine.EventSystems
{
[Flags]
/// <summary>
/// Enum that tracks event State.
/// </summary>
public enum EventHandle
{
Unused = 0,
Used = 1
}
}

View file

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

View file

@ -0,0 +1,376 @@
namespace UnityEngine.EventSystems
{
/// <summary>
/// Base class that all EventSystem events inherit from.
/// </summary>
public interface IEventSystemHandler
{
}
/// <summary>
/// Interface to implement if you wish to receive OnPointerEnter callbacks.
/// </summary>
/// <remarks>
/// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
/// </remarks>
public interface IPointerEnterHandler : IEventSystemHandler
{
/// <summary>
/// Use this callback to detect pointer enter events
/// </summary>
void OnPointerEnter(PointerEventData eventData);
}
/// <summary>
/// Interface to implement if you wish to receive OnPointerExit callbacks.
/// </summary>
/// <remarks>
/// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
/// </remarks>
public interface IPointerExitHandler : IEventSystemHandler
{
/// <summary>
/// Use this callback to detect pointer exit events
/// </summary>
void OnPointerExit(PointerEventData eventData);
}
/// <summary>
/// Interface to implement if you wish to receive OnPointerDown callbacks.
/// </summary>
/// <remarks>
/// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
/// </remarks>
public interface IPointerDownHandler : IEventSystemHandler
{
/// <summary>
/// Use this callback to detect pointer down events.
/// </summary>
void OnPointerDown(PointerEventData eventData);
}
/// <summary>
/// Interface to implement if you wish to receive OnPointerUp callbacks.
/// Note: In order to receive OnPointerUp callbacks, you must also implement the EventSystems.IPointerDownHandler|IPointerDownHandler interface
/// </summary>
/// <remarks>
/// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
/// </remarks>
public interface IPointerUpHandler : IEventSystemHandler
{
/// <summary>
/// Use this callback to detect pointer up events.
/// </summary>
void OnPointerUp(PointerEventData eventData);
}
/// <summary>
/// Interface to implement if you wish to receive OnPointerClick callbacks.
/// </summary>
/// <remarks>
/// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
/// </remarks>
/// <remarks>
/// Use the IPointerClickHandler Interface to handle click input using OnPointerClick callbacks. Ensure an Event System exists in the Scene to allow click detection. For click detection on non-UI GameObjects, ensure a EventSystems.PhysicsRaycaster is attached to the Camera.
/// </remarks>
/// <example>
/// <code>
/// using UnityEngine;
/// using UnityEngine.EventSystems;
///
/// public class Example : MonoBehaviour, IPointerClickHandler
/// {
/// //Detect if a click occurs
/// public void OnPointerClick(PointerEventData pointerEventData)
/// {
/// //Output to console the clicked GameObject's name and the following message. You can replace this with your own actions for when clicking the GameObject.
/// Debug.Log(name + " Game Object Clicked!");
/// }
/// }
/// </code>
/// </example>
public interface IPointerClickHandler : IEventSystemHandler
{
/// <summary>
/// Use this callback to detect clicks.
/// </summary>
void OnPointerClick(PointerEventData eventData);
}
/// <summary>
/// Interface to implement if you wish to receive OnBeginDrag callbacks.
/// Note: You need to implement IDragHandler in addition to IBeginDragHandler.
/// </summary>
/// <remarks>
/// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
/// </remarks>
public interface IBeginDragHandler : IEventSystemHandler
{
/// <summary>
/// Called by a BaseInputModule before a drag is started.
/// </summary>
void OnBeginDrag(PointerEventData eventData);
}
/// <summary>
/// Interface to implement if you wish to receive OnInitializePotentialDrag callbacks.
/// </summary>
/// <remarks>
/// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
/// </remarks>
public interface IInitializePotentialDragHandler : IEventSystemHandler
{
/// <summary>
/// Called by a BaseInputModule when a drag has been found but before it is valid to begin the drag.
/// </summary>
void OnInitializePotentialDrag(PointerEventData eventData);
}
/// <summary>
/// Interface to implement if you wish to receive OnDrag callbacks.
/// </summary>
/// <remarks>
/// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
/// </remarks>
/// <example>
/// <code>
/// using UnityEngine;
/// using UnityEngine.EventSystems;
/// using UnityEngine.UI;
///
/// [RequireComponent(typeof(Image))]
/// public class DragMe : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
/// {
/// public bool dragOnSurfaces = true;
///
/// private GameObject m_DraggingIcon;
/// private RectTransform m_DraggingPlane;
///
/// public void OnBeginDrag(PointerEventData eventData)
/// {
/// var canvas = FindInParents<Canvas>(gameObject);
/// if (canvas == null)
/// return;
///
/// // We have clicked something that can be dragged.
/// // What we want to do is create an icon for this.
/// m_DraggingIcon = new GameObject("icon");
///
/// m_DraggingIcon.transform.SetParent(canvas.transform, false);
/// m_DraggingIcon.transform.SetAsLastSibling();
///
/// var image = m_DraggingIcon.AddComponent<Image>();
///
/// image.sprite = GetComponent<Image>().sprite;
/// image.SetNativeSize();
///
/// if (dragOnSurfaces)
/// m_DraggingPlane = transform as RectTransform;
/// else
/// m_DraggingPlane = canvas.transform as RectTransform;
///
/// SetDraggedPosition(eventData);
/// }
///
/// public void OnDrag(PointerEventData data)
/// {
/// if (m_DraggingIcon != null)
/// SetDraggedPosition(data);
/// }
///
/// private void SetDraggedPosition(PointerEventData data)
/// {
/// if (dragOnSurfaces && data.pointerEnter != null && data.pointerEnter.transform as RectTransform != null)
/// m_DraggingPlane = data.pointerEnter.transform as RectTransform;
///
/// var rt = m_DraggingIcon.GetComponent<RectTransform>();
/// Vector3 globalMousePos;
/// if (RectTransformUtility.ScreenPointToWorldPointInRectangle(m_DraggingPlane, data.position, data.pressEventCamera, out globalMousePos))
/// {
/// rt.position = globalMousePos;
/// rt.rotation = m_DraggingPlane.rotation;
/// }
/// }
///
/// public void OnEndDrag(PointerEventData eventData)
/// {
/// if (m_DraggingIcon != null)
/// Destroy(m_DraggingIcon);
/// }
///
/// static public T FindInParents<T>(GameObject go) where T : Component
/// {
/// if (go == null) return null;
/// var comp = go.GetComponent<T>();
///
/// if (comp != null)
/// return comp;
///
/// Transform t = go.transform.parent;
/// while (t != null && comp == null)
/// {
/// comp = t.gameObject.GetComponent<T>();
/// t = t.parent;
/// }
/// return comp;
/// }
/// }
/// </code>
/// </example>
public interface IDragHandler : IEventSystemHandler
{
/// <summary>
/// When dragging is occurring this will be called every time the cursor is moved.
/// </summary>
void OnDrag(PointerEventData eventData);
}
/// <summary>
/// Interface to implement if you wish to receive OnEndDrag callbacks.
/// Note: You need to implement IDragHandler in addition to IEndDragHandler.
/// </summary>
/// <remarks>
/// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
/// </remarks>
public interface IEndDragHandler : IEventSystemHandler
{
/// <summary>
/// Called by a BaseInputModule when a drag is ended.
/// </summary>
void OnEndDrag(PointerEventData eventData);
}
/// <summary>
/// Interface to implement if you wish to receive OnDrop callbacks.
/// </summary>
/// <example>
/// <code>
/// using UnityEngine;
/// using UnityEngine.EventSystems;
///
/// public class DropMe : MonoBehaviour, IDropHandler
/// {
/// public void OnDrop(PointerEventData data)
/// {
/// if (data.pointerDrag != null)
/// {
/// Debug.Log ("Dropped object was: " + data.pointerDrag);
/// }
/// }
/// }
/// </code>
/// </example>
/// <remarks>
/// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
/// </remarks>
public interface IDropHandler : IEventSystemHandler
{
/// <summary>
/// Called by a BaseInputModule on a target that can accept a drop.
/// </summary>
void OnDrop(PointerEventData eventData);
}
/// <summary>
/// Interface to implement if you wish to receive OnScroll callbacks.
/// </summary>
/// <remarks>
/// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
/// </remarks>
public interface IScrollHandler : IEventSystemHandler
{
/// <summary>
/// Use this callback to detect scroll events.
/// </summary>
void OnScroll(PointerEventData eventData);
}
/// <summary>
/// Interface to implement if you wish to receive OnUpdateSelected callbacks.
/// </summary>
/// <remarks>
/// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
/// </remarks>
public interface IUpdateSelectedHandler : IEventSystemHandler
{
/// <summary>
/// Called by the EventSystem when the object associated with this EventTrigger is updated.
/// </summary>
/// <example>
/// <code>
/// using UnityEngine;
/// using UnityEngine.EventSystems;
///
/// public class UpdateSelectedExample : MonoBehaviour, IUpdateSelectedHandler
/// {
/// public void OnUpdateSelected(BaseEventData data)
/// {
/// Debug.Log("OnUpdateSelected called.");
/// }
/// }
/// </code>
/// </example>
void OnUpdateSelected(BaseEventData eventData);
}
/// <summary>
/// Interface to implement if you wish to receive OnSelect callbacks.
/// </summary>
/// <remarks>
/// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
/// </remarks>
public interface ISelectHandler : IEventSystemHandler
{
void OnSelect(BaseEventData eventData);
}
/// <summary>
/// Interface to implement if you wish to receive OnDeselect callbacks.
/// </summary>
/// <remarks>
/// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
/// </remarks>
public interface IDeselectHandler : IEventSystemHandler
{
/// <summary>
/// Called by the EventSystem when a new object is being selected.
/// </summary>
void OnDeselect(BaseEventData eventData);
}
/// <summary>
/// Interface to implement if you wish to receive OnMove callbacks.
/// </summary>
/// <remarks>
/// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
/// </remarks>
public interface IMoveHandler : IEventSystemHandler
{
/// <summary>
/// Called by a BaseInputModule when a move event occurs.
/// </summary>
void OnMove(AxisEventData eventData);
}
/// <summary>
/// Interface to implement if you wish to receive OnSubmit callbacks.
/// </summary>
/// <remarks>
/// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
/// </remarks>
public interface ISubmitHandler : IEventSystemHandler
{
void OnSubmit(BaseEventData eventData);
}
/// <summary>
/// Interface to implement if you wish to receive OnCancel callbacks.
/// </summary>
/// <remarks>
/// Criteria for this event is implementation dependent. For example see StandAloneInputModule.
/// </remarks>
public interface ICancelHandler : IEventSystemHandler
{
void OnCancel(BaseEventData eventData);
}
}

View file

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

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