init
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: RenderQuadMaterial
|
||||
m_Shader: {fileID: 4800000, guid: 1e0cc951f440af74dacaf86ac4ae2602, type: 3}
|
||||
m_ShaderKeywords: _ALPHAPREMULTIPLY_ON _USE8NEIGHBOURHOOD_ON
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Floats:
|
||||
- _BumpScale: 1
|
||||
- _Cutoff: 0.5
|
||||
- _DarkColorAlphaAdditive: 0
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 10
|
||||
- _GlossMapScale: 1
|
||||
- _Glossiness: 0.5
|
||||
- _GlossyReflections: 1
|
||||
- _Metallic: 0
|
||||
- _Mode: 3
|
||||
- _OcclusionStrength: 1
|
||||
- _OutlineMipLevel: 0
|
||||
- _OutlineReferenceTexWidth: 1024
|
||||
- _OutlineSmoothness: 1
|
||||
- _OutlineWidth: 3
|
||||
- _Parallax: 0.02
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _SrcBlend: 1
|
||||
- _StencilComp: 8
|
||||
- _StencilRef: 1
|
||||
- _StraightAlphaInput: 0
|
||||
- _ThresholdEnd: 0.25
|
||||
- _UVSec: 0
|
||||
- _Use8Neighbourhood: 1
|
||||
- _ZWrite: 0
|
||||
m_Colors:
|
||||
- _Black: {r: 0, g: 0, b: 0, a: 0}
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _OutlineColor: {r: 1, g: 1, b: 0, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c507f887c6274a44a603d96e0eabf2a
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,104 @@
|
||||
// Simple shader for e.g. a Quad that renders a RenderTexture.
|
||||
// Texture color is multiplied by a color property, mostly for alpha fadeout.
|
||||
Shader "Spine/RenderQuad" {
|
||||
Properties{
|
||||
_Color("Color", Color) = (1,1,1,1)
|
||||
[NoScaleOffset] _MainTex("MainTex", 2D) = "white" {}
|
||||
_Cutoff("Shadow alpha cutoff", Range(0,1)) = 0.1
|
||||
[HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
|
||||
[HideInInspector][Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default
|
||||
}
|
||||
SubShader{
|
||||
Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane" }
|
||||
Blend One OneMinusSrcAlpha
|
||||
Cull Off
|
||||
ZWrite Off
|
||||
Lighting Off
|
||||
|
||||
Stencil {
|
||||
Ref[_StencilRef]
|
||||
Comp[_StencilComp]
|
||||
Pass Keep
|
||||
}
|
||||
|
||||
Pass {
|
||||
Name "Normal"
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
sampler2D _MainTex;
|
||||
float4 _Color;
|
||||
|
||||
struct VertexInput {
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 vertexColor : COLOR;
|
||||
};
|
||||
|
||||
struct VertexOutput {
|
||||
float4 pos : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 vertexColor : COLOR;
|
||||
};
|
||||
|
||||
VertexOutput vert(VertexInput v) {
|
||||
VertexOutput o = (VertexOutput)0;
|
||||
o.uv = v.uv;
|
||||
o.vertexColor = v.vertexColor;
|
||||
o.pos = UnityObjectToClipPos(v.vertex);
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 frag(VertexOutput i) : SV_Target {
|
||||
float4 texColor = tex2D(_MainTex,i.uv);
|
||||
_Color.rgb *= _Color.a;
|
||||
return texColor * _Color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
|
||||
Pass {
|
||||
Name "Caster"
|
||||
Tags { "LightMode" = "ShadowCaster" }
|
||||
Offset 1, 1
|
||||
ZWrite On
|
||||
ZTest LEqual
|
||||
|
||||
Fog { Mode Off }
|
||||
Cull Off
|
||||
Lighting Off
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma multi_compile_shadowcaster
|
||||
#pragma fragmentoption ARB_precision_hint_fastest
|
||||
#include "UnityCG.cginc"
|
||||
sampler2D _MainTex;
|
||||
fixed _Cutoff;
|
||||
|
||||
struct VertexOutput {
|
||||
V2F_SHADOW_CASTER;
|
||||
float4 uvAndAlpha : TEXCOORD1;
|
||||
};
|
||||
|
||||
VertexOutput vert(appdata_base v, float4 vertexColor : COLOR) {
|
||||
VertexOutput o;
|
||||
o.uvAndAlpha = v.texcoord;
|
||||
o.uvAndAlpha.a = vertexColor.a;
|
||||
TRANSFER_SHADOW_CASTER(o)
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 frag(VertexOutput i) : SV_Target {
|
||||
fixed4 texcol = tex2D(_MainTex, i.uvAndAlpha.xy);
|
||||
clip(texcol.a* i.uvAndAlpha.a - _Cutoff);
|
||||
SHADOW_CASTER_FRAGMENT(i)
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
FallBack "Diffuse"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1e0cc951f440af74dacaf86ac4ae2602
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,248 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2022, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
|
||||
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
#define HAS_FORCE_RENDER_OFF
|
||||
#endif
|
||||
|
||||
#if UNITY_2017_2_OR_NEWER
|
||||
#define HAS_VECTOR_INT
|
||||
#endif
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace Spine.Unity.Examples {
|
||||
|
||||
/// <summary>
|
||||
/// When enabled, this component renders a skeleton to a RenderTexture and
|
||||
/// then draws this RenderTexture at a quad of the same size.
|
||||
/// This allows changing transparency at a single quad, which produces a more
|
||||
/// natural fadeout effect.
|
||||
/// Note: It is recommended to keep this component disabled as much as possible
|
||||
/// because of the additional rendering overhead. Only enable it when alpha blending is required.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(SkeletonRenderer))]
|
||||
public class SkeletonRenderTexture : MonoBehaviour {
|
||||
#if HAS_VECTOR_INT
|
||||
public Color color = Color.white;
|
||||
public Material quadMaterial;
|
||||
public Camera targetCamera;
|
||||
public int maxRenderTextureSize = 1024;
|
||||
protected SkeletonRenderer skeletonRenderer;
|
||||
protected MeshRenderer meshRenderer;
|
||||
protected MeshFilter meshFilter;
|
||||
public GameObject quad;
|
||||
protected MeshRenderer quadMeshRenderer;
|
||||
protected MeshFilter quadMeshFilter;
|
||||
protected Mesh quadMesh;
|
||||
public RenderTexture renderTexture;
|
||||
|
||||
private CommandBuffer commandBuffer;
|
||||
private MaterialPropertyBlock propertyBlock;
|
||||
private readonly List<Material> materials = new List<Material>();
|
||||
|
||||
protected Vector2Int requiredRenderTextureSize;
|
||||
protected Vector2Int allocatedRenderTextureSize;
|
||||
|
||||
void Awake () {
|
||||
meshRenderer = this.GetComponent<MeshRenderer>();
|
||||
meshFilter = this.GetComponent<MeshFilter>();
|
||||
skeletonRenderer = this.GetComponent<SkeletonRenderer>();
|
||||
if (targetCamera == null)
|
||||
targetCamera = Camera.main;
|
||||
|
||||
commandBuffer = new CommandBuffer();
|
||||
propertyBlock = new MaterialPropertyBlock();
|
||||
|
||||
CreateQuadChild();
|
||||
}
|
||||
|
||||
void OnDestroy () {
|
||||
if (renderTexture)
|
||||
RenderTexture.ReleaseTemporary(renderTexture);
|
||||
}
|
||||
|
||||
void CreateQuadChild () {
|
||||
quad = new GameObject(this.name + " RenderTexture", typeof(MeshRenderer), typeof(MeshFilter));
|
||||
quad.transform.SetParent(this.transform.parent, false);
|
||||
quadMeshRenderer = quad.GetComponent<MeshRenderer>();
|
||||
quadMeshFilter = quad.GetComponent<MeshFilter>();
|
||||
|
||||
quadMesh = new Mesh();
|
||||
quadMesh.MarkDynamic();
|
||||
quadMesh.name = "RenderTexture Quad";
|
||||
quadMesh.hideFlags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor;
|
||||
|
||||
if (quadMaterial != null)
|
||||
quadMeshRenderer.material = new Material(quadMaterial);
|
||||
else
|
||||
quadMeshRenderer.material = new Material(Shader.Find("Spine/RenderQuad"));
|
||||
}
|
||||
|
||||
void OnEnable () {
|
||||
skeletonRenderer.OnMeshAndMaterialsUpdated += RenderOntoQuad;
|
||||
#if HAS_FORCE_RENDER_OFF
|
||||
meshRenderer.forceRenderingOff = true;
|
||||
#else
|
||||
Debug.LogError("This component requires Unity 2019.3 or newer for meshRenderer.forceRenderingOff. " +
|
||||
"Otherwise you will see the mesh rendered twice.");
|
||||
#endif
|
||||
if (quadMeshRenderer)
|
||||
quadMeshRenderer.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
void OnDisable () {
|
||||
skeletonRenderer.OnMeshAndMaterialsUpdated -= RenderOntoQuad;
|
||||
#if HAS_FORCE_RENDER_OFF
|
||||
meshRenderer.forceRenderingOff = false;
|
||||
#endif
|
||||
if (quadMeshRenderer)
|
||||
quadMeshRenderer.gameObject.SetActive(false);
|
||||
if (renderTexture)
|
||||
RenderTexture.ReleaseTemporary(renderTexture);
|
||||
allocatedRenderTextureSize = Vector2Int.zero;
|
||||
}
|
||||
|
||||
void RenderOntoQuad (SkeletonRenderer skeletonRenderer) {
|
||||
PrepareForMesh();
|
||||
RenderToRenderTexture();
|
||||
AssignAtQuad();
|
||||
}
|
||||
|
||||
protected void PrepareForMesh () {
|
||||
Bounds boundsLocalSpace = meshFilter.sharedMesh.bounds;
|
||||
Vector3 meshMinWorldSpace = transform.TransformPoint(boundsLocalSpace.min);
|
||||
Vector3 meshMaxWorldSpace = transform.TransformPoint(boundsLocalSpace.max);
|
||||
Vector3 meshMinXMaxYWorldSpace = new Vector3(meshMinWorldSpace.x, meshMaxWorldSpace.y);
|
||||
Vector3 meshMaxXMinYWorldSpace = new Vector3(meshMaxWorldSpace.x, meshMinWorldSpace.y);
|
||||
|
||||
// We need to get the min/max of all four corners, close position and rotation of the skeleton
|
||||
// in combination with perspective projection otherwise might lead to incorrect screen space min/max.
|
||||
Vector3 meshMinProjected = targetCamera.WorldToScreenPoint(meshMinWorldSpace);
|
||||
Vector3 meshMaxProjected = targetCamera.WorldToScreenPoint(meshMaxWorldSpace);
|
||||
Vector3 meshMinXMaxYProjected = targetCamera.WorldToScreenPoint(meshMinXMaxYWorldSpace);
|
||||
Vector3 meshMaxXMinYProjected = targetCamera.WorldToScreenPoint(meshMaxXMinYWorldSpace);
|
||||
// To handle 180 degree rotation and thus min/max inversion, we get min/max of all four corners
|
||||
Vector3 meshMinScreenSpace =
|
||||
Vector3.Min(meshMinProjected, Vector3.Min(meshMaxProjected,
|
||||
Vector3.Min(meshMinXMaxYProjected, meshMaxXMinYProjected)));
|
||||
Vector3 meshMaxScreenSpace =
|
||||
Vector3.Max(meshMinProjected, Vector3.Max(meshMaxProjected,
|
||||
Vector3.Max(meshMinXMaxYProjected, meshMaxXMinYProjected)));
|
||||
|
||||
requiredRenderTextureSize = new Vector2Int(
|
||||
Mathf.Min(maxRenderTextureSize, Mathf.CeilToInt(Mathf.Abs(meshMaxScreenSpace.x - meshMinScreenSpace.x))),
|
||||
Mathf.Min(maxRenderTextureSize, Mathf.CeilToInt(Mathf.Abs(meshMaxScreenSpace.y - meshMinScreenSpace.y))));
|
||||
|
||||
PrepareRenderTexture();
|
||||
PrepareCommandBuffer(meshMinWorldSpace, meshMaxWorldSpace);
|
||||
}
|
||||
|
||||
protected void PrepareCommandBuffer (Vector3 meshMinWorldSpace, Vector3 meshMaxWorldSpace) {
|
||||
commandBuffer.Clear();
|
||||
commandBuffer.SetRenderTarget(renderTexture);
|
||||
commandBuffer.ClearRenderTarget(true, true, Color.clear);
|
||||
|
||||
Matrix4x4 projectionMatrix = Matrix4x4.Ortho(
|
||||
meshMinWorldSpace.x, meshMaxWorldSpace.x,
|
||||
meshMinWorldSpace.y, meshMaxWorldSpace.y,
|
||||
float.MinValue, float.MaxValue);
|
||||
|
||||
commandBuffer.SetProjectionMatrix(projectionMatrix);
|
||||
commandBuffer.SetViewport(new Rect(Vector2.zero, requiredRenderTextureSize));
|
||||
}
|
||||
|
||||
protected void RenderToRenderTexture () {
|
||||
meshRenderer.GetPropertyBlock(propertyBlock);
|
||||
meshRenderer.GetSharedMaterials(materials);
|
||||
|
||||
for (int i = 0; i < materials.Count; i++)
|
||||
commandBuffer.DrawMesh(meshFilter.sharedMesh, transform.localToWorldMatrix,
|
||||
materials[i], meshRenderer.subMeshStartIndex + i, -1, propertyBlock);
|
||||
Graphics.ExecuteCommandBuffer(commandBuffer);
|
||||
}
|
||||
|
||||
protected void AssignAtQuad () {
|
||||
Vector2 min = meshFilter.sharedMesh.bounds.min;
|
||||
Vector2 max = meshFilter.sharedMesh.bounds.max;
|
||||
|
||||
Vector3[] vertices = new Vector3[4] {
|
||||
new Vector3(min.x, min.y, 0),
|
||||
new Vector3(max.x, min.y, 0),
|
||||
new Vector3(min.x, max.y, 0),
|
||||
new Vector3(max.x, max.y, 0)
|
||||
};
|
||||
quadMesh.vertices = vertices;
|
||||
|
||||
int[] indices = new int[6] { 0, 2, 1, 2, 3, 1 };
|
||||
quadMesh.triangles = indices;
|
||||
|
||||
Vector3[] normals = new Vector3[4] {
|
||||
-Vector3.forward,
|
||||
-Vector3.forward,
|
||||
-Vector3.forward,
|
||||
-Vector3.forward
|
||||
};
|
||||
quadMesh.normals = normals;
|
||||
|
||||
float maxU = (float)(requiredRenderTextureSize.x) / allocatedRenderTextureSize.x;
|
||||
float maxV = (float)(requiredRenderTextureSize.y) / allocatedRenderTextureSize.y;
|
||||
Vector2[] uv = new Vector2[4] {
|
||||
new Vector2(0, 0),
|
||||
new Vector2(maxU, 0),
|
||||
new Vector2(0, maxV),
|
||||
new Vector2(maxU, maxV)
|
||||
};
|
||||
quadMesh.uv = uv;
|
||||
quadMeshFilter.mesh = quadMesh;
|
||||
quadMeshRenderer.sharedMaterial.mainTexture = this.renderTexture;
|
||||
quadMeshRenderer.sharedMaterial.color = color;
|
||||
|
||||
quadMeshRenderer.transform.position = this.transform.position;
|
||||
quadMeshRenderer.transform.rotation = this.transform.rotation;
|
||||
quadMeshRenderer.transform.localScale = this.transform.localScale;
|
||||
}
|
||||
|
||||
protected void PrepareRenderTexture () {
|
||||
Vector2Int textureSize = new Vector2Int(
|
||||
Mathf.NextPowerOfTwo(requiredRenderTextureSize.x),
|
||||
Mathf.NextPowerOfTwo(requiredRenderTextureSize.y));
|
||||
|
||||
if (textureSize != allocatedRenderTextureSize) {
|
||||
if (renderTexture)
|
||||
RenderTexture.ReleaseTemporary(renderTexture);
|
||||
renderTexture = RenderTexture.GetTemporary(textureSize.x, textureSize.y);
|
||||
allocatedRenderTextureSize = textureSize;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 25e6ceb271c9af848ae53f2af1073d0d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,88 @@
|
||||
/******************************************************************************
|
||||
* Spine Runtimes License Agreement
|
||||
* Last updated January 1, 2020. Replaces all prior versions.
|
||||
*
|
||||
* Copyright (c) 2013-2022, Esoteric Software LLC
|
||||
*
|
||||
* Integration of the Spine Runtimes into software or otherwise creating
|
||||
* derivative works of the Spine Runtimes is permitted under the terms and
|
||||
* conditions of Section 2 of the Spine Editor License Agreement:
|
||||
* http://esotericsoftware.com/spine-editor-license
|
||||
*
|
||||
* Otherwise, it is permitted to integrate the Spine Runtimes into software
|
||||
* or otherwise create derivative works of the Spine Runtimes (collectively,
|
||||
* "Products"), provided that each user of the Products must obtain their own
|
||||
* Spine Editor license and redistribution of the Products in any form must
|
||||
* include this license and copyright notice.
|
||||
*
|
||||
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
|
||||
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*****************************************************************************/
|
||||
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
#define HAS_FORCE_RENDER_OFF
|
||||
#endif
|
||||
|
||||
#if UNITY_2017_2_OR_NEWER
|
||||
#define HAS_VECTOR_INT
|
||||
#endif
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Spine.Unity.Examples {
|
||||
|
||||
/// <summary>
|
||||
/// A simple fadeout component that uses a <see cref="SkeletonRenderTexture"/> for transparency fadeout.
|
||||
/// Attach a <see cref="SkeletonRenderTexture"/> and this component to a skeleton GameObject and disable both
|
||||
/// components initially and keep them disabled during normal gameplay. When you need to start fadeout,
|
||||
/// enable this component.
|
||||
/// At the end of the fadeout, the event delegate <c>OnFadeoutComplete</c> is called, to which you can bind e.g.
|
||||
/// a method that disables or destroys the entire GameObject.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(SkeletonRenderTexture))]
|
||||
public class SkeletonRenderTextureFadeout : MonoBehaviour {
|
||||
SkeletonRenderTexture skeletonRenderTexture;
|
||||
|
||||
public float fadeoutSeconds = 2.0f;
|
||||
protected float fadeoutSecondsRemaining;
|
||||
|
||||
public delegate void FadeoutCallback (SkeletonRenderTextureFadeout skeleton);
|
||||
public event FadeoutCallback OnFadeoutComplete;
|
||||
|
||||
protected void Awake () {
|
||||
skeletonRenderTexture = this.GetComponent<SkeletonRenderTexture>();
|
||||
}
|
||||
|
||||
protected void OnEnable () {
|
||||
fadeoutSecondsRemaining = fadeoutSeconds;
|
||||
skeletonRenderTexture.enabled = true;
|
||||
}
|
||||
|
||||
protected void Update () {
|
||||
if (fadeoutSecondsRemaining == 0)
|
||||
return;
|
||||
|
||||
fadeoutSecondsRemaining -= Time.deltaTime;
|
||||
if (fadeoutSecondsRemaining <= 0) {
|
||||
fadeoutSecondsRemaining = 0;
|
||||
if (OnFadeoutComplete != null)
|
||||
OnFadeoutComplete(this);
|
||||
return;
|
||||
}
|
||||
float fadeoutAlpha = fadeoutSecondsRemaining / fadeoutSeconds;
|
||||
#if HAS_VECTOR_INT
|
||||
skeletonRenderTexture.color.a = fadeoutAlpha;
|
||||
#else
|
||||
Debug.LogError("The SkeletonRenderTexture component requires Unity 2017.2 or newer.");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5fc94f89310427643babb41e000a8462
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user