Skip to content

Commit 67d5d85

Browse files
author
Unity Technologies
committed
Unity 2023.3.0a3 C# reference source code
1 parent 906c689 commit 67d5d85

File tree

575 files changed

+12486
-6503
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

575 files changed

+12486
-6503
lines changed

Editor/Mono/Animation/AnimationWindow/AnimationWindowControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ private List<AnimationWindowKeyframe> GetKeys(PropertyModification[] modificatio
920920
int keyIndex = curve.GetKeyframeIndex(state.time);
921921
if (keyIndex >= 0)
922922
{
923-
keys.Add(curve.m_Keyframes[keyIndex]);
923+
keys.Add(curve.keyframes[keyIndex]);
924924
}
925925
}
926926
}

Editor/Mono/Animation/AnimationWindow/AnimationWindowCurve.cs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal class AnimationWindowCurve : IComparable<AnimationWindowCurve>, IEquata
1515
{
1616
public const float timeEpsilon = 0.00001f;
1717

18-
public List<AnimationWindowKeyframe> m_Keyframes;
18+
private List<AnimationWindowKeyframe> m_Keyframes;
1919

2020
private EditorCurveBinding m_Binding;
2121
private int m_BindingHashCode;
@@ -46,6 +46,8 @@ internal class AnimationWindowCurve : IComparable<AnimationWindowCurve>, IEquata
4646
public bool animationIsEditable { get { return m_SelectionBinding != null ? m_SelectionBinding.animationIsEditable : true; } }
4747
public int selectionID { get { return m_SelectionBinding != null ? m_SelectionBinding.id : 0; } }
4848

49+
public IReadOnlyList<AnimationWindowKeyframe> keyframes => m_Keyframes;
50+
4951
private object defaultValue
5052
{
5153
get
@@ -190,17 +192,10 @@ public AnimationCurve ToAnimationCurve()
190192
AnimationCurve animationCurve = new AnimationCurve();
191193
List<Keyframe> keys = new List<Keyframe>();
192194

193-
float lastFrameTime = float.MinValue;
194-
195195
for (int i = 0; i < length; i++)
196196
{
197-
// Make sure we don't get two keyframes in an exactly the same time. We just ignore those.
198-
if (Mathf.Abs(m_Keyframes[i].time - lastFrameTime) > AnimationWindowCurve.timeEpsilon)
199-
{
200-
Keyframe newKeyframe = m_Keyframes[i].ToKeyframe();
201-
keys.Add(newKeyframe);
202-
lastFrameTime = m_Keyframes[i].time;
203-
}
197+
Keyframe newKeyframe = m_Keyframes[i].ToKeyframe();
198+
keys.Add(newKeyframe);
204199
}
205200

206201
animationCurve.keys = keys.ToArray();
@@ -212,17 +207,10 @@ public ObjectReferenceKeyframe[] ToObjectCurve()
212207
int length = m_Keyframes.Count;
213208
List<ObjectReferenceKeyframe> keys = new List<ObjectReferenceKeyframe>();
214209

215-
float lastFrameTime = float.MinValue;
216-
217210
for (int i = 0; i < length; i++)
218211
{
219-
// Make sure we don't get two keyframes in an exactly the same time. We just ignore those.
220-
if (Mathf.Abs(m_Keyframes[i].time - lastFrameTime) > AnimationWindowCurve.timeEpsilon)
221-
{
222-
ObjectReferenceKeyframe newKeyframe = m_Keyframes[i].ToObjectReferenceKeyframe();
223-
lastFrameTime = newKeyframe.time;
224-
keys.Add(newKeyframe);
225-
}
212+
ObjectReferenceKeyframe newKeyframe = m_Keyframes[i].ToObjectReferenceKeyframe();
213+
keys.Add(newKeyframe);
226214
}
227215

228216
keys.Sort((a, b) => a.time.CompareTo(b.time));
@@ -301,6 +289,11 @@ public void RemoveKeyframe(AnimationKeyTime time)
301289
}
302290
}
303291

