Skip to content

Commit 3f3735f

Browse files
author
Philip Cosgrave
committed
Commit of UI system for 2017.2f3
1 parent e6a22a0 commit 3f3735f

36 files changed

+247
-93
lines changed

LICENSE

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1-
The MIT License (MIT)
1+
Unity Companion License (“License”)
2+
Software Copyright © 2014 - 2018 Unity Technologies ApS
3+
4+
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:
5+
6+
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.
7+
8+
2. No Modification of Engine License. Neither this License nor any exercise of the license granted herein modifies the Engine License in any way.
9+
10+
3. Ownership & Grant Back to You.
211

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

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
14+
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.
15+
16+
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.
17+
18+
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.
19+
20+
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.
21+
22+
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.
23+
24+
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.
25+
26+
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.
27+
28+
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.
29+
30+
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.
1131

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

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21-
THE SOFTWARE.

README.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
# README #
22

3-
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!
3+
This document details how to get it up and running on your computer and start modifying the code!
44

55
### What license is the UI system shipped under? ###
6-
The UI system is released under an MIT/X11 license; see the LICENSE file.
7-
8-
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.
9-
10-
You can keep the source to yourself or share your customized version under the same MIT license or a compatible license.
11-
12-
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.
6+
Please see the LICENSE file.
137

148
### How do I get started? ###
159
* Clone this repository onto a location on your computer.

UnityEditor.UI/UI/ImageEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ protected void TypeGUI()
171171
if (EditorGUILayout.BeginFadeGroup(m_ShowTiled.faded))
172172
{
173173
if (image.sprite != null && !image.hasBorder && (image.sprite.texture.wrapMode != TextureWrapMode.Repeat || image.sprite.packed))
174-
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);
174+
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);
175175
}
176176
EditorGUILayout.EndFadeGroup();
177177

UnityEditor.UI/UnityEditor.UI.csproj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@
4949
<SpecificVersion>False</SpecificVersion>
5050
<HintPath>..\lib\UnityEngine.dll</HintPath>
5151
</Reference>
52+
<Reference Include="UnityEngine.AnimationModule">
53+
<HintPath>..\lib\UnityEngine.AnimationModule.dll</HintPath>
54+
</Reference>
55+
<Reference Include="UnityEngine.CoreModule">
56+
<HintPath>..\lib\UnityEngine.CoreModule.dll</HintPath>
57+
</Reference>
58+
<Reference Include="UnityEngine.IMGUIModule">
59+
<HintPath>..\lib\UnityEngine.IMGUIModule.dll</HintPath>
60+
</Reference>
61+
<Reference Include="UnityEngine.Physics2DModule">
62+
<HintPath>..\lib\UnityEngine.Physics2DModule.dll</HintPath>
63+
</Reference>
64+
<Reference Include="UnityEngine.PhysicsModule">
65+
<HintPath>..\lib\UnityEngine.PhysicsModule.dll</HintPath>
66+
</Reference>
67+
<Reference Include="UnityEngine.TextRenderingModule">
68+
<HintPath>..\lib\UnityEngine.TextRenderingModule.dll</HintPath>
69+
</Reference>
70+
<Reference Include="UnityEngine.UIModule">
71+
<HintPath>..\lib\UnityEngine.UIModule.dll</HintPath>
72+
</Reference>
5273
</ItemGroup>
5374
<ItemGroup>
5475
<Folder Include="Properties\" />

UnityEngine.UI-Editor/UnityEngine.UI-Editor.csproj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@
4949
<SpecificVersion>False</SpecificVersion>
5050
<HintPath>..\lib\UnityEngine.dll</HintPath>
5151
</Reference>
52+
<Reference Include="UnityEngine.AnimationModule">
53+
<HintPath>..\lib\UnityEngine.AnimationModule.dll</HintPath>
54+
</Reference>
55+
<Reference Include="UnityEngine.CoreModule">
56+
<HintPath>..\lib\UnityEngine.CoreModule.dll</HintPath>
57+
</Reference>
58+
<Reference Include="UnityEngine.IMGUIModule">
59+
<HintPath>..\lib\UnityEngine.IMGUIModule.dll</HintPath>
60+
</Reference>
61+
<Reference Include="UnityEngine.Physics2DModule">
62+
<HintPath>..\lib\UnityEngine.Physics2DModule.dll</HintPath>
63+
</Reference>
64+
<Reference Include="UnityEngine.PhysicsModule">
65+
<HintPath>..\lib\UnityEngine.PhysicsModule.dll</HintPath>
66+
</Reference>
67+
<Reference Include="UnityEngine.TextRenderingModule">
68+
<HintPath>..\lib\UnityEngine.TextRenderingModule.dll</HintPath>
69+
</Reference>
70+
<Reference Include="UnityEngine.UIModule">
71+
<HintPath>..\lib\UnityEngine.UIModule.dll</HintPath>
72+
</Reference>
5273
</ItemGroup>
5374
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5475
<PropertyGroup>

