Skip to content

Commit

Permalink
Commit of UI system for 2017.2f3
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Cosgrave committed Feb 6, 2018
1 parent e6a22a0 commit 3f3735f
Show file tree
Hide file tree
Showing 36 changed files with 247 additions and 93 deletions.
45 changes: 28 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
The MIT License (MIT)
Unity Companion License (“License”)
Software Copyright © 2014 - 2018 Unity Technologies ApS

Unity Technologies ApS (“Unity”) 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 under 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 content authoring and rendering 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, and in no event may the Software be used for competitive analysis or to develop a competing product or service.

2. No Modification of Engine License. Neither this License nor any exercise of the license granted herein modifies the Engine License in any way.

3. Ownership & Grant Back to You.

Copyright (c) 2014-2015, Unity Technologies
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.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
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.

4. 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, Unity’s Branding Usage Guidelines at https://unity3d.com/public-relations/brand.

5. Notices & Third-Party Rights. This License, including the copyright notice associated with the Software, 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.

6. 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.

7. 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.

8. 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.

9. 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.

10. 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.

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
# README #

The Unity UI system is open and available for use in your games and applications. This document details how to get it up and running on your computer and start modifying the code!
This document details how to get it up and running on your computer and start modifying the code!

### What license is the UI system shipped under? ###
The UI system is released under an MIT/X11 license; see the LICENSE file.

This means that you pretty much can customize and embed it in any software under any license without any other constraints than preserving the copyright and license information while adding your own copyright and license information.

You can keep the source to yourself or share your customized version under the same MIT license or a compatible license.

If you want to contribute patches back, please keep it under the unmodified MIT license so it can be integrated in future versions and shared under the same license.
Please see the LICENSE file.

### How do I get started? ###
* Clone this repository onto a location on your computer.
Expand Down
2 changes: 1 addition & 1 deletion UnityEditor.UI/UI/ImageEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ protected void TypeGUI()
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 convert the Sprite to an Advanced texture, clear the Packing tag and set the Wrap mode to Repeat.", MessageType.Warning);
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();

Expand Down
21 changes: 21 additions & 0 deletions UnityEditor.UI/UnityEditor.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\lib\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AnimationModule">
<HintPath>..\lib\UnityEngine.AnimationModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\lib\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.IMGUIModule">
<HintPath>..\lib\UnityEngine.IMGUIModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.Physics2DModule">
<HintPath>..\lib\UnityEngine.Physics2DModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule">
<HintPath>..\lib\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TextRenderingModule">
<HintPath>..\lib\UnityEngine.TextRenderingModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UIModule">
<HintPath>..\lib\UnityEngine.UIModule.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
Expand Down
21 changes: 21 additions & 0 deletions UnityEngine.UI-Editor/UnityEngine.UI-Editor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\lib\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AnimationModule">
<HintPath>..\lib\UnityEngine.AnimationModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\lib\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.IMGUIModule">
<HintPath>..\lib\UnityEngine.IMGUIModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.Physics2DModule">
<HintPath>..\lib\UnityEngine.Physics2DModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule">
<HintPath>..\lib\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TextRenderingModule">
<HintPath>..\lib\UnityEngine.TextRenderingModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UIModule">
<HintPath>..\lib\UnityEngine.UIModule.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
Expand Down
29 changes: 18 additions & 11 deletions UnityEngine.UI/EventSystem/EventSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,22 @@ public class EventSystem : UIBehaviour

private BaseInputModule m_CurrentInputModule;

public static EventSystem current { get; set; }
private static List<EventSystem> m_EventSystems = new List<EventSystem>();

public static EventSystem current
{
get { return m_EventSystems.Count > 0 ? m_EventSystems[0] : null; }
set
{
int index = m_EventSystems.IndexOf(value);

if (index >= 0)
{
m_EventSystems.RemoveAt(index);
m_EventSystems.Insert(0, value);
}
}
}

