Skip to content

Commit

Permalink
Commit of ui system for 2017.4.16f1
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickfournier committed Dec 6, 2018
1 parent be30270 commit 7af367a
Show file tree
Hide file tree
Showing 36 changed files with 306 additions and 161 deletions.
4 changes: 2 additions & 2 deletions UnityEditor.UI/UI/RawImageEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public override string GetInfoString()

// 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)));
Mathf.RoundToInt(Mathf.Abs(rawImage.rectTransform.rect.width)),
Mathf.RoundToInt(Mathf.Abs(rawImage.rectTransform.rect.height)));

return text;
}
Expand Down
14 changes: 7 additions & 7 deletions UnityEditor.UI/UI/SpriteDrawUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ static Texture2D contrastTexture
{
if (s_ContrastTex == null)
s_ContrastTex = CreateCheckerTex(
new Color(0f, 0.0f, 0f, 0.5f),
new Color(1f, 1f, 1f, 0.5f));
new Color(0f, 0.0f, 0f, 0.5f),
new Color(1f, 1f, 1f, 0.5f));
return s_ContrastTex;
}
}
Expand Down Expand Up @@ -143,11 +143,11 @@ private static void DrawSprite(Texture tex, Rect drawArea, Vector4 padding, Rect
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))
);
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)
{
Expand Down
33 changes: 6 additions & 27 deletions UnityEditor.UI/UnityEditor.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>3</WarningLevel>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Test|AnyCPU' ">
<DebugSymbols>True</DebugSymbols>
Expand All @@ -28,7 +29,8 @@
<OutputPath>bin\Test\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>3</WarningLevel>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -41,35 +43,12 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="UnityEditor, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<Reference Include="UnityEditor">
<HintPath>..\lib\UnityEditor.dll</HintPath>
</Reference>
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<Reference Include="UnityEngine">
<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
30 changes: 5 additions & 25 deletions UnityEngine.UI-Editor/UnityEngine.UI-Editor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<DefineConstants>TRACE;DEBUG;UNITY_EDITOR</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Test|AnyCPU' ">
<DebugSymbols>True</DebugSymbols>
Expand All @@ -29,6 +30,7 @@
<DefineConstants>TRACE;DEBUG;UNITY_EDITOR</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -41,35 +43,12 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="UnityEditor, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<Reference Include="UnityEditor">
<HintPath>..\lib\UnityEditor.dll</HintPath>
</Reference>
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<Reference Include="UnityEngine">
<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 Expand Up @@ -121,6 +100,7 @@
</Compile>
<Compile Include="..\UnityEngine.UI\EventSystem\InputModules\BaseInput.cs">
<Link>EventSystem\InputModules\BaseInput.cs</Link>
<SubType>Code</SubType>
</Compile>
<Compile Include="..\UnityEngine.UI\EventSystem\InputModules\BaseInputModule.cs">
<Link>EventSystem\InputModules\BaseInputModule.cs</Link>
Expand Down
15 changes: 11 additions & 4 deletions UnityEngine.UI/EventSystem/InputModules/PointerInputModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,18 @@ protected PointerEventData GetTouchPointerEventData(Touch input, out bool presse

pointerData.button = PointerEventData.InputButton.Left;

eventSystem.RaycastAll(pointerData, m_RaycastResultCache);
if (input.phase == TouchPhase.Canceled)
{
pointerData.pointerCurrentRaycast = new RaycastResult();
}
else
{
eventSystem.RaycastAll(pointerData, m_RaycastResultCache);

var raycast = FindFirstRaycast(m_RaycastResultCache);
pointerData.pointerCurrentRaycast = raycast;
m_RaycastResultCache.Clear();
var raycast = FindFirstRaycast(m_RaycastResultCache);
pointerData.pointerCurrentRaycast = raycast;
m_RaycastResultCache.Clear();
}
return pointerData;
}

Expand Down
17 changes: 17 additions & 0 deletions UnityEngine.UI/EventSystem/InputModules/StandaloneInputModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class StandaloneInputModule : PointerInputModule

private GameObject m_CurrentFocusedGameObject;

private PointerEventData m_InputPointerEvent;

protected StandaloneInputModule()
{
}
Expand Down Expand Up @@ -139,7 +141,14 @@ private bool ShouldIgnoreEventsOnNoFocus()
public override void UpdateModule()
{
if (!eventSystem.isFocused && ShouldIgnoreEventsOnNoFocus())
{
if (m_InputPointerEvent != null && m_InputPointerEvent.pointerDrag != null && m_InputPointerEvent.dragging)
ExecuteEvents.Execute(m_InputPointerEvent.pointerDrag, m_InputPointerEvent, ExecuteEvents.endDragHandler);

m_InputPointerEvent = null;

return;
}

m_LastMousePosition = m_MousePosition;
m_MousePosition = input.mousePosition;
Expand Down Expand Up @@ -299,6 +308,8 @@ protected void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bo

if (pointerEvent.pointerDrag != null)
ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag);

m_InputPointerEvent = pointerEvent;
}

