Skip to content

Commit

Permalink
Unity 6000.1.0a2 C# reference source code
Browse files Browse the repository at this point in the history
  • Loading branch information
Unity Technologies committed Oct 30, 2024
1 parent 5e328f0 commit 59e16ee
Show file tree
Hide file tree
Showing 220 changed files with 5,187 additions and 1,560 deletions.
19 changes: 14 additions & 5 deletions Editor/Mono/AssetPipeline/SpeedTree/SpeedTree9Importer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@

namespace UnityEditor.SpeedTree.Importer
{
// [2024-08-07] version: 2
// Fixed mesh's UV2 & UV3 data usage strategy to 'always allocate' from 'conditionally allocate'
// to fix unwanted application of leaf-facing effect to geometries without leaf-facing data.

[ScriptedImporter(version: 2, ext: "st9", AllowCaching = true)]
// [2024-09-27] version: 3
// Fixed code that would lead to m_LODCount vs m_PerLODSettings.arraySize mismatching in GUI
[ScriptedImporter(version: 3, ext: "st9", AllowCaching = true)]
public class SpeedTree9Importer : ScriptedImporter
{
const int SPEEDTREE_9_WIND_VERSION = 1;
Expand Down Expand Up @@ -233,6 +231,16 @@ private void CacheTreeImporterValues(string assetPath)
{
// Variables used a lot are cached, since accessing any Reader array has a non-negligeable cost.
m_LODCount = (uint)m_Tree.Lod.Length;
if(m_LODCount > LODGroupGUI.kLODColors.Length)
{
Debug.LogWarningFormat("Number of LOD meshes in asset ({0}) is larger than the maximum number supported by Unity GUI ({1})." +
"\nImporting only the first {1} LOD meshes."
, m_LODCount, LODGroupGUI.kLODColors.Length);

// LODGroup GUI won't draw if we're above this limit, so we prevent future assertions here.
m_LODCount = (uint)LODGroupGUI.kLODColors.Length;
}

m_HasFacingData = TreeHasFacingData();
m_HasBranch2Data = m_Tree.Wind.DoBranch2;
m_LastLodIsBillboard = m_Tree.BillboardInfo.LastLodIsBillboard;
Expand Down Expand Up @@ -532,6 +540,7 @@ private void CalculateBillboardAndPerLODSettings()
}
else if (m_PerLODSettings.Count < m_LODCount)
{
m_PerLODSettings.Clear();
for (int i = 0; i < m_LODCount; ++i)
{
bool isBillboardLOD = m_LastLodIsBillboard && i == m_LODCount - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,12 @@ private void DrawLODGroupFoldouts(List<LODGroupGUI.LODInfo> lods)
private string GetLODSubmeshAndTriCountLabel(int numLODs, int lodGroupIndex, SpeedTree9Importer im, LODGroup lodGroup)
{
LOD[] lods = lodGroup.GetLODs();
Debug.Assert(lods.Length == numLODs);

if(lods.Length != numLODs)
{
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);
numLODs = lods.Length;
}

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

private Color GetLODGroupColor(int lodIndex)
{
return LODGroupGUI.kLODColors[lodIndex % LODGroupGUI.kLODColors.Length];
}

private void DrawLODGroupFoldout(Camera camera, int lodGroupIndex, ref SavedBool foldoutState, List<LODGroupGUI.LODInfo> lodInfoList)
{
GameObject[] ObjectArrayToGameObjectArray(UnityEngine.Object[] objects)
Expand Down Expand Up @@ -598,7 +608,7 @@ GameObject[] ObjectArrayToGameObjectArray(UnityEngine.Object[] objects)
, foldoutState.value
, LODFoldoutHeaderLabel
, m_LODColorTextures[lodGroupIndex]
, LODGroupGUI.kLODColors[lodGroupIndex] * 0.6f // 0.5f magic number is copied from LODGroupsGUI.cs
, GetLODGroupColor(lodGroupIndex) * 0.6f // 0.5f magic number is copied from LODGroupsGUI.cs
, LODFoldoutHeaderGroupAdditionalText
);

Expand Down Expand Up @@ -727,13 +737,13 @@ void InitAndSetFoldoutLabelTextures()
for (int i = 0; i < m_LODColorTextures.Length; i++)
{
m_LODColorTextures[i] = new Texture2D(1, 1);
m_LODColorTextures[i].SetPixel(0, 0, LODGroupGUI.kLODColors[i]);
m_LODColorTextures[i].SetPixel(0, 0, GetLODGroupColor(i));
}
}

void ResetFoldoutLists()
{
int lodArraySize = m_PerLODSettings.arraySize;
int lodArraySize = Mathf.Min(m_PerLODSettings.arraySize, LODGroupGUI.kLODColors.Length);
m_LODGroupFoldoutHeaderValues = new SavedBool[lodArraySize];
for (int i = 0; i < lodArraySize; i++)
{
Expand Down
9 changes: 7 additions & 2 deletions Editor/Mono/AssetPipeline/SpeedTreeImporter.bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,14 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse
bool st8 = asset.EndsWith(".st", StringComparison.OrdinalIgnoreCase);
if(st8)
{
SpeedTreeImporter importer = AssetImporter.GetAtPath(asset) as SpeedTreeImporter;
if (importer == null)
continue;

// Check the external materials in case the user has extracted
Dictionary<AssetImporter.SourceAssetIdentifier, UnityEngine.Object> externalAssets = (AssetImporter.GetAtPath(asset) as SpeedTreeImporter).GetExternalObjectMap();
FixExtraTexture_sRGB(externalAssets.Values);
Dictionary<AssetImporter.SourceAssetIdentifier, UnityEngine.Object> externalAssets = importer.GetExternalObjectMap();
if(externalAssets != null)
FixExtraTexture_sRGB(externalAssets.Values);

// Check the object subassets -- updates the materials if they're embedded in the SpeedTree asset
UnityEngine.Object[] subAssets = AssetDatabase.LoadAllAssetsAtPath(asset);
Expand Down
11 changes: 1 addition & 10 deletions Editor/Mono/AssetPreviewUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,9 @@ public static Texture2D CreatePreview(Object obj, Object[] subAssets, string ass
var editor = Editor.CreateEditor(obj);
if (editor == null)
return null;

//Check that Render Pipeline is ready
//Beware: AssetImportWorkers have their own Render Pipeline instance. Render Pipeline will be separately created for each one of them.
var pipelineWasNotInitialized = !RenderPipelineManager.pipelineSwitchCompleted;

//We always keep this call to initialize Render Pipeline when Render Pipeline was not ready

var previewTexture = editor.RenderStaticPreview(assetPath, subAssets, width, height);

//If after render our Render Pipeline is initialized we re-render to have a valid result
if (pipelineWasNotInitialized && RenderPipelineManager.pipelineSwitchCompleted)
previewTexture = editor.RenderStaticPreview(assetPath, subAssets, width, height);

// For debugging we write the preview to a file (keep)
//{
// var bytes = tex.EncodeToPNG();
Expand Down
4 changes: 2 additions & 2 deletions Editor/Mono/AssetStore/AssetStoreWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void OpenAssetStoreInBrowser()
[MenuItem("Window/My Assets", false, 1498)]
public static void OpenMyAssetsInPackageManager()
{
PackageManagerWindow.SelectPackageAndPageStatic(pageId: PackageManager.UI.Internal.MyAssetsPage.k_Id);
PackageManagerWindow.OpenAndSelectPage(PackageManager.UI.Internal.MyAssetsPage.k_Id);
}

public void OnEnable()
Expand Down Expand Up @@ -100,7 +100,7 @@ private void OnVisitWebsiteButtonClicked()

private void OnLaunchPackageManagerButtonClicked()
{
PackageManagerWindow.OpenPackageManager(null);
PackageManagerWindow.OpenAndSelectPackage(null);
}

private void SetMinMaxSizes()
Expand Down
56 changes: 29 additions & 27 deletions Editor/Mono/Audio/AudioContainerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,6 @@ void OnTargetChanged(object sender, EventArgs e)
m_CachedElements.Clear();
else
m_CachedElements = State.AudioContainer.elements.ToList();

m_AddedElements.Clear();
}

void OnSerializedObjectChanged(SerializedObject obj)
Expand Down Expand Up @@ -836,7 +834,17 @@ void OnElementPropertyChanged(SerializedProperty property)
void OnListItemsAdded(IEnumerable<int> indices)
{
var indicesArray = indices as int[] ?? indices.ToArray();
const string undoName = $"Add {nameof(AudioRandomContainer)} element";
var groupUndoName = undoName;

if (indicesArray.Length > 1)
{
groupUndoName = $"{undoName}s";
}

Undo.SetCurrentGroupName(groupUndoName);
var elements = State.AudioContainer.elements.ToList();
m_AddedElements.Clear();

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

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

// Object creation undo recording needs to be done in a separate pass from the object property changes above
foreach (var element in m_AddedElements)
Undo.RegisterCreatedObjectUndo(element, "Create AudioContainerElement");

m_AddedElements.Clear();

var undoName = $"Add {nameof(AudioRandomContainer)} element";

if (indicesArray.Length > 1)
{
undoName = $"{undoName}s";
Undo.RegisterCreatedObjectUndo(element, undoName);
}

Undo.SetCurrentGroupName(undoName);

m_AddedElements.Clear();
}

void OnListItemsRemoved(IEnumerable<int> indices)
Expand All @@ -881,13 +877,10 @@ void OnListItemsRemoved(IEnumerable<int> indices)
{
if (m_CachedElements[index] != null)
{
AssetDatabase.RemoveObjectFromAsset(m_CachedElements[index]);
Undo.DestroyObjectImmediate(m_CachedElements[index]);
}
}

State.AudioContainer.NotifyObservers(AudioRandomContainer.ChangeEventType.List);

var undoName = $"Remove {nameof(AudioRandomContainer)} element";

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

Undo.SetCurrentGroupName(undoName);
State.AudioContainer.NotifyObservers(AudioRandomContainer.ChangeEventType.List);
}

void OnItemListIndexChanged(int oldIndex, int newIndex)
Expand All @@ -906,14 +900,18 @@ void OnItemListIndexChanged(int oldIndex, int newIndex)

void OnAudioClipDrag(List<AudioClip> audioClips)
{
var undoName = $"Add {nameof(AudioRandomContainer)} element";
const string undoName = $"Add {nameof(AudioRandomContainer)} element";
var groupUndoName = undoName;

if (audioClips.Count > 1)
undoName = $"{undoName}s";

Undo.RegisterCompleteObjectUndo(State.AudioContainer, undoName);
{
groupUndoName = $"{undoName}s";
}

Undo.RegisterCompleteObjectUndo(State.AudioContainer, groupUndoName);
Undo.SetCurrentGroupName(groupUndoName);
var elements = State.AudioContainer.elements.ToList();
m_AddedElements.Clear();

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

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

// Object creation undo recording needs to be done in a separate pass from the object property changes above
foreach (var element in m_AddedElements)
Undo.RegisterCreatedObjectUndo(element, "Create AudioContainerElement");

m_AddedElements.Clear();
Undo.SetCurrentGroupName(undoName);
{
Undo.RegisterCreatedObjectUndo(element, undoName);
}
}

void OnAudioClipListChanged(SerializedProperty property)
Expand All @@ -948,6 +944,12 @@ void OnAudioClipListChanged(SerializedProperty property)

foreach (var elm in elements)
{
// If the element is null, OnBindListItem will handle it, log an error and grey out the list entry.
if (elm == null)
{
continue;
}

AssetDatabase.TryGetGUIDAndLocalFileIdentifier(elm, out var guid, out var localId);

// An empty asset GUID means the subasset has lost the reference
Expand Down
Loading

0 comments on commit 59e16ee

Please sign in to comment.