• 한국어
  • Blend Mode Materials 의 스크립트에서의 사용법이 궁금합니다.

Related Discussions
...

UI에서 SkeletonGraphic 오브젝트를 하나 만들어 놓고,
런타임 도중 SkeletonData 프리팹들을 가져와 캐릭터를 표현해주고있습니다.

allowMultipleCanvasRenderers 를 사용하지 않으면

이런식으로 이미지가 깨지기 때문에
MultipleCanvasRenderers 를 사용해야하는데

인스펙터에서는 Blend Mode Materials 부분의 Assign Default 버튼을 클릭하면
Multiply , Screen Material이 자동으로 할당되지만,

코드로 spine..allowMultipleCanvasRenderers = true; 를 사용하면
메테리얼이 자동으로 할당되지않습니다.

코드상에서 Assign Default을 사용하려면 어떤 코드를 사용해야하나요 ?
물론 단순하게
character_LD_Spine.multiplyMaterial = SkeletonGraphicMultiply
character_LD_Spine.screenMaterial = SkeletonGraphicScreen
이런방법도 존재하겠지만,
이경우 두개의 메테리얼을 프리팹이나 변수로 등록해야합니다.


이버튼의 스크립트 사용법을 알려주세요

그리고 스크립트상의 코드 순서가 맞는순서인지 알려주세요

可以在此处找到“分配默认值”按钮代码:
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.

🙂 🙂 Thank you. Thanks to you, I solved it!

很高兴听到,感谢您回到我们身边! 🙂
Very glad to hear, thanks for getting back to us! 🙂