备份CatanBuilding瘦身独立工程

This commit is contained in:
JSD\13999
2026-05-26 16:15:54 +08:00
commit 2d0e6a61b7
12001 changed files with 2431925 additions and 0 deletions

View File

@@ -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: []

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4c507f887c6274a44a603d96e0eabf2a
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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"
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 1e0cc951f440af74dacaf86ac4ae2602
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,260 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated July 28, 2023. Replaces all prior versions.
*
* Copyright (c) 2013-2023, 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_2017_2_OR_NEWER
#define HAS_VECTOR2INT
#endif
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;
namespace Spine.Unity.Examples {
/// <summary>
/// When enabled, this component renders a skeleton to a RenderTexture and
/// then draws this RenderTexture at a UI RawImage 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(SkeletonGraphic))]
public class SkeletonGraphicRenderTexture : SkeletonRenderTextureBase {
#if HAS_VECTOR2INT
[System.Serializable]
public struct TextureMaterialPair {
public Texture texture;
public Material material;
public TextureMaterialPair (Texture texture, Material material) {
this.texture = texture;
this.material = material;
}
}
public RectTransform customRenderRect;
protected SkeletonGraphic skeletonGraphic;
public List<TextureMaterialPair> meshRendererMaterialForTexture = new List<TextureMaterialPair>();
protected CanvasRenderer quadCanvasRenderer;
protected RawImage quadRawImage;
protected readonly Vector3[] worldCorners = new Vector3[4];
protected override void Awake () {
base.Awake();
skeletonGraphic = this.GetComponent<SkeletonGraphic>();
if (targetCamera == null) {
targetCamera = skeletonGraphic.canvas.worldCamera;
if (targetCamera == null)
targetCamera = Camera.main;
}
CreateQuadChild();
}
void CreateQuadChild () {
quad = new GameObject(this.name + " RenderTexture", typeof(CanvasRenderer), typeof(RawImage));
quad.transform.SetParent(this.transform.parent, false);
quadCanvasRenderer = quad.GetComponent<CanvasRenderer>();
quadRawImage = quad.GetComponent<RawImage>();
quadMesh = new Mesh();
quadMesh.MarkDynamic();
quadMesh.name = "RenderTexture Quad";
quadMesh.hideFlags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor;
}
void Reset () {
skeletonGraphic = this.GetComponent<SkeletonGraphic>();
AtlasAssetBase[] atlasAssets = skeletonGraphic.SkeletonDataAsset.atlasAssets;
for (int i = 0; i < atlasAssets.Length; ++i) {
foreach (Material material in atlasAssets[i].Materials) {
if (material.mainTexture != null) {
meshRendererMaterialForTexture.Add(
new TextureMaterialPair(material.mainTexture, material));
}
}
}
}
void OnEnable () {
skeletonGraphic.OnInstructionsPrepared += PrepareQuad;
skeletonGraphic.AssignMeshOverrideSingleRenderer += RenderSingleMeshToRenderTexture;
skeletonGraphic.AssignMeshOverrideMultipleRenderers += RenderMultipleMeshesToRenderTexture;
skeletonGraphic.disableMeshAssignmentOnOverride = true;
skeletonGraphic.OnMeshAndMaterialsUpdated += RenderOntoQuad;
List<CanvasRenderer> canvasRenderers = skeletonGraphic.canvasRenderers;
for (int i = 0; i < canvasRenderers.Count; ++i)
canvasRenderers[i].cull = true;
if (quadCanvasRenderer)
quadCanvasRenderer.gameObject.SetActive(true);
}
void OnDisable () {
skeletonGraphic.OnInstructionsPrepared -= PrepareQuad;
skeletonGraphic.AssignMeshOverrideSingleRenderer -= RenderSingleMeshToRenderTexture;
skeletonGraphic.AssignMeshOverrideMultipleRenderers -= RenderMultipleMeshesToRenderTexture;
skeletonGraphic.disableMeshAssignmentOnOverride = false;
skeletonGraphic.OnMeshAndMaterialsUpdated -= RenderOntoQuad;
List<CanvasRenderer> canvasRenderers = skeletonGraphic.canvasRenderers;
for (int i = 0; i < canvasRenderers.Count; ++i)
canvasRenderers[i].cull = false;
if (quadCanvasRenderer)
quadCanvasRenderer.gameObject.SetActive(false);
if (renderTexture)
RenderTexture.ReleaseTemporary(renderTexture);
allocatedRenderTextureSize = Vector2Int.zero;
}
void PrepareQuad (SkeletonRendererInstruction instruction) {
PrepareForMesh();
SetupQuad();
}
void RenderOntoQuad (SkeletonGraphic skeletonRenderer) {
AssignAtQuad();
}
protected void PrepareForMesh () {
// We need to get the min/max of all four corners, rotation of the skeleton
// in combination with perspective projection otherwise might lead to incorrect
// screen space min/max.
RectTransform rectTransform = customRenderRect ? customRenderRect : skeletonGraphic.rectTransform;
rectTransform.GetWorldCorners(worldCorners);
RenderMode canvasRenderMode = skeletonGraphic.canvas.renderMode;
Vector3 screenCorner0, screenCorner1, screenCorner2, screenCorner3;
// note: world corners are ordered bottom left, top left, top right, bottom right.
// This corresponds to 0, 3, 1, 2 in our desired order.
if (canvasRenderMode == RenderMode.ScreenSpaceOverlay) {
screenCorner0 = worldCorners[0];
screenCorner1 = worldCorners[3];
screenCorner2 = worldCorners[1];
screenCorner3 = worldCorners[2];
} else {
screenCorner0 = targetCamera.WorldToScreenPoint(worldCorners[0]);
screenCorner1 = targetCamera.WorldToScreenPoint(worldCorners[3]);
screenCorner2 = targetCamera.WorldToScreenPoint(worldCorners[1]);
screenCorner3 = targetCamera.WorldToScreenPoint(worldCorners[2]);
}
// To avoid perspective distortion when rotated, we project all vertices
// onto a plane parallel to the view frustum near plane.
// Avoids the requirement of 'noperspective' vertex attribute interpolation modifier in shaders.
float averageScreenDepth = (screenCorner0.z + screenCorner1.z + screenCorner2.z + screenCorner3.z) / 4.0f;
screenCorner0.z = screenCorner1.z = screenCorner2.z = screenCorner3.z = averageScreenDepth;
if (canvasRenderMode == RenderMode.ScreenSpaceOverlay) {
worldCornerNoDistortion0 = screenCorner0;
worldCornerNoDistortion1 = screenCorner1;
worldCornerNoDistortion2 = screenCorner2;
worldCornerNoDistortion3 = screenCorner3;
} else {
worldCornerNoDistortion0 = targetCamera.ScreenToWorldPoint(screenCorner0);
worldCornerNoDistortion1 = targetCamera.ScreenToWorldPoint(screenCorner1);
worldCornerNoDistortion2 = targetCamera.ScreenToWorldPoint(screenCorner2);
worldCornerNoDistortion3 = targetCamera.ScreenToWorldPoint(screenCorner3);
}
Vector3 screenSpaceMin, screenSpaceMax;
PrepareTextureMapping(out screenSpaceMin, out screenSpaceMax,
screenCorner0, screenCorner1, screenCorner2, screenCorner3);
PrepareCommandBuffer(targetCamera, screenSpaceMin, screenSpaceMax);
}
protected Material MeshRendererMaterialForTexture (Texture texture) {
return meshRendererMaterialForTexture.Find(x => x.texture == texture).material;
}
protected void RenderSingleMeshToRenderTexture (Mesh mesh, Material graphicMaterial, Texture texture) {
Material meshRendererMaterial = MeshRendererMaterialForTexture(texture);
commandBuffer.DrawMesh(mesh, transform.localToWorldMatrix, meshRendererMaterial, 0, -1);
Graphics.ExecuteCommandBuffer(commandBuffer);
}
protected void RenderMultipleMeshesToRenderTexture (int meshCount,
Mesh[] meshes, Material[] graphicMaterials, Texture[] textures) {
for (int i = 0; i < meshCount; ++i) {
Material meshRendererMaterial = MeshRendererMaterialForTexture(textures[i]);
commandBuffer.DrawMesh(meshes[i], transform.localToWorldMatrix, meshRendererMaterial, 0, -1);
}
Graphics.ExecuteCommandBuffer(commandBuffer);
}
protected void SetupQuad () {
quadRawImage.texture = this.renderTexture;
quadRawImage.color = color;
quadCanvasRenderer.SetColor(color);
RectTransform srcRectTransform = skeletonGraphic.rectTransform;
RectTransform dstRectTransform = quadRawImage.rectTransform;
dstRectTransform.anchorMin = srcRectTransform.anchorMin;
dstRectTransform.anchorMax = srcRectTransform.anchorMax;
dstRectTransform.anchoredPosition = srcRectTransform.anchoredPosition;
dstRectTransform.pivot = srcRectTransform.pivot;
dstRectTransform.localScale = srcRectTransform.localScale;
dstRectTransform.sizeDelta = srcRectTransform.sizeDelta;
dstRectTransform.rotation = srcRectTransform.rotation;
}
protected void PrepareCommandBuffer (Camera targetCamera, Vector3 screenSpaceMin, Vector3 screenSpaceMax) {
commandBuffer.Clear();
commandBuffer.SetRenderTarget(renderTexture);
commandBuffer.ClearRenderTarget(true, true, Color.clear);
Rect canvasRect = skeletonGraphic.canvas.pixelRect;
Matrix4x4 projectionMatrix = Matrix4x4.Ortho(
canvasRect.x, canvasRect.x + canvasRect.width,
canvasRect.y, canvasRect.y + canvasRect.height,
float.MinValue, float.MaxValue);
RenderMode canvasRenderMode = skeletonGraphic.canvas.renderMode;
if (canvasRenderMode == RenderMode.ScreenSpaceOverlay) {
commandBuffer.SetViewMatrix(Matrix4x4.identity);
commandBuffer.SetProjectionMatrix(projectionMatrix);
} else {
commandBuffer.SetViewMatrix(targetCamera.worldToCameraMatrix);
commandBuffer.SetProjectionMatrix(targetCamera.projectionMatrix);
}
Vector2 targetCameraViewportSize = targetCamera.pixelRect.size;
Rect viewportRect = new Rect(-screenSpaceMin * downScaleFactor, targetCameraViewportSize * downScaleFactor);
commandBuffer.SetViewport(viewportRect);
}
protected override void AssignMeshAtRenderer () {
quadCanvasRenderer.SetMesh(quadMesh);
}
#endif // HAS_VECTOR2INT
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6cbe1f11426513d49ad8e21e9d6643f7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,202 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated July 28, 2023. Replaces all prior versions.
*
* Copyright (c) 2013-2023, 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_2018_2_OR_NEWER
#define HAS_GET_SHARED_MATERIALS
#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 : SkeletonRenderTextureBase {
#if HAS_GET_SHARED_MATERIALS
public Material quadMaterial;
protected SkeletonRenderer skeletonRenderer;
protected MeshRenderer meshRenderer;
protected MeshFilter meshFilter;
protected MeshRenderer quadMeshRenderer;
protected MeshFilter quadMeshFilter;
private MaterialPropertyBlock propertyBlock;
private readonly List<Material> materials = new List<Material>();
protected override void Awake () {
base.Awake();
meshRenderer = this.GetComponent<MeshRenderer>();
meshFilter = this.GetComponent<MeshFilter>();
skeletonRenderer = this.GetComponent<SkeletonRenderer>();
if (targetCamera == null)
targetCamera = Camera.main;
propertyBlock = new MaterialPropertyBlock();
CreateQuadChild();
}
#if UNITY_EDITOR
protected void Reset () {
string[] folders = { "Assets", "Packages" };
string[] assets = UnityEditor.AssetDatabase.FindAssets("t:material RenderQuadMaterial", folders);
if (assets.Length > 0) {
string materialPath = UnityEditor.AssetDatabase.GUIDToAssetPath(assets[0]);
quadMaterial = UnityEditor.AssetDatabase.LoadAssetAtPath<Material>(materialPath);
}
}
#endif
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>();
quadMeshRenderer.sortingOrder = meshRenderer.sortingOrder;
quadMeshRenderer.sortingLayerID = meshRenderer.sortingLayerID;
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 () {
// We need to get the min/max of all four corners, rotation of the skeleton
// in combination with perspective projection otherwise might lead to incorrect
// screen space min/max.
Bounds boundsLocalSpace = meshFilter.sharedMesh.bounds;
Vector3 localCorner0 = boundsLocalSpace.min;
Vector3 localCorner3 = boundsLocalSpace.max;
Vector3 localCorner1 = new Vector3(localCorner0.x, localCorner3.y, localCorner0.z);
Vector3 localCorner2 = new Vector3(localCorner3.x, localCorner0.y, localCorner3.z);
Vector3 worldCorner0 = transform.TransformPoint(localCorner0);
Vector3 worldCorner1 = transform.TransformPoint(localCorner1);
Vector3 worldCorner2 = transform.TransformPoint(localCorner2);
Vector3 worldCorner3 = transform.TransformPoint(localCorner3);
Vector3 screenCorner0 = targetCamera.WorldToScreenPoint(worldCorner0);
Vector3 screenCorner1 = targetCamera.WorldToScreenPoint(worldCorner1);
Vector3 screenCorner2 = targetCamera.WorldToScreenPoint(worldCorner2);
Vector3 screenCorner3 = targetCamera.WorldToScreenPoint(worldCorner3);
// To avoid perspective distortion when rotated, we project all vertices
// onto a plane parallel to the view frustum near plane.
// Avoids the requirement of 'noperspective' vertex attribute interpolation modifier in shaders.
float averageScreenDepth = (screenCorner0.z + screenCorner1.z + screenCorner2.z + screenCorner3.z) / 4.0f;
screenCorner0.z = screenCorner1.z = screenCorner2.z = screenCorner3.z = averageScreenDepth;
worldCornerNoDistortion0 = targetCamera.ScreenToWorldPoint(screenCorner0);
worldCornerNoDistortion1 = targetCamera.ScreenToWorldPoint(screenCorner1);
worldCornerNoDistortion2 = targetCamera.ScreenToWorldPoint(screenCorner2);
worldCornerNoDistortion3 = targetCamera.ScreenToWorldPoint(screenCorner3);
Vector3 screenSpaceMin, screenSpaceMax;
PrepareTextureMapping(out screenSpaceMin, out screenSpaceMax,
screenCorner0, screenCorner1, screenCorner2, screenCorner3);
PrepareCommandBuffer(targetCamera, screenSpaceMin, screenSpaceMax);
}
protected void PrepareCommandBuffer (Camera targetCamera, Vector3 screenSpaceMin, Vector3 screenSpaceMax) {
commandBuffer.Clear();
commandBuffer.SetRenderTarget(renderTexture);
commandBuffer.ClearRenderTarget(true, true, Color.clear);
commandBuffer.SetProjectionMatrix(targetCamera.projectionMatrix);
commandBuffer.SetViewMatrix(targetCamera.worldToCameraMatrix);
Vector2 targetCameraViewportSize = targetCamera.pixelRect.size;
Rect viewportRect = new Rect(-screenSpaceMin * downScaleFactor, targetCameraViewportSize * downScaleFactor);
commandBuffer.SetViewport(viewportRect);
}
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 override void AssignMeshAtRenderer () {
quadMeshFilter.mesh = quadMesh;
quadMeshRenderer.sharedMaterial.mainTexture = this.renderTexture;
quadMeshRenderer.sharedMaterial.color = color;
}
#endif
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 25e6ceb271c9af848ae53f2af1073d0d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,164 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated July 28, 2023. Replaces all prior versions.
*
* Copyright (c) 2013-2023, 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_2017_2_OR_NEWER
#define HAS_VECTOR2INT
#endif
using System;
using UnityEngine;
using UnityEngine.Rendering;
namespace Spine.Unity.Examples {
public abstract class SkeletonRenderTextureBase : MonoBehaviour {
#if HAS_VECTOR2INT
public Color color = Color.white;
public int maxRenderTextureSize = 1024;
public GameObject quad;
protected Mesh quadMesh;
public RenderTexture renderTexture;
public Camera targetCamera;
protected CommandBuffer commandBuffer;
protected Vector2Int screenSize;
protected Vector2Int usedRenderTextureSize;
protected Vector2Int allocatedRenderTextureSize;
protected Vector2 downScaleFactor = Vector2.one;
protected Vector3 worldCornerNoDistortion0;
protected Vector3 worldCornerNoDistortion1;
protected Vector3 worldCornerNoDistortion2;
protected Vector3 worldCornerNoDistortion3;
protected Vector2 uvCorner0;
protected Vector2 uvCorner1;
protected Vector2 uvCorner2;
protected Vector2 uvCorner3;
protected virtual void Awake () {
commandBuffer = new CommandBuffer();
}
void OnDestroy () {
if (renderTexture)
RenderTexture.ReleaseTemporary(renderTexture);
}
protected void PrepareTextureMapping (out Vector3 screenSpaceMin, out Vector3 screenSpaceMax,
Vector3 screenCorner0, Vector3 screenCorner1, Vector3 screenCorner2, Vector3 screenCorner3) {
screenSpaceMin =
Vector3.Min(screenCorner0, Vector3.Min(screenCorner1,
Vector3.Min(screenCorner2, screenCorner3)));
screenSpaceMax =
Vector3.Max(screenCorner0, Vector3.Max(screenCorner1,
Vector3.Max(screenCorner2, screenCorner3)));
// ensure we are on whole pixel borders
screenSpaceMin.x = Mathf.Floor(screenSpaceMin.x);
screenSpaceMin.y = Mathf.Floor(screenSpaceMin.y);
screenSpaceMax.x = Mathf.Ceil(screenSpaceMax.x);
screenSpaceMax.y = Mathf.Ceil(screenSpaceMax.y);
// inverse-map screenCornerN to screenSpaceMin/screenSpaceMax area to get UV coordinates
uvCorner0 = MathUtilities.InverseLerp(screenSpaceMin, screenSpaceMax, screenCorner0);
uvCorner1 = MathUtilities.InverseLerp(screenSpaceMin, screenSpaceMax, screenCorner1);
uvCorner2 = MathUtilities.InverseLerp(screenSpaceMin, screenSpaceMax, screenCorner2);
uvCorner3 = MathUtilities.InverseLerp(screenSpaceMin, screenSpaceMax, screenCorner3);
screenSize = new Vector2Int(Math.Abs((int)screenSpaceMax.x - (int)screenSpaceMin.x),
Math.Abs((int)screenSpaceMax.y - (int)screenSpaceMin.y));
usedRenderTextureSize = new Vector2Int(
Math.Min(maxRenderTextureSize, screenSize.x),
Math.Min(maxRenderTextureSize, screenSize.y));
downScaleFactor = new Vector2(
(float)usedRenderTextureSize.x / (float)screenSize.x,
(float)usedRenderTextureSize.y / (float)screenSize.y);
PrepareRenderTexture();
}
protected void PrepareRenderTexture () {
Vector2Int textureSize = new Vector2Int(
Mathf.NextPowerOfTwo(usedRenderTextureSize.x),
Mathf.NextPowerOfTwo(usedRenderTextureSize.y));
if (textureSize != allocatedRenderTextureSize) {
if (renderTexture)
RenderTexture.ReleaseTemporary(renderTexture);
renderTexture = RenderTexture.GetTemporary(textureSize.x, textureSize.y);
renderTexture.filterMode = FilterMode.Point;
allocatedRenderTextureSize = textureSize;
}
}
protected void AssignAtQuad () {
Transform quadTransform = quad.transform;
quadTransform.position = this.transform.position;
quadTransform.rotation = this.transform.rotation;
quadTransform.localScale = this.transform.localScale;
Vector3 v0 = quadTransform.InverseTransformPoint(worldCornerNoDistortion0);
Vector3 v1 = quadTransform.InverseTransformPoint(worldCornerNoDistortion1);
Vector3 v2 = quadTransform.InverseTransformPoint(worldCornerNoDistortion2);
Vector3 v3 = quadTransform.InverseTransformPoint(worldCornerNoDistortion3);
Vector3[] vertices = new Vector3[4] { v0, v1, v2, v3 };
quadMesh.vertices = vertices;
int[] indices = new int[6] { 0, 1, 2, 2, 1, 3 };
quadMesh.triangles = indices;
Vector3[] normals = new Vector3[4] {
-Vector3.forward,
-Vector3.forward,
-Vector3.forward,
-Vector3.forward
};
quadMesh.normals = normals;
float maxU = (float)usedRenderTextureSize.x / (float)allocatedRenderTextureSize.x;
float maxV = (float)usedRenderTextureSize.y / (float)allocatedRenderTextureSize.y;
if (downScaleFactor.x < 1 || downScaleFactor.y < 1) {
maxU = downScaleFactor.x * (float)screenSize.x / (float)allocatedRenderTextureSize.x;
maxV = downScaleFactor.y * (float)screenSize.y / (float)allocatedRenderTextureSize.y;
}
Vector2[] uv = new Vector2[4] {
new Vector2(uvCorner0.x * maxU, uvCorner0.y * maxV),
new Vector2(uvCorner1.x * maxU, uvCorner1.y * maxV),
new Vector2(uvCorner2.x * maxU, uvCorner2.y * maxV),
new Vector2(uvCorner3.x * maxU, uvCorner3.y * maxV),
};
quadMesh.uv = uv;
AssignMeshAtRenderer();
}
protected abstract void AssignMeshAtRenderer ();
#endif // HAS_VECTOR2INT
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ccf9b5e5034b0ea45962f9cf32168dd9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,88 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated July 28, 2023. Replaces all prior versions.
*
* Copyright (c) 2013-2023, 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(SkeletonRenderTextureBase))]
public class SkeletonRenderTextureFadeout : MonoBehaviour {
SkeletonRenderTextureBase 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<SkeletonRenderTextureBase>();
}
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
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5fc94f89310427643babb41e000a8462
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: