Skip to content

Commit 4e215c0

Browse files
author
Unity Technologies
committed
Unity 2023.3.0b6 C# reference source code
1 parent 2d4714b commit 4e215c0

File tree

26 files changed

+262
-70
lines changed

26 files changed

+262
-70
lines changed

Editor/Mono/EditorGUIUtility.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,16 +891,27 @@ internal static GUIContent IconContent<T>(string text = null) where T : UnityObj
891891
[ExcludeFromDocs]
892892
public static GUIContent IconContent(string name)
893893
{
894-
return IconContent(name, null);
894+
return IconContent(name, null, true);
895+
}
896+
897+
internal static GUIContent IconContent(string name, bool logError)
898+
{
899+
return IconContent(name, null, logError);
895900
}
896901

897902
public static GUIContent IconContent(string name, [DefaultValue("null")] string text)
903+
{
904+
return IconContent(name, text, true);
905+
}
906+
907+
internal static GUIContent IconContent(string name, [DefaultValue("null")] string text, bool logError)
898908
{
899909
GUIContent gc = (GUIContent)s_IconGUIContents[name];
900910
if (gc != null)
901911
{
902912
return gc;
903913
}
914+
904915
gc = new GUIContent();
905916

906917
if (text != null)
@@ -911,12 +922,13 @@ public static GUIContent IconContent(string name, [DefaultValue("null")] string
911922
gc.tooltip = strings[2];
912923
}
913924
}
914-
gc.image = LoadIconRequired(name);
925+
gc.image = logError ? LoadIconRequired(name) : LoadIcon(name);
926+
915927
s_IconGUIContents[name] = gc;
916928
return gc;
917929
}
918930

919-
private static GUIContent IconContent(Texture icon, string text)
931+
static GUIContent IconContent(Texture icon, string text)
920932
{
921933
GUIContent gc = text != null ? (GUIContent)s_IconGUIContents[text] : null;
922934
if (gc != null)

Editor/Mono/EditorWindow.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public partial class EditorWindow : ScriptableObject
4141
[HideInInspector]
4242
int m_AntiAliasing = 1;
4343

44+
[HideInInspector]
45+
bool m_ResetPanelRenderingOnAssetChange = true;
46+
4447
[SerializeField]
4548
[HideInInspector]
4649
internal Rect m_Pos = new Rect(0, 0, 320, 550);
@@ -519,6 +522,7 @@ internal void MakeParentsSettingsMatchMe()
519522
bool parentChanged = m_Parent.depthBufferBits != m_DepthBufferBits || m_Parent.antiAliasing != m_AntiAliasing;
520523
m_Parent.depthBufferBits = m_DepthBufferBits;
521524
m_Parent.antiAliasing = m_AntiAliasing;
525+
m_Parent.resetPanelRenderingOnAssetChange = m_ResetPanelRenderingOnAssetChange;
522526
m_Parent.SetInternalGameViewDimensions(m_GameViewRect, m_GameViewClippedRect, m_GameViewTargetSize);
523527
m_Parent.eventInterests = m_EventInterests;
524528
m_Parent.disableInputEvents = m_DisableInputEvents;
@@ -1154,6 +1158,12 @@ internal int antiAliasing
11541158
set { m_AntiAliasing = value; }
11551159
}
11561160

1161+
internal bool resetPanelRenderingOnAssetChange
1162+
{
1163+
get => m_ResetPanelRenderingOnAssetChange;
1164+
set => m_ResetPanelRenderingOnAssetChange = value;
1165+
}
1166+
11571167
internal void SetParentGameViewDimensions(Rect rect, Rect clippedRect, Vector2 targetSize)
11581168
{
11591169
m_GameViewRect = rect;

Editor/Mono/GUIView.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ internal partial class GUIView : View, IWindowModel
2121

2222
int m_DepthBufferBits = 0;
2323
int m_AntiAliasing = 1;
24+
bool m_ResetPanelRenderingOnAssetChange = true;
2425
bool m_AutoRepaintOnSceneChange = false;
2526
private IWindowBackend m_WindowBackend;
2627

@@ -154,6 +155,19 @@ public int antiAlias
154155
set { throw new NotSupportedException("AA is not supported on GUIViews"); }
155156
}
156157

