• RuntimesUnity
  • 有關Spine物件於Unity中透明度調整的問題

我希望將Spine物件導出至Unity中,像是文字冒險遊戲一樣淡出淡入角色,但爬過文之後還是不清楚要怎麼操作。想問一下現在的Spine4.2版本中,輸出到Unity後要怎麼調整透明度會比較方便呢?

Related Discussions
...
  • 編集済み

要在Unity中調整Spine物件的透明度,可以使用幾種方法。首先,確保你使用的是Spine-Unity 4.0或更新的版本,因為這些版本提供了更多的功能和支持。

  1. 使用SkeletonGraphicSkeleton Color屬性:你可以通過調整這些組件上的Skeleton Color屬性來改變透明度。這個屬性包括RGBA值,其中A值代表透明度。將A值設置為低於1的值可以使物件變得半透明。

  2. 使用SkeletonRenderTexture組件:根據你提供的第一個上下文,Spine-Unity庫中添加了一個新的例子組件SkeletonRenderTexture,以及一個名為'RenderTexture FadeOut Transparency'的淡出示例場景。這個組件允許你將Spine動畫渲染到一個RenderTexture上,然後你可以使用這個RenderTexture來實現淡入淡出效果。

  3. 自定義Shader和材質:如果你需要更複雜的透明度控制,比如基於時間的淡入淡出或者其他視覺效果,你可能需要創建自定義的Shader。Spine-Unity支持使用自定義Shader,你可以根據需要調整透明度。確保在導出Spine資源時選擇適合你Shader的設置,比如使用直接Alpha工作流程。

總之,根據你的需求,你可以選擇直接通過組件屬性調整透明度,或者使用更高級的方法如SkeletonRenderTexture組件或自定義Shader。確保你的Spine和Spine-Unity版本是最新的,以便利用最新的功能和修復。

  • Harald が「いいね」しました。

@markcky2433 In general when you need correct semi-transparent skeletons, using SkeletonRenderTexture is the recommended way.

Apart from that you can also set the SkeletonAnimation.Skeleton.A value.
Another alternative is to set the skeleton Material's Color property, also possible via MaterialPropertyBlock, see the documentation here.

    感謝回覆,但我看了範例文件後仍然不是很確定要怎麼用。
    感覺還是有點複雜,不確定我需要用哪些程式碼進行替換,尤其是SkeletonRenderTexture,如果有更清楚的說明或更簡單的操作方式就太感謝了。

    • Misaki がこの投稿に返信しました。

      markcky2433 The SkletonRenderTextureFadeout provided by the spine-unity runtime is pretty easy to use, so I'm not sure what you're having trouble with.

      To be clear, I have uploaded a video showing how to use it here:

      First add a SkeletonRenderTexture component to the skeleton GameObject you want to fade out, then add a SkeletonRenderTextureFadeout. This will start the fade-out as soon as it is enabled, so you might want to attach it with it disabled by default and enable it when you perform the fade out effect. SkeletonRenderTexture should also be disabled by default, as it will add extra performance cost if it is always enabled.
      In the video above, I manually enabled the SkeletonRenderTextureFadeout component to make it easier to see what is happening, but you can easily get the same effect by simply enabling it from your code.
      (When the SkeletonRenderTextureFadeout is enabled, it enables the SkeletonRenderTexture attached to the same GameObject.)

      Also, at the end of the fadeout, the event delegate OnFadeoutComplete is called, to which you can bind, for example, a method that disables or destroys the entire GameObject.


      The fade in effect should be achieved with only a slight modification to the SkeltonRenderTextureFadeout.cs. For example, you can change the lines 80 through 82 as follows:

      float fadeinAlpha = (fadeinSeconds - fadeinSecondsRemaining) / fadeinSeconds;
      #if HAS_VECTOR_INT
      	skeletonRenderTexture.color.a = fadeinAlpha;

      (Assuming that all strings fadeout in variable names etc. in the script are replaced to fadein.)

        Thank you Harald and Misaki, I'm successfully fade in and fade out my skeleton texture now.🥰

        • Misaki がこの投稿に返信しました。
        • Harald が「いいね」しました。

          markcky2433 Glad to hear that! Thank you for getting back to us! 🙂