diff --git a/com.unity.formats.alembic/Editor/Importer/AlembicImporter.cs b/com.unity.formats.alembic/Editor/Importer/AlembicImporter.cs index 032d411f4..260e3231d 100644 --- a/com.unity.formats.alembic/Editor/Importer/AlembicImporter.cs +++ b/com.unity.formats.alembic/Editor/Importer/AlembicImporter.cs @@ -543,8 +543,7 @@ void GenerateSubAssets(Subassets subassets, AlembicTreeNode root, AlembicStreamD void CollectSubAssets(Subassets subassets, AlembicTreeNode node) { int submeshCount = 0; - var meshFilter = node.gameObject.GetComponent(); - if (meshFilter != null) + if (node.gameObject.TryGetComponent(out var meshFilter)) { var m = meshFilter.sharedMesh; submeshCount = m.subMeshCount; @@ -552,8 +551,7 @@ void CollectSubAssets(Subassets subassets, AlembicTreeNode node) subassets.Add(node.abcObject.abcObject.fullname, m); } - var renderer = node.gameObject.GetComponent(); - if (renderer != null) + if (node.gameObject.TryGetComponent(out var renderer)) { var mats = new Material[submeshCount]; for (int i = 0; i < submeshCount; ++i) @@ -561,8 +559,7 @@ void CollectSubAssets(Subassets subassets, AlembicTreeNode node) renderer.sharedMaterials = mats; } - var apr = node.gameObject.GetComponent(); - if (apr != null) + if (node.gameObject.TryGetComponent(out var apr)) { var cubeGO = GameObject.CreatePrimitive(PrimitiveType.Cube); apr.InstancedMesh = cubeGO.GetComponent().sharedMesh; diff --git a/com.unity.formats.alembic/Editor/Importer/AlembicImporterEditor.cs b/com.unity.formats.alembic/Editor/Importer/AlembicImporterEditor.cs index acfd012f4..6efa14ef6 100644 --- a/com.unity.formats.alembic/Editor/Importer/AlembicImporterEditor.cs +++ b/com.unity.formats.alembic/Editor/Importer/AlembicImporterEditor.cs @@ -337,7 +337,7 @@ void DrawMaterialUI(AlembicImporter importer, bool multiEdit) { importer.RemoveRemap(o.ToSourceAssetIdentifier()); } - else if (AssetDatabase.GetAssetPath(assign).ToLower().EndsWith("abc")) + else if (AssetDatabase.GetAssetPath(assign).EndsWith("abc", StringComparison.OrdinalIgnoreCase)) { Debug.LogError("Materials cannot be remapped to materials bundled with Alembic files."); } @@ -390,7 +390,7 @@ static Material LoadMaterial(string assetName, string[] searchPath) string.Equals(Path.GetFileNameWithoutExtension(str), assetName, StringComparison.CurrentCultureIgnoreCase)); - if (path == null || path.ToLower().EndsWith("abc")) // we don't want to assign materials from other alembics since these gets recreated on every re-import. + if (path == null || path.EndsWith("abc", StringComparison.OrdinalIgnoreCase)) // we don't want to assign materials from other alembics since these gets recreated on every re-import. { return null; } diff --git a/com.unity.formats.alembic/Runtime/Scripts/Exporter/AlembicExporter_impl.cs b/com.unity.formats.alembic/Runtime/Scripts/Exporter/AlembicExporter_impl.cs index edc34a3d0..a0bcc3985 100644 --- a/com.unity.formats.alembic/Runtime/Scripts/Exporter/AlembicExporter_impl.cs +++ b/com.unity.formats.alembic/Runtime/Scripts/Exporter/AlembicExporter_impl.cs @@ -651,8 +651,7 @@ class MeshCapturer : ComponentCapturer, IDisposable public override void Setup(Component c) { m_target = c as MeshRenderer; - MeshFilter meshFilter = m_target.GetComponent(); - if (meshFilter == null) + if (!m_target.TryGetComponent(out var meshFilter)) { m_target = null; return; @@ -712,8 +711,7 @@ public override void Setup(Component c) m_mbuf.SetupSubmeshes(abcObject, mesh); m_meshSrc = target.sharedMesh; - m_cloth = m_target.GetComponent(); - if (m_cloth != null) + if (m_target.TryGetComponent(out m_cloth)) { m_cbuf = new ClothBuffer(); m_cbuf.rootBone = m_target.rootBone != null ? m_target.rootBone : m_target.GetComponent(); diff --git a/com.unity.formats.alembic/Runtime/Scripts/Importer/AlembicElement.cs b/com.unity.formats.alembic/Runtime/Scripts/Importer/AlembicElement.cs index a2ddad805..d36895f2c 100644 --- a/com.unity.formats.alembic/Runtime/Scripts/Importer/AlembicElement.cs +++ b/com.unity.formats.alembic/Runtime/Scripts/Importer/AlembicElement.cs @@ -17,8 +17,7 @@ internal abstract class AlembicElement : IDisposable public Camera GetOrAddCamera() { - var c = abcTreeNode.gameObject.GetComponent(); - if (c == null) + if (!abcTreeNode.gameObject.TryGetComponent(out var c)) { c = abcTreeNode.gameObject.AddComponent(); c.usePhysicalProperties = true; diff --git a/com.unity.formats.alembic/Runtime/Scripts/Importer/AlembicMesh.cs b/com.unity.formats.alembic/Runtime/Scripts/Importer/AlembicMesh.cs index a40a4125d..3361c750c 100644 --- a/com.unity.formats.alembic/Runtime/Scripts/Importer/AlembicMesh.cs +++ b/com.unity.formats.alembic/Runtime/Scripts/Importer/AlembicMesh.cs @@ -322,8 +322,7 @@ public override void AbcSyncDataEnd() if (split.host == null) continue; - var mf = split.host.GetComponent(); - if (mf != null) + if (split.host.TryGetComponent(out var mf)) mf.sharedMesh = split.mesh; } #endif diff --git a/com.unity.formats.alembic/Runtime/Scripts/Importer/AlembicPoints.cs b/com.unity.formats.alembic/Runtime/Scripts/Importer/AlembicPoints.cs index 68e5ed0a5..651601534 100644 --- a/com.unity.formats.alembic/Runtime/Scripts/Importer/AlembicPoints.cs +++ b/com.unity.formats.alembic/Runtime/Scripts/Importer/AlembicPoints.cs @@ -29,8 +29,7 @@ public override void AbcPrepareSample() return; } - var cloud = abcTreeNode.gameObject.GetComponent(); - if (cloud != null) + if (abcTreeNode.gameObject.TryGetComponent(out var cloud)) { m_abcSchema.sort = cloud.m_sort; if (cloud.m_sort && cloud.m_sortFrom != null) @@ -49,8 +48,7 @@ public override void AbcSyncDataBegin() sample.GetSummary(ref m_sampleSummary); // get points cloud component - var cloud = abcTreeNode.gameObject.GetComponent(); - if (cloud == null) + if (!abcTreeNode.gameObject.TryGetComponent(out var cloud)) { cloud = abcTreeNode.gameObject.AddComponent(); abcTreeNode.gameObject.AddComponent(); diff --git a/com.unity.formats.alembic/Runtime/Scripts/Importer/AlembicXForm.cs b/com.unity.formats.alembic/Runtime/Scripts/Importer/AlembicXForm.cs index 5c822d47e..3819cfca2 100644 --- a/com.unity.formats.alembic/Runtime/Scripts/Importer/AlembicXForm.cs +++ b/com.unity.formats.alembic/Runtime/Scripts/Importer/AlembicXForm.cs @@ -37,8 +37,7 @@ public override void AbcSyncDataEnd() } else { - trans.position = m_abcData.translation; - trans.rotation = m_abcData.rotation; + trans.SetPositionAndRotation(m_abcData.translation, m_abcData.rotation); trans.localScale = m_abcData.scale; } }