158+
public bool resetPanelRenderingOnAssetChange
159+
{
160+
get => m_ResetPanelRenderingOnAssetChange;
161+
set
162+
{
163+
if (m_ResetPanelRenderingOnAssetChange != value)
164+
{
165+
m_ResetPanelRenderingOnAssetChange = value;
166+
windowBackend?.ResetPanelRenderingOnAssetChangeChanged();
167+
}
168+
}
169+
}
170+
157171
internal IWindowBackend windowBackend
158172
{
159173
get { return m_WindowBackend; }

Editor/Mono/Tools/EditorToolUtility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ internal static GUIContent GetIcon(Type editorToolType, bool forceReload = false
245245

246246
// First check if the tool as an icon attribute
247247
var iconPath = EditorGUIUtility.GetIconPathFromAttribute(editorToolType);
248-
if(!string.IsNullOrEmpty(iconPath) && (res.image = EditorGUIUtility.IconContent(iconPath).image))
248+
if(!string.IsNullOrEmpty(iconPath) && (res.image = EditorGUIUtility.IconContent(iconPath, false).image))
249249
goto ReturnToolbarIcon;
250250

251251
// Second check for the tool type itself

Editor/Mono/UIElements/Controls/GradientField.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,15 @@ internal static Gradient GradientCopy(Gradient other)
133133
/// USS class name for the content for the gradient visual in the <see cref="GradientField"/> element.
134134
/// </summary>
135135
public static readonly string contentUssClassName = ussClassName + "__content";
136+
/// <summary>
137+
/// USS class name for the background of the gradient visual in the <see cref="GradientField"/> element.
138+
/// </summary>
139+
public static readonly string backgroundUssClassName = ussClassName + "__background";
136140

137141
/// <summary>
138142
/// USS class name for border elements in elements of this type.
139143
/// </summary>
140-
[Obsolete("borderUssClass is not used anymore", false)]
144+
[Obsolete("borderUssClass is not used anymore", true)]
141145
public static readonly string borderUssClassName = ussClassName + "__border";
142146

143147
VisualElement m_GradientTextureImage;
@@ -159,19 +163,14 @@ public GradientField(string label)
159163
labelElement.AddToClassList(labelUssClassName);
160164
visualInput.AddToClassList(inputUssClassName);
161165

162-
m_GradientTextureImage = new VisualElement() { pickingMode = PickingMode.Ignore };
163-
m_GradientTextureImage.AddToClassList(contentUssClassName);
164-
visualInput.Add(m_GradientTextureImage);
166+
var background = new VisualElement { pickingMode = PickingMode.Ignore };
167+
background.AddToClassList(backgroundUssClassName);
168+
visualInput.Add(background);
165169

166-
// Keep creating and adding a VisualElement for the border even though it is not used anymore.
167-
// It is done to remain backwards compatible (c.f. obsoleted borderUssClassName).
168-
VisualElement borderElement = new VisualElement() { name = "unity-border", pickingMode = PickingMode.Ignore };
169-
170-
#pragma warning disable 0618 // borderUssClassName is now obsolete.
171-
borderElement.AddToClassList(borderUssClassName);
172-
#pragma warning restore 0618
170+
m_GradientTextureImage = new VisualElement { pickingMode = PickingMode.Ignore };
171+
m_GradientTextureImage.AddToClassList(contentUssClassName);
172+
background.Add(m_GradientTextureImage);
173173

174-
visualInput.Add(borderElement);
175174
rawValue = new Gradient();
176175
}
177176

Editor/Mono/WindowBackendManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ internal interface IWindowModel
2222
Action onGUIHandler { get; }
2323

2424
IWindowBackend windowBackend { get; set; }
25+
26+
bool resetPanelRenderingOnAssetChange { get; }
2527
}
2628

2729
[VisibleToOtherModules("UnityEditor.UIBuilderModule")]
@@ -50,6 +52,7 @@ internal interface IWindowBackend
5052

5153
void SizeChanged();
5254
void EventInterestsChanged();
55+
void ResetPanelRenderingOnAssetChangeChanged();
5356
}
5457

5558
internal interface IEditorWindowBackend : IWindowBackend

