From e0e005018f16b690e223f85365cacc3fc76d0662 Mon Sep 17 00:00:00 2001 From: IzayoiJiichan Date: Sat, 22 Jul 2023 00:00:00 +0900 Subject: [PATCH] version 2.5.11 --- CHANGELOG.md | 9 + Documentation~/UniVGO/Installation.ja.md | 32 +- Documentation~/UniVGO/Installation.md | 32 +- .../Runtime/Buffers/ArraySegmentByteBuffer.cs | 6 +- .../Buffers/ReadOnlyArraySegmentByteBuffer.cs | 10 + .../Enums/UnityEngine/ParticleSystemModule.cs | 270 ++++---- .../Runtime/Enums/UnityEngine/Rendering.cs | 24 +- .../Extensions/ArraySegmentExtensions.cs | 36 +- .../Extensions/CollectionsExtensions.cs | 6 +- .../Runtime/Extensions/StructureExtensions.cs | 4 +- .../Runtime/Extensions/SystemExtensions.cs | 6 +- NewtonVgo/Runtime/Helper/ThrowHelper.cs | 583 ++++++++++++++++++ NewtonVgo/Runtime/Models/ExModel.cs | 4 +- .../Runtime/Schema/Assets/VgoGeneratorInfo.cs | 4 +- NewtonVgo/Runtime/Schema/Assets/VgoRight.cs | 2 +- .../Schema/Extensions/VgoExtensions.cs | 25 +- NewtonVgo/Runtime/Security/AesCrypter.cs | 120 ++-- ...VgoMeshPrimitiveAttributesJsonConverter.cs | 13 +- NewtonVgo/Runtime/Storage/IVgoStorage.cs | 28 +- .../Runtime/Storage/VgoStorage.Export.cs | 49 +- .../Runtime/Storage/VgoStorage.Import.cs | 79 ++- .../Runtime/Storage/VgoStorageAdapter.cs | 29 +- NewtonVgo/Runtime/Structures/Bounds.cs | 24 +- NewtonVgo/Runtime/Structures/Color3.cs | 28 +- NewtonVgo/Runtime/Structures/Color4.cs | 28 +- NewtonVgo/Runtime/Structures/Vector4Ubyte.cs | 26 +- NewtonVgo/Runtime/Structures/Vector4Uint.cs | 30 +- NewtonVgo/Runtime/Structures/Vector4Ushort.cs | 30 +- UniVgo2/Editor/Inspector/ScriptEditorBase.cs | 4 +- .../Editor/Inspector/VgoBlendShapeEditor.cs | 22 +- .../Editor/Processors/VgoExportProcessor.cs | 14 +- .../ScriptedImporters/VgoScriptedImporter.cs | 20 +- .../VgoScriptedImporterEditor.cs | 2 +- UniVgo2/Runtime/Components/VgoBlendShape.cs | 52 +- .../Configurations/AvatarConfiguration.cs | 17 +- .../BlendShape/BlendShapeBlink.cs | 21 +- .../BlendShape/BlendShapeFacePart.cs | 21 +- .../BlendShape/BlendShapeViseme.cs | 21 +- .../Configurations/BlendShapeConfiguration.cs | 59 +- UniVgo2/Runtime/Converters/ArrayConverter.cs | 12 +- .../Converters/Textures/ColorSpaceScope.cs | 6 +- .../Converters/Textures/ITextureConverter.cs | 4 +- .../Textures/MetallicRoughnessMapConverter.cs | 14 +- .../Converters/Textures/NormalMapConverter.cs | 4 +- .../Textures/OcclusionMapConverter.cs | 8 +- .../Converters/Textures/TextureConverter.cs | 6 +- .../Converters/VgoAnimationClipConverter.cs | 10 +- .../Converters/VgoAnimationConverter.cs | 4 +- .../Converters/VgoAnimationCurveConverter.cs | 8 +- .../Converters/VgoAnimatorConverter.cs | 4 +- .../Runtime/Converters/VgoAvatarConverter.cs | 4 +- .../Runtime/Converters/VgoBoundsConverter.cs | 4 +- .../Runtime/Converters/VgoClothConverter.cs | 6 +- .../Converters/VgoColliderConverter.cs | 6 +- .../Converters/VgoGradientConverter.cs | 8 +- .../Converters/VgoKeyframeConverter.cs | 4 +- .../Runtime/Converters/VgoLightConverter.cs | 11 +- .../VgoParticleSystemBurstConverter.cs | 15 +- .../VgoParticleSystemMinMaxCurveConverter.cs | 4 +- ...goParticleSystemMinMaxGradientConverter.cs | 10 +- .../Converters/VgoPhysicMaterialConverter.cs | 6 +- .../Converters/VgoRigidbodyConverter.cs | 4 +- .../Converters/VgoTransformConverter.cs | 25 +- UniVgo2/Runtime/Extensions/ListExtensions.cs | 20 +- .../Extensions/UnityColorExtensions.cs | 23 +- UniVgo2/Runtime/Extensions/UnityExtensions.cs | 109 +++- .../Extensions/UnityGameObjectExtensions.cs | 2 +- .../Extensions/UnityMaterialExtensions.cs | 72 +-- .../Extensions/UnityNumericsExtensions.cs | 170 ++++- .../Extensions/VgoMaterialExtensions.cs | 34 +- UniVgo2/Runtime/Models/BlendShapeConfig.cs | 2 +- UniVgo2/Runtime/Models/ExportModelAsset.cs | 16 +- .../Porters/Interfaces/IMaterialPorter.cs | 4 +- .../Interfaces/IMaterialPorterStore.cs | 10 +- .../Interfaces/IVgoMaterialExporter.cs | 2 +- .../Interfaces/IVgoMaterialImporter.cs | 2 +- .../Porters/Interfaces/IVgoMeshExporter.cs | 2 +- .../Porters/Interfaces/IVgoMeshImporter.cs | 5 +- .../Interfaces/IVgoParticleSystemExporter.cs | 2 +- .../Interfaces/IVgoParticleSystemImporter.cs | 4 +- .../Porters/Interfaces/IVgoTextureExporter.cs | 2 +- .../Porters/Interfaces/IVgoTextureImporter.cs | 2 +- .../Materials/AbstractMaterialPorterBase.cs | 302 +++++---- .../Porters/Materials/HdrpMaterialPorter.cs | 10 +- .../Materials/LilToonMaterialPorter.cs | 32 +- .../Materials/Mtoon10MaterialPorter.cs | 75 ++- .../Porters/Materials/MtoonMaterialPorter.cs | 58 +- .../Materials/ParticleMaterialPorter.cs | 15 +- .../Porters/Materials/SkyboxMaterialPorter.cs | 4 +- .../Materials/StandardMaterialPorter.cs | 4 +- .../Materials/StandardVColorMaterialPorter.cs | 2 +- .../Porters/Materials/UnlitMaterialPorter.cs | 4 +- .../Porters/Materials/UrpMaterialPorter.cs | 10 +- .../Materials/UrpParticleMaterialPorter.cs | 6 +- .../Porters/Materials/VgoMaterialPorter.cs | 10 +- .../Materials/VgoMaterialPorterStore.cs | 10 +- .../Runtime/Porters/Meshes/VgoMeshExporter.cs | 37 +- .../Runtime/Porters/Meshes/VgoMeshImporter.cs | 48 +- .../VgoParticleSystemExporter.cs | 60 +- .../VgoParticleSystemImporter.cs | 61 +- .../Porters/Textures/VgoTextureExporter.cs | 7 +- .../Porters/Textures/VgoTextureImporter.cs | 4 +- UniVgo2/Runtime/Porters/VgoExporter.cs | 63 +- UniVgo2/Runtime/Porters/VgoImporter.cs | 93 +-- UniVgo2/Runtime/Shaders/IShaderStore.cs | 6 +- UniVgo2/Runtime/Shaders/ShaderStore.cs | 285 +++------ UniVgo2/Runtime/VgoVersion.cs | 4 +- package.json | 2 +- 108 files changed, 2399 insertions(+), 1273 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f853f7..c23676a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Change Log +## [2.5.11] - 2023-07-22 + +- Changes + - ScriptableObject fields are now accessed by properties. +- Improvements + - Program safety is enhanced. +- Fixes + - The MeshExporter export option was not done correctly. + ## [2.5.10] - 2023-07-17 - Features diff --git a/Documentation~/UniVGO/Installation.ja.md b/Documentation~/UniVGO/Installation.ja.md index 55264b7..495fd8b 100644 --- a/Documentation~/UniVGO/Installation.ja.md +++ b/Documentation~/UniVGO/Installation.ja.md @@ -44,7 +44,7 @@ Unity 2021.1 以下のバージョンを使用する場合 |com.izayoi.liltoon.shader.utility|IzayoiJiichan|GitHub||1.4.0|2023年5月30日| |com.izayoi.unishaders|IzayoiJiichan|GitHub||1.5.0|2023年7月17日| |com.izayoi.vgospringbone|IzayoiJiichan|GitHub||1.1.2|2022年8月24日| -|com.izayoi.univgo|IzayoiJiichan|GitHub|VGO 2.5|2.5.10|2023年7月17日| +|com.izayoi.univgo|IzayoiJiichan|GitHub|VGO 2.5|2.5.11|2023年7月22日| #### 追加パッケージ @@ -142,7 +142,7 @@ UniVGOを使用するために、以下の設定を追加してください。 "dependencies": { "com.izayoi.liltoon.shader.utility": "https://github.com/izayoijiichan/lilToonShaderUtility.git#v1.4.0", "com.izayoi.unishaders": "https://github.com/izayoijiichan/UniShaders.git#v1.5.0", - "com.izayoi.univgo": "https://github.com/izayoijiican/VGO.git#v2.5.10", + "com.izayoi.univgo": "https://github.com/izayoijiican/VGO.git#v2.5.11", "com.izayoi.vgospringbone": "https://github.com/izayoijiichan/VgoSpringBone.git#v1.1.2", "com.unity.nuget.newtonsoft-json": "3.2.1", "com.unity.ugui": "1.0.0", @@ -245,19 +245,19 @@ ___ |UniVRM|UniVGO|min Unity| |:---:|:---:|:---:| -|0.100.0|2.5.10|2020.3| -|0.101.0|2.5.10|2020.3| -|0.102.0|2.5.10|2020.3| -|0.103.2|2.5.10|2020.3| -|0.104.2|2.5.10|2020.3| -|0.105.0|2.5.10|2020.3| -|0.106.0|2.5.10|2020.3| -|0.107.2|2.5.10|2020.3| -|0.108.0|2.5.10|2020.3| -|0.109.0|2.5.10|2020.3| -|0.110.0|2.5.10|2020.3| -|0.111.0|2.5.10|2020.3| -|0.112.0|2.5.10|2020.3| +|0.100.0|2.5.11|2020.3| +|0.101.0|2.5.11|2020.3| +|0.102.0|2.5.11|2020.3| +|0.103.2|2.5.11|2020.3| +|0.104.2|2.5.11|2020.3| +|0.105.0|2.5.11|2020.3| +|0.106.0|2.5.11|2020.3| +|0.107.2|2.5.11|2020.3| +|0.108.0|2.5.11|2020.3| +|0.109.0|2.5.11|2020.3| +|0.110.0|2.5.11|2020.3| +|0.111.0|2.5.11|2020.3| +|0.112.0|2.5.11|2020.3| `/Packages/package.json` に以下の記述を行います。 @@ -288,7 +288,7 @@ https://github.com/izayoijiichan/VGO/wiki/How-to-use-UniVRM-and-UniVGO-together |2022.3.0f1|BRP|UniVGO + UniVRM|[Link](https://github.com/izayoijiichan/univgo2.sample.unity.project/tree/unity2022.3.brp.univrm)| ___ -最終更新日:2023年7月17日 +最終更新日:2023年7月22日 編集者:十六夜おじいちゃん *Copyright (C) 2020 Izayoi Jiichan. All Rights Reserved.* diff --git a/Documentation~/UniVGO/Installation.md b/Documentation~/UniVGO/Installation.md index 53e0980..5885e10 100644 --- a/Documentation~/UniVGO/Installation.md +++ b/Documentation~/UniVGO/Installation.md @@ -44,7 +44,7 @@ This package is required for any Unity version. |com.izayoi.liltoon.shader.utility|IzayoiJiichan|GitHub||1.4.0|30 May, 2023| |com.izayoi.unishaders|IzayoiJiichan|GitHub||1.5.0|17 Jul, 2023| |com.izayoi.vgospringbone|IzayoiJiichan|GitHub||1.1.2|24 Aug, 2022| -|com.izayoi.univgo|IzayoiJiichan|GitHub|VGO 2.5|2.5.10|17 Jul, 2023| +|com.izayoi.univgo|IzayoiJiichan|GitHub|VGO 2.5|2.5.11|22 Jul, 2023| #### Additional Packages @@ -141,7 +141,7 @@ To use UniVGO, add the following settings. "dependencies": { "com.izayoi.liltoon.shader.utility": "https://github.com/izayoijiichan/lilToonShaderUtility.git#v1.4.0", "com.izayoi.unishaders": "https://github.com/izayoijiichan/UniShaders.git#v1.5.0", - "com.izayoi.univgo": "https://github.com/izayoijiican/VGO.git#v2.5.10", + "com.izayoi.univgo": "https://github.com/izayoijiican/VGO.git#v2.5.11", "com.izayoi.vgospringbone": "https://github.com/izayoijiichan/VgoSpringBone.git#v1.1.2", "com.unity.nuget.newtonsoft-json": "3.2.1", "com.unity.ugui": "1.0.0", @@ -243,19 +243,19 @@ The version combinations are as follows. |UniVRM|UniVGO|min Unity| |:---:|:---:|:---:| -|0.100.0|2.5.10|2020.3| -|0.101.0|2.5.10|2020.3| -|0.102.0|2.5.10|2020.3| -|0.103.2|2.5.10|2020.3| -|0.104.2|2.5.10|2020.3| -|0.105.0|2.5.10|2020.3| -|0.106.0|2.5.10|2020.3| -|0.107.2|2.5.10|2020.3| -|0.108.0|2.5.10|2020.3| -|0.109.0|2.5.10|2020.3| -|0.110.0|2.5.10|2020.3| -|0.111.0|2.5.10|2020.3| -|0.112.0|2.5.10|2020.3| +|0.100.0|2.5.11|2020.3| +|0.101.0|2.5.11|2020.3| +|0.102.0|2.5.11|2020.3| +|0.103.2|2.5.11|2020.3| +|0.104.2|2.5.11|2020.3| +|0.105.0|2.5.11|2020.3| +|0.106.0|2.5.11|2020.3| +|0.107.2|2.5.11|2020.3| +|0.108.0|2.5.11|2020.3| +|0.109.0|2.5.11|2020.3| +|0.110.0|2.5.11|2020.3| +|0.111.0|2.5.11|2020.3| +|0.112.0|2.5.11|2020.3| Write the following in ` /Packages/package.json`. @@ -285,7 +285,7 @@ https://github.com/izayoijiichan/VGO/wiki/How-to-use-UniVRM-and-UniVGO-together |2022.3.0f1|BRP|UniVGO + UniVRM|[Link](https://github.com/izayoijiichan/univgo2.sample.unity.project/tree/unity2022.3.brp.univrm)| ___ -Last updated: 17 July, 2023 +Last updated: 22 July, 2023 Editor: Izayoi Jiichan *Copyright (C) 2020 Izayoi Jiichan. All Rights Reserved.* diff --git a/NewtonVgo/Runtime/Buffers/ArraySegmentByteBuffer.cs b/NewtonVgo/Runtime/Buffers/ArraySegmentByteBuffer.cs index 41e5137..2d933d9 100644 --- a/NewtonVgo/Runtime/Buffers/ArraySegmentByteBuffer.cs +++ b/NewtonVgo/Runtime/Buffers/ArraySegmentByteBuffer.cs @@ -69,9 +69,11 @@ public ArraySegmentByteBuffer(int capacity) /// Returns the size of the appended data. public int Append(ArraySegment data, int stride = 0) where T : struct { - if (data == null) + if (data.Array is null) { - ThrowHelper.ThrowArgumentNullException(nameof(data)); + ThrowHelper.ThrowArgumentException(nameof(data)); + + return 0; } if (data.Count == 0) diff --git a/NewtonVgo/Runtime/Buffers/ReadOnlyArraySegmentByteBuffer.cs b/NewtonVgo/Runtime/Buffers/ReadOnlyArraySegmentByteBuffer.cs index 9489b5a..9b1fef6 100644 --- a/NewtonVgo/Runtime/Buffers/ReadOnlyArraySegmentByteBuffer.cs +++ b/NewtonVgo/Runtime/Buffers/ReadOnlyArraySegmentByteBuffer.cs @@ -75,6 +75,16 @@ public ArraySegment GetBytes() /// A new byte array. public byte[] ToArray() { + if (_Bytes.Array is null) + { + return Array.Empty(); + } + + if (_Bytes.Count == 0) + { + return Array.Empty(); + } + byte[] destinationArray = new byte[_Bytes.Count]; Array.Copy(sourceArray: _Bytes.Array, _Bytes.Offset, destinationArray, 0, _Bytes.Count); diff --git a/NewtonVgo/Runtime/Enums/UnityEngine/ParticleSystemModule.cs b/NewtonVgo/Runtime/Enums/UnityEngine/ParticleSystemModule.cs index 4de55af..bb0bc01 100644 --- a/NewtonVgo/Runtime/Enums/UnityEngine/ParticleSystemModule.cs +++ b/NewtonVgo/Runtime/Enums/UnityEngine/ParticleSystemModule.cs @@ -5,361 +5,367 @@ #nullable enable namespace NewtonVgo { - /// + /// The animation mode. public enum ParticleSystemAnimationMode { - /// + /// Use a regular grid to construct a sequence of animation frames. Grid = 0, - /// + /// Use a list of sprites to construct a sequence of animation frames. Sprites = 1, } - /// + /// The mode used for selecting rows of an animation in the Texture Sheet Animation Module. public enum ParticleSystemAnimationRowMode { - /// + /// Use a specific row for all particles. Custom = 0, - /// + /// Use a random row for each particle. Random = 1, - /// + /// Use the mesh index as the row, so that meshes can be mapped to specific animation frames. MeshIndex = 2, } - /// + /// Control how animation frames are selected. public enum ParticleSystemAnimationTimeMode { - /// + /// Select animation frames based on the particle ages. Lifetime = 0, - /// + /// Select animation frames based on the particle speeds. Speed = 1, - /// + /// Select animation frames sequentially at a constant rate of the specified frames per second. FPS = 2, } - /// + /// The animation type. public enum ParticleSystemAnimationType { - /// + /// Animate over the whole texture sheet from left to right, top to bottom. WholeSheet = 0, - /// + /// Animate a single row in the sheet from left to right. SingleRow = 1, } - /// + /// Whether to use 2D or 3D colliders for particle collisions. public enum ParticleSystemCollisionMode { - /// + /// Use 3D colliders to collide particles against. Collision3D = 0, - /// + /// Use 2D colliders to collide particles against. Collision2D = 1, } - /// + /// Quality of world collisions. Medium and low quality are approximate and may leak particles. public enum ParticleSystemCollisionQuality { - /// + /// The most accurate world collisions. High = 0, - /// + /// Approximate world collisions. Medium = 1, - /// + /// Fastest and most approximate world collisions. Low = 2, } - /// + /// The type of collisions to use for a given Particle System. public enum ParticleSystemCollisionType { - /// + /// Collide with a list of planes. Planes = 0, - /// + /// Collide with the world geometry. World = 1, } - /// + /// The action to perform when the Particle System is offscreen. public enum ParticleSystemCullingMode { - /// + /// For looping effects, the simulation is paused when offscreen, and for one-shot effects, the simulation will continue playing. Automatic = 0, - /// + /// Pause the Particle System simulation when it is offscreen, and perform an extra simulation when the system comes back onscreen, creating the impression that it was never paused. PauseAndCatchup = 1, - /// + /// Pause the Particle System simulation when it is offscreen. Pause = 2, - /// + /// Continue simulating the Particle System when it is offscreen. AlwaysSimulate = 3, } - /// + /// The particle curve mode. public enum ParticleSystemCurveMode { - /// + /// Use a single constant for the MinMaxCurve. Constant = 0, - /// + /// Use a single curve for the MinMaxCurve. Curve = 1, - /// + /// Use a random value between 2 curves for the MinMaxCurve. TwoCurves = 2, - /// + /// Use a random value between 2 constants for the MinMaxCurve. TwoConstants = 3, } - /// + /// Control how a Particle System calculates its velocity. public enum ParticleSystemEmitterVelocityMode { - /// + /// Calculate the Particle System velocity by using the Transform component. Transform = 0, - /// + /// Calculate the Particle System velocity by using a Rigidbody or Rigidbody2D component, if one exists on the GameObject. Rigidbody = 1, + /// When the Particle System calculates its velocity, it instead uses the custom value set in ParticleSystem.MainModule.emitterVelocity. + Custom = 2, } - /// + /// The particle GameObject filtering mode that specifies which objects are used by specific Particle System modules. public enum ParticleSystemGameObjectFilter { - /// + /// Include objects based on a layer mask, where all objects that match the mask are included. LayerMask = 0, - /// + /// Include objects based on an explicitly provided list. List = 1, - /// + /// Include objects based on both a layer mask and an explicitly provided list. LayerMaskAndList = 2, } - /// + /// The particle gradient mode. public enum ParticleSystemGradientMode { - /// + /// Use a single color for the MinMaxGradient. Color = 0, - /// + /// Use a single color gradient for the MinMaxGradient. Gradient = 1, - /// + /// Use a random value between 2 colors for the MinMaxGradient. TwoColors = 2, - /// + /// Use a random value between 2 color gradients for the MinMaxGradient. TwoGradients = 3, - /// + /// Define a list of colors in the MinMaxGradient, to be chosen from at random. RandomColor = 4, } - /// + /// How to apply emitter velocity to particles. public enum ParticleSystemInheritVelocityMode { - /// + /// Each particle inherits the emitter's velocity on the frame when it was initially emitted. Initial = 0, - /// + /// Each particle's velocity is set to the emitter's current velocity value, every frame. Current = 1, } - /// + /// The mesh emission type. public enum ParticleSystemMeshShapeType { - /// + /// Emit from the vertices of the mesh. Vertex = 0, - /// + /// Emit from the edges of the mesh. Edge = 1, - /// + /// Emit from the surface of the mesh. Triangle = 2, } - /// + /// The quality of the generated noise. public enum ParticleSystemNoiseQuality { - /// + /// Low quality 1D noise. Low = 0, - /// + /// Medium quality 2D noise. Medium = 1, - /// + /// High quality 3D noise. High = 2, } - /// + /// What action to perform when the particle trigger module passes a test. public enum ParticleSystemOverlapAction { - /// + /// Do nothing. Ignore = 0, - /// + /// Kill all particles that pass this test. Kill = 1, - /// + /// Send the OnParticleTrigger command to the Particle System's script. Callback = 2, } - /// + /// The rendering mode for particle systems. public enum ParticleSystemRenderMode { - /// + /// Render particles as billboards facing the active camera. (Default) Billboard = 0, - /// + /// Stretch particles in the direction of motion. Stretch = 1, - /// + /// Render particles as billboards always facing up along the y-Axis. HorizontalBillboard = 2, - /// + /// Render particles as billboards always facing the player, but not pitching along the x-Axis. VerticalBillboard = 3, - /// + /// Render particles as meshes. Mesh = 4, - /// + /// Do not render particles. None = 5, } - /// + /// How particles are aligned when rendered. public enum ParticleSystemRenderSpace { - /// + /// Particles face the camera plane. View = 0, - /// + /// Particles align with the world. World = 1, - /// + /// Particles align with their local transform. Local = 2, - /// + /// Particles face the eye position. Facing = 3, - /// + /// Particles are aligned to their direction of travel. Velocity = 4, } - /// + /// Control how particles are removed from the Particle System. public enum ParticleSystemRingBufferMode { - /// + /// Particles are removed when their age exceeds their lifetime. Disabled = 0, - /// + /// Particle ages pause at the end of their lifetime until they need to be removed. Particles are removed when creating new particles would exceed the Max Particles property. PauseUntilReplaced = 1, - /// + /// Particle ages loop until they need to be removed. Particles are removed when creating new particles would exceed the Max Particles property. LoopUntilReplaced = 2, } - /// + /// Control how particle systems apply transform scale. public enum ParticleSystemScalingMode { - /// + /// Scale the Particle System using the entire transform hierarchy. Hierarchy = 0, - /// + /// Scale the Particle System using only its own transform scale. (Ignores parent scale). Local = 1, - /// + /// Only apply transform scale to the shape component, which controls where particles are spawned, but does not affect their size or movement. Shape = 2, } - /// + /// The mode used to generate new points in a shape. public enum ParticleSystemShapeMultiModeValue { - /// + /// Generate points randomly. (Default) Random = 0, - /// + /// Animate the emission point around the shape. Loop = 1, - /// + /// Animate the emission point around the shape, alternating between clockwise and counter-clockwise directions. PingPong = 2, - /// + /// Distribute new particles around the shape evenly. BurstSpread = 3, } - /// + /// The texture channel. public enum ParticleSystemShapeTextureChannel { - /// + /// The red channel. Red = 0, - /// + /// The green channel. Green = 1, - /// + /// The blue channel. Blue = 2, - /// + /// The alpha channel. Alpha = 3, } - /// + /// The emission shape. public enum ParticleSystemShapeType { - /// + /// Emit from a sphere. Sphere = 0, /// SphereShell = 1, - /// + /// Emit from a half-sphere. Hemisphere = 2, /// HemisphereShell = 3, - /// + /// Emit from the base of a cone. Cone = 4, - /// + /// Emit from the volume of a box. Box = 5, - /// + /// Emit from a mesh. Mesh = 6, /// ConeShell = 7, - /// + /// Emit from a cone. ConeVolume = 8, /// ConeVolumeShell = 9, - /// + /// Emit from a circle. Circle = 10, /// CircleEdge = 11, - /// + /// Emit from an edge. SingleSidedEdge = 12, - /// + /// Emit from a mesh renderer. MeshRenderer = 13, - /// + /// Emit from a skinned mesh renderer. SkinnedMeshRenderer = 14, - /// + /// Emit from the surface of a box. BoxShell = 15, - /// + /// Emit from the edges of a box. BoxEdge = 16, - /// + /// Emit from a Donut. Donut = 17, - /// + /// Emit from a rectangle. Rectangle = 18, - /// + /// Emit from a sprite. Sprite = 19, - /// + /// Emit from a sprite renderer. SpriteRenderer = 20, } - /// + /// The space to simulate particles in. public enum ParticleSystemSimulationSpace { - /// + /// Simulate particles in local space. Local = 0, - /// + /// Simulate particles in world space. World = 1, - /// + /// Simulate particles relative to a custom transform component, defined by ParticleSystem.MainModule.customSimulationSpace. Custom = 2, } - /// + /// The sorting mode for particle systems. public enum ParticleSystemSortMode { - /// + /// No sorting. None = 0, - /// + /// Sort based on distance to the camera position. For orthographic cameras, this mode is the same as sorting by depth. Distance = 1, - /// + /// Sort the oldest particles to the front. OldestInFront = 2, - /// + /// Sort the youngest particles to the front. YoungestInFront = 3, + /// Sort based on depth from the camera plane. + Depth = 4, } - /// + /// The action to perform when the Particle System stops. public enum ParticleSystemStopAction { - /// + /// Do nothing. None = 0, - /// + /// Disable the GameObject containing the Particle System. Disable = 1, - /// + /// Destroy the GameObject containing the Particle System. Destroy = 2, - /// + /// Call MonoBehaviour.OnParticleSystemStopped on all scripts attached to the same GameObject. Callback = 3, } - /// + /// Choose how Particle Trails are generated. public enum ParticleSystemTrailMode { - /// + /// Makes a trail behind each particle as the particle moves. PerParticle = 0, - /// + /// Draws a line between each particle, connecting the youngest particle to the oldest. Ribbon = 1, } - /// + /// Choose how textures are applied to Particle Trails. public enum ParticleSystemTrailTextureMode { - /// + /// Map the texture once along the entire length of the trail. Stretch = 0, - /// + /// Repeat the texture along the trail. To set the tiling rate, use Material.SetTextureScale. Tile = 1, - /// + /// Map the texture once along the entire length of the trail, assuming all vertices are evenly spaced. DistributePerSegment = 2, - /// + /// Repeat the texture along the trail, repeating at a rate of once per trail segment. To adjust the tiling rate, use Material.SetTextureScale. RepeatPerSegment = 3, + /// Trails do not change the texture coordinates of existing points when they add or remove points. + Static = 4, } } diff --git a/NewtonVgo/Runtime/Enums/UnityEngine/Rendering.cs b/NewtonVgo/Runtime/Enums/UnityEngine/Rendering.cs index 639c4b6..92833ca 100644 --- a/NewtonVgo/Runtime/Enums/UnityEngine/Rendering.cs +++ b/NewtonVgo/Runtime/Enums/UnityEngine/Rendering.cs @@ -7,15 +7,15 @@ namespace NewtonVgo { using System; - /// + /// Determines which faces Unity culls. public enum CullMode { - /// - Off, - /// - Front, - /// - Back, + /// Disable culling. + Off = 0, + /// Cull front-facing geometry. + Front = 1, + /// Cull back-facing geometry. + Back = 2, } /// Enum describing what part of a light contribution can be baked. @@ -155,16 +155,16 @@ public enum TextureDimension CubeArray = 6, } - /// + /// A flag representing each UV channel. public enum UVChannelFlags { - /// + /// First UV channel. UV0 = 0, - /// + /// Second UV channel. UV1 = 1, - /// + /// Third UV channel. UV2 = 2, - /// + /// Fourth UV channel. UV3 = 3, } } diff --git a/NewtonVgo/Runtime/Extensions/ArraySegmentExtensions.cs b/NewtonVgo/Runtime/Extensions/ArraySegmentExtensions.cs index 1719d8f..1d2b527 100644 --- a/NewtonVgo/Runtime/Extensions/ArraySegmentExtensions.cs +++ b/NewtonVgo/Runtime/Extensions/ArraySegmentExtensions.cs @@ -23,6 +23,18 @@ public static class ArraySegmentExtensions /// The copied byte size. public static int MarshalCopyTo(this ArraySegment src, T[] dst) where T : struct { + if (src.Array is null) + { + ThrowHelper.ThrowArgumentException(nameof(src)); + + return 0; + } + + if (src.Count == 0) + { + return 0; + } + int copySize = Marshal.SizeOf(typeof(T)) * dst.Length; using (Pin pin = Pin.Create(dst)) @@ -41,8 +53,20 @@ public static int MarshalCopyTo(this ArraySegment src, T[] dst) where T /// The index at which to begin the slice. /// The number of elements to include in the slice. /// - public static ArraySegment Slice(this ArraySegment self, int offset, int count) + public static ArraySegment Slice(this ArraySegment self, in int offset, in int count) { + if (self.Array is null) + { + ThrowHelper.ThrowArgumentException(nameof(self)); + + return self; + } + + if (self.Count == 0) + { + ThrowHelper.ThrowArgumentOutOfRangeException(nameof(self)); + } + return new ArraySegment(self.Array, self.Offset + offset, count); } @@ -53,6 +77,16 @@ public static ArraySegment Slice(this ArraySegment self, int offset, in /// A new byte array. public static byte[] ToArray(this ArraySegment self) { + if (self.Array is null) + { + return Array.Empty(); + } + + if (self.Count == 0) + { + return Array.Empty(); + } + byte[] destinationArray = new byte[self.Count]; Array.Copy(self.Array, self.Offset, destinationArray, 0, self.Count); diff --git a/NewtonVgo/Runtime/Extensions/CollectionsExtensions.cs b/NewtonVgo/Runtime/Extensions/CollectionsExtensions.cs index 86b22ff..b421481 100644 --- a/NewtonVgo/Runtime/Extensions/CollectionsExtensions.cs +++ b/NewtonVgo/Runtime/Extensions/CollectionsExtensions.cs @@ -33,7 +33,7 @@ public static void Deconstruct(this KeyValuePair pair, out T key, ou /// The list. /// The index of the list. /// - public static T? GetValueOrDefault(this IList list, int index) where T : class + public static T? GetValueOrDefault(this IList list, in int index) where T : class { if (index < 0) { @@ -54,7 +54,7 @@ public static void Deconstruct(this KeyValuePair pair, out T key, ou /// The list. /// The index of the list. /// - public static T? GetNullableValueOrDefault(this IList list, int index) where T : class + public static T? GetNullableValueOrDefault(this IList list, in int index) where T : class { if (index < 0) { @@ -77,7 +77,7 @@ public static void Deconstruct(this KeyValuePair pair, out T key, ou /// The index of the list. /// /// true if the list contains a item with the specified index; otherwise, false. - public static bool TryGetValue(this IList list, int index, out T item) where T : class + public static bool TryGetValue(this IList list, in int index, out T item) where T : class { item = default; diff --git a/NewtonVgo/Runtime/Extensions/StructureExtensions.cs b/NewtonVgo/Runtime/Extensions/StructureExtensions.cs index 4a0afc7..fae827a 100644 --- a/NewtonVgo/Runtime/Extensions/StructureExtensions.cs +++ b/NewtonVgo/Runtime/Extensions/StructureExtensions.cs @@ -67,8 +67,8 @@ public static T ConvertToStructure(this byte[] source) where T : struct { Marshal.Copy(source: source, startIndex: 0, destination: structurePointer, length: structureSize); - //structure = Marshal.PtrToStructure(structurePointer); - structure = (T)Marshal.PtrToStructure(structurePointer, structureType); + structure = Marshal.PtrToStructure(structurePointer); + //T? structure = (T?)Marshal.PtrToStructure(structurePointer, structureType); } catch (Exception) { diff --git a/NewtonVgo/Runtime/Extensions/SystemExtensions.cs b/NewtonVgo/Runtime/Extensions/SystemExtensions.cs index f431e38..770c712 100644 --- a/NewtonVgo/Runtime/Extensions/SystemExtensions.cs +++ b/NewtonVgo/Runtime/Extensions/SystemExtensions.cs @@ -19,7 +19,7 @@ public static class SystemExtensions /// /// /// - public static int SafeValue(this int value, int min, int max, int defaultValue = 0) + public static int SafeValue(this int value, in int min, in int max, in int defaultValue = 0) { if (value < min) { @@ -41,7 +41,7 @@ public static int SafeValue(this int value, int min, int max, int defaultValue = /// /// /// - public static float SafeValue(this float value, float min, float max, float defaultValue = 0.0f) + public static float SafeValue(this float value, in float min, in float max, in float defaultValue = 0.0f) { if (value < min) { @@ -62,7 +62,7 @@ public static float SafeValue(this float value, float min, float max, float defa /// /// /// Returns true if the index is in the range of the collection, false otherwise. - public static bool IsInRangeOf(this int index, ICollection collection) + public static bool IsInRangeOf(this int index, in ICollection collection) { if (collection == null) { diff --git a/NewtonVgo/Runtime/Helper/ThrowHelper.cs b/NewtonVgo/Runtime/Helper/ThrowHelper.cs index 45ec4a1..e535aa6 100644 --- a/NewtonVgo/Runtime/Helper/ThrowHelper.cs +++ b/NewtonVgo/Runtime/Helper/ThrowHelper.cs @@ -34,6 +34,10 @@ namespace NewtonVgo /// public static class ThrowHelper { + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -42,6 +46,10 @@ public static void ThrowAccessViolationException() throw new AccessViolationException(); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -50,6 +58,10 @@ public static void ThrowAggregateException() throw new AggregateException(); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -58,6 +70,10 @@ public static void ThrowApplicationException() throw new ApplicationException(); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -66,6 +82,11 @@ public static void ThrowArgumentException() throw new ArgumentException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -74,6 +95,12 @@ public static void ThrowArgumentException(in string parameterName) throw new ArgumentException(message: string.Empty, parameterName); } + /// + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -82,6 +109,10 @@ public static void ThrowArgumentException(in string parameterName, in string mes throw new ArgumentException(message, parameterName); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -90,6 +121,11 @@ public static void ThrowArgumentNullException() throw new ArgumentNullException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -98,6 +134,13 @@ public static void ThrowArgumentNullException(in string parameterName) throw new ArgumentNullException(parameterName); } + /// + /// + /// + /// + /// + /// + /// public static void ThrowExceptionIfArgumentIsNull(in string parameterName, in T parameter) where T : class? { if (parameter == null) @@ -106,6 +149,10 @@ public static void ThrowExceptionIfArgumentIsNull(in string parameterName, in } } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -114,6 +161,11 @@ public static void ThrowArgumentOutOfRangeException() throw new ArgumentOutOfRangeException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -122,6 +174,12 @@ public static void ThrowArgumentOutOfRangeException(in string parameterName) throw new ArgumentOutOfRangeException(parameterName); } + /// + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -130,6 +188,12 @@ public static void ThrowArgumentOutOfRangeException(in string parameterName, in throw new ArgumentOutOfRangeException(parameterName, message); } + /// + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -138,6 +202,13 @@ public static void ThrowArgumentOutOfRangeException(in string parameterName, in throw new ArgumentOutOfRangeException(parameterName, actualValue: parameterValue, message: string.Empty); } + /// + /// + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -216,6 +287,10 @@ public static void ThrowExceptionIfArgumentIsOutOfRange(in string parameterName, } } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -224,6 +299,10 @@ public static void ThrowArrayTypeMismatchException() throw new ArrayTypeMismatchException(); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -232,6 +311,11 @@ public static void ThrowAuthenticationException() throw new AuthenticationException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -240,6 +324,10 @@ public static void ThrowAuthenticationException(in string message) throw new AuthenticationException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -248,6 +336,11 @@ public static void ThrowBadImageFormatException() throw new BadImageFormatException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -256,6 +349,12 @@ public static void ThrowBadImageFormatException(in string fileName) throw new BadImageFormatException(message: string.Empty, fileName); } + /// + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -264,6 +363,10 @@ public static void ThrowBadImageFormatException(in string fileName, in string me throw new BadImageFormatException(message, fileName); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -272,6 +375,11 @@ public static void ThrowCryptographicException() throw new CryptographicException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -280,6 +388,10 @@ public static void ThrowCryptographicException(in string message) throw new CryptographicException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -289,6 +401,11 @@ public static void ThrowCryptographicUnexpectedOperationException() throw new CryptographicUnexpectedOperationException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -298,6 +415,10 @@ public static void ThrowCryptographicUnexpectedOperationException(in string mess throw new CryptographicUnexpectedOperationException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -306,6 +427,11 @@ public static void ThrowCultureNotFoundException() throw new CultureNotFoundException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -314,6 +440,12 @@ public static void ThrowCultureNotFoundException(in string parameterName) throw new CultureNotFoundException(parameterName, message: string.Empty); } + /// + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -322,6 +454,12 @@ public static void ThrowCultureNotFoundException(in string parameterName, in int throw new CultureNotFoundException(parameterName, invalidCultureId, message: string.Empty); } + /// + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -330,6 +468,13 @@ public static void ThrowCultureNotFoundException(in string parameterName, in str throw new CultureNotFoundException(parameterName, message); } + /// + /// + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -338,6 +483,10 @@ public static void ThrowCultureNotFoundException(in string parameterName, in int throw new CultureNotFoundException(parameterName, invalidCultureId, message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -346,6 +495,11 @@ public static void ThrowDataException() throw new DataException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -354,6 +508,10 @@ public static void ThrowDataException(in string s) throw new DataException(s); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -362,6 +520,11 @@ public static void ThrowDirectoryNotFoundException() throw new DirectoryNotFoundException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -370,6 +533,10 @@ public static void ThrowDirectoryNotFoundException(in string message) throw new DirectoryNotFoundException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -378,6 +545,10 @@ public static void ThrowDivideByZeroException() throw new DivideByZeroException(); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -386,6 +557,10 @@ public static void ThrowDllNotFoundException() throw new DllNotFoundException(); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -394,6 +569,11 @@ public static void ThrowDuplicateWaitObjectException() throw new DuplicateWaitObjectException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -402,6 +582,10 @@ public static void ThrowDuplicateWaitObjectException(in string parameterName) throw new DuplicateWaitObjectException(parameterName); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -410,6 +594,10 @@ public static void ThrowEndOfStreamException() throw new EndOfStreamException(); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -418,6 +606,10 @@ public static void ThrowEntryPointNotFoundException() throw new EntryPointNotFoundException(); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -426,6 +618,11 @@ public static void ThrowException() throw new Exception(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -434,6 +631,10 @@ public static void ThrowException(in string message) throw new Exception(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -442,6 +643,11 @@ public static void ThrowFileLoadException() throw new FileLoadException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -450,6 +656,12 @@ public static void ThrowFileLoadException(in string fileName) throw new FileLoadException(message: string.Empty, fileName); } + /// + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -458,6 +670,10 @@ public static void ThrowFileLoadException(in string fileName, in string message) throw new FileLoadException(message, fileName); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -466,6 +682,11 @@ public static void ThrowFileNotFoundException() throw new FileNotFoundException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -474,6 +695,12 @@ public static void ThrowFileNotFoundException(in string fileName) throw new FileNotFoundException(message: string.Empty, fileName); } + /// + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -482,6 +709,10 @@ public static void ThrowFileNotFoundException(in string fileName, in string mess throw new FileNotFoundException(message, fileName); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -490,6 +721,11 @@ public static void ThrowFormatException() throw new FormatException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -498,6 +734,10 @@ public static void ThrowFormatException(in string message) throw new FormatException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -506,6 +746,11 @@ public static void ThrowHttpRequestException() throw new HttpRequestException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -514,6 +759,10 @@ public static void ThrowHttpRequestException(in string message) throw new HttpRequestException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -522,12 +771,22 @@ public static void ThrowIndexOutOfRangeException() throw new IndexOutOfRangeException(); } + ///// + ///// + ///// + ///// + ///// //[DoesNotReturn] //public static void ThrowIndexOutOfRangeException(in string message) //{ // throw new IndexOutOfRangeException(message); //} + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -606,6 +865,10 @@ public static void ThrowExceptionIfIndexIsOutOfRange(in string parameterName, in } } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -614,6 +877,10 @@ public static void ThrowInternalBufferOverflowException() throw new InternalBufferOverflowException(); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -622,6 +889,11 @@ public static void ThrowInvalidCastException() throw new InvalidCastException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -630,6 +902,11 @@ public static void ThrowInvalidCastException(in int errorCode) throw new InvalidCastException(message: string.Empty, errorCode); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -638,6 +915,12 @@ public static void ThrowInvalidCastException(in string message) throw new InvalidCastException(message); } + /// + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -646,6 +929,10 @@ public static void ThrowInvalidCastException(in int errorCode, in string message throw new InvalidCastException(message, errorCode); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -654,6 +941,11 @@ public static void ThrowInvalidDataException() throw new InvalidDataException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -662,6 +954,10 @@ public static void ThrowInvalidDataException(in string message) throw new InvalidDataException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -670,6 +966,11 @@ public static void ThrowInvalidEnumArgumentException() throw new InvalidEnumArgumentException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -678,6 +979,10 @@ public static void ThrowInvalidEnumArgumentException(in string message) throw new InvalidEnumArgumentException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -687,6 +992,11 @@ public static void ThrowInvalidExpressionException() throw new InvalidExpressionException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -696,6 +1006,10 @@ public static void ThrowInvalidExpressionException(in string s) throw new InvalidExpressionException(s); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -704,6 +1018,11 @@ public static void ThrowInvalidOperationException() throw new InvalidOperationException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -712,6 +1031,10 @@ public static void ThrowInvalidOperationException(in string message) throw new InvalidOperationException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -720,6 +1043,11 @@ public static void ThrowInvalidProgramException() throw new InvalidProgramException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -728,6 +1056,10 @@ public static void ThrowInvalidProgramException(in string message) throw new InvalidProgramException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -736,6 +1068,11 @@ public static void ThrowInvalidTimeZoneException() throw new InvalidTimeZoneException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -744,6 +1081,10 @@ public static void ThrowInvalidTimeZoneException(in string message) throw new InvalidTimeZoneException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -752,6 +1093,11 @@ public static void ThrowIOException() throw new IOException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -760,6 +1106,11 @@ public static void ThrowIOException(in int hresult) throw new IOException(message: string.Empty, hresult); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -768,6 +1119,12 @@ public static void ThrowIOException(in string message) throw new IOException(message); } + /// + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -776,6 +1133,10 @@ public static void ThrowIOException(in int hresult, in string message) throw new IOException(message, hresult); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -784,6 +1145,11 @@ public static void ThrowKeyNotFoundException() throw new KeyNotFoundException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -792,6 +1158,10 @@ public static void ThrowKeyNotFoundException(in string message) throw new KeyNotFoundException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -800,6 +1170,11 @@ public static void ThrowNotFiniteNumberException() throw new NotFiniteNumberException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -808,6 +1183,11 @@ public static void ThrowNotFiniteNumberException(in double offendingNumber) throw new NotFiniteNumberException(message: string.Empty, offendingNumber); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -816,6 +1196,12 @@ public static void ThrowNotFiniteNumberException(in string message) throw new NotFiniteNumberException(message); } + /// + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -824,6 +1210,10 @@ public static void ThrowNotFiniteNumberException(in double offendingNumber, in s throw new NotFiniteNumberException(message, offendingNumber); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -832,6 +1222,11 @@ public static void ThrowNotImplementedException() throw new NotImplementedException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -840,6 +1235,10 @@ public static void ThrowNotImplementedException(in string message) throw new NotImplementedException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -848,6 +1247,11 @@ public static void ThrowNotSupportedException() throw new NotSupportedException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -856,6 +1260,10 @@ public static void ThrowNotSupportedException(in string message) throw new NotSupportedException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -864,6 +1272,11 @@ public static void ThrowNullReferenceException() throw new NullReferenceException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -872,6 +1285,11 @@ public static void ThrowNullReferenceException(in string message) throw new NullReferenceException(message); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -880,6 +1298,11 @@ public static void ThrowObjectDisposedException(string objectName) throw new ObjectDisposedException(objectName); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -888,6 +1311,11 @@ public static void ThrowObjectDisposedException(object obj) throw new ObjectDisposedException(obj.GetType().FullName); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -896,6 +1324,11 @@ public static void ThrowObjectDisposedException(Type objectType) throw new ObjectDisposedException(objectType.FullName); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -904,6 +1337,12 @@ public static void ThrowOperationCanceledException(CancellationToken token) throw new OperationCanceledException(token); } + /// + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -912,6 +1351,10 @@ public static void ThrowOperationCanceledException(CancellationToken token, in s throw new OperationCanceledException(message, token); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -920,6 +1363,11 @@ public static void ThrowOutOfMemoryException() throw new OutOfMemoryException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -928,6 +1376,10 @@ public static void ThrowOutOfMemoryException(in string message) throw new OutOfMemoryException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -936,6 +1388,11 @@ public static void ThrowOverflowException() throw new OverflowException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -944,6 +1401,10 @@ public static void ThrowOverflowException(in string message) throw new OverflowException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -952,6 +1413,11 @@ public static void ThrowPathTooLongException() throw new PathTooLongException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -960,6 +1426,10 @@ public static void ThrowPathTooLongException(in string message) throw new PathTooLongException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -968,6 +1438,11 @@ public static void ThrowPlatformNotSupportedException() throw new PlatformNotSupportedException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -976,6 +1451,10 @@ public static void ThrowPlatformNotSupportedException(in string message) throw new PlatformNotSupportedException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -984,6 +1463,11 @@ public static void ThrowRankException() throw new RankException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -992,6 +1476,10 @@ public static void ThrowRankException(in string message) throw new RankException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1000,6 +1488,11 @@ public static void ThrowReadOnlyException() throw new ReadOnlyException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1008,6 +1501,10 @@ public static void ThrowReadOnlyException(in string s) throw new ReadOnlyException(s); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1016,6 +1513,11 @@ public static void ThrowSecurityException() throw new SecurityException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1024,6 +1526,10 @@ public static void ThrowSecurityException(in string message) throw new SecurityException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1032,6 +1538,11 @@ public static void ThrowSerializationException() throw new SerializationException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1040,6 +1551,10 @@ public static void ThrowSerializationException(in string message) throw new SerializationException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1048,6 +1563,11 @@ public static void ThrowStackOverflowException() throw new StackOverflowException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1056,6 +1576,10 @@ public static void ThrowStackOverflowException(in string message) throw new StackOverflowException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1064,6 +1588,11 @@ public static void ThrowSystemException() throw new SystemException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1072,6 +1601,10 @@ public static void ThrowSystemException(in string message) throw new SystemException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1080,6 +1613,11 @@ public static void ThrowTimeoutException() throw new TimeoutException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1088,6 +1626,10 @@ public static void ThrowTimeoutException(in string message) throw new TimeoutException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1096,6 +1638,11 @@ public static void ThrowUnauthorizedAccessException() throw new UnauthorizedAccessException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1104,6 +1651,10 @@ public static void ThrowUnauthorizedAccessException(in string message) throw new UnauthorizedAccessException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1112,6 +1663,11 @@ public static void ThrowUriFormatException() throw new UriFormatException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1120,6 +1676,10 @@ public static void ThrowUriFormatException(in string textString) throw new UriFormatException(textString); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1128,6 +1688,11 @@ public static void ThrowVerificationException() throw new VerificationException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1136,6 +1701,10 @@ public static void ThrowVerificationException(in string message) throw new VerificationException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1144,6 +1713,11 @@ public static void ThrowWarningException() throw new WarningException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1152,6 +1726,10 @@ public static void ThrowWarningException(in string message) throw new WarningException(message); } + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif @@ -1160,6 +1738,11 @@ public static void ThrowWebException() throw new WebException(); } + /// + /// + /// + /// + /// #if NET_STANDARD_2_1 [DoesNotReturn] #endif diff --git a/NewtonVgo/Runtime/Models/ExModel.cs b/NewtonVgo/Runtime/Models/ExModel.cs index 316f088..52088ee 100644 --- a/NewtonVgo/Runtime/Models/ExModel.cs +++ b/NewtonVgo/Runtime/Models/ExModel.cs @@ -30,7 +30,7 @@ public class ExModel /// /// /// - public ExModel(string key, string json) + public ExModel(in string key, in string json) { ThrowHelper.ThrowExceptionIfArgumentIsNull(nameof(key), key); ThrowHelper.ThrowExceptionIfArgumentIsNull(nameof(json), json); @@ -48,7 +48,7 @@ public ExModel(string key, string json) /// /// /// true if the value is the same; otherwise, false. - public bool Equals(ExModel other) + public bool Equals(in ExModel other) { if ((key == other.key) && (json == other.json)) diff --git a/NewtonVgo/Runtime/Schema/Assets/VgoGeneratorInfo.cs b/NewtonVgo/Runtime/Schema/Assets/VgoGeneratorInfo.cs index 9050186..6ab8942 100644 --- a/NewtonVgo/Runtime/Schema/Assets/VgoGeneratorInfo.cs +++ b/NewtonVgo/Runtime/Schema/Assets/VgoGeneratorInfo.cs @@ -37,8 +37,8 @@ public VgoGeneratorInfo() { } /// /// Create a new instance of VgoGeneratorInfo by specifying VgoGeneratorInfo. /// - /// - public VgoGeneratorInfo(VgoGeneratorInfo generatorInfo) + /// + public VgoGeneratorInfo(in VgoGeneratorInfo generatorInfo) { if (generatorInfo != null) { diff --git a/NewtonVgo/Runtime/Schema/Assets/VgoRight.cs b/NewtonVgo/Runtime/Schema/Assets/VgoRight.cs index ec8ee86..7386459 100644 --- a/NewtonVgo/Runtime/Schema/Assets/VgoRight.cs +++ b/NewtonVgo/Runtime/Schema/Assets/VgoRight.cs @@ -71,7 +71,7 @@ public VgoRight() { } /// Create a new instance of VgoRight by specifying VgoRight. /// /// - public VgoRight(VgoRight right) + public VgoRight(in VgoRight right) { if (right != null) { diff --git a/NewtonVgo/Runtime/Schema/Extensions/VgoExtensions.cs b/NewtonVgo/Runtime/Schema/Extensions/VgoExtensions.cs index 8e79cd4..d11aa65 100644 --- a/NewtonVgo/Runtime/Schema/Extensions/VgoExtensions.cs +++ b/NewtonVgo/Runtime/Schema/Extensions/VgoExtensions.cs @@ -31,7 +31,6 @@ public class VgoExtensions : KeyedCollection /// /// Create a new instance of VgoExtensions. /// - /// public VgoExtensions() { JsonSerializerSettings = new VgoJsonSerializerSettings(); @@ -41,7 +40,7 @@ public VgoExtensions() /// Create a new instance of VgoExtensions with jsonSerializerSettings. /// /// - public VgoExtensions(JsonSerializerSettings jsonSerializerSettings) + public VgoExtensions(in JsonSerializerSettings jsonSerializerSettings) { JsonSerializerSettings = jsonSerializerSettings; } @@ -71,12 +70,9 @@ protected override string GetKeyForItem(ExModel item) /// The key of the element to add. /// The value of the element to add. /// - public void Add(string key, T value, JsonSerializerSettings? jsonSerializerSettings = null) + public void Add(in string key, in T value, JsonSerializerSettings? jsonSerializerSettings = null) { - if (jsonSerializerSettings == null) - { - jsonSerializerSettings = JsonSerializerSettings; - } + jsonSerializerSettings ??= JsonSerializerSettings; string json = JsonConvert.SerializeObject(value, jsonSerializerSettings); @@ -92,15 +88,12 @@ public void Add(string key, T value, JsonSerializerSettings? jsonSerializerSe /// The key of the element to get. /// /// Returns the value associated with the specified key. - public T GetValue(string key, JsonSerializerSettings? jsonSerializerSettings = null) + public T GetValue(in string key, JsonSerializerSettings? jsonSerializerSettings = null) where T : class, new() { ExModel model = this[key]; - if (jsonSerializerSettings == null) - { - jsonSerializerSettings = JsonSerializerSettings; - } + jsonSerializerSettings ??= JsonSerializerSettings; T? value = JsonConvert.DeserializeObject(model.json, jsonSerializerSettings); @@ -124,7 +117,7 @@ public T GetValue(string key, JsonSerializerSettings? jsonSerializerSettings /// If the key is found, returns the value associated with the specified key. /// otherwise, the default value for the type of the value parameter. /// - public T? GetValueOrDefault(string key, JsonSerializerSettings? jsonSerializerSettings = null) + public T? GetValueOrDefault(in string key, JsonSerializerSettings? jsonSerializerSettings = null) where T : class, new() { try @@ -150,7 +143,7 @@ public T GetValue(string key, JsonSerializerSettings? jsonSerializerSettings /// The value of the element to add. /// /// - public bool TryAdd(string key, T value, JsonSerializerSettings? jsonSerializerSettings = null) + public bool TryAdd(in string key, in T value, JsonSerializerSettings? jsonSerializerSettings = null) { if (Contains(key)) { @@ -178,7 +171,7 @@ public bool TryAdd(string key, T value, JsonSerializerSettings? jsonSerialize /// When this method returns true, contains the value associated with the specified key; otherwise, the default value for the type of the value parameter. /// /// true if the collection contains an element with the specified key; otherwise, false. - public bool TryGetValue(string key, out T value, JsonSerializerSettings jsonSerializerSettings = null) + public bool TryGetValue(in string key, out T value, JsonSerializerSettings jsonSerializerSettings = null) where T : class, new() { try @@ -234,7 +227,7 @@ public bool TryGetValue(string key, out T value, JsonSerializerSettings jsonS /// /// /// for JsonConverter - public void SetConverterDictionary(Dictionary? src) + public void SetConverterDictionary(in IDictionary? src) { if (src == null) { diff --git a/NewtonVgo/Runtime/Security/AesCrypter.cs b/NewtonVgo/Runtime/Security/AesCrypter.cs index b2fb610..f8dd07d 100644 --- a/NewtonVgo/Runtime/Security/AesCrypter.cs +++ b/NewtonVgo/Runtime/Security/AesCrypter.cs @@ -33,21 +33,19 @@ public class AesCrypter /// The key to be used for the algorithm. /// The initialization vector to be used for the algorithm. /// - public byte[] Encrypt(byte[] src, byte[] key, byte[] iv) + public byte[] Encrypt(in byte[] src, in byte[] key, in byte[] iv) { - using (Aes aes = Aes.Create()) - { - aes.Mode = CipherMode; - aes.Padding = PaddingMode; + using Aes aes = Aes.Create(); - aes.Key = key; - aes.IV = iv; + aes.Mode = CipherMode; + aes.Padding = PaddingMode; - using (ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV)) - { - return encryptor.TransformFinalBlock(src, 0, src.Length); - } - } + aes.Key = key; + aes.IV = iv; + + using ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV); + + return encryptor.TransformFinalBlock(src, 0, src.Length); } /// @@ -59,27 +57,25 @@ public byte[] Encrypt(byte[] src, byte[] key, byte[] iv) /// The initialization vector. /// The initialization vector string (Base64). /// - public byte[] Encrypt(byte[] src, byte[] key, int blockSize, out byte[] iv, out string ivString) + public byte[] Encrypt(in byte[] src, in byte[] key, in int blockSize, out byte[] iv, out string ivString) { - using (Aes aes = Aes.Create()) - { - aes.Mode = CipherMode; - aes.Padding = PaddingMode; + using Aes aes = Aes.Create(); - aes.BlockSize = blockSize; + aes.Mode = CipherMode; + aes.Padding = PaddingMode; - aes.Key = key; - aes.GenerateIV(); + aes.BlockSize = blockSize; - iv = aes.IV; + aes.Key = key; + aes.GenerateIV(); - ivString = Convert.ToBase64String(iv); + iv = aes.IV; - using (ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV)) - { - return encryptor.TransformFinalBlock(src, 0, src.Length); - } - } + ivString = Convert.ToBase64String(iv); + + using ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV); + + return encryptor.TransformFinalBlock(src, 0, src.Length); } /// @@ -93,30 +89,28 @@ public byte[] Encrypt(byte[] src, byte[] key, int blockSize, out byte[] iv, out /// The initialization vector. /// The initialization vector string (Base64). /// - public byte[] Encrypt(byte[] src, int keySize, int blockSize, out byte[] key, out string keyString, out byte[] iv, out string ivString) + public byte[] Encrypt(in byte[] src, in int keySize, in int blockSize, out byte[] key, out string keyString, out byte[] iv, out string ivString) { - using (Aes aes = Aes.Create()) - { - aes.Mode = CipherMode; - aes.Padding = PaddingMode; + using Aes aes = Aes.Create(); - aes.KeySize = keySize; - aes.BlockSize = blockSize; + aes.Mode = CipherMode; + aes.Padding = PaddingMode; - aes.GenerateKey(); - aes.GenerateIV(); + aes.KeySize = keySize; + aes.BlockSize = blockSize; - key = aes.Key; - iv = aes.IV; + aes.GenerateKey(); + aes.GenerateIV(); - keyString = Convert.ToBase64String(key); - ivString = Convert.ToBase64String(iv); + key = aes.Key; + iv = aes.IV; - using (ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV)) - { - return encryptor.TransformFinalBlock(src, 0, src.Length); - } - } + keyString = Convert.ToBase64String(key); + ivString = Convert.ToBase64String(iv); + + using ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV); + + return encryptor.TransformFinalBlock(src, 0, src.Length); } /// @@ -126,7 +120,7 @@ public byte[] Encrypt(byte[] src, int keySize, int blockSize, out byte[] key, ou /// The key string (Base64) to be used for the algorithm. /// The initialization vector string (Base64) to be used for the algorithm.. /// - public byte[] Decrypt(byte[] src, string key, string iv) + public byte[] Decrypt(in byte[] src, in string key, in string iv) { byte[] keyBytes = Convert.FromBase64String(key); byte[] ivBytes = Convert.FromBase64String(iv); @@ -141,18 +135,16 @@ public byte[] Decrypt(byte[] src, string key, string iv) /// The key to be used for the algorithm. /// The initialization vector to be used for the algorithm.. /// - public byte[] Decrypt(byte[] src, byte[] key, byte[] iv) + public byte[] Decrypt(in byte[] src, in byte[] key, in byte[] iv) { - using (Aes aes = Aes.Create()) - { - aes.Key = key; - aes.IV = iv; + using Aes aes = Aes.Create(); - using (ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV)) - { - return decryptor.TransformFinalBlock(src, 0, src.Length); - } - } + aes.Key = key; + aes.IV = iv; + + using ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV); + + return decryptor.TransformFinalBlock(src, 0, src.Length); } #endregion @@ -163,13 +155,13 @@ public byte[] Decrypt(byte[] src, byte[] key, byte[] iv) /// Generate a random key. /// /// - public byte[] GenerateRandomKey(int keySize) + public byte[] GenerateRandomKey(in int keySize) { int keyByteSize = keySize / 8; - var bytes = new byte[32]; + byte[] bytes = new byte[32]; - using (var rng = RNGCryptoServiceProvider.Create()) + using (var rng = RandomNumberGenerator.Create()) { rng.GetBytes(bytes); } @@ -181,10 +173,12 @@ public byte[] GenerateRandomKey(int keySize) sb.Append(Convert.ToChar(b)); } - using (Rfc2898DeriveBytes deriveBytes = new Rfc2898DeriveBytes(password: sb.ToString(), saltSize: 16, iterations: 1000)) - { - return deriveBytes.GetBytes(keyByteSize); - } +#if UNITY_2021_2_OR_NEWER // CSHARP_8_OR_LATER + using var deriveBytes = new Rfc2898DeriveBytes(password: sb.ToString(), saltSize: 16, iterations: 1000, hashAlgorithm: HashAlgorithmName.SHA1); +#else + using var deriveBytes = new Rfc2898DeriveBytes(password: sb.ToString(), saltSize: 16, iterations: 1000); +#endif + return deriveBytes.GetBytes(keyByteSize); } #endregion diff --git a/NewtonVgo/Runtime/Serialization/JsonConverters/VgoMeshPrimitiveAttributesJsonConverter.cs b/NewtonVgo/Runtime/Serialization/JsonConverters/VgoMeshPrimitiveAttributesJsonConverter.cs index 893f145..c08f609 100644 --- a/NewtonVgo/Runtime/Serialization/JsonConverters/VgoMeshPrimitiveAttributesJsonConverter.cs +++ b/NewtonVgo/Runtime/Serialization/JsonConverters/VgoMeshPrimitiveAttributesJsonConverter.cs @@ -39,16 +39,21 @@ public override bool CanConvert(Type objectType) if (reader.TokenType == JsonToken.StartArray) { - dictionary = serializer - .Deserialize[]>(reader) - .ToDictionary(x => x.Key, x => x.Value); + var kvp = serializer.Deserialize[]>(reader); + + if (kvp is null) + { + return null; + } + + dictionary = kvp.ToDictionary(x => x.Key, x => x.Value); } else { dictionary = serializer.Deserialize>(reader); } - if (dictionary == null) + if (dictionary is null) { return null; } diff --git a/NewtonVgo/Runtime/Storage/IVgoStorage.cs b/NewtonVgo/Runtime/Storage/IVgoStorage.cs index 5fa4f25..5cb543d 100644 --- a/NewtonVgo/Runtime/Storage/IVgoStorage.cs +++ b/NewtonVgo/Runtime/Storage/IVgoStorage.cs @@ -53,7 +53,7 @@ public interface IVgoStorage /// The full path of the file. /// A vgo export setting. /// Returns true if the export was successful, false otherwise. - bool ExportVgoFile(string filePath, VgoExportSetting exportSetting); + bool ExportVgoFile(in string filePath, in VgoExportSetting exportSetting); #endregion @@ -64,7 +64,7 @@ public interface IVgoStorage /// /// The index of the accessor. /// An accessor. - VgoResourceAccessor GetAccessor(int accessorIndex); + VgoResourceAccessor GetAccessor(in int accessorIndex); /// /// Gets array data from the resource through the accessor. @@ -72,7 +72,7 @@ public interface IVgoStorage /// Type of data. /// The index of the accessor. /// Array data. - T[] GetAccessorArrayData(int accessorIndex) where T : struct; + T[] GetAccessorArrayData(in int accessorIndex) where T : struct; /// /// Gets span data from the resource through the accessor. @@ -80,21 +80,21 @@ public interface IVgoStorage /// Type of data. /// The index of the accessor. /// Span data. - ReadOnlySpan GetAccessorSpan(int accessorIndex) where T : struct; + ReadOnlySpan GetAccessorSpan(in int accessorIndex) where T : struct; /// /// Gets array segment data from the resource through the accessor. /// /// The index of the accessor. /// Array segment byte. - ArraySegment GetAccessorBytes(int accessorIndex); + ArraySegment GetAccessorBytes(in int accessorIndex); /// /// Gets array segment data from the resource through the accessor. /// /// An accessor. /// Array segment byte. - ArraySegment GetAccessorBytes(VgoResourceAccessor accessor); + ArraySegment GetAccessorBytes(in VgoResourceAccessor accessor); /// /// Add an accessor (non sparse) to resource. @@ -105,9 +105,9 @@ public interface IVgoStorage /// The kind of the accessor. /// The index of the accessor. int AddAccessorWithoutSparse( - T[] arrayData, - VgoResourceAccessorDataType dataType, - VgoResourceAccessorKind kind + in T[] arrayData, + in VgoResourceAccessorDataType dataType, + in VgoResourceAccessorKind kind ) where T : struct; /// @@ -123,13 +123,13 @@ VgoResourceAccessorKind kind /// The kind of the accessor. /// The index of the accessor. int AddAccessorWithSparse( - VgoResourceAccessorSparseType sparseType, + in VgoResourceAccessorSparseType sparseType, in int[] sparseIndices, in TValue[] sparseValues, - VgoResourceAccessorDataType sparseValueDataType, - VgoResourceAccessorDataType accessorDataType, - int accessorCount, - VgoResourceAccessorKind kind + in VgoResourceAccessorDataType sparseValueDataType, + in VgoResourceAccessorDataType accessorDataType, + in int accessorCount, + in VgoResourceAccessorKind kind ) where TValue : struct; #endregion diff --git a/NewtonVgo/Runtime/Storage/VgoStorage.Export.cs b/NewtonVgo/Runtime/Storage/VgoStorage.Export.cs index 16c8429..c630bed 100644 --- a/NewtonVgo/Runtime/Storage/VgoStorage.Export.cs +++ b/NewtonVgo/Runtime/Storage/VgoStorage.Export.cs @@ -27,7 +27,7 @@ public partial class VgoStorage : IVgoStorage /// The full path of the file. /// A vgo export setting. /// Returns true if the export was successful, false otherwise. - public virtual bool ExportVgoFile(string filePath, VgoExportSetting exportSetting) + public virtual bool ExportVgoFile(in string filePath, in VgoExportSetting exportSetting) { ThrowHelper.ThrowExceptionIfArgumentIsNull(nameof(filePath), filePath); @@ -158,7 +158,7 @@ public virtual bool ExportVgoFile(string filePath, VgoExportSetting exportSettin { string keyFileName = fileInfo.Name.Substring(0, fileInfo.Name.Length - fileInfo.Extension.Length) + ".vgk"; - string keyFullPath = Path.Combine(fileInfo.DirectoryName, keyFileName); + string keyFullPath = Path.Combine(fileInfo.DirectoryName!, keyFileName); // Output (.vgk) using (var stream = new FileStream(keyFullPath, FileMode.Create, FileAccess.Write, FileShare.None)) @@ -172,7 +172,14 @@ public virtual bool ExportVgoFile(string filePath, VgoExportSetting exportSettin if (exportSetting.ResourceTypeId != VgoChunkTypeID.REPb) { - string binFullPath = Path.Combine(fileInfo.DirectoryName, exportSetting.BinFileName); // @notice binFileName + if (exportSetting.BinFileName is null) + { + ThrowHelper.ThrowArgumentException(nameof(exportSetting), "exportSetting.BinFileName is null."); + + return false; + } + + string binFullPath = Path.Combine(fileInfo.DirectoryName!, exportSetting.BinFileName); // @notice binFileName // Output (.bin) using (var stream = new FileStream(binFullPath, FileMode.Create, FileAccess.Write, FileShare.None)) @@ -196,7 +203,7 @@ public virtual bool ExportVgoFile(string filePath, VgoExportSetting exportSettin /// /// The asset info chunk type ID. /// An asset info chunk. - public virtual VgoChunk CreateAssetInfoChunk(VgoChunkTypeID assetInfoTypeId) + public virtual VgoChunk CreateAssetInfoChunk(in VgoChunkTypeID assetInfoTypeId) { IByteBuffer assetInfoChunkData; @@ -250,7 +257,7 @@ public virtual VgoChunk CreateAssetInfoChunk(VgoChunkTypeID assetInfoTypeId) /// /// The layout chunk type ID. /// A layout chunk. - protected virtual VgoChunk CreateLayoutChunk(VgoChunkTypeID layoutTypeId) + protected virtual VgoChunk CreateLayoutChunk(in VgoChunkTypeID layoutTypeId) { IByteBuffer layoutChunkData; @@ -308,10 +315,10 @@ protected virtual VgoChunk CreateLayoutChunk(VgoChunkTypeID layoutTypeId) /// The crypt key. /// A resource accessor chunk and a crypt chunk. protected virtual (VgoChunk, VgoChunk?) CreateResourceAccessorChunk( - VgoChunkTypeID resourceAccessorTypeId, - VgoChunkTypeID resourceAccessorCryptTypeId, - string? cryptAlgorithm = null, - byte[]? cryptKey = null) + in VgoChunkTypeID resourceAccessorTypeId, + in VgoChunkTypeID resourceAccessorCryptTypeId, + in string? cryptAlgorithm = null, + in byte[]? cryptKey = null) { IByteBuffer resourceAccessorChunkData; IByteBuffer? resourceAccessorCryptChunkData = null; @@ -478,17 +485,11 @@ protected virtual (VgoChunk, VgoChunk?) CreateResourceAccessorChunk( /// The resource binary file name. /// The resource URI. /// A resouce chunk. - protected virtual VgoChunk CreateResourceChunk(VgoChunkTypeID resourceTypeId, FileInfo fileInfo, string? binFileName = null, string? resourceUri = null) + protected virtual VgoChunk CreateResourceChunk(in VgoChunkTypeID resourceTypeId, in FileInfo fileInfo, string? binFileName = null, string? resourceUri = null) { - if (binFileName == null) - { - binFileName = fileInfo.Name.Substring(0, fileInfo.Name.Length - fileInfo.Extension.Length) + ".bin"; - } + binFileName ??= fileInfo.Name.Substring(0, fileInfo.Name.Length - fileInfo.Extension.Length) + ".bin"; - if (resourceUri == null) - { - resourceUri = binFileName; - } + resourceUri ??= binFileName; if (Resource == null) { @@ -567,11 +568,11 @@ protected virtual VgoChunk CreateResourceChunk(VgoChunkTypeID resourceTypeId, Fi /// The resourse chunk type ID. /// A composer chunk. public virtual VgoChunk CreateComposerChunk( - VgoChunkTypeID assetInfoTypeId, - VgoChunkTypeID layoutTypeId, - VgoChunkTypeID resourceAccessorTypeId, - VgoChunkTypeID resourceAccessorCryptTypeId, - VgoChunkTypeID resourceTypeId) + in VgoChunkTypeID assetInfoTypeId, + in VgoChunkTypeID layoutTypeId, + in VgoChunkTypeID resourceAccessorTypeId, + in VgoChunkTypeID resourceAccessorCryptTypeId, + in VgoChunkTypeID resourceTypeId) { VgoComposerChunkData composerChunkData = new VgoComposerChunkData { @@ -601,7 +602,7 @@ public virtual VgoChunk CreateComposerChunk( /// /// List of chunk. /// A index chunk. - protected virtual VgoChunk CreateIndexChunk(List chunkList) + protected virtual VgoChunk CreateIndexChunk(in List chunkList) { VgoIndexChunkDataElement[] indexChunkDataArray = new VgoIndexChunkDataElement[chunkList.Count]; diff --git a/NewtonVgo/Runtime/Storage/VgoStorage.Import.cs b/NewtonVgo/Runtime/Storage/VgoStorage.Import.cs index 3da341c..1ca7274 100644 --- a/NewtonVgo/Runtime/Storage/VgoStorage.Import.cs +++ b/NewtonVgo/Runtime/Storage/VgoStorage.Import.cs @@ -28,7 +28,8 @@ public partial class VgoStorage : IVgoStorage /// /// The vgo bytes. /// The vgk bytes. - protected virtual void ParseVgo(byte[] vgoBytes, byte[]? vgkBytes, out VgoLayout layout) + /// The vgo layout. + protected virtual void ParseVgo(in byte[] vgoBytes, in byte[]? vgkBytes, out VgoLayout layout) { if (vgoBytes == null) { @@ -121,7 +122,7 @@ protected virtual void ParseVgo(byte[] vgoBytes, byte[]? vgkBytes, out VgoLayout /// /// The all segment bytes. /// The header chunk. - protected virtual VgoHeader GetHeader(ArraySegment allSegmentBytes) + protected virtual VgoHeader GetHeader(in ArraySegment allSegmentBytes) { try { @@ -129,7 +130,7 @@ protected virtual VgoHeader GetHeader(ArraySegment allSegmentBytes) ArraySegment headerSegment = allSegmentBytes.Slice(offset: 0, count: headerSize); - VgoHeader header = headerSegment.Array.ConvertToStructure(); + VgoHeader header = headerSegment.ToArray().ConvertToStructure(); if (header.Magic != (uint)VgoChunkTypeID.Vgo) { @@ -179,8 +180,20 @@ protected virtual VgoHeader GetHeader(ArraySegment allSegmentBytes) /// /// Index chunk (8 + 16 * n byte) /// - protected virtual VgoIndexChunkDataElement[] GetChunkIndexMap(ArraySegment allSegmentBytes, int indexByteOffset) + protected virtual VgoIndexChunkDataElement[] GetChunkIndexMap(in ArraySegment allSegmentBytes, in int indexByteOffset) { + if (allSegmentBytes.Array is null) + { + ThrowHelper.ThrowArgumentException(nameof(allSegmentBytes)); + + return Array.Empty(); + } + + if (allSegmentBytes.Count == 0) + { + ThrowHelper.ThrowArgumentOutOfRangeException(nameof(allSegmentBytes)); + } + try { uint indexChunkTypeId = BitConverter.ToUInt32(allSegmentBytes.Array, indexByteOffset); @@ -226,11 +239,11 @@ protected virtual VgoIndexChunkDataElement[] GetChunkIndexMap(ArraySegment /// The chunk type ID. /// The chunk index map. /// - protected virtual VgoIndexChunkDataElement GetIndexChunkDataElement(VgoChunkTypeID chunkTypeId, VgoIndexChunkDataElement[] chunkIndexMap) + protected virtual VgoIndexChunkDataElement GetIndexChunkDataElement(VgoChunkTypeID chunkTypeId, in VgoIndexChunkDataElement[] chunkIndexMap) { try { - int count = chunkIndexMap.Where(x => x.ChunkTypeId == chunkTypeId).Count(); + int count = chunkIndexMap.Count(x => x.ChunkTypeId == chunkTypeId); if (count == 0) { @@ -242,7 +255,7 @@ protected virtual VgoIndexChunkDataElement GetIndexChunkDataElement(VgoChunkType ThrowHelper.ThrowFormatException($"{chunkTypeId} is defined more than once in IDX chunk."); } - VgoIndexChunkDataElement chunkInfo = chunkIndexMap.Where(x => x.ChunkTypeId == chunkTypeId).First(); + VgoIndexChunkDataElement chunkInfo = chunkIndexMap.First(x => x.ChunkTypeId == chunkTypeId); if (chunkInfo.ByteOffset == 0) { @@ -274,8 +287,20 @@ protected virtual VgoIndexChunkDataElement GetIndexChunkDataElement(VgoChunkType /// The chunk index map. /// The all segment bytes. /// The chunk data bytes. - protected virtual ArraySegment ExtractChunkData(VgoChunkTypeID chunkTypeId, VgoIndexChunkDataElement[] chunkIndexMap, ArraySegment allSegmentBytes) + protected virtual ArraySegment ExtractChunkData(in VgoChunkTypeID chunkTypeId, in VgoIndexChunkDataElement[] chunkIndexMap, in ArraySegment allSegmentBytes) { + if (allSegmentBytes.Array is null) + { + ThrowHelper.ThrowArgumentException(nameof(allSegmentBytes)); + + return new ArraySegment(Array.Empty()); + } + + if (allSegmentBytes.Count == 0) + { + ThrowHelper.ThrowArgumentOutOfRangeException(nameof(allSegmentBytes)); + } + VgoIndexChunkDataElement chunkIndexInfo = GetIndexChunkDataElement(chunkTypeId, chunkIndexMap); uint chunkChunkTypeId = BitConverter.ToUInt32(allSegmentBytes.Array, (int)chunkIndexInfo.ByteOffset); @@ -311,7 +336,7 @@ protected virtual ArraySegment ExtractChunkData(VgoChunkTypeID chunkTypeId /// The chunk index map. /// The all segment bytes. /// The asset info. - protected virtual VgoAssetInfo? ExtractAssetInfo(VgoComposerChunkData composerChunkData, VgoIndexChunkDataElement[] chunkIndexMap, ArraySegment allSegmentBytes) + protected virtual VgoAssetInfo? ExtractAssetInfo(in VgoComposerChunkData composerChunkData, in VgoIndexChunkDataElement[] chunkIndexMap, in ArraySegment allSegmentBytes) { try { @@ -359,7 +384,7 @@ protected virtual ArraySegment ExtractChunkData(VgoChunkTypeID chunkTypeId /// The chunk index map. /// The all segment bytes. /// The layout. - protected virtual VgoLayout ExtractLayout(VgoComposerChunkData composerChunkData, VgoIndexChunkDataElement[] chunkIndexMap, ArraySegment allSegmentBytes) + protected virtual VgoLayout ExtractLayout(in VgoComposerChunkData composerChunkData, in VgoIndexChunkDataElement[] chunkIndexMap, in ArraySegment allSegmentBytes) { try { @@ -423,7 +448,7 @@ protected virtual VgoLayout ExtractLayout(VgoComposerChunkData composerChunkData /// The all segment bytes. /// The crypt key. /// List of the resource accessor. - protected virtual List? ExtractResourceAccessor(VgoComposerChunkData composerChunkData, VgoIndexChunkDataElement[] chunkIndexMap, ArraySegment allSegmentBytes, byte[]? cryptKey = null) + protected virtual List? ExtractResourceAccessor(in VgoComposerChunkData composerChunkData, in VgoIndexChunkDataElement[] chunkIndexMap, in ArraySegment allSegmentBytes, in byte[]? cryptKey = null) { VgoChunkTypeID raChunkTypeId = composerChunkData.ResourceAccessorChunkTypeId; @@ -528,7 +553,6 @@ protected virtual VgoLayout ExtractLayout(VgoComposerChunkData composerChunkData return default; } - } catch (JsonSerializationException) { @@ -587,7 +611,7 @@ protected virtual VgoLayout ExtractLayout(VgoComposerChunkData composerChunkData /// The chunk index map. /// The all segment bytes. /// The resouce bytes. - protected virtual ArraySegment ExtractResource(VgoComposerChunkData composerChunkData, VgoIndexChunkDataElement[] chunkIndexMap, ArraySegment allSegmentBytes) + protected virtual ArraySegment ExtractResource(in VgoComposerChunkData composerChunkData, in VgoIndexChunkDataElement[] chunkIndexMap, in ArraySegment allSegmentBytes) { VgoChunkTypeID resourceChunkTypeId = composerChunkData.ResourceChunkTypeId; @@ -662,7 +686,7 @@ protected virtual ArraySegment ExtractResource(VgoComposerChunkData compos /// The chunk index map. /// The all segment bytes. /// The vgo crypt. - protected virtual VgoCryptV0? GetVgoCrypt(VgoChunkTypeID cryptChunkTypeId, VgoIndexChunkDataElement[] chunkIndexMap, ArraySegment allSegmentBytes) + protected virtual VgoCryptV0? GetVgoCrypt(in VgoChunkTypeID cryptChunkTypeId, in VgoIndexChunkDataElement[] chunkIndexMap, in ArraySegment allSegmentBytes) { try { @@ -708,7 +732,7 @@ protected virtual ArraySegment ExtractResource(VgoComposerChunkData compos /// /// The uri. /// An byte array of uri data. - protected virtual byte[] GetUriData(string uri) + protected virtual byte[] GetUriData(in string uri) { ThrowHelper.ThrowExceptionIfArgumentIsNull(nameof(uri), uri); @@ -722,22 +746,21 @@ protected virtual byte[] GetUriData(string uri) uri.StartsWith("http://") || uri.StartsWith("https://")) { - using (HttpClient httpClient = new HttpClient() { Timeout = TimeSpan.FromSeconds(HttpTimeoutSeconds) }) - using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, uri)) - using (HttpResponseMessage response = httpClient.SendAsync(request).GetAwaiter().GetResult()) + using HttpClient httpClient = new HttpClient() { Timeout = TimeSpan.FromSeconds(HttpTimeoutSeconds) }; + using HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, uri); + using HttpResponseMessage response = httpClient.SendAsync(request).GetAwaiter().GetResult(); + + if (response.IsSuccessStatusCode) { - if (response.IsSuccessStatusCode) - { - byte[] byteArray = response.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult(); + byte[] byteArray = response.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult(); - return byteArray; - } - else - { - ThrowHelper.ThrowHttpRequestException(response.StatusCode.ToString()); + return byteArray; + } + else + { + ThrowHelper.ThrowHttpRequestException(response.StatusCode.ToString()); - return Array.Empty(); - } + return Array.Empty(); } } else if (uri.StartsWith("file://")) diff --git a/NewtonVgo/Runtime/Storage/VgoStorageAdapter.cs b/NewtonVgo/Runtime/Storage/VgoStorageAdapter.cs index cf46b48..9b4029f 100644 --- a/NewtonVgo/Runtime/Storage/VgoStorageAdapter.cs +++ b/NewtonVgo/Runtime/Storage/VgoStorageAdapter.cs @@ -32,7 +32,7 @@ public partial class VgoStorage /// /// The index of the accessor. /// An accessor. - public VgoResourceAccessor GetAccessor(int accessorIndex) + public VgoResourceAccessor GetAccessor(in int accessorIndex) { if (ResourceAccessors == null) { @@ -61,7 +61,7 @@ public VgoResourceAccessor GetAccessor(int accessorIndex) /// Type of data. /// The index of the accessor. /// Array data. - public T[] GetAccessorArrayData(int accessorIndex) where T : struct + public T[] GetAccessorArrayData(in int accessorIndex) where T : struct { VgoResourceAccessor accessor = GetAccessor(accessorIndex); @@ -89,7 +89,7 @@ public T[] GetAccessorArrayData(int accessorIndex) where T : struct /// Type of data. /// The index of the accessor. /// Span data. - public ReadOnlySpan GetAccessorSpan(int accessorIndex) where T : struct + public ReadOnlySpan GetAccessorSpan(in int accessorIndex) where T : struct { VgoResourceAccessor accessor = GetAccessor(accessorIndex); @@ -114,7 +114,7 @@ public ReadOnlySpan GetAccessorSpan(int accessorIndex) where T : struct /// /// The index of the accessor. /// Array segment byte. - public ArraySegment GetAccessorBytes(int accessorIndex) + public ArraySegment GetAccessorBytes(in int accessorIndex) { VgoResourceAccessor accessor = GetAccessor(accessorIndex); @@ -126,7 +126,7 @@ public ArraySegment GetAccessorBytes(int accessorIndex) /// /// An accessor. /// Array segment byte. - public ArraySegment GetAccessorBytes(VgoResourceAccessor accessor) + public ArraySegment GetAccessorBytes(in VgoResourceAccessor accessor) { if (accessor.sparseType == VgoResourceAccessorSparseType.None) { @@ -143,7 +143,7 @@ public ArraySegment GetAccessorBytes(VgoResourceAccessor accessor) /// /// An accessor. /// Array segment byte. - protected ArraySegment GetAccessorBytesWithoutSparse(VgoResourceAccessor accessor) + protected ArraySegment GetAccessorBytesWithoutSparse(in VgoResourceAccessor accessor) { if (accessor.count <= 0) { @@ -182,7 +182,7 @@ protected ArraySegment GetAccessorBytesWithoutSparse(VgoResourceAccessor a /// /// An accessor. /// Array segment byte. - protected ArraySegment GetAccessorBytesWithSparse(VgoResourceAccessor accessor) + protected ArraySegment GetAccessorBytesWithSparse(in VgoResourceAccessor accessor) { if (accessor.count <= 0) { @@ -295,7 +295,7 @@ protected ArraySegment GetAccessorBytesWithSparse(VgoResourceAccessor acce /// The data type of sparse value. /// An accessor. /// Array segment byte. - protected ArraySegment RestoreArraySegmentFromSparse(VgoResourceAccessor accessor) + protected ArraySegment RestoreArraySegmentFromSparse(in VgoResourceAccessor accessor) where TValue : struct { return RestoreArraySegmentFromSparse(accessor); @@ -308,7 +308,7 @@ protected ArraySegment RestoreArraySegmentFromSparse(VgoResourceAc /// The data type of accessor. /// An accessor. /// Array segment byte. - protected ArraySegment RestoreArraySegmentFromSparse(VgoResourceAccessor accessor) + protected ArraySegment RestoreArraySegmentFromSparse(in VgoResourceAccessor accessor) where TValue : struct where TData : struct { @@ -408,7 +408,7 @@ protected ArraySegment RestoreArraySegmentFromSparse(VgoRes /// The type of data. /// The kind of the accessor. /// The index of the accessor. - public int AddAccessorWithoutSparse(T[] arrayData, VgoResourceAccessorDataType dataType, VgoResourceAccessorKind kind) + public int AddAccessorWithoutSparse(in T[] arrayData, in VgoResourceAccessorDataType dataType, in VgoResourceAccessorKind kind) where T : struct { if (arrayData == null) @@ -472,7 +472,14 @@ public int AddAccessorWithoutSparse(T[] arrayData, VgoResourceAccessorDataTyp /// The number of attributes referenced by this accessor. /// The kind of the accessor. /// The index of the accessor. - public int AddAccessorWithSparse(VgoResourceAccessorSparseType sparseType, in int[] sparseIndices, in TValue[] sparseValues, VgoResourceAccessorDataType sparseValueDataType, VgoResourceAccessorDataType accessorDataType, int accessorCount, VgoResourceAccessorKind kind) + public int AddAccessorWithSparse( + in VgoResourceAccessorSparseType sparseType, + in int[] sparseIndices, + in TValue[] sparseValues, + in VgoResourceAccessorDataType sparseValueDataType, + in VgoResourceAccessorDataType accessorDataType, + in int accessorCount, + in VgoResourceAccessorKind kind) where TValue : struct { if (accessorCount == 0) diff --git a/NewtonVgo/Runtime/Structures/Bounds.cs b/NewtonVgo/Runtime/Structures/Bounds.cs index 5d88201..9b05306 100644 --- a/NewtonVgo/Runtime/Structures/Bounds.cs +++ b/NewtonVgo/Runtime/Structures/Bounds.cs @@ -53,7 +53,7 @@ public Bounds(Vector3 center, Vector3 size) /// /// /// - public void Deconstruct(out Vector3 center, out Vector3 size) + public readonly void Deconstruct(out Vector3 center, out Vector3 size) { center = this.center; size = this.size; @@ -64,7 +64,7 @@ public void Deconstruct(out Vector3 center, out Vector3 size) /// /// /// true if the specified object is equal to the current object; otherwise, false. - public bool Equals(Bounds other) + public readonly bool Equals(in Bounds other) { return center.Equals(other.center) && @@ -76,7 +76,7 @@ public bool Equals(Bounds other) /// /// /// true if the specified object is equal to the current object; otherwise, false. - public override bool Equals(object? other) + public override readonly bool Equals(object? other) { if (other is Bounds otherBounds) { @@ -90,7 +90,7 @@ public override bool Equals(object? other) /// Serves as the default hash function. /// /// A hash code for the current object. - public override int GetHashCode() + public override readonly int GetHashCode() { return center.GetHashCode() ^ @@ -101,12 +101,24 @@ public override int GetHashCode() #region Operators - public static bool operator ==(Bounds b1, Bounds b2) + /// + /// + /// + /// + /// + /// + public static bool operator ==(in Bounds b1, in Bounds b2) { return b1.Equals(b2); } - public static bool operator !=(Bounds b1, Bounds b2) + /// + /// + /// + /// + /// + /// + public static bool operator !=(in Bounds b1, in Bounds b2) { return b1.Equals(b2) == false; } diff --git a/NewtonVgo/Runtime/Structures/Color3.cs b/NewtonVgo/Runtime/Structures/Color3.cs index adf1594..7247863 100644 --- a/NewtonVgo/Runtime/Structures/Color3.cs +++ b/NewtonVgo/Runtime/Structures/Color3.cs @@ -76,7 +76,7 @@ public Color3(Color4 color4) /// public float this[int index] { - get + readonly get { switch (index) { @@ -122,7 +122,7 @@ public float this[int index] /// /// /// - public void Deconstruct(out float r, out float g, out float b) + public readonly void Deconstruct(out float r, out float g, out float b) { r = R; g = G; @@ -134,7 +134,7 @@ public void Deconstruct(out float r, out float g, out float b) /// /// /// true if the specified object is equal to the current object; otherwise, false. - public bool Equals(Color3 other) + public readonly bool Equals(in Color3 other) { return R.Equals(other.R) && @@ -147,7 +147,7 @@ public bool Equals(Color3 other) /// /// /// true if the specified object is equal to the current object; otherwise, false. - public override bool Equals(object? other) + public override readonly bool Equals(object? other) { if (other is Color3 otherColor3) { @@ -161,7 +161,7 @@ public override bool Equals(object? other) /// Serves as the default hash function. /// /// A hash code for the current object. - public override int GetHashCode() + public override readonly int GetHashCode() { return R.GetHashCode() ^ @@ -186,7 +186,7 @@ public void Set(float newR, float newG, float newB) /// Convert Color3 to Color4. /// /// - public Color4 ToColor4(float a = 1.0f) + public readonly Color4 ToColor4(in float a = 1.0f) { return new Color4(this, a); } @@ -195,12 +195,24 @@ public Color4 ToColor4(float a = 1.0f) #region Operators - public static bool operator ==(Color3 c1, Color3 c2) + /// + /// + /// + /// + /// + /// + public static bool operator ==(in Color3 c1, in Color3 c2) { return c1.Equals(c2); } - public static bool operator !=(Color3 c1, Color3 c2) + /// + /// + /// + /// + /// + /// + public static bool operator !=(in Color3 c1, in Color3 c2) { return c1.Equals(c2) == false; } diff --git a/NewtonVgo/Runtime/Structures/Color4.cs b/NewtonVgo/Runtime/Structures/Color4.cs index 8bd0e8d..2334221 100644 --- a/NewtonVgo/Runtime/Structures/Color4.cs +++ b/NewtonVgo/Runtime/Structures/Color4.cs @@ -91,7 +91,7 @@ public Color4(Color3 color3, float a = 1.0f) /// public float this[int index] { - get + readonly get { switch (index) { @@ -143,7 +143,7 @@ public float this[int index] /// /// /// - public void Deconstruct(out float r, out float g, out float b, out float a) + public readonly void Deconstruct(out float r, out float g, out float b, out float a) { r = R; g = G; @@ -156,7 +156,7 @@ public void Deconstruct(out float r, out float g, out float b, out float a) /// /// /// true if the specified object is equal to the current object; otherwise, false. - public bool Equals(Color4 other) + public readonly bool Equals(in Color4 other) { return R.Equals(other.R) && @@ -170,7 +170,7 @@ public bool Equals(Color4 other) /// /// /// true if the specified object is equal to the current object; otherwise, false. - public override bool Equals(object? other) + public override readonly bool Equals(object? other) { if (other is Color4 otherColor4) { @@ -184,7 +184,7 @@ public override bool Equals(object? other) /// Serves as the default hash function. /// /// A hash code for the current object. - public override int GetHashCode() + public override readonly int GetHashCode() { return R.GetHashCode() ^ @@ -212,7 +212,7 @@ public void Set(float newR, float newG, float newB, float newA) /// Convert Color4 to Color3. /// /// - public Color3 ToColor3() + public readonly Color3 ToColor3() { return new Color3(this); } @@ -221,12 +221,24 @@ public Color3 ToColor3() #region Operators - public static bool operator ==(Color4 c1, Color4 c2) + /// + /// + /// + /// + /// + /// + public static bool operator ==(in Color4 c1, in Color4 c2) { return c1.Equals(c2); } - public static bool operator !=(Color4 c1, Color4 c2) + /// + /// + /// + /// + /// + /// + public static bool operator !=(in Color4 c1, in Color4 c2) { return c1.Equals(c2) == false; } diff --git a/NewtonVgo/Runtime/Structures/Vector4Ubyte.cs b/NewtonVgo/Runtime/Structures/Vector4Ubyte.cs index 24c3864..f690a8c 100644 --- a/NewtonVgo/Runtime/Structures/Vector4Ubyte.cs +++ b/NewtonVgo/Runtime/Structures/Vector4Ubyte.cs @@ -60,7 +60,7 @@ public Vector4Ubyte(byte x, byte y, byte z, byte w) /// public byte this[int index] { - get + readonly get { switch (index) { @@ -112,7 +112,7 @@ public byte this[int index] /// /// /// - public void Deconstruct(out byte x, out byte y, out byte z, out byte w) + public readonly void Deconstruct(out byte x, out byte y, out byte z, out byte w) { x = X; y = Y; @@ -125,7 +125,7 @@ public void Deconstruct(out byte x, out byte y, out byte z, out byte w) /// /// /// true if the specified object is equal to the current object; otherwise, false. - public bool Equals(Vector4Ubyte other) + public readonly bool Equals(in Vector4Ubyte other) { return X.Equals(other.X) && @@ -139,7 +139,7 @@ public bool Equals(Vector4Ubyte other) /// /// /// true if the specified object is equal to the current object; otherwise, false. - public override bool Equals(object? other) + public override readonly bool Equals(object? other) { if (other is Vector4Ubyte otherVector4) { @@ -153,7 +153,7 @@ public override bool Equals(object? other) /// Serves as the default hash function. /// /// A hash code for the current object. - public override int GetHashCode() + public override readonly int GetHashCode() { return X.GetHashCode() ^ @@ -181,7 +181,7 @@ public void Set(byte newX, byte newY, byte newZ, byte newW) /// Convert Vector4Ubyte to Vector4Uint. /// /// - public Vector4Uint ToVector4Uint() + public readonly Vector4Uint ToVector4Uint() { return new Vector4Uint(this); } @@ -190,7 +190,7 @@ public Vector4Uint ToVector4Uint() /// Convert Vector4Ubyte to Vector4Ushort. /// /// - public Vector4Ushort ToVector4Ushort() + public readonly Vector4Ushort ToVector4Ushort() { return new Vector4Ushort(this); } @@ -199,11 +199,23 @@ public Vector4Ushort ToVector4Ushort() #region Operators + /// + /// + /// + /// + /// + /// public static bool operator ==(Vector4Ubyte v1, Vector4Ubyte v2) { return v1.Equals(v2); } + /// + /// + /// + /// + /// + /// public static bool operator !=(Vector4Ubyte v1, Vector4Ubyte v2) { return v1.Equals(v2) == false; diff --git a/NewtonVgo/Runtime/Structures/Vector4Uint.cs b/NewtonVgo/Runtime/Structures/Vector4Uint.cs index 63941fa..75a43f6 100644 --- a/NewtonVgo/Runtime/Structures/Vector4Uint.cs +++ b/NewtonVgo/Runtime/Structures/Vector4Uint.cs @@ -84,7 +84,7 @@ public Vector4Uint(Vector4Ushort source) /// public uint this[int index] { - get + readonly get { switch (index) { @@ -136,7 +136,7 @@ public uint this[int index] /// /// /// - public void Deconstruct(out uint x, out uint y, out uint z, out uint w) + public readonly void Deconstruct(out uint x, out uint y, out uint z, out uint w) { x = X; y = Y; @@ -149,7 +149,7 @@ public void Deconstruct(out uint x, out uint y, out uint z, out uint w) /// /// /// true if the specified object is equal to the current object; otherwise, false. - public bool Equals(Vector4Uint other) + public readonly bool Equals(in Vector4Uint other) { return X.Equals(other.X) && @@ -163,7 +163,7 @@ public bool Equals(Vector4Uint other) /// /// /// true if the specified object is equal to the current object; otherwise, false. - public override bool Equals(object? other) + public override readonly bool Equals(object? other) { if (other is Vector4Uint otherVector4) { @@ -177,7 +177,7 @@ public override bool Equals(object? other) /// Serves as the default hash function. /// /// A hash code for the current object. - public override int GetHashCode() + public override readonly int GetHashCode() { return X.GetHashCode() ^ @@ -205,7 +205,7 @@ public void Set(uint newX, uint newY, uint newZ, uint newW) /// Try convert Vector4Uint to Vector4Ubyte. /// /// true if the operation is successful; otherwise, false. - public bool TryConvertTo(out Vector4Ubyte destination) + public readonly bool TryConvertTo(out Vector4Ubyte destination) { if ((X <= byte.MaxValue) && (Y <= byte.MaxValue) && @@ -231,7 +231,7 @@ public bool TryConvertTo(out Vector4Ubyte destination) /// Try convert Vector4Uint to Vector4Ushort. /// /// true if the operation is successful; otherwise, false. - public bool TryConvertTo(out Vector4Ushort destination) + public readonly bool TryConvertTo(out Vector4Ushort destination) { if ((X <= ushort.MaxValue) && (Y <= ushort.MaxValue) && @@ -257,12 +257,24 @@ public bool TryConvertTo(out Vector4Ushort destination) #region Operators - public static bool operator ==(Vector4Uint v1, Vector4Uint v2) + /// + /// + /// + /// + /// + /// + public static bool operator ==(in Vector4Uint v1, in Vector4Uint v2) { return v1.Equals(v2); } - public static bool operator !=(Vector4Uint v1, Vector4Uint v2) + /// + /// + /// + /// + /// + /// + public static bool operator !=(in Vector4Uint v1, in Vector4Uint v2) { return v1.Equals(v2) == false; } diff --git a/NewtonVgo/Runtime/Structures/Vector4Ushort.cs b/NewtonVgo/Runtime/Structures/Vector4Ushort.cs index 0151ce8..69c543b 100644 --- a/NewtonVgo/Runtime/Structures/Vector4Ushort.cs +++ b/NewtonVgo/Runtime/Structures/Vector4Ushort.cs @@ -72,7 +72,7 @@ public Vector4Ushort(Vector4Ubyte source) /// public ushort this[int index] { - get + readonly get { switch (index) { @@ -124,7 +124,7 @@ public ushort this[int index] /// /// /// - public void Deconstruct(out ushort x, out ushort y, out ushort z, out ushort w) + public readonly void Deconstruct(out ushort x, out ushort y, out ushort z, out ushort w) { x = X; y = Y; @@ -137,7 +137,7 @@ public void Deconstruct(out ushort x, out ushort y, out ushort z, out ushort w) /// /// /// true if the specified object is equal to the current object; otherwise, false. - public bool Equals(Vector4Ushort other) + public readonly bool Equals(in Vector4Ushort other) { return X.Equals(other.X) && @@ -151,7 +151,7 @@ public bool Equals(Vector4Ushort other) /// /// /// true if the specified object is equal to the current object; otherwise, false. - public override bool Equals(object? other) + public override readonly bool Equals(object? other) { if (other is Vector4Ushort otherVector4) { @@ -165,7 +165,7 @@ public override bool Equals(object? other) /// Serves as the default hash function. /// /// A hash code for the current object. - public override int GetHashCode() + public override readonly int GetHashCode() { return X.GetHashCode() ^ @@ -193,7 +193,7 @@ public void Set(ushort newX, ushort newY, ushort newZ, ushort newW) /// Convert Vector4Ushort to Vector4Uint. /// /// - public Vector4Uint ToVector4Uint() + public readonly Vector4Uint ToVector4Uint() { return new Vector4Uint(this); } @@ -202,7 +202,7 @@ public Vector4Uint ToVector4Uint() /// Try convert Vector4Ushort to Vector4Ubyte. /// /// true if the operation is successful; otherwise, false. - public bool TryConvertTo(out Vector4Ubyte destination) + public readonly bool TryConvertTo(out Vector4Ubyte destination) { if ((X <= byte.MaxValue) && (Y <= byte.MaxValue) && @@ -228,12 +228,24 @@ public bool TryConvertTo(out Vector4Ubyte destination) #region Operators - public static bool operator ==(Vector4Ushort v1, Vector4Ushort v2) + /// + /// + /// + /// + /// + /// + public static bool operator ==(in Vector4Ushort v1, in Vector4Ushort v2) { return v1.Equals(v2); } - public static bool operator !=(Vector4Ushort v1, Vector4Ushort v2) + /// + /// + /// + /// + /// + /// + public static bool operator !=(in Vector4Ushort v1, in Vector4Ushort v2) { return v1.Equals(v2) == false; } diff --git a/UniVgo2/Editor/Inspector/ScriptEditorBase.cs b/UniVgo2/Editor/Inspector/ScriptEditorBase.cs index 1c0e527..50e709c 100644 --- a/UniVgo2/Editor/Inspector/ScriptEditorBase.cs +++ b/UniVgo2/Editor/Inspector/ScriptEditorBase.cs @@ -42,7 +42,7 @@ public override void OnInspectorGUI() /// /// /// - protected virtual void SetPropertyField(SerializedProperty serializedProperty, string fieldName) + protected virtual void SetPropertyField(in SerializedProperty serializedProperty, in string fieldName) { var property = serializedProperty.FindPropertyRelative(fieldName); @@ -61,7 +61,7 @@ protected virtual void SetPropertyField(SerializedProperty serializedProperty, s /// /// /// - protected virtual void SetPropertyFields(SerializedProperty serializedProperty, IEnumerable fieldNames) + protected virtual void SetPropertyFields(in SerializedProperty serializedProperty, in IEnumerable fieldNames) { foreach (string fieldName in fieldNames) { diff --git a/UniVgo2/Editor/Inspector/VgoBlendShapeEditor.cs b/UniVgo2/Editor/Inspector/VgoBlendShapeEditor.cs index 5cc6105..4cdb8d2 100644 --- a/UniVgo2/Editor/Inspector/VgoBlendShapeEditor.cs +++ b/UniVgo2/Editor/Inspector/VgoBlendShapeEditor.cs @@ -169,7 +169,7 @@ private void DrawKind() EditorGUILayout.PrefixLabel("Kind"); - _BlendShapeConfiguration.kind = (VgoBlendShapeKind)EditorGUILayout.EnumPopup(_BlendShapeConfiguration.kind); + _BlendShapeConfiguration.Kind = (VgoBlendShapeKind)EditorGUILayout.EnumPopup(_BlendShapeConfiguration.Kind); EditorGUILayout.EndHorizontal(); } @@ -184,7 +184,7 @@ private void DrawFaceParts() return; } - List confFaceParts = _BlendShapeConfiguration.faceParts; + List confFaceParts = _BlendShapeConfiguration.FaceParts; int listCount = confFaceParts.Count; @@ -227,9 +227,9 @@ private void DrawFaceParts() using (new EditorGUILayout.VerticalScope(boxStyle, GUILayout.ExpandWidth(true))) { - facePart.index = EditorGUILayout.IntPopup("Index", facePart.index, _BlendShapeNames, _BlendShapeIndices); + facePart.Index = EditorGUILayout.IntPopup("Index", facePart.Index, _BlendShapeNames, _BlendShapeIndices); - facePart.type = (VgoBlendShapeFacePartsType)EditorGUILayout.EnumPopup("Type", facePart.type); + facePart.Type = (VgoBlendShapeFacePartsType)EditorGUILayout.EnumPopup("Type", facePart.Type); } } @@ -249,7 +249,7 @@ private void DrawBlinks() return; } - List confBlinks = _BlendShapeConfiguration.blinks; + List confBlinks = _BlendShapeConfiguration.Blinks; int listCount = confBlinks.Count; @@ -290,9 +290,9 @@ private void DrawBlinks() using (new EditorGUILayout.VerticalScope(boxStyle, GUILayout.ExpandWidth(true))) { - blink.type = (VgoBlendShapeBlinkType)EditorGUILayout.EnumPopup("Type", blink.type); + blink.Type = (VgoBlendShapeBlinkType)EditorGUILayout.EnumPopup("Type", blink.Type); - blink.index = EditorGUILayout.IntPopup("Index", blink.index, _BlendShapeNames, _BlendShapeIndices); + blink.Index = EditorGUILayout.IntPopup("Index", blink.Index, _BlendShapeNames, _BlendShapeIndices); } } } @@ -310,7 +310,7 @@ private void DrawVisemes() return; } - List confVisemes = _BlendShapeConfiguration.visemes; + List confVisemes = _BlendShapeConfiguration.Visemes; int listCount = confVisemes.Count; @@ -351,9 +351,9 @@ private void DrawVisemes() using (new EditorGUILayout.VerticalScope(boxStyle, GUILayout.ExpandWidth(true))) { - viseme.type = (VgoBlendShapeVisemeType)EditorGUILayout.EnumPopup("Type", viseme.type); + viseme.Type = (VgoBlendShapeVisemeType)EditorGUILayout.EnumPopup("Type", viseme.Type); - viseme.index = EditorGUILayout.IntPopup("Index", viseme.index, _BlendShapeNames, _BlendShapeIndices); + viseme.Index = EditorGUILayout.IntPopup("Index", viseme.Index, _BlendShapeNames, _BlendShapeIndices); } } } @@ -371,7 +371,7 @@ private void DrawPresets() return; } - List confPresets = _BlendShapeConfiguration.presets; + List confPresets = _BlendShapeConfiguration.Presets; int listCount = confPresets.Count; diff --git a/UniVgo2/Editor/Processors/VgoExportProcessor.cs b/UniVgo2/Editor/Processors/VgoExportProcessor.cs index 03dbba6..b129ab3 100644 --- a/UniVgo2/Editor/Processors/VgoExportProcessor.cs +++ b/UniVgo2/Editor/Processors/VgoExportProcessor.cs @@ -37,12 +37,12 @@ public static class VgoExportProcessor /// Whether type is BSON, otherwise JSON. /// The crypt algorithm. public static void ExportVgo( - GameObject gameObject, - VgoGeometryCoordinate geometryCoordinate = VgoGeometryCoordinate.RightHanded, - VgoUVCoordinate uvCoordinate = VgoUVCoordinate.TopLeft, - ImageType textureType = ImageType.PNG, - bool isBson = false, - string? cryptAlgorithms = null) + in GameObject gameObject, + in VgoGeometryCoordinate geometryCoordinate = VgoGeometryCoordinate.RightHanded, + in VgoUVCoordinate uvCoordinate = VgoUVCoordinate.TopLeft, + in ImageType textureType = ImageType.PNG, + in bool isBson = false, + in string? cryptAlgorithms = null) { try { @@ -149,7 +149,7 @@ public static void ExportVgo( /// The target. /// /// Returns true if validation is successful, false otherwise. - private static bool Validate(GameObject gameObject, out string errorMessage) + private static bool Validate(in GameObject gameObject, out string errorMessage) { //if (gameObject.TryGetComponent(out _) == false) //{ diff --git a/UniVgo2/Editor/ScriptedImporters/VgoScriptedImporter.cs b/UniVgo2/Editor/ScriptedImporters/VgoScriptedImporter.cs index f1dacae..f372717 100644 --- a/UniVgo2/Editor/ScriptedImporters/VgoScriptedImporter.cs +++ b/UniVgo2/Editor/ScriptedImporters/VgoScriptedImporter.cs @@ -182,7 +182,7 @@ public override void OnImportAsset(AssetImportContext ctx) continue; } - blendShapeConfiguration.name = blendShapeConfiguration.kind + "BlendShapeConfiguration"; + blendShapeConfiguration.name = blendShapeConfiguration.Kind + "BlendShapeConfiguration"; ctx.AddObjectToAsset(blendShapeConfiguration.name, blendShapeConfiguration); } } @@ -206,7 +206,7 @@ public override void OnImportAsset(AssetImportContext ctx) /// /// The file path of the vgo. /// A vgo model asset. - protected virtual VgoModelAsset LoadModel(string vgoFilePath) + protected virtual VgoModelAsset LoadModel(in string vgoFilePath) { string? vgkFilePath = FindVgkFilePath(vgoFilePath); @@ -220,7 +220,7 @@ protected virtual VgoModelAsset LoadModel(string vgoFilePath) /// /// The file path of the vgo. /// A vgo model asset. - protected virtual VgoModelAsset ExtractModel(string vgoFilePath) + protected virtual VgoModelAsset ExtractModel(in string vgoFilePath) { string? vgkFilePath = FindVgkFilePath(vgoFilePath); @@ -234,7 +234,7 @@ protected virtual VgoModelAsset ExtractModel(string vgoFilePath) /// /// The file path of the vgo. /// The file path of the vgk. - protected virtual string? FindVgkFilePath(string vgoFilePath) + protected virtual string? FindVgkFilePath(in string vgoFilePath) { var vgoFileInfo = new FileInfo(vgoFilePath); @@ -363,7 +363,7 @@ public virtual void ExtractTextures() /// /// /// - public virtual void ExtractTextures(string dirName, Func ExtractModel, bool continueMaterial = false) + public virtual void ExtractTextures(in string dirName, in Func ExtractModel, bool continueMaterial = false) { if (string.IsNullOrEmpty(assetPath)) { @@ -529,7 +529,7 @@ public virtual void ClearExtarnalObjects() where T : UnityEngine.Object /// /// /// - public virtual void ExtractAssets(string dirName, string extension) where T : UnityEngine.Object + public virtual void ExtractAssets(in string dirName, in string extension) where T : UnityEngine.Object { if (string.IsNullOrEmpty(assetPath)) { @@ -558,7 +558,7 @@ public virtual void ExtractAssets(string dirName, string extension) where T : /// /// /// - protected virtual void ExtractFromAsset(UnityEngine.Object subAsset, string destinationPath, bool isForceUpdate) + protected virtual void ExtractFromAsset(in UnityEngine.Object subAsset, in string destinationPath, in bool isForceUpdate) { string assetPath = AssetDatabase.GetAssetPath(subAsset); @@ -594,7 +594,7 @@ public virtual Dictionary GetExternalUnityObjects() where T : Unit /// /// /// - public virtual void SetExternalUnityObject(SourceAssetIdentifier sourceAssetIdentifier, T obj) where T : UnityEngine.Object + public virtual void SetExternalUnityObject(in SourceAssetIdentifier sourceAssetIdentifier, T obj) where T : UnityEngine.Object { AddRemap(sourceAssetIdentifier, obj); AssetDatabase.WriteImportSettingsIfDirty(assetPath); @@ -607,7 +607,7 @@ public virtual void SetExternalUnityObject(SourceAssetIdentifier sourceAssetI /// /// /// - protected virtual IEnumerable GetSubAssets(string assetPath) where T : UnityEngine.Object + protected virtual IEnumerable GetSubAssets(in string assetPath) where T : UnityEngine.Object { return AssetDatabase .LoadAllAssetsAtPath(assetPath) @@ -621,7 +621,7 @@ protected virtual IEnumerable GetSubAssets(string assetPath) where T : Uni /// /// /// - protected virtual DirectoryInfo CreateDirectoryIfNotExists(string path) + protected virtual DirectoryInfo CreateDirectoryIfNotExists(in string path) { DirectoryInfo directoryInfo = new DirectoryInfo(path); diff --git a/UniVgo2/Editor/ScriptedImporters/VgoScriptedImporterEditor.cs b/UniVgo2/Editor/ScriptedImporters/VgoScriptedImporterEditor.cs index 85036f7..24bb79f 100644 --- a/UniVgo2/Editor/ScriptedImporters/VgoScriptedImporterEditor.cs +++ b/UniVgo2/Editor/ScriptedImporters/VgoScriptedImporterEditor.cs @@ -127,7 +127,7 @@ public override void OnInspectorGUI() /// /// /// - protected virtual void DrawRemapGUI(string title, VgoScriptedImporter importer) where T : UnityEngine.Object + protected virtual void DrawRemapGUI(in string title, in VgoScriptedImporter importer) where T : UnityEngine.Object { EditorGUILayout.Foldout(_isOpen, title); EditorGUI.indentLevel++; diff --git a/UniVgo2/Runtime/Components/VgoBlendShape.cs b/UniVgo2/Runtime/Components/VgoBlendShape.cs index 34a57c2..2300234 100644 --- a/UniVgo2/Runtime/Components/VgoBlendShape.cs +++ b/UniVgo2/Runtime/Components/VgoBlendShape.cs @@ -40,7 +40,7 @@ private void Awake() /// /// /// - public int GetVgoBlendShapeIndex(VgoBlendShapeBlinkType blinkType) + public int GetVgoBlendShapeIndex(in VgoBlendShapeBlinkType blinkType) { if (blinkType == VgoBlendShapeBlinkType.None) { @@ -52,14 +52,16 @@ public int GetVgoBlendShapeIndex(VgoBlendShapeBlinkType blinkType) return -1; } - BlendShapeBlink? blendShapeBlink = BlendShapeConfiguration.blinks.FirstOrDefault(x => x.type == blinkType); + var type = blinkType; + + BlendShapeBlink? blendShapeBlink = BlendShapeConfiguration.Blinks.FirstOrDefault(x => x.Type == type); if (blendShapeBlink == null) { return -1; } - return blendShapeBlink.index; + return blendShapeBlink.Index; } /// @@ -67,7 +69,7 @@ public int GetVgoBlendShapeIndex(VgoBlendShapeBlinkType blinkType) /// /// /// - public int GetVgoBlendShapeIndex(VgoBlendShapeVisemeType visemeType) + public int GetVgoBlendShapeIndex(in VgoBlendShapeVisemeType visemeType) { if (visemeType == VgoBlendShapeVisemeType.None) { @@ -79,14 +81,16 @@ public int GetVgoBlendShapeIndex(VgoBlendShapeVisemeType visemeType) return -1; } - BlendShapeViseme? blendShapeViseme = BlendShapeConfiguration.visemes.FirstOrDefault(x => x.type == visemeType); + var type = visemeType; + + BlendShapeViseme? blendShapeViseme = BlendShapeConfiguration.Visemes.FirstOrDefault(x => x.Type == type); if (blendShapeViseme == null) { return -1; } - return blendShapeViseme.index; + return blendShapeViseme.Index; } /// @@ -94,7 +98,7 @@ public int GetVgoBlendShapeIndex(VgoBlendShapeVisemeType visemeType) /// /// The index of the BlendShape whose weight you want to retrieve. /// The weight of the BlendShape. - public float GetBlendShapeWeight(int index) + public float GetBlendShapeWeight(in int index) { if (_SkinnedMeshRenderer == null) { @@ -109,7 +113,7 @@ public float GetBlendShapeWeight(int index) /// /// The index of the BlendShape to modify. /// The weight for this BlendShape. - public void SetBlendShapeWeight(int index, float value) + public void SetBlendShapeWeight(in int index, in float value) { if (_SkinnedMeshRenderer == null) { @@ -124,7 +128,7 @@ public void SetBlendShapeWeight(int index, float value) /// /// The type of blink. /// The weight for this BlendShape. - public void SetBlendShapeWeight(VgoBlendShapeBlinkType blinkType, float value) + public void SetBlendShapeWeight(in VgoBlendShapeBlinkType blinkType, in float value) { if (_SkinnedMeshRenderer == null) { @@ -136,14 +140,16 @@ public void SetBlendShapeWeight(VgoBlendShapeBlinkType blinkType, float value) return; } - BlendShapeBlink? vgoBlink = BlendShapeConfiguration.blinks.FirstOrDefault(x => x.type == blinkType); + var type = blinkType; + + BlendShapeBlink? vgoBlink = BlendShapeConfiguration.Blinks.FirstOrDefault(x => x.Type == type); if (vgoBlink == null) { return; } - _SkinnedMeshRenderer.SetBlendShapeWeight(vgoBlink.index, value); + _SkinnedMeshRenderer.SetBlendShapeWeight(vgoBlink.Index, value); } /// @@ -151,7 +157,7 @@ public void SetBlendShapeWeight(VgoBlendShapeBlinkType blinkType, float value) /// /// The type of viseme. /// The weight for this BlendShape. - public void SetBlendShapeWeight(VgoBlendShapeVisemeType visemeType, float value) + public void SetBlendShapeWeight(in VgoBlendShapeVisemeType visemeType, in float value) { if (_SkinnedMeshRenderer == null) { @@ -163,14 +169,16 @@ public void SetBlendShapeWeight(VgoBlendShapeVisemeType visemeType, float value) return; } - BlendShapeViseme? vgoViseme = BlendShapeConfiguration.visemes.FirstOrDefault(x => x.type == visemeType); + var type = visemeType; + + BlendShapeViseme? vgoViseme = BlendShapeConfiguration.Visemes.FirstOrDefault(x => x.Type == type); if (vgoViseme == null) { return; } - _SkinnedMeshRenderer.SetBlendShapeWeight(vgoViseme.index, value); + _SkinnedMeshRenderer.SetBlendShapeWeight(vgoViseme.Index, value); } /// @@ -179,7 +187,7 @@ public void SetBlendShapeWeight(VgoBlendShapeVisemeType visemeType, float value) /// The preset type. /// Whether to ignore the eyelids. /// Whether to ignore the mouth. - public void SetBlendShapeWeight(VgoBlendShapePresetType presetType, bool ignoreEyelid = false, bool ignoreMouth = false) + public void SetBlendShapeWeight(in VgoBlendShapePresetType presetType, in bool ignoreEyelid = false, in bool ignoreMouth = false) { if (_SkinnedMeshRenderer == null) { @@ -191,7 +199,9 @@ public void SetBlendShapeWeight(VgoBlendShapePresetType presetType, bool ignoreE return; } - VgoMeshBlendShapePreset? preset = BlendShapeConfiguration.presets.FirstOrDefault(x => x.type == presetType); + var type = presetType; + + VgoMeshBlendShapePreset? preset = BlendShapeConfiguration.Presets.FirstOrDefault(x => x.type == type); if (preset == null) { @@ -204,7 +214,7 @@ public void SetBlendShapeWeight(VgoBlendShapePresetType presetType, bool ignoreE { if (ignoreEyelid) { - BlendShapeBlink? blink = BlendShapeConfiguration.blinks.FirstOrDefault(x => x.index == binding.index); + BlendShapeBlink? blink = BlendShapeConfiguration.Blinks.FirstOrDefault(x => x.Index == binding.index); if (blink != null) { @@ -214,7 +224,7 @@ public void SetBlendShapeWeight(VgoBlendShapePresetType presetType, bool ignoreE if (ignoreMouth) { - BlendShapeViseme? visume = BlendShapeConfiguration.visemes.FirstOrDefault(x => x.index == binding.index); + BlendShapeViseme? visume = BlendShapeConfiguration.Visemes.FirstOrDefault(x => x.Index == binding.index); if (visume != null) { @@ -222,18 +232,18 @@ public void SetBlendShapeWeight(VgoBlendShapePresetType presetType, bool ignoreE } } - BlendShapeFacePart? facePart = BlendShapeConfiguration.faceParts.FirstOrDefault(x => x.index == binding.index); + BlendShapeFacePart? facePart = BlendShapeConfiguration.FaceParts.FirstOrDefault(x => x.Index == binding.index); if (facePart != null) { - if (facePart.type == VgoBlendShapeFacePartsType.Eyelid) + if (facePart.Type == VgoBlendShapeFacePartsType.Eyelid) { if (ignoreEyelid) { continue; } } - else if (facePart.type == VgoBlendShapeFacePartsType.Mouth) + else if (facePart.Type == VgoBlendShapeFacePartsType.Mouth) { if (ignoreMouth) { diff --git a/UniVgo2/Runtime/Configurations/AvatarConfiguration.cs b/UniVgo2/Runtime/Configurations/AvatarConfiguration.cs index a8cbde9..a7fbf71 100644 --- a/UniVgo2/Runtime/Configurations/AvatarConfiguration.cs +++ b/UniVgo2/Runtime/Configurations/AvatarConfiguration.cs @@ -20,7 +20,22 @@ public class AvatarConfiguration : ScriptableObject ///// The name of this human avatar. //public string name; + /// The name of this human avatar. + public string Name + { + get => name; + set => name = value; + } + + /// List of the human bone. + [SerializeField] + private List humanBones = new List(); + /// List of the human bone. - public List humanBones = new List(); + public List HumanBones + { + get => humanBones; + set => humanBones = value; + } } } diff --git a/UniVgo2/Runtime/Configurations/BlendShape/BlendShapeBlink.cs b/UniVgo2/Runtime/Configurations/BlendShape/BlendShapeBlink.cs index c8cd975..28f9a9d 100644 --- a/UniVgo2/Runtime/Configurations/BlendShape/BlendShapeBlink.cs +++ b/UniVgo2/Runtime/Configurations/BlendShape/BlendShapeBlink.cs @@ -7,6 +7,7 @@ namespace UniVgo2 { using NewtonVgo; using System; + using UnityEngine; /// /// BlendShape Blink @@ -15,9 +16,25 @@ namespace UniVgo2 public class BlendShapeBlink { /// The type of blink. - public VgoBlendShapeBlinkType type; + [SerializeField] + private VgoBlendShapeBlinkType type; + + /// The type of blink. + public VgoBlendShapeBlinkType Type + { + get => type; + set => type = value; + } + + /// The index of the BlendShape. + [SerializeField] + private int index; /// The index of the BlendShape. - public int index; + public int Index + { + get => index; + set => index = value; + } } } diff --git a/UniVgo2/Runtime/Configurations/BlendShape/BlendShapeFacePart.cs b/UniVgo2/Runtime/Configurations/BlendShape/BlendShapeFacePart.cs index 04104e9..9ce05b5 100644 --- a/UniVgo2/Runtime/Configurations/BlendShape/BlendShapeFacePart.cs +++ b/UniVgo2/Runtime/Configurations/BlendShape/BlendShapeFacePart.cs @@ -7,6 +7,7 @@ namespace UniVgo2 { using NewtonVgo; using System; + using UnityEngine; /// /// VGO BlendShape Face Part @@ -15,9 +16,25 @@ namespace UniVgo2 public class BlendShapeFacePart { /// The index of the BlendShape. - public int index; + [SerializeField] + private int index; + + /// The index of the BlendShape. + public int Index + { + get => index; + set => index = value; + } + + /// The type of the face parts. + [SerializeField] + private VgoBlendShapeFacePartsType type; /// The type of the face parts. - public VgoBlendShapeFacePartsType type; + public VgoBlendShapeFacePartsType Type + { + get => type; + set => type = value; + } } } diff --git a/UniVgo2/Runtime/Configurations/BlendShape/BlendShapeViseme.cs b/UniVgo2/Runtime/Configurations/BlendShape/BlendShapeViseme.cs index 3b4dc6e..0e3c211 100644 --- a/UniVgo2/Runtime/Configurations/BlendShape/BlendShapeViseme.cs +++ b/UniVgo2/Runtime/Configurations/BlendShape/BlendShapeViseme.cs @@ -7,6 +7,7 @@ namespace UniVgo2 { using NewtonVgo; using System; + using UnityEngine; /// /// BlendShape Viseme @@ -15,9 +16,25 @@ namespace UniVgo2 public class BlendShapeViseme { /// The type of viseme. - public VgoBlendShapeVisemeType type; + [SerializeField] + private VgoBlendShapeVisemeType type; + + /// The type of viseme. + public VgoBlendShapeVisemeType Type + { + get => type; + set => type = value; + } + + /// The index of the BlendShape. + [SerializeField] + private int index; /// The index of the BlendShape. - public int index; + public int Index + { + get => index; + set => index = value; + } } } diff --git a/UniVgo2/Runtime/Configurations/BlendShapeConfiguration.cs b/UniVgo2/Runtime/Configurations/BlendShapeConfiguration.cs index 7606fc7..efa938c 100644 --- a/UniVgo2/Runtime/Configurations/BlendShapeConfiguration.cs +++ b/UniVgo2/Runtime/Configurations/BlendShapeConfiguration.cs @@ -17,11 +17,30 @@ namespace UniVgo2 [Serializable] public class BlendShapeConfiguration : ScriptableObject { - ///// The name of this info. + ///// The name of this configuration. //public string name; + /// The name of this configuration. + public string Name + { + get => name; + set => name = value; + } + + /// The kind of the BlendShape. + [SerializeField] + private VgoBlendShapeKind kind; + /// The kind of the BlendShape. - public VgoBlendShapeKind kind; + public VgoBlendShapeKind Kind + { + get => kind; + set => kind = value; + } + + /// List of face parts. + [SerializeField] + private List faceParts = new List(); /// List of face parts. /// @@ -29,15 +48,43 @@ public class BlendShapeConfiguration : ScriptableObject /// it becomes possible for the application to control such as ignoring changes in the eyelids and mouth when using FaceRig or microphone. /// The ones included in blinks and visemes will work without being set here. /// - public List faceParts = new List(); + public List FaceParts + { + get => faceParts; + set => faceParts = value; + } /// List of blink. - public List blinks = new List(); + [SerializeField] + private List blinks = new List(); + + /// List of blink. + public List Blinks + { + get => blinks; + set => blinks = value; + } + + /// Visemes. + [SerializeField] + private List visemes = new List(); /// Visemes. - public List visemes = new List(); + public List Visemes + { + get => visemes; + set => visemes = value; + } + + /// List of preset. + [SerializeField] + private List presets = new List(); /// List of preset. - public List presets = new List(); + public List Presets + { + get => presets; + set => presets = value; + } } } diff --git a/UniVgo2/Runtime/Converters/ArrayConverter.cs b/UniVgo2/Runtime/Converters/ArrayConverter.cs index e2bcff0..08e97ef 100644 --- a/UniVgo2/Runtime/Converters/ArrayConverter.cs +++ b/UniVgo2/Runtime/Converters/ArrayConverter.cs @@ -18,7 +18,7 @@ public static class ArrayConverter /// /// /// - public static Color ToColor(float[] values, bool gamma = false) + public static Color ToColor(in float[] values, in bool gamma = false) { if (values == null) { @@ -56,7 +56,7 @@ public static Color ToColor(float[] values, bool gamma = false) /// /// /// - public static Quaternion ToQuaternion(float[] values) + public static Quaternion ToQuaternion(in float[] values) { if (values == null) { @@ -76,7 +76,7 @@ public static Quaternion ToQuaternion(float[] values) /// /// /// - public static Vector2 ToVector2(float[] values) + public static Vector2 ToVector2(in float[] values) { if (values == null) { @@ -96,7 +96,7 @@ public static Vector2 ToVector2(float[] values) /// /// /// - public static Vector3 ToVector3(float[] values) + public static Vector3 ToVector3(in float[] values) { if (values == null) { @@ -116,7 +116,7 @@ public static Vector3 ToVector3(float[] values) /// /// /// - public static Vector4 ToVector4(float[] values) + public static Vector4 ToVector4(in float[] values) { if (values == null) { @@ -136,7 +136,7 @@ public static Vector4 ToVector4(float[] values) /// /// /// - public static Matrix4x4 ToMatrix4x4(float[] values) + public static Matrix4x4 ToMatrix4x4(in float[] values) { if (values == null) { diff --git a/UniVgo2/Runtime/Converters/Textures/ColorSpaceScope.cs b/UniVgo2/Runtime/Converters/Textures/ColorSpaceScope.cs index fc37d31..0dc52f6 100644 --- a/UniVgo2/Runtime/Converters/Textures/ColorSpaceScope.cs +++ b/UniVgo2/Runtime/Converters/Textures/ColorSpaceScope.cs @@ -11,7 +11,7 @@ namespace UniVgo2.Converters /// /// Color Space Scope /// - public struct ColorSpaceScope : IDisposable + public readonly struct ColorSpaceScope : IDisposable { /// Controls whether Linear-to-sRGB color conversion is performed while rendering. private readonly bool sRGBWrite; @@ -30,7 +30,7 @@ public ColorSpaceScope(bool sRGBWrite) /// Create a new instance of ColorSpaceScope with colorSpace. /// /// - public ColorSpaceScope(RenderTextureReadWrite colorSpace) + public ColorSpaceScope(in RenderTextureReadWrite colorSpace) { sRGBWrite = GL.sRGBWrite; GL.sRGBWrite = colorSpace != RenderTextureReadWrite.Linear; @@ -39,7 +39,7 @@ public ColorSpaceScope(RenderTextureReadWrite colorSpace) /// /// Restore Linear-to-sRGB color conversion state. /// - public void Dispose() + public readonly void Dispose() { GL.sRGBWrite = sRGBWrite; } diff --git a/UniVgo2/Runtime/Converters/Textures/ITextureConverter.cs b/UniVgo2/Runtime/Converters/Textures/ITextureConverter.cs index 4fad71e..0f03371 100644 --- a/UniVgo2/Runtime/Converters/Textures/ITextureConverter.cs +++ b/UniVgo2/Runtime/Converters/Textures/ITextureConverter.cs @@ -22,7 +22,7 @@ public interface ITextureConverter /// The texture map type. /// The metallic roughness. /// - Texture2D GetImportTexture(Texture2D source, VgoTextureMapType textureMapType, float metallicRoughness = -1.0f); + Texture2D GetImportTexture(in Texture2D source, in VgoTextureMapType textureMapType, in float metallicRoughness = -1.0f); /// /// Get export texture. @@ -32,7 +32,7 @@ public interface ITextureConverter /// The color space type. /// The metallic smoothness. /// - Texture2D GetExportTexture(Texture2D source, VgoTextureMapType textureMapType, VgoColorSpaceType colorSpaceType, float metallicSmoothness = -1.0f); + Texture2D GetExportTexture(in Texture2D source, in VgoTextureMapType textureMapType, in VgoColorSpaceType colorSpaceType, in float metallicSmoothness = -1.0f); #endregion } diff --git a/UniVgo2/Runtime/Converters/Textures/MetallicRoughnessMapConverter.cs b/UniVgo2/Runtime/Converters/Textures/MetallicRoughnessMapConverter.cs index dcaef8d..62fa456 100644 --- a/UniVgo2/Runtime/Converters/Textures/MetallicRoughnessMapConverter.cs +++ b/UniVgo2/Runtime/Converters/Textures/MetallicRoughnessMapConverter.cs @@ -14,7 +14,7 @@ namespace UniVgo2.Converters public class MetallicRoughnessMapConverter : TextureConverter { /// The smoothness or roughness. - private float _SmoothnessOrRoughness; + private readonly float _SmoothnessOrRoughness; /// /// Create a new instance of MetallicRoughnessMapConverter with smoothnessOrRoughness. @@ -28,9 +28,9 @@ public MetallicRoughnessMapConverter(float smoothnessOrRoughness) /// /// Get import texture. /// - /// The source texture. + /// The source texture. /// - public Texture2D GetImportTexture(Texture2D texture) + public Texture2D GetImportTexture(in Texture2D texture) { Texture2D copyTexture = CopyTexture2d(texture, VgoColorSpaceType.Linear); @@ -51,9 +51,9 @@ public Texture2D GetImportTexture(Texture2D texture) /// /// Get export texture. /// - /// The source texture. + /// The source texture. /// - public Texture2D GetExportTexture(Texture2D texture) + public Texture2D GetExportTexture(in Texture2D texture) { Texture2D copyTexture = CopyTexture2d(texture, VgoColorSpaceType.Linear); @@ -82,7 +82,7 @@ public Texture2D GetExportTexture(Texture2D texture) /// /// https://github.com/dwango/UniVRM/issues/212. /// - public Color32 Import(Color32 src) + public Color32 Import(in Color32 src) { float pixelRoughnessFactor = (src.g * _SmoothnessOrRoughness) / 255.0f; // roughness float pixelSmoothness = 1.0f - Mathf.Sqrt(pixelRoughnessFactor); @@ -108,7 +108,7 @@ public Color32 Import(Color32 src) /// https://blogs.unity3d.com/jp/2016/01/25/ggx-in-unity-5-3/ /// https://github.com/dwango/UniVRM/issues/212. /// - public Color32 Export(Color32 src) + public Color32 Export(in Color32 src) { float pixelSmoothness = (src.a * _SmoothnessOrRoughness) / 255.0f; // smoothness float pixelRoughnessFactorSqrt = (1.0f - pixelSmoothness); diff --git a/UniVgo2/Runtime/Converters/Textures/NormalMapConverter.cs b/UniVgo2/Runtime/Converters/Textures/NormalMapConverter.cs index 7253d6a..b280398 100644 --- a/UniVgo2/Runtime/Converters/Textures/NormalMapConverter.cs +++ b/UniVgo2/Runtime/Converters/Textures/NormalMapConverter.cs @@ -19,7 +19,7 @@ public class NormalMapConverter : TextureConverter /// /// The source texture. /// - public Texture2D GetImportTexture(Texture2D source) + public Texture2D GetImportTexture(in Texture2D source) { Shader? encoder = Shader.Find("UniGLTF/NormalMapEncoder"); @@ -49,7 +49,7 @@ public Texture2D GetImportTexture(Texture2D source) /// /// The source texture. /// - public Texture2D GetExportTexture(Texture2D source) + public Texture2D GetExportTexture(in Texture2D source) { Shader? decoder = Shader.Find("UniGLTF/NormalMapDecoder"); diff --git a/UniVgo2/Runtime/Converters/Textures/OcclusionMapConverter.cs b/UniVgo2/Runtime/Converters/Textures/OcclusionMapConverter.cs index 33d319e..4759e48 100644 --- a/UniVgo2/Runtime/Converters/Textures/OcclusionMapConverter.cs +++ b/UniVgo2/Runtime/Converters/Textures/OcclusionMapConverter.cs @@ -16,9 +16,9 @@ public class OcclusionMapConverter : TextureConverter /// /// Get import texture. /// - /// The source texture. + /// The source texture. /// - public Texture2D GetImportTexture(Texture2D texture) + public Texture2D GetImportTexture(in Texture2D texture) { Texture2D copyTexture = CopyTexture2d(texture, VgoColorSpaceType.Linear); @@ -39,9 +39,9 @@ public Texture2D GetImportTexture(Texture2D texture) /// /// Get export texture. /// - /// The source texture. + /// The source texture. /// - public Texture2D GetExportTexture(Texture2D texture) + public Texture2D GetExportTexture(in Texture2D texture) { Texture2D copyTexture = CopyTexture2d(texture, VgoColorSpaceType.Linear); diff --git a/UniVgo2/Runtime/Converters/Textures/TextureConverter.cs b/UniVgo2/Runtime/Converters/Textures/TextureConverter.cs index 59c1eac..91ecbae 100644 --- a/UniVgo2/Runtime/Converters/Textures/TextureConverter.cs +++ b/UniVgo2/Runtime/Converters/Textures/TextureConverter.cs @@ -20,7 +20,7 @@ public class TextureConverter : ITextureConverter /// The texture map type. /// The metallic roughness. /// - public virtual Texture2D GetImportTexture(Texture2D source, VgoTextureMapType textureMapType, float metallicRoughness = -1.0f) + public virtual Texture2D GetImportTexture(in Texture2D source, in VgoTextureMapType textureMapType, in float metallicRoughness = -1.0f) { if (textureMapType == VgoTextureMapType.NormalMap) { @@ -52,7 +52,7 @@ public virtual Texture2D GetImportTexture(Texture2D source, VgoTextureMapType te /// The color space type. /// The metallic smoothness. /// - public virtual Texture2D GetExportTexture(Texture2D source, VgoTextureMapType textureMapType, VgoColorSpaceType colorSpaceType, float metallicSmoothness = -1.0f) + public virtual Texture2D GetExportTexture(in Texture2D source, in VgoTextureMapType textureMapType, in VgoColorSpaceType colorSpaceType, in float metallicSmoothness = -1.0f) { if (textureMapType == VgoTextureMapType.NormalMap) { @@ -79,7 +79,7 @@ public virtual Texture2D GetExportTexture(Texture2D source, VgoTextureMapType te /// The color space type. /// The converter. /// The copied Texture2D. - protected virtual Texture2D CopyTexture2d(Texture2D source, VgoColorSpaceType colorSpaceType, Material? converter = null) + protected virtual Texture2D CopyTexture2d(in Texture2D source, in VgoColorSpaceType colorSpaceType, in Material? converter = null) { RenderTextureReadWrite readWrite = (colorSpaceType == VgoColorSpaceType.Linear) ? RenderTextureReadWrite.Linear : RenderTextureReadWrite.sRGB; diff --git a/UniVgo2/Runtime/Converters/VgoAnimationClipConverter.cs b/UniVgo2/Runtime/Converters/VgoAnimationClipConverter.cs index 703d533..3d77085 100644 --- a/UniVgo2/Runtime/Converters/VgoAnimationClipConverter.cs +++ b/UniVgo2/Runtime/Converters/VgoAnimationClipConverter.cs @@ -6,8 +6,8 @@ namespace UniVgo2.Converters { using NewtonVgo; - using System.Collections.Generic; using System; + using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -22,7 +22,7 @@ public class VgoAnimationClipConverter /// /// /// - public static VgoAnimationClip CreateFrom(AnimationClip animationClip, VgoGeometryCoordinate geometryCoordinate) + public static VgoAnimationClip CreateFrom(in AnimationClip animationClip, in VgoGeometryCoordinate geometryCoordinate) { var vgoAnimationClip = new VgoAnimationClip() { @@ -86,7 +86,7 @@ public static VgoAnimationClip CreateFrom(AnimationClip animationClip, VgoGeomet /// /// /// - public static VgoAnimationClip? CreateOrDefaultFrom(AnimationClip? animationClip, VgoGeometryCoordinate geometryCoordinate) + public static VgoAnimationClip? CreateOrDefaultFrom(in AnimationClip? animationClip, in VgoGeometryCoordinate geometryCoordinate) { if (animationClip == null) { @@ -101,7 +101,7 @@ public static VgoAnimationClip CreateFrom(AnimationClip animationClip, VgoGeomet /// /// /// - public static AnimationClip CreateAnimationClip(VgoAnimationClip vgoAnimationClip, VgoGeometryCoordinate geometryCoordinate) + public static AnimationClip CreateAnimationClip(in VgoAnimationClip vgoAnimationClip, in VgoGeometryCoordinate geometryCoordinate) { var animationClip = new AnimationClip() { @@ -195,7 +195,7 @@ public static AnimationClip CreateAnimationClip(VgoAnimationClip vgoAnimationCli /// /// /// - public static AnimationClip? CreateAnimationClipOrDefault(VgoAnimationClip? vgoAnimationClip, VgoGeometryCoordinate geometryCoordinate) + public static AnimationClip? CreateAnimationClipOrDefault(in VgoAnimationClip? vgoAnimationClip, in VgoGeometryCoordinate geometryCoordinate) { if (vgoAnimationClip == null) { diff --git a/UniVgo2/Runtime/Converters/VgoAnimationConverter.cs b/UniVgo2/Runtime/Converters/VgoAnimationConverter.cs index 3193418..06a5935 100644 --- a/UniVgo2/Runtime/Converters/VgoAnimationConverter.cs +++ b/UniVgo2/Runtime/Converters/VgoAnimationConverter.cs @@ -21,7 +21,7 @@ public class VgoAnimationConverter /// /// /// - public static VgoAnimation CreateFrom(Animation animation, IList animationClips, VgoGeometryCoordinate geometryCoordinate) + public static VgoAnimation CreateFrom(in Animation animation, in IList animationClips, in VgoGeometryCoordinate geometryCoordinate) { var vgoAnimation = new VgoAnimation() { @@ -45,7 +45,7 @@ public static VgoAnimation CreateFrom(Animation animation, IList /// /// /// - public static void SetComponentValue(Animation animation, VgoAnimation vgoAnimation, List? animationClips, VgoGeometryCoordinate geometryCoordinate) + public static void SetComponentValue(in Animation animation, in VgoAnimation vgoAnimation, in List? animationClips, in VgoGeometryCoordinate geometryCoordinate) { animation.name = vgoAnimation.name; animation.enabled = vgoAnimation.enabled; diff --git a/UniVgo2/Runtime/Converters/VgoAnimationCurveConverter.cs b/UniVgo2/Runtime/Converters/VgoAnimationCurveConverter.cs index b429849..1536f82 100644 --- a/UniVgo2/Runtime/Converters/VgoAnimationCurveConverter.cs +++ b/UniVgo2/Runtime/Converters/VgoAnimationCurveConverter.cs @@ -18,7 +18,7 @@ public class VgoAnimationCurveConverter /// /// /// - public static VgoAnimationCurve CreateFrom(AnimationCurve animationCurve) + public static VgoAnimationCurve CreateFrom(in AnimationCurve animationCurve) { var vgoAnimationCurve = new VgoAnimationCurve() { @@ -44,7 +44,7 @@ public static VgoAnimationCurve CreateFrom(AnimationCurve animationCurve) /// /// /// - public static VgoAnimationCurve? CreateOrDefaultFrom(AnimationCurve? animationCurve) + public static VgoAnimationCurve? CreateOrDefaultFrom(in AnimationCurve? animationCurve) { if (animationCurve == null) { @@ -59,7 +59,7 @@ public static VgoAnimationCurve CreateFrom(AnimationCurve animationCurve) /// /// /// - public static AnimationCurve CreateAnimationCurve(VgoAnimationCurve vgoAnimationCurve) + public static AnimationCurve CreateAnimationCurve(in VgoAnimationCurve vgoAnimationCurve) { var animationCurve = new AnimationCurve() { @@ -88,7 +88,7 @@ public static AnimationCurve CreateAnimationCurve(VgoAnimationCurve vgoAnimation /// /// /// - public static AnimationCurve? CreateAnimationCurveOrDefault(VgoAnimationCurve? vgoAnimationCurve) + public static AnimationCurve? CreateAnimationCurveOrDefault(in VgoAnimationCurve? vgoAnimationCurve) { if (vgoAnimationCurve is null) { diff --git a/UniVgo2/Runtime/Converters/VgoAnimatorConverter.cs b/UniVgo2/Runtime/Converters/VgoAnimatorConverter.cs index 4546847..9ad8e7c 100644 --- a/UniVgo2/Runtime/Converters/VgoAnimatorConverter.cs +++ b/UniVgo2/Runtime/Converters/VgoAnimatorConverter.cs @@ -18,7 +18,7 @@ public class VgoAnimatorConverter /// /// /// - public static VgoAnimator CreateFrom(Animator animator) + public static VgoAnimator CreateFrom(in Animator animator) { var vgoAnimator = new VgoAnimator() { @@ -38,7 +38,7 @@ public static VgoAnimator CreateFrom(Animator animator) /// /// /// - public static void SetComponentValue(Animator animator, VgoAnimator vgoAnimator) + public static void SetComponentValue(Animator animator, in VgoAnimator vgoAnimator) { animator.name = vgoAnimator.name; animator.enabled = vgoAnimator.enabled; diff --git a/UniVgo2/Runtime/Converters/VgoAvatarConverter.cs b/UniVgo2/Runtime/Converters/VgoAvatarConverter.cs index 8f3813b..74ee723 100644 --- a/UniVgo2/Runtime/Converters/VgoAvatarConverter.cs +++ b/UniVgo2/Runtime/Converters/VgoAvatarConverter.cs @@ -23,7 +23,7 @@ public class VgoAvatarConverter /// /// /// - public static VgoHumanAvatar? CreateVgoAvatarOrDefault(Animator animator, string nodeName, IList nodes) + public static VgoHumanAvatar? CreateVgoAvatarOrDefault(in Animator animator, in string nodeName, in IList nodes) { if (animator.avatar is null) { @@ -77,7 +77,7 @@ public class VgoAvatarConverter /// /// /// - public static Avatar CreateHumanAvatar(VgoHumanAvatar vgoAvatar, GameObject go, List nodes) + public static Avatar CreateHumanAvatar(in VgoHumanAvatar vgoAvatar, in GameObject go, in List nodes) { //string[] humanNames = HumanTrait.BoneName; diff --git a/UniVgo2/Runtime/Converters/VgoBoundsConverter.cs b/UniVgo2/Runtime/Converters/VgoBoundsConverter.cs index 9bb35d2..4669369 100644 --- a/UniVgo2/Runtime/Converters/VgoBoundsConverter.cs +++ b/UniVgo2/Runtime/Converters/VgoBoundsConverter.cs @@ -18,7 +18,7 @@ public class VgoBoundsConverter /// /// /// - public static NewtonVgo.Bounds? CreateFrom(UnityEngine.Bounds bounds, VgoGeometryCoordinate geometryCoordinate) + public static NewtonVgo.Bounds? CreateFrom(in UnityEngine.Bounds bounds, in VgoGeometryCoordinate geometryCoordinate) { if (bounds == default) { @@ -36,7 +36,7 @@ public class VgoBoundsConverter /// /// /// - public static UnityEngine.Bounds CreateBounds(NewtonVgo.Bounds? vgoBounds, VgoGeometryCoordinate geometryCoordinate) + public static UnityEngine.Bounds CreateBounds(in NewtonVgo.Bounds? vgoBounds, in VgoGeometryCoordinate geometryCoordinate) { if (vgoBounds == null) { diff --git a/UniVgo2/Runtime/Converters/VgoClothConverter.cs b/UniVgo2/Runtime/Converters/VgoClothConverter.cs index 9a2267f..aee867e 100644 --- a/UniVgo2/Runtime/Converters/VgoClothConverter.cs +++ b/UniVgo2/Runtime/Converters/VgoClothConverter.cs @@ -23,7 +23,7 @@ public class VgoClothConverter /// /// /// - public static VgoCloth CreateFrom(Cloth cloth, VgoGeometryCoordinate geometryCoordinate, IList colliderList, IVgoStorage vgoStorage) + public static VgoCloth CreateFrom(in Cloth cloth, in VgoGeometryCoordinate geometryCoordinate, IList colliderList, in IVgoStorage vgoStorage) { var vgoCloth = new VgoCloth() { @@ -82,7 +82,7 @@ public static VgoCloth CreateFrom(Cloth cloth, VgoGeometryCoordinate geometryCoo /// /// /// - public static VgoCloth? CreateOrDefaultFrom(Cloth? cloth, VgoGeometryCoordinate geometryCoordinate, IList colliderList, IVgoStorage vgoStorage) + public static VgoCloth? CreateOrDefaultFrom(in Cloth? cloth, in VgoGeometryCoordinate geometryCoordinate, IList colliderList, in IVgoStorage vgoStorage) { if (cloth == null) { @@ -100,7 +100,7 @@ public static VgoCloth CreateFrom(Cloth cloth, VgoGeometryCoordinate geometryCoo /// /// /// - public static void SetComponentValue(Cloth cloth, VgoCloth vgoCloth, VgoGeometryCoordinate geometryCoordinate, List colliderList, IVgoStorage vgoStorage) + public static void SetComponentValue(Cloth cloth, in VgoCloth vgoCloth, in VgoGeometryCoordinate geometryCoordinate, List colliderList, in IVgoStorage vgoStorage) { //cloth.enabled = vgoCloth.enabled; cloth.enabled = false; diff --git a/UniVgo2/Runtime/Converters/VgoColliderConverter.cs b/UniVgo2/Runtime/Converters/VgoColliderConverter.cs index 1827ea4..63c075e 100644 --- a/UniVgo2/Runtime/Converters/VgoColliderConverter.cs +++ b/UniVgo2/Runtime/Converters/VgoColliderConverter.cs @@ -20,7 +20,7 @@ public class VgoColliderConverter /// /// /// - public static VgoCollider CreateFrom(Collider collider, VgoGeometryCoordinate geometryCoordinate) + public static VgoCollider CreateFrom(in Collider collider, in VgoGeometryCoordinate geometryCoordinate) { if (collider is BoxCollider boxCollider) { @@ -77,7 +77,7 @@ public static VgoCollider CreateFrom(Collider collider, VgoGeometryCoordinate ge /// /// /// - public static VgoCollider? CreateOrDefaultFrom(Collider? collider, VgoGeometryCoordinate geometryCoordinate) + public static VgoCollider? CreateOrDefaultFrom(in Collider? collider, in VgoGeometryCoordinate geometryCoordinate) { if (collider == null) { @@ -102,7 +102,7 @@ collider is CapsuleCollider || /// /// /// - public static void SetComponentValue(Collider collider, VgoCollider vgoCollider, VgoGeometryCoordinate geometryCoordinate) + public static void SetComponentValue(Collider collider, in VgoCollider vgoCollider, in VgoGeometryCoordinate geometryCoordinate) { if (collider == null) { diff --git a/UniVgo2/Runtime/Converters/VgoGradientConverter.cs b/UniVgo2/Runtime/Converters/VgoGradientConverter.cs index 0be5554..d45ffb2 100644 --- a/UniVgo2/Runtime/Converters/VgoGradientConverter.cs +++ b/UniVgo2/Runtime/Converters/VgoGradientConverter.cs @@ -18,7 +18,7 @@ public class VgoGradientConverter /// /// /// - public static VgoGradient CreateFrom(Gradient gradient) + public static VgoGradient CreateFrom(in Gradient gradient) { var vgoGradient = new VgoGradient() { @@ -63,7 +63,7 @@ public static VgoGradient CreateFrom(Gradient gradient) /// /// /// - public static VgoGradient? CreateOrDefaultFrom(Gradient? gradient) + public static VgoGradient? CreateOrDefaultFrom(in Gradient? gradient) { if (gradient == null) { @@ -78,7 +78,7 @@ public static VgoGradient CreateFrom(Gradient gradient) /// /// /// - public static Gradient CreateGradient(VgoGradient vgoGradient) + public static Gradient CreateGradient(in VgoGradient vgoGradient) { var gradient = new Gradient() { @@ -125,7 +125,7 @@ public static Gradient CreateGradient(VgoGradient vgoGradient) /// /// /// - public static Gradient? CreateGradientOrDefault(VgoGradient? vgoGradient) + public static Gradient? CreateGradientOrDefault(in VgoGradient? vgoGradient) { if (vgoGradient == null) { diff --git a/UniVgo2/Runtime/Converters/VgoKeyframeConverter.cs b/UniVgo2/Runtime/Converters/VgoKeyframeConverter.cs index b7e5780..36122bc 100644 --- a/UniVgo2/Runtime/Converters/VgoKeyframeConverter.cs +++ b/UniVgo2/Runtime/Converters/VgoKeyframeConverter.cs @@ -18,7 +18,7 @@ public class VgoKeyframeConverter /// /// /// - public static VgoKeyframe CreateFrom(Keyframe keyframe) + public static VgoKeyframe CreateFrom(in Keyframe keyframe) { return new VgoKeyframe() { @@ -37,7 +37,7 @@ public static VgoKeyframe CreateFrom(Keyframe keyframe) /// /// /// - public static Keyframe CreateKeyframe(VgoKeyframe vgoKeyframe) + public static Keyframe CreateKeyframe(in VgoKeyframe vgoKeyframe) { if (vgoKeyframe == null) { diff --git a/UniVgo2/Runtime/Converters/VgoLightConverter.cs b/UniVgo2/Runtime/Converters/VgoLightConverter.cs index 35beafe..90c364a 100644 --- a/UniVgo2/Runtime/Converters/VgoLightConverter.cs +++ b/UniVgo2/Runtime/Converters/VgoLightConverter.cs @@ -18,13 +18,8 @@ public class VgoLightConverter /// /// /// - public static VgoLight? CreateFrom(Light? light) + public static VgoLight CreateFrom(in Light light) { - if (light == null) - { - return null; - } - var vgoLight = new VgoLight() { enabled = light.enabled, @@ -127,7 +122,7 @@ public class VgoLightConverter /// /// /// - public static VgoLight? CreateOrDefaultFrom(Light? light) + public static VgoLight? CreateOrDefaultFrom(in Light? light) { if (light == null) { @@ -142,7 +137,7 @@ public class VgoLightConverter /// /// /// - public static void SetComponentValue(Light light, VgoLight vgoLight) + public static void SetComponentValue(Light light, in VgoLight vgoLight) { if (light == null) { diff --git a/UniVgo2/Runtime/Converters/VgoParticleSystemBurstConverter.cs b/UniVgo2/Runtime/Converters/VgoParticleSystemBurstConverter.cs index f4762df..93ceb65 100644 --- a/UniVgo2/Runtime/Converters/VgoParticleSystemBurstConverter.cs +++ b/UniVgo2/Runtime/Converters/VgoParticleSystemBurstConverter.cs @@ -16,9 +16,9 @@ public class VgoParticleSystemBurstConverter /// /// Create VGO_PS_Burst from Burst. /// - /// + /// /// - public static VGO_PS_Burst CreateFrom(Burst burst) + public static VGO_PS_Burst CreateFrom(in Burst burst) { return new VGO_PS_Burst() { @@ -35,7 +35,7 @@ public static VGO_PS_Burst CreateFrom(Burst burst) /// /// /// - public static Burst CreateBurst(VGO_PS_Burst vgoBurst) + public static Burst CreateBurst(in VGO_PS_Burst vgoBurst) { if (vgoBurst == null) { @@ -77,14 +77,15 @@ public static Burst CreateBurst(VGO_PS_Burst vgoBurst) probability = vgoBurst.probability; } - Burst burst = new Burst( + var burst = new Burst( _time: time, _count: count, _cycleCount: cycleCount, _repeatInterval: repeatInterval - ); - - burst.probability = probability; + ) + { + probability = probability, + }; return burst; } diff --git a/UniVgo2/Runtime/Converters/VgoParticleSystemMinMaxCurveConverter.cs b/UniVgo2/Runtime/Converters/VgoParticleSystemMinMaxCurveConverter.cs index 3d62e8d..e44eb7e 100644 --- a/UniVgo2/Runtime/Converters/VgoParticleSystemMinMaxCurveConverter.cs +++ b/UniVgo2/Runtime/Converters/VgoParticleSystemMinMaxCurveConverter.cs @@ -20,7 +20,7 @@ public class VgoParticleSystemMinMaxCurveConverter /// /// /// - public static VGO_PS_MinMaxCurve CreateFrom(MinMaxCurve minMaxCurve) + public static VGO_PS_MinMaxCurve CreateFrom(in MinMaxCurve minMaxCurve) { switch (minMaxCurve.mode) { @@ -72,7 +72,7 @@ public static VGO_PS_MinMaxCurve CreateFrom(MinMaxCurve minMaxCurve) /// /// /// - public static MinMaxCurve CreateMinMaxCurve(VGO_PS_MinMaxCurve? vgoMinMaxCurve) + public static MinMaxCurve CreateMinMaxCurve(in VGO_PS_MinMaxCurve? vgoMinMaxCurve) { if (vgoMinMaxCurve == null) { diff --git a/UniVgo2/Runtime/Converters/VgoParticleSystemMinMaxGradientConverter.cs b/UniVgo2/Runtime/Converters/VgoParticleSystemMinMaxGradientConverter.cs index b05a1cd..d2ca2cb 100644 --- a/UniVgo2/Runtime/Converters/VgoParticleSystemMinMaxGradientConverter.cs +++ b/UniVgo2/Runtime/Converters/VgoParticleSystemMinMaxGradientConverter.cs @@ -20,7 +20,7 @@ public class VgoParticleSystemMinMaxGradientConverter /// /// /// - public static VGO_PS_MinMaxGradient CreateFrom(MinMaxGradient minMaxGradient) + public static VGO_PS_MinMaxGradient CreateFrom(in MinMaxGradient minMaxGradient) { switch (minMaxGradient.mode) { @@ -80,7 +80,7 @@ public static VGO_PS_MinMaxGradient CreateFrom(MinMaxGradient minMaxGradient) /// /// /// - public static MinMaxGradient CreateMinMaxGradient(VGO_PS_MinMaxGradient? vgoMinMaxGradient) + public static MinMaxGradient CreateMinMaxGradient(in VGO_PS_MinMaxGradient? vgoMinMaxGradient) { if (vgoMinMaxGradient == null) { @@ -116,8 +116,10 @@ public static MinMaxGradient CreateMinMaxGradient(VGO_PS_MinMaxGradient? vgoMinM var minMaxGradient = new MinMaxGradient( min: vgoMinMaxGradient.colorMin.ToUnityColor().gamma, max: vgoMinMaxGradient.colorMax.ToUnityColor().gamma - ); - minMaxGradient.mode = UnityEngine.ParticleSystemGradientMode.RandomColor; + ) + { + mode = UnityEngine.ParticleSystemGradientMode.RandomColor + }; return minMaxGradient; default: diff --git a/UniVgo2/Runtime/Converters/VgoPhysicMaterialConverter.cs b/UniVgo2/Runtime/Converters/VgoPhysicMaterialConverter.cs index 25b48ef..60e34fd 100644 --- a/UniVgo2/Runtime/Converters/VgoPhysicMaterialConverter.cs +++ b/UniVgo2/Runtime/Converters/VgoPhysicMaterialConverter.cs @@ -18,7 +18,7 @@ public class VgoPhysicMaterialConverter /// /// /// - public static VgoPhysicMaterial CreateFrom(PhysicMaterial physicMaterial) + public static VgoPhysicMaterial CreateFrom(in PhysicMaterial physicMaterial) { return new VgoPhysicMaterial { @@ -35,7 +35,7 @@ public static VgoPhysicMaterial CreateFrom(PhysicMaterial physicMaterial) /// /// /// - public static VgoPhysicMaterial? CreateOrDefaultFrom(PhysicMaterial? physicMaterial) + public static VgoPhysicMaterial? CreateOrDefaultFrom(in PhysicMaterial? physicMaterial) { if (physicMaterial == null) { @@ -50,7 +50,7 @@ public static VgoPhysicMaterial CreateFrom(PhysicMaterial physicMaterial) /// /// /// PhysicMaterial - public static PhysicMaterial ToPhysicMaterial(VgoPhysicMaterial vgoPhysicMaterial) + public static PhysicMaterial ToPhysicMaterial(in VgoPhysicMaterial vgoPhysicMaterial) { return new PhysicMaterial() { diff --git a/UniVgo2/Runtime/Converters/VgoRigidbodyConverter.cs b/UniVgo2/Runtime/Converters/VgoRigidbodyConverter.cs index 7ab619d..a0b2b0b 100644 --- a/UniVgo2/Runtime/Converters/VgoRigidbodyConverter.cs +++ b/UniVgo2/Runtime/Converters/VgoRigidbodyConverter.cs @@ -18,7 +18,7 @@ public class VgoRigidbodyConverter /// /// /// - public static VgoRigidbody CreateFrom(Rigidbody rigidbody) + public static VgoRigidbody CreateFrom(in Rigidbody rigidbody) { return new VgoRigidbody() { @@ -38,7 +38,7 @@ public static VgoRigidbody CreateFrom(Rigidbody rigidbody) /// /// /// - public static void SetComponentValue(Rigidbody rigidbody, VgoRigidbody vgoRigidbody) + public static void SetComponentValue(Rigidbody rigidbody, in VgoRigidbody vgoRigidbody) { rigidbody.mass = vgoRigidbody.mass; rigidbody.drag = vgoRigidbody.drag; diff --git a/UniVgo2/Runtime/Converters/VgoTransformConverter.cs b/UniVgo2/Runtime/Converters/VgoTransformConverter.cs index 11a2c5a..8ecaa2c 100644 --- a/UniVgo2/Runtime/Converters/VgoTransformConverter.cs +++ b/UniVgo2/Runtime/Converters/VgoTransformConverter.cs @@ -19,13 +19,8 @@ public class VgoTransformConverter /// /// /// - public static VgoTransform? CreateFrom(Transform? transform, VgoGeometryCoordinate geometryCoordinate) + public static VgoTransform CreateFrom(in Transform transform, in VgoGeometryCoordinate geometryCoordinate) { - if (transform == null) - { - return null; - } - VgoTransform vgoTransform = new VgoTransform() { position = transform.localPosition.ToNullableNumericsVector3(Vector3.zero, geometryCoordinate), @@ -36,6 +31,22 @@ public class VgoTransformConverter return vgoTransform; } + /// + /// Create VgoTransform from Transform. + /// + /// + /// + /// + public static VgoTransform? CreateOrDefaultFrom(in Transform? transform, in VgoGeometryCoordinate geometryCoordinate) + { + if (transform == null) + { + return default; + } + + return CreateFrom(transform, geometryCoordinate); + } + /// /// Create Transform from VgoTransform. /// @@ -43,7 +54,7 @@ public class VgoTransformConverter /// /// /// - public static void SetComponentValue(Transform transform, VgoTransform vgoTransform, VgoGeometryCoordinate geometryCoordinate) + public static void SetComponentValue(Transform transform, in VgoTransform vgoTransform, in VgoGeometryCoordinate geometryCoordinate) { transform.localPosition = vgoTransform.position.ToUnityVector3(Vector3.zero, geometryCoordinate); transform.localRotation = vgoTransform.rotation.ToUnityQuaternion(Quaternion.identity, geometryCoordinate); diff --git a/UniVgo2/Runtime/Extensions/ListExtensions.cs b/UniVgo2/Runtime/Extensions/ListExtensions.cs index 609d0e0..e8133c4 100644 --- a/UniVgo2/Runtime/Extensions/ListExtensions.cs +++ b/UniVgo2/Runtime/Extensions/ListExtensions.cs @@ -14,13 +14,13 @@ namespace UniVgo2 public static class ListExtensions { /// - /// Searches for the specified object and returns the zero-based index of the first occurrence within the entire List. + /// Searches for the specified object and returns the zero-based index of the first occurrence within the entire List<T>. /// /// /// - /// The object to locate in the List. The value can be null for reference types. - /// The zero-based index of the first occurrence of item within the entire List, if found; otherwise, -1. - public static int IndexOf(this IReadOnlyList self, T item) + /// The object to locate in the List<T>. The value can be null for reference types. + /// The zero-based index of the first occurrence of item within the entire List<T>, if found; otherwise, -1. + public static int IndexOf(this IReadOnlyList self, in T item) { if (item == null) { @@ -39,13 +39,13 @@ public static int IndexOf(this IReadOnlyList self, T item) } /// - /// Searches for the specified object and returns the zero-based index of the first occurrence within the entire List. + /// Searches for the specified object and returns the zero-based index of the first occurrence within the entire List<T>. /// /// /// /// - /// The zero-based index of the first occurrence of item within the entire List, if found; otherwise, -1. - public static int IndexOf(this IReadOnlyList self, Func predicate) + /// The zero-based index of the first occurrence of item within the entire List<T>, if found; otherwise, -1. + public static int IndexOf(this IReadOnlyList self, in Func predicate) { for (int index = 0; index < self.Count; index++) { @@ -59,13 +59,13 @@ public static int IndexOf(this IReadOnlyList self, Func predicate } /// - /// Searches for the specified object and returns the zero-based index of the first occurrence within the entire List. + /// Searches for the specified object and returns the zero-based index of the first occurrence within the entire List<T>. /// /// /// /// - /// The zero-based index of the first occurrence of item within the entire List, if found; otherwise, -1. - public static int IndexOf(this IList self, Func predicate) + /// The zero-based index of the first occurrence of item within the entire List<T>, if found; otherwise, -1. + public static int IndexOf(this IList self, in Func predicate) { for (int index = 0; index < self.Count; index++) { diff --git a/UniVgo2/Runtime/Extensions/UnityColorExtensions.cs b/UniVgo2/Runtime/Extensions/UnityColorExtensions.cs index 8c3e9ac..6cb15d9 100644 --- a/UniVgo2/Runtime/Extensions/UnityColorExtensions.cs +++ b/UniVgo2/Runtime/Extensions/UnityColorExtensions.cs @@ -12,6 +12,11 @@ public static class UnityColorExtensions { #region UnityEngine -> NewtonVgo + /// + /// Convert UnityEngine.Color to NewtonVgo.Color3. + /// + /// + /// public static NewtonVgo.Color3 ToVgoColor3(this UnityEngine.Color unityColor) { return new NewtonVgo.Color3( @@ -21,6 +26,11 @@ public static NewtonVgo.Color3 ToVgoColor3(this UnityEngine.Color unityColor) ); } + /// + /// Convert UnityEngine.Color to NewtonVgo.Color4. + /// + /// + /// public static NewtonVgo.Color4 ToVgoColor4(this UnityEngine.Color unityColor) { return new NewtonVgo.Color4( @@ -35,7 +45,13 @@ public static NewtonVgo.Color4 ToVgoColor4(this UnityEngine.Color unityColor) #region NewtonVgo -> UnityEngine - public static UnityEngine.Color ToUnityColor(this NewtonVgo.Color3 vgoColor, float alpha = 1.0f) + /// + /// Convert NewtonVgo.Color3 to UnityEngine.Color. + /// + /// + /// + /// + public static UnityEngine.Color ToUnityColor(this NewtonVgo.Color3 vgoColor, in float alpha = 1.0f) { return new UnityEngine.Color( vgoColor.R, @@ -45,6 +61,11 @@ public static UnityEngine.Color ToUnityColor(this NewtonVgo.Color3 vgoColor, flo ); } + /// + /// Convert NewtonVgo.Color4 to UnityEngine.Color. + /// + /// + /// public static UnityEngine.Color ToUnityColor(this NewtonVgo.Color4 vgoColor) { return new UnityEngine.Color( diff --git a/UniVgo2/Runtime/Extensions/UnityExtensions.cs b/UniVgo2/Runtime/Extensions/UnityExtensions.cs index d0caaaf..3f1c675 100644 --- a/UniVgo2/Runtime/Extensions/UnityExtensions.cs +++ b/UniVgo2/Runtime/Extensions/UnityExtensions.cs @@ -12,75 +12,140 @@ namespace UniVgo2 /// public static class UnityExtensions { - public static float[] ToArray3(this UnityEngine.Color c) + /// + /// Convert Color to float[3]. + /// + /// + /// + public static float[] ToArray3(this in UnityEngine.Color c) { return new float[3] { c.r, c.g, c.b }; } - public static float[] ToArray4(this UnityEngine.Color c) + /// + /// Convert Color to float[4]. + /// + /// + /// + public static float[] ToArray4(this in UnityEngine.Color c) { return new float[4] { c.r, c.g, c.b, c.a }; } - public static float[] ToArray(this Quaternion q) + /// + /// Convert Quaternion to float[4]. + /// + /// + /// + public static float[] ToArray(this in Quaternion q) { return new float[] { q.x, q.y, q.z, q.w }; } - public static float[] ToArray(this Vector2 v) + /// + /// Convert Vector2 to float[2]. + /// + /// + /// + public static float[] ToArray(this in Vector2 v) { return new float[] { v.x, v.y }; } - public static float[] ToArray(this Vector3 v) + /// + /// Convert Vector3 to float[3]. + /// + /// + /// + public static float[] ToArray(this in Vector3 v) { return new float[] { v.x, v.y, v.z }; } - public static float[] ToArray(this Vector4 v) + /// + /// Convert Vector4 to float[4]. + /// + /// + /// + public static float[] ToArray(this in Vector4 v) { return new float[] { v.x, v.y, v.z, v.w }; } - public static float[] ToArray2(this Vector4 v) + /// + /// Convert Vector4 to float[2]. + /// + /// + /// + public static float[] ToArray2(this in Vector4 v) { return new float[] { v.x, v.y }; } - public static float[] ToArray3(this Vector4 v) + /// + /// Convert Vector4 to float[3]. + /// + /// + /// + public static float[] ToArray3(this in Vector4 v) { return new float[] { v.x, v.y, v.z }; } - public static Vector2 ReverseUV(this Vector2 v) + /// + /// + /// + /// + /// + public static Vector2 ReverseUV(this in Vector2 v) { return new Vector2(v.x, 1.0f - v.y); } - public static Vector3 ReverseZ(this Vector3 v) + /// + /// + /// + /// + /// + public static Vector3 ReverseZ(this in Vector3 v) { return new Vector3(v.x, v.y, -v.z); } - public static Vector4 ReverseZ(this Vector4 v) + /// + /// + /// + /// + /// + public static Vector4 ReverseZ(this in Vector4 v) { return new Vector4(v.x, v.y, -v.z, v.w); } - public static Quaternion ReverseZ(this Quaternion q) + /// + /// + /// + /// + /// + public static Quaternion ReverseZ(this in Quaternion q) { - float angle; - Vector3 axis; - q.ToAngleAxis(out angle, out axis); + q.ToAngleAxis(out float angle, out Vector3 axis); + return Quaternion.AngleAxis(-angle, ReverseZ(axis)); } - public static Matrix4x4 ReverseZ(this Matrix4x4 m) + /// + /// + /// + /// + /// + public static Matrix4x4 ReverseZ(this in Matrix4x4 m) { m.SetTRS( m.ExtractTransration().ReverseZ(), m.ExtractRotation().ReverseZ(), m.ExtractScale()); + return m; } @@ -89,12 +154,14 @@ public static Matrix4x4 ReverseZ(this Matrix4x4 m) /// /// /// transration - public static Vector3 ExtractTransration(this Matrix4x4 matrix) + public static Vector3 ExtractTransration(this in Matrix4x4 matrix) { Vector3 transration; + transration.x = matrix.m03; transration.y = matrix.m13; transration.z = matrix.m23; + return transration; } @@ -106,14 +173,16 @@ public static Vector3 ExtractTransration(this Matrix4x4 matrix) /// /// https://forum.unity.com/threads/how-to-assign-matrix4x4-to-transform.121966/ /// - public static Quaternion ExtractRotation(this Matrix4x4 matrix) + public static Quaternion ExtractRotation(this in Matrix4x4 matrix) { Vector3 forward; + forward.x = matrix.m02; forward.y = matrix.m12; forward.z = matrix.m22; Vector3 upwards; + upwards.x = matrix.m01; upwards.y = matrix.m11; upwards.z = matrix.m21; @@ -126,12 +195,14 @@ public static Quaternion ExtractRotation(this Matrix4x4 matrix) /// /// /// scale - public static Vector3 ExtractScale(this Matrix4x4 matrix) + public static Vector3 ExtractScale(this in Matrix4x4 matrix) { Vector3 scale; + scale.x = new Vector4(matrix.m00, matrix.m10, matrix.m20, matrix.m30).magnitude; scale.y = new Vector4(matrix.m01, matrix.m11, matrix.m21, matrix.m31).magnitude; scale.z = new Vector4(matrix.m02, matrix.m12, matrix.m22, matrix.m32).magnitude; + return scale; } } diff --git a/UniVgo2/Runtime/Extensions/UnityGameObjectExtensions.cs b/UniVgo2/Runtime/Extensions/UnityGameObjectExtensions.cs index 4249a62..23090b9 100644 --- a/UniVgo2/Runtime/Extensions/UnityGameObjectExtensions.cs +++ b/UniVgo2/Runtime/Extensions/UnityGameObjectExtensions.cs @@ -23,7 +23,7 @@ public static class UnityGameObjectExtensions /// The type of the component to retrieve. /// The output argument that will contain the component or null. /// Returns true if the component is found, false otherwise. - public static bool TryGetComponentEx(this GameObject go, Type type, out Component component) + public static bool TryGetComponentEx(this GameObject go, in Type type, out Component component) { #if UNITY_2019_2_OR_NEWER return go.TryGetComponent(type, out component); diff --git a/UniVgo2/Runtime/Extensions/UnityMaterialExtensions.cs b/UniVgo2/Runtime/Extensions/UnityMaterialExtensions.cs index d2ee900..7174045 100644 --- a/UniVgo2/Runtime/Extensions/UnityMaterialExtensions.cs +++ b/UniVgo2/Runtime/Extensions/UnityMaterialExtensions.cs @@ -21,7 +21,7 @@ public static class UnityMaterialExtensions /// A material. /// A material property name ID. /// - public static bool GetSafeBool(this Material material, int propertyNameId) + public static bool GetSafeBool(this Material material, in int propertyNameId) { #if UNITY_2021_2_OR_NEWER if (material.HasInt(propertyNameId)) @@ -54,7 +54,7 @@ public static bool GetSafeBool(this Material material, int propertyNameId) /// A material. /// A material property name. /// - public static bool GetSafeBool(this Material material, string propertyName) + public static bool GetSafeBool(this Material material, in string propertyName) { #if UNITY_2021_2_OR_NEWER if (material.HasInt(propertyName)) @@ -87,7 +87,7 @@ public static bool GetSafeBool(this Material material, string propertyName) /// A material. /// A material property name ID. /// - public static Color GetSafeColor(this Material material, int propertyNameId) + public static Color GetSafeColor(this Material material, in int propertyNameId) { #if UNITY_2021_2_OR_NEWER if (material.HasColor(propertyNameId)) @@ -118,9 +118,9 @@ public static Color GetSafeColor(this Material material, int propertyNameId) /// Gets color value. /// /// A material. - /// A material property name. + /// A material property name. /// - public static Color GetSafeColor(this Material material, string propertyName) + public static Color GetSafeColor(this Material material, in string propertyName) { #if UNITY_2021_2_OR_NEWER if (material.HasColor(propertyName)) @@ -155,7 +155,7 @@ public static Color GetSafeColor(this Material material, string propertyName) /// A material property name ID. /// /// - public static TEnum GetSafeEnum(this Material material, int propertyNameId, TEnum? defaultValue = null) where TEnum : struct + public static TEnum GetSafeEnum(this Material material, in int propertyNameId, in TEnum? defaultValue = null) where TEnum : struct { int propertyValue = material.GetSafeInt(propertyNameId); @@ -181,7 +181,7 @@ public static TEnum GetSafeEnum(this Material material, int propertyNameI /// A material property name. /// /// - public static TEnum GetSafeEnum(this Material material, string propertyName, TEnum? defaultValue = null) where TEnum : struct + public static TEnum GetSafeEnum(this Material material, in string propertyName, in TEnum? defaultValue = null) where TEnum : struct { int propertyValue = material.GetSafeInt(propertyName); @@ -205,7 +205,7 @@ public static TEnum GetSafeEnum(this Material material, string propertyNa /// A material. /// A material property name ID. /// - public static float GetSafeFloat(this Material material, int propertyNameId) + public static float GetSafeFloat(this Material material, in int propertyNameId) { #if UNITY_2021_2_OR_NEWER if (material.HasFloat(propertyNameId)) @@ -238,7 +238,7 @@ public static float GetSafeFloat(this Material material, int propertyNameId) /// A material. /// A material property name. /// - public static float GetSafeFloat(this Material material, string propertyName) + public static float GetSafeFloat(this Material material, in string propertyName) { #if UNITY_2021_2_OR_NEWER if (material.HasFloat(propertyName)) @@ -271,7 +271,7 @@ public static float GetSafeFloat(this Material material, string propertyName) /// A material. /// A material property name ID. /// - public static int GetSafeInt(this Material material, int propertyNameId) + public static int GetSafeInt(this Material material, in int propertyNameId) { //return material.GetSafeInteger(propertyNameId); @@ -306,7 +306,7 @@ public static int GetSafeInt(this Material material, int propertyNameId) /// A material. /// A material property name. /// - public static int GetSafeInt(this Material material, string propertyName) + public static int GetSafeInt(this Material material, in string propertyName) { //return material.GetSafeInteger(propertyName); @@ -341,7 +341,7 @@ public static int GetSafeInt(this Material material, string propertyName) /// A material. /// A material property name ID. /// - public static int GetSafeInteger(this Material material, int propertyNameId) + public static int GetSafeInteger(this Material material, in int propertyNameId) { #if UNITY_2021_2_OR_NEWER if (material.HasInteger(propertyNameId)) @@ -371,7 +371,7 @@ public static int GetSafeInteger(this Material material, int propertyNameId) /// A material. /// A material property name. /// - public static int GetSafeInteger(this Material material, string propertyName) + public static int GetSafeInteger(this Material material, in string propertyName) { #if UNITY_2021_2_OR_NEWER if (material.HasInteger(propertyName)) @@ -401,7 +401,7 @@ public static int GetSafeInteger(this Material material, string propertyName) /// A material. /// A material property name ID. /// - public static Texture2D? GetSafeTexture(this Material material, int propertyNameId) + public static Texture2D? GetSafeTexture(this Material material, in int propertyNameId) { #if UNITY_2021_2_OR_NEWER if (material.HasTexture(propertyNameId)) @@ -441,7 +441,7 @@ public static int GetSafeInteger(this Material material, string propertyName) /// A material. /// A material property name. /// - public static Texture2D? GetSafeTexture(this Material material, string propertyName) + public static Texture2D? GetSafeTexture(this Material material, in string propertyName) { #if UNITY_2021_2_OR_NEWER if (material.HasTexture(propertyName)) @@ -481,7 +481,7 @@ public static int GetSafeInteger(this Material material, string propertyName) /// A material. /// A material property name ID. /// - public static Vector3 GetSafeVector3(this Material material, int propertyNameId) + public static Vector3 GetSafeVector3(this Material material, in int propertyNameId) { return material.GetSafeVector4(propertyNameId); } @@ -492,7 +492,7 @@ public static Vector3 GetSafeVector3(this Material material, int propertyNameId) /// A material. /// A material property name. /// - public static Vector3 GetSafeVector3(this Material material, string propertyName) + public static Vector3 GetSafeVector3(this Material material, in string propertyName) { return material.GetSafeVector4(propertyName); } @@ -503,7 +503,7 @@ public static Vector3 GetSafeVector3(this Material material, string propertyName /// A material. /// A material property name ID. /// - public static Vector4 GetSafeVector4(this Material material, int propertyNameId) + public static Vector4 GetSafeVector4(this Material material, in int propertyNameId) { #if UNITY_2021_2_OR_NEWER if (material.HasVector(propertyNameId)) @@ -536,7 +536,7 @@ public static Vector4 GetSafeVector4(this Material material, int propertyNameId) /// A material. /// A material property name. /// - public static Vector4 GetSafeVector4(this Material material, string propertyName) + public static Vector4 GetSafeVector4(this Material material, in string propertyName) { #if UNITY_2021_2_OR_NEWER if (material.HasVector(propertyName)) @@ -574,7 +574,7 @@ public static Vector4 GetSafeVector4(this Material material, string propertyName /// A material property name ID. /// /// Whether it could be set. - public static bool SetSafeBool(this Material material, int propertyNameId, bool value) + public static bool SetSafeBool(this Material material, in int propertyNameId, bool value) { if (material.HasProperty(propertyNameId)) { @@ -597,7 +597,7 @@ public static bool SetSafeBool(this Material material, int propertyNameId, bool /// A material property name. /// /// Whether it could be set. - public static bool SetSafeBool(this Material material, string propertyName, bool value) + public static bool SetSafeBool(this Material material, in string propertyName, bool value) { if (material.HasProperty(propertyName)) { @@ -622,7 +622,7 @@ public static bool SetSafeBool(this Material material, string propertyName, bool /// /// /// Whether it could be set. - public static bool SetSafeInt(this Material material, int propertyNameId, int value, int? minValue = null, int? maxValue = null) + public static bool SetSafeInt(this Material material, in int propertyNameId, int value, int? minValue = null, int? maxValue = null) { //return material.SetSafeInteger(propertyName, value, minValue, maxValue); @@ -660,7 +660,7 @@ public static bool SetSafeInt(this Material material, int propertyNameId, int va /// /// /// Whether it could be set. - public static bool SetSafeInt(this Material material, string propertyName, int value, int? minValue = null, int? maxValue = null) + public static bool SetSafeInt(this Material material, in string propertyName, int value, int? minValue = null, int? maxValue = null) { //return material.SetSafeInteger(propertyName, value, minValue, maxValue); @@ -698,7 +698,7 @@ public static bool SetSafeInt(this Material material, string propertyName, int v /// /// /// Whether it could be set. - public static bool SetSafeInteger(this Material material, int propertyNameId, int value, int? minValue = null, int? maxValue = null) + public static bool SetSafeInteger(this Material material, in int propertyNameId, int value, int? minValue = null, int? maxValue = null) { if (material.HasProperty(propertyNameId)) { @@ -737,7 +737,7 @@ public static bool SetSafeInteger(this Material material, int propertyNameId, in /// /// /// Whether it could be set. - public static bool SetSafeInteger(this Material material, string propertyName, int value, int? minValue = null, int? maxValue = null) + public static bool SetSafeInteger(this Material material, in string propertyName, int value, int? minValue = null, int? maxValue = null) { if (material.HasProperty(propertyName)) { @@ -776,7 +776,7 @@ public static bool SetSafeInteger(this Material material, string propertyName, i /// /// /// Whether it could be set. - public static bool SetSafeFloat(this Material material, int propertyNameId, float value, float? minValue = null, float? maxValue = null) + public static bool SetSafeFloat(this Material material, in int propertyNameId, float value, float? minValue = null, float? maxValue = null) { if (material.HasProperty(propertyNameId)) { @@ -813,7 +813,7 @@ public static bool SetSafeFloat(this Material material, int propertyNameId, floa /// /// /// Whether it could be set. - public static bool SetSafeFloat(this Material material, int propertyNameId, float value, float? minValue = null, float? maxValue = null, float defaultValue = default) + public static bool SetSafeFloat(this Material material, in int propertyNameId, float value, float? minValue = null, float? maxValue = null, float defaultValue = default) { if (material.HasProperty(propertyNameId)) { @@ -850,7 +850,7 @@ public static bool SetSafeFloat(this Material material, int propertyNameId, floa /// /// /// Whether it could be set. - public static bool SetSafeFloat(this Material material, string propertyName, float value, float? minValue = null, float? maxValue = null, float defaultValue = default) + public static bool SetSafeFloat(this Material material, in string propertyName, float value, float? minValue = null, float? maxValue = null, float defaultValue = default) { if (material.HasProperty(propertyName)) { @@ -886,7 +886,7 @@ public static bool SetSafeFloat(this Material material, string propertyName, flo /// /// /// Whether it could be set. - public static bool SetSafeFloat(this Material material, string propertyName, float value, float? minValue = null, float? maxValue = null) + public static bool SetSafeFloat(this Material material, in string propertyName, float value, float? minValue = null, float? maxValue = null) { if (material.HasProperty(propertyName)) { @@ -920,7 +920,7 @@ public static bool SetSafeFloat(this Material material, string propertyName, flo /// A material property name ID. /// /// Whether it could be set. - public static bool SetSafeColor(this Material material, int propertyNameId, Color color) + public static bool SetSafeColor(this Material material, in int propertyNameId, Color color) { if (material.HasProperty(propertyNameId)) { @@ -943,7 +943,7 @@ public static bool SetSafeColor(this Material material, int propertyNameId, Colo /// A material property name. /// /// Whether it could be set. - public static bool SetSafeColor(this Material material, string propertyName, Color color) + public static bool SetSafeColor(this Material material, in string propertyName, Color color) { if (material.HasProperty(propertyName)) { @@ -966,7 +966,7 @@ public static bool SetSafeColor(this Material material, string propertyName, Col /// A material property name ID. /// /// Whether it could be set. - public static bool SetSafeTexture(this Material material, int propertyNameId, Texture2D texture) + public static bool SetSafeTexture(this Material material, in int propertyNameId, Texture2D texture) { if (material.HasProperty(propertyNameId)) { @@ -989,7 +989,7 @@ public static bool SetSafeTexture(this Material material, int propertyNameId, Te /// A material property name. /// /// Whether it could be set. - public static bool SetSafeTexture(this Material material, string propertyName, Texture2D texture) + public static bool SetSafeTexture(this Material material, in string propertyName, Texture2D texture) { if (material.HasProperty(propertyName)) { @@ -1012,7 +1012,7 @@ public static bool SetSafeTexture(this Material material, string propertyName, T /// A material property name ID. /// /// Whether it could be set. - public static bool SetSafeVector(this Material material, int propertyNameId, Vector4 vector) + public static bool SetSafeVector(this Material material, in int propertyNameId, Vector4 vector) { if (material.HasProperty(propertyNameId)) { @@ -1035,7 +1035,7 @@ public static bool SetSafeVector(this Material material, int propertyNameId, Vec /// A material property name. /// /// Whether it could be set. - public static bool SetSafeVector(this Material material, string propertyName, Vector4 vector) + public static bool SetSafeVector(this Material material, in string propertyName, Vector4 vector) { if (material.HasProperty(propertyName)) { @@ -1057,7 +1057,7 @@ public static bool SetSafeVector(this Material material, string propertyName, Ve /// A material. /// A material keyword. /// - public static void SetKeyword(this Material material, string keyword, bool enable) + public static void SetKeyword(this Material material, in string keyword, in bool enable) { if (enable) { diff --git a/UniVgo2/Runtime/Extensions/UnityNumericsExtensions.cs b/UniVgo2/Runtime/Extensions/UnityNumericsExtensions.cs index d10cd23..b00f2b6 100644 --- a/UniVgo2/Runtime/Extensions/UnityNumericsExtensions.cs +++ b/UniVgo2/Runtime/Extensions/UnityNumericsExtensions.cs @@ -12,7 +12,12 @@ public static class UnityNumericsExtensions { #region UnityEngine -> System.Numerics - public static System.Numerics.Vector2 ToNumericsVector2(this UnityEngine.Vector2 unityVector) + /// + /// Convert UnityEngine.Vector2 to System.Numerics.Vector2. + /// + /// + /// + public static System.Numerics.Vector2 ToNumericsVector2(this in UnityEngine.Vector2 unityVector) { return new System.Numerics.Vector2( unityVector.x, @@ -20,7 +25,12 @@ public static System.Numerics.Vector2 ToNumericsVector2(this UnityEngine.Vector2 ); } - public static System.Numerics.Vector3 ToNumericsVector3(this UnityEngine.Vector3 unityVector) + /// + /// Convert UnityEngine.Vector3 to System.Numerics.Vector3. + /// + /// + /// + public static System.Numerics.Vector3 ToNumericsVector3(this in UnityEngine.Vector3 unityVector) { return new System.Numerics.Vector3( unityVector.x, @@ -29,7 +39,13 @@ public static System.Numerics.Vector3 ToNumericsVector3(this UnityEngine.Vector3 ); } - public static System.Numerics.Vector3 ToNumericsVector3(this UnityEngine.Vector3 unityVector, NewtonVgo.VgoGeometryCoordinate geometryCoordinate) + /// + /// Convert UnityEngine.Vector3 to System.Numerics.Vector3. + /// + /// + /// + /// + public static System.Numerics.Vector3 ToNumericsVector3(this in UnityEngine.Vector3 unityVector, in NewtonVgo.VgoGeometryCoordinate geometryCoordinate) { if (geometryCoordinate == NewtonVgo.VgoGeometryCoordinate.RightHanded) { @@ -41,12 +57,23 @@ public static System.Numerics.Vector3 ToNumericsVector3(this UnityEngine.Vector3 } } - public static System.Numerics.Vector4 ToNumericsVector4(this UnityEngine.Vector4 unityVector) + /// + /// Convert UnityEngine.Vector4 to System.Numerics.Vector4. + /// + /// + /// + public static System.Numerics.Vector4 ToNumericsVector4(this in UnityEngine.Vector4 unityVector) { return new System.Numerics.Vector4(unityVector.x, unityVector.y, unityVector.z, unityVector.w); } - public static System.Numerics.Vector4 ToNumericsVector4(this UnityEngine.Vector4 unityVector, NewtonVgo.VgoGeometryCoordinate geometryCoordinate) + /// + /// Convert UnityEngine.Vector4 to System.Numerics.Vector4. + /// + /// + /// + /// + public static System.Numerics.Vector4 ToNumericsVector4(this in UnityEngine.Vector4 unityVector, in NewtonVgo.VgoGeometryCoordinate geometryCoordinate) { if (geometryCoordinate == NewtonVgo.VgoGeometryCoordinate.RightHanded) { @@ -58,7 +85,12 @@ public static System.Numerics.Vector4 ToNumericsVector4(this UnityEngine.Vector4 } } - public static System.Numerics.Quaternion ToNumericsQuaternion(this UnityEngine.Quaternion unityQuaternion) + /// + /// Convert UnityEngine.Quaternion to System.Numerics.Quaternion. + /// + /// + /// + public static System.Numerics.Quaternion ToNumericsQuaternion(this in UnityEngine.Quaternion unityQuaternion) { return new System.Numerics.Quaternion( unityQuaternion.x, @@ -68,7 +100,13 @@ public static System.Numerics.Quaternion ToNumericsQuaternion(this UnityEngine.Q ); } - public static System.Numerics.Quaternion ToNumericsQuaternion(this UnityEngine.Quaternion unityQuaternion, NewtonVgo.VgoGeometryCoordinate geometryCoordinate) + /// + /// Convert UnityEngine.Quaternion to System.Numerics.Quaternion. + /// + /// + /// + /// + public static System.Numerics.Quaternion ToNumericsQuaternion(this in UnityEngine.Quaternion unityQuaternion, in NewtonVgo.VgoGeometryCoordinate geometryCoordinate) { if (geometryCoordinate == NewtonVgo.VgoGeometryCoordinate.RightHanded) { @@ -80,7 +118,12 @@ public static System.Numerics.Quaternion ToNumericsQuaternion(this UnityEngine.Q } } - public static System.Numerics.Matrix4x4 ToNumericsMatrix(this UnityEngine.Matrix4x4 unityMatrix) + /// + /// Convert UnityEngine.Matrix4x4 to System.Numerics.Matrix4x4. + /// + /// + /// + public static System.Numerics.Matrix4x4 ToNumericsMatrix(this in UnityEngine.Matrix4x4 unityMatrix) { return new System.Numerics.Matrix4x4() { @@ -103,7 +146,13 @@ public static System.Numerics.Matrix4x4 ToNumericsMatrix(this UnityEngine.Matrix }; } - public static System.Numerics.Vector3? ToNullableNumericsVector3(this UnityEngine.Vector3 unityVector, UnityEngine.Vector3 defaultValue) + /// + /// Convert UnityEngine.Vector3 to System.Numerics.Vector3. + /// + /// + /// + /// + public static System.Numerics.Vector3? ToNullableNumericsVector3(this in UnityEngine.Vector3 unityVector, in UnityEngine.Vector3 defaultValue) { if (unityVector == defaultValue) { @@ -115,7 +164,14 @@ public static System.Numerics.Matrix4x4 ToNumericsMatrix(this UnityEngine.Matrix } } - public static System.Numerics.Vector3? ToNullableNumericsVector3(this UnityEngine.Vector3 unityVector, UnityEngine.Vector3 defaultValue, NewtonVgo.VgoGeometryCoordinate geometryCoordinate) + /// + /// Convert UnityEngine.Vector3 to System.Numerics.Vector3. + /// + /// + /// + /// + /// + public static System.Numerics.Vector3? ToNullableNumericsVector3(this in UnityEngine.Vector3 unityVector, in UnityEngine.Vector3 defaultValue, in NewtonVgo.VgoGeometryCoordinate geometryCoordinate) { if (unityVector == defaultValue) { @@ -127,7 +183,14 @@ public static System.Numerics.Matrix4x4 ToNumericsMatrix(this UnityEngine.Matrix } } - public static System.Numerics.Quaternion? ToNullableNumericsQuaternion(this UnityEngine.Quaternion unityQuaternion, UnityEngine.Quaternion defaultValue, NewtonVgo.VgoGeometryCoordinate geometryCoordinate) + /// + /// Convert UnityEngine.Quaternion to System.Numerics.Quaternion. + /// + /// + /// + /// + /// + public static System.Numerics.Quaternion? ToNullableNumericsQuaternion(this in UnityEngine.Quaternion unityQuaternion, in UnityEngine.Quaternion defaultValue, in NewtonVgo.VgoGeometryCoordinate geometryCoordinate) { if (unityQuaternion == defaultValue) { @@ -143,7 +206,12 @@ public static System.Numerics.Matrix4x4 ToNumericsMatrix(this UnityEngine.Matrix #region System.Numerics -> UnityEngine - public static UnityEngine.Vector2 ToUnityVector2(this System.Numerics.Vector2 numericsVector) + /// + /// Convert System.Numerics.Vector2 to UnityEngine.Vector2. + /// + /// + /// + public static UnityEngine.Vector2 ToUnityVector2(this in System.Numerics.Vector2 numericsVector) { return new UnityEngine.Vector2( numericsVector.X, @@ -151,7 +219,12 @@ public static UnityEngine.Vector2 ToUnityVector2(this System.Numerics.Vector2 nu ); } - public static UnityEngine.Vector3 ToUnityVector3(this System.Numerics.Vector3 numericsVector) + /// + /// Convert System.Numerics.Vector3 to UnityEngine.Vector3. + /// + /// + /// + public static UnityEngine.Vector3 ToUnityVector3(this in System.Numerics.Vector3 numericsVector) { return new UnityEngine.Vector3( numericsVector.X, @@ -160,7 +233,13 @@ public static UnityEngine.Vector3 ToUnityVector3(this System.Numerics.Vector3 nu ); } - public static UnityEngine.Vector3 ToUnityVector3(this System.Numerics.Vector3 numericsVector, NewtonVgo.VgoGeometryCoordinate geometryCoordinate) + /// + /// Convert System.Numerics.Vector3 to UnityEngine.Vector3. + /// + /// + /// + /// + public static UnityEngine.Vector3 ToUnityVector3(this in System.Numerics.Vector3 numericsVector, in NewtonVgo.VgoGeometryCoordinate geometryCoordinate) { if (geometryCoordinate == NewtonVgo.VgoGeometryCoordinate.RightHanded) { @@ -172,7 +251,13 @@ public static UnityEngine.Vector3 ToUnityVector3(this System.Numerics.Vector3 nu } } - public static UnityEngine.Vector3 ToUnityVector3(this System.Numerics.Vector3? numericsVector, UnityEngine.Vector3 defaultValue) + /// + /// Convert System.Numerics.Vector3 to UnityEngine.Vector3. + /// + /// + /// + /// + public static UnityEngine.Vector3 ToUnityVector3(this in System.Numerics.Vector3? numericsVector, in UnityEngine.Vector3 defaultValue) { if (numericsVector.HasValue) { @@ -184,7 +269,14 @@ public static UnityEngine.Vector3 ToUnityVector3(this System.Numerics.Vector3? n } } - public static UnityEngine.Vector3 ToUnityVector3(this System.Numerics.Vector3? numericsVector, UnityEngine.Vector3 defaultValue, NewtonVgo.VgoGeometryCoordinate geometryCoordinate) + /// + /// Convert System.Numerics.Vector3 to UnityEngine.Vector3. + /// + /// + /// + /// + /// + public static UnityEngine.Vector3 ToUnityVector3(this in System.Numerics.Vector3? numericsVector, in UnityEngine.Vector3 defaultValue, in NewtonVgo.VgoGeometryCoordinate geometryCoordinate) { if (numericsVector.HasValue) { @@ -196,7 +288,12 @@ public static UnityEngine.Vector3 ToUnityVector3(this System.Numerics.Vector3? n } } - public static UnityEngine.Vector4 ToUnityVector4(this System.Numerics.Vector4 numericsVector) + /// + /// Convert System.Numerics.Vector4 to UnityEngine.Vector4. + /// + /// + /// + public static UnityEngine.Vector4 ToUnityVector4(this in System.Numerics.Vector4 numericsVector) { return new UnityEngine.Vector4( numericsVector.X, @@ -206,7 +303,13 @@ public static UnityEngine.Vector4 ToUnityVector4(this System.Numerics.Vector4 nu ); } - public static UnityEngine.Vector4 ToUnityVector4(this System.Numerics.Vector4 numericsVector, NewtonVgo.VgoGeometryCoordinate geometryCoordinate) + /// + /// Convert System.Numerics.Vector4 to UnityEngine.Vector4. + /// + /// + /// + /// + public static UnityEngine.Vector4 ToUnityVector4(this in System.Numerics.Vector4 numericsVector, in NewtonVgo.VgoGeometryCoordinate geometryCoordinate) { if (geometryCoordinate == NewtonVgo.VgoGeometryCoordinate.RightHanded) { @@ -218,7 +321,12 @@ public static UnityEngine.Vector4 ToUnityVector4(this System.Numerics.Vector4 nu } } - public static UnityEngine.Quaternion ToUnityQuaternion(this System.Numerics.Quaternion numericsQuaternion) + /// + /// Convert System.Numerics.Quaternion to UnityEngine.Quaternion. + /// + /// + /// + public static UnityEngine.Quaternion ToUnityQuaternion(this in System.Numerics.Quaternion numericsQuaternion) { return new UnityEngine.Quaternion( numericsQuaternion.X, @@ -228,7 +336,13 @@ public static UnityEngine.Quaternion ToUnityQuaternion(this System.Numerics.Quat ); } - public static UnityEngine.Quaternion ToUnityQuaternion(this System.Numerics.Quaternion numericsQuaternion, NewtonVgo.VgoGeometryCoordinate geometryCoordinate) + /// + /// Convert System.Numerics.Quaternion to UnityEngine.Quaternion. + /// + /// + /// + /// + public static UnityEngine.Quaternion ToUnityQuaternion(this in System.Numerics.Quaternion numericsQuaternion, in NewtonVgo.VgoGeometryCoordinate geometryCoordinate) { if (geometryCoordinate == NewtonVgo.VgoGeometryCoordinate.RightHanded) { @@ -240,7 +354,14 @@ public static UnityEngine.Quaternion ToUnityQuaternion(this System.Numerics.Quat } } - public static UnityEngine.Quaternion ToUnityQuaternion(this System.Numerics.Quaternion? numericsQuaternion, UnityEngine.Quaternion defaultValue, NewtonVgo.VgoGeometryCoordinate geometryCoordinate) + /// + /// Convert System.Numerics.Quaternion to UnityEngine.Quaternion. + /// + /// + /// + /// + /// + public static UnityEngine.Quaternion ToUnityQuaternion(this in System.Numerics.Quaternion? numericsQuaternion, in UnityEngine.Quaternion defaultValue, in NewtonVgo.VgoGeometryCoordinate geometryCoordinate) { if (numericsQuaternion.HasValue) { @@ -252,7 +373,12 @@ public static UnityEngine.Quaternion ToUnityQuaternion(this System.Numerics.Quat } } - public static UnityEngine.Matrix4x4 ToUnityMatrix(this System.Numerics.Matrix4x4 numericsMatrix) + /// + /// Convert System.Numerics.Matrix4x4 to UnityEngine.Matrix4x4. + /// + /// + /// + public static UnityEngine.Matrix4x4 ToUnityMatrix(this in System.Numerics.Matrix4x4 numericsMatrix) { return new UnityEngine.Matrix4x4() { diff --git a/UniVgo2/Runtime/Extensions/VgoMaterialExtensions.cs b/UniVgo2/Runtime/Extensions/VgoMaterialExtensions.cs index a17aa7f..357b41a 100644 --- a/UniVgo2/Runtime/Extensions/VgoMaterialExtensions.cs +++ b/UniVgo2/Runtime/Extensions/VgoMaterialExtensions.cs @@ -23,7 +23,7 @@ public static class VgoMaterialExtensions /// A material property name. /// /// - public static TEnum GetEnumOrDefault(this VgoMaterial self, string propertyName, TEnum? defaultValue = null) where TEnum : struct + public static TEnum GetEnumOrDefault(this VgoMaterial self, in string propertyName, TEnum? defaultValue = null) where TEnum : struct { int? propertyValue = null; @@ -77,7 +77,7 @@ public static TEnum GetEnumOrDefault(this VgoMaterial self, string proper /// /// /// - public static int GetIntOrDefault(this VgoMaterial self, string propertyName, int defaultValue = 0) + public static int GetIntOrDefault(this VgoMaterial self, in string propertyName, int defaultValue = 0) { if (self.intProperties == null) { @@ -99,7 +99,7 @@ public static int GetIntOrDefault(this VgoMaterial self, string propertyName, in /// /// /// - public static float GetFloatOrDefault(this VgoMaterial self, string propertyName, float defaultValue = 0.0f) + public static float GetFloatOrDefault(this VgoMaterial self, in string propertyName, float defaultValue = 0.0f) { if (self.floatProperties == null) { @@ -117,12 +117,13 @@ public static float GetFloatOrDefault(this VgoMaterial self, string propertyName /// /// /// + /// /// /// /// /// /// - public static int GetSafeInt(this VgoMaterial self, string propertyName, int min, int max, int defaultValue = 0) + public static int GetSafeInt(this VgoMaterial self, in string propertyName, in int min, in int max, int defaultValue = 0) { if (self.intProperties == null) { @@ -152,10 +153,11 @@ public static int GetSafeInt(this VgoMaterial self, string propertyName, int min /// /// /// + /// /// /// /// - public static int GetSafeInt(this VgoMaterial self, string propertyName, IntRangeDefault range) + public static int GetSafeInt(this VgoMaterial self, in string propertyName, in IntRangeDefault range) { return GetSafeInt(self, propertyName, range.minValue, range.maxValue, range.defaultValue); } @@ -169,7 +171,7 @@ public static int GetSafeInt(this VgoMaterial self, string propertyName, IntRang /// /// /// - public static float GetSafeFloat(this VgoMaterial self, string propertyName, float min, float max, float defaultValue = 0.0f) + public static float GetSafeFloat(this VgoMaterial self, in string propertyName, in float min, in float max, float defaultValue = 0.0f) { if (self.floatProperties == null) { @@ -203,7 +205,7 @@ public static float GetSafeFloat(this VgoMaterial self, string propertyName, flo /// /// /// - public static float GetSafeFloat(this VgoMaterial self, string propertyName, FloatRangeDefault range) + public static float GetSafeFloat(this VgoMaterial self, in string propertyName, in FloatRangeDefault range) { return GetSafeFloat(self, propertyName, range.minValue, range.maxValue, range.defaultValue); } @@ -215,7 +217,7 @@ public static float GetSafeFloat(this VgoMaterial self, string propertyName, Flo /// /// /// - public static Color GetColorOrDefault(this VgoMaterial self, string propertyName, Color defaultValue) + public static Color GetColorOrDefault(this VgoMaterial self, in string propertyName, Color defaultValue) { if (self.colorProperties == null) { @@ -254,7 +256,7 @@ public static Color GetColorOrDefault(this VgoMaterial self, string propertyName /// /// /// - public static Vector2 GetVector2OrDefault(this VgoMaterial self, string propertyName, Vector2 defaultValue) + public static Vector2 GetVector2OrDefault(this VgoMaterial self, in string propertyName, Vector2 defaultValue) { if (self.vectorProperties == null) { @@ -288,7 +290,7 @@ public static Vector2 GetVector2OrDefault(this VgoMaterial self, string property /// /// /// - public static Vector3 GetVector3OrDefault(this VgoMaterial self, string propertyName, Vector3 defaultValue) + public static Vector3 GetVector3OrDefault(this VgoMaterial self, in string propertyName, Vector3 defaultValue) { if (self.vectorProperties == null) { @@ -322,7 +324,7 @@ public static Vector3 GetVector3OrDefault(this VgoMaterial self, string property /// /// /// - public static Vector4 GetVector4OrDefault(this VgoMaterial self, string propertyName, Vector4 defaultValue) + public static Vector4 GetVector4OrDefault(this VgoMaterial self, in string propertyName, Vector4 defaultValue) { if (self.vectorProperties == null) { @@ -355,7 +357,7 @@ public static Vector4 GetVector4OrDefault(this VgoMaterial self, string property /// /// /// - public static int GetTextureIndexOrDefault(this VgoMaterial self, string propertyName) + public static int GetTextureIndexOrDefault(this VgoMaterial self, in string propertyName) { if (self.textureIndexProperties == null) { @@ -377,7 +379,7 @@ public static int GetTextureIndexOrDefault(this VgoMaterial self, string propert /// /// /// - public static Vector2 GetTextureOffsetOrDefault(this VgoMaterial self, string propertyName, Vector2 defaultValue = default) + public static Vector2 GetTextureOffsetOrDefault(this VgoMaterial self, in string propertyName, Vector2 defaultValue = default) { Vector2? offsetVector = self.GetTextureOffsetOrNull(propertyName); @@ -395,7 +397,7 @@ public static Vector2 GetTextureOffsetOrDefault(this VgoMaterial self, string pr /// /// /// - public static Vector2? GetTextureOffsetOrNull(this VgoMaterial self, string propertyName) + public static Vector2? GetTextureOffsetOrNull(this VgoMaterial self, in string propertyName) { if (self.textureOffsetProperties == null) { @@ -431,7 +433,7 @@ public static Vector2 GetTextureOffsetOrDefault(this VgoMaterial self, string pr /// /// /// - public static Vector2 GetTextureScaleOrDefault(this VgoMaterial self, string propertyName, Vector2 defaultValue = default) + public static Vector2 GetTextureScaleOrDefault(this VgoMaterial self, in string propertyName, Vector2 defaultValue = default) { Vector2? scaleVector = self.GetTextureScaleOrNull(propertyName); @@ -449,7 +451,7 @@ public static Vector2 GetTextureScaleOrDefault(this VgoMaterial self, string pro /// /// /// - public static Vector2? GetTextureScaleOrNull(this VgoMaterial self, string propertyName) + public static Vector2? GetTextureScaleOrNull(this VgoMaterial self, in string propertyName) { if (self.textureScaleProperties == null) { diff --git a/UniVgo2/Runtime/Models/BlendShapeConfig.cs b/UniVgo2/Runtime/Models/BlendShapeConfig.cs index 6aedaad..c984428 100644 --- a/UniVgo2/Runtime/Models/BlendShapeConfig.cs +++ b/UniVgo2/Runtime/Models/BlendShapeConfig.cs @@ -13,7 +13,7 @@ namespace UniVgo2 /// public class BlendShapeConfig { - /// The name of this info. + /// The name of this configuration. private string? _Name; /// The kind of the BlendShape. diff --git a/UniVgo2/Runtime/Models/ExportModelAsset.cs b/UniVgo2/Runtime/Models/ExportModelAsset.cs index ba367c7..02c84dd 100644 --- a/UniVgo2/Runtime/Models/ExportModelAsset.cs +++ b/UniVgo2/Runtime/Models/ExportModelAsset.cs @@ -362,7 +362,7 @@ protected virtual List GetMeshRendererAssetList(List /// Get list of unity mesh. /// - /// List of export mesh renderer asset. + /// List of export mesh renderer asset. /// List of export mesh asset. protected virtual List GetMeshAssetList(List meshRendererAssetList) { @@ -408,12 +408,12 @@ protected virtual List GetMeshAssetList(List meshAsset.BlendShapeConfig = new BlendShapeConfig { - Name = blendShapeConfiguration.name ?? string.Empty, - Kind = blendShapeConfiguration.kind, - FaceParts = blendShapeConfiguration.faceParts, - Blinks = blendShapeConfiguration.blinks, - Visemes = blendShapeConfiguration.visemes, - Presets = blendShapeConfiguration.presets, + Name = blendShapeConfiguration.Name, + Kind = blendShapeConfiguration.Kind, + FaceParts = blendShapeConfiguration.FaceParts, + Blinks = blendShapeConfiguration.Blinks, + Visemes = blendShapeConfiguration.Visemes, + Presets = blendShapeConfiguration.Presets, }; } } @@ -428,7 +428,7 @@ protected virtual List GetMeshAssetList(List /// /// Get list of unity mesh. /// - /// List of mesh renderer asset. + /// List of mesh renderer asset. /// List of unity mesh. protected virtual List GetMeshList(List meshRendererAssetList) { diff --git a/UniVgo2/Runtime/Porters/Interfaces/IMaterialPorter.cs b/UniVgo2/Runtime/Porters/Interfaces/IMaterialPorter.cs index 747fd9f..6f3abe8 100644 --- a/UniVgo2/Runtime/Porters/Interfaces/IMaterialPorter.cs +++ b/UniVgo2/Runtime/Porters/Interfaces/IMaterialPorter.cs @@ -30,7 +30,7 @@ public interface IMaterialPorter /// A unity material. /// A vgo storage. /// A vgo material. - VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgoStorage); + VgoMaterial CreateVgoMaterial(in Material material, in IVgoStorage vgoStorage); #endregion @@ -43,7 +43,7 @@ public interface IMaterialPorter /// A shader. /// List of all texture 2D. /// A unity material. - Material CreateMaterialAsset(VgoMaterial vgoMaterial, Shader shader, List allTexture2dList); + Material CreateMaterialAsset(in VgoMaterial vgoMaterial, in Shader shader, in List allTexture2dList); #endregion } diff --git a/UniVgo2/Runtime/Porters/Interfaces/IMaterialPorterStore.cs b/UniVgo2/Runtime/Porters/Interfaces/IMaterialPorterStore.cs index 4cf176b..4c0ebc2 100644 --- a/UniVgo2/Runtime/Porters/Interfaces/IMaterialPorterStore.cs +++ b/UniVgo2/Runtime/Porters/Interfaces/IMaterialPorterStore.cs @@ -19,7 +19,7 @@ public interface IMaterialPorterStore /// /// The vgo material. /// A material porter instanse. - IMaterialPorter? GetPorterOrDefault(VgoMaterial vgoMaterial); + IMaterialPorter? GetPorterOrDefault(in VgoMaterial vgoMaterial); /// /// Get a porter or standard. @@ -27,7 +27,7 @@ public interface IMaterialPorterStore /// The vgo material. /// Type of render pipeline. /// A material porter instanse. - IMaterialPorter GetPorterOrStandard(VgoMaterial vgoMaterial, RenderPipelineType renderPipelineType); + IMaterialPorter GetPorterOrStandard(in VgoMaterial vgoMaterial, in RenderPipelineType renderPipelineType); #endregion @@ -38,7 +38,7 @@ public interface IMaterialPorterStore /// /// The shader name. /// A material porter instanse. - IMaterialPorter? GetPorterOrDefault(string shaderName); + IMaterialPorter? GetPorterOrDefault(in string shaderName); /// /// Get a porter or standard. @@ -46,7 +46,7 @@ public interface IMaterialPorterStore /// The shader name. /// Type of render pipeline. /// A material porter instanse. - IMaterialPorter GetPorterOrStandard(string shaderName, RenderPipelineType renderPipelineType); + IMaterialPorter GetPorterOrStandard(in string shaderName, in RenderPipelineType renderPipelineType); /// /// Get a porter or standard. @@ -55,7 +55,7 @@ public interface IMaterialPorterStore /// The vgo material. /// Type of render pipeline. /// A material porter instanse. - IMaterialPorter GetPorterOrStandard(string shaderName, VgoMaterial vgoMaterial, RenderPipelineType renderPipelineType); + IMaterialPorter GetPorterOrStandard(in string shaderName, in VgoMaterial vgoMaterial, in RenderPipelineType renderPipelineType); #endregion } diff --git a/UniVgo2/Runtime/Porters/Interfaces/IVgoMaterialExporter.cs b/UniVgo2/Runtime/Porters/Interfaces/IVgoMaterialExporter.cs index 14cc472..98fd5f9 100644 --- a/UniVgo2/Runtime/Porters/Interfaces/IVgoMaterialExporter.cs +++ b/UniVgo2/Runtime/Porters/Interfaces/IVgoMaterialExporter.cs @@ -32,7 +32,7 @@ public interface IVgoMaterialExporter /// A unity material. /// A vgo storage. /// A vgo material. - VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgoStorage); + VgoMaterial CreateVgoMaterial(in Material material, in IVgoStorage vgoStorage); #endregion } diff --git a/UniVgo2/Runtime/Porters/Interfaces/IVgoMaterialImporter.cs b/UniVgo2/Runtime/Porters/Interfaces/IVgoMaterialImporter.cs index 67a7a5e..f1be614 100644 --- a/UniVgo2/Runtime/Porters/Interfaces/IVgoMaterialImporter.cs +++ b/UniVgo2/Runtime/Porters/Interfaces/IVgoMaterialImporter.cs @@ -32,7 +32,7 @@ public interface IVgoMaterialImporter /// A vgo material. /// List of Texture2D. /// A unity material. - Material CreateMaterialAsset(VgoMaterial vgoMaterial, List texture2dList); + Material CreateMaterialAsset(in VgoMaterial vgoMaterial, in List texture2dList); #endregion } diff --git a/UniVgo2/Runtime/Porters/Interfaces/IVgoMeshExporter.cs b/UniVgo2/Runtime/Porters/Interfaces/IVgoMeshExporter.cs index fc83490..b8f09ec 100644 --- a/UniVgo2/Runtime/Porters/Interfaces/IVgoMeshExporter.cs +++ b/UniVgo2/Runtime/Porters/Interfaces/IVgoMeshExporter.cs @@ -22,7 +22,7 @@ public interface IVgoMeshExporter /// A vgo storage. /// List of unity mesh asset. /// List of unity material. - void ExportMeshes(IVgoStorage vgoStorage, IList unityMeshAssetList, IList? unityMaterialList = null); + void ExportMeshes(IVgoStorage vgoStorage, in IList unityMeshAssetList, in IList? unityMaterialList = null); #endregion } diff --git a/UniVgo2/Runtime/Porters/Interfaces/IVgoMeshImporter.cs b/UniVgo2/Runtime/Porters/Interfaces/IVgoMeshImporter.cs index 28eded5..2414fbc 100644 --- a/UniVgo2/Runtime/Porters/Interfaces/IVgoMeshImporter.cs +++ b/UniVgo2/Runtime/Porters/Interfaces/IVgoMeshImporter.cs @@ -31,7 +31,7 @@ public interface IVgoMeshImporter /// A vgo storage. /// List of unity material. /// List of mesh asset. - List CreateMeshAssets(IVgoStorage vgoStorage, IList? materialList = null); + List CreateMeshAssets(in IVgoStorage vgoStorage, in IList? materialList = null); /// /// Create mesh assets. @@ -70,7 +70,7 @@ public interface IVgoMeshImporter ///// The index of vgo mesh. ///// List of unity material. ///// A mesh asset. - //MeshAsset CreateMeshAsset(IVgoStorage vgoStorage, int meshIndex, IList? unityMaterialList = null); + //MeshAsset CreateMeshAsset(in IVgoStorage vgoStorage, in int meshIndex, in IList? unityMaterialList = null); ///// ///// Create a mesh asset. @@ -88,7 +88,6 @@ public interface IVgoMeshImporter //Task CreateMeshAssetAsync(IVgoStorage vgoStorage, int meshIndex, IList? unityMaterialList, CancellationToken cancellationToken); #endif - #endregion } } diff --git a/UniVgo2/Runtime/Porters/Interfaces/IVgoParticleSystemExporter.cs b/UniVgo2/Runtime/Porters/Interfaces/IVgoParticleSystemExporter.cs index ed6099e..1e5413e 100644 --- a/UniVgo2/Runtime/Porters/Interfaces/IVgoParticleSystemExporter.cs +++ b/UniVgo2/Runtime/Porters/Interfaces/IVgoParticleSystemExporter.cs @@ -23,7 +23,7 @@ public interface IVgoParticleSystemExporter /// /// /// - VgoParticleSystem Create(ParticleSystem particleSystem, ParticleSystemRenderer particleSystemRenderer, IVgoStorage vgoStorage, ExportTextureDelegate exportTexture); + VgoParticleSystem Create(in ParticleSystem particleSystem, in ParticleSystemRenderer particleSystemRenderer, in IVgoStorage vgoStorage, in ExportTextureDelegate exportTexture); #endregion } diff --git a/UniVgo2/Runtime/Porters/Interfaces/IVgoParticleSystemImporter.cs b/UniVgo2/Runtime/Porters/Interfaces/IVgoParticleSystemImporter.cs index 2830cf0..c67ec60 100644 --- a/UniVgo2/Runtime/Porters/Interfaces/IVgoParticleSystemImporter.cs +++ b/UniVgo2/Runtime/Porters/Interfaces/IVgoParticleSystemImporter.cs @@ -26,7 +26,7 @@ public interface IVgoParticleSystemImporter /// /// /// Returns ParticleSystem component. - ParticleSystem AddComponent(GameObject go, VgoParticleSystem vgoParticleSystem, VgoGeometryCoordinate geometryCoordinate, IList? materialList, IList? texture2dList); + ParticleSystem AddComponent(GameObject go, in VgoParticleSystem vgoParticleSystem, in VgoGeometryCoordinate geometryCoordinate, in IList? materialList, in IList? texture2dList); /// /// Set particleSystemRenderer field value. @@ -35,7 +35,7 @@ public interface IVgoParticleSystemImporter /// /// /// - void SetComponentValue(ParticleSystemRenderer particleSystemRenderer, VGO_PS_Renderer vgoRenderer, VgoGeometryCoordinate geometryCoordinate, IList? materialList); + void SetComponentValue(ParticleSystemRenderer particleSystemRenderer, in VGO_PS_Renderer vgoRenderer, in VgoGeometryCoordinate geometryCoordinate, in IList? materialList); #endregion } diff --git a/UniVgo2/Runtime/Porters/Interfaces/IVgoTextureExporter.cs b/UniVgo2/Runtime/Porters/Interfaces/IVgoTextureExporter.cs index ff8661a..d809609 100644 --- a/UniVgo2/Runtime/Porters/Interfaces/IVgoTextureExporter.cs +++ b/UniVgo2/Runtime/Porters/Interfaces/IVgoTextureExporter.cs @@ -11,7 +11,7 @@ namespace UniVgo2.Porters #region Delegates /// The delegate to ExportTexture method. - public delegate int ExportTextureDelegate(IVgoStorage vgoStorage, Texture srcTexture, VgoTextureMapType textureMapType = VgoTextureMapType.Default, VgoColorSpaceType colorSpaceType = VgoColorSpaceType.Srgb, float metallicSmoothness = -1.0f); + public delegate int ExportTextureDelegate(IVgoStorage vgoStorage, Texture srcTexture, in VgoTextureMapType textureMapType = VgoTextureMapType.Default, in VgoColorSpaceType colorSpaceType = VgoColorSpaceType.Srgb, in float metallicSmoothness = -1.0f); #endregion diff --git a/UniVgo2/Runtime/Porters/Interfaces/IVgoTextureImporter.cs b/UniVgo2/Runtime/Porters/Interfaces/IVgoTextureImporter.cs index a8bf1c0..e385cd8 100644 --- a/UniVgo2/Runtime/Porters/Interfaces/IVgoTextureImporter.cs +++ b/UniVgo2/Runtime/Porters/Interfaces/IVgoTextureImporter.cs @@ -30,7 +30,7 @@ public interface IVgoTextureImporter /// /// A vgo storage. /// List of unity texture2D. - List CreateTextureAssets(IVgoStorage vgoStorage); + List CreateTextureAssets(in IVgoStorage vgoStorage); /// /// Create texture assets. diff --git a/UniVgo2/Runtime/Porters/Materials/AbstractMaterialPorterBase.cs b/UniVgo2/Runtime/Porters/Materials/AbstractMaterialPorterBase.cs index 4e14525..5903bd5 100644 --- a/UniVgo2/Runtime/Porters/Materials/AbstractMaterialPorterBase.cs +++ b/UniVgo2/Runtime/Porters/Materials/AbstractMaterialPorterBase.cs @@ -44,7 +44,7 @@ public AbstractMaterialPorterBase() /// A unity material. /// A vgo storage. /// A vgo material. - public abstract VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgoStorage); + public abstract VgoMaterial CreateVgoMaterial(in Material material, in IVgoStorage vgoStorage); #endregion @@ -84,7 +84,7 @@ protected virtual bool ExportProperties(VgoMaterial vgoMaterial, Material materi /// Whether to exclude property of type color. /// Whether to exclude property of type vector. /// - protected virtual bool ExportProperty(VgoMaterial vgoMaterial, Material material, int propertyIndex, bool excludeColor = false, bool excludeVector = false) + protected virtual bool ExportProperty(VgoMaterial vgoMaterial, Material material, in int propertyIndex, bool excludeColor = false, bool excludeVector = false) { string propertyName = material.shader.GetPropertyName(propertyIndex); @@ -95,10 +95,8 @@ protected virtual bool ExportProperty(VgoMaterial vgoMaterial, Material material case ShaderPropertyType.Color: if (excludeColor == false) { - if (vgoMaterial.colorProperties == null) - { - vgoMaterial.colorProperties = new Dictionary(); - } + vgoMaterial.colorProperties ??= new Dictionary(); + if (vgoMaterial.colorProperties.ContainsKey(propertyName)) { Debug.LogFormat($"vgoMaterial.colorProperties {propertyName}"); @@ -113,10 +111,8 @@ protected virtual bool ExportProperty(VgoMaterial vgoMaterial, Material material case ShaderPropertyType.Vector: if (excludeVector == false) { - if (vgoMaterial.vectorProperties == null) - { - vgoMaterial.vectorProperties = new Dictionary(); - } + vgoMaterial.vectorProperties ??= new Dictionary(); + if (vgoMaterial.vectorProperties.ContainsKey(propertyName)) { Debug.LogFormat($"vgoMaterial.vectorProperties {propertyName}"); @@ -130,17 +126,17 @@ protected virtual bool ExportProperty(VgoMaterial vgoMaterial, Material material case ShaderPropertyType.Float: case ShaderPropertyType.Range: - if (vgoMaterial.floatProperties == null) - { - vgoMaterial.floatProperties = new Dictionary(); - } - if (vgoMaterial.floatProperties.ContainsKey(propertyName)) { - Debug.LogFormat($"vgoMaterial.floatProperties {propertyName}"); - } - else - { - vgoMaterial.floatProperties.Add(propertyName, material.GetFloat(propertyName)); + vgoMaterial.floatProperties ??= new Dictionary(); + + if (vgoMaterial.floatProperties.ContainsKey(propertyName)) + { + Debug.LogFormat($"vgoMaterial.floatProperties {propertyName}"); + } + else + { + vgoMaterial.floatProperties.Add(propertyName, material.GetFloat(propertyName)); + } } break; @@ -150,17 +146,17 @@ protected virtual bool ExportProperty(VgoMaterial vgoMaterial, Material material #if UNITY_2021_1_OR_NEWER case ShaderPropertyType.Int: - if (vgoMaterial.intProperties == null) - { - vgoMaterial.intProperties = new Dictionary(); - } - if (vgoMaterial.intProperties.ContainsKey(propertyName)) { - Debug.LogFormat($"vgoMaterial.intProperties {propertyName}"); - } - else - { - vgoMaterial.intProperties.Add(propertyName, material.GetInt(propertyName)); + vgoMaterial.intProperties ??= new Dictionary(); + + if (vgoMaterial.intProperties.ContainsKey(propertyName)) + { + Debug.LogFormat($"vgoMaterial.intProperties {propertyName}"); + } + else + { + vgoMaterial.intProperties.Add(propertyName, material.GetInt(propertyName)); + } } break; #endif @@ -180,7 +176,7 @@ protected virtual bool ExportProperty(VgoMaterial vgoMaterial, Material material /// A property name. /// The type of property. /// - protected virtual bool ExportProperty(VgoMaterial vgoMaterial, Material material, string propertyName, VgoMaterialPropertyType type) + protected virtual bool ExportProperty(VgoMaterial vgoMaterial, Material material, in string propertyName, in VgoMaterialPropertyType type) { if (material.HasProperty(propertyName) == false) { @@ -190,107 +186,107 @@ protected virtual bool ExportProperty(VgoMaterial vgoMaterial, Material material switch (type) { case VgoMaterialPropertyType.Int: - if (vgoMaterial.intProperties == null) { - vgoMaterial.intProperties = new Dictionary(); - } - if (vgoMaterial.intProperties.ContainsKey(propertyName)) - { - Debug.LogFormat($"vgoMaterial.intProperties {propertyName}"); - } - else - { - vgoMaterial.intProperties.Add(propertyName, material.GetInt(propertyName)); + vgoMaterial.intProperties ??= new Dictionary(); + + if (vgoMaterial.intProperties.ContainsKey(propertyName)) + { + Debug.LogFormat($"vgoMaterial.intProperties {propertyName}"); + } + else + { + vgoMaterial.intProperties.Add(propertyName, material.GetInt(propertyName)); + } } break; case VgoMaterialPropertyType.Float: - if (vgoMaterial.floatProperties == null) - { - vgoMaterial.floatProperties = new Dictionary(); - } - if (vgoMaterial.floatProperties.ContainsKey(propertyName)) - { - Debug.LogFormat($"vgoMaterial.floatProperties {propertyName}"); - } - else { - vgoMaterial.floatProperties.Add(propertyName, material.GetFloat(propertyName)); + vgoMaterial.floatProperties ??= new Dictionary(); + + if (vgoMaterial.floatProperties.ContainsKey(propertyName)) + { + Debug.LogFormat($"vgoMaterial.floatProperties {propertyName}"); + } + else + { + vgoMaterial.floatProperties.Add(propertyName, material.GetFloat(propertyName)); + } } break; case VgoMaterialPropertyType.Color3: - if (vgoMaterial.colorProperties == null) { - vgoMaterial.colorProperties = new Dictionary(); - } - if (vgoMaterial.colorProperties.ContainsKey(propertyName)) - { - Debug.LogFormat($"vgoMaterial.colorProperties {propertyName}"); - } - else - { - vgoMaterial.colorProperties.Add(propertyName, material.GetColor(propertyName).linear.ToArray3()); + vgoMaterial.colorProperties ??= new Dictionary(); + + if (vgoMaterial.colorProperties.ContainsKey(propertyName)) + { + Debug.LogFormat($"vgoMaterial.colorProperties {propertyName}"); + } + else + { + vgoMaterial.colorProperties.Add(propertyName, material.GetColor(propertyName).linear.ToArray3()); + } } break; case VgoMaterialPropertyType.Color4: - if (vgoMaterial.colorProperties == null) - { - vgoMaterial.colorProperties = new Dictionary(); - } - if (vgoMaterial.colorProperties.ContainsKey(propertyName)) { - Debug.LogFormat($"vgoMaterial.colorProperties {propertyName}"); - } - else - { - vgoMaterial.colorProperties.Add(propertyName, material.GetColor(propertyName).linear.ToArray4()); + vgoMaterial.colorProperties ??= new Dictionary(); + + if (vgoMaterial.colorProperties.ContainsKey(propertyName)) + { + Debug.LogFormat($"vgoMaterial.colorProperties {propertyName}"); + } + else + { + vgoMaterial.colorProperties.Add(propertyName, material.GetColor(propertyName).linear.ToArray4()); + } } break; case VgoMaterialPropertyType.Vector2: - if (vgoMaterial.vectorProperties == null) - { - vgoMaterial.vectorProperties = new Dictionary(); - } - if (vgoMaterial.vectorProperties.ContainsKey(propertyName)) - { - Debug.LogFormat($"vgoMaterial.vectorProperties {propertyName}"); - } - else { - vgoMaterial.vectorProperties.Add(propertyName, material.GetVector(propertyName).ToArray2()); + vgoMaterial.vectorProperties ??= new Dictionary(); + + if (vgoMaterial.vectorProperties.ContainsKey(propertyName)) + { + Debug.LogFormat($"vgoMaterial.vectorProperties {propertyName}"); + } + else + { + vgoMaterial.vectorProperties.Add(propertyName, material.GetVector(propertyName).ToArray2()); + } } break; case VgoMaterialPropertyType.Vector3: - if (vgoMaterial.vectorProperties == null) - { - vgoMaterial.vectorProperties = new Dictionary(); - } - if (vgoMaterial.vectorProperties.ContainsKey(propertyName)) - { - Debug.LogFormat($"vgoMaterial.vectorProperties {propertyName}"); - } - else { - vgoMaterial.vectorProperties.Add(propertyName, material.GetVector(propertyName).ToArray3()); + vgoMaterial.vectorProperties ??= new Dictionary(); + + if (vgoMaterial.vectorProperties.ContainsKey(propertyName)) + { + Debug.LogFormat($"vgoMaterial.vectorProperties {propertyName}"); + } + else + { + vgoMaterial.vectorProperties.Add(propertyName, material.GetVector(propertyName).ToArray3()); + } } break; case VgoMaterialPropertyType.Vector4: - if (vgoMaterial.vectorProperties == null) - { - vgoMaterial.vectorProperties = new Dictionary(); - } - if (vgoMaterial.vectorProperties.ContainsKey(propertyName)) { - Debug.LogFormat($"vgoMaterial.vectorProperties {propertyName}"); - } - else - { - vgoMaterial.vectorProperties.Add(propertyName, material.GetVector(propertyName).ToArray()); + vgoMaterial.vectorProperties ??= new Dictionary(); + + if (vgoMaterial.vectorProperties.ContainsKey(propertyName)) + { + Debug.LogFormat($"vgoMaterial.vectorProperties {propertyName}"); + } + else + { + vgoMaterial.vectorProperties.Add(propertyName, material.GetVector(propertyName).ToArray()); + } } break; @@ -299,32 +295,32 @@ protected virtual bool ExportProperty(VgoMaterial vgoMaterial, Material material break; case VgoMaterialPropertyType.TextureOffset: - if (vgoMaterial.textureOffsetProperties == null) - { - vgoMaterial.textureOffsetProperties = new Dictionary(); - } - if (vgoMaterial.textureOffsetProperties.ContainsKey(propertyName)) { - Debug.LogFormat($"vgoMaterial.textureOffsetProperties {propertyName}"); - } - else - { - vgoMaterial.textureOffsetProperties.Add(propertyName, material.GetTextureOffset(propertyName).ToArray()); + vgoMaterial.textureOffsetProperties ??= new Dictionary(); + + if (vgoMaterial.textureOffsetProperties.ContainsKey(propertyName)) + { + Debug.LogFormat($"vgoMaterial.textureOffsetProperties {propertyName}"); + } + else + { + vgoMaterial.textureOffsetProperties.Add(propertyName, material.GetTextureOffset(propertyName).ToArray()); + } } break; case VgoMaterialPropertyType.TextureScale: - if (vgoMaterial.textureScaleProperties == null) - { - vgoMaterial.textureScaleProperties = new Dictionary(); - } - if (vgoMaterial.textureScaleProperties.ContainsKey(propertyName)) - { - Debug.LogFormat($"vgoMaterial.textureScaleProperties {propertyName}"); - } - else { - vgoMaterial.textureScaleProperties.Add(propertyName, material.GetTextureScale(propertyName).ToArray()); + vgoMaterial.textureScaleProperties ??= new Dictionary(); + + if (vgoMaterial.textureScaleProperties.ContainsKey(propertyName)) + { + Debug.LogFormat($"vgoMaterial.textureScaleProperties {propertyName}"); + } + else + { + vgoMaterial.textureScaleProperties.Add(propertyName, material.GetTextureScale(propertyName).ToArray()); + } } break; @@ -343,7 +339,7 @@ protected virtual bool ExportProperty(VgoMaterial vgoMaterial, Material material /// The type of property. /// A property name. /// - protected virtual bool ExportProperty(VgoMaterial vgoMaterial, Material material, VgoMaterialPropertyType type, string propertyName) + protected virtual bool ExportProperty(VgoMaterial vgoMaterial, Material material, in VgoMaterialPropertyType type, in string propertyName) { return ExportProperty(vgoMaterial, material, propertyName, type); } @@ -378,12 +374,9 @@ protected virtual bool ExportKeywords(VgoMaterial vgoMaterial, Material material /// A unity material. /// keyword. /// - protected virtual bool ExportKeyword(VgoMaterial vgoMaterial, Material material, string keyword) + protected virtual bool ExportKeyword(VgoMaterial vgoMaterial, Material material, in string keyword) { - if (vgoMaterial.keywordMap == null) - { - vgoMaterial.keywordMap = new Dictionary(); - } + vgoMaterial.keywordMap ??= new Dictionary(); if (material.IsKeywordEnabled(keyword)) { @@ -409,14 +402,11 @@ protected virtual bool ExportKeyword(VgoMaterial vgoMaterial, Material material, /// /// If the material's shader does not define the tag, defaultValue is returned. /// - protected virtual bool ExportTag(VgoMaterial vgoMaterial, Material material, string tagName, bool searchFallbacks = false, string? defaultValue = null) + protected virtual bool ExportTag(VgoMaterial vgoMaterial, Material material, in string tagName, in bool searchFallbacks = false, in string? defaultValue = null) { string tagValue = material.GetTag(tagName, searchFallbacks, defaultValue); - if (vgoMaterial.tagMap == null) - { - vgoMaterial.tagMap = new Dictionary(); - } + vgoMaterial.tagMap ??= new Dictionary(); if (vgoMaterial.tagMap.ContainsKey(tagName)) { @@ -441,7 +431,14 @@ protected virtual bool ExportTag(VgoMaterial vgoMaterial, Material material, str /// The color space. /// The metallic smoothness. /// - protected virtual bool ExportTextureProperty(IVgoStorage vgoStorage, VgoMaterial vgoMaterial, Material material, string propertyName, VgoTextureMapType textureMapType = VgoTextureMapType.Default, VgoColorSpaceType colorSpace = VgoColorSpaceType.Srgb, float metallicSmoothness = -1.0f) + protected virtual bool ExportTextureProperty( + IVgoStorage vgoStorage, + VgoMaterial vgoMaterial, + Material material, + in string propertyName, + in VgoTextureMapType textureMapType = VgoTextureMapType.Default, + in VgoColorSpaceType colorSpace = VgoColorSpaceType.Srgb, + in float metallicSmoothness = -1.0f) { if (material.HasProperty(propertyName) == false) { @@ -474,10 +471,7 @@ protected virtual bool ExportTextureProperty(IVgoStorage vgoStorage, VgoMaterial return false; } - if (vgoMaterial.textureIndexProperties == null) - { - vgoMaterial.textureIndexProperties = new Dictionary(); - } + vgoMaterial.textureIndexProperties ??= new Dictionary(); if (vgoMaterial.textureIndexProperties.ContainsKey(propertyName)) { @@ -501,7 +495,7 @@ protected virtual bool ExportTextureProperty(IVgoStorage vgoStorage, VgoMaterial /// A unity material. /// A property name. /// - protected virtual bool ExportTextureOffset(VgoMaterial vgoMaterial, Material material, string propertyName) + protected virtual bool ExportTextureOffset(VgoMaterial vgoMaterial, Material material, in string propertyName) { if (material.HasProperty(propertyName) == false) { @@ -512,10 +506,7 @@ protected virtual bool ExportTextureOffset(VgoMaterial vgoMaterial, Material mat if (textureOffset != Vector2.zero) { - if (vgoMaterial.textureOffsetProperties == null) - { - vgoMaterial.textureOffsetProperties = new Dictionary(); - } + vgoMaterial.textureOffsetProperties ??= new Dictionary(); if (vgoMaterial.textureOffsetProperties.ContainsKey(propertyName)) { @@ -537,7 +528,7 @@ protected virtual bool ExportTextureOffset(VgoMaterial vgoMaterial, Material mat /// A unity material. /// A property name. /// - protected virtual bool ExportTextureScale(VgoMaterial vgoMaterial, Material material, string propertyName) + protected virtual bool ExportTextureScale(VgoMaterial vgoMaterial, Material material, in string propertyName) { if (material.HasProperty(propertyName) == false) { @@ -548,10 +539,7 @@ protected virtual bool ExportTextureScale(VgoMaterial vgoMaterial, Material mate if (textureScale != Vector2.one) { - if (vgoMaterial.textureScaleProperties == null) - { - vgoMaterial.textureScaleProperties = new Dictionary(); - } + vgoMaterial.textureScaleProperties ??= new Dictionary(); if (vgoMaterial.textureScaleProperties.ContainsKey(propertyName)) { @@ -577,7 +565,7 @@ protected virtual bool ExportTextureScale(VgoMaterial vgoMaterial, Material mate /// A shader. /// List of all texture 2D. /// A unity material. - public virtual Material CreateMaterialAsset(VgoMaterial vgoMaterial, Shader shader, List allTexture2dList) + public virtual Material CreateMaterialAsset(in VgoMaterial vgoMaterial, in Shader shader, in List allTexture2dList) { var material = new Material(shader) { @@ -613,7 +601,7 @@ public virtual Material CreateMaterialAsset(VgoMaterial vgoMaterial, Shader shad /// /// A unity material. /// A vgo material. - protected virtual void ImportKeywords(Material material, VgoMaterial vgoMaterial) + protected virtual void ImportKeywords(Material material, in VgoMaterial vgoMaterial) { if (vgoMaterial.keywordMap == null) { @@ -645,7 +633,7 @@ protected virtual void ImportKeywords(Material material, VgoMaterial vgoMaterial /// /// A unity material. /// A vgo material. - protected virtual void ImportTagMap(Material material, VgoMaterial vgoMaterial) + protected virtual void ImportTagMap(Material material, in VgoMaterial vgoMaterial) { if (vgoMaterial.tagMap == null) { @@ -680,7 +668,7 @@ protected virtual void ImportTagMap(Material material, VgoMaterial vgoMaterial) /// /// A unity material. /// A vgo material. - protected virtual void ImportColorProperties(Material material, VgoMaterial vgoMaterial) + protected virtual void ImportColorProperties(Material material, in VgoMaterial vgoMaterial) { if (vgoMaterial.colorProperties == null) { @@ -723,7 +711,7 @@ protected virtual void ImportColorProperties(Material material, VgoMaterial vgoM /// /// A unity material. /// A vgo material. - protected virtual void ImportFloatProperties(Material material, VgoMaterial vgoMaterial) + protected virtual void ImportFloatProperties(Material material, in VgoMaterial vgoMaterial) { if (vgoMaterial.floatProperties == null) { @@ -754,7 +742,7 @@ protected virtual void ImportFloatProperties(Material material, VgoMaterial vgoM /// /// A unity material. /// A vgo material. - protected virtual void ImportIntProperties(Material material, VgoMaterial vgoMaterial) + protected virtual void ImportIntProperties(Material material, in VgoMaterial vgoMaterial) { if (vgoMaterial.intProperties == null) { @@ -784,7 +772,7 @@ protected virtual void ImportIntProperties(Material material, VgoMaterial vgoMat /// /// A unity material. /// A vgo material. - protected virtual void ImportMatrixProperties(Material material, VgoMaterial vgoMaterial) + protected virtual void ImportMatrixProperties(Material material, in VgoMaterial vgoMaterial) { if (vgoMaterial.matrixProperties == null) { @@ -826,7 +814,7 @@ protected virtual void ImportMatrixProperties(Material material, VgoMaterial vgo /// /// A unity material. /// A vgo material. - protected virtual void ImportVectorProperties(Material material, VgoMaterial vgoMaterial) + protected virtual void ImportVectorProperties(Material material, in VgoMaterial vgoMaterial) { if (vgoMaterial.vectorProperties == null) { @@ -877,7 +865,7 @@ protected virtual void ImportVectorProperties(Material material, VgoMaterial vgo /// A unity material. /// A vgo material. /// List of all texture 2D. - protected virtual void ImportTextureProperties(Material material, VgoMaterial vgoMaterial, List allTexture2dList) + protected virtual void ImportTextureProperties(Material material, in VgoMaterial vgoMaterial, in List allTexture2dList) { if (vgoMaterial.textureIndexProperties != null) { @@ -977,7 +965,7 @@ protected virtual void ImportTextureProperties(Material material, VgoMaterial vg /// /// A unity material. /// List of the property name. - protected List GetPropertyNameList(Material material) + protected List GetPropertyNameList(in Material material) { int propertyCount = material.shader.GetPropertyCount(); diff --git a/UniVgo2/Runtime/Porters/Materials/HdrpMaterialPorter.cs b/UniVgo2/Runtime/Porters/Materials/HdrpMaterialPorter.cs index 3444abd..b6167c4 100644 --- a/UniVgo2/Runtime/Porters/Materials/HdrpMaterialPorter.cs +++ b/UniVgo2/Runtime/Porters/Materials/HdrpMaterialPorter.cs @@ -33,7 +33,7 @@ public HdrpMaterialPorter() : base() { } /// A HDRP material. /// A vgo storage. /// A vgo material. - public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgoStorage) + public override VgoMaterial CreateVgoMaterial(in Material material, in IVgoStorage vgoStorage) { switch (material.shader.name) { @@ -63,7 +63,7 @@ public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgo /// A HDRP/Eye material. /// A vgo storage. /// A vgo material. - protected VgoMaterial CreateVgoMaterialFromHdrpEye(Material material, IVgoStorage vgoStorage) + protected VgoMaterial CreateVgoMaterialFromHdrpEye(in Material material, in IVgoStorage vgoStorage) { //HdrpEyeDefinition definition = UniHdrpShader.Utils.GetParametersFromMaterial(material); @@ -93,7 +93,7 @@ protected VgoMaterial CreateVgoMaterialFromHdrpEye(Material material, IVgoStorag /// A HDRP/Hair material. /// A vgo storage. /// A vgo material. - protected VgoMaterial CreateVgoMaterialFromHdrpHair(Material material, IVgoStorage vgoStorage) + protected VgoMaterial CreateVgoMaterialFromHdrpHair(in Material material, in IVgoStorage vgoStorage) { //HdrpHairDefinition definition = UniHdrpShader.Utils.GetParametersFromMaterial(material); @@ -123,7 +123,7 @@ protected VgoMaterial CreateVgoMaterialFromHdrpHair(Material material, IVgoStora /// A HDRP/Lit material. /// A vgo storage. /// A vgo material. - protected VgoMaterial CreateVgoMaterialFromHdrpLit(Material material, IVgoStorage vgoStorage) + protected VgoMaterial CreateVgoMaterialFromHdrpLit(in Material material, in IVgoStorage vgoStorage) { //HdrpLitDefinition definition = UniHdrpShader.Utils.GetParametersFromMaterial(material); @@ -173,7 +173,7 @@ protected VgoMaterial CreateVgoMaterialFromHdrpLit(Material material, IVgoStorag /// A HDRP shader. /// List of all texture 2D. /// A HDRP material. - public override Material CreateMaterialAsset(VgoMaterial vgoMaterial, Shader shader, List allTexture2dList) + public override Material CreateMaterialAsset(in VgoMaterial vgoMaterial, in Shader shader, in List allTexture2dList) { switch (vgoMaterial.shaderName) { diff --git a/UniVgo2/Runtime/Porters/Materials/LilToonMaterialPorter.cs b/UniVgo2/Runtime/Porters/Materials/LilToonMaterialPorter.cs index 3c27111..05de0ca 100644 --- a/UniVgo2/Runtime/Porters/Materials/LilToonMaterialPorter.cs +++ b/UniVgo2/Runtime/Porters/Materials/LilToonMaterialPorter.cs @@ -34,7 +34,7 @@ public LilToonMaterialPorter() : base() { } /// A URP material. /// A vgo storage. /// A vgo material. - public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgoStorage) + public override VgoMaterial CreateVgoMaterial(in Material material, in IVgoStorage vgoStorage) { switch (material.shader.name) { @@ -200,14 +200,14 @@ public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgo /// /// A vgo material. protected virtual VgoMaterial CreateVgoMaterialFromLilToon( - Material material, - IVgoStorage vgoStorage, - LilShaderType shaderType = LilShaderType.Normal, - LilRenderingMode renderingMode = LilRenderingMode.Opaque, - LilTransparentMode transparentMode = LilTransparentMode.Normal, - bool isOverlay = false, - bool isOutline = false, - bool isTessellation = false) + in Material material, + in IVgoStorage vgoStorage, + in LilShaderType shaderType = LilShaderType.Normal, + in LilRenderingMode renderingMode = LilRenderingMode.Opaque, + in LilTransparentMode transparentMode = LilTransparentMode.Normal, + in bool isOverlay = false, + in bool isOutline = false, + in bool isTessellation = false) { var vgoMaterial = new VgoMaterial() { @@ -232,7 +232,7 @@ protected virtual VgoMaterial CreateVgoMaterialFromLilToon( /// A lilToon FakeShadow material. /// A vgo storage. /// A vgo material. - protected virtual VgoMaterial CreateVgoMaterialFromLilToonFakeShadow(Material material, IVgoStorage vgoStorage) + protected virtual VgoMaterial CreateVgoMaterialFromLilToonFakeShadow(in Material material, in IVgoStorage vgoStorage) { var vgoMaterial = new VgoMaterial() { @@ -262,7 +262,7 @@ protected virtual VgoMaterial CreateVgoMaterialFromLilToonFakeShadow(Material ma /// A lilToon Multi material. /// A vgo storage. /// A vgo material. - protected virtual VgoMaterial CreateVgoMaterialFromLilToonMulti(Material material, IVgoStorage vgoStorage) + protected virtual VgoMaterial CreateVgoMaterialFromLilToonMulti(in Material material, in IVgoStorage vgoStorage) { // @notice Multi.TransparentMode is RenderingMode LilRenderingMode renderingMode = material.GetSafeEnum(LilToonShader.PropertyName.TransparentMode); @@ -288,10 +288,10 @@ protected virtual VgoMaterial CreateVgoMaterialFromLilToonMulti(Material materia protected virtual void ExportLilTextureProperties( IVgoStorage vgoStorage, VgoMaterial vgoMaterial, - Material material, - LilShaderType shaderType = LilShaderType.Normal, - LilRenderingMode renderingMode = LilRenderingMode.Opaque, - bool isOutline = false) + in Material material, + in LilShaderType shaderType = LilShaderType.Normal, + in LilRenderingMode renderingMode = LilRenderingMode.Opaque, + in bool isOutline = false) { int lilToonVersion = material.GetLilToonVersion(); @@ -570,7 +570,7 @@ protected virtual void ExportLilTextureProperties( /// A lilToon shader. /// List of all texture 2D. /// A lilToon material. - public override Material CreateMaterialAsset(VgoMaterial vgoMaterial, Shader shader, List allTexture2dList) + public override Material CreateMaterialAsset(in VgoMaterial vgoMaterial, in Shader shader, in List allTexture2dList) { if ((shader.name.Contains("lilToon") == false) && (shader.name.StartsWith("Hidden/ltspass") == false)) diff --git a/UniVgo2/Runtime/Porters/Materials/Mtoon10MaterialPorter.cs b/UniVgo2/Runtime/Porters/Materials/Mtoon10MaterialPorter.cs index cb4c92e..1237573 100644 --- a/UniVgo2/Runtime/Porters/Materials/Mtoon10MaterialPorter.cs +++ b/UniVgo2/Runtime/Porters/Materials/Mtoon10MaterialPorter.cs @@ -32,7 +32,7 @@ public Mtoon10MaterialPorter() : base() { } /// A MToon material. /// A vgo storage. /// A vgo material. - public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgoStorage) + public override VgoMaterial CreateVgoMaterial(in Material material, in IVgoStorage vgoStorage) { var mtoonContext = new MToon10Context(material); @@ -160,7 +160,7 @@ public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgo /// A MToon 1.0 property. /// The type of property. /// - protected virtual bool ExportProperty(VgoMaterial vgoMaterial, Material material, MToon10Prop property, VgoMaterialPropertyType type) + protected virtual bool ExportProperty(in VgoMaterial vgoMaterial, in Material material, in MToon10Prop property, in VgoMaterialPropertyType type) { return ExportProperty(vgoMaterial, material, property.ToUnityShaderLabName(), type); } @@ -173,7 +173,7 @@ protected virtual bool ExportProperty(VgoMaterial vgoMaterial, Material material /// The type of property. /// A MToon 1.0 property. /// - protected virtual bool ExportProperty(VgoMaterial vgoMaterial, Material material, VgoMaterialPropertyType type, MToon10Prop property) + protected virtual bool ExportProperty(in VgoMaterial vgoMaterial, in Material material, in VgoMaterialPropertyType type, in MToon10Prop property) { return ExportProperty(vgoMaterial, material, property, type); } @@ -189,7 +189,14 @@ protected virtual bool ExportProperty(VgoMaterial vgoMaterial, Material material /// The color space. /// The metallic smoothness. /// - protected virtual bool ExportTextureProperty(IVgoStorage vgoStorage, VgoMaterial vgoMaterial, Material material, MToon10Prop property, VgoTextureMapType textureMapType = VgoTextureMapType.Default, VgoColorSpaceType colorSpace = VgoColorSpaceType.Srgb, float metallicSmoothness = -1.0f) + protected virtual bool ExportTextureProperty( + IVgoStorage vgoStorage, + VgoMaterial vgoMaterial, + in Material material, + in MToon10Prop property, + in VgoTextureMapType textureMapType = VgoTextureMapType.Default, + in VgoColorSpaceType colorSpace = VgoColorSpaceType.Srgb, + in float metallicSmoothness = -1.0f) { return ExportTextureProperty(vgoStorage, vgoMaterial, material, property.ToUnityShaderLabName(), textureMapType, colorSpace, metallicSmoothness); } @@ -205,7 +212,7 @@ protected virtual bool ExportTextureProperty(IVgoStorage vgoStorage, VgoMaterial /// A MToon shader. /// List of all texture 2D. /// A MToon material. - public override Material CreateMaterialAsset(VgoMaterial vgoMaterial, Shader shader, List allTexture2dList) + public override Material CreateMaterialAsset(in VgoMaterial vgoMaterial, in Shader shader, in List allTexture2dList) { if (vgoMaterial.shaderName != ShaderName.VRM_MToon10) { @@ -448,7 +455,14 @@ protected virtual void SetUnityShaderPassSettings(Material material, in MToon10A material.SetInt(MToon10Prop.RenderQueueOffsetNumber, renderQueueOffset); } - protected virtual void SetSafeValue(Material material, VgoMaterial vgoMaterial, MToon10Prop property, int defaultValue = default) + /// + /// + /// + /// + /// + /// + /// + protected virtual void SetSafeValue(Material material, in VgoMaterial vgoMaterial, in MToon10Prop property, int defaultValue = default) { string propertyName = property.ToUnityShaderLabName(); @@ -457,7 +471,16 @@ protected virtual void SetSafeValue(Material material, VgoMaterial vgoMaterial, material.SetSafeInt(propertyName, value); } - protected virtual void SetSafeValue(Material material, VgoMaterial vgoMaterial, MToon10Prop property, int min, int max, int defaultValue = default) + /// + /// + /// + /// + /// + /// + /// + /// + /// + protected virtual void SetSafeValue(Material material, in VgoMaterial vgoMaterial, in MToon10Prop property, int min, int max, int defaultValue = default) { string propertyName = property.ToUnityShaderLabName(); @@ -466,7 +489,14 @@ protected virtual void SetSafeValue(Material material, VgoMaterial vgoMaterial, material.SetSafeInt(propertyName, value); } - protected virtual void SetSafeValue(Material material, VgoMaterial vgoMaterial, MToon10Prop property, float defaultValue = default) + /// + /// + /// + /// + /// + /// + /// + protected virtual void SetSafeValue(Material material, in VgoMaterial vgoMaterial, in MToon10Prop property, float defaultValue = default) { string propertyName = property.ToUnityShaderLabName(); @@ -475,7 +505,16 @@ protected virtual void SetSafeValue(Material material, VgoMaterial vgoMaterial, material.SetSafeFloat(propertyName, value, minValue: null, maxValue: null); } - protected virtual void SetSafeValue(Material material, VgoMaterial vgoMaterial, MToon10Prop property, float min, float max, float defaultValue = default) + /// + /// + /// + /// + /// + /// + /// + /// + /// + protected virtual void SetSafeValue(Material material, in VgoMaterial vgoMaterial, in MToon10Prop property, float min, float max, float defaultValue = default) { string propertyName = property.ToUnityShaderLabName(); @@ -484,7 +523,14 @@ protected virtual void SetSafeValue(Material material, VgoMaterial vgoMaterial, material.SetSafeFloat(propertyName, value, minValue: null, maxValue: null); } - protected virtual void SetColor(Material material, VgoMaterial vgoMaterial, MToon10Prop property, Color defaultValue = default) + /// + /// + /// + /// + /// + /// + /// + protected virtual void SetColor(Material material, in VgoMaterial vgoMaterial, in MToon10Prop property, Color defaultValue = default) { string propertyName = property.ToUnityShaderLabName(); @@ -493,7 +539,14 @@ protected virtual void SetColor(Material material, VgoMaterial vgoMaterial, MToo material.SetSafeColor(propertyName, color); } - protected virtual void SetTexture(Material material, VgoMaterial vgoMaterial, List allTexture2dList, MToon10Prop property) + /// + /// + /// + /// + /// + /// + /// + protected virtual void SetTexture(Material material, in VgoMaterial vgoMaterial, in List allTexture2dList, in MToon10Prop property) { string propertyName = property.ToUnityShaderLabName(); diff --git a/UniVgo2/Runtime/Porters/Materials/MtoonMaterialPorter.cs b/UniVgo2/Runtime/Porters/Materials/MtoonMaterialPorter.cs index 23b17c7..296c1d0 100644 --- a/UniVgo2/Runtime/Porters/Materials/MtoonMaterialPorter.cs +++ b/UniVgo2/Runtime/Porters/Materials/MtoonMaterialPorter.cs @@ -34,7 +34,7 @@ public MtoonMaterialPorter() : base() { } /// A MToon material. /// A vgo storage. /// A vgo material. - public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgoStorage) + public override VgoMaterial CreateVgoMaterial(in Material material, in IVgoStorage vgoStorage) { //MToonDefinition definition = MToon.Utils.GetMToonParametersFromMaterial(material); @@ -122,7 +122,7 @@ public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgo /// A MToon shader. /// List of all texture 2D. /// A MToon material. - public override Material CreateMaterialAsset(VgoMaterial vgoMaterial, Shader shader, List allTexture2dList) + public override Material CreateMaterialAsset(in VgoMaterial vgoMaterial, in Shader shader, in List allTexture2dList) { if (vgoMaterial.shaderName != ShaderName.VRM_MToon) { @@ -166,7 +166,7 @@ public override Material CreateMaterialAsset(VgoMaterial vgoMaterial, Shader sha /// A vgo material. /// List of all texture 2D. /// A MToon definition. - protected virtual MToonDefinition CreateMToonDefinition(VgoMaterial vgoMaterial, List allTexture2dList) + protected virtual MToonDefinition CreateMToonDefinition(in VgoMaterial vgoMaterial, in List allTexture2dList) { MToonDefinition mtoonDefinition = new MToonDefinition(); @@ -286,7 +286,7 @@ protected virtual MToonDefinition CreateMToonDefinition(VgoMaterial vgoMaterial, /// /// Migrate from MToon 0.x setting to MToon 1.0 material. /// - protected virtual Material CreateMaterialAssetAsMtoon10(VgoMaterial vgoMaterial, Shader shader, List allTexture2dList) + protected virtual Material CreateMaterialAssetAsMtoon10(in VgoMaterial vgoMaterial, Shader shader, in List allTexture2dList) { var material = new Material(shader) { @@ -580,35 +580,75 @@ protected virtual void SetUnityShaderPassSettingsAsMtoon10(Material material, in material.SetInt(MToon10Prop.RenderQueueOffsetNumber, renderQueueOffset); } - protected virtual void SetSafeValue(Material material, VgoMaterial vgoMaterial, MToon10Prop property, int value) + /// + /// + /// + /// + /// + /// + /// + protected virtual void SetSafeValue(Material material, in VgoMaterial vgoMaterial, in MToon10Prop property, int value) { string propertyName = property.ToUnityShaderLabName(); material.SetSafeInt(propertyName, value); } - protected virtual void SetSafeValue(Material material, VgoMaterial vgoMaterial, MToon10Prop property, float value) + /// + /// + /// + /// + /// + /// + /// + protected virtual void SetSafeValue(Material material, in VgoMaterial vgoMaterial, in MToon10Prop property, float value) { string propertyName = property.ToUnityShaderLabName(); material.SetSafeFloat(propertyName, value, minValue: null, maxValue: null); } - protected virtual void SetSafeValue(Material material, VgoMaterial vgoMaterial, MToon10Prop property, float value, float min, float max, float defaultValue = default) + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + protected virtual void SetSafeValue(Material material, in VgoMaterial vgoMaterial, in MToon10Prop property, float value, float min, float max, float defaultValue = default) { string propertyName = property.ToUnityShaderLabName(); material.SetSafeFloat(propertyName, value, min, max, defaultValue); } - protected virtual void SetColor(Material material, VgoMaterial vgoMaterial, MToon10Prop property, Color color) + /// + /// + /// + /// + /// + /// + /// + protected virtual void SetColor(Material material, in VgoMaterial vgoMaterial, in MToon10Prop property, Color color) { string propertyName = property.ToUnityShaderLabName(); material.SetSafeColor(propertyName, color); } - protected virtual void SetTexture(Material material, VgoMaterial vgoMaterial, MToon10Prop property, Texture2D? texture, Vector2? offset = null, Vector2? scale = null) + /// + /// + /// + /// + /// + /// + /// + /// + /// + protected virtual void SetTexture(Material material, in VgoMaterial vgoMaterial, in MToon10Prop property, Texture2D? texture, Vector2? offset = null, Vector2? scale = null) { string propertyName = property.ToUnityShaderLabName(); diff --git a/UniVgo2/Runtime/Porters/Materials/ParticleMaterialPorter.cs b/UniVgo2/Runtime/Porters/Materials/ParticleMaterialPorter.cs index 88a5c13..97c7abb 100644 --- a/UniVgo2/Runtime/Porters/Materials/ParticleMaterialPorter.cs +++ b/UniVgo2/Runtime/Porters/Materials/ParticleMaterialPorter.cs @@ -35,7 +35,7 @@ public ParticleMaterialPorter() : base() { } /// A particle material. /// A vgo storage. /// A vgo material. - public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgoStorage) + public override VgoMaterial CreateVgoMaterial(in Material material, in IVgoStorage vgoStorage) { //ParticleDefinition particleDefinition = UniParticleShader.Utils.GetParametersFromMaterial(material); @@ -50,10 +50,7 @@ public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgo // Properties - if (vgoMaterial.intProperties is null) - { - vgoMaterial.intProperties = new Dictionary(); - } + vgoMaterial.intProperties ??= new Dictionary(); ExportProperty(vgoMaterial, material, Property.BlendMode, VgoMaterialPropertyType.Int); @@ -136,7 +133,7 @@ public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgo /// A particle shader. /// List of all texture 2D. /// A particle material. - public override Material CreateMaterialAsset(VgoMaterial vgoMaterial, Shader shader, List allTexture2dList) + public override Material CreateMaterialAsset(in VgoMaterial vgoMaterial, in Shader shader, in List allTexture2dList) { if ((vgoMaterial.shaderName != UniVgo2.ShaderName.Particles_Standard_Surface) && (vgoMaterial.shaderName != UniVgo2.ShaderName.Particles_Standard_Unlit)) @@ -178,7 +175,7 @@ public override Material CreateMaterialAsset(VgoMaterial vgoMaterial, Shader sha /// A vgo material. /// List of all texture 2D. /// A particle definition. - protected virtual ParticleDefinition CreateParticleDefinition(VgoMaterial vgoMaterial, List allTexture2dList) + protected virtual ParticleDefinition CreateParticleDefinition(in VgoMaterial vgoMaterial, in List allTexture2dList) { var particleDefinition = new ParticleDefinition { @@ -263,7 +260,7 @@ protected virtual ParticleDefinition CreateParticleDefinition(VgoMaterial vgoMat /// A URP Particle shader. /// List of all texture 2D. /// A URP Particle material. - public virtual Material CreateMaterialAssetAsUrp(VgoMaterial vgoMaterial, Shader shader, List allTexture2dList) + public virtual Material CreateMaterialAssetAsUrp(in VgoMaterial vgoMaterial, Shader shader, in List allTexture2dList) { var material = new Material(shader) { @@ -299,7 +296,7 @@ public virtual Material CreateMaterialAssetAsUrp(VgoMaterial vgoMaterial, Shader /// /// A BRP particle definition. /// A URP particle definition. - protected virtual UniUrpParticleShader.UrpParticleDefinition ConvertDefinitionBrpToUrp(ParticleDefinition brpParticleDefinition) + protected virtual UniUrpParticleShader.UrpParticleDefinition ConvertDefinitionBrpToUrp(in ParticleDefinition brpParticleDefinition) { var urpParticleDefinition = new UniUrpParticleShader.UrpParticleDefinition { diff --git a/UniVgo2/Runtime/Porters/Materials/SkyboxMaterialPorter.cs b/UniVgo2/Runtime/Porters/Materials/SkyboxMaterialPorter.cs index dc284f6..d0c5bda 100644 --- a/UniVgo2/Runtime/Porters/Materials/SkyboxMaterialPorter.cs +++ b/UniVgo2/Runtime/Porters/Materials/SkyboxMaterialPorter.cs @@ -33,7 +33,7 @@ public SkyboxMaterialPorter() : base() { } /// A skybox material. /// A vgo storage. /// A vgo material. - public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgoStorage) + public override VgoMaterial CreateVgoMaterial(in Material material, in IVgoStorage vgoStorage) { var vgoMaterial = new VgoMaterial { @@ -116,7 +116,7 @@ public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgo /// A skybox shader. /// List of all texture 2D. /// A skybox material. - public override Material CreateMaterialAsset(VgoMaterial vgoMaterial, Shader shader, List allTexture2dList) + public override Material CreateMaterialAsset(in VgoMaterial vgoMaterial, in Shader shader, in List allTexture2dList) { var material = new Material(shader) { diff --git a/UniVgo2/Runtime/Porters/Materials/StandardMaterialPorter.cs b/UniVgo2/Runtime/Porters/Materials/StandardMaterialPorter.cs index 58c8c17..c73c303 100644 --- a/UniVgo2/Runtime/Porters/Materials/StandardMaterialPorter.cs +++ b/UniVgo2/Runtime/Porters/Materials/StandardMaterialPorter.cs @@ -32,7 +32,7 @@ public StandardMaterialPorter() : base() { } /// A standard material. /// A vgo storage. /// A vgo material. - public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgoStorage) + public override VgoMaterial CreateVgoMaterial(in Material material, in IVgoStorage vgoStorage) { //StandardDefinition definition = UniStandardShader.Utils.GetParametersFromMaterial(material); @@ -118,7 +118,7 @@ public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgo /// A standard shader. /// List of all texture 2D. /// A standard material. - public override Material CreateMaterialAsset(VgoMaterial vgoMaterial, Shader shader, List allTexture2dList) + public override Material CreateMaterialAsset(in VgoMaterial vgoMaterial, in Shader shader, in List allTexture2dList) { Material material = base.CreateMaterialAsset(vgoMaterial, shader, allTexture2dList); diff --git a/UniVgo2/Runtime/Porters/Materials/StandardVColorMaterialPorter.cs b/UniVgo2/Runtime/Porters/Materials/StandardVColorMaterialPorter.cs index efe15c8..29c65e3 100644 --- a/UniVgo2/Runtime/Porters/Materials/StandardVColorMaterialPorter.cs +++ b/UniVgo2/Runtime/Porters/Materials/StandardVColorMaterialPorter.cs @@ -30,7 +30,7 @@ public StandardVColorMaterialPorter() : base() { } /// A standard material. /// A vgo storage. /// A vgo material. - public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgoStorage) + public override VgoMaterial CreateVgoMaterial(in Material material, in IVgoStorage vgoStorage) { VgoMaterial vgoMaterial = new VgoMaterial() { diff --git a/UniVgo2/Runtime/Porters/Materials/UnlitMaterialPorter.cs b/UniVgo2/Runtime/Porters/Materials/UnlitMaterialPorter.cs index b5e47a3..c0329c9 100644 --- a/UniVgo2/Runtime/Porters/Materials/UnlitMaterialPorter.cs +++ b/UniVgo2/Runtime/Porters/Materials/UnlitMaterialPorter.cs @@ -59,7 +59,7 @@ protected enum BlendMode /// A unlit material. /// A vgo storage. /// vgo material - public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgoStorage) + public override VgoMaterial CreateVgoMaterial(in Material material, in IVgoStorage vgoStorage) { VgoMaterial vgoMaterial = new VgoMaterial() { @@ -105,7 +105,7 @@ public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgo ///// A unlit shader. ///// List of all texture 2D. ///// A unlit material. - //public override Material CreateMaterialAsset(VgoMaterial vgoMaterial, Shader shader, List allTexture2dList) + //public override Material CreateMaterialAsset(in VgoMaterial vgoMaterial, in Shader shader, in List allTexture2dList) //{ // Material material = base.CreateMaterialAsset(vgoMaterial, shader, allTexture2dList); diff --git a/UniVgo2/Runtime/Porters/Materials/UrpMaterialPorter.cs b/UniVgo2/Runtime/Porters/Materials/UrpMaterialPorter.cs index ebef148..ca82431 100644 --- a/UniVgo2/Runtime/Porters/Materials/UrpMaterialPorter.cs +++ b/UniVgo2/Runtime/Porters/Materials/UrpMaterialPorter.cs @@ -33,7 +33,7 @@ public UrpMaterialPorter() : base() { } /// A URP material. /// A vgo storage. /// A vgo material. - public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgoStorage) + public override VgoMaterial CreateVgoMaterial(in Material material, in IVgoStorage vgoStorage) { switch (material.shader.name) { @@ -59,7 +59,7 @@ public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgo /// A URP/Lit material. /// A vgo storage. /// A vgo material. - protected VgoMaterial CreateVgoMaterialFromUrpLit(Material material, IVgoStorage vgoStorage) + protected VgoMaterial CreateVgoMaterialFromUrpLit(in Material material, in IVgoStorage vgoStorage) { //UrpLitDefinition definition = UniUrpShader.Utils.GetParametersFromMaterial(material); @@ -109,7 +109,7 @@ protected VgoMaterial CreateVgoMaterialFromUrpLit(Material material, IVgoStorage /// A URP/Simple Lit material. /// A vgo storage. /// A vgo material. - protected VgoMaterial CreateVgoMaterialFromUrpSimpleLit(Material material, IVgoStorage vgoStorage) + protected VgoMaterial CreateVgoMaterialFromUrpSimpleLit(in Material material, in IVgoStorage vgoStorage) { UrpSimpleLitDefinition definition = UniUrpShader.Utils.GetParametersFromMaterial(material); @@ -155,7 +155,7 @@ protected VgoMaterial CreateVgoMaterialFromUrpSimpleLit(Material material, IVgoS /// A URP/Unlit material. /// A vgo storage. /// A vgo material. - protected VgoMaterial CreateVgoMaterialFromUrpUnlit(Material material, IVgoStorage vgoStorage) + protected VgoMaterial CreateVgoMaterialFromUrpUnlit(in Material material, in IVgoStorage vgoStorage) { UrpUnlitDefinition definition = UniUrpShader.Utils.GetParametersFromMaterial(material); @@ -187,7 +187,7 @@ protected VgoMaterial CreateVgoMaterialFromUrpUnlit(Material material, IVgoStora /// A URP shader. /// List of all texture 2D. /// A URP material. - public override Material CreateMaterialAsset(VgoMaterial vgoMaterial, Shader shader, List allTexture2dList) + public override Material CreateMaterialAsset(in VgoMaterial vgoMaterial, in Shader shader, in List allTexture2dList) { switch (vgoMaterial.shaderName) { diff --git a/UniVgo2/Runtime/Porters/Materials/UrpParticleMaterialPorter.cs b/UniVgo2/Runtime/Porters/Materials/UrpParticleMaterialPorter.cs index 746f3e6..a196373 100644 --- a/UniVgo2/Runtime/Porters/Materials/UrpParticleMaterialPorter.cs +++ b/UniVgo2/Runtime/Porters/Materials/UrpParticleMaterialPorter.cs @@ -35,7 +35,7 @@ public UrpParticleMaterialPorter() : base() { } /// A HDRP material. /// A vgo storage. /// A vgo material. - public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgoStorage) + public override VgoMaterial CreateVgoMaterial(in Material material, in IVgoStorage vgoStorage) { var vgoMaterial = new VgoMaterial() { @@ -125,7 +125,7 @@ public override VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgo /// A URP Particle shader. /// List of all texture 2D. /// A URP Particle material. - public override Material CreateMaterialAsset(VgoMaterial vgoMaterial, Shader shader, List allTexture2dList) + public override Material CreateMaterialAsset(in VgoMaterial vgoMaterial, in Shader shader, in List allTexture2dList) { switch (vgoMaterial.shaderName) { @@ -171,7 +171,7 @@ public override Material CreateMaterialAsset(VgoMaterial vgoMaterial, Shader sha /// A vgo material. /// List of all texture 2D. /// A URP particle definition. - protected virtual UrpParticleDefinition CreateUrpParticleDefinition(VgoMaterial vgoMaterial, List allTexture2dList) + protected virtual UrpParticleDefinition CreateUrpParticleDefinition(in VgoMaterial vgoMaterial, in List allTexture2dList) { var urpParticleDefinition = new UrpParticleDefinition { diff --git a/UniVgo2/Runtime/Porters/Materials/VgoMaterialPorter.cs b/UniVgo2/Runtime/Porters/Materials/VgoMaterialPorter.cs index f656af0..8aeba84 100644 --- a/UniVgo2/Runtime/Porters/Materials/VgoMaterialPorter.cs +++ b/UniVgo2/Runtime/Porters/Materials/VgoMaterialPorter.cs @@ -41,10 +41,8 @@ public RenderPipelineType RenderPipelineType { get { - if (_RenderPipelineType == null) - { - _RenderPipelineType = GetRenderPipelineType(); - } + _RenderPipelineType ??= GetRenderPipelineType(); + return (RenderPipelineType)_RenderPipelineType; } } @@ -59,7 +57,7 @@ public RenderPipelineType RenderPipelineType /// A unity material. /// A vgo storage. /// A vgo material. - public VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgoStorage) + public VgoMaterial CreateVgoMaterial(in Material material, in IVgoStorage vgoStorage) { if (MaterialPorterStore == null) { @@ -94,7 +92,7 @@ public VgoMaterial CreateVgoMaterial(Material material, IVgoStorage vgoStorage) /// A vgo material. /// List of Texture2D. /// A unity material. - public virtual Material CreateMaterialAsset(VgoMaterial vgoMaterial, List texture2dList) + public virtual Material CreateMaterialAsset(in VgoMaterial vgoMaterial, in List texture2dList) { if (MaterialPorterStore == null) { diff --git a/UniVgo2/Runtime/Porters/Materials/VgoMaterialPorterStore.cs b/UniVgo2/Runtime/Porters/Materials/VgoMaterialPorterStore.cs index 13051ee..4e98747 100644 --- a/UniVgo2/Runtime/Porters/Materials/VgoMaterialPorterStore.cs +++ b/UniVgo2/Runtime/Porters/Materials/VgoMaterialPorterStore.cs @@ -100,7 +100,7 @@ protected UrpParticleMaterialPorter UrpParticleMaterialPorter /// /// The vgo material. /// A material porter instanse. - public virtual IMaterialPorter? GetPorterOrDefault(VgoMaterial vgoMaterial) + public virtual IMaterialPorter? GetPorterOrDefault(in VgoMaterial vgoMaterial) { if (vgoMaterial == null) { @@ -139,7 +139,7 @@ protected UrpParticleMaterialPorter UrpParticleMaterialPorter /// The vgo material. /// Type of render pipeline. /// A material porter instanse. - public virtual IMaterialPorter GetPorterOrStandard(VgoMaterial vgoMaterial, RenderPipelineType renderPipelineType) + public virtual IMaterialPorter GetPorterOrStandard(in VgoMaterial vgoMaterial, in RenderPipelineType renderPipelineType) { IMaterialPorter? porter = GetPorterOrDefault(vgoMaterial); @@ -178,7 +178,7 @@ public virtual IMaterialPorter GetPorterOrStandard(VgoMaterial vgoMaterial, Rend /// /// The shader name. /// A material porter instanse. - public virtual IMaterialPorter? GetPorterOrDefault(string shaderName) + public virtual IMaterialPorter? GetPorterOrDefault(in string shaderName) { if (string.IsNullOrEmpty(shaderName)) { @@ -312,7 +312,7 @@ public virtual IMaterialPorter GetPorterOrStandard(VgoMaterial vgoMaterial, Rend /// The shader name. /// Type of render pipeline. /// A material porter instanse. - public virtual IMaterialPorter GetPorterOrStandard(string shaderName, RenderPipelineType renderPipelineType) + public virtual IMaterialPorter GetPorterOrStandard(in string shaderName, in RenderPipelineType renderPipelineType) { IMaterialPorter? porter = GetPorterOrDefault(shaderName); @@ -342,7 +342,7 @@ public virtual IMaterialPorter GetPorterOrStandard(string shaderName, RenderPipe /// The vgo material. /// Type of render pipeline. /// A material porter instanse. - public virtual IMaterialPorter GetPorterOrStandard(string shaderName, VgoMaterial vgoMaterial, RenderPipelineType renderPipelineType) + public virtual IMaterialPorter GetPorterOrStandard(in string shaderName, in VgoMaterial vgoMaterial, in RenderPipelineType renderPipelineType) { IMaterialPorter? porter = GetPorterOrDefault(shaderName); diff --git a/UniVgo2/Runtime/Porters/Meshes/VgoMeshExporter.cs b/UniVgo2/Runtime/Porters/Meshes/VgoMeshExporter.cs index 34b135a..d38456e 100644 --- a/UniVgo2/Runtime/Porters/Meshes/VgoMeshExporter.cs +++ b/UniVgo2/Runtime/Porters/Meshes/VgoMeshExporter.cs @@ -35,7 +35,7 @@ public VgoMeshExporter() : this(new MeshExporterOption()) { } /// Create a new instance of VgoMeshExporter with option. /// /// The mesh exporter option. - public VgoMeshExporter(MeshExporterOption option) + public VgoMeshExporter(in MeshExporterOption option) { _Option = option; } @@ -50,7 +50,7 @@ public VgoMeshExporter(MeshExporterOption option) /// A vgo storage. /// List of unity mesh asset. /// List of unity material. - public virtual void ExportMeshes(IVgoStorage vgoStorage, IList unityMeshAssetList, IList? unityMaterialList = null) + public virtual void ExportMeshes(IVgoStorage vgoStorage, in IList unityMeshAssetList, in IList? unityMaterialList = null) { if (vgoStorage.IsSpecVersion_2_4_orLower) { @@ -78,13 +78,13 @@ public virtual void ExportMeshes(IVgoStorage vgoStorage, IList unityM /// A mesh asset. /// List of unity material. /// A vgo mesh. - protected virtual VgoMesh CreateVgoMesh(IVgoStorage vgoStorage, MeshAsset meshAsset, IList? unityMaterialList) + protected virtual VgoMesh CreateVgoMesh(IVgoStorage vgoStorage, in MeshAsset meshAsset, in IList? unityMaterialList) { Mesh mesh = meshAsset.Mesh; BlendShapeConfig? blendShapeConfig = meshAsset.BlendShapeConfig; - VgoMesh vgoMesh = new VgoMesh(mesh.name); + var vgoMesh = new VgoMesh(mesh.name); // Attribetes vgoMesh.attributes = CreatePrimitiveAttributes(vgoStorage, mesh); @@ -113,10 +113,7 @@ protected virtual VgoMesh CreateVgoMesh(IVgoStorage vgoStorage, MeshAsset meshAs if (materialIndex >= 0) { - if (vgoMesh.materials == null) - { - vgoMesh.materials = new List(); - } + vgoMesh.materials ??= new List(); vgoMesh.materials.Add(materialIndex); } @@ -144,25 +141,25 @@ protected virtual VgoMesh CreateVgoMesh(IVgoStorage vgoStorage, MeshAsset meshAs if (blendShapeConfig != null) { - BlendShapeFacePart? facePart = blendShapeConfig.FaceParts.FirstOrDefault(x => x.index == shapeIndex); + BlendShapeFacePart? facePart = blendShapeConfig.FaceParts.FirstOrDefault(x => x.Index == shapeIndex); if (facePart != null) { - vgoMeshBlendShape.facePartsType = facePart.type; + vgoMeshBlendShape.facePartsType = facePart.Type; } - BlendShapeBlink? blink = blendShapeConfig.Blinks.FirstOrDefault(x => x.index == shapeIndex); + BlendShapeBlink? blink = blendShapeConfig.Blinks.FirstOrDefault(x => x.Index == shapeIndex); if (blink != null) { - vgoMeshBlendShape.blinkType = blink.type; + vgoMeshBlendShape.blinkType = blink.Type; } - BlendShapeViseme? viseme = blendShapeConfig.Visemes.FirstOrDefault(x => x.index == shapeIndex); + BlendShapeViseme? viseme = blendShapeConfig.Visemes.FirstOrDefault(x => x.Index == shapeIndex); if (viseme != null) { - vgoMeshBlendShape.visemeType = viseme.type; + vgoMeshBlendShape.visemeType = viseme.Type; } } @@ -192,7 +189,7 @@ protected virtual VgoMesh CreateVgoMesh(IVgoStorage vgoStorage, MeshAsset meshAs /// A vgo storage. /// A unity mesh. /// A vgo mesh primitive attributes. - protected virtual VgoMeshPrimitiveAttributes CreatePrimitiveAttributes(IVgoStorage vgoStorage, Mesh mesh) + protected virtual VgoMeshPrimitiveAttributes CreatePrimitiveAttributes(in IVgoStorage vgoStorage, in Mesh mesh) { var attributes = new VgoMeshPrimitiveAttributes(); @@ -344,7 +341,7 @@ protected void SetUV(IVgoStorage vgoStorage, VgoMeshPrimitiveAttributes attribut /// A vgo storage. /// The mesh indices. /// The index of accessor. - protected virtual int AddAccessorForSubMesh(IVgoStorage vgoStorage, int[] meshIndices) + protected virtual int AddAccessorForSubMesh(IVgoStorage vgoStorage, in int[] meshIndices) { int accessorIndex = -1; @@ -397,7 +394,7 @@ protected virtual int AddAccessorForSubMesh(IVgoStorage vgoStorage, int[] meshIn /// index is byte(1) or ushort(2) or uint(4) /// value is uint(4) /// - protected virtual bool JudgeSparseForSubMesh(int[] meshIndices) + protected virtual bool JudgeSparseForSubMesh(in int[] meshIndices) { int sparseValuesCount = meshIndices.Count(x => x != 0); @@ -433,7 +430,7 @@ protected virtual bool JudgeSparseForSubMesh(int[] meshIndices) /// A unity mesh. /// The index of blend shape. /// A vgo blend shape attributes. - protected virtual VgoMeshPrimitiveAttributes CreateBlendShapeAttributes(IVgoStorage vgoStorage, Mesh mesh, int blendShapeIndex) + protected virtual VgoMeshPrimitiveAttributes CreateBlendShapeAttributes(IVgoStorage vgoStorage, in Mesh mesh, in int blendShapeIndex) { int frameIndex = mesh.GetBlendShapeFrameCount(blendShapeIndex) - 1; @@ -597,12 +594,14 @@ protected virtual int AddAccessorForBlendShape(IVgoStorage vgoStorage, Vector3[] /// Judge if accessor sparse should be applied. /// /// The vertexes. + /// The sparse type. + /// The sparse count. /// Returns true if sparse should be applied, false otherwise. /// /// index is byte(1) or ushort(2) or uint(4) /// value is Vector3(12) [General] or float(4) [Powerful] /// - protected virtual bool JudgeSparseForBlendShape(Vector3[] vertexes, out VgoResourceAccessorSparseType sparseType, out int sparseCount) + protected virtual bool JudgeSparseForBlendShape(in Vector3[] vertexes, out VgoResourceAccessorSparseType sparseType, out int sparseCount) { sparseType = VgoResourceAccessorSparseType.None; sparseCount = 0; diff --git a/UniVgo2/Runtime/Porters/Meshes/VgoMeshImporter.cs b/UniVgo2/Runtime/Porters/Meshes/VgoMeshImporter.cs index 4bf5eb9..a4f4584 100644 --- a/UniVgo2/Runtime/Porters/Meshes/VgoMeshImporter.cs +++ b/UniVgo2/Runtime/Porters/Meshes/VgoMeshImporter.cs @@ -45,7 +45,7 @@ public VgoMeshImporter() : this(new MeshImporterOption()) { } /// Create a new instance of VgoMeshImporter with option. /// /// - public VgoMeshImporter(MeshImporterOption option) + public VgoMeshImporter(in MeshImporterOption option) { _Option = option; } @@ -60,7 +60,7 @@ public VgoMeshImporter(MeshImporterOption option) /// A vgo storage. /// List of unity material. /// List of mesh asset. - public virtual List CreateMeshAssets(IVgoStorage vgoStorage, IList? materialList = null) + public virtual List CreateMeshAssets(in IVgoStorage vgoStorage, in IList? materialList = null) { if ((vgoStorage.Layout.meshes == null) || (vgoStorage.Layout.meshes.Any() == false)) { @@ -198,7 +198,7 @@ public virtual async Task> CreateMeshAssetsParallelAsync(IVgoSto /// The index of vgo mesh. /// List of unity material. /// A mesh asset. - protected virtual MeshAsset CreateMeshAsset(IVgoStorage vgoStorage, int meshIndex, IList? unityMaterialList = null) + protected virtual MeshAsset CreateMeshAsset(in IVgoStorage vgoStorage, in int meshIndex, in IList? unityMaterialList = null) { MeshContext meshContext = ReadMesh(vgoStorage, meshIndex); @@ -215,7 +215,9 @@ protected virtual MeshAsset CreateMeshAsset(IVgoStorage vgoStorage, int meshInde return meshAsset; } - meshAsset.Materials = meshContext.MaterialIndices.Select(x => unityMaterialList[x]).ToArray(); + var materialList = unityMaterialList; + + meshAsset.Materials = meshContext.MaterialIndices.Select(x => materialList[x]).ToArray(); } if ((meshContext.BlendShapesContext != null) && @@ -235,7 +237,7 @@ protected virtual MeshAsset CreateMeshAsset(IVgoStorage vgoStorage, int meshInde /// List of mesh context. /// List of unity material. /// A mesh asset. - protected virtual MeshAsset CreateMeshAsset(IVgoStorage vgoStorage, int meshIndex, IList meshContextList, IList? unityMaterialList = null) + protected virtual MeshAsset CreateMeshAsset(in IVgoStorage vgoStorage, in int meshIndex, in IList meshContextList, in IList? unityMaterialList = null) { if (meshIndex.IsInRangeOf(meshContextList) == false) { @@ -257,7 +259,9 @@ protected virtual MeshAsset CreateMeshAsset(IVgoStorage vgoStorage, int meshInde return meshAsset; } - meshAsset.Materials = meshContext.MaterialIndices.Select(x => unityMaterialList[x]).ToArray(); + var materialList = unityMaterialList; + + meshAsset.Materials = meshContext.MaterialIndices.Select(x => materialList[x]).ToArray(); } if ((meshContext.BlendShapesContext != null) && @@ -420,9 +424,8 @@ protected virtual async Task> CreateMeshContextListParallelAsy /// /// A vgo storage. /// The index of vgo mesh. - /// A blend shape configuration. /// A mesh context. - protected virtual MeshContext ReadMesh(IVgoStorage vgoStorage, int meshIndex) + protected virtual MeshContext ReadMesh(in IVgoStorage vgoStorage, in int meshIndex) { if (vgoStorage.Layout.meshes == null) { @@ -511,7 +514,7 @@ protected virtual MeshContext ReadMesh(IVgoStorage vgoStorage, int meshIndex) /// A mesh context. /// The mesh primitive attributes. /// The count of positions. - protected virtual void SetPrimitiveAttributes(IVgoStorage vgoStorage, MeshContext meshContext, VgoMeshPrimitiveAttributes attributes, out int positionsCount) + protected virtual void SetPrimitiveAttributes(in IVgoStorage vgoStorage, MeshContext meshContext, in VgoMeshPrimitiveAttributes attributes, out int positionsCount) { positionsCount = 0; @@ -683,7 +686,7 @@ protected virtual void SetPrimitiveAttributes(IVgoStorage vgoStorage, MeshContex /// The accessor index of texture coord. /// The positions count. /// An array of UV. - protected virtual Vector2[]? ReadUV(IVgoStorage vgoStorage, int texcoord, int positionsCount) + protected virtual Vector2[]? ReadUV(in IVgoStorage vgoStorage, in int texcoord, in int positionsCount) { Vector2[]? uvs; @@ -731,7 +734,7 @@ protected virtual void SetPrimitiveAttributes(IVgoStorage vgoStorage, MeshContex /// The vgo subMesh accessor indices. /// /// List of blend shape. - protected virtual List? CreateSubMeshes(IVgoStorage vgoStorage, List? vgoSubMeshes, int positionsLength) + protected virtual List? CreateSubMeshes(in IVgoStorage vgoStorage, in List? vgoSubMeshes, in int positionsLength) { if ((vgoSubMeshes == null) || (vgoSubMeshes.Any() == false)) { @@ -768,7 +771,7 @@ protected virtual void SetPrimitiveAttributes(IVgoStorage vgoStorage, MeshContex /// A vgo storage. /// The index of accessor. /// The indices. - protected virtual int[] GetSubMeshIndices(IVgoStorage vgoStorage, int accessorIndex) + protected virtual int[] GetSubMeshIndices(in IVgoStorage vgoStorage, in int accessorIndex) { VgoResourceAccessor accessor = vgoStorage.GetAccessor(accessorIndex); @@ -837,7 +840,7 @@ protected virtual int[] GetSubMeshIndices(IVgoStorage vgoStorage, int accessorIn /// A vgo storage. /// List of vgo mesh blend shape. /// List of blend shapes context. - protected virtual BlendShapesContext? CreateBlendShapes(IVgoStorage vgoStorage, List? vgoMeshBlendShapes) + protected virtual BlendShapesContext? CreateBlendShapes(in IVgoStorage vgoStorage, in List? vgoMeshBlendShapes) { if ((vgoMeshBlendShapes == null) || (vgoMeshBlendShapes.Any() == false)) { @@ -929,8 +932,8 @@ protected virtual int[] GetSubMeshIndices(IVgoStorage vgoStorage, int accessorIn { var facePart = new BlendShapeFacePart { - index = shapeIndex, - type = vgoBlendShape.facePartsType, + Index = shapeIndex, + Type = vgoBlendShape.facePartsType, }; context.BlendShapeConfig.FaceParts.Add(facePart); @@ -940,8 +943,8 @@ protected virtual int[] GetSubMeshIndices(IVgoStorage vgoStorage, int accessorIn { var blink = new BlendShapeBlink { - index = shapeIndex, - type = vgoBlendShape.blinkType, + Index = shapeIndex, + Type = vgoBlendShape.blinkType, }; context.BlendShapeConfig.Blinks.Add(blink); @@ -951,8 +954,8 @@ protected virtual int[] GetSubMeshIndices(IVgoStorage vgoStorage, int accessorIn { var viseme = new BlendShapeViseme { - index = shapeIndex, - type = vgoBlendShape.visemeType, + Index = shapeIndex, + Type = vgoBlendShape.visemeType, }; context.BlendShapeConfig.Visemes.Add(viseme); @@ -1099,10 +1102,7 @@ protected virtual Mesh BuildMesh(MeshContext meshContext) } else { - if (emptyVertices == null) - { - emptyVertices = new Vector3[mesh.vertexCount]; - } + emptyVertices ??= new Vector3[mesh.vertexCount]; // add empty blend shape for keep blend shape index mesh.AddBlendShapeFrame(blendShape.Name, frameWeight: 100.0f, emptyVertices, deltaNormals: null, deltaTangents: null); @@ -1123,7 +1123,7 @@ protected virtual Mesh BuildMesh(MeshContext meshContext) /// A joint. /// A weight. /// A bone weight. - protected virtual BoneWeight ConvertJointAndWeightToBoneWeight(Vector4Ushort joint, Vector4 weight) + protected virtual BoneWeight ConvertJointAndWeightToBoneWeight(in Vector4Ushort joint, in Vector4 weight) { float sum = weight.x + weight.y + weight.z + weight.w; float f = 1.0f / sum; diff --git a/UniVgo2/Runtime/Porters/ParticleSystems/VgoParticleSystemExporter.cs b/UniVgo2/Runtime/Porters/ParticleSystems/VgoParticleSystemExporter.cs index 2d8fc2e..6642f89 100644 --- a/UniVgo2/Runtime/Porters/ParticleSystems/VgoParticleSystemExporter.cs +++ b/UniVgo2/Runtime/Porters/ParticleSystems/VgoParticleSystemExporter.cs @@ -28,7 +28,11 @@ public class VgoParticleSystemExporter : IVgoParticleSystemExporter /// /// /// - public virtual VgoParticleSystem Create(ParticleSystem particleSystem, ParticleSystemRenderer particleSystemRenderer, IVgoStorage vgoStorage, ExportTextureDelegate exportTexture) + public virtual VgoParticleSystem Create( + in ParticleSystem particleSystem, + in ParticleSystemRenderer particleSystemRenderer, + in IVgoStorage vgoStorage, + in ExportTextureDelegate exportTexture) { var vgoParticleSystem = new VgoParticleSystem() { @@ -70,7 +74,7 @@ public virtual VgoParticleSystem Create(ParticleSystem particleSystem, ParticleS /// /// /// - protected virtual VGO_PS_MainModule CreateVgoModule(MainModule module, VgoGeometryCoordinate geometryCoordinate) + protected virtual VGO_PS_MainModule CreateVgoModule(in MainModule module, in VgoGeometryCoordinate geometryCoordinate) { var vgoModule = new VGO_PS_MainModule() { @@ -91,7 +95,7 @@ protected virtual VGO_PS_MainModule CreateVgoModule(MainModule module, VgoGeomet gravityModifierMultiplier = module.gravityModifierMultiplier, simulationSpace = (NewtonVgo.ParticleSystemSimulationSpace)module.simulationSpace, simulationSpeed = module.simulationSpeed, - customSimulationSpace = VgoTransformConverter.CreateFrom(module.customSimulationSpace, geometryCoordinate), + customSimulationSpace = VgoTransformConverter.CreateOrDefaultFrom(module.customSimulationSpace, geometryCoordinate), useUnscaledTime = module.useUnscaledTime, scalingMode = (NewtonVgo.ParticleSystemScalingMode)module.scalingMode, playOnAwake = module.playOnAwake, @@ -145,7 +149,7 @@ protected virtual VGO_PS_MainModule CreateVgoModule(MainModule module, VgoGeomet /// /// /// - protected virtual VGO_PS_EmissionModule CreateVgoModule(EmissionModule module) + protected virtual VGO_PS_EmissionModule CreateVgoModule(in EmissionModule module) { var vgoModule = new VGO_PS_EmissionModule() { @@ -184,7 +188,7 @@ protected virtual VGO_PS_EmissionModule CreateVgoModule(EmissionModule module) /// /// /// - protected virtual VGO_PS_ShapeModule CreateVgoModule(ShapeModule module, IVgoStorage vgoStorage, ExportTextureDelegate exportTexture) + protected virtual VGO_PS_ShapeModule CreateVgoModule(in ShapeModule module, in IVgoStorage vgoStorage, in ExportTextureDelegate exportTexture) { var vgoShapeModule = new VGO_PS_ShapeModule() { @@ -248,7 +252,7 @@ protected virtual VGO_PS_ShapeModule CreateVgoModule(ShapeModule module, IVgoSto /// /// /// - protected virtual VGO_PS_VelocityOverLifetimeModule CreateVgoModule(VelocityOverLifetimeModule module) + protected virtual VGO_PS_VelocityOverLifetimeModule CreateVgoModule(in VelocityOverLifetimeModule module) { return new VGO_PS_VelocityOverLifetimeModule() { @@ -284,7 +288,7 @@ protected virtual VGO_PS_VelocityOverLifetimeModule CreateVgoModule(VelocityOver /// /// /// - protected virtual VGO_PS_LimitVelocityOverLifetimeModule CreateVgoModule(LimitVelocityOverLifetimeModule module) + protected virtual VGO_PS_LimitVelocityOverLifetimeModule CreateVgoModule(in LimitVelocityOverLifetimeModule module) { var vgoModule = new VGO_PS_LimitVelocityOverLifetimeModule() { @@ -321,7 +325,7 @@ protected virtual VGO_PS_LimitVelocityOverLifetimeModule CreateVgoModule(LimitVe /// /// /// - protected virtual VGO_PS_InheritVelocityModule CreateVgoModule(InheritVelocityModule module) + protected virtual VGO_PS_InheritVelocityModule CreateVgoModule(in InheritVelocityModule module) { return new VGO_PS_InheritVelocityModule() { @@ -358,7 +362,7 @@ protected virtual VGO_PS_ForceOverLifetimeModule CreateVgoModule(ForceOverLifeti /// /// /// - protected virtual VGO_PS_ColorOverLifetimeModule CreateVgoModule(ColorOverLifetimeModule module) + protected virtual VGO_PS_ColorOverLifetimeModule CreateVgoModule(in ColorOverLifetimeModule module) { return new VGO_PS_ColorOverLifetimeModule() { @@ -372,7 +376,7 @@ protected virtual VGO_PS_ColorOverLifetimeModule CreateVgoModule(ColorOverLifeti /// /// /// - protected virtual VGO_PS_ColorBySpeedModule CreateVgoModule(ColorBySpeedModule module) + protected virtual VGO_PS_ColorBySpeedModule CreateVgoModule(in ColorBySpeedModule module) { return new VGO_PS_ColorBySpeedModule() { @@ -387,7 +391,7 @@ protected virtual VGO_PS_ColorBySpeedModule CreateVgoModule(ColorBySpeedModule m /// /// /// - protected virtual VGO_PS_SizeOverLifetimeModule CreateVgoModule(SizeOverLifetimeModule module) + protected virtual VGO_PS_SizeOverLifetimeModule CreateVgoModule(in SizeOverLifetimeModule module) { if (module.separateAxes) { @@ -420,7 +424,7 @@ protected virtual VGO_PS_SizeOverLifetimeModule CreateVgoModule(SizeOverLifetime /// /// /// - protected virtual VGO_PS_SizeBySpeedModule CreateVgoModule(SizeBySpeedModule module) + protected virtual VGO_PS_SizeBySpeedModule CreateVgoModule(in SizeBySpeedModule module) { if (module.separateAxes) { @@ -455,7 +459,7 @@ protected virtual VGO_PS_SizeBySpeedModule CreateVgoModule(SizeBySpeedModule mod /// /// /// - protected virtual VGO_PS_RotationOverLifetimeModule CreateVgoModule(RotationOverLifetimeModule module) + protected virtual VGO_PS_RotationOverLifetimeModule CreateVgoModule(in RotationOverLifetimeModule module) { if (module.separateAxes) { @@ -488,7 +492,7 @@ protected virtual VGO_PS_RotationOverLifetimeModule CreateVgoModule(RotationOver /// /// /// - protected virtual VGO_PS_RotationBySpeedModule CreateVgoModule(RotationBySpeedModule module) + protected virtual VGO_PS_RotationBySpeedModule CreateVgoModule(in RotationBySpeedModule module) { if (module.separateAxes) { @@ -523,7 +527,7 @@ protected virtual VGO_PS_RotationBySpeedModule CreateVgoModule(RotationBySpeedMo /// /// /// - protected virtual VGO_PS_ExternalForcesModule CreateVgoModule(ExternalForcesModule module) + protected virtual VGO_PS_ExternalForcesModule CreateVgoModule(in ExternalForcesModule module) { return new VGO_PS_ExternalForcesModule() { @@ -599,14 +603,14 @@ protected virtual VGO_PS_NoiseModule CreateVgoModule(NoiseModule module) /// /// /// - protected virtual VGO_PS_LightsModule CreateVgoModule(LightsModule module) + protected virtual VGO_PS_LightsModule CreateVgoModule(in LightsModule module) { return new VGO_PS_LightsModule() { enabled = module.enabled, ratio = module.ratio, useRandomDistribution = module.useRandomDistribution, - light = VgoLightConverter.CreateFrom(module.light), + light = VgoLightConverter.CreateOrDefaultFrom(module.light), useParticleColor = module.useParticleColor, sizeAffectsRange = module.sizeAffectsRange, alphaAffectsIntensity = module.alphaAffectsIntensity, @@ -623,7 +627,7 @@ protected virtual VGO_PS_LightsModule CreateVgoModule(LightsModule module) /// /// /// - protected virtual VGO_PS_CollisionModule CreateVgoModule(CollisionModule module) + protected virtual VGO_PS_CollisionModule CreateVgoModule(in CollisionModule module) { #if NET_STANDARD_2_1 ThrowHelper.ThrowNotImplementedException(); @@ -639,7 +643,7 @@ protected virtual VGO_PS_CollisionModule CreateVgoModule(CollisionModule module) /// /// /// - protected virtual VGO_PS_TriggerModule CreateVgoModule(TriggerModule module) + protected virtual VGO_PS_TriggerModule CreateVgoModule(in TriggerModule module) { #if NET_STANDARD_2_1 ThrowHelper.ThrowNotImplementedException(); @@ -655,7 +659,7 @@ protected virtual VGO_PS_TriggerModule CreateVgoModule(TriggerModule module) /// /// /// - protected virtual VGO_PS_SubEmittersModule CreateVgoModule(SubEmittersModule module) + protected virtual VGO_PS_SubEmittersModule CreateVgoModule(in SubEmittersModule module) { #if NET_STANDARD_2_1 ThrowHelper.ThrowNotImplementedException(); @@ -671,7 +675,7 @@ protected virtual VGO_PS_SubEmittersModule CreateVgoModule(SubEmittersModule mod /// /// /// - protected virtual VGO_PS_TextureSheetAnimationModule CreateVgoModule(TextureSheetAnimationModule module) + protected virtual VGO_PS_TextureSheetAnimationModule CreateVgoModule(in TextureSheetAnimationModule module) { #if NET_STANDARD_2_1 ThrowHelper.ThrowNotImplementedException(); @@ -687,7 +691,7 @@ protected virtual VGO_PS_TextureSheetAnimationModule CreateVgoModule(TextureShee /// /// /// - protected virtual VGO_PS_TrailModule CreateVgoModule(TrailModule module) + protected virtual VGO_PS_TrailModule CreateVgoModule(in TrailModule module) { return new VGO_PS_TrailModule() { @@ -720,7 +724,7 @@ protected virtual VGO_PS_TrailModule CreateVgoModule(TrailModule module) /// /// /// - protected virtual VGO_PS_CustomDataModule CreateVgoModule(CustomDataModule module) + protected virtual VGO_PS_CustomDataModule CreateVgoModule(in CustomDataModule module) { #if NET_STANDARD_2_1 ThrowHelper.ThrowNotImplementedException(); @@ -738,7 +742,7 @@ protected virtual VGO_PS_CustomDataModule CreateVgoModule(CustomDataModule modul /// /// /// - protected virtual VGO_PS_Renderer CreateVgoPsRenderer(ParticleSystemRenderer particleSystemRenderer, VgoGeometryCoordinate geometryCoordinate, VgoLayout vgoLayout) + protected virtual VGO_PS_Renderer CreateVgoPsRenderer(in ParticleSystemRenderer particleSystemRenderer, in VgoGeometryCoordinate geometryCoordinate, in VgoLayout vgoLayout) { return new VGO_PS_Renderer() { @@ -771,7 +775,7 @@ protected virtual VGO_PS_Renderer CreateVgoPsRenderer(ParticleSystemRenderer par sortingOrder = particleSystemRenderer.sortingOrder, lightProbeUsage = (LightProbeUsage)particleSystemRenderer.lightProbeUsage, reflectionProbeUsage = (ReflectionProbeUsage)particleSystemRenderer.reflectionProbeUsage, - probeAnchor = VgoTransformConverter.CreateFrom(particleSystemRenderer.probeAnchor, geometryCoordinate), + probeAnchor = VgoTransformConverter.CreateOrDefaultFrom(particleSystemRenderer.probeAnchor, geometryCoordinate), }; } @@ -785,7 +789,7 @@ protected virtual VGO_PS_Renderer CreateVgoPsRenderer(ParticleSystemRenderer par /// /// /// - protected virtual int GetMaterialIndex(Material material, VgoLayout vgoLayout) + protected virtual int GetMaterialIndex(in Material material, in VgoLayout vgoLayout) { if (material == null) { @@ -797,7 +801,9 @@ protected virtual int GetMaterialIndex(Material material, VgoLayout vgoLayout) return -1; } - var vgoMaterial = vgoLayout.materials.FirstOrDefault(m => m?.name != null && m.name.Equals(material.name)); + var mat = material; + + var vgoMaterial = vgoLayout.materials.FirstOrDefault(m => m?.name != null && m.name.Equals(mat.name)); if (vgoMaterial == null) { diff --git a/UniVgo2/Runtime/Porters/ParticleSystems/VgoParticleSystemImporter.cs b/UniVgo2/Runtime/Porters/ParticleSystems/VgoParticleSystemImporter.cs index 14df38e..969fbff 100644 --- a/UniVgo2/Runtime/Porters/ParticleSystems/VgoParticleSystemImporter.cs +++ b/UniVgo2/Runtime/Porters/ParticleSystems/VgoParticleSystemImporter.cs @@ -30,7 +30,12 @@ public class VgoParticleSystemImporter : IVgoParticleSystemImporter /// /// /// Returns ParticleSystem component. - public virtual ParticleSystem AddComponent(GameObject go, VgoParticleSystem vgoParticleSystem, VgoGeometryCoordinate geometryCoordinate, IList? materialList, IList? texture2dList) + public virtual ParticleSystem AddComponent( + GameObject go, + in VgoParticleSystem vgoParticleSystem, + in VgoGeometryCoordinate geometryCoordinate, + in IList? materialList, + in IList? texture2dList) { if (go.TryGetComponentEx(out var particleSystem) == false) { @@ -142,7 +147,7 @@ public virtual ParticleSystem AddComponent(GameObject go, VgoParticleSystem vgoP /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_MainModule vgoModule, VgoGeometryCoordinate geometryCoordinate) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_MainModule vgoModule, in VgoGeometryCoordinate geometryCoordinate) { if (vgoModule == null) { @@ -233,7 +238,7 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Main /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_EmissionModule vgoModule) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_EmissionModule vgoModule) { if (vgoModule == null) { @@ -267,7 +272,7 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Emis /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_ShapeModule vgoModule, IList? texture2dList, VgoGeometryCoordinate geometryCoordinate) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_ShapeModule vgoModule, in IList? texture2dList, in VgoGeometryCoordinate geometryCoordinate) { if (vgoModule == null) { @@ -334,7 +339,7 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Shap /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_VelocityOverLifetimeModule vgoModule) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_VelocityOverLifetimeModule vgoModule) { if (vgoModule == null) { @@ -380,7 +385,7 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Velo /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_LimitVelocityOverLifetimeModule vgoModule) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_LimitVelocityOverLifetimeModule vgoModule) { if (vgoModule == null) { @@ -419,8 +424,8 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Limi /// Set ParticleSystem inhelitVelocity field value. /// /// - /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_InheritVelocityModule vgoModule) + /// + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_InheritVelocityModule vgoModule) { if (vgoModule == null) { @@ -440,7 +445,7 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Inhe /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_ForceOverLifetimeModule vgoModule) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_ForceOverLifetimeModule vgoModule) { if (vgoModule == null) { @@ -465,7 +470,7 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Forc /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_ColorOverLifetimeModule vgoModule) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_ColorOverLifetimeModule vgoModule) { if (vgoModule == null) { @@ -483,7 +488,7 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Colo /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_ColorBySpeedModule vgoModule) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_ColorBySpeedModule vgoModule) { if (vgoModule == null) { @@ -502,7 +507,7 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Colo /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_SizeOverLifetimeModule vgoModule) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_SizeOverLifetimeModule vgoModule) { if (vgoModule == null) { @@ -535,7 +540,7 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Size /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_SizeBySpeedModule vgoModule) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_SizeBySpeedModule vgoModule) { if (vgoModule == null) { @@ -570,7 +575,7 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Size /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_RotationOverLifetimeModule vgoModule) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_RotationOverLifetimeModule vgoModule) { if (vgoModule == null) { @@ -603,7 +608,7 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Rota /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_RotationBySpeedModule vgoModule) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_RotationBySpeedModule vgoModule) { if (vgoModule == null) { @@ -638,7 +643,7 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Rota /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_ExternalForcesModule vgoModule) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_ExternalForcesModule vgoModule) { if (vgoModule == null) { @@ -659,7 +664,7 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Exte /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_NoiseModule vgoModule) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_NoiseModule vgoModule) { if (vgoModule == null) { @@ -724,7 +729,7 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Nois /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_CollisionModule vgoModule) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_CollisionModule vgoModule) { ThrowHelper.ThrowNotImplementedException(); } @@ -734,7 +739,7 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Coll /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_TriggerModule vgoModule) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_TriggerModule vgoModule) { ThrowHelper.ThrowNotImplementedException(); } @@ -744,7 +749,7 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Trig /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_SubEmittersModule vgoModule) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_SubEmittersModule vgoModule) { ThrowHelper.ThrowNotImplementedException(); } @@ -754,7 +759,7 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_SubE /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_TextureSheetAnimationModule vgoModule) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_TextureSheetAnimationModule vgoModule) { ThrowHelper.ThrowNotImplementedException(); } @@ -764,7 +769,7 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Text /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_LightsModule vgoModule) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_LightsModule vgoModule) { if (vgoModule == null) { @@ -811,7 +816,7 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Ligh /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_TrailModule vgoModule) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_TrailModule vgoModule) { if (vgoModule == null) { @@ -853,7 +858,7 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Trai /// /// /// - protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_CustomDataModule vgoModule) + protected virtual void SetModuleValue(ParticleSystem particleSystem, in VGO_PS_CustomDataModule vgoModule) { ThrowHelper.ThrowNotImplementedException(); } @@ -869,7 +874,11 @@ protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_Cust /// /// /// - public virtual void SetComponentValue(ParticleSystemRenderer particleSystemRenderer, VGO_PS_Renderer vgoRenderer, VgoGeometryCoordinate geometryCoordinate, IList? materialList) + public virtual void SetComponentValue( + ParticleSystemRenderer particleSystemRenderer, + in VGO_PS_Renderer vgoRenderer, + in VgoGeometryCoordinate geometryCoordinate, + in IList? materialList) { if (vgoRenderer == null) { @@ -949,7 +958,7 @@ public virtual void SetComponentValue(ParticleSystemRenderer particleSystemRende /// /// /// - protected virtual void SetVertexStream(ParticleSystemRenderer particleSystemRenderer, Material material) + protected virtual void SetVertexStream(ParticleSystemRenderer particleSystemRenderer, in Material material) { bool useLighting = (material.GetFloat(UniParticleShader.Property.LightingEnabled) > 0.0f); bool useFlipbookBlending = (material.GetFloat(UniParticleShader.Property.FlipbookMode) > 0.0f); diff --git a/UniVgo2/Runtime/Porters/Textures/VgoTextureExporter.cs b/UniVgo2/Runtime/Porters/Textures/VgoTextureExporter.cs index ad211f3..948b229 100644 --- a/UniVgo2/Runtime/Porters/Textures/VgoTextureExporter.cs +++ b/UniVgo2/Runtime/Porters/Textures/VgoTextureExporter.cs @@ -61,7 +61,12 @@ public VgoTextureExporter() /// The color space type of image. /// The metallic-roughness value. /// The index of layout.texture. - protected virtual int ExportTexture(IVgoStorage vgoStorage, Texture texture, VgoTextureMapType textureMapType = VgoTextureMapType.Default, VgoColorSpaceType colorSpaceType = VgoColorSpaceType.Srgb, float metallicRoughness = -1.0f) + protected virtual int ExportTexture( + IVgoStorage vgoStorage, + Texture texture, + in VgoTextureMapType textureMapType = VgoTextureMapType.Default, + in VgoColorSpaceType colorSpaceType = VgoColorSpaceType.Srgb, + in float metallicRoughness = -1.0f) { if (texture == null) { diff --git a/UniVgo2/Runtime/Porters/Textures/VgoTextureImporter.cs b/UniVgo2/Runtime/Porters/Textures/VgoTextureImporter.cs index ccb2ee2..050347c 100644 --- a/UniVgo2/Runtime/Porters/Textures/VgoTextureImporter.cs +++ b/UniVgo2/Runtime/Porters/Textures/VgoTextureImporter.cs @@ -52,7 +52,7 @@ public VgoTextureImporter() /// /// A vgo storage. /// List of unity texture2D. - public virtual List CreateTextureAssets(IVgoStorage vgoStorage) + public virtual List CreateTextureAssets(in IVgoStorage vgoStorage) { if ((vgoStorage.Layout.textures == null) || (vgoStorage.Layout.textures.Any() == false)) { @@ -154,7 +154,7 @@ public VgoTextureImporter() /// A vgo texture. /// A vgo storage. /// A unity texture 2D. - protected virtual Texture2D? CreateTexture2D(VgoTexture vgoTexture, IVgoStorage vgoStorage) + protected virtual Texture2D? CreateTexture2D(in VgoTexture vgoTexture, in IVgoStorage vgoStorage) { if (vgoStorage.ResourceAccessors is null) { diff --git a/UniVgo2/Runtime/Porters/VgoExporter.cs b/UniVgo2/Runtime/Porters/VgoExporter.cs index 6c10678..cd47796 100644 --- a/UniVgo2/Runtime/Porters/VgoExporter.cs +++ b/UniVgo2/Runtime/Porters/VgoExporter.cs @@ -49,7 +49,7 @@ public VgoExporter() : this(new VgoExporterOption()) { } /// Create a new instance of VgoExporter with option. /// /// The vgo exporter option. - public VgoExporter(VgoExporterOption option) + public VgoExporter(in VgoExporterOption option) { _Option = option; @@ -61,7 +61,7 @@ public VgoExporter(VgoExporterOption option) ExportTexture = _TextureExporter.ExportTextureDelegate }; - _MeshExporter = new VgoMeshExporter(new MeshExporterOption()); + _MeshExporter = new VgoMeshExporter(_Option.MeshExporterOption); _ParticleSystemExporter = new VgoParticleSystemExporter(); } @@ -79,16 +79,16 @@ public VgoExporter(VgoExporterOption option) /// /// A vgo storage. public virtual IVgoStorage CreateVgoStorage( - GameObject root, - VgoGeometryCoordinate geometryCoordinate = VgoGeometryCoordinate.RightHanded, - VgoUVCoordinate uvCoordinate = VgoUVCoordinate.TopLeft, - ImageType textureType = ImageType.PNG) + in GameObject root, + in VgoGeometryCoordinate geometryCoordinate = VgoGeometryCoordinate.RightHanded, + in VgoUVCoordinate uvCoordinate = VgoUVCoordinate.TopLeft, + in ImageType textureType = ImageType.PNG) { _TextureExporter.TextureType = textureType; - int initialResourceSize = 10 * 1024 * 1024; // 10MB + int initialResourceCapacity = 10 * 1024 * 1024; // 10MB - IByteBuffer resource = new ArraySegmentByteBuffer(initialResourceSize); + IByteBuffer resource = new ArraySegmentByteBuffer(initialResourceCapacity); IVgoStorage vgoStorage = new VgoStorage(resource, geometryCoordinate, uvCoordinate); @@ -135,7 +135,14 @@ public virtual IVgoStorage CreateVgoStorage( finally { #if UNITY_EDITOR - GameObject.DestroyImmediate(copy); + if (Application.isPlaying) + { + GameObject.Destroy(copy); + } + else + { + GameObject.DestroyImmediate(copy); + } #else GameObject.Destroy(copy); #endif @@ -153,7 +160,7 @@ public virtual IVgoStorage CreateVgoStorage( /// /// A vgo storage. /// A model asset. - protected virtual void SetVgoAssetInfo(IVgoStorage vgoStorage, ExportModelAsset modelAsset) + protected virtual void SetVgoAssetInfo(IVgoStorage vgoStorage, in ExportModelAsset modelAsset) { vgoStorage.AssetInfo = new VgoAssetInfo { @@ -183,7 +190,7 @@ protected virtual void SetVgoAssetInfo(IVgoStorage vgoStorage, ExportModelAsset /// A vgo layout. /// A model asset. /// - protected virtual void CreateVgoColliders(VgoLayout vgoLayout, ExportModelAsset modelAsset, VgoGeometryCoordinate geometryCoordinate) + protected virtual void CreateVgoColliders(VgoLayout vgoLayout, in ExportModelAsset modelAsset, in VgoGeometryCoordinate geometryCoordinate) { if (modelAsset.ColliderList == null) { @@ -229,7 +236,7 @@ protected virtual void CreateVgoColliders(VgoLayout vgoLayout, ExportModelAsset /// /// A vgo storage. /// A model asset. - protected virtual void CreateVgoMaterialsAndExportTextures(IVgoStorage vgoStorage, ExportModelAsset modelAsset) + protected virtual void CreateVgoMaterialsAndExportTextures(IVgoStorage vgoStorage, in ExportModelAsset modelAsset) { if (modelAsset.MaterialList == null) { @@ -269,7 +276,7 @@ protected virtual void CreateVgoMaterialsAndExportTextures(IVgoStorage vgoStorag /// /// A vgo storage. /// A model asset. - protected virtual void CreateVgoMeshes(IVgoStorage vgoStorage, ExportModelAsset modelAsset) + protected virtual void CreateVgoMeshes(IVgoStorage vgoStorage, in ExportModelAsset modelAsset) { if (modelAsset.MeshAssetList == null) { @@ -290,7 +297,7 @@ protected virtual void CreateVgoMeshes(IVgoStorage vgoStorage, ExportModelAsset /// /// A vgo storage. /// A model asset. - protected virtual void CreateVgoSkins(IVgoStorage vgoStorage, ExportModelAsset modelAsset) + protected virtual void CreateVgoSkins(IVgoStorage vgoStorage, in ExportModelAsset modelAsset) { if (modelAsset.SkinnedMeshRendererList == null) { @@ -377,7 +384,7 @@ protected virtual void CreateVgoSkins(IVgoStorage vgoStorage, ExportModelAsset m /// A vgo storage. /// A model asset. /// - protected virtual void CreateVgoNodes(IVgoStorage vgoStorage, ExportModelAsset modelAsset, VgoGeometryCoordinate geometryCoordinate) + protected virtual void CreateVgoNodes(IVgoStorage vgoStorage, in ExportModelAsset modelAsset, in VgoGeometryCoordinate geometryCoordinate) { if (modelAsset.TransformList == null) { @@ -418,7 +425,7 @@ protected virtual void CreateVgoNodes(IVgoStorage vgoStorage, ExportModelAsset m /// A model asset. /// /// A layout.node. - protected virtual VgoNode CreateVgoNode(int nodeIndex, IVgoStorage vgoStorage, ExportModelAsset modelAsset, VgoGeometryCoordinate geometryCoordinate) + protected virtual VgoNode CreateVgoNode(in int nodeIndex, in IVgoStorage vgoStorage, in ExportModelAsset modelAsset, in VgoGeometryCoordinate geometryCoordinate) { GameObject gameObject = modelAsset.TransformList[nodeIndex].gameObject; @@ -462,8 +469,10 @@ protected virtual VgoNode CreateVgoNode(int nodeIndex, IVgoStorage vgoStorage, E // Colliders if (gameObject.TryGetComponentsEx(out Collider[] colliders)) { + var colliderList = modelAsset.ColliderList; + vgoNode.colliders = colliders - .Select(collider => modelAsset.ColliderList.IndexOf(collider)) + .Select(collider => colliderList.IndexOf(collider)) .Where(index => index != -1) .ToList(); } @@ -533,20 +542,22 @@ protected virtual VgoNode CreateVgoNode(int nodeIndex, IVgoStorage vgoStorage, E ThrowHelper.ThrowIndexOutOfRangeException(nameof(meshIndex), meshIndex, min: 0, max: modelAsset.MeshList.Count); } + var materialList = modelAsset.MaterialList; + var vgoMeshRenderer = new VgoMeshRenderer() { name = renderer.name, enabled = renderer.enabled, mesh = meshIndex, - materials = renderer.sharedMaterials.Select(m => modelAsset.MaterialList.IndexOf(m)).ToList(), + materials = renderer.sharedMaterials.Select(m => materialList.IndexOf(m)).ToList(), }; if (gameObject.TryGetComponentEx(out VgoBlendShape vgoBlendShapeComponent)) { if (vgoBlendShapeComponent.BlendShapeConfiguration != null) { - vgoMeshRenderer.blendShapeKind = vgoBlendShapeComponent.BlendShapeConfiguration.kind; - vgoMeshRenderer.blendShapePesets = vgoBlendShapeComponent.BlendShapeConfiguration.presets; + vgoMeshRenderer.blendShapeKind = vgoBlendShapeComponent.BlendShapeConfiguration.Kind; + vgoMeshRenderer.blendShapePesets = vgoBlendShapeComponent.BlendShapeConfiguration.Presets; } } @@ -648,7 +659,7 @@ protected virtual VgoNode CreateVgoNode(int nodeIndex, IVgoStorage vgoStorage, E /// /// A vgo storage. /// A model asset. - protected virtual void ExportNodeTransforms(IVgoStorage vgoStorage, ExportModelAsset modelAsset) + protected virtual void ExportNodeTransforms(IVgoStorage vgoStorage, in ExportModelAsset modelAsset) { if (modelAsset.TransformList == null) { @@ -694,7 +705,7 @@ protected virtual void ExportNodeTransforms(IVgoStorage vgoStorage, ExportModelA /// A vgo layout. /// A model asset. /// - protected virtual void CreateVgoAnimationClips(VgoLayout vgoLayout, ExportModelAsset modelAsset, VgoGeometryCoordinate geometryCoordinate) + protected virtual void CreateVgoAnimationClips(VgoLayout vgoLayout, in ExportModelAsset modelAsset, in VgoGeometryCoordinate geometryCoordinate) { if (modelAsset.AnimationClipList == null) { @@ -731,7 +742,7 @@ protected virtual void CreateVgoAnimationClips(VgoLayout vgoLayout, ExportModelA /// /// A vgo storage. /// A model asset. - protected virtual void CreateVgoClothes(IVgoStorage vgoStorage, ExportModelAsset modelAsset) + protected virtual void CreateVgoClothes(IVgoStorage vgoStorage, in ExportModelAsset modelAsset) { if (modelAsset.ClothList == null) { @@ -766,7 +777,7 @@ protected virtual void CreateVgoClothes(IVgoStorage vgoStorage, ExportModelAsset /// /// A vgo layout. /// A model asset. - protected virtual void CreateVgoLights(VgoLayout vgoLayout, ExportModelAsset modelAsset) + protected virtual void CreateVgoLights(VgoLayout vgoLayout, in ExportModelAsset modelAsset) { if (modelAsset.LightList == null) { @@ -802,7 +813,7 @@ protected virtual void CreateVgoLights(VgoLayout vgoLayout, ExportModelAsset mod /// A vgo storage. /// A model asset. /// - protected virtual void CreateVgoParticlesAndExportTextures(IVgoStorage vgoStorage, ExportModelAsset modelAsset, VgoGeometryCoordinate geometryCoordinate) + protected virtual void CreateVgoParticlesAndExportTextures(IVgoStorage vgoStorage, in ExportModelAsset modelAsset, in VgoGeometryCoordinate geometryCoordinate) { if (modelAsset.ParticleSystemAssetList == null) { @@ -847,7 +858,7 @@ protected virtual void CreateVgoParticlesAndExportTextures(IVgoStorage vgoStorag /// A vgo layout. /// A model asset. /// - protected virtual void CreateSpringBoneInfo(VgoLayout vgoLayout, ExportModelAsset modelAsset, VgoGeometryCoordinate geometryCoordinate) + protected virtual void CreateSpringBoneInfo(VgoLayout vgoLayout, in ExportModelAsset modelAsset, in VgoGeometryCoordinate geometryCoordinate) { if (((modelAsset.VgoSpringBoneGroupList == null) || modelAsset.VgoSpringBoneGroupList.Any() == false) && ((modelAsset.VgoSpringBoneColliderGroupList == null) || modelAsset.VgoSpringBoneColliderGroupList.Any() == false)) diff --git a/UniVgo2/Runtime/Porters/VgoImporter.cs b/UniVgo2/Runtime/Porters/VgoImporter.cs index bbb8664..d839a61 100644 --- a/UniVgo2/Runtime/Porters/VgoImporter.cs +++ b/UniVgo2/Runtime/Porters/VgoImporter.cs @@ -48,7 +48,7 @@ public VgoImporter() : this(new VgoImporterOption()) { } /// Create a new instance of VgoImporter with option. /// /// The vgo importer option. - public VgoImporter(VgoImporterOption option) + public VgoImporter(in VgoImporterOption option) { _Option = option; @@ -75,7 +75,7 @@ public VgoImporter(VgoImporterOption option) /// The file path of the vgo. /// The file path of the crypt key. /// A vgo model asset. - public virtual VgoModelAsset Load(string vgoFilePath, string? vgkFilePath = null) + public virtual VgoModelAsset Load(in string vgoFilePath, in string? vgkFilePath = null) { var vgoStorage = new VgoStorage(vgoFilePath, vgkFilePath); @@ -88,7 +88,7 @@ public virtual VgoModelAsset Load(string vgoFilePath, string? vgkFilePath = null /// The vgo bytes. /// The vgk bytes. /// A vgo model asset. - public virtual VgoModelAsset Load(byte[] vgoBytes, byte[]? vgkBytes = null) + public virtual VgoModelAsset Load(in byte[] vgoBytes, in byte[]? vgkBytes = null) { var vgoStorage = new VgoStorage(vgoBytes, vgkBytes); @@ -100,7 +100,7 @@ public virtual VgoModelAsset Load(byte[] vgoBytes, byte[]? vgkBytes = null) /// /// A vgo storage. /// A vgo model asset. - public virtual VgoModelAsset Load(IVgoStorage vgoStorage) + public virtual VgoModelAsset Load(in IVgoStorage vgoStorage) { var vgoModelAsset = new VgoModelAsset(); @@ -154,7 +154,7 @@ public virtual VgoModelAsset Load(IVgoStorage vgoStorage) /// The file path of the vgk. /// A vgo model asset. /// for ScriptedImporter - public virtual VgoModelAsset Extract(string vgoFilePath, string? vgkFilePath = null) + public virtual VgoModelAsset Extract(in string vgoFilePath, in string? vgkFilePath = null) { var vgoStorage = new VgoStorage(vgoFilePath, vgkFilePath); @@ -181,7 +181,7 @@ public virtual VgoModelAsset Extract(string vgoFilePath, string? vgkFilePath = n /// A vgo storage. /// List of unity texture 2D. /// List of unity material. - protected virtual List CreateMaterialAssets(IVgoStorage vgoStorage, List texture2dList) + protected virtual List CreateMaterialAssets(in IVgoStorage vgoStorage, in List texture2dList) { var materialList = new List(); @@ -218,7 +218,7 @@ public virtual VgoModelAsset Extract(string vgoFilePath, string? vgkFilePath = n /// /// A vgo layout. /// An array of vgo spring bone collider group. - protected virtual VgoSpringBone.VgoSpringBoneColliderGroup[]? CreateSpringBoneColliderGroupArray(VgoLayout vgoLayout) + protected virtual VgoSpringBone.VgoSpringBoneColliderGroup[]? CreateSpringBoneColliderGroupArray(in VgoLayout vgoLayout) { if (vgoLayout.springBoneInfo == null) { @@ -247,7 +247,7 @@ public virtual VgoModelAsset Extract(string vgoFilePath, string? vgkFilePath = n /// /// A vgo storage. /// List of transform. - protected virtual List CreateNodes(IVgoStorage vgoStorage) + protected virtual List CreateNodes(in IVgoStorage vgoStorage) { if (vgoStorage.Layout.nodes is null) { @@ -296,7 +296,7 @@ protected virtual List CreateNodes(IVgoStorage vgoStorage) /// /// List of node. /// A vgo layout. - protected virtual void CreateNodeHierarchy(List nodes, VgoLayout vgoLayout) + protected virtual void CreateNodeHierarchy(List nodes, in VgoLayout vgoLayout) { if (vgoLayout.nodes is null) { @@ -365,7 +365,7 @@ protected virtual void FixCoordinate(List nodes) /// List of node. /// A vgo storage. /// A vgo model asset. - protected virtual void SetupNodes(List nodes, IVgoStorage vgoStorage, VgoModelAsset vgoModelAsset) + protected virtual void SetupNodes(List nodes, in IVgoStorage vgoStorage, VgoModelAsset vgoModelAsset) { if (vgoStorage.Layout.nodes is null) { @@ -426,7 +426,12 @@ protected virtual void SetupNodes(List nodes, IVgoStorage vgoStorage, /// A vgo layout. /// /// A vgo model asset. - protected virtual void SetupNode(List nodes, int nodeIndex, VgoLayout vgoLayout, VgoGeometryCoordinate geometryCoordinate, VgoModelAsset vgoModelAsset) + protected virtual void SetupNode( + List nodes, + in int nodeIndex, + in VgoLayout vgoLayout, + in VgoGeometryCoordinate geometryCoordinate, + VgoModelAsset vgoModelAsset) { if (vgoLayout.nodes is null) { @@ -674,7 +679,12 @@ protected virtual void SetupNode(List nodes, int nodeIndex, VgoLayout /// A vgo layout. /// /// A vgo model asset. - protected virtual void SetupNodeSpringBone(List nodes, int nodeIndex, VgoLayout vgoLayout, VgoGeometryCoordinate geometryCoordinate, VgoModelAsset vgoModelAsset) + protected virtual void SetupNodeSpringBone( + List nodes, + in int nodeIndex, + in VgoLayout vgoLayout, + in VgoGeometryCoordinate geometryCoordinate, + VgoModelAsset vgoModelAsset) { if (vgoLayout.nodes is null) { @@ -772,7 +782,7 @@ protected virtual void SetupNodeSpringBone(List nodes, int nodeIndex, /// The index of layout.nodes. /// A vgo storage. /// List of collider. - protected virtual void SetupNodeCloth(List nodes, int nodeIndex, IVgoStorage vgoStorage, List colliderList) + protected virtual void SetupNodeCloth(List nodes, in int nodeIndex, in IVgoStorage vgoStorage, in List colliderList) { if (vgoStorage.Layout.nodes is null) { @@ -822,7 +832,7 @@ protected virtual void SetupNodeCloth(List nodes, int nodeIndex, IVgo /// /// VgoExporter.CreateUnityColliderList is same logic. /// - protected virtual List CreateUnityColliderList(List nodes) + protected virtual List CreateUnityColliderList(in List nodes) { var colliderList = new List(); @@ -853,10 +863,17 @@ protected virtual void SetupNodeCloth(List nodes, int nodeIndex, IVgo /// /// List of node. /// The index of layout.node. + /// A vgo storage. /// A vgo model asset. /// Whether show mesh renderer. /// Whether update skinned mesh renderer when off screen. - protected virtual void AttachMeshAndRenderer(List nodes, int nodeIndex, IVgoStorage vgoStorage, VgoModelAsset vgoModelAsset, bool showMesh = true, bool updateWhenOffscreen = false) + protected virtual void AttachMeshAndRenderer( + List nodes, + in int nodeIndex, + in IVgoStorage vgoStorage, + VgoModelAsset vgoModelAsset, + in bool showMesh = true, + in bool updateWhenOffscreen = false) { if (vgoStorage.Layout.nodes is null) { @@ -931,12 +948,12 @@ protected virtual void AttachMeshAndRenderer(List nodes, int nodeInde BlendShapeConfiguration blendShapeConfiguration = ScriptableObject.CreateInstance(); - blendShapeConfiguration.name = meshAsset.BlendShapeConfig.Name; - blendShapeConfiguration.kind = meshAsset.BlendShapeConfig.Kind; - blendShapeConfiguration.faceParts = meshAsset.BlendShapeConfig.FaceParts; - blendShapeConfiguration.blinks = meshAsset.BlendShapeConfig.Blinks; - blendShapeConfiguration.visemes = meshAsset.BlendShapeConfig.Visemes; - blendShapeConfiguration.presets = meshAsset.BlendShapeConfig.Presets; + blendShapeConfiguration.Name = meshAsset.BlendShapeConfig.Name ?? string.Empty; + blendShapeConfiguration.Kind = meshAsset.BlendShapeConfig.Kind; + blendShapeConfiguration.FaceParts = meshAsset.BlendShapeConfig.FaceParts; + blendShapeConfiguration.Blinks = meshAsset.BlendShapeConfig.Blinks; + blendShapeConfiguration.Visemes = meshAsset.BlendShapeConfig.Visemes; + blendShapeConfiguration.Presets = meshAsset.BlendShapeConfig.Presets; vgoBlendShape.BlendShapeConfiguration = blendShapeConfiguration; @@ -963,8 +980,10 @@ protected virtual void AttachMeshAndRenderer(List nodes, int nodeInde vgoModelAsset.MaterialList != null && vgoModelAsset.MaterialList.Any()) { + var materialList = vgoModelAsset.MaterialList; + materials = vgoMeshRenderer.materials - .Select(materialIndex => vgoModelAsset.MaterialList[materialIndex]) + .Select(materialIndex => materialList[materialIndex]) .ToArray(); } @@ -1034,18 +1053,18 @@ protected virtual void AttachMeshAndRenderer(List nodes, int nodeInde BlendShapeConfiguration blendShapeConfiguration = ScriptableObject.CreateInstance(); - blendShapeConfiguration.name = meshAsset.BlendShapeConfig.Name; + blendShapeConfiguration.Name = meshAsset.BlendShapeConfig.Name ?? string.Empty; - blendShapeConfiguration.kind = vgoMeshRenderer.blendShapeKind.Value; + blendShapeConfiguration.Kind = vgoMeshRenderer.blendShapeKind.Value; - blendShapeConfiguration.faceParts = meshAsset.BlendShapeConfig.FaceParts; - blendShapeConfiguration.blinks = meshAsset.BlendShapeConfig.Blinks; - blendShapeConfiguration.visemes = meshAsset.BlendShapeConfig.Visemes; + blendShapeConfiguration.FaceParts = meshAsset.BlendShapeConfig.FaceParts; + blendShapeConfiguration.Blinks = meshAsset.BlendShapeConfig.Blinks; + blendShapeConfiguration.Visemes = meshAsset.BlendShapeConfig.Visemes; if (vgoMeshRenderer.blendShapePesets != null && vgoMeshRenderer.blendShapePesets.Any()) { - blendShapeConfiguration.presets.AddRange(vgoMeshRenderer.blendShapePesets); + blendShapeConfiguration.Presets.AddRange(vgoMeshRenderer.blendShapePesets); } vgoBlendShape.BlendShapeConfiguration = blendShapeConfiguration; @@ -1071,7 +1090,7 @@ protected virtual void AttachMeshAndRenderer(List nodes, int nodeInde /// The index of gltf.skin. /// List of node. /// A vgo storage. - protected virtual void SetupSkin(SkinnedMeshRenderer skinnedMeshRenderer, int skinIndex, List nodes, IVgoStorage vgoStorage) + protected virtual void SetupSkin(SkinnedMeshRenderer skinnedMeshRenderer, in int skinIndex, in List nodes, in IVgoStorage vgoStorage) { if (skinnedMeshRenderer.sharedMesh == null) { @@ -1189,7 +1208,7 @@ protected virtual void SetupSkin(SkinnedMeshRenderer skinnedMeshRenderer, int sk /// A vgo layout. /// /// List of unity animation clip. - protected virtual List CreateAnimationClipAssets(VgoLayout vgoLayout, VgoGeometryCoordinate geometryCoordinate) + protected virtual List CreateAnimationClipAssets(in VgoLayout vgoLayout, in VgoGeometryCoordinate geometryCoordinate) { var animationClipList = new List(); @@ -1219,7 +1238,7 @@ protected virtual void SetupSkin(SkinnedMeshRenderer skinnedMeshRenderer, int sk /// /// A vgo storage. /// A vgo model asset. - protected virtual void SetupAssetInfo(IVgoStorage vgoStorage, VgoModelAsset vgoModelAsset) + protected virtual void SetupAssetInfo(in IVgoStorage vgoStorage, VgoModelAsset vgoModelAsset) { if (vgoStorage.AssetInfo == null) { @@ -1285,12 +1304,12 @@ public virtual void ReflectSkybox(Camera camera, VgoModelAsset vgoModelAsset) /// Create and add avatar configuration. /// /// The vgo human avatar. - protected virtual AvatarConfiguration CreateAvatarConfiguration(VgoHumanAvatar vgoHumanAvatar) + protected virtual AvatarConfiguration CreateAvatarConfiguration(in VgoHumanAvatar vgoHumanAvatar) { var avatarConfiguration = ScriptableObject.CreateInstance(); - avatarConfiguration.name = vgoHumanAvatar.name; - avatarConfiguration.humanBones = vgoHumanAvatar.humanBones + avatarConfiguration.Name = vgoHumanAvatar.name ?? string.Empty; + avatarConfiguration.HumanBones = vgoHumanAvatar.humanBones .Where(x => x != null) .Select(x => x!) .ToList(); @@ -1303,9 +1322,9 @@ protected virtual AvatarConfiguration CreateAvatarConfiguration(VgoHumanAvatar v /// /// A vgo storage. /// An array of matrix. - protected virtual System.Numerics.Matrix4x4[] GetVgoNodeTransforms(IVgoStorage vgoStorage) + protected virtual System.Numerics.Matrix4x4[] GetVgoNodeTransforms(in IVgoStorage vgoStorage) { - if (vgoStorage.ResourceAccessors.Where(x => x.kind == VgoResourceAccessorKind.NodeTransform).Count() != 1) + if (vgoStorage.ResourceAccessors.Count(x => x.kind == VgoResourceAccessorKind.NodeTransform) != 1) { #if NET_STANDARD_2_1 ThrowHelper.ThrowException(); @@ -1323,7 +1342,7 @@ protected virtual System.Numerics.Matrix4x4[] GetVgoNodeTransforms(IVgoStorage v #endif } - VgoResourceAccessor accessor = vgoStorage.ResourceAccessors.Where(x => x.kind == VgoResourceAccessorKind.NodeTransform).First(); + VgoResourceAccessor accessor = vgoStorage.ResourceAccessors.First(x => x.kind == VgoResourceAccessorKind.NodeTransform); ArraySegment transformBytes = vgoStorage.GetAccessorBytes(accessor); diff --git a/UniVgo2/Runtime/Shaders/IShaderStore.cs b/UniVgo2/Runtime/Shaders/IShaderStore.cs index 1c20345..12f967a 100644 --- a/UniVgo2/Runtime/Shaders/IShaderStore.cs +++ b/UniVgo2/Runtime/Shaders/IShaderStore.cs @@ -20,7 +20,7 @@ public interface IShaderStore /// /// The vgo material. /// - Shader? GetShaderOrDefault(VgoMaterial vgoMaterial); + Shader? GetShaderOrDefault(in VgoMaterial vgoMaterial); /// /// Get a shader or standard. @@ -28,7 +28,7 @@ public interface IShaderStore /// The vgo material. /// Type of render pipeline. /// - Shader GetShaderOrStandard(VgoMaterial vgoMaterial, RenderPipelineType renderPipelineType); + Shader GetShaderOrStandard(in VgoMaterial vgoMaterial, in RenderPipelineType renderPipelineType); ///// ///// Try get a shader. @@ -36,7 +36,7 @@ public interface IShaderStore ///// ///// ///// - //bool TryGetShader(MaterialInfo materialInfo, out Shader shader); + //bool TryGetShader(in MaterialInfo materialInfo, out Shader shader); #endregion } diff --git a/UniVgo2/Runtime/Shaders/ShaderStore.cs b/UniVgo2/Runtime/Shaders/ShaderStore.cs index e3bb769..b36fefb 100644 --- a/UniVgo2/Runtime/Shaders/ShaderStore.cs +++ b/UniVgo2/Runtime/Shaders/ShaderStore.cs @@ -19,19 +19,17 @@ public class ShaderStore : IShaderStore protected Shader? _Standard; /// Standard - protected Shader Standard - => _Standard - = _Standard != null - ? _Standard : Shader.Find(ShaderName.Standard); + protected Shader Standard + => _Standard + ??= Shader.Find(ShaderName.Standard); /// Particles/Standard Surface protected Shader? _ParticlesStandardSurface; /// Particles/Standard Surface protected Shader ParticlesStandardSurface - => _ParticlesStandardSurface - = _ParticlesStandardSurface != null - ? _ParticlesStandardSurface : Shader.Find(ShaderName.Particles_Standard_Surface); + => _ParticlesStandardSurface + ??= Shader.Find(ShaderName.Particles_Standard_Surface); /// Particles/Standard Unlit protected Shader? _ParticlesStandardUnlit; @@ -39,17 +37,15 @@ protected Shader ParticlesStandardSurface /// Particles/Standard Unlit protected Shader ParticlesStandardUnlit => _ParticlesStandardUnlit - = _ParticlesStandardUnlit != null - ? _ParticlesStandardUnlit : Shader.Find(ShaderName.Particles_Standard_Unlit); + ??= Shader.Find(ShaderName.Particles_Standard_Unlit); /// Skybox/6 Sided protected Shader? _Skybox6Sided; /// Skybox/6 Sided - protected Shader Skybox6Sided + protected Shader Skybox6Sided => _Skybox6Sided - = _Skybox6Sided != null - ? _Skybox6Sided : Shader.Find(ShaderName.Skybox_6_Sided); + ??= Shader.Find(ShaderName.Skybox_6_Sided); /// Skybox/Cubemap protected Shader? _SkyboxCubemap; @@ -57,8 +53,7 @@ protected Shader Skybox6Sided /// Skybox/Cubemap protected Shader SkyboxCubemap => _SkyboxCubemap - = _SkyboxCubemap != null - ? _SkyboxCubemap : Shader.Find(ShaderName.Skybox_Cubemap); + ??= Shader.Find(ShaderName.Skybox_Cubemap); /// Skybox/Panoramic protected Shader? _SkyboxPanoramic; @@ -66,8 +61,7 @@ protected Shader SkyboxCubemap /// Skybox/Panoramic protected Shader SkyboxPanoramic => _SkyboxPanoramic - = _SkyboxPanoramic != null - ? _SkyboxPanoramic : Shader.Find(ShaderName.Skybox_Panoramic); + ??= Shader.Find(ShaderName.Skybox_Panoramic); /// Skybox/Procedural protected Shader? _SkyboxProcedural; @@ -75,8 +69,7 @@ protected Shader SkyboxPanoramic /// Skybox/Procedural protected Shader SkyboxProcedural => _SkyboxProcedural - = _SkyboxProcedural != null - ? _SkyboxProcedural : Shader.Find(ShaderName.Skybox_Procedural); + ??= Shader.Find(ShaderName.Skybox_Procedural); /// Unlit/Texture protected Shader? _UnlitTexture; @@ -84,8 +77,7 @@ protected Shader SkyboxProcedural /// Unlit/Texture protected Shader UnlitTexture => _UnlitTexture - = _UnlitTexture != null - ? _UnlitTexture : Shader.Find(ShaderName.Unlit_Texture); + ??= Shader.Find(ShaderName.Unlit_Texture); /// Unlit/Color protected Shader? _UnlitColor; @@ -93,8 +85,7 @@ protected Shader UnlitTexture /// Unlit/Color protected Shader UnlitColor => _UnlitColor - = _UnlitColor != null - ? _UnlitColor : Shader.Find(ShaderName.Unlit_Color); + ??= Shader.Find(ShaderName.Unlit_Color); /// Unlit/Transparent protected Shader? _UnlitTransparent; @@ -102,8 +93,7 @@ protected Shader UnlitColor /// Unlit/Transparent protected Shader UnlitTransparent => _UnlitTransparent - = _UnlitTransparent != null - ? _UnlitTransparent : Shader.Find(ShaderName.Unlit_Transparent); + ??= Shader.Find(ShaderName.Unlit_Transparent); /// Unlit/Transparent Cutout protected Shader? _UnlitTransparentCutout; @@ -111,8 +101,7 @@ protected Shader UnlitTransparent /// Unlit/Transparent Cutout protected Shader UnlitTransparentCutout => _UnlitTransparentCutout - = _UnlitTransparentCutout != null - ? _UnlitTransparentCutout : Shader.Find(ShaderName.Unlit_Transparent_Cutout); + ??= Shader.Find(ShaderName.Unlit_Transparent_Cutout); /// UniGLTF/UniUnlit protected Shader? _UniGLTFUniUnlit; @@ -120,8 +109,7 @@ protected Shader UnlitTransparentCutout /// UniGLTF/UniUnlit protected Shader UniGLTFUniUnlit => _UniGLTFUniUnlit - = _UniGLTFUniUnlit != null - ? _UniGLTFUniUnlit : Shader.Find(ShaderName.UniGLTF_UniUnlit); + ??= Shader.Find(ShaderName.UniGLTF_UniUnlit); /// UniGLTF/StandardVColor protected Shader? _UniGLTFStandardVColor; @@ -129,8 +117,7 @@ protected Shader UniGLTFUniUnlit /// UniGLTF/StandardVColor protected Shader UniGLTFStandardVColor => _UniGLTFStandardVColor - = _UniGLTFStandardVColor != null - ? _UniGLTFStandardVColor : Shader.Find(ShaderName.UniGLTF_StandardVColor); + ??= Shader.Find(ShaderName.UniGLTF_StandardVColor); /// VRM/UnlitTexture protected Shader? _VrmUnlitTexture; @@ -138,8 +125,7 @@ protected Shader UniGLTFStandardVColor /// VRM/UnlitTexture protected Shader VrmUnlitTexture => _VrmUnlitTexture - = _VrmUnlitTexture != null - ? _VrmUnlitTexture : Shader.Find(ShaderName.VRM_UnlitTexture); + ??= Shader.Find(ShaderName.VRM_UnlitTexture); /// VRM/UnlitTransparent protected Shader? _VrmUnlitTransparent; @@ -147,8 +133,7 @@ protected Shader VrmUnlitTexture /// VRM/UnlitTransparent protected Shader VrmUnlitTransparent => _VrmUnlitTransparent - = _VrmUnlitTransparent != null - ? _VrmUnlitTransparent : Shader.Find(ShaderName.VRM_UnlitTransparent); + ??= Shader.Find(ShaderName.VRM_UnlitTransparent); /// VRM/UnlitCutout protected Shader? _VrmUnlitCutout; @@ -156,8 +141,7 @@ protected Shader VrmUnlitTransparent /// VRM/UnlitCutout protected Shader VrmUnlitCutout => _VrmUnlitCutout - = _VrmUnlitCutout != null - ? _VrmUnlitCutout : Shader.Find(ShaderName.VRM_UnlitCutout); + ??= Shader.Find(ShaderName.VRM_UnlitCutout); /// VRM/UnlitTransparentZWrite protected Shader? _VrmUnlitTransparentZWrite; @@ -165,8 +149,7 @@ protected Shader VrmUnlitCutout /// VRM/UnlitTransparentZWrite protected Shader VrmUnlitTransparentZWrite => _VrmUnlitTransparentZWrite - = _VrmUnlitTransparentZWrite != null - ? _VrmUnlitTransparentZWrite : Shader.Find(ShaderName.VRM_UnlitTransparentZWrite); + ??= Shader.Find(ShaderName.VRM_UnlitTransparentZWrite); #endregion @@ -178,8 +161,7 @@ protected Shader VrmUnlitTransparentZWrite /// Universal Render Pipeline/Lit protected Shader UrpLit => _UrpLit - = _UrpLit != null - ? _UrpLit : Shader.Find(ShaderName.URP_Lit); + ??= Shader.Find(ShaderName.URP_Lit); /// Universal Render Pipeline/Simple Lit protected Shader? _UrpSimpleLit; @@ -187,8 +169,7 @@ protected Shader UrpLit /// Universal Render Pipeline/Simple Lit protected Shader UrpSimpleLit => _UrpSimpleLit - = _UrpSimpleLit != null - ? _UrpSimpleLit : Shader.Find(ShaderName.URP_SimpleLit); + ??= Shader.Find(ShaderName.URP_SimpleLit); /// Universal Render Pipeline/Unlit protected Shader? _UrpUnlit; @@ -196,8 +177,7 @@ protected Shader UrpSimpleLit /// Universal Render Pipeline/Unlit protected Shader UrpUnlit => _UrpUnlit - = _UrpUnlit != null - ? _UrpUnlit : Shader.Find(ShaderName.URP_Unlit); + ??= Shader.Find(ShaderName.URP_Unlit); /// Universal Render Pipeline/Particles/Lit protected Shader? _UrpParticlesLit; @@ -205,8 +185,7 @@ protected Shader UrpUnlit /// Universal Render Pipeline/Particles/Lit protected Shader UrpParticlesLit => _UrpParticlesLit - = _UrpParticlesLit != null - ? _UrpParticlesLit : Shader.Find(ShaderName.URP_Particles_Lit); + ??= Shader.Find(ShaderName.URP_Particles_Lit); /// Universal Render Pipeline/Particles/Unlit protected Shader? _UrpParticlesUnlit; @@ -214,8 +193,7 @@ protected Shader UrpParticlesLit /// Universal Render Pipeline/Particles/Unlit protected Shader UrpParticlesUnlit => _UrpParticlesUnlit - = _UrpParticlesUnlit != null - ? _UrpParticlesUnlit : Shader.Find(ShaderName.URP_Particles_Unlit); + ??= Shader.Find(ShaderName.URP_Particles_Unlit); #endregion @@ -227,8 +205,7 @@ protected Shader UrpParticlesUnlit /// HDRP/Eye protected Shader HDRPEye => _HDRPEye - = _HDRPEye != null - ? _HDRPEye : Shader.Find(ShaderName.HDRP_Eye); + ??= Shader.Find(ShaderName.HDRP_Eye); /// HDRP/Hair protected Shader? _HDRPHair; @@ -236,8 +213,7 @@ protected Shader HDRPEye /// HDRP/Hair protected Shader HDRPHair => _HDRPHair - = _HDRPHair != null - ? _HDRPHair : Shader.Find(ShaderName.HDRP_Hair); + ??= Shader.Find(ShaderName.HDRP_Hair); /// HDRP/Lit protected Shader? _HDRPLit; @@ -245,8 +221,7 @@ protected Shader HDRPHair /// HDRP/Lit protected Shader HDRPLit => _HDRPLit - = _HDRPLit != null - ? _HDRPLit : Shader.Find(ShaderName.HDRP_Lit); + ??= Shader.Find(ShaderName.HDRP_Lit); #endregion @@ -260,8 +235,7 @@ protected Shader HDRPLit /// lilToon protected Shader Lil_LilToon => _Lil_LilToon - = _Lil_LilToon != null - ? _Lil_LilToon : Shader.Find(ShaderName.Lil_LilToon); + ??= Shader.Find(ShaderName.Lil_LilToon); /// lilToon Outline /// Hidden/lilToonOutline @@ -271,8 +245,7 @@ protected Shader Lil_LilToon /// Hidden/lilToonOutline protected Shader Lil_LilToonOutline => _Lil_LilToonOutline - = _Lil_LilToonOutline != null - ? _Lil_LilToonOutline : Shader.Find(ShaderName.Lil_LilToonOutline); + ??= Shader.Find(ShaderName.Lil_LilToonOutline); /// lilToon Outline only /// _lil/[Optional] lilToonOutlineOnly @@ -282,8 +255,7 @@ protected Shader Lil_LilToonOutline /// _lil/[Optional] lilToonOutlineOnly protected Shader Lil_LilToonOutlineOnly => _Lil_LilToonOutlineOnly - = _Lil_LilToonOutlineOnly != null - ? _Lil_LilToonOutlineOnly : Shader.Find(ShaderName.Lil_LilToonOutlineOnly); + ??= Shader.Find(ShaderName.Lil_LilToonOutlineOnly); /// lilToon Outline only Cutout /// _lil/[Optional] lilToonOutlineOnlyCutout @@ -293,8 +265,7 @@ protected Shader Lil_LilToonOutlineOnly /// _lil/[Optional] lilToonOutlineOnlyCutout protected Shader Lil_LilToonOutlineOnlyCutout => _Lil_LilToonOutlineOnlyCutout - = _Lil_LilToonOutlineOnlyCutout != null - ? _Lil_LilToonOutlineOnlyCutout : Shader.Find(ShaderName.Lil_LilToonOutlineOnlyCutout); + ??= Shader.Find(ShaderName.Lil_LilToonOutlineOnlyCutout); /// lilToon Outline only Transparent /// _lil/[Optional] lilToonOutlineOnlyTransparent @@ -304,8 +275,7 @@ protected Shader Lil_LilToonOutlineOnlyCutout /// _lil/[Optional] lilToonOutlineOnlyTransparent protected Shader Lil_LilToonOutlineOnlyTransparent => _Lil_LilToonOutlineOnlyTransparent - = _Lil_LilToonOutlineOnlyTransparent != null - ? _Lil_LilToonOutlineOnlyTransparent : Shader.Find(ShaderName.Lil_LilToonOutlineOnlyTransparent); + ??= Shader.Find(ShaderName.Lil_LilToonOutlineOnlyTransparent); /// lilToon Cutout /// Hidden/lilToonCutout @@ -315,8 +285,7 @@ protected Shader Lil_LilToonOutlineOnlyTransparent /// Hidden/lilToonCutout protected Shader Lil_LilToonCutout => _Lil_LilToonCutout - = _Lil_LilToonCutout != null - ? _Lil_LilToonCutout : Shader.Find(ShaderName.Lil_LilToonCutout); + ??= Shader.Find(ShaderName.Lil_LilToonCutout); /// lilToon Cutout Outline /// Hidden/lilToonCutoutOutline @@ -326,8 +295,7 @@ protected Shader Lil_LilToonCutout /// Hidden/lilToonCutoutOutline protected Shader Lil_LilToonCutoutOutline => _Lil_LilToonCutoutOutline - = _Lil_LilToonCutoutOutline != null - ? _Lil_LilToonCutoutOutline : Shader.Find(ShaderName.Lil_LilToonCutoutOutline); + ??= Shader.Find(ShaderName.Lil_LilToonCutoutOutline); /// lilToon Transparent /// Hidden/lilToonTransparent @@ -337,8 +305,7 @@ protected Shader Lil_LilToonCutoutOutline /// Hidden/lilToonTransparent protected Shader Lil_LilToonTransparent => _Lil_LilToonTransparent - = _Lil_LilToonTransparent != null - ? _Lil_LilToonTransparent : Shader.Find(ShaderName.Lil_LilToonTransparent); + ??= Shader.Find(ShaderName.Lil_LilToonTransparent); /// lilToon Transparent Outline /// Hidden/lilToonTransparentOutline @@ -348,8 +315,7 @@ protected Shader Lil_LilToonTransparent /// Hidden/lilToonTransparentOutline protected Shader Lil_LilToonTransparentOutline => _Lil_LilToonTransparentOutline - = _Lil_LilToonTransparentOutline != null - ? _Lil_LilToonTransparentOutline : Shader.Find(ShaderName.Lil_LilToonTransparentOutline); + ??= Shader.Find(ShaderName.Lil_LilToonTransparentOutline); /// lilToon OnePass Transparent /// Hidden/lilToonOnePassTransparent @@ -359,8 +325,7 @@ protected Shader Lil_LilToonTransparentOutline /// Hidden/lilToonOnePassTransparent protected Shader Lil_LilToonOnePassTransparent => _Lil_LilToonOnePassTransparent - = _Lil_LilToonOnePassTransparent != null - ? _Lil_LilToonOnePassTransparent : Shader.Find(ShaderName.Lil_LilToonOnePassTransparent); + ??= Shader.Find(ShaderName.Lil_LilToonOnePassTransparent); /// lilToon OnePass Transparent Outline /// Hidden/lilToonOnePassTransparentOutline @@ -370,8 +335,7 @@ protected Shader Lil_LilToonOnePassTransparent /// Hidden/lilToonOnePassTransparentOutline protected Shader Lil_LilToonOnePassTransparentOutline => _Lil_LilToonOnePassTransparentOutline - = _Lil_LilToonOnePassTransparentOutline != null - ? _Lil_LilToonOnePassTransparentOutline : Shader.Find(ShaderName.Lil_LilToonOnePassTransparentOutline); + ??= Shader.Find(ShaderName.Lil_LilToonOnePassTransparentOutline); /// lilToon TwoPass Transparent /// Hidden/lilToonTwoPassTransparent @@ -381,8 +345,7 @@ protected Shader Lil_LilToonOnePassTransparentOutline /// Hidden/lilToonTwoPassTransparent protected Shader Lil_LilToonTwoPassTransparent => _Lil_LilToonTwoPassTransparent - = _Lil_LilToonTwoPassTransparent != null - ? _Lil_LilToonTwoPassTransparent : Shader.Find(ShaderName.Lil_LilToonTwoPassTransparent); + ??= Shader.Find(ShaderName.Lil_LilToonTwoPassTransparent); /// lilToon TwoPass Transparent Outline /// Hidden/lilToonTwoPassTransparentOutline @@ -392,8 +355,7 @@ protected Shader Lil_LilToonTwoPassTransparent /// Hidden/lilToonTwoPassTransparentOutline protected Shader Lil_LilToonTwoPassTransparentOutline => _Lil_LilToonTwoPassTransparentOutline - = _Lil_LilToonTwoPassTransparentOutline != null - ? _Lil_LilToonTwoPassTransparentOutline : Shader.Find(ShaderName.Lil_LilToonTwoPassTransparentOutline); + ??= Shader.Find(ShaderName.Lil_LilToonTwoPassTransparentOutline); /// lilToon Overlay /// _lil/[Optional] lilToonOverlay @@ -403,8 +365,7 @@ protected Shader Lil_LilToonTwoPassTransparentOutline /// _lil/[Optional] lilToonOverlay protected Shader Lil_LilToonOverlay => _Lil_LilToonOverlay - = _Lil_LilToonOverlay != null - ? _Lil_LilToonOverlay : Shader.Find(ShaderName.Lil_LilToonOverlay); + ??= Shader.Find(ShaderName.Lil_LilToonOverlay); /// lilToon Overlay OnePass /// _lil/[Optional] lilToonOverlayOnePass @@ -414,8 +375,7 @@ protected Shader Lil_LilToonOverlay /// _lil/[Optional] lilToonOverlayOnePass protected Shader Lil_LilToonOverlayOnePass => _Lil_LilToonOverlayOnePass - = _Lil_LilToonOverlayOnePass != null - ? _Lil_LilToonOverlayOnePass : Shader.Find(ShaderName.Lil_LilToonOverlayOnePass); + ??= Shader.Find(ShaderName.Lil_LilToonOverlayOnePass); /// lilToon Refraction /// Hidden/lilToonRefraction @@ -425,8 +385,7 @@ protected Shader Lil_LilToonOverlayOnePass /// Hidden/lilToonRefraction protected Shader Lil_LilToonRefraction => _Lil_LilToonRefraction - = _Lil_LilToonRefraction != null - ? _Lil_LilToonRefraction : Shader.Find(ShaderName.Lil_LilToonRefraction); + ??= Shader.Find(ShaderName.Lil_LilToonRefraction); /// lilToon Refraction Blur /// Hidden/lilToonRefractionBlur @@ -436,8 +395,7 @@ protected Shader Lil_LilToonRefraction /// Hidden/lilToonRefractionBlur protected Shader Lil_LilToonRefractionBlur => _Lil_LilToonRefractionBlur - = _Lil_LilToonRefractionBlur != null - ? _Lil_LilToonRefractionBlur : Shader.Find(ShaderName.Lil_LilToonRefractionBlur); + ??= Shader.Find(ShaderName.Lil_LilToonRefractionBlur); #endregion @@ -451,8 +409,7 @@ protected Shader Lil_LilToonRefractionBlur /// Hidden/lilToonFur protected Shader Lil_LilToonFur => _Lil_LilToonFur - = _Lil_LilToonFur != null - ? _Lil_LilToonFur : Shader.Find(ShaderName.Lil_LilToonFur); + ??= Shader.Find(ShaderName.Lil_LilToonFur); /// lilToon Fur Cutout /// Hidden/lilToonFurCutout @@ -462,8 +419,7 @@ protected Shader Lil_LilToonFur /// Hidden/lilToonFurCutout protected Shader Lil_LilToonFurCutout => _Lil_LilToonFurCutout - = _Lil_LilToonFurCutout != null - ? _Lil_LilToonFurCutout : Shader.Find(ShaderName.Lil_LilToonFurCutout); + ??= Shader.Find(ShaderName.Lil_LilToonFurCutout); /// lilToon Fur TwoPass /// Hidden/lilToonFurTwoPass @@ -473,8 +429,7 @@ protected Shader Lil_LilToonFurCutout /// Hidden/lilToonFurTwoPass protected Shader Lil_LilToonFurTwoPass => _Lil_LilToonFurTwoPass - = _Lil_LilToonFurTwoPass != null - ? _Lil_LilToonFurTwoPass : Shader.Find(ShaderName.Lil_LilToonFurTwoPass); + ??= Shader.Find(ShaderName.Lil_LilToonFurTwoPass); /// lilToon Fur only /// _lil/[Optional] lilToonFurOnly @@ -484,8 +439,7 @@ protected Shader Lil_LilToonFurTwoPass /// _lil/[Optional] lilToonFurOnly protected Shader Lil_LilToonFurOnly => _Lil_LilToonFurOnly - = _Lil_LilToonFurOnly != null - ? _Lil_LilToonFurOnly : Shader.Find(ShaderName.Lil_LilToonFurOnly); + ??= Shader.Find(ShaderName.Lil_LilToonFurOnly); /// lilToon Fur only Cutout /// _lil/[Optional] lilToonFurOnlyCutout @@ -495,8 +449,7 @@ protected Shader Lil_LilToonFurOnly /// _lil/[Optional] lilToonFurOnlyCutout protected Shader Lil_LilToonFurOnlyCutout => _Lil_LilToonFurOnlyCutout - = _Lil_LilToonFurOnlyCutout != null - ? _Lil_LilToonFurOnlyCutout : Shader.Find(ShaderName.Lil_LilToonFurOnlyCutout); + ??= Shader.Find(ShaderName.Lil_LilToonFurOnlyCutout); /// lilToon Fur only TwoPass /// _lil/[Optional] lilToonFurOnlyTwoPass @@ -506,8 +459,7 @@ protected Shader Lil_LilToonFurOnlyCutout /// _lil/[Optional] lilToonFurOnlyTwoPass protected Shader Lil_LilToonFurOnlyTwoPass => _Lil_LilToonFurOnlyTwoPass - = _Lil_LilToonFurOnlyTwoPass != null - ? _Lil_LilToonFurOnlyTwoPass : Shader.Find(ShaderName.Lil_LilToonFurOnlyTwoPass); + ??= Shader.Find(ShaderName.Lil_LilToonFurOnlyTwoPass); #endregion @@ -521,8 +473,7 @@ protected Shader Lil_LilToonFurOnlyTwoPass /// Hidden/lilToonGem protected Shader Lil_LilToonGem => _Lil_LilToonGem - = _Lil_LilToonGem != null - ? _Lil_LilToonGem : Shader.Find(ShaderName.Lil_LilToonGem); + ??= Shader.Find(ShaderName.Lil_LilToonGem); #endregion @@ -536,8 +487,7 @@ protected Shader Lil_LilToonGem /// Hidden/lilToonTessellation protected Shader Lil_LilToonTessellation => _Lil_LilToonTessellation - = _Lil_LilToonTessellation != null - ? _Lil_LilToonTessellation : Shader.Find(ShaderName.Lil_LilToonTessellation); + ??= Shader.Find(ShaderName.Lil_LilToonTessellation); /// lilToon Tessellation Outline /// Hidden/lilToonTessellationOutline @@ -547,8 +497,7 @@ protected Shader Lil_LilToonTessellation /// Hidden/lilToonTessellationOutline protected Shader Lil_LilToonTessellationOutline => _Lil_LilToonTessellationOutline - = _Lil_LilToonTessellationOutline != null - ? _Lil_LilToonTessellationOutline : Shader.Find(ShaderName.Lil_LilToonTessellationOutline); + ??= Shader.Find(ShaderName.Lil_LilToonTessellationOutline); /// lilToon Tessellation Cutout /// Hidden/lilToonTessellationCutout @@ -558,8 +507,7 @@ protected Shader Lil_LilToonTessellationOutline /// Hidden/lilToonTessellationCutout protected Shader Lil_LilToonTessellationCutout => _Lil_LilToonTessellationCutout - = _Lil_LilToonTessellationCutout != null - ? _Lil_LilToonTessellationCutout : Shader.Find(ShaderName.Lil_LilToonTessellationCutout); + ??= Shader.Find(ShaderName.Lil_LilToonTessellationCutout); /// lilToon Tessellation Cutout Outline /// Hidden/lilToonTessellationCutoutOutline @@ -569,8 +517,7 @@ protected Shader Lil_LilToonTessellationCutout /// Hidden/lilToonTessellationCutoutOutline protected Shader Lil_LilToonTessellationCutoutOutline => _Lil_LilToonTessellationCutoutOutline - = _Lil_LilToonTessellationCutoutOutline != null - ? _Lil_LilToonTessellationCutoutOutline : Shader.Find(ShaderName.Lil_LilToonTessellationCutoutOutline); + ??= Shader.Find(ShaderName.Lil_LilToonTessellationCutoutOutline); /// lilToon Tessellation Transparent /// Hidden/lilToonTessellationTransparent @@ -580,8 +527,7 @@ protected Shader Lil_LilToonTessellationCutoutOutline /// Hidden/lilToonTessellationTransparent protected Shader Lil_LilToonTessellationTransparent => _Lil_LilToonTessellationTransparent - = _Lil_LilToonTessellationTransparent != null - ? _Lil_LilToonTessellationTransparent : Shader.Find(ShaderName.Lil_LilToonTessellationTransparent); + ??= Shader.Find(ShaderName.Lil_LilToonTessellationTransparent); /// lilToon Tessellation Transparent Outline /// Hidden/lilToonTessellationTransparentOutline @@ -591,8 +537,7 @@ protected Shader Lil_LilToonTessellationTransparent /// Hidden/lilToonTessellationTransparentOutline protected Shader Lil_LilToonTessellationTransparentOutline => _Lil_LilToonTessellationTransparentOutline - = _Lil_LilToonTessellationTransparentOutline != null - ? _Lil_LilToonTessellationTransparentOutline : Shader.Find(ShaderName.Lil_LilToonTessellationTransparentOutline); + ??= Shader.Find(ShaderName.Lil_LilToonTessellationTransparentOutline); /// lilToon Tessellation OnePass Transparent /// Hidden/lilToonTessellationOnePassTransparent @@ -602,8 +547,7 @@ protected Shader Lil_LilToonTessellationTransparentOutline /// Hidden/lilToonTessellationOnePassTransparent protected Shader Lil_LilToonTessellationOnePassTransparent => _Lil_LilToonTessellationOnePassTransparent - = _Lil_LilToonTessellationOnePassTransparent != null - ? _Lil_LilToonTessellationOnePassTransparent : Shader.Find(ShaderName.Lil_LilToonTessellationOnePassTransparent); + ??= Shader.Find(ShaderName.Lil_LilToonTessellationOnePassTransparent); /// lilToon Tessellation OnePass Transparent Outline /// Hidden/lilToonTessellationOnePassTransparentOutline @@ -613,8 +557,7 @@ protected Shader Lil_LilToonTessellationOnePassTransparent /// Hidden/lilToonTessellationOnePassTransparentOutline protected Shader Lil_LilToonTessellationOnePassTransparentOutline => _Lil_LilToonTessellationOnePassTransparentOutline - = _Lil_LilToonTessellationOnePassTransparentOutline != null - ? _Lil_LilToonTessellationOnePassTransparentOutline : Shader.Find(ShaderName.Lil_LilToonTessellationOnePassTransparentOutline); + ??= Shader.Find(ShaderName.Lil_LilToonTessellationOnePassTransparentOutline); /// lilToon Tessellation TwoPass Transparent /// Hidden/lilToonTessellationTwoPassTransparent @@ -624,8 +567,7 @@ protected Shader Lil_LilToonTessellationOnePassTransparentOutline /// Hidden/lilToonTessellationTwoPassTransparent protected Shader Lil_LilToonTessellationTwoPassTransparent => _Lil_LilToonTessellationTwoPassTransparent - = _Lil_LilToonTessellationTwoPassTransparent != null - ? _Lil_LilToonTessellationTwoPassTransparent : Shader.Find(ShaderName.Lil_LilToonTessellationTwoPassTransparent); + ??= Shader.Find(ShaderName.Lil_LilToonTessellationTwoPassTransparent); /// lilToon Tessellation TwoPass Transparent Outline /// Hidden/lilToonTessellationTwoPassTransparentOutline @@ -635,8 +577,7 @@ protected Shader Lil_LilToonTessellationTwoPassTransparent /// Hidden/lilToonTessellationTwoPassTransparentOutline protected Shader Lil_LilToonTessellationTwoPassTransparentOutline => _Lil_LilToonTessellationTwoPassTransparentOutline - = _Lil_LilToonTessellationTwoPassTransparentOutline != null - ? _Lil_LilToonTessellationTwoPassTransparentOutline : Shader.Find(ShaderName.Lil_LilToonTessellationTwoPassTransparentOutline); + ??= Shader.Find(ShaderName.Lil_LilToonTessellationTwoPassTransparentOutline); #endregion @@ -650,8 +591,7 @@ protected Shader Lil_LilToonTessellationTwoPassTransparentOutline /// Hidden/lilToonLite protected Shader Lil_LilToonLite => _Lil_LilToonLite - = _Lil_LilToonLite != null - ? _Lil_LilToonLite : Shader.Find(ShaderName.Lil_LilToonLite); + ??= Shader.Find(ShaderName.Lil_LilToonLite); /// lilToon Lite Outline /// Hidden/lilToonLiteOutline @@ -661,8 +601,7 @@ protected Shader Lil_LilToonLite /// Hidden/lilToonLiteOutline protected Shader Lil_LilToonLiteOutline => _Lil_LilToonLiteOutline - = _Lil_LilToonLiteOutline != null - ? _Lil_LilToonLiteOutline : Shader.Find(ShaderName.Lil_LilToonLiteOutline); + ??= Shader.Find(ShaderName.Lil_LilToonLiteOutline); /// lilToon Lite Cutout /// Hidden/lilToonLiteCutout @@ -672,8 +611,7 @@ protected Shader Lil_LilToonLiteOutline /// Hidden/lilToonLiteCutout protected Shader Lil_LilToonLiteCutout => _Lil_LilToonLiteCutout - = _Lil_LilToonLiteCutout != null - ? _Lil_LilToonLiteCutout : Shader.Find(ShaderName.Lil_LilToonLiteCutout); + ??= Shader.Find(ShaderName.Lil_LilToonLiteCutout); /// lilToon Lite Cutout Outline /// Hidden/lilToonLiteCutoutOutline @@ -683,8 +621,7 @@ protected Shader Lil_LilToonLiteCutout /// Hidden/lilToonLiteCutoutOutline protected Shader Lil_LilToonLiteCutoutOutline => _Lil_LilToonLiteCutoutOutline - = _Lil_LilToonLiteCutoutOutline != null - ? _Lil_LilToonLiteCutoutOutline : Shader.Find(ShaderName.Lil_LilToonLiteCutoutOutline); + ??= Shader.Find(ShaderName.Lil_LilToonLiteCutoutOutline); /// lilToon Lite Transparent /// Hidden/lilToonLiteTransparent @@ -694,8 +631,7 @@ protected Shader Lil_LilToonLiteCutoutOutline /// Hidden/lilToonLiteTransparent protected Shader Lil_LilToonLiteTransparent => _Lil_LilToonLiteTransparent - = _Lil_LilToonLiteTransparent != null - ? _Lil_LilToonLiteTransparent : Shader.Find(ShaderName.Lil_LilToonLiteTransparent); + ??= Shader.Find(ShaderName.Lil_LilToonLiteTransparent); /// lilToon Lite Transparent Outline /// Hidden/lilToonLiteTransparentOutline @@ -705,8 +641,7 @@ protected Shader Lil_LilToonLiteTransparent /// Hidden/lilToonLiteTransparentOutline protected Shader Lil_LilToonLiteTransparentOutline => _Lil_LilToonLiteTransparentOutline - = _Lil_LilToonLiteTransparentOutline != null - ? _Lil_LilToonLiteTransparentOutline : Shader.Find(ShaderName.Lil_LilToonLiteTransparentOutline); + ??= Shader.Find(ShaderName.Lil_LilToonLiteTransparentOutline); /// lilToon Lite OnePass Transparent /// Hidden/lilToonLiteOnePassTransparent @@ -716,8 +651,7 @@ protected Shader Lil_LilToonLiteTransparentOutline /// Hidden/lilToonLiteOnePassTransparent protected Shader Lil_LilToonLiteOnePassTransparent => _Lil_LilToonLiteOnePassTransparent - = _Lil_LilToonLiteOnePassTransparent != null - ? _Lil_LilToonLiteOnePassTransparent : Shader.Find(ShaderName.Lil_LilToonLiteOnePassTransparent); + ??= Shader.Find(ShaderName.Lil_LilToonLiteOnePassTransparent); /// lilToon Lite OnePass Transparent Outline /// Hidden/lilToonLiteOnePassTransparentOutline @@ -727,8 +661,7 @@ protected Shader Lil_LilToonLiteOnePassTransparent /// Hidden/lilToonLiteOnePassTransparentOutline protected Shader Lil_LilToonLiteOnePassTransparentOutline => _Lil_LilToonLiteOnePassTransparentOutline - = _Lil_LilToonLiteOnePassTransparentOutline != null - ? _Lil_LilToonLiteOnePassTransparentOutline : Shader.Find(ShaderName.Lil_LilToonLiteOnePassTransparentOutline); + ??= Shader.Find(ShaderName.Lil_LilToonLiteOnePassTransparentOutline); /// lilToon Lite TwoPass Transparent /// Hidden/lilToonLiteTransparent @@ -738,8 +671,7 @@ protected Shader Lil_LilToonLiteOnePassTransparentOutline /// Hidden/lilToonLiteTransparent protected Shader Lil_LilToonLiteTwoPassTransparent => _Lil_LilToonLiteTwoPassTransparent - = _Lil_LilToonLiteTwoPassTransparent != null - ? _Lil_LilToonLiteTwoPassTransparent : Shader.Find(ShaderName.Lil_LilToonLiteTwoPassTransparent); + ??= Shader.Find(ShaderName.Lil_LilToonLiteTwoPassTransparent); /// lilToon Lite TwoPass Transparent Outline /// Hidden/lilToonLiteTwoPassTransparentOutline @@ -749,8 +681,7 @@ protected Shader Lil_LilToonLiteTwoPassTransparent /// Hidden/lilToonLiteTwoPassTransparentOutline protected Shader Lil_LilToonLiteTwoPassTransparentOutline => _Lil_LilToonLiteTwoPassTransparentOutline - = _Lil_LilToonLiteTwoPassTransparentOutline != null - ? _Lil_LilToonLiteTwoPassTransparentOutline : Shader.Find(ShaderName.Lil_LilToonLiteTwoPassTransparentOutline); + ??= Shader.Find(ShaderName.Lil_LilToonLiteTwoPassTransparentOutline); /// lilToon Lite Overlay /// _lil/[Optional] lilToonLiteOverlay @@ -760,8 +691,7 @@ protected Shader Lil_LilToonLiteTwoPassTransparentOutline /// _lil/[Optional] lilToonLiteOverlay protected Shader Lil_LilToonLiteOverlay => _Lil_LilToonLiteOverlay - = _Lil_LilToonLiteOverlay != null - ? _Lil_LilToonLiteOverlay : Shader.Find(ShaderName.Lil_LilToonLiteOverlay); + ??= Shader.Find(ShaderName.Lil_LilToonLiteOverlay); /// lilToon Lite Overlay OnePass /// _lil/[Optional] lilToonLiteOverlayOnePass @@ -771,8 +701,7 @@ protected Shader Lil_LilToonLiteOverlay /// _lil/[Optional] lilToonLiteOverlayOnePass protected Shader Lil_LilToonLiteOverlayOnePass => _Lil_LilToonLiteOverlayOnePass - = _Lil_LilToonLiteOverlayOnePass != null - ? _Lil_LilToonLiteOverlayOnePass : Shader.Find(ShaderName.Lil_LilToonLiteOverlayOnePass); + ??= Shader.Find(ShaderName.Lil_LilToonLiteOverlayOnePass); #endregion @@ -786,8 +715,7 @@ protected Shader Lil_LilToonLiteOverlayOnePass /// _lil/lilToonMulti protected Shader Lil_LilToonMulti => _Lil_LilToonMulti - = _Lil_LilToonMulti != null - ? _Lil_LilToonMulti : Shader.Find(ShaderName.Lil_LilToonMulti); + ??= Shader.Find(ShaderName.Lil_LilToonMulti); /// lilToon Multi Outline /// Hidden/lilToonMultiOutline @@ -797,8 +725,7 @@ protected Shader Lil_LilToonMulti /// Hidden/lilToonMultiOutline protected Shader Lil_LilToonMultiOutline => _Lil_LilToonMultiOutline - = _Lil_LilToonMultiOutline != null - ? _Lil_LilToonMultiOutline : Shader.Find(ShaderName.Lil_LilToonMultiOutline); + ??= Shader.Find(ShaderName.Lil_LilToonMultiOutline); /// lilToon Multi Refraction /// Hidden/lilToonMultiRefraction @@ -808,8 +735,7 @@ protected Shader Lil_LilToonMultiOutline /// Hidden/lilToonMultiRefraction protected Shader Lil_LilToonMultiRefraction => _Lil_LilToonMultiRefraction - = _Lil_LilToonMultiRefraction != null - ? _Lil_LilToonMultiRefraction : Shader.Find(ShaderName.Lil_LilToonMultiRefraction); + ??= Shader.Find(ShaderName.Lil_LilToonMultiRefraction); /// lilToon Multi Fur /// Hidden/lilToonMultiFur @@ -819,8 +745,7 @@ protected Shader Lil_LilToonMultiRefraction /// Hidden/lilToonMultiFur protected Shader Lil_LilToonMultiFur => _Lil_LilToonMultiFur - = _Lil_LilToonMultiFur != null - ? _Lil_LilToonMultiFur : Shader.Find(ShaderName.Lil_LilToonMultiFur); + ??= Shader.Find(ShaderName.Lil_LilToonMultiFur); /// lilToon Multi Gem /// Hidden/lilToonMultiGem @@ -830,8 +755,7 @@ protected Shader Lil_LilToonMultiFur /// Hidden/lilToonMultiGem protected Shader Lil_LilToonMultiGem => _Lil_LilToonMultiGem - = _Lil_LilToonMultiGem != null - ? _Lil_LilToonMultiGem : Shader.Find(ShaderName.Lil_LilToonMultiGem); + ??= Shader.Find(ShaderName.Lil_LilToonMultiGem); #endregion @@ -845,8 +769,7 @@ protected Shader Lil_LilToonMultiGem /// _lil/[Optional] lilToonFakeShadow protected Shader Lil_LilToonFakeShadow => _Lil_LilToonFakeShadow - = _Lil_LilToonFakeShadow != null - ? _Lil_LilToonFakeShadow : Shader.Find(ShaderName.Lil_LilToonFakeShadow); + ??= Shader.Find(ShaderName.Lil_LilToonFakeShadow); #endregion @@ -860,8 +783,7 @@ protected Shader Lil_LilToonFakeShadow /// Hidden/ltsother_baker protected Shader Lil_LilToonOtherBaker => _Lil_LilToonOtherBaker - = _Lil_LilToonOtherBaker != null - ? _Lil_LilToonOtherBaker : Shader.Find(ShaderName.Lil_LilToonOtherBaker); + ??= Shader.Find(ShaderName.Lil_LilToonOtherBaker); /// lilToon Pass Dummy /// Hidden/ltspass_dummy @@ -871,8 +793,7 @@ protected Shader Lil_LilToonOtherBaker /// Hidden/ltspass_dummy protected Shader Lil_LilToonPassDummy => _Lil_LilToonPassDummy - = _Lil_LilToonPassDummy != null - ? _Lil_LilToonPassDummy : Shader.Find(ShaderName.Lil_LilToonPassDummy); + ??= Shader.Find(ShaderName.Lil_LilToonPassDummy); /// lilToon Pass Opaque /// Hidden/ltspass_opaque @@ -882,8 +803,7 @@ protected Shader Lil_LilToonPassDummy /// Hidden/ltspass_opaque protected Shader Lil_LilToonPassOpaque => _Lil_LilToonPassOpaque - = _Lil_LilToonPassOpaque != null - ? _Lil_LilToonPassOpaque : Shader.Find(ShaderName.Lil_LilToonPassOpaque); + ??= Shader.Find(ShaderName.Lil_LilToonPassOpaque); /// lilToon Pass Cutout /// Hidden/ltspass_cutout @@ -893,8 +813,7 @@ protected Shader Lil_LilToonPassOpaque /// Hidden/ltspass_cutout protected Shader Lil_LilToonPassCutout => _Lil_LilToonPassCutout - = _Lil_LilToonPassCutout != null - ? _Lil_LilToonPassCutout : Shader.Find(ShaderName.Lil_LilToonPassCutout); + ??= Shader.Find(ShaderName.Lil_LilToonPassCutout); /// lilToon Pass Transparent /// Hidden/ltspass_transparent @@ -904,8 +823,7 @@ protected Shader Lil_LilToonPassCutout /// Hidden/ltspass_transparent protected Shader Lil_LilToonPassTransparent => _Lil_LilToonPassTransparent - = _Lil_LilToonPassTransparent != null - ? _Lil_LilToonPassTransparent : Shader.Find(ShaderName.Lil_LilToonPassTransparent); + ??= Shader.Find(ShaderName.Lil_LilToonPassTransparent); /// lilToon Pass Tessellation Opaque /// Hidden/ltspass_tess_opaque @@ -915,8 +833,7 @@ protected Shader Lil_LilToonPassTransparent /// Hidden/ltspass_tess_opaque protected Shader Lil_LilToonPassTessOpaque => _Lil_LilToonPassTessOpaque - = _Lil_LilToonPassTessOpaque != null - ? _Lil_LilToonPassTessOpaque : Shader.Find(ShaderName.Lil_LilToonPassTessOpaque); + ??= Shader.Find(ShaderName.Lil_LilToonPassTessOpaque); /// lilToon Pass Tessellation Cutout /// Hidden/ltspass_tess_cutout @@ -926,8 +843,7 @@ protected Shader Lil_LilToonPassTessOpaque /// Hidden/ltspass_tess_cutout protected Shader Lil_LilToonPassTessCutout => _Lil_LilToonPassTessCutout - = _Lil_LilToonPassTessCutout != null - ? _Lil_LilToonPassTessCutout : Shader.Find(ShaderName.Lil_LilToonPassTessCutout); + ??= Shader.Find(ShaderName.Lil_LilToonPassTessCutout); /// lilToon Pass Tessellation Transparent /// Hidden/ltspass_tess_transparent @@ -937,8 +853,7 @@ protected Shader Lil_LilToonPassTessCutout /// Hidden/ltspass_tess_transparent protected Shader Lil_LilToonPassTessTransparent => _Lil_LilToonPassTessTransparent - = _Lil_LilToonPassTessTransparent != null - ? _Lil_LilToonPassTessTransparent : Shader.Find(ShaderName.Lil_LilToonPassTessTransparent); + ??= Shader.Find(ShaderName.Lil_LilToonPassTessTransparent); /// lilToon Pass Lite Opaque /// Hidden/ltspass_lite_opaque @@ -948,8 +863,7 @@ protected Shader Lil_LilToonPassTessTransparent /// Hidden/ltspass_lite_opaque protected Shader Lil_LilToonPassLiteOpaque => _Lil_LilToonPassLiteOpaque - = _Lil_LilToonPassLiteOpaque != null - ? _Lil_LilToonPassLiteOpaque : Shader.Find(ShaderName.Lil_LilToonPassLiteOpaque); + ??= Shader.Find(ShaderName.Lil_LilToonPassLiteOpaque); /// lilToon Pass Lite Cutout /// Hidden/ltspass_lite_cutout @@ -959,8 +873,7 @@ protected Shader Lil_LilToonPassLiteOpaque /// Hidden/ltspass_lite_cutout protected Shader Lil_LilToonPassLiteCutout => _Lil_LilToonPassLiteCutout - = _Lil_LilToonPassLiteCutout != null - ? _Lil_LilToonPassLiteCutout : Shader.Find(ShaderName.Lil_LilToonPassLiteCutout); + ??= Shader.Find(ShaderName.Lil_LilToonPassLiteCutout); /// lilToon Pass Lite Transparent /// Hidden/ltspass_lite_transparent @@ -970,8 +883,8 @@ protected Shader Lil_LilToonPassLiteCutout /// Hidden/ltspass_lite_transparent protected Shader Lil_LilToonPassLiteTransparent => _Lil_LilToonPassLiteTransparent - = _Lil_LilToonPassLiteTransparent != null - ? _Lil_LilToonPassLiteTransparent : Shader.Find(ShaderName.Lil_LilToonPassLiteTransparent); + ??= Shader.Find(ShaderName.Lil_LilToonPassLiteTransparent); + #endregion #region Fields & Properties (MToon) @@ -982,8 +895,7 @@ protected Shader Lil_LilToonPassLiteTransparent /// VRM/MToon protected Shader VrmMtoon => _VrmMtoon - = _VrmMtoon != null - ? _VrmMtoon : Shader.Find(ShaderName.VRM_MToon); + ??= Shader.Find(ShaderName.VRM_MToon); /// VRM10/MToon10 protected Shader? _VrmMtoon10; @@ -991,8 +903,7 @@ protected Shader VrmMtoon /// VRM10/MToon10 protected Shader VrmMtoon10 => _VrmMtoon10 - = _VrmMtoon10 != null - ? _VrmMtoon10 : Shader.Find(ShaderName.VRM_MToon10); + ??= Shader.Find(ShaderName.VRM_MToon10); #endregion @@ -1003,7 +914,7 @@ protected Shader VrmMtoon10 /// /// The shader name. /// A shader instanse or default. - public virtual Shader? GetShaderOrDefault(string shaderName) + public virtual Shader? GetShaderOrDefault(in string shaderName) { if (string.IsNullOrEmpty(shaderName)) { @@ -1292,7 +1203,7 @@ protected Shader VrmMtoon10 /// /// The vgo material. /// A shader instanse or default. - public virtual Shader? GetShaderOrDefault(VgoMaterial vgoMaterial) + public virtual Shader? GetShaderOrDefault(in VgoMaterial vgoMaterial) { if (vgoMaterial == null) { @@ -1331,7 +1242,7 @@ protected Shader VrmMtoon10 /// The vgo material. /// Type of render pipeline. /// A shader instanse. - public virtual Shader GetShaderOrStandard(VgoMaterial vgoMaterial, RenderPipelineType renderPipelineType) + public virtual Shader GetShaderOrStandard(in VgoMaterial vgoMaterial, in RenderPipelineType renderPipelineType) { Shader? shader = GetShaderOrDefault(vgoMaterial); diff --git a/UniVgo2/Runtime/VgoVersion.cs b/UniVgo2/Runtime/VgoVersion.cs index 933def4..9a806c5 100644 --- a/UniVgo2/Runtime/VgoVersion.cs +++ b/UniVgo2/Runtime/VgoVersion.cs @@ -17,9 +17,9 @@ public class VgoVersion public const int MINOR = 5; /// Patch - public const int PATCH = 10; + public const int PATCH = 11; /// Version - public const string VERSION = "2.5.10"; + public const string VERSION = "2.5.11"; } } diff --git a/package.json b/package.json index 2556425..0e0358a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "com.izayoi.univgo", "displayName": "UniVGO", "description": "UniVGO is a package that can handle VGO files in Unity.", - "version": "2.5.10", + "version": "2.5.11", "type": "tool", "category": "", "keywords": [