UnityEngine.UI/EventSystem/EventSystem.cs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,22 @@ public class EventSystem : UIBehaviour
1313

1414
private BaseInputModule m_CurrentInputModule;
1515

16-
public static EventSystem current { get; set; }
16+
private static List<EventSystem> m_EventSystems = new List<EventSystem>();
17+
18+
public static EventSystem current
19+
{
20+
get { return m_EventSystems.Count > 0 ? m_EventSystems[0] : null; }
21+
set
22+
{
23+
int index = m_EventSystems.IndexOf(value);
24+
25+
if (index >= 0)
26+
{
27+
m_EventSystems.RemoveAt(index);
28+
m_EventSystems.Insert(0, value);
29+
}
30+
}
31+
}
1732

1833
[SerializeField]
1934
[FormerlySerializedAs("m_Selected")]
@@ -209,14 +224,7 @@ public bool IsPointerOverGameObject(int pointerId)
209224
protected override void OnEnable()
210225
{
211226
base.OnEnable();
212-
if (EventSystem.current == null)
213-
EventSystem.current = this;
214-
#if UNITY_EDITOR
215-
else
216-
{
217-
Debug.LogWarning("Multiple EventSystems in scene... this is not supported");
218-
}
219-
#endif
227+
m_EventSystems.Add(this);
220228
}
221229

222230
protected override void OnDisable()
@@ -227,8 +235,7 @@ protected override void OnDisable()
227235
m_CurrentInputModule = null;
228236
}
229237

230-
if (EventSystem.current == this)
231-
EventSystem.current = null;
238+
m_EventSystems.Remove(this);
232239

233240
base.OnDisable();
234241
}