Modules/AndroidJNI/AndroidJNI.bindings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,12 @@ public void Dispose()
452452
// Deletes the global reference pointed to by <tt>obj</tt>.
453453
[ThreadSafe]
454454
public static extern void DeleteGlobalRef(IntPtr obj);
455+
// Checks that current thread is attached and deletes the global reference pointed to by <tt>obj</tt>.
456+
[ThreadSafe]
457+
internal static extern void QueueDeleteGlobalRef(IntPtr obj);
458+
// Returns the number of global references to delete in queue.
459+
[ThreadSafe]
460+
internal static extern uint GetQueueGlobalRefsCount();
455461
// Creates a new global weak reference to the object referred to by the <tt>obj</tt> argument.
456462
[ThreadSafe]
457463
public static extern IntPtr NewWeakGlobalRef(IntPtr obj);

Modules/AndroidJNI/AndroidJNISafe.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public static void DeleteGlobalRef(IntPtr globalref)
4141
if (globalref != IntPtr.Zero) AndroidJNI.DeleteGlobalRef(globalref);
4242
}
4343

44+
public static void QueueDeleteGlobalRef(IntPtr globalref)
45+
{
46+
if (globalref != IntPtr.Zero) AndroidJNI.QueueDeleteGlobalRef(globalref);
47+
}
48+
4449
public static void DeleteWeakGlobalRef(IntPtr globalref)
4550
{
4651
if (globalref != IntPtr.Zero) AndroidJNI.DeleteWeakGlobalRef(globalref);

Modules/AndroidJNI/AndroidJava.cs

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void Dispose()
5757

5858
if (m_jobject != IntPtr.Zero)
5959
{
60-
AndroidJNISafe.DeleteGlobalRef(m_jobject);
60+
AndroidJNISafe.QueueDeleteGlobalRef(m_jobject);
6161
}
6262
}
6363

