我是 C# 编码的新手,无法在 Nvidia FlexArray 脚本中设置粒子计数,粒子计数公共类显示为灰色且无法编辑。它以某种方式永久设置为0。
我附上了一张图片和包装附带的脚本。我非常感谢任何帮助。数组 actor 上的检查器视图的图像
using UnityEngine;
namespace NVIDIA.Flex
{
[ExecuteInEditMode]
public class FlexArrayAsset : FlexAsset
{
#region Properties
public Mesh boundaryMesh
{
get { return m_boundaryMesh; }
set { m_boundaryMesh = value; }
}
public Vector3 meshLocalScale
{
get { return m_meshLocalScale; }
set { m_meshLocalScale = value; }
}
public float meshExpansion
{
get { return m_meshExpansion; }
set { m_meshExpansion = value; }
}
public float particleSpacing
{
get { return m_particleSpacing; }
set { m_particleSpacing = Mathf.Max(value, 0.01f); }
}
public float particleCount
{
get { return m_particleCount; }
set { m_particleCount = Mathf.Max(value, 516f); }
}
#endregion
#region Methods
#endregion
#region Messages
#endregion
#region Protected
protected override void ValidateFields()
{
base.ValidateFields();
m_particleSpacing = Mathf.Max(m_particleSpacing, 0.01f);
}
protected override void RebuildAsset()
{
BuildFromMesh();
base.RebuildAsset();
}
#endregion
#region Private
void BuildFromMesh()
{
if (m_boundaryMesh)
{
Vector3[] vertices = m_boundaryMesh.vertices;
if (vertices != null && vertices.Length > 0)
{
for (int i = 0; i < vertices.Length; ++i)
{
Vector3 v = vertices[i];
vertices[i] = new Vector3(v.x * m_meshLocalScale.x, v.y * m_meshLocalScale.y, v.z * m_meshLocalScale.z);
}
int[] indices = m_boundaryMesh.triangles;
if (indices != null && indices.Length > 0)
{
FlexExt.Asset.Handle assetHandle = FlexExt.CreateRigidFromMesh(ref vertices[0], vertices.Length, ref indices[0], indices.Length, m_particleSpacing, m_meshExpansion);
if (assetHandle)
{
FlexExt.Asset asset = assetHandle.asset;
FlexExt.Asset particlesOnly = new FlexExt.Asset();
particlesOnly.numParticles = asset.numParticles;
particlesOnly.maxParticles = asset.numParticles;
particlesOnly.particles = asset.particles;
StoreAsset(particlesOnly);
FlexExt.DestroyAsset(assetHandle);
}
}
}
}
}
[SerializeField]
Mesh m_boundaryMesh = null;
[SerializeField]
Vector3 m_meshLocalScale = Vector3.one;
[SerializeField, Tooltip("Particles will be moved inwards (if negative) or outwards (if positive) from the surface of the mesh according to this factor")]
float m_meshExpansion = 0.0f;
[SerializeField, Tooltip("The spacing used for voxelization, note that the number of voxels grows proportional to the inverse cube of radius, currently this method limits construction to resolutions < 64^3")]
float m_particleSpacing = 0.1f;
#endregion
}
}