可以在此处找到“分配默认值”按钮代码:
SkeletonGraphicInspector.cs : L348 - L355
它只是将第一个材料资产分配给例如 默认乘法材质的名称“SkeletonGraphicMultiply”:
SkeletonGraphicInspector.cs: L498.
所以在你的代码中,你只需要类似地分配材料,正如你上面已经提到的:
skeletonGraphic.additiveMaterial = DefaultSkeletonGraphicAdditiveMaterial;
skeletonGraphic.multiplyMaterial = DefaultSkeletonGraphicMultiplyMaterial;
skeletonGraphic.screenMaterial = DefaultSkeletonGraphicScreenMaterial;
对于提供这些材料参考,适用正常的 Unity 规则,您可以按您认为合适的方式提供它们。 您可以简单地使用对资产的直接引用,这应该没有错。 如果你真的想避免直接引用,你可以例如 通过使用 Resources
工作流程 加载这些资产,或使用任何其他系统在运行时提供资产。 请注意,这不是 Spine 特有的,它只是一个关于如何在 Unity 中加载或提供材质的一般性问题。
The button Assign Default
code can be found here:
SkeletonGraphicInspector.cs : L348 - L355
It just assigns the first material asset with e.g. the name "SkeletonGraphicMultiply"
for the default multiply material:
SkeletonGraphicInspector.cs: L498.
So in your code, you just need to assign materials similarly, as you already mentioned above:
skeletonGraphic.additiveMaterial = DefaultSkeletonGraphicAdditiveMaterial;
skeletonGraphic.multiplyMaterial = DefaultSkeletonGraphicMultiplyMaterial;
skeletonGraphic.screenMaterial = DefaultSkeletonGraphicScreenMaterial;
For providing these material references, normal Unity rules apply, you can provide them however you think is suitable. You can simply use direct references to the assets, there should be nothing wrong with that. If you really want to avoid direct references, you could e.g. load these assets via using the Resources
workflow, or use any other system to provide the assets at runtime. Please note that this is not specific to Spine, its just a general question how to load or provide a material in Unity.