UnityEngine.UI/EventSystem/Raycasters/Physics2DRaycaster.cs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace UnityEngine.EventSystems
1010
[RequireComponent(typeof(Camera))]
1111
public class Physics2DRaycaster : PhysicsRaycaster
1212
{
13+
RaycastHit2D[] m_Hits;
14+
1315
protected Physics2DRaycaster()
1416
{}
1517

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

25-
if (ReflectionMethodsCache.Singleton.getRayIntersectionAll == null)
26-
return;
27+
int hitCount = 0;
28+
29+
if (maxRayIntersections == 0)
30+
{
31+
if (ReflectionMethodsCache.Singleton.getRayIntersectionAll == null)
32+
return;
2733

28-
var hits = ReflectionMethodsCache.Singleton.getRayIntersectionAll(ray, distanceToClipPlane, finalEventMask);
34+
m_Hits = ReflectionMethodsCache.Singleton.getRayIntersectionAll(ray, distanceToClipPlane, finalEventMask);
35+
hitCount = m_Hits.Length;
36+
}
37+
else
38+
{
39+
if (ReflectionMethodsCache.Singleton.getRayIntersectionAllNonAlloc == null)
40+
return;
41+
42+
if (m_LastMaxRayIntersections != m_MaxRayIntersections)
43+
{
44+
m_Hits = new RaycastHit2D[maxRayIntersections];
45+
m_LastMaxRayIntersections = m_MaxRayIntersections;
46+
}
47+
48+
hitCount = ReflectionMethodsCache.Singleton.getRayIntersectionAllNonAlloc(ray, m_Hits, distanceToClipPlane, finalEventMask);
49+
}
2950

30-
if (hits.Length != 0)
51+
if (hitCount != 0)
3152
{
32-
for (int b = 0, bmax = hits.Length; b < bmax; ++b)
53+
for (int b = 0, bmax = hitCount; b < bmax; ++b)
3354
{
34-
var sr = hits[b].collider.gameObject.GetComponent<SpriteRenderer>();
55+
var sr = m_Hits[b].collider.gameObject.GetComponent<SpriteRenderer>();
3556

3657
var result = new RaycastResult
3758
{
38-
gameObject = hits[b].collider.gameObject,
59+
gameObject = m_Hits[b].collider.gameObject,
3960
module = this,
40-
distance = Vector3.Distance(eventCamera.transform.position, hits[b].point),
41-
worldPosition = hits[b].point,
42-
worldNormal = hits[b].normal,
61+
distance = Vector3.Distance(eventCamera.transform.position, m_Hits[b].point),
62+
worldPosition = m_Hits[b].point,
63+
worldNormal = m_Hits[b].normal,
4364
screenPosition = eventData.position,
4465
index = resultAppendList.Count,
4566
sortingLayer = sr != null ? sr.sortingLayerID : 0,

UnityEngine.UI/EventSystem/Raycasters/PhysicsRaycaster.cs

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ public class PhysicsRaycaster : BaseRaycaster
2323
[SerializeField]
2424
protected LayerMask m_EventMask = kNoEventMaskSet;
2525

26+
/// <summary>
27+
/// The max number of intersections allowed. 0 = allocating version anything else is non alloc.
28+
/// </summary>
29+
[SerializeField]
30+
protected int m_MaxRayIntersections = 0;
31+
protected int m_LastMaxRayIntersections = 0;
32+
33+
RaycastHit[] m_Hits;
34+
2635
protected PhysicsRaycaster()
2736
{}
2837

@@ -62,6 +71,12 @@ public LayerMask eventMask
6271
set { m_EventMask = value; }
6372
}
6473

74+
public int maxRayIntersections
75+
{
76+
get { return m_MaxRayIntersections; }
77+
set { m_MaxRayIntersections = value; }
78+
}
79+
6580
protected void ComputeRayAndDistance(PointerEventData eventData, out Ray ray, out float distanceToClipPlane)
6681
{
6782
ray = eventCamera.ScreenPointToRay(eventData.position);
@@ -82,25 +97,44 @@ public override void Raycast(PointerEventData eventData, List<RaycastResult> res
8297
float distanceToClipPlane;
8398
ComputeRayAndDistance(eventData, out ray, out distanceToClipPlane);
8499

85-
if (ReflectionMethodsCache.Singleton.raycast3DAll == null)
86-
return;
100+
int hitCount = 0;
87101

88-
var hits = ReflectionMethodsCache.Singleton.raycast3DAll(ray, distanceToClipPlane, finalEventMask);
102+
if (m_MaxRayIntersections == 0)
103+
{
104+
if (ReflectionMethodsCache.Singleton.raycast3DAll == null)
105+
return;
106+
107+
m_Hits = ReflectionMethodsCache.Singleton.raycast3DAll(ray, distanceToClipPlane, finalEventMask);
108+
hitCount = m_Hits.Length;
109+
}
110+
else
111+
{
112+
if (ReflectionMethodsCache.Singleton.getRaycastNonAlloc == null)
113+
return;
114+
115+
if (m_LastMaxRayIntersections != m_MaxRayIntersections)
116+
{
117+
m_Hits = new RaycastHit[m_MaxRayIntersections];
118+
m_LastMaxRayIntersections = m_MaxRayIntersections;
119+
}
120+
121+
hitCount = ReflectionMethodsCache.Singleton.getRaycastNonAlloc(ray, m_Hits, distanceToClipPlane, finalEventMask);
122+
}
89123

90-
if (hits.Length > 1)
91-
System.Array.Sort(hits, (r1, r2) => r1.distance.CompareTo(r2.distance));
124+
if (hitCount > 1)
125+
System.Array.Sort(m_Hits, (r1, r2) => r1.distance.CompareTo(r2.distance));
92126

93-
if (hits.Length != 0)
127+
if (hitCount != 0)
94128
{
95-
for (int b = 0, bmax = hits.Length; b < bmax; ++b)
129+
for (int b = 0, bmax = hitCount; b < bmax; ++b)
96130
{
97131
var result = new RaycastResult
98132
{
99-
gameObject = hits[b].collider.gameObject,
133+
gameObject = m_Hits[b].collider.gameObject,
100134
module = this,
101-
distance = hits[b].distance,
102-
worldPosition = hits[b].point,
103-
worldNormal = hits[b].normal,
135+
distance = m_Hits[b].distance,
136+
worldPosition = m_Hits[b].point,
137+
worldNormal = m_Hits[b].normal,
104138
screenPosition = eventData.position,
105139
index = resultAppendList.Count,
106140
sortingLayer = 0,

UnityEngine.UI/UI/Core/InputField.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1605,9 +1605,12 @@ protected virtual void Append(string input)
16051605
}
16061606
}
16071607

1608+
// cf. TextGenerator.cpp
1609+
private const int k_MaxTextLength = UInt16.MaxValue / 4 - 1;
1610+
16081611
protected virtual void Append(char input)
16091612
{
1610-
if (m_ReadOnly)
1613+
if (m_ReadOnly || text.Length >= k_MaxTextLength)
16111614
return;
16121615

16131616
if (!InPlaceEditing())

UnityEngine.UI/UI/Core/Layout/AspectRatioFitter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected override void OnEnable()
4141

4242
protected override void OnDisable()
4343
{
44-
m_Tracker.Clear();
44+
m_Tracker.Clear(true);
4545
LayoutRebuilder.MarkLayoutForRebuild(rectTransform);
4646
base.OnDisable();
4747
}
@@ -56,7 +56,7 @@ private void UpdateRect()
5656
if (!IsActive())
5757
return;
5858

59-
m_Tracker.Clear();
59+
m_Tracker.Clear(false);
6060

6161
switch (m_AspectMode)
6262
{

0 commit comments

Comments
 (0)