diff --git a/Unity-19050-05-BallPool/Assets/Frozen/Character.prefab.meta b/Unity-19050-05-BallPool/Assets/Frozen/Character.prefab.meta new file mode 100644 index 0000000..2a2bd2c --- /dev/null +++ b/Unity-19050-05-BallPool/Assets/Frozen/Character.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 39491758eb9e12c4eabfd1587027ca77 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Unity-19050-05-BallPool/Assets/Frozen/Script/FrozenScreenToWorldSpace.cs b/Unity-19050-05-BallPool/Assets/Frozen/Script/FrozenScreenToWorldSpace.cs new file mode 100644 index 0000000..98ea13a --- /dev/null +++ b/Unity-19050-05-BallPool/Assets/Frozen/Script/FrozenScreenToWorldSpace.cs @@ -0,0 +1,122 @@ +using System.Collections; +using System.Collections.Generic; +using UltraCombos.Utility.Attributes; +using UnityEngine; + +public enum Area +{ + LeftWall, + RightWall, + TopWall, + Floor +} + +public class FrozenScreenToWorldSpace : MonoBehaviour +{ + public static FrozenScreenToWorldSpace Instance + { + get + { + return instacnce; + } + } + private static FrozenScreenToWorldSpace instacnce; + + public float width = 8; + public float depth = 5; + public float height = 3; + public float blackLength = 0.89f; + public float PixelsByMeter = 360; + public float finalPixelsByMeter = 90; + + [Header("Debug")] + [SerializeField, ReadOnly] + Rect LeftWall; + [SerializeField, ReadOnly] + Rect TopWall; + [SerializeField, ReadOnly] + Rect RightWall; + [SerializeField, ReadOnly] + Rect Floor; + + Dictionary RenderTextureROIList = new Dictionary(); + + private void Awake() + { + instacnce = this; + InitailROISetting(); + } + + void InitailROISetting() + { + var totalWidth = height * 2 + width; + var totalHeight = height + depth + blackLength; + + var nWidth = width / totalWidth;//normalized + var nWidth2 = height / totalWidth; + + var nHeight = height / totalHeight; + var nHeight2 = depth / totalHeight; + + TopWall = new Rect(nWidth2, 0, nWidth, nHeight); + + LeftWall = new Rect(0, nHeight, nWidth2, nHeight2); + Floor = new Rect(nWidth2, nHeight, nWidth, nHeight2); + RightWall = new Rect(nWidth + nWidth2, nHeight, nWidth2, nHeight2); + + RenderTextureROIList = new Dictionary() + { + [Area.LeftWall] = LeftWall, + [Area.RightWall] = RightWall, + [Area.TopWall] = TopWall, + [Area.Floor] = Floor, + }; + } + + public Vector2 GetFinalScreenPos(Area area, Vector2 wallROI) + { + if (!RenderTextureROIList.ContainsKey(area)) + return Vector2.zero; + Rect textureROI = RenderTextureROIList[area]; + Vector2 currenPos = Vector2.zero; + switch (area) + { + case Area.LeftWall: + currenPos = Rect.NormalizedToPoint(textureROI, new Vector2(1 - wallROI.y, 1 - wallROI.x)); + break; + case Area.RightWall: + currenPos = Rect.NormalizedToPoint(textureROI, new Vector2(wallROI.y, 1 - wallROI.x)); + break; + case Area.TopWall: + currenPos = Rect.NormalizedToPoint(textureROI, new Vector2(wallROI.x, 1 - wallROI.y)); + break; + } + currenPos = new Vector2(currenPos.x * Screen.width, (1 - currenPos.y) * Screen.height); + return currenPos; + } + + public Vector2 GetWallRoiFromPosition(Area area, Vector3 position) + { + position -= transform.position; + Vector2 roi = Vector2.zero; + switch (area) + { + case Area.TopWall: + roi.x = (position.x + width * 0.5f) / width; + roi.y = position.y / height; + break; + case Area.LeftWall: + roi.x = (position.z + depth * 0.5f) / depth; + roi.y = position.y / height; + break; + case Area.RightWall: + roi.x = (position.z + depth * 0.5f) / depth; + roi.y = position.y / height; + break; + } + // Debug.Log($"{area} {position.ToString()} {roi.ToString()}"); + return roi; + } + + public Vector3 Position { get { return transform.position; } } +} diff --git a/Unity-19050-05-BallPool/Assets/Frozen/Shader/FrozenUnlitTexture.shader b/Unity-19050-05-BallPool/Assets/Frozen/Shader/FrozenUnlitTexture.shader new file mode 100644 index 0000000..70b6735 --- /dev/null +++ b/Unity-19050-05-BallPool/Assets/Frozen/Shader/FrozenUnlitTexture.shader @@ -0,0 +1,63 @@ +Shader "UltraCombos/Frozen/Unlit/Texture" +{ + Properties + { + _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} + _Color("Color",Color) = (1,1,1,1) + [Toggle] _isGamma("is Gamma", Float) = 0 + } + SubShader + { + //Tags { "RenderType"="Opaque" } + Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" "IgnoreProjector" = "True" } + LOD 100 + ZWrite Off + Cull off + // Blend SrcAlpha OneMinusSrcAlpha + //Blend One OneMinusSrcAlpha + Blend SrcAlpha OneMinusSrcAlpha, Zero One + + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + + #include "UnityCG.cginc" + + struct appdata + { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + }; + + struct v2f + { + float2 uv : TEXCOORD0; + float4 vertex : SV_POSITION; + }; + + sampler2D _MainTex; + float4 _MainTex_ST; + float4 _Color; + float _Rate; + float _isGamma; + + v2f vert (appdata v) + { + v2f o; + o.vertex = UnityObjectToClipPos(v.vertex); + o.uv = TRANSFORM_TEX(v.uv, _MainTex); + return o; + } + + fixed4 frag (v2f i) : SV_Target + { + fixed4 frag_color = tex2D(_MainTex, i.uv); + frag_color.rgb = lerp(frag_color.rgb, GammaToLinearSpace(frag_color.rgb), _isGamma); + return frag_color * _Color; + } + ENDCG + } + } +} diff --git a/Unity-19050-05-BallPool/Assets/Frozen/Shader/UnlitColorAlpha.shader b/Unity-19050-05-BallPool/Assets/Frozen/Shader/UnlitColorAlpha.shader new file mode 100644 index 0000000..87adeb8 --- /dev/null +++ b/Unity-19050-05-BallPool/Assets/Frozen/Shader/UnlitColorAlpha.shader @@ -0,0 +1,70 @@ +// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) + +// Unlit alpha-blended shader. +// - no lighting +// - no lightmap support +// - no per-material color + +Shader "Unlit/ColorTransparent" { +Properties { + _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} + _Color("Color",Color) = (1,1,1,1) +} + +SubShader { + Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"} + LOD 100 + + ZWrite Off + // Blend SrcAlpha OneMinusSrcAlpha + Blend SrcAlpha OneMinusSrcAlpha, Zero One + + Pass { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #pragma target 2.0 + #pragma multi_compile_fog + + #include "UnityCG.cginc" + + struct appdata_t { + float4 vertex : POSITION; + float2 texcoord : TEXCOORD0; + UNITY_VERTEX_INPUT_INSTANCE_ID + }; + + struct v2f { + float4 vertex : SV_POSITION; + float2 texcoord : TEXCOORD0; + UNITY_FOG_COORDS(1) + UNITY_VERTEX_OUTPUT_STEREO + }; + + sampler2D _MainTex; + float4 _MainTex_ST; + float4 _Color; + + v2f vert (appdata_t v) + { + v2f o; + UNITY_SETUP_INSTANCE_ID(v); + UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); + o.vertex = UnityObjectToClipPos(v.vertex); + o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); + UNITY_TRANSFER_FOG(o,o.vertex); + return o; + } + + fixed4 frag (v2f i) : SV_Target + { + fixed4 col = tex2D(_MainTex, i.texcoord) * _Color; + + UNITY_APPLY_FOG(i.fogCoord, col); + return col; + } + ENDCG + } +} + +} diff --git a/Unity-19050-05-BallPool/ProjectSettings/TagManager.asset b/Unity-19050-05-BallPool/ProjectSettings/TagManager.asset new file mode 100644 index 0000000..3ea81b3 --- /dev/null +++ b/Unity-19050-05-BallPool/ProjectSettings/TagManager.asset @@ -0,0 +1,43 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!78 &1 +TagManager: + serializedVersion: 2 + tags: [] + layers: + - Default + - TransparentFX + - Ignore Raycast + - + - Water + - UI + - + - + - Scene + - Particle + - Post + - Post2 + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + m_SortingLayers: + - name: Default + uniqueID: 0 + locked: 0