292+
public void RemoveKeyframe(AnimationWindowKeyframe keyframe)
293+
{
294+
m_Keyframes.Remove(keyframe);
295+
}
296+
304297
public bool HasKeyframe(AnimationKeyTime time)
305298
{
306299
return GetKeyframeIndex(time) != -1;

Editor/Mono/Animation/AnimationWindow/AnimationWindowHierarchyGUI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ private void DoCurveColorIndicator(Rect rect, AnimationWindowHierarchyNode node)
491491
{
492492
foreach (var curve in node.curves)
493493
{
494-
if (curve.m_Keyframes.Any(key => state.time.ContainsTime(key.time)))
494+
if (curve.keyframes.Any(key => state.time.ContainsTime(key.time)))
495495
{
496496
hasKey = true;
497497
}

Editor/Mono/Animation/AnimationWindow/AnimationWindowKeyframe.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ public int GetHash()
149149

150150
public int GetIndex()
151151
{
152-
for (int i = 0; i < curve.m_Keyframes.Count; i++)
152+
for (int i = 0; i < curve.keyframes.Count; i++)
153153
{
154-
if (curve.m_Keyframes[i] == this)
154+
if (curve.keyframes[i] == this)
155155
{
156156
return i;
157157
}

Editor/Mono/Animation/AnimationWindow/AnimationWindowState.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ private void SaveSelectedKeys(string undoLabel)
514514
List<AnimationWindowKeyframe> toBeDeleted = new List<AnimationWindowKeyframe>();
515515

516516
// If selected keys are dragged over non-selected keyframe at exact same time, then delete the unselected ones underneath
517-
foreach (AnimationWindowKeyframe other in snapshot.curve.m_Keyframes)
517+
foreach (AnimationWindowKeyframe other in snapshot.curve.keyframes)
518518
{
519519
// Keyframe is in selection, skip.
520520
if (snapshot.selectedKeys.Exists(liveEditKey => liveEditKey.key == other))
@@ -529,7 +529,7 @@ private void SaveSelectedKeys(string undoLabel)
529529

530530
foreach (AnimationWindowKeyframe deletedKey in toBeDeleted)
531531
{
532-
snapshot.curve.m_Keyframes.Remove(deletedKey);
532+
snapshot.curve.RemoveKeyframe(deletedKey);
533533
}
534534
}
535535

@@ -984,7 +984,7 @@ public AnimationWindowKeyframe activeKeyframe
984984
{
985985
foreach (AnimationWindowCurve curve in filteredCurves)
986986
{
987-
foreach (AnimationWindowKeyframe keyframe in curve.m_Keyframes)
987+
foreach (AnimationWindowKeyframe keyframe in curve.keyframes)
988988
{
989989
if (keyframe.GetHash() == m_ActiveKeyframeHash)
990990
m_ActiveKeyframeCache = keyframe;
@@ -1009,7 +1009,7 @@ public List<AnimationWindowKeyframe> selectedKeys
10091009
m_SelectedKeysCache = new List<AnimationWindowKeyframe>();
10101010
foreach (AnimationWindowCurve curve in filteredCurves)
10111011
{
1012-
foreach (AnimationWindowKeyframe keyframe in curve.m_Keyframes)
1012+
foreach (AnimationWindowKeyframe keyframe in curve.keyframes)
10131013
{
10141014
if (KeyIsSelected(keyframe))
10151015
{
@@ -1139,7 +1139,7 @@ public void DeleteKeys(List<AnimationWindowKeyframe> keys)
11391139
curves.Add(keyframe.curve);
11401140

11411141
UnselectKey(keyframe);
1142-
keyframe.curve.m_Keyframes.Remove(keyframe);
1142+
keyframe.curve.RemoveKeyframe(keyframe);
11431143
}
11441144

11451145
SaveCurves(activeAnimationClip, curves, kEditCurveUndoLabel);
@@ -1162,7 +1162,7 @@ public void StartLiveEdit()
11621162
{
11631163
LiveEditCurve snapshot = new LiveEditCurve();
11641164
snapshot.curve = selectedKey.curve;
1165-
foreach (AnimationWindowKeyframe key in selectedKey.curve.m_Keyframes)
1165+
foreach (AnimationWindowKeyframe key in selectedKey.curve.keyframes)
11661166
{
11671167
LiveEditKeyframe liveEditKey = new LiveEditKeyframe();
11681168
liveEditKey.keySnapshot = new AnimationWindowKeyframe(key);
@@ -1400,7 +1400,7 @@ public void CopyAllActiveCurves()
14001400
{
14011401
foreach (AnimationWindowCurve curve in activeCurves)
14021402
{
1403-
foreach (AnimationWindowKeyframe keyframe in curve.m_Keyframes)
1403+
foreach (AnimationWindowKeyframe keyframe in curve.keyframes)
14041404
{
14051405
s_KeyframeClipboard.Add(new AnimationWindowKeyframe(keyframe));
14061406
}
@@ -1476,14 +1476,16 @@ public void PasteKeys()
14761476
// Only allow pasting of key frame from numerical curves to numerical curves or from pptr curves to pptr curves.
14771477
if ((newKeyframe.time >= 0.0f) && (newKeyframe.curve != null) && (newKeyframe.curve.isPPtrCurve == keyframe.curve.isPPtrCurve))
14781478
{
1479-
if (newKeyframe.curve.HasKeyframe(AnimationKeyTime.Time(newKeyframe.time, newKeyframe.curve.clip.frameRate)))
1480-
newKeyframe.curve.RemoveKeyframe(AnimationKeyTime.Time(newKeyframe.time, newKeyframe.curve.clip.frameRate));
1479+
var keyTime = AnimationKeyTime.Time(newKeyframe.time, newKeyframe.curve.clip.frameRate);
1480+
1481+
if (newKeyframe.curve.HasKeyframe(keyTime))
1482+
newKeyframe.curve.RemoveKeyframe(keyTime);
14811483

14821484
// When copy-pasting multiple keyframes (curve), its a continous thing. This is why we delete the existing keyframes in the pasted range.
14831485
if (lastTargetCurve == newKeyframe.curve)
14841486
newKeyframe.curve.RemoveKeysAtRange(lastTime, newKeyframe.time);
14851487

1486-
newKeyframe.curve.m_Keyframes.Add(newKeyframe);
1488+
newKeyframe.curve.AddKeyframe(newKeyframe, keyTime);
14871489
SelectKey(newKeyframe);
14881490
// TODO: Optimize to only save curve once instead once per keyframe
14891491
SaveCurve(newKeyframe.curve.clip, newKeyframe.curve, kEditCurveUndoLabel);
@@ -1838,7 +1840,7 @@ public float clipFrameRate
18381840
// Reposition all keyframes to match the new sampling rate
18391841
foreach (var curve in allCurves)
18401842
{
1841-
foreach (var key in curve.m_Keyframes)
1843+
foreach (var key in curve.keyframes)
18421844
{
18431845
int frame = AnimationKeyTime.Time(key.time, clipFrameRate).frame;
18441846
key.time = AnimationKeyTime.Frame(frame, value).time;

Editor/Mono/Animation/AnimationWindow/AnimationWindowUtility.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ public static float GetNextKeyframeTime(AnimationWindowCurve[] curves, float cur
888888

889889
foreach (AnimationWindowCurve curve in curves)
890890
{
891-
foreach (AnimationWindowKeyframe keyframe in curve.m_Keyframes)
891+
foreach (AnimationWindowKeyframe keyframe in curve.keyframes)
892892
{
893893
AnimationKeyTime keyTime = AnimationKeyTime.Time(keyframe.time, frameRate);
894894
if (keyTime.frame <= candidateKeyTime.frame && keyTime.frame >= nextTime.frame)
@@ -914,7 +914,7 @@ public static float GetPreviousKeyframeTime(AnimationWindowCurve[] curves, float
914914

915915
foreach (AnimationWindowCurve curve in curves)
916916
{
917-
foreach (AnimationWindowKeyframe keyframe in curve.m_Keyframes)
917+
foreach (AnimationWindowKeyframe keyframe in curve.keyframes)
918918
{
919919
AnimationKeyTime keyTime = AnimationKeyTime.Time(keyframe.time, frameRate);
920920
if (keyTime.frame >= candidateKeyTime.frame && keyTime.frame <= previousTime.frame)
@@ -1299,8 +1299,8 @@ public static AnimationWindowKeyframe CurveSelectionToAnimationWindowKeyframe(Cu
12991299
{
13001300
int curveID = curve.GetHashCode();
13011301
if (curveID == curveSelection.curveID)
1302-
if (curve.m_Keyframes.Count > curveSelection.key)
1303-
return curve.m_Keyframes[curveSelection.key];
1302+
if (curve.keyframes.Count > curveSelection.key)
1303+
return curve.keyframes[curveSelection.key];
13041304
}
13051305

13061306
return null;

Editor/Mono/Animation/AnimationWindow/DopeLine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public List<AnimationWindowKeyframe> keys
9898
{
9999
m_Keys = new List<AnimationWindowKeyframe>();
100100
foreach (AnimationWindowCurve curve in m_Curves)
101-
foreach (AnimationWindowKeyframe key in curve.m_Keyframes)
101+
foreach (AnimationWindowKeyframe key in curve.keyframes)
102102
m_Keys.Add(key);
103103

104104
m_Keys.Sort((a, b) => a.time.CompareTo(b.time));

Editor/Mono/Animation/AnimationWindow/DopeSheetEditor.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ private void AssignSpriteToSpriteRenderer(AnimationWindowCurve curve)
806806
if (rootGameObject == null)
807807
return;
808808

809-
var hasValidCurve = curve.m_Keyframes.Count > 0 && curve.binding.type == typeof(SpriteRenderer);
809+
var hasValidCurve = curve.keyframes.Count > 0 && curve.binding.type == typeof(SpriteRenderer);
810810
if (!hasValidCurve)
811811
return;
812812

@@ -815,7 +815,7 @@ private void AssignSpriteToSpriteRenderer(AnimationWindowCurve curve)
815815
if (!hasValidSpriteRenderer)
816816
return;
817817

818-
var keyframe = curve.m_Keyframes[0];
818+
var keyframe = curve.keyframes[0];
819819
var sprite = keyframe.value as Sprite;
820820
if (sprite != null)
821821
{
@@ -1126,12 +1126,12 @@ public void FrameSelected()
11261126
{
11271127
foreach (AnimationWindowCurve curve in state.activeCurves)
11281128
{
1129-
int keyCount = curve.m_Keyframes.Count;
1129+
int keyCount = curve.keyframes.Count;
11301130

11311131
if (keyCount > 1)
11321132
{
1133-
Vector2 pt1 = new Vector2(curve.m_Keyframes[0].time, 0.0f);
1134-
Vector2 pt2 = new Vector2(curve.m_Keyframes[keyCount - 1].time, 0.0f);
1133+
Vector2 pt1 = new Vector2(curve.keyframes[0].time, 0.0f);
1134+
Vector2 pt2 = new Vector2(curve.keyframes[keyCount - 1].time, 0.0f);
11351135

11361136
if (firstKey)
11371137
{

Editor/Mono/AssetPreviewUpdater.cs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
// Copyright (c) Unity Technologies. For terms of use, see
33
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
44

5+
using System;
56
using UnityEngine;
6-
using UnityEngine.Scripting;
77
using UnityEngine.Rendering;
8+
using UnityEngine.Scripting;
9+
using Object = UnityEngine.Object;
810

911
namespace UnityEditor
1012
{
1113
internal static class AssetPreviewUpdater
1214
{
15+
static readonly Type[] s_InspectorsRequireFullPipelineInitialization = new[] { typeof(MaterialEditor), typeof(ModelInspector), typeof(GameObjectInspector) };
16+
1317
[RequiredByNativeCode]
1418
public static Texture2D CreatePreviewForAsset(Object obj, Object[] subAssets, string assetPath)
1519
{
@@ -19,17 +23,11 @@ public static Texture2D CreatePreviewForAsset(Object obj, Object[] subAssets, st
1923
// Generate a preview texture for an asset
2024
public static Texture2D CreatePreview(Object obj, Object[] subAssets, string assetPath, int width, int height)
2125
{
22-
if (obj == null)
23-
return null;
24-
25-
if (!RenderPipelineManager.pipelineSwitchCompleted)
26-
return null;
27-
28-
System.Type type = CustomEditorAttributes.FindCustomEditorType(obj, false);
26+
var type = CustomEditorAttributes.FindCustomEditorType(obj, false);
2927
if (type == null)
3028
return null;
3129

32-
System.Reflection.MethodInfo info = type.GetMethod("RenderStaticPreview");
30+
var info = type.GetMethod("RenderStaticPreview");
3331
if (info == null)
3432
{
3533
Debug.LogError("Fail to find RenderStaticPreview base method");
@@ -40,12 +38,29 @@ public static Texture2D CreatePreview(Object obj, Object[] subAssets, string ass
4038
return null;
4139

4240

43-
Editor editor = Editor.CreateEditor(obj);
41+
var editor = Editor.CreateEditor(obj);
4442

4543
if (editor == null)
4644
return null;
4745

48-
Texture2D tex = editor.RenderStaticPreview(assetPath, subAssets, width, height);
46+
//Check that Render Pipeline is ready
47+
var pipelineWasNotInitialized = !RenderPipelineManager.pipelineSwitchCompleted;
48+
49+
//We keep this call to initialize Render Pipeline when Render Pipeline is not ready
50+
var tex = editor.RenderStaticPreview(assetPath, subAssets, width, height);
51+
52+
//If Render Pipeline was not created before we will ignore the results and mark it dirty.
53+
if (pipelineWasNotInitialized)
54+
{
55+
for (int i = 0; i < s_InspectorsRequireFullPipelineInitialization.Length; i++)
56+
{
57+
if (type != s_InspectorsRequireFullPipelineInitialization[i])
58+
continue;
59+
EditorUtility.SetDirty(obj);
60+
Object.DestroyImmediate(editor);
61+
return null;
62+
}
63+
}
4964

5065
// For debugging we write the preview to a file (keep)
5166
//{

Editor/Mono/Audio/AudioContainerWindow.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ void CreateGUI()
193193

194194
var styleSheet = UIToolkitUtilities.LoadStyleSheet("StyleSheets/Audio/AudioRandomContainer.uss");
195195
rootVisualElement.styleSheets.Add(styleSheet);
196+
rootVisualElement.Add(State.GetResourceTrackerElement());
196197

197198
m_ContainerRootVisualElement = UIToolkitUtilities.GetChildByName<ScrollView>(rootVisualElement, "ARC_ScrollView");
198199
m_Day0RootVisualElement = UIToolkitUtilities.GetChildByName<VisualElement>(rootVisualElement, "Day0");

0 commit comments

Comments
 (0)