// PointerUp notification
Expand Down Expand Up @@ -335,6 +346,8 @@ protected void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bo
// send exit events as we need to simulate this on touch up on touch device
ExecuteEvents.ExecuteHierarchy(pointerEvent.pointerEnter, pointerEvent, ExecuteEvents.pointerExitHandler);
pointerEvent.pointerEnter = null;

m_InputPointerEvent = pointerEvent;
}
}

Expand Down Expand Up @@ -535,6 +548,8 @@ protected void ProcessMousePress(MouseButtonEventData data)

if (pointerEvent.pointerDrag != null)
ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag);

m_InputPointerEvent = pointerEvent;
}

// PointerUp notification
Expand Down Expand Up @@ -577,6 +592,8 @@ protected void ProcessMousePress(MouseButtonEventData data)
HandlePointerExitAndEnter(pointerEvent, null);
HandlePointerExitAndEnter(pointerEvent, currentOverGo);
}

m_InputPointerEvent = pointerEvent;
}
}

Expand Down
14 changes: 14 additions & 0 deletions UnityEngine.UI/EventSystem/InputModules/TouchInputModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ protected TouchInputModule()
private Vector2 m_LastMousePosition;
private Vector2 m_MousePosition;

private PointerEventData m_InputPointerEvent;

[SerializeField]
[FormerlySerializedAs("m_AllowActivationOnStandalone")]
private bool m_ForceModuleActive;
Expand All @@ -33,6 +35,14 @@ public bool forceModuleActive

public override void UpdateModule()
{
if (!eventSystem.isFocused)
{
if (m_InputPointerEvent != null && m_InputPointerEvent.pointerDrag != null && m_InputPointerEvent.dragging)
ExecuteEvents.Execute(m_InputPointerEvent.pointerDrag, m_InputPointerEvent, ExecuteEvents.endDragHandler);

m_InputPointerEvent = null;
}

m_LastMousePosition = m_MousePosition;
m_MousePosition = input.mousePosition;
}
Expand Down Expand Up @@ -189,6 +199,8 @@ protected void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bo

if (pointerEvent.pointerDrag != null)
ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag);

m_InputPointerEvent = pointerEvent;
}

// PointerUp notification
Expand Down Expand Up @@ -230,6 +242,8 @@ protected void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bo
// send exit events as we need to simulate this on touch up on touch device
ExecuteEvents.ExecuteHierarchy(pointerEvent.pointerEnter, pointerEvent, ExecuteEvents.pointerExitHandler);
pointerEvent.pointerEnter = null;

m_InputPointerEvent = pointerEvent;
}
}

Expand Down
42 changes: 35 additions & 7 deletions UnityEngine.UI/UI/Core/Graphic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static public Material defaultGraphicMaterial
public virtual bool raycastTarget { get { return m_RaycastTarget; } set { m_RaycastTarget = value; } }

[NonSerialized] private RectTransform m_RectTransform;
[NonSerialized] private CanvasRenderer m_CanvasRender;
[NonSerialized] private CanvasRenderer m_CanvasRenderer;
[NonSerialized] private Canvas m_Canvas;

