Skip to content

Commit 59e16ee

Browse files
author
Unity Technologies
committed
Unity 6000.1.0a2 C# reference source code
1 parent 5e328f0 commit 59e16ee

File tree

220 files changed

+5187
-1560
lines changed

Some content is hidden

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

220 files changed

+5187
-1560
lines changed

Editor/Mono/AssetPipeline/SpeedTree/SpeedTree9Importer.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121

2222
namespace UnityEditor.SpeedTree.Importer
2323
{
24-
// [2024-08-07] version: 2
25-
// Fixed mesh's UV2 & UV3 data usage strategy to 'always allocate' from 'conditionally allocate'
26-
// to fix unwanted application of leaf-facing effect to geometries without leaf-facing data.
27-
28-
[ScriptedImporter(version: 2, ext: "st9", AllowCaching = true)]
24+
// [2024-09-27] version: 3
25+
// Fixed code that would lead to m_LODCount vs m_PerLODSettings.arraySize mismatching in GUI
26+
[ScriptedImporter(version: 3, ext: "st9", AllowCaching = true)]
2927
public class SpeedTree9Importer : ScriptedImporter
3028
{
3129
const int SPEEDTREE_9_WIND_VERSION = 1;
@@ -233,6 +231,16 @@ private void CacheTreeImporterValues(string assetPath)
233231
{
234232
// Variables used a lot are cached, since accessing any Reader array has a non-negligeable cost.
235233
m_LODCount = (uint)m_Tree.Lod.Length;
234+
if(m_LODCount > LODGroupGUI.kLODColors.Length)
235+
{
236+
Debug.LogWarningFormat("Number of LOD meshes in asset ({0}) is larger than the maximum number supported by Unity GUI ({1})." +
237+
"\nImporting only the first {1} LOD meshes."
238+
, m_LODCount, LODGroupGUI.kLODColors.Length);
239+
240+
// LODGroup GUI won't draw if we're above this limit, so we prevent future assertions here.
241+
m_LODCount = (uint)LODGroupGUI.kLODColors.Length;
242+
}
243+
236244
m_HasFacingData = TreeHasFacingData();
237245
m_HasBranch2Data = m_Tree.Wind.DoBranch2;
238246
m_LastLodIsBillboard = m_Tree.BillboardInfo.LastLodIsBillboard;
@@ -532,6 +540,7 @@ private void CalculateBillboardAndPerLODSettings()
532540
}
533541
else if (m_PerLODSettings.Count < m_LODCount)
534542
{
543+
m_PerLODSettings.Clear();
535544
for (int i = 0; i < m_LODCount; ++i)
536545
{
537546
bool isBillboardLOD = m_LastLodIsBillboard && i == m_LODCount - 1;

Editor/Mono/AssetPipeline/SpeedTree/SpeedTree9ImporterModelEditor.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,12 @@ private void DrawLODGroupFoldouts(List<LODGroupGUI.LODInfo> lods)
493493
private string GetLODSubmeshAndTriCountLabel(int numLODs, int lodGroupIndex, SpeedTree9Importer im, LODGroup lodGroup)
494494
{
495495
LOD[] lods = lodGroup.GetLODs();
496-
Debug.Assert(lods.Length == numLODs);
496+
497+
if(lods.Length != numLODs)
498+
{
499+
Debug.LogWarningFormat("Number of LODs mismatch between serialized object & LODGroup: {0}\nPlease re-import the asset and kindly report a bug if this warning keeps coming back.", im.assetPath);
500+
numLODs = lods.Length;
501+
}
497502

498503
int[][] primitiveCounts = new int[numLODs][];
499504
int[] submeshCounts = new int[numLODs];
@@ -547,6 +552,11 @@ private string GetLODSubmeshAndTriCountLabel(int numLODs, int lodGroupIndex, Spe
547552
return $"{totalTriCount} {LODGroupGUI.GUIStyles.m_TriangleCountLabel.text} {triangleChangeLabel} {submeshCountLabel}";
548553
}
549554

555+
private Color GetLODGroupColor(int lodIndex)
556+
{
557+
return LODGroupGUI.kLODColors[lodIndex % LODGroupGUI.kLODColors.Length];
558+
}
559+
550560
private void DrawLODGroupFoldout(Camera camera, int lodGroupIndex, ref SavedBool foldoutState, List<LODGroupGUI.LODInfo> lodInfoList)
551561
{
552562
GameObject[] ObjectArrayToGameObjectArray(UnityEngine.Object[] objects)
@@ -598,7 +608,7 @@ GameObject[] ObjectArrayToGameObjectArray(UnityEngine.Object[] objects)
598608
, foldoutState.value
599609
, LODFoldoutHeaderLabel
600610
, m_LODColorTextures[lodGroupIndex]
601-
, LODGroupGUI.kLODColors[lodGroupIndex] * 0.6f // 0.5f magic number is copied from LODGroupsGUI.cs
611+
, GetLODGroupColor(lodGroupIndex) * 0.6f // 0.5f magic number is copied from LODGroupsGUI.cs
602612
, LODFoldoutHeaderGroupAdditionalText
603613
);
604614

@@ -727,13 +737,13 @@ void InitAndSetFoldoutLabelTextures()
727737
for (int i = 0; i < m_LODColorTextures.Length; i++)
728738
{
729739
m_LODColorTextures[i] = new Texture2D(1, 1);
730-
m_LODColorTextures[i].SetPixel(0, 0, LODGroupGUI.kLODColors[i]);
740+
m_LODColorTextures[i].SetPixel(0, 0, GetLODGroupColor(i));
731741
}
732742
}
733743

734744
void ResetFoldoutLists()
735745
{
736-
int lodArraySize = m_PerLODSettings.arraySize;
746+
int lodArraySize = Mathf.Min(m_PerLODSettings.arraySize, LODGroupGUI.kLODColors.Length);
737747
m_LODGroupFoldoutHeaderValues = new SavedBool[lodArraySize];
738748
for (int i = 0; i < lodArraySize; i++)
739749
{

Editor/Mono/AssetPipeline/SpeedTreeImporter.bindings.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,14 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse
305305
bool st8 = asset.EndsWith(".st", StringComparison.OrdinalIgnoreCase);
306306
if(st8)
307307
{
308+
SpeedTreeImporter importer = AssetImporter.GetAtPath(asset) as SpeedTreeImporter;
309+
if (importer == null)
310+
continue;
311+
308312
// Check the external materials in case the user has extracted
309-
Dictionary<AssetImporter.SourceAssetIdentifier, UnityEngine.Object> externalAssets = (AssetImporter.GetAtPath(asset) as SpeedTreeImporter).GetExternalObjectMap();
310-
FixExtraTexture_sRGB(externalAssets.Values);
313+
Dictionary<AssetImporter.SourceAssetIdentifier, UnityEngine.Object> externalAssets = importer.GetExternalObjectMap();
314+
if(externalAssets != null)
315+
FixExtraTexture_sRGB(externalAssets.Values);
311316

312317
// Check the object subassets -- updates the materials if they're embedded in the SpeedTree asset
313318
UnityEngine.Object[] subAssets = AssetDatabase.LoadAllAssetsAtPath(asset);

Editor/Mono/AssetPreviewUpdater.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,9 @@ public static Texture2D CreatePreview(Object obj, Object[] subAssets, string ass
3636
var editor = Editor.CreateEditor(obj);
3737
if (editor == null)
3838
return null;
39-
40-
//Check that Render Pipeline is ready
41-
//Beware: AssetImportWorkers have their own Render Pipeline instance. Render Pipeline will be separately created for each one of them.
42-
var pipelineWasNotInitialized = !RenderPipelineManager.pipelineSwitchCompleted;
43-
44-
//We always keep this call to initialize Render Pipeline when Render Pipeline was not ready
39+
4540
var previewTexture = editor.RenderStaticPreview(assetPath, subAssets, width, height);
4641

47-
//If after render our Render Pipeline is initialized we re-render to have a valid result
48-
if (pipelineWasNotInitialized && RenderPipelineManager.pipelineSwitchCompleted)
49-
previewTexture = editor.RenderStaticPreview(assetPath, subAssets, width, height);
50-
5142
// For debugging we write the preview to a file (keep)
5243
//{
5344
// var bytes = tex.EncodeToPNG();

Editor/Mono/AssetStore/AssetStoreWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static void OpenAssetStoreInBrowser()
4242
[MenuItem("Window/My Assets", false, 1498)]
4343
public static void OpenMyAssetsInPackageManager()
4444
{
45-
PackageManagerWindow.SelectPackageAndPageStatic(pageId: PackageManager.UI.Internal.MyAssetsPage.k_Id);
45+
PackageManagerWindow.OpenAndSelectPage(PackageManager.UI.Internal.MyAssetsPage.k_Id);
4646
}
4747

4848
public void OnEnable()
@@ -100,7 +100,7 @@ private void OnVisitWebsiteButtonClicked()
100100

101101
private void OnLaunchPackageManagerButtonClicked()
102102
{
103-
PackageManagerWindow.OpenPackageManager(null);
103+
PackageManagerWindow.OpenAndSelectPackage(null);
104104
}
105105

106106
private void SetMinMaxSizes()

Editor/Mono/Audio/AudioContainerWindow.cs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,6 @@ void OnTargetChanged(object sender, EventArgs e)
348348
m_CachedElements.Clear();
349349
else
350350
m_CachedElements = State.AudioContainer.elements.ToList();
351-
352-
m_AddedElements.Clear();
353351
}
354352

355353
void OnSerializedObjectChanged(SerializedObject obj)
@@ -836,7 +834,17 @@ void OnElementPropertyChanged(SerializedProperty property)
836834
void OnListItemsAdded(IEnumerable<int> indices)
837835
{
838836
var indicesArray = indices as int[] ?? indices.ToArray();
837+
const string undoName = $"Add {nameof(AudioRandomContainer)} element";
838+
var groupUndoName = undoName;
839+
840+
if (indicesArray.Length > 1)
841+
{
842+
groupUndoName = $"{undoName}s";
843+
}
844+
845+
Undo.SetCurrentGroupName(groupUndoName);
839846
var elements = State.AudioContainer.elements.ToList();
847+
m_AddedElements.Clear();
840848

841849
foreach (var index in indicesArray)
842850
{
@@ -852,22 +860,10 @@ void OnListItemsAdded(IEnumerable<int> indices)
852860

853861
State.AudioContainer.elements = elements.ToArray();
854862

855-
// Object creation undo recording needs to be done in a separate pass from the object property changes above
856863
foreach (var element in m_AddedElements)
857-
Undo.RegisterCreatedObjectUndo(element, "Create AudioContainerElement");
858-
859-
m_AddedElements.Clear();
860-
861-
var undoName = $"Add {nameof(AudioRandomContainer)} element";
862-
863-
if (indicesArray.Length > 1)
864864
{
865-
undoName = $"{undoName}s";
865+
Undo.RegisterCreatedObjectUndo(element, undoName);
866866
}
867-
868-
Undo.SetCurrentGroupName(undoName);
869-
870-
m_AddedElements.Clear();
871867
}
872868

873869
void OnListItemsRemoved(IEnumerable<int> indices)
@@ -881,13 +877,10 @@ void OnListItemsRemoved(IEnumerable<int> indices)
881877
{
882878
if (m_CachedElements[index] != null)
883879
{
884-
AssetDatabase.RemoveObjectFromAsset(m_CachedElements[index]);
885880
Undo.DestroyObjectImmediate(m_CachedElements[index]);
886881
}
887882
}
888883

889-
State.AudioContainer.NotifyObservers(AudioRandomContainer.ChangeEventType.List);
890-
891884
var undoName = $"Remove {nameof(AudioRandomContainer)} element";
892885

893886
if (indicesArray.Length > 1)
@@ -896,6 +889,7 @@ void OnListItemsRemoved(IEnumerable<int> indices)
896889
}
897890

898891
Undo.SetCurrentGroupName(undoName);
892+
State.AudioContainer.NotifyObservers(AudioRandomContainer.ChangeEventType.List);
899893
}
900894

901895
void OnItemListIndexChanged(int oldIndex, int newIndex)
@@ -906,14 +900,18 @@ void OnItemListIndexChanged(int oldIndex, int newIndex)
906900

907901
void OnAudioClipDrag(List<AudioClip> audioClips)
908902
{
909-
var undoName = $"Add {nameof(AudioRandomContainer)} element";
903+
const string undoName = $"Add {nameof(AudioRandomContainer)} element";
904+
var groupUndoName = undoName;
910905

911906
if (audioClips.Count > 1)
912-
undoName = $"{undoName}s";
913-
914-
Undo.RegisterCompleteObjectUndo(State.AudioContainer, undoName);
907+
{
908+
groupUndoName = $"{undoName}s";
909+
}
915910

911+
Undo.RegisterCompleteObjectUndo(State.AudioContainer, groupUndoName);
912+
Undo.SetCurrentGroupName(groupUndoName);
916913
var elements = State.AudioContainer.elements.ToList();
914+
m_AddedElements.Clear();
917915

918916
foreach (var audioClip in audioClips)
919917
{
@@ -930,12 +928,10 @@ void OnAudioClipDrag(List<AudioClip> audioClips)
930928

931929
State.AudioContainer.elements = elements.ToArray();
932930

933-
// Object creation undo recording needs to be done in a separate pass from the object property changes above
934931
foreach (var element in m_AddedElements)
935-
Undo.RegisterCreatedObjectUndo(element, "Create AudioContainerElement");
936-
937-
m_AddedElements.Clear();
938-
Undo.SetCurrentGroupName(undoName);
932+
{
933+
Undo.RegisterCreatedObjectUndo(element, undoName);
934+
}
939935
}
940936

941937
void OnAudioClipListChanged(SerializedProperty property)
@@ -948,6 +944,12 @@ void OnAudioClipListChanged(SerializedProperty property)
948944

949945
foreach (var elm in elements)
950946
{
947+
// If the element is null, OnBindListItem will handle it, log an error and grey out the list entry.
948+
if (elm == null)
949+
{
950+
continue;
951+
}
952+
951953
AssetDatabase.TryGetGUIDAndLocalFileIdentifier(elm, out var guid, out var localId);
952954

953955
// An empty asset GUID means the subasset has lost the reference

0 commit comments

Comments
 (0)