[SerializeField]
[FormerlySerializedAs("m_Selected")]
Expand Down Expand Up @@ -209,14 +224,7 @@ public bool IsPointerOverGameObject(int pointerId)
protected override void OnEnable()
{
base.OnEnable();
if (EventSystem.current == null)
EventSystem.current = this;
#if UNITY_EDITOR
else
{
Debug.LogWarning("Multiple EventSystems in scene... this is not supported");
}
#endif
m_EventSystems.Add(this);
}

protected override void OnDisable()
Expand All @@ -227,8 +235,7 @@ protected override void OnDisable()
m_CurrentInputModule = null;
}

if (EventSystem.current == this)
EventSystem.current = null;
m_EventSystems.Remove(this);

base.OnDisable();
}
Expand Down
41 changes: 31 additions & 10 deletions UnityEngine.UI/EventSystem/Raycasters/Physics2DRaycaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace UnityEngine.EventSystems
[RequireComponent(typeof(Camera))]
public class Physics2DRaycaster : PhysicsRaycaster
{
RaycastHit2D[] m_Hits;

protected Physics2DRaycaster()
{}

Expand All @@ -22,24 +24,43 @@ public override void Raycast(PointerEventData eventData, List<RaycastResult> res
float distanceToClipPlane;
ComputeRayAndDistance(eventData, out ray, out distanceToClipPlane);

if (ReflectionMethodsCache.Singleton.getRayIntersectionAll == null)
return;
int hitCount = 0;

if (maxRayIntersections == 0)
{
if (ReflectionMethodsCache.Singleton.getRayIntersectionAll == null)
return;

var hits = ReflectionMethodsCache.Singleton.getRayIntersectionAll(ray, distanceToClipPlane, finalEventMask);
m_Hits = ReflectionMethodsCache.Singleton.getRayIntersectionAll(ray, distanceToClipPlane, finalEventMask);
hitCount = m_Hits.Length;
}
else
{
if (ReflectionMethodsCache.Singleton.getRayIntersectionAllNonAlloc == null)
return;

if (m_LastMaxRayIntersections != m_MaxRayIntersections)
{
m_Hits = new RaycastHit2D[maxRayIntersections];
m_LastMaxRayIntersections = m_MaxRayIntersections;
}

hitCount = ReflectionMethodsCache.Singleton.getRayIntersectionAllNonAlloc(ray, m_Hits, distanceToClipPlane, finalEventMask);
}

if (hits.Length != 0)
if (hitCount != 0)
{
for (int b = 0, bmax = hits.Length; b < bmax; ++b)
for (int b = 0, bmax = hitCount; b < bmax; ++b)
{
var sr = hits[b].collider.gameObject.GetComponent<SpriteRenderer>();
var sr = m_Hits[b].collider.gameObject.GetComponent<SpriteRenderer>();

var result = new RaycastResult
{
gameObject = hits[b].collider.gameObject,
gameObject = m_Hits[b].collider.gameObject,
module = this,
distance = Vector3.Distance(eventCamera.transform.position, hits[b].point),
worldPosition = hits[b].point,
worldNormal = hits[b].normal,
distance = Vector3.Distance(eventCamera.transform.position, m_Hits[b].point),
worldPosition = m_Hits[b].point,
worldNormal = m_Hits[b].normal,
screenPosition = eventData.position,
index = resultAppendList.Count,
sortingLayer = sr != null ? sr.sortingLayerID : 0,
Expand Down
56 changes: 45 additions & 11 deletions UnityEngine.UI/EventSystem/Raycasters/PhysicsRaycaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ public class PhysicsRaycaster : BaseRaycaster
[SerializeField]
protected LayerMask m_EventMask = kNoEventMaskSet;

/// <summary>
/// The max number of intersections allowed. 0 = allocating version anything else is non alloc.
/// </summary>
[SerializeField]
protected int m_MaxRayIntersections = 0;
protected int m_LastMaxRayIntersections = 0;

RaycastHit[] m_Hits;

protected PhysicsRaycaster()
{}

Expand Down Expand Up @@ -62,6 +71,12 @@ public LayerMask eventMask
set { m_EventMask = value; }
}

public int maxRayIntersections
{
get { return m_MaxRayIntersections; }
set { m_MaxRayIntersections = value; }
}

protected void ComputeRayAndDistance(PointerEventData eventData, out Ray ray, out float distanceToClipPlane)
{
ray = eventCamera.ScreenPointToRay(eventData.position);
Expand All @@ -82,25 +97,44 @@ public override void Raycast(PointerEventData eventData, List<RaycastResult> res
float distanceToClipPlane;
ComputeRayAndDistance(eventData, out ray, out distanceToClipPlane);

if (ReflectionMethodsCache.Singleton.raycast3DAll == null)
return;
int hitCount = 0;

var hits = ReflectionMethodsCache.Singleton.raycast3DAll(ray, distanceToClipPlane, finalEventMask);
if (m_MaxRayIntersections == 0)
{
if (ReflectionMethodsCache.Singleton.raycast3DAll == null)
return;

m_Hits = ReflectionMethodsCache.Singleton.raycast3DAll(ray, distanceToClipPlane, finalEventMask);
hitCount = m_Hits.Length;
}
else
{
if (ReflectionMethodsCache.Singleton.getRaycastNonAlloc == null)
return;

if (m_LastMaxRayIntersections != m_MaxRayIntersections)
{
m_Hits = new RaycastHit[m_MaxRayIntersections];
m_LastMaxRayIntersections = m_MaxRayIntersections;
}

hitCount = ReflectionMethodsCache.Singleton.getRaycastNonAlloc(ray, m_Hits, distanceToClipPlane, finalEventMask);
}

if (hits.Length > 1)
System.Array.Sort(hits, (r1, r2) => r1.distance.CompareTo(r2.distance));
if (hitCount > 1)
System.Array.Sort(m_Hits, (r1, r2) => r1.distance.CompareTo(r2.distance));

if (hits.Length != 0)
if (hitCount != 0)
{
for (int b = 0, bmax = hits.Length; b < bmax; ++b)
for (int b = 0, bmax = hitCount; b < bmax; ++b)
{
var result = new RaycastResult
{
gameObject = hits[b].collider.gameObject,
gameObject = m_Hits[b].collider.gameObject,
module = this,
distance = hits[b].distance,
worldPosition = hits[b].point,
worldNormal = hits[b].normal,
distance = m_Hits[b].distance,
worldPosition = m_Hits[b].point,
worldNormal = m_Hits[b].normal,
screenPosition = eventData.position,
index = resultAppendList.Count,
sortingLayer = 0,
Expand Down
5 changes: 4 additions & 1 deletion UnityEngine.UI/UI/Core/InputField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1605,9 +1605,12 @@ protected virtual void Append(string input)
}
}

// cf. TextGenerator.cpp
private const int k_MaxTextLength = UInt16.MaxValue / 4 - 1;

protected virtual void Append(char input)
{
if (m_ReadOnly)
if (m_ReadOnly || text.Length >= k_MaxTextLength)
return;

if (!InPlaceEditing())
Expand Down
4 changes: 2 additions & 2 deletions UnityEngine.UI/UI/Core/Layout/AspectRatioFitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected override void OnEnable()

protected override void OnDisable()
{
m_Tracker.Clear();
m_Tracker.Clear(true);
LayoutRebuilder.MarkLayoutForRebuild(rectTransform);
base.OnDisable();
}
Expand All @@ -56,7 +56,7 @@ private void UpdateRect()
if (!IsActive())
return;

m_Tracker.Clear();
m_Tracker.Clear(false);

switch (m_AspectMode)
{
Expand Down
Loading

0 comments on commit 3f3735f

Please sign in to comment.