[NonSerialized] private bool m_VertsDirty;
Expand Down Expand Up @@ -164,7 +164,16 @@ protected override void OnTransformParentChanged()
/// </summary>
public RectTransform rectTransform
{
get { return m_RectTransform ?? (m_RectTransform = GetComponent<RectTransform>()); }
get
{
// The RectTransform is a required component that must not be destroyed. Based on this assumption, a
// null-reference check is sufficient.
if (ReferenceEquals(m_RectTransform, null))
{
m_RectTransform = GetComponent<RectTransform>();
}
return m_RectTransform;
}
}

public Canvas canvas
Expand Down Expand Up @@ -205,9 +214,13 @@ public CanvasRenderer canvasRenderer
{
get
{
if (m_CanvasRender == null)
m_CanvasRender = GetComponent<CanvasRenderer>();
return m_CanvasRender;
// The CanvasRenderer is a required component that must not be destroyed. Based on this assumption, a
// null-reference check is sufficient.
if (ReferenceEquals(m_CanvasRenderer, null))
{
m_CanvasRenderer = GetComponent<CanvasRenderer>();
}
return m_CanvasRenderer;
}
}

Expand Down Expand Up @@ -322,6 +335,21 @@ protected override void OnCanvasHierarchyChanged()
}
}

/// <summary>
/// This method must be called when <c>CanvasRenderer.cull</c> is modified.
/// </summary>
/// <remarks>
/// This can be used to perform operations that were previously skipped because the <c>Graphic</c> was culled.
/// </remarks>
public virtual void OnCullingChanged()
{
if (!canvasRenderer.cull && (m_VertsDirty || m_MaterialDirty))
{
/// When we were culled, we potentially skipped calls to <c>Rebuild</c>.
CanvasUpdateRegistry.RegisterCanvasElementForGraphicRebuild(this);
}
}

public virtual void Rebuild(CanvasUpdate update)
{
if (canvasRenderer.cull)
Expand Down Expand Up @@ -599,8 +627,8 @@ public virtual void CrossFadeColor(Color targetColor, float duration, bool ignor
}

ColorTween.ColorTweenMode mode = (useRGB && useAlpha ?
ColorTween.ColorTweenMode.All :
(useRGB ? ColorTween.ColorTweenMode.RGB : ColorTween.ColorTweenMode.Alpha));
ColorTween.ColorTweenMode.All :
(useRGB ? ColorTween.ColorTweenMode.RGB : ColorTween.ColorTweenMode.Alpha));

var colorTween = new ColorTween {duration = duration, startColor = canvasRenderer.GetColor(), targetColor = targetColor};
colorTween.AddOnChangedCallback(canvasRenderer.SetColor);
Expand Down
2 changes: 1 addition & 1 deletion UnityEngine.UI/UI/Core/GraphicRaycaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public override void Raycast(PointerEventData eventData, List<RaycastResult> res
Transform trans = go.transform;
Vector3 transForward = trans.forward;
// http://geomalgorithms.com/a06-_intersect-2.html
distance = (Vector3.Dot(transForward, trans.position - currentEventCamera.transform.position) / Vector3.Dot(transForward, ray.direction));
distance = (Vector3.Dot(transForward, trans.position - ray.origin) / Vector3.Dot(transForward, ray.direction));

// Check to see if the go is behind the camera.
if (distance < 0)
Expand Down
14 changes: 9 additions & 5 deletions UnityEngine.UI/UI/Core/GraphicRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ public class GraphicRegistry

protected GraphicRegistry()
{
// This is needed for AOT on IOS. Without it the compile doesn't get the definition of the Dictionarys
#pragma warning disable 168
Dictionary<Graphic, int> emptyGraphicDic;
Dictionary<ICanvasElement, int> emptyElementDic;
#pragma warning restore 168
// Avoid runtime generation of these types. Some platforms are AOT only and do not support
// JIT. What's more we actually create a instance of the required types instead of
// just declaring an unused variable which may be optimized away by some compilers (Mono vs MS).

// See: 877060

System.GC.KeepAlive(new Dictionary<Graphic, int>());
System.GC.KeepAlive(new Dictionary<ICanvasElement, int>());
System.GC.KeepAlive(new Dictionary<IClipper, int>());
}

public static GraphicRegistry instance
Expand Down
Loading

0 comments on commit 7af367a

Please sign in to comment.