@@ -797,7 +797,9 @@ protected void _Set<FieldType>(IntPtr fieldID, FieldType val)
797797
AndroidJNISafe.SetCharField(m_jobject, fieldID, (Char)(object)val);
798798
}
799799
else if (typeof(FieldType) == typeof(String))
800+
{
800801
AndroidJNISafe.SetStringField(m_jobject, fieldID, (String)(object)val);
802+
}
801803
else if (typeof(FieldType) == typeof(AndroidJavaClass))
802804
{
803805
AndroidJNISafe.SetObjectField(m_jobject, fieldID, val == null ? IntPtr.Zero : ((AndroidJavaClass)(object)val).m_jclass);
@@ -806,10 +808,14 @@ protected void _Set<FieldType>(IntPtr fieldID, FieldType val)
806808
{
807809
AndroidJNISafe.SetObjectField(m_jobject, fieldID, val == null ? IntPtr.Zero : ((AndroidJavaObject)(object)val).m_jobject);
808810
}
811+
else if (AndroidReflection.IsAssignableFrom(typeof(AndroidJavaProxy), typeof(FieldType)))
812+
{
813+
AndroidJNISafe.SetObjectField(m_jobject, fieldID, val == null ? IntPtr.Zero : ((AndroidJavaProxy)(object)val).GetRawProxy());
814+
}
809815
else if (AndroidReflection.IsAssignableFrom(typeof(System.Array), typeof(FieldType)))
810816
{
811817
IntPtr jobject = AndroidJNIHelper.ConvertToJNIArray((Array)(object)val);
812-
AndroidJNISafe.SetObjectField(m_jclass, fieldID, jobject);
818+
AndroidJNISafe.SetObjectField(m_jobject, fieldID, jobject);
813819
}
814820
else
815821
{
@@ -1011,6 +1017,10 @@ protected void _SetStatic<FieldType>(IntPtr fieldID, FieldType val)
10111017
{
10121018
AndroidJNISafe.SetStaticObjectField(m_jclass, fieldID, val == null ? IntPtr.Zero : ((AndroidJavaObject)(object)val).m_jobject);
10131019
}
1020+
else if (AndroidReflection.IsAssignableFrom(typeof(AndroidJavaProxy), typeof(FieldType)))
1021+
{
1022+
AndroidJNISafe.SetStaticObjectField(m_jclass, fieldID, val == null ? IntPtr.Zero : ((AndroidJavaProxy)(object)val).GetRawProxy());
1023+
}
10141024
else if (AndroidReflection.IsAssignableFrom(typeof(System.Array), typeof(FieldType)))
10151025
{
10161026
IntPtr jobject = AndroidJNIHelper.ConvertToJNIArray((Array)(object)val);
@@ -1551,16 +1561,46 @@ public static IntPtr ConvertToJNIArray(System.Array array)
15511561
{
15521562
jniObjs[i] = objArray[i].GetRawObject();
15531563
IntPtr objectType = objArray[i].GetRawClass();
1554-
if (arrayType != objectType)
1564+
if (arrayType == IntPtr.Zero)
15551565
{
1556-
if (arrayType == IntPtr.Zero)
1557-
{
1558-
arrayType = objectType;
1559-
}
1560-
else
1561-
{
1562-
arrayType = fallBackType; // java/lang/Object
1563-
}
1566+
arrayType = objectType;
1567+
}
1568+
else if (arrayType != fallBackType && !AndroidJNI.IsSameObject(arrayType, objectType))
1569+
{
1570+
arrayType = fallBackType; // java/lang/Object
1571+
}
1572+
}
1573+
else
1574+
{
1575+
jniObjs[i] = IntPtr.Zero;
1576+
}
1577+
}
1578+
// zero sized array will call this with IntPtr.Zero type translated into java/lang/Object
1579+
IntPtr res = AndroidJNISafe.ToObjectArray(jniObjs, arrayType);
1580+
AndroidJNISafe.DeleteLocalRef(fallBackType);
1581+
return res;
1582+
}
1583+
else if (AndroidReflection.IsAssignableFrom(typeof(AndroidJavaProxy), type))
1584+
{
1585+
AndroidJavaProxy[] objArray = (AndroidJavaProxy[])array;
1586+
int arrayLen = array.GetLength(0);
1587+
IntPtr[] jniObjs = new IntPtr[arrayLen];
1588+
IntPtr fallBackType = AndroidJNISafe.FindClass("java/lang/Object");
1589+
IntPtr arrayType = IntPtr.Zero;
1590+
1591+
for (int i = 0; i < arrayLen; ++i)
1592+
{
1593+
if (objArray[i] != null)
1594+
{
1595+
jniObjs[i] = objArray[i].GetRawProxy();
1596+
IntPtr objectType = objArray[i].javaInterface.GetRawClass();
1597+
if (arrayType == IntPtr.Zero)
1598+
{
1599+
arrayType = objectType;
1600+
}
1601+
else if (arrayType != fallBackType && !AndroidJNI.IsSameObject(arrayType, objectType))
1602+
{
1603+
arrayType = fallBackType; // java/lang/Object
15641604
}
15651605
}
15661606
else
@@ -1573,6 +1613,7 @@ public static IntPtr ConvertToJNIArray(System.Array array)
15731613
AndroidJNISafe.DeleteLocalRef(fallBackType);
15741614
return res;
15751615
}
1616+
15761617
else
15771618
{
15781619
throw new Exception("JNI; Unknown array type '" + type + "'");
@@ -1832,6 +1873,13 @@ public static string GetSignature(object obj)
18321873
return "L" + javaClass.Call<System.String>("getName") + ";";
18331874
}
18341875
}
1876+
else if (obj == (object)type && AndroidReflection.IsAssignableFrom(typeof(AndroidJavaProxy), type))
1877+
{
1878+
// underlying Java class/interface can be found only for an actual object of 'type',
1879+
// and we cannot use Activator.CreateInstance(type) here because default constructor might not exist for 'type',
1880+
// returning empty string, this way ReflectionHelper finds field by name only.
1881+
return "";
1882+
}
18351883
else if (type.Equals(typeof(AndroidJavaRunnable)))
18361884
{
18371885
return "Ljava/lang/Runnable;";
@@ -1861,7 +1909,7 @@ public static string GetSignature(object obj)
18611909
System.Text.StringBuilder sb = new System.Text.StringBuilder();
18621910
sb.Append('[');
18631911
sb.Append(GetSignature(type.GetElementType()));
1864-
return sb.ToString();
1912+
return sb.Length > 1 ? sb.ToString() : "";
18651913
}
18661914
else
18671915
{

Modules/AndroidJNI/AssemblyInfo.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Unity C# reference source
2+
// Copyright (c) Unity Technologies. For terms of use, see
3+
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4+
5+
using System.Runtime.CompilerServices;
6+
7+
[assembly: InternalsVisibleTo("Assembly-CSharp-testable")]

0 commit comments

Comments
 (0)