scripts
This commit is contained in:
@@ -0,0 +1,369 @@
|
||||
using System;
|
||||
using UnityEngine.Experimental.UIElements.StyleSheets;
|
||||
|
||||
namespace UnityEngine.Experimental.UIElements
|
||||
{
|
||||
// Token: 0x02000338 RID: 824
|
||||
internal class Panel : BaseVisualElementPanel
|
||||
{
|
||||
// Token: 0x0600334D RID: 13133 RVA: 0x0004FA6C File Offset: 0x0004DC6C
|
||||
public Panel(int instanceID, ContextType contextType, LoadResourceFunction loadResourceDelegate = null, IDataWatchService dataWatch = null, IDispatcher dispatcher = null)
|
||||
{
|
||||
this.instanceID = instanceID;
|
||||
this.contextType = contextType;
|
||||
LoadResourceFunction loadResourceFunction = loadResourceDelegate;
|
||||
if (loadResourceDelegate == null)
|
||||
{
|
||||
loadResourceFunction = new LoadResourceFunction(Resources.Load);
|
||||
}
|
||||
this.loadResourceFunc = loadResourceFunction;
|
||||
this.dataWatch = dataWatch;
|
||||
this.dispatcher = dispatcher;
|
||||
this.stylePainter = new StylePainter();
|
||||
this.m_RootContainer = new VisualContainer();
|
||||
this.m_RootContainer.name = VisualElementUtils.GetUniqueName("PanelContainer");
|
||||
this.visualTree.ChangePanel(this);
|
||||
this.m_StyleContext = new StyleContext(this.m_RootContainer);
|
||||
this.defaultIMRoot = new IMContainer
|
||||
{
|
||||
name = "DefaultOnGUI",
|
||||
pickingMode = PickingMode.Ignore
|
||||
};
|
||||
this.defaultIMRoot.StretchToParentSize();
|
||||
this.visualTree.InsertChild(0, this.defaultIMRoot);
|
||||
this.allowPixelCaching = true;
|
||||
}
|
||||
|
||||
// Token: 0x17000BA4 RID: 2980
|
||||
// (get) Token: 0x0600334E RID: 13134 RVA: 0x0004FB54 File Offset: 0x0004DD54
|
||||
public override VisualContainer visualTree
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_RootContainer;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000BA5 RID: 2981
|
||||
// (get) Token: 0x0600334F RID: 13135 RVA: 0x0004FB70 File Offset: 0x0004DD70
|
||||
// (set) Token: 0x06003350 RID: 13136 RVA: 0x0004FB8C File Offset: 0x0004DD8C
|
||||
public VisualContainer defaultIMRoot { get; set; }
|
||||
|
||||
// Token: 0x17000BA6 RID: 2982
|
||||
// (get) Token: 0x06003351 RID: 13137 RVA: 0x0004FB98 File Offset: 0x0004DD98
|
||||
// (set) Token: 0x06003352 RID: 13138 RVA: 0x0004FBB4 File Offset: 0x0004DDB4
|
||||
public override IDispatcher dispatcher { get; protected set; }
|
||||
|
||||
// Token: 0x17000BA7 RID: 2983
|
||||
// (get) Token: 0x06003353 RID: 13139 RVA: 0x0004FBC0 File Offset: 0x0004DDC0
|
||||
// (set) Token: 0x06003354 RID: 13140 RVA: 0x0004FBDC File Offset: 0x0004DDDC
|
||||
public override IDataWatchService dataWatch { get; protected set; }
|
||||
|
||||
// Token: 0x17000BA8 RID: 2984
|
||||
// (get) Token: 0x06003355 RID: 13141 RVA: 0x0004FBE8 File Offset: 0x0004DDE8
|
||||
public TimerEventScheduler timerEventScheduler
|
||||
{
|
||||
get
|
||||
{
|
||||
TimerEventScheduler timerEventScheduler;
|
||||
if ((timerEventScheduler = this.m_Scheduler) == null)
|
||||
{
|
||||
timerEventScheduler = (this.m_Scheduler = new TimerEventScheduler());
|
||||
}
|
||||
return timerEventScheduler;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000BA9 RID: 2985
|
||||
// (get) Token: 0x06003356 RID: 13142 RVA: 0x0004FC18 File Offset: 0x0004DE18
|
||||
public override IScheduler scheduler
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.timerEventScheduler;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000BAA RID: 2986
|
||||
// (get) Token: 0x06003357 RID: 13143 RVA: 0x0004FC34 File Offset: 0x0004DE34
|
||||
internal StyleContext styleContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_StyleContext;
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x17000BAB RID: 2987
|
||||
// (get) Token: 0x06003358 RID: 13144 RVA: 0x0004FC50 File Offset: 0x0004DE50
|
||||
// (set) Token: 0x06003359 RID: 13145 RVA: 0x0004FC6C File Offset: 0x0004DE6C
|
||||
public override int instanceID { get; protected set; }
|
||||
|
||||
// Token: 0x17000BAC RID: 2988
|
||||
// (get) Token: 0x0600335A RID: 13146 RVA: 0x0004FC78 File Offset: 0x0004DE78
|
||||
// (set) Token: 0x0600335B RID: 13147 RVA: 0x0004FC94 File Offset: 0x0004DE94
|
||||
public bool allowPixelCaching { get; set; }
|
||||
|
||||
// Token: 0x17000BAD RID: 2989
|
||||
// (get) Token: 0x0600335C RID: 13148 RVA: 0x0004FCA0 File Offset: 0x0004DEA0
|
||||
// (set) Token: 0x0600335D RID: 13149 RVA: 0x0004FCBC File Offset: 0x0004DEBC
|
||||
public override ContextType contextType { get; protected set; }
|
||||
|
||||
// Token: 0x17000BAE RID: 2990
|
||||
// (get) Token: 0x0600335E RID: 13150 RVA: 0x0004FCC8 File Offset: 0x0004DEC8
|
||||
// (set) Token: 0x0600335F RID: 13151 RVA: 0x0004FCE4 File Offset: 0x0004DEE4
|
||||
public override EventInterests IMGUIEventInterests { get; set; }
|
||||
|
||||
// Token: 0x17000BAF RID: 2991
|
||||
// (get) Token: 0x06003360 RID: 13152 RVA: 0x0004FCF0 File Offset: 0x0004DEF0
|
||||
// (set) Token: 0x06003361 RID: 13153 RVA: 0x0004FD0C File Offset: 0x0004DF0C
|
||||
public override LoadResourceFunction loadResourceFunc { get; protected set; }
|
||||
|
||||
// Token: 0x17000BB0 RID: 2992
|
||||
// (get) Token: 0x06003362 RID: 13154 RVA: 0x0004FD18 File Offset: 0x0004DF18
|
||||
// (set) Token: 0x06003363 RID: 13155 RVA: 0x0004FD34 File Offset: 0x0004DF34
|
||||
public override int IMGUIContainersCount { get; set; }
|
||||
|
||||
// Token: 0x06003364 RID: 13156 RVA: 0x0004FD40 File Offset: 0x0004DF40
|
||||
private VisualElement Pick(VisualElement root, Vector2 point)
|
||||
{
|
||||
VisualElement visualElement;
|
||||
if ((root.pseudoStates & PseudoStates.Invisible) == PseudoStates.Invisible)
|
||||
{
|
||||
visualElement = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
VisualContainer visualContainer = root as VisualContainer;
|
||||
Vector3 vector = root.transform.inverse.MultiplyPoint3x4(point);
|
||||
bool flag = root.ContainsPoint(vector);
|
||||
if (visualContainer != null)
|
||||
{
|
||||
if (!flag && visualContainer.clipChildren)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
vector -= new Vector3(visualContainer.position.position.x, visualContainer.position.position.y, 0f);
|
||||
for (int i = visualContainer.childrenCount - 1; i >= 0; i--)
|
||||
{
|
||||
VisualElement childAt = visualContainer.GetChildAt(i);
|
||||
VisualElement visualElement2 = this.Pick(childAt, vector);
|
||||
if (visualElement2 != null)
|
||||
{
|
||||
return visualElement2;
|
||||
}
|
||||
}
|
||||
}
|
||||
PickingMode pickingMode = root.pickingMode;
|
||||
if (pickingMode != PickingMode.Position)
|
||||
{
|
||||
if (pickingMode != PickingMode.Ignore)
|
||||
{
|
||||
}
|
||||
}
|
||||
else if (flag)
|
||||
{
|
||||
return root;
|
||||
}
|
||||
visualElement = null;
|
||||
}
|
||||
return visualElement;
|
||||
}
|
||||
|
||||
// Token: 0x06003365 RID: 13157 RVA: 0x0004FE88 File Offset: 0x0004E088
|
||||
public override VisualElement Pick(Vector2 point)
|
||||
{
|
||||
this.ValidateLayout();
|
||||
return this.Pick(this.visualTree, point);
|
||||
}
|
||||
|
||||
// Token: 0x06003366 RID: 13158 RVA: 0x0004FEB0 File Offset: 0x0004E0B0
|
||||
private void ValidateStyling()
|
||||
{
|
||||
if (!Mathf.Approximately(this.m_StyleContext.currentPixelsPerPoint, GUIUtility.pixelsPerPoint))
|
||||
{
|
||||
this.m_RootContainer.Dirty(ChangeType.Styles);
|
||||
this.m_StyleContext.currentPixelsPerPoint = GUIUtility.pixelsPerPoint;
|
||||
}
|
||||
if (this.m_RootContainer.IsDirty(ChangeType.Styles | ChangeType.StylesPath))
|
||||
{
|
||||
this.m_StyleContext.ApplyStyles();
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06003367 RID: 13159 RVA: 0x0004FF18 File Offset: 0x0004E118
|
||||
public override void ValidateLayout()
|
||||
{
|
||||
this.ValidateStyling();
|
||||
int num = 0;
|
||||
while (this.visualTree.cssNode.IsDirty)
|
||||
{
|
||||
this.visualTree.cssNode.CalculateLayout();
|
||||
this.ValidateSubTree(this.visualTree);
|
||||
if (num++ >= 5)
|
||||
{
|
||||
Debug.LogError("ValidateLayout is struggling to process current layout (consider simplifying to avoid recursive layout): " + this.visualTree);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x06003368 RID: 13160 RVA: 0x0004FF90 File Offset: 0x0004E190
|
||||
private bool ValidateSubTree(VisualElement root)
|
||||
{
|
||||
if (root.renderData.lastLayout != new Rect(root.cssNode.LayoutX, root.cssNode.LayoutY, root.cssNode.LayoutWidth, root.cssNode.LayoutHeight))
|
||||
{
|
||||
root.Dirty(ChangeType.Transform);
|
||||
root.renderData.lastLayout = new Rect(root.cssNode.LayoutX, root.cssNode.LayoutY, root.cssNode.LayoutWidth, root.cssNode.LayoutHeight);
|
||||
}
|
||||
bool flag = root.cssNode.HasNewLayout;
|
||||
if (flag)
|
||||
{
|
||||
VisualContainer visualContainer = root as VisualContainer;
|
||||
if (visualContainer != null)
|
||||
{
|
||||
foreach (VisualElement visualElement in visualContainer)
|
||||
{
|
||||
flag |= this.ValidateSubTree(visualElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
root.OnPostLayout(flag);
|
||||
root.ClearDirty(ChangeType.Layout);
|
||||
root.cssNode.MarkLayoutSeen();
|
||||
return flag;
|
||||
}
|
||||
|
||||
// Token: 0x06003369 RID: 13161 RVA: 0x000500C0 File Offset: 0x0004E2C0
|
||||
private Rect ComputeAAAlignedBound(Rect position, Matrix4x4 mat)
|
||||
{
|
||||
Rect rect = position;
|
||||
Vector3 vector = mat.MultiplyPoint3x4(new Vector3(rect.x, rect.y, 0f));
|
||||
Vector3 vector2 = mat.MultiplyPoint3x4(new Vector3(rect.x + rect.width, rect.y, 0f));
|
||||
Vector3 vector3 = mat.MultiplyPoint3x4(new Vector3(rect.x, rect.y + rect.height, 0f));
|
||||
Vector3 vector4 = mat.MultiplyPoint3x4(new Vector3(rect.x + rect.width, rect.y + rect.height, 0f));
|
||||
return Rect.MinMaxRect(Mathf.Min(vector.x, Mathf.Min(vector2.x, Mathf.Min(vector3.x, vector4.x))), Mathf.Min(vector.y, Mathf.Min(vector2.y, Mathf.Min(vector3.y, vector4.y))), Mathf.Max(vector.x, Mathf.Max(vector2.x, Mathf.Max(vector3.x, vector4.x))), Mathf.Max(vector.y, Mathf.Max(vector2.y, Mathf.Max(vector3.y, vector4.y))));
|
||||
}
|
||||
|
||||
// Token: 0x0600336A RID: 13162 RVA: 0x0005022C File Offset: 0x0004E42C
|
||||
public void PaintSubTree(Event e, VisualElement root, Matrix4x4 offset, Rect currentGlobalClip)
|
||||
{
|
||||
if ((root.pseudoStates & PseudoStates.Invisible) != PseudoStates.Invisible)
|
||||
{
|
||||
VisualContainer visualContainer = root as VisualContainer;
|
||||
if (visualContainer != null)
|
||||
{
|
||||
if (visualContainer.clipChildren)
|
||||
{
|
||||
Rect rect = this.ComputeAAAlignedBound(root.position, offset * root.globalTransform);
|
||||
if (!rect.Overlaps(currentGlobalClip))
|
||||
{
|
||||
return;
|
||||
}
|
||||
float num = Mathf.Max(rect.x, currentGlobalClip.x);
|
||||
float num2 = Mathf.Min(rect.x + rect.width, currentGlobalClip.x + currentGlobalClip.width);
|
||||
float num3 = Mathf.Max(rect.y, currentGlobalClip.y);
|
||||
float num4 = Mathf.Min(rect.y + rect.height, currentGlobalClip.y + currentGlobalClip.height);
|
||||
currentGlobalClip = new Rect(num, num3, num2 - num, num4 - num3);
|
||||
}
|
||||
}
|
||||
else if (!this.ComputeAAAlignedBound(root.globalBound, offset).Overlaps(currentGlobalClip))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (root.usePixelCaching && this.allowPixelCaching && root.globalBound.size.magnitude > Mathf.Epsilon)
|
||||
{
|
||||
IStylePainter stylePainter = this.stylePainter;
|
||||
Rect globalBound = root.globalBound;
|
||||
int num5 = (int)globalBound.width;
|
||||
int num6 = (int)globalBound.height;
|
||||
int num7 = (int)(globalBound.width * GUIUtility.pixelsPerPoint);
|
||||
int num8 = (int)(globalBound.height * GUIUtility.pixelsPerPoint);
|
||||
RenderTexture renderTexture = root.renderData.pixelCache;
|
||||
if (renderTexture != null && renderTexture.width != num7 && renderTexture.height != num8)
|
||||
{
|
||||
Object.DestroyImmediate(renderTexture);
|
||||
root.renderData.pixelCache = null;
|
||||
}
|
||||
float opacity = this.stylePainter.opacity;
|
||||
if (root.IsDirty(ChangeType.Repaint) || root.renderData.pixelCache == null)
|
||||
{
|
||||
if (renderTexture == null)
|
||||
{
|
||||
renderTexture = (root.renderData.pixelCache = new RenderTexture(num7, num8, 32, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear));
|
||||
}
|
||||
RenderTexture active = RenderTexture.active;
|
||||
RenderTexture.active = renderTexture;
|
||||
GL.Clear(true, true, new Color(0f, 0f, 0f, 0f));
|
||||
offset = Matrix4x4.Translate(new Vector3(-globalBound.x, -globalBound.y, 0f));
|
||||
Rect rect2 = new Rect(0f, 0f, (float)num5, (float)num6);
|
||||
GUIClip.SetTransform(offset * root.globalTransform, rect2);
|
||||
stylePainter.currentWorldClip = currentGlobalClip;
|
||||
root.DoRepaint(stylePainter);
|
||||
root.ClearDirty(ChangeType.Repaint);
|
||||
if (visualContainer != null)
|
||||
{
|
||||
int childrenCount = visualContainer.childrenCount;
|
||||
for (int i = 0; i < childrenCount; i++)
|
||||
{
|
||||
VisualElement childAt = visualContainer.GetChildAt(i);
|
||||
this.PaintSubTree(e, childAt, offset, rect2);
|
||||
if (childrenCount != visualContainer.childrenCount)
|
||||
{
|
||||
throw new NotImplementedException("Visual tree is read-only during repaint");
|
||||
}
|
||||
}
|
||||
}
|
||||
RenderTexture.active = active;
|
||||
}
|
||||
stylePainter.currentWorldClip = currentGlobalClip;
|
||||
GUIClip.SetTransform(root.globalTransform, currentGlobalClip);
|
||||
stylePainter.DrawTexture(root.position, root.renderData.pixelCache, Color.white, ScaleMode.ScaleAndCrop, 0f, 0f, 0, 0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
GUIClip.SetTransform(offset * root.globalTransform, currentGlobalClip);
|
||||
this.stylePainter.currentWorldClip = currentGlobalClip;
|
||||
this.stylePainter.mousePosition = root.globalTransform.inverse.MultiplyPoint3x4(e.mousePosition);
|
||||
this.stylePainter.opacity = root.styles.opacity.GetSpecifiedValueOrDefault(1f);
|
||||
root.DoRepaint(this.stylePainter);
|
||||
this.stylePainter.opacity = 1f;
|
||||
root.ClearDirty(ChangeType.Repaint);
|
||||
if (visualContainer != null)
|
||||
{
|
||||
int childrenCount2 = visualContainer.childrenCount;
|
||||
for (int j = 0; j < childrenCount2; j++)
|
||||
{
|
||||
VisualElement childAt2 = visualContainer.GetChildAt(j);
|
||||
this.PaintSubTree(e, childAt2, offset, currentGlobalClip);
|
||||
if (childrenCount2 != visualContainer.childrenCount)
|
||||
{
|
||||
throw new NotImplementedException("Visual tree is read-only during repaint");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Token: 0x0600336B RID: 13163 RVA: 0x00050698 File Offset: 0x0004E898
|
||||
public override void Repaint(Event e)
|
||||
{
|
||||
this.ValidateLayout();
|
||||
this.stylePainter.repaintEvent = e;
|
||||
this.PaintSubTree(e, this.visualTree, Matrix4x4.identity, this.visualTree.position);
|
||||
}
|
||||
|
||||
// Token: 0x04000A86 RID: 2694
|
||||
private StyleContext m_StyleContext;
|
||||
|
||||
// Token: 0x04000A87 RID: 2695
|
||||
private VisualContainer m_RootContainer;
|
||||
|
||||
// Token: 0x04000A8B RID: 2699
|
||||
private TimerEventScheduler m_Scheduler;
|
||||
|
||||
// Token: 0x04000A92 RID: 2706
|
||||
private const int kMaxValidateLayoutCount = 5;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user