From 0d77344b9bb13ac6f13b5c1f499f6df3a4ee1af7 Mon Sep 17 00:00:00 2001 From: ghiboz Date: Tue, 3 Apr 2018 14:07:31 +0200 Subject: [PATCH] Added semaphore lights system --- Lights/GR_Semaphore.cs | 58 ++++++++++++++++++++++++ Lights/GR_Semaphore.cs.meta | 13 ++++++ README.md | 3 ++ Shaders/semaphore.shader | 85 +++++++++++++++++++++++++++++++++++ Shaders/semaphore.shader.meta | 10 +++++ 5 files changed, 169 insertions(+) create mode 100644 Lights/GR_Semaphore.cs create mode 100644 Lights/GR_Semaphore.cs.meta create mode 100644 Shaders/semaphore.shader create mode 100644 Shaders/semaphore.shader.meta diff --git a/Lights/GR_Semaphore.cs b/Lights/GR_Semaphore.cs new file mode 100644 index 0000000..6f3e997 --- /dev/null +++ b/Lights/GR_Semaphore.cs @@ -0,0 +1,58 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[ExecuteInEditMode] +public class GR_Semaphore : MonoBehaviour +{ + public Light RedLight; + public Light YellowLight; + public Light GreenLight; + public Material Semaphore; + + [Range(0,6)] + public int DebugCountDown = 6; + + private int fDebugCountDown = 6; + // Use this for initialization + + // Update is called once per frame + void Update () + { + if (DebugCountDown != fDebugCountDown) + { + if (DebugCountDown == 0) + { + // green + if (RedLight != null) RedLight.intensity = 0.0f; + if (YellowLight != null) YellowLight.intensity = 0.0f; + if (GreenLight != null) GreenLight.intensity = 2.0f; + if (Semaphore != null) Semaphore.SetFloat("_startFrame", 3.0f); + } + else if (DebugCountDown == 1) + { + // yellow + if (RedLight != null) RedLight.intensity = 0.0f; + if (YellowLight != null) YellowLight.intensity = 2.0f; + if (GreenLight != null) GreenLight.intensity = 0.0f; + if (Semaphore != null) Semaphore.SetFloat("_startFrame", 2.0f); + } + else if (DebugCountDown < 6) + { + // red + if (RedLight != null) RedLight.intensity = 2.0f; + if (YellowLight != null) YellowLight.intensity = 0.0f; + if (GreenLight != null) GreenLight.intensity = 0.0f; + if (Semaphore != null) Semaphore.SetFloat("_startFrame", 1.0f); + } + else + { + if (RedLight != null) RedLight.intensity = 0.0f; + if (YellowLight != null) YellowLight.intensity = 0.0f; + if (GreenLight != null) GreenLight.intensity = 0.0f; + if (Semaphore != null) Semaphore.SetFloat("_startFrame", 0.0f); + } + fDebugCountDown = DebugCountDown; + } + } +} diff --git a/Lights/GR_Semaphore.cs.meta b/Lights/GR_Semaphore.cs.meta new file mode 100644 index 0000000..3ab28ab --- /dev/null +++ b/Lights/GR_Semaphore.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: b5d4cd93d78f7a64db3d568eb781a876 +timeCreated: 1522747550 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/README.md b/README.md index edacc31..ae6d913 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +### V1.7.0 - 2018/04/03 +- Added semaphore lights system; + ### v1.6.1 - 2018/03/24 - Puddles enabled/disabled diff --git a/Shaders/semaphore.shader b/Shaders/semaphore.shader new file mode 100644 index 0000000..56a6245 --- /dev/null +++ b/Shaders/semaphore.shader @@ -0,0 +1,85 @@ +// Made with Amplify Shader Editor +// Available at the Unity Asset Store - http://u3d.as/y3X +Shader "gRally/semaphore" +{ + Properties + { + _TextureSample0("Texture Sample 0", 2D) = "white" {} + _startFrame("startFrame", Range( 0 , 3)) = 0 + [HideInInspector] _texcoord( "", 2D ) = "white" {} + [HideInInspector] __dirty( "", Int ) = 1 + } + + SubShader + { + Tags{ "RenderType" = "Opaque" "Queue" = "Geometry+0" "IsEmissive" = "true" } + Cull Back + CGPROGRAM + #pragma target 3.5 + #pragma surface surf StandardSpecular keepalpha addshadow fullforwardshadows + struct Input + { + float2 uv_texcoord; + }; + + uniform sampler2D _TextureSample0; + uniform fixed _startFrame; + + void surf( Input i , inout SurfaceOutputStandardSpecular o ) + { + float2 uv_TexCoord11 = i.uv_texcoord * float2( 1,1 ) + float2( 0,0 ); + // *** BEGIN Flipbook UV Animation vars *** + // Total tiles of Flipbook Texture + float fbtotaltiles12 = 2 * 2; + // Offsets for cols and rows of Flipbook Texture + float fbcolsoffset12 = 1.0f / 2; + float fbrowsoffset12 = 1.0f / 2; + // Speed of animation + float fbspeed12 = _Time[ 1 ] * 0; + // UV Tiling (col and row offset) + float2 fbtiling12 = float2(fbcolsoffset12, fbrowsoffset12); + // UV Offset - calculate current tile linear index, and convert it to (X * coloffset, Y * rowoffset) + // Calculate current tile linear index + float fbcurrenttileindex12 = round( fmod( fbspeed12 + _startFrame, fbtotaltiles12) ); + fbcurrenttileindex12 += ( fbcurrenttileindex12 < 0) ? fbtotaltiles12 : 0; + // Obtain Offset X coordinate from current tile linear index + float fblinearindextox12 = round ( fmod ( fbcurrenttileindex12, 2 ) ); + // Multiply Offset X by coloffset + float fboffsetx12 = fblinearindextox12 * fbcolsoffset12; + // Obtain Offset Y coordinate from current tile linear index + float fblinearindextoy12 = round( fmod( ( fbcurrenttileindex12 - fblinearindextox12 ) / 2, 2 ) ); + // Reverse Y to get tiles from Top to Bottom + fblinearindextoy12 = (int)(2-1) - fblinearindextoy12; + // Multiply Offset Y by rowoffset + float fboffsety12 = fblinearindextoy12 * fbrowsoffset12; + // UV Offset + float2 fboffset12 = float2(fboffsetx12, fboffsety12); + // Flipbook UV + half2 fbuv12 = uv_TexCoord11 * fbtiling12 + fboffset12; + // *** END Flipbook UV Animation vars *** + float4 tex2DNode10 = tex2D( _TextureSample0, fbuv12 ); + o.Albedo = tex2DNode10.rgb; + o.Emission = tex2DNode10.rgb; + o.Alpha = 1; + } + + ENDCG + } + Fallback "Diffuse" + CustomEditor "ASEMaterialInspector" +} +/*ASEBEGIN +Version=15103 +134;97;1458;853;1850.342;460.0829;1.475;True;True +Node;AmplifyShaderEditor.TextureCoordinatesNode;11;-1363.634,-4.699924;Float;False;0;-1;2;3;2;SAMPLER2D;;False;0;FLOAT2;1,1;False;1;FLOAT2;0,0;False;5;FLOAT2;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4 +Node;AmplifyShaderEditor.RangedFloatNode;14;-1373.48,281.1392;Fixed;False;Property;_startFrame;startFrame;1;0;Create;True;0;0;False;0;0;0;0;3;0;1;FLOAT;0 +Node;AmplifyShaderEditor.TFHCFlipBookUVAnimation;12;-1006.184,-3.594935;Float;False;0;0;6;0;FLOAT2;0,0;False;1;FLOAT;2;False;2;FLOAT;2;False;3;FLOAT;0;False;4;FLOAT;0;False;5;FLOAT;0;False;3;FLOAT2;0;FLOAT;1;FLOAT;2 +Node;AmplifyShaderEditor.SamplerNode;10;-630.9352,1.620116;Float;True;Property;_TextureSample0;Texture Sample 0;0;0;Create;True;0;0;False;0;None;6701f7837d69e0544862b46e0474f9ea;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;6;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;1;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4 +Node;AmplifyShaderEditor.StandardSurfaceOutputNode;0;277.1951,14.75;Float;False;True;3;Float;ASEMaterialInspector;0;0;StandardSpecular;semaforo;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;Back;0;False;-1;0;False;-1;False;0;0;False;0;Opaque;0.5;True;True;0;False;Opaque;;Geometry;All;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;0;False;-1;False;0;False;-1;255;False;-1;255;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;False;0;4;10;25;False;0.5;True;0;Zero;Zero;0;Zero;Zero;Add;Add;0;False;0;0,0,0,0;VertexOffset;True;False;Cylindrical;False;Relative;0;;-1;-1;-1;-1;0;0;0;False;0;0;0;False;-1;-1;16;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;2;FLOAT3;0,0,0;False;3;FLOAT3;0,0,0;False;4;FLOAT;0;False;5;FLOAT;0;False;6;FLOAT3;0,0,0;False;7;FLOAT3;0,0,0;False;8;FLOAT;0;False;9;FLOAT;0;False;10;FLOAT;0;False;13;FLOAT3;0,0,0;False;11;FLOAT3;0,0,0;False;12;FLOAT3;0,0,0;False;14;FLOAT4;0,0,0,0;False;15;FLOAT3;0,0,0;False;0 +WireConnection;12;0;11;0 +WireConnection;12;4;14;0 +WireConnection;10;1;12;0 +WireConnection;0;0;10;0 +WireConnection;0;2;10;0 +ASEEND*/ +//CHKSM=0415970B1FB07CA402121F77629E6A00F7D5668A \ No newline at end of file diff --git a/Shaders/semaphore.shader.meta b/Shaders/semaphore.shader.meta new file mode 100644 index 0000000..b9f7a2a --- /dev/null +++ b/Shaders/semaphore.shader.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 087b0e18d7472634090ce23afd54b688 +timeCreated: 1522749066 +licenseType: Free +ShaderImporter: + externalObjects: {} + defaultTextures: [] + userData: + assetBundleName: + assetBundleVariant: