推进度!
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
// Made with Amplify Shader Editor v1.9.0.2
|
||||
// Available at the Unity Asset Store - http://u3d.as/y3X
|
||||
Shader "UI/Demo/Color Picker"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
|
||||
_Color ("Tint", Color) = (1,1,1,1)
|
||||
|
||||
_StencilComp ("Stencil Comparison", Float) = 8
|
||||
_Stencil ("Stencil ID", Float) = 0
|
||||
_StencilOp ("Stencil Operation", Float) = 0
|
||||
_StencilWriteMask ("Stencil Write Mask", Float) = 255
|
||||
_StencilReadMask ("Stencil Read Mask", Float) = 255
|
||||
|
||||
_ColorMask ("Color Mask", Float) = 15
|
||||
|
||||
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
|
||||
[ASEEnd]_Brightness("Brightness", Float) = 1
|
||||
[HideInInspector] _texcoord( "", 2D ) = "white" {}
|
||||
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
LOD 0
|
||||
|
||||
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }
|
||||
|
||||
Stencil
|
||||
{
|
||||
Ref [_Stencil]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
Comp [_StencilComp]
|
||||
Pass [_StencilOp]
|
||||
}
|
||||
|
||||
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
ZTest [unity_GUIZTestMode]
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ColorMask [_ColorMask]
|
||||
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "Default"
|
||||
CGPROGRAM
|
||||
|
||||
#ifndef UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX
|
||||
#define UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input)
|
||||
#endif
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma target 3.0
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityUI.cginc"
|
||||
|
||||
#pragma multi_compile __ UNITY_UI_CLIP_RECT
|
||||
#pragma multi_compile __ UNITY_UI_ALPHACLIP
|
||||
|
||||
#define ASE_NEEDS_FRAG_COLOR
|
||||
|
||||
|
||||
struct appdata_t
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
fixed4 color : COLOR;
|
||||
half2 texcoord : TEXCOORD0;
|
||||
float4 worldPosition : TEXCOORD1;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
UNITY_VERTEX_OUTPUT_STEREO
|
||||
|
||||
};
|
||||
|
||||
uniform fixed4 _Color;
|
||||
uniform fixed4 _TextureSampleAdd;
|
||||
uniform float4 _ClipRect;
|
||||
uniform sampler2D _MainTex;
|
||||
uniform float _Brightness;
|
||||
uniform float4 _MainTex_ST;
|
||||
float3 HSVToRGB( float3 c )
|
||||
{
|
||||
float4 K = float4( 1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0 );
|
||||
float3 p = abs( frac( c.xxx + K.xyz ) * 6.0 - K.www );
|
||||
return c.z * lerp( K.xxx, saturate( p - K.xxx ), c.y );
|
||||
}
|
||||
|
||||
|
||||
|
||||
v2f vert( appdata_t IN )
|
||||
{
|
||||
v2f OUT;
|
||||
UNITY_SETUP_INSTANCE_ID( IN );
|
||||
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
|
||||
UNITY_TRANSFER_INSTANCE_ID(IN, OUT);
|
||||
OUT.worldPosition = IN.vertex;
|
||||
|
||||
|
||||
OUT.worldPosition.xyz += float3( 0, 0, 0 ) ;
|
||||
OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
|
||||
|
||||
OUT.texcoord = IN.texcoord;
|
||||
|
||||
OUT.color = IN.color * _Color;
|
||||
return OUT;
|
||||
}
|
||||
|
||||
fixed4 frag(v2f IN ) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID( IN );
|
||||
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX( IN );
|
||||
|
||||
float2 texCoord1 = IN.texcoord.xy * float2( 1,1 ) + float2( 0,0 );
|
||||
float3 hsvTorgb2 = HSVToRGB( float3(texCoord1.x,texCoord1.y,_Brightness) );
|
||||
float2 uv_MainTex = IN.texcoord.xy * _MainTex_ST.xy + _MainTex_ST.zw;
|
||||
float4 appendResult3 = (float4(hsvTorgb2 , tex2D( _MainTex, uv_MainTex ).a));
|
||||
|
||||
half4 color = ( IN.color * appendResult3 );
|
||||
|
||||
#ifdef UNITY_UI_CLIP_RECT
|
||||
color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
|
||||
#endif
|
||||
|
||||
#ifdef UNITY_UI_ALPHACLIP
|
||||
clip (color.a - 0.001);
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Fallback Off
|
||||
}
|
||||
/*ASEBEGIN
|
||||
Version=19002
|
||||
292;343;1837;1028;755.5;601;1;True;False
|
||||
Node;AmplifyShaderEditor.RangedFloatNode;7;-230.5,-45;Inherit;False;Property;_Brightness;Brightness;0;0;Create;True;0;0;0;False;0;False;1;0;0;0;0;1;FLOAT;0
|
||||
Node;AmplifyShaderEditor.TextureCoordinatesNode;1;-422.5,-224;Inherit;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.TemplateShaderPropertyNode;4;-393.5,44;Inherit;False;0;0;_MainTex;Shader;False;0;5;SAMPLER2D;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
|
||||
Node;AmplifyShaderEditor.HSVToRGBNode;2;-50.5,-126;Inherit;False;3;0;FLOAT;0;False;1;FLOAT;1;False;2;FLOAT;1;False;4;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3
|
||||
Node;AmplifyShaderEditor.SamplerNode;5;-148.5,74;Inherit;True;Property;_TextureSample0;Texture Sample 0;0;0;Create;True;0;0;0;False;0;False;-1;None;None;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
|
||||
Node;AmplifyShaderEditor.DynamicAppendNode;3;295.5,-125;Inherit;False;FLOAT4;4;0;FLOAT3;0,0,0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT4;0
|
||||
Node;AmplifyShaderEditor.VertexColorNode;10;245.5,-342;Inherit;False;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
|
||||
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;9;460.5,-214;Inherit;False;2;2;0;COLOR;0,0,0,0;False;1;FLOAT4;0,0,0,0;False;1;COLOR;0
|
||||
Node;AmplifyShaderEditor.TemplateMultiPassMasterNode;0;654,-145;Float;False;True;-1;2;;0;6;UI/Demo/Color Picker;5056123faa0c79b47ab6ad7e8bf059a4;True;Default;0;0;Default;2;False;True;2;5;False;;10;False;;0;1;False;;0;False;;False;False;False;False;False;False;False;False;False;False;False;False;True;2;False;;False;True;True;True;True;True;0;True;_ColorMask;False;False;False;False;False;False;False;True;True;0;True;_Stencil;255;True;_StencilReadMask;255;True;_StencilWriteMask;0;True;_StencilComp;0;True;_StencilOp;1;False;;1;False;;7;False;;1;False;;1;False;;1;False;;False;True;2;False;;True;0;True;unity_GUIZTestMode;False;True;5;Queue=Transparent=Queue=0;IgnoreProjector=True;RenderType=Transparent=RenderType;PreviewType=Plane;CanUseSpriteAtlas=True;False;False;0;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;True;2;False;0;;0;0;Standard;0;0;1;True;False;;False;0
|
||||
WireConnection;2;0;1;1
|
||||
WireConnection;2;1;1;2
|
||||
WireConnection;2;2;7;0
|
||||
WireConnection;5;0;4;0
|
||||
WireConnection;3;0;2;0
|
||||
WireConnection;3;3;5;4
|
||||
WireConnection;9;0;10;0
|
||||
WireConnection;9;1;3;0
|
||||
WireConnection;0;0;9;0
|
||||
ASEEND*/
|
||||
//CHKSM=A297402DF8CB1D7D3CFDD9257341E61777EE44BC
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b860201e6bb5e4f458641dd9676038c0
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
preprocessorOverride: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SpriteShadersUltimate.Demo
|
||||
{
|
||||
public class Demo_Camera : MonoBehaviour
|
||||
{
|
||||
void LateUpdate()
|
||||
{
|
||||
//Follow player's x position.
|
||||
Vector3 position = transform.position;
|
||||
position.x = Mathf.Lerp(position.x, Demo_Player.instance.transform.position.x, Time.deltaTime * 3f);
|
||||
transform.position = position;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f86ad67ce4d37b44d84fb7fb5eb2bef0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,153 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace SpriteShadersUltimate.Demo
|
||||
{
|
||||
public class Demo_ColorPicker : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
public Material targetMaterial;
|
||||
public string propertyName;
|
||||
|
||||
RectTransform colorArea;
|
||||
Slider brightnessSlider;
|
||||
RectTransform dotRect;
|
||||
Image dotImage;
|
||||
|
||||
bool isHovered;
|
||||
bool isDragging;
|
||||
|
||||
float lastHue;
|
||||
float lastSaturation;
|
||||
float maxBrightness;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if(brightnessSlider == null || colorArea == null)
|
||||
{
|
||||
//References:
|
||||
colorArea = transform.Find("Color Area").GetComponent<RectTransform>();
|
||||
brightnessSlider = transform.Find("Brightness Slider").GetComponent<Slider>();
|
||||
dotRect = transform.Find("Color Area/Dot").GetComponent<RectTransform>();
|
||||
dotImage = dotRect.GetComponent<Image>();
|
||||
|
||||
//Initialize:
|
||||
dotImage.material = Instantiate<Material>(dotImage.material);
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
Vector2 mousePosition = default;
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(colorArea, Input.mousePosition, Camera.main, out mousePosition);
|
||||
|
||||
if (isHovered && Input.GetMouseButtonDown(0))
|
||||
{
|
||||
if (mousePosition.x > -colorArea.sizeDelta.x * 0.5f && mousePosition.x < colorArea.sizeDelta.x * 0.5f && mousePosition.y > -colorArea.sizeDelta.y * 0.5f && mousePosition.y < colorArea.sizeDelta.y * 0.5f)
|
||||
{
|
||||
isDragging = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(isDragging)
|
||||
{
|
||||
if(Input.GetMouseButton(0) == false)
|
||||
{
|
||||
isDragging = false;
|
||||
}
|
||||
|
||||
Vector2 colorRange = (mousePosition + colorArea.sizeDelta * 0.5f) / colorArea.sizeDelta;
|
||||
float hue = Mathf.Clamp01(colorRange.x);
|
||||
float saturation = Mathf.Clamp01(colorRange.y);
|
||||
UpdateColor(hue, saturation);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTarget(Material newMaterial, string newProperty, string shaderName)
|
||||
{
|
||||
Start();
|
||||
|
||||
targetMaterial = newMaterial;
|
||||
propertyName = newProperty;
|
||||
|
||||
LoadColor(targetMaterial.GetColor(propertyName));
|
||||
|
||||
//Title:
|
||||
string displayString = newProperty.Replace("_" + shaderName.Replace(" ", ""), "");
|
||||
char[] displayChars = displayString.ToCharArray();
|
||||
displayString = "";
|
||||
for(int c = 0; c < displayChars.Length; c++)
|
||||
{
|
||||
if(c > 0 && displayChars[c].ToString().ToUpper() == displayChars[c].ToString())
|
||||
{
|
||||
displayString += " ";
|
||||
}
|
||||
|
||||
displayString += displayChars[c];
|
||||
}
|
||||
transform.Find("Title").GetComponent<Text>().text = displayString;
|
||||
}
|
||||
|
||||
public void LoadColor(Color color)
|
||||
{
|
||||
float hue;
|
||||
float saturation;
|
||||
float value;
|
||||
Color.RGBToHSV(color, out hue, out saturation, out value);
|
||||
|
||||
maxBrightness = Mathf.Ceil(value * 0.5f) * 4f + 5f;
|
||||
|
||||
if(value <= 1f)
|
||||
{
|
||||
brightnessSlider.SetValueWithoutNotify(value * 0.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
brightnessSlider.SetValueWithoutNotify(0.5f + (value - 1f) / maxBrightness);
|
||||
}
|
||||
|
||||
UpdateColor(hue, saturation);
|
||||
}
|
||||
|
||||
public void UpdateColor(float hue, float saturation)
|
||||
{
|
||||
lastHue = hue;
|
||||
lastSaturation = saturation;
|
||||
|
||||
dotRect.anchoredPosition = new Vector2(Mathf.Clamp(colorArea.sizeDelta.x * hue, 5, colorArea.sizeDelta.x - 5), Mathf.Clamp(colorArea.sizeDelta.y * saturation, 5, colorArea.sizeDelta.y - 5));
|
||||
dotImage.color = Color.HSVToRGB(hue, saturation, 1f);
|
||||
|
||||
float value = Mathf.Min(brightnessSlider.value * 2f, 1) + Mathf.Max((brightnessSlider.value - 0.5f) * maxBrightness, 0);
|
||||
dotImage.materialForRendering.SetFloat("_Brightness", value);
|
||||
|
||||
if(targetMaterial != null)
|
||||
{
|
||||
targetMaterial.SetColor(propertyName, Color.HSVToRGB(hue, saturation, value));
|
||||
}
|
||||
}
|
||||
|
||||
public void SliderChanged()
|
||||
{
|
||||
if (Mathf.Abs(brightnessSlider.value - 0.5f) < 0.05f)
|
||||
{
|
||||
brightnessSlider.SetValueWithoutNotify(0.5f);
|
||||
}
|
||||
|
||||
UpdateColor(lastHue, lastSaturation);
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
isHovered = true;
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
isHovered = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7900ce9e82d3d9f4090a336fc0109c02
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,295 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace SpriteShadersUltimate.Demo
|
||||
{
|
||||
public class Demo_Display : MonoBehaviour
|
||||
{
|
||||
//Selected:
|
||||
public static Demo_Display selected;
|
||||
|
||||
[Header("Material Settings:")]
|
||||
public string firstProperty = "";
|
||||
public bool ignorePlayer = false;
|
||||
public float cycleTime = 2f;
|
||||
|
||||
//Runtime:
|
||||
Transform shader;
|
||||
Material frameMaterial;
|
||||
bool isHovered;
|
||||
float lastScale;
|
||||
float activeUntil;
|
||||
int mainIndex;
|
||||
|
||||
//Material:
|
||||
Renderer mainRenderer;
|
||||
Material mainMaterial;
|
||||
Transform extraSprites;
|
||||
|
||||
//Position:
|
||||
int row;
|
||||
int slot;
|
||||
int maxSlots;
|
||||
float camWidth;
|
||||
|
||||
void Start()
|
||||
{
|
||||
//Initialize:
|
||||
frameMaterial = transform.Find("Display/Frame").GetComponent<SpriteRenderer>().material;
|
||||
shader = transform.Find("Shader");
|
||||
isHovered = false;
|
||||
lastScale = 0f;
|
||||
activeUntil = Time.unscaledTime + 2f;
|
||||
|
||||
//Position:
|
||||
int index = transform.GetSiblingIndex();
|
||||
row = index % 3 - 1;
|
||||
slot = index / 3;
|
||||
int parentCount = transform.parent.childCount;
|
||||
maxSlots = parentCount / 3 + (row + 1 < parentCount % 3 ? 1 : 0);
|
||||
camWidth = ((float)Screen.width / (float)Screen.height) * Camera.main.orthographicSize;
|
||||
UpdatePosition();
|
||||
UpdatePosition();
|
||||
|
||||
//Material:
|
||||
mainIndex = 0;
|
||||
UpdateIndex();
|
||||
|
||||
extraSprites = shader.Find("Extra Sprites");
|
||||
|
||||
if (extraSprites != null)
|
||||
{
|
||||
extraSprites.localPosition = new Vector3(4f, 0, 0);
|
||||
}
|
||||
|
||||
//First Property:
|
||||
if (firstProperty == null || firstProperty == "")
|
||||
{
|
||||
firstProperty = "_" + gameObject.name.Replace(" ", "") + "Fade";
|
||||
}
|
||||
|
||||
//Title:
|
||||
Demo_GUI.instance.CreateTitle(gameObject.name, transform.Find("Display/Title Position"));
|
||||
|
||||
//Coroutine:
|
||||
StartCoroutine(CycleShader());
|
||||
StartCoroutine(HandlePosition());
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Time.unscaledTime > activeUntil) return;
|
||||
|
||||
float scale = transform.localScale.x;
|
||||
|
||||
if (selected == this)
|
||||
{
|
||||
activeUntil = Time.unscaledTime + 4f;
|
||||
scale = Mathf.Clamp(Mathf.Lerp(scale, 1.11f, Time.unscaledDeltaTime * 5f), 1, 1.1f);
|
||||
shader.localScale = Vector3.Lerp(shader.localScale, Vector3.one * 1f / 8f, Time.unscaledDeltaTime * 10f);
|
||||
shader.localPosition = Vector3.Lerp(shader.localPosition, new Vector3(-0.3f, 0, 0), Time.unscaledDeltaTime * 10f);
|
||||
|
||||
if(extraSprites != null)
|
||||
{
|
||||
extraSprites.localPosition = Vector3.Lerp(extraSprites.localPosition, new Vector3(0, 0, 0), Time.unscaledDeltaTime * 10f);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
scale = Mathf.Clamp(Mathf.Lerp(scale, isHovered && selected == null ? 1.11f : 0.99f, Time.unscaledDeltaTime * 5f), 1, 1.1f);
|
||||
shader.localScale = Vector3.Lerp(shader.localScale, new Vector3(0.45f, 0.45f, 1f), Time.unscaledDeltaTime * 4f);
|
||||
shader.localPosition = Vector3.Lerp(shader.localPosition, new Vector3(0f, 0.45f, 0f), Time.unscaledDeltaTime * 4f);
|
||||
|
||||
if (extraSprites != null)
|
||||
{
|
||||
extraSprites.localPosition = Vector3.Lerp(extraSprites.localPosition, new Vector3(2f, 0, 0), Time.unscaledDeltaTime * 10f);
|
||||
}
|
||||
}
|
||||
|
||||
if (scale != lastScale)
|
||||
{
|
||||
lastScale = scale;
|
||||
transform.localScale = new Vector3(scale, scale, 1);
|
||||
frameMaterial.SetFloat("_SineGlowFade", (scale - 1f) * 10f);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator CycleShader()
|
||||
{
|
||||
yield return new WaitForSeconds(transform.GetSiblingIndex() * 0.01f);
|
||||
|
||||
while (true)
|
||||
{
|
||||
yield return new WaitForSeconds(cycleTime);
|
||||
|
||||
if(selected != this)
|
||||
{
|
||||
ChangeIndex();
|
||||
}
|
||||
}
|
||||
}
|
||||
IEnumerator HandlePosition()
|
||||
{
|
||||
yield return new WaitForSeconds(transform.GetSiblingIndex() * 0.01f);
|
||||
|
||||
while (true)
|
||||
{
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
UpdatePosition();
|
||||
}
|
||||
}
|
||||
|
||||
Transform GetMainSprite(int index)
|
||||
{
|
||||
if (index <= 0)
|
||||
{
|
||||
return shader.Find("Main Sprite");
|
||||
}
|
||||
else
|
||||
{
|
||||
return shader.Find("Main Sprite " + (int) (index + 1));
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeIndex()
|
||||
{
|
||||
mainIndex++;
|
||||
if(GetMainSprite(mainIndex) == null)
|
||||
{
|
||||
mainIndex = 0;
|
||||
}
|
||||
|
||||
UpdateIndex();
|
||||
}
|
||||
|
||||
public bool HasAlternatives()
|
||||
{
|
||||
return shader.Find("Main Sprite 2") != null;
|
||||
}
|
||||
|
||||
public void UpdateIndex()
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
Transform sprite = GetMainSprite(i);
|
||||
|
||||
if (sprite != null)
|
||||
{
|
||||
Demo_SpriteFader dsf = sprite.GetComponent<Demo_SpriteFader>();
|
||||
if(dsf != null)
|
||||
{
|
||||
dsf.SetFade(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Transform mainSprite = GetMainSprite(mainIndex);
|
||||
if (mainSprite != null)
|
||||
{
|
||||
Demo_SpriteFader dsf = mainSprite.GetComponent<Demo_SpriteFader>();
|
||||
if (dsf != null)
|
||||
{
|
||||
dsf.SetFade(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
mainSprite.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
mainRenderer = mainSprite.GetComponent<Renderer>();
|
||||
mainMaterial = mainRenderer.material;
|
||||
}
|
||||
}
|
||||
|
||||
void OnMouseOver()
|
||||
{
|
||||
isHovered = true;
|
||||
activeUntil = Time.unscaledTime + 4f;
|
||||
}
|
||||
|
||||
void OnMouseExit()
|
||||
{
|
||||
isHovered = false;
|
||||
activeUntil = Time.unscaledTime + 4f;
|
||||
}
|
||||
|
||||
void OnMouseDown()
|
||||
{
|
||||
if(selected == null)
|
||||
{
|
||||
Select();
|
||||
}
|
||||
}
|
||||
|
||||
public void Select()
|
||||
{
|
||||
mainIndex = 0;
|
||||
UpdateIndex();
|
||||
activeUntil = Time.unscaledTime + 4f;
|
||||
selected = this;
|
||||
Demo_Player.instance.ResetPosition();
|
||||
Demo_GUI.instance.UpdateHud();
|
||||
}
|
||||
|
||||
public void Deselect()
|
||||
{
|
||||
activeUntil = Time.unscaledTime + 4f;
|
||||
selected = null;
|
||||
ResetMaterial();
|
||||
}
|
||||
|
||||
public void ResetMaterial()
|
||||
{
|
||||
if (mainRenderer != null && mainRenderer.material != null && mainRenderer.material != mainMaterial)
|
||||
{
|
||||
Destroy(mainRenderer.material);
|
||||
mainRenderer.material = mainMaterial;
|
||||
}
|
||||
}
|
||||
|
||||
public Material InstantiateMaterial()
|
||||
{
|
||||
if (mainMaterial == null)
|
||||
{
|
||||
Demo_Player.instance.ResetMaterial();
|
||||
return null;
|
||||
}
|
||||
|
||||
Material newMaterial = Instantiate(mainMaterial);
|
||||
mainRenderer.material = newMaterial;
|
||||
|
||||
if (newMaterial != null && !ignorePlayer)
|
||||
{
|
||||
Demo_Player.instance.ApplyMaterial(newMaterial);
|
||||
}
|
||||
else
|
||||
{
|
||||
Demo_Player.instance.ResetMaterial();
|
||||
}
|
||||
|
||||
return newMaterial;
|
||||
}
|
||||
|
||||
void UpdatePosition()
|
||||
{
|
||||
float position = transform.position.x / Demo_Shaders.instance.transform.localScale.x;
|
||||
|
||||
if (position < -camWidth * 1.4f)
|
||||
{
|
||||
slot += maxSlots;
|
||||
}else if(position > camWidth * 1.4f)
|
||||
{
|
||||
slot -= maxSlots;
|
||||
}
|
||||
|
||||
transform.localPosition = new Vector3(2.75f * slot, -3.25f * row, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61a62e02a5514794596a0707a24170c4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SpriteShadersUltimate.Demo
|
||||
{
|
||||
public class Demo_DisplayTitle : MonoBehaviour
|
||||
{
|
||||
public Transform target;
|
||||
|
||||
RectTransform rectTransform;
|
||||
RectTransform rectParent;
|
||||
|
||||
void Start()
|
||||
{
|
||||
rectTransform = GetComponent<RectTransform>();
|
||||
rectParent = transform.parent.GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
Vector3 screenPosition = RectTransformUtility.WorldToScreenPoint(Camera.main, target.position);
|
||||
|
||||
|
||||
Vector2 rectPosition;
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectParent, screenPosition, Camera.main, out rectPosition);
|
||||
|
||||
rectTransform.anchoredPosition = rectPosition;
|
||||
|
||||
transform.localScale = target.lossyScale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 730d145ce9bfd0847839d0ec91dbf0a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,129 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace SpriteShadersUltimate.Demo
|
||||
{
|
||||
public class Demo_FloatPicker : MonoBehaviour
|
||||
{
|
||||
public Material targetMaterial;
|
||||
public string propertyName;
|
||||
|
||||
Slider slider;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if(slider == null)
|
||||
{
|
||||
//References:
|
||||
slider = transform.Find("Slider").GetComponent<Slider>();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTarget(Material newMaterial, string newProperty, string shaderName)
|
||||
{
|
||||
Start();
|
||||
|
||||
targetMaterial = newMaterial;
|
||||
propertyName = newProperty;
|
||||
|
||||
//Limits:
|
||||
float floatValue = targetMaterial.GetFloat(propertyName);
|
||||
int propIndex = targetMaterial.shader.FindPropertyIndex(propertyName);
|
||||
if (targetMaterial.shader.GetPropertyType(propIndex) == UnityEngine.Rendering.ShaderPropertyType.Range)
|
||||
{
|
||||
Vector2 limits = targetMaterial.shader.GetPropertyRangeLimits(propIndex);
|
||||
slider.minValue = limits.x;
|
||||
slider.maxValue = limits.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (newProperty.EndsWith("Contrast"))
|
||||
{
|
||||
slider.minValue = 0f;
|
||||
slider.maxValue = 3f;
|
||||
}
|
||||
else if (newProperty.EndsWith("Saturation"))
|
||||
{
|
||||
slider.minValue = 0f;
|
||||
slider.maxValue = 2f;
|
||||
}
|
||||
else if (newProperty.EndsWith("Brightness"))
|
||||
{
|
||||
slider.minValue = 0f;
|
||||
slider.maxValue = 5f;
|
||||
}
|
||||
else if (newProperty.EndsWith("PixelDensity"))
|
||||
{
|
||||
slider.minValue = 1f;
|
||||
slider.maxValue = 32f;
|
||||
}
|
||||
else
|
||||
{
|
||||
float limit = 1f;
|
||||
while (Mathf.Abs(floatValue) > limit)
|
||||
{
|
||||
limit *= 10f;
|
||||
}
|
||||
slider.minValue = -limit;
|
||||
slider.maxValue = limit;
|
||||
}
|
||||
}
|
||||
|
||||
if (newProperty.EndsWith("Width"))
|
||||
{
|
||||
slider.minValue = 0f;
|
||||
}
|
||||
|
||||
//Load:
|
||||
LoadFloat(floatValue);
|
||||
|
||||
//Title:
|
||||
string displayString = newProperty.Replace("_" + shaderName.Replace(" ", ""), "");
|
||||
char[] displayChars = displayString.ToCharArray();
|
||||
displayString = "";
|
||||
for(int c = 0; c < displayChars.Length; c++)
|
||||
{
|
||||
if(c > 0 && displayChars[c].ToString().ToUpper() == displayChars[c].ToString())
|
||||
{
|
||||
displayString += " ";
|
||||
}
|
||||
|
||||
displayString += displayChars[c];
|
||||
}
|
||||
|
||||
if (displayString == "") displayString = "Value";
|
||||
transform.Find("Title").GetComponent<Text>().text = displayString;
|
||||
}
|
||||
|
||||
public void LoadFloat(float floatValue)
|
||||
{
|
||||
slider.SetValueWithoutNotify(floatValue);
|
||||
UpdateFloat(floatValue);
|
||||
}
|
||||
|
||||
public void UpdateFloat(float floatValue)
|
||||
{
|
||||
//String:
|
||||
string floatString = floatValue.ToString().Replace(",", ".");
|
||||
string[] splitValues = floatString.Split('.');
|
||||
if (splitValues.Length > 1)
|
||||
{
|
||||
floatString = splitValues[0] + "." + splitValues[1].Substring(0, Mathf.Min(splitValues[1].Length, 2));
|
||||
}
|
||||
transform.Find("Value").GetComponent<Text>().text = floatString;
|
||||
|
||||
if(targetMaterial != null)
|
||||
{
|
||||
targetMaterial.SetFloat(propertyName, floatValue);
|
||||
}
|
||||
}
|
||||
|
||||
public void SliderChanged()
|
||||
{
|
||||
UpdateFloat(slider.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 384bca986640c8e44bd32d54a80f4139
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,257 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace SpriteShadersUltimate.Demo
|
||||
{
|
||||
public class Demo_GUI : MonoBehaviour
|
||||
{
|
||||
public static Demo_GUI instance;
|
||||
|
||||
GameObject displayTitlePrefab;
|
||||
RectTransform propertyRect;
|
||||
CanvasGroup hudCG;
|
||||
Slider slider;
|
||||
|
||||
float scrollArea;
|
||||
float targetHeight;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
instance = this;
|
||||
|
||||
hudCG = transform.Find("Shader Hud").GetComponent<CanvasGroup>();
|
||||
displayTitlePrefab = transform.Find("Display Titles/Title Prefab").gameObject;
|
||||
propertyRect = transform.Find("Shader Hud/Properties/Rect").GetComponent<RectTransform>();
|
||||
slider = transform.Find("Shader Hud/Properties/Slider").GetComponent<Slider>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
hudCG.alpha = Mathf.Lerp(hudCG.alpha, Demo_Shaders.instance.FadeInGUI() ? 1.1f : -0.1f, Time.unscaledDeltaTime * 7.5f);
|
||||
|
||||
if(hudCG.alpha > 0.5f)
|
||||
{
|
||||
if (slider.gameObject.activeInHierarchy)
|
||||
{
|
||||
float strength = 100f / Mathf.Abs(scrollArea - 500f);
|
||||
if (Input.mouseScrollDelta.y > 0.01f)
|
||||
{
|
||||
slider.SetValueWithoutNotify(Mathf.Clamp01(slider.value - strength));
|
||||
UpdateScroll();
|
||||
}
|
||||
else if (Input.mouseScrollDelta.y < -0.01)
|
||||
{
|
||||
slider.SetValueWithoutNotify(Mathf.Clamp01(slider.value + strength));
|
||||
UpdateScroll();
|
||||
}
|
||||
}
|
||||
|
||||
propertyRect.anchoredPosition = new Vector2(0, Mathf.Lerp(propertyRect.anchoredPosition.y, targetHeight, Time.unscaledDeltaTime * 8f));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void CreateTitle(string title, Transform target)
|
||||
{
|
||||
GameObject newTitle = Instantiate<GameObject>(displayTitlePrefab);
|
||||
newTitle.transform.SetParent(displayTitlePrefab.transform.parent, true);
|
||||
newTitle.name = title;
|
||||
|
||||
newTitle.GetComponent<Demo_DisplayTitle>().target = target;
|
||||
newTitle.GetComponent<Text>().text = title;
|
||||
newTitle.SetActive(true);
|
||||
}
|
||||
|
||||
public void UpdateHud()
|
||||
{
|
||||
//Toggle Interaction:
|
||||
if (Demo_Display.selected == null)
|
||||
{
|
||||
hudCG.blocksRaycasts = hudCG.interactable = false;
|
||||
return;
|
||||
}
|
||||
hudCG.blocksRaycasts = hudCG.interactable = true;
|
||||
|
||||
//Set Title:
|
||||
Transform hud = transform.Find("Shader Hud");
|
||||
hud.Find("Shader Title").GetComponent<Text>().text = Demo_Display.selected.gameObject.name;
|
||||
|
||||
//Alternative Button:
|
||||
float currentY = 240f;
|
||||
if (Demo_Display.selected.HasAlternatives())
|
||||
{
|
||||
propertyRect.Find("AlternativeButton").gameObject.SetActive(true);
|
||||
currentY = 240f - 60f;
|
||||
}
|
||||
else
|
||||
{
|
||||
propertyRect.Find("AlternativeButton").gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
//Properties:
|
||||
Transform properties = hud.Find("Properties");
|
||||
GameObject colorPrefab = properties.Find("Color").gameObject;
|
||||
colorPrefab.SetActive(false);
|
||||
GameObject floatPrefab = properties.Find("Float").gameObject;
|
||||
floatPrefab.SetActive(false);
|
||||
GameObject vectorPrefab = properties.Find("Vector").gameObject;
|
||||
vectorPrefab.SetActive(false);
|
||||
|
||||
//Clear Properties:
|
||||
for (int c = 0; c < propertyRect.childCount; c++)
|
||||
{
|
||||
Transform child = propertyRect.GetChild(c);
|
||||
|
||||
if(child.gameObject.name != "AlternativeButton")
|
||||
{
|
||||
Destroy(propertyRect.GetChild(c).gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
//Create Properties:
|
||||
Material mat = Demo_Display.selected.InstantiateMaterial();
|
||||
if (mat == null)
|
||||
{
|
||||
slider.gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
int index = mat.shader.FindPropertyIndex(Demo_Display.selected.firstProperty);
|
||||
int maxCount = mat.shader.GetPropertyCount();
|
||||
bool hidden = false;
|
||||
while(index < maxCount)
|
||||
{
|
||||
string propertyName = mat.shader.GetPropertyName(index);
|
||||
ShaderPropertyType propertyType = mat.shader.GetPropertyType(index);
|
||||
index++;
|
||||
if (propertyName.StartsWith("_Enable"))
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!IsKeyword(propertyName))
|
||||
{
|
||||
if (hidden)
|
||||
{
|
||||
if (propertyName == "_EnchantedLowColor" || propertyName == "_EnchantedHighColor" || propertyName == "_ShiftingColorA" || propertyName == "_ShiftingColorB")
|
||||
{
|
||||
//No Skipping
|
||||
}
|
||||
else
|
||||
{
|
||||
continue; //Skip hidden properties.
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (propertyName == "_EnchantedLowColor" || propertyName == "_EnchantedHighColor" || propertyName == "_ShiftingColorA" || propertyName == "_ShiftingColorB")
|
||||
{
|
||||
continue; //Skipping if not Hidden
|
||||
}
|
||||
}
|
||||
|
||||
RectTransform newRect = null;
|
||||
if (propertyType == ShaderPropertyType.Color)
|
||||
{
|
||||
GameObject newColor = Instantiate<GameObject>(colorPrefab);
|
||||
newColor.transform.SetParent(propertyRect, true);
|
||||
newColor.transform.position = colorPrefab.transform.position;
|
||||
newColor.transform.localScale = Vector3.one;
|
||||
newColor.SetActive(true);
|
||||
|
||||
newRect = newColor.GetComponent<RectTransform>();
|
||||
newColor.GetComponent<Demo_ColorPicker>().SetTarget(mat, propertyName, Demo_Display.selected.gameObject.name);
|
||||
}
|
||||
else if (propertyType == ShaderPropertyType.Float || propertyType == ShaderPropertyType.Range)
|
||||
{
|
||||
GameObject newFloat = Instantiate<GameObject>(floatPrefab);
|
||||
newFloat.transform.SetParent(propertyRect, true);
|
||||
newFloat.transform.position = floatPrefab.transform.position;
|
||||
newFloat.transform.localScale = Vector3.one;
|
||||
newFloat.SetActive(true);
|
||||
|
||||
newRect = newFloat.GetComponent<RectTransform>();
|
||||
newFloat.GetComponent<Demo_FloatPicker>().SetTarget(mat, propertyName, Demo_Display.selected.gameObject.name);
|
||||
}
|
||||
else if (propertyType == ShaderPropertyType.Vector)
|
||||
{
|
||||
GameObject newVector = Instantiate<GameObject>(vectorPrefab);
|
||||
newVector.transform.SetParent(propertyRect, true);
|
||||
newVector.transform.position = vectorPrefab.transform.position;
|
||||
newVector.transform.localScale = Vector3.one;
|
||||
newVector.SetActive(true);
|
||||
|
||||
newRect = newVector.GetComponent<RectTransform>();
|
||||
newVector.GetComponent<Demo_VectorPicker>().SetTarget(mat, propertyName, Demo_Display.selected.gameObject.name);
|
||||
}
|
||||
|
||||
if (newRect != null)
|
||||
{
|
||||
Vector2 anchoredPosition = newRect.anchoredPosition;
|
||||
anchoredPosition.y = currentY - newRect.sizeDelta.y * 0.5f;
|
||||
currentY -= newRect.sizeDelta.y;
|
||||
newRect.anchoredPosition = anchoredPosition;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hidden = mat.GetFloat(propertyName) < 0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
scrollArea = 240f - currentY;
|
||||
slider.SetValueWithoutNotify(0f);
|
||||
slider.gameObject.SetActive(scrollArea > 500f);
|
||||
targetHeight = 0f;
|
||||
}
|
||||
|
||||
public static bool IsKeyword(string propName)
|
||||
{
|
||||
if (propName.StartsWith("_Toggle") || propName.EndsWith("Toggle") || propName.EndsWith("Invert") || propName == "PixelSnap" || propName == "_ShaderSpace" || propName == "_SmokeVertexSeed" || propName == "_ShaderFading" || propName == "_BakedMaterial" || propName == "_SpriteSheetFix" || propName == "_ForceAlpha" || propName == "_VertexTintFirst" || propName == "_PixelPerfectSpace" || propName == "_PixelPerfectUV" || propName == "_WindLocalWind" || propName == "_WindHighQualityNoise" || propName == "_WindIsParallax" || propName == "_WindFlip" || propName == "_SquishFlip")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Buttons:
|
||||
public void BackButton()
|
||||
{
|
||||
if(Demo_Display.selected != null)
|
||||
{
|
||||
Demo_Display.selected.Deselect();
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetMaterialButton()
|
||||
{
|
||||
if (Demo_Display.selected != null)
|
||||
{
|
||||
UpdateHud();
|
||||
}
|
||||
}
|
||||
|
||||
public void AlternativeButton()
|
||||
{
|
||||
if(Demo_Display.selected != null)
|
||||
{
|
||||
Demo_Display.selected.InstantiateMaterial();
|
||||
Demo_Display.selected.ChangeIndex();
|
||||
UpdateHud();
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateScroll()
|
||||
{
|
||||
targetHeight = slider.value * (scrollArea - 500f);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dfd9b85be57ad1d40b8879150fcb48ca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,174 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SpriteShadersUltimate.Demo
|
||||
{
|
||||
public class Demo_Player : MonoBehaviour
|
||||
{
|
||||
public static Demo_Player instance;
|
||||
|
||||
[Header("Sprites:")]
|
||||
public List<Sprite> idleSprites;
|
||||
public List<Sprite> runningSprites;
|
||||
public List<Sprite> hurtSprites;
|
||||
|
||||
[Header("Other:")]
|
||||
public bool ignoreMaterials;
|
||||
|
||||
//References:
|
||||
SpriteRenderer spriteRenderer;
|
||||
Rigidbody2D rig;
|
||||
|
||||
//Runtime:
|
||||
float nextFrame;
|
||||
int currentIndex;
|
||||
List<Sprite> currentAnimation;
|
||||
Material originalMaterial;
|
||||
Material currentMaterial;
|
||||
Vector3 snapPosition;
|
||||
bool isShadow;
|
||||
|
||||
void Start()
|
||||
{
|
||||
instance = this;
|
||||
|
||||
//References:
|
||||
spriteRenderer = transform.Find("SpriteRenderer").GetComponent<SpriteRenderer>();
|
||||
rig = GetComponent<Rigidbody2D>();
|
||||
|
||||
if (!ignoreMaterials)
|
||||
{
|
||||
currentMaterial = originalMaterial = spriteRenderer.material;
|
||||
}
|
||||
|
||||
//Initialize:
|
||||
nextFrame = -1f;
|
||||
|
||||
//Idle:
|
||||
PlayAnimation(idleSprites);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
//Animation:
|
||||
if (Time.time > nextFrame)
|
||||
{
|
||||
spriteRenderer.sprite = currentAnimation[currentIndex];
|
||||
|
||||
if(currentAnimation == runningSprites)
|
||||
{
|
||||
nextFrame = Time.time + 0.2f / Mathf.Max(Mathf.Abs(rig.linearVelocity.x), 3.5f);
|
||||
}
|
||||
else
|
||||
{
|
||||
nextFrame = Time.time + 0.065f;
|
||||
}
|
||||
|
||||
currentIndex++;
|
||||
if(currentIndex >= currentAnimation.Count)
|
||||
{
|
||||
currentIndex = 0;
|
||||
|
||||
if(currentAnimation == hurtSprites)
|
||||
{
|
||||
currentAnimation = idleSprites;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (snapPosition != Vector3.zero)
|
||||
{
|
||||
//Snap to position:
|
||||
rig.linearVelocity = Vector2.Lerp(rig.linearVelocity, new Vector2(0, -1f), Time.deltaTime * 5f);
|
||||
if (Mathf.Abs(rig.linearVelocity.x) < 1f && currentAnimation != hurtSprites)
|
||||
{
|
||||
PlayAnimation(idleSprites);
|
||||
}
|
||||
|
||||
transform.position = Vector3.Lerp(transform.position, snapPosition, Time.deltaTime * 6f);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Movement:
|
||||
if ((Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) && currentAnimation != hurtSprites)
|
||||
{
|
||||
rig.linearVelocity = Vector2.Lerp(rig.linearVelocity, new Vector2(7f, -1f), Time.deltaTime * 5f);
|
||||
transform.eulerAngles = new Vector3(0, 0, 0);
|
||||
PlayAnimation(runningSprites);
|
||||
}
|
||||
else if ((Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) && currentAnimation != hurtSprites)
|
||||
{
|
||||
rig.linearVelocity = Vector2.Lerp(rig.linearVelocity, new Vector2(-7f, -1f), Time.deltaTime * 5f);
|
||||
transform.eulerAngles = new Vector3(0, 180, 0);
|
||||
PlayAnimation(runningSprites);
|
||||
}
|
||||
else
|
||||
{
|
||||
rig.linearVelocity = Vector2.Lerp(rig.linearVelocity, new Vector2(0, -1f), Time.deltaTime * 5f);
|
||||
|
||||
if (Mathf.Abs(rig.linearVelocity.x) < 1f && currentAnimation != hurtSprites)
|
||||
{
|
||||
PlayAnimation(idleSprites);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Adjust Shadow Offset:
|
||||
if(isShadow)
|
||||
{
|
||||
MaterialPropertyBlock mpb = new MaterialPropertyBlock();
|
||||
spriteRenderer.GetPropertyBlock(mpb);
|
||||
Vector2 offset = currentMaterial.GetVector("_ShadowOffset");
|
||||
if(transform.eulerAngles.y > 90)
|
||||
{
|
||||
offset.x = -offset.x;
|
||||
}
|
||||
mpb.SetVector("_ShadowOffset", offset);
|
||||
spriteRenderer.SetPropertyBlock(mpb);
|
||||
}
|
||||
}
|
||||
|
||||
public void GetHurt(Vector2 velocity)
|
||||
{
|
||||
rig.linearVelocity = velocity;
|
||||
transform.eulerAngles = new Vector3(0, velocity.x > 0 ? 180 : 0, 0);
|
||||
PlayAnimation(hurtSprites);
|
||||
}
|
||||
|
||||
void PlayAnimation(List<Sprite> animation)
|
||||
{
|
||||
if(currentAnimation != animation)
|
||||
{
|
||||
currentAnimation = animation;
|
||||
currentIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyMaterial(Material material)
|
||||
{
|
||||
spriteRenderer.material = currentMaterial = material;
|
||||
|
||||
isShadow = material.name.StartsWith("SSU_Demo_Shadow");
|
||||
}
|
||||
|
||||
public void SnapPosition(Vector3 newPosition)
|
||||
{
|
||||
snapPosition = newPosition;
|
||||
}
|
||||
|
||||
public void ResetPosition()
|
||||
{
|
||||
transform.position = new Vector3(6f, -2.645f, 0);
|
||||
transform.eulerAngles = new Vector3(0, 180, 0);
|
||||
}
|
||||
|
||||
public void ResetMaterial()
|
||||
{
|
||||
spriteRenderer.material = originalMaterial;
|
||||
currentMaterial = originalMaterial;
|
||||
isShadow = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: abbbff4ef1cc7bf4e8cbae3277c4004b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,139 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SpriteShadersUltimate.Demo
|
||||
{
|
||||
public class Demo_Shaders : MonoBehaviour
|
||||
{
|
||||
public static Demo_Shaders instance;
|
||||
public static float zoomFactor;
|
||||
|
||||
GameObject environmentGO;
|
||||
List<SpriteRenderer> environmentSprites;
|
||||
Vector3 currentPosition;
|
||||
|
||||
float lastZoomFactor;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
//Reference:
|
||||
instance = this;
|
||||
|
||||
//Environment:
|
||||
Transform environment = GameObject.Find("Environment").transform;
|
||||
environmentSprites = new List<SpriteRenderer>();
|
||||
foreach(SpriteRenderer sr in environment.GetComponentsInChildren<SpriteRenderer>())
|
||||
{
|
||||
environmentSprites.Add(sr);
|
||||
}
|
||||
environmentGO = environment.gameObject;
|
||||
|
||||
//Initialize:
|
||||
Demo_Display.selected = null;
|
||||
currentPosition = Vector3.zero;
|
||||
zoomFactor = 0f;
|
||||
lastZoomFactor = -1000;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
//Zoom Factor:
|
||||
if (Demo_Display.selected != null)
|
||||
{
|
||||
zoomFactor += Time.unscaledDeltaTime * 2f;
|
||||
if (zoomFactor > 1f) zoomFactor = 1f;
|
||||
}
|
||||
else
|
||||
{
|
||||
zoomFactor -= Time.unscaledDeltaTime * 2f;
|
||||
if (zoomFactor < 0f) zoomFactor = 0f;
|
||||
}
|
||||
|
||||
//Scale:
|
||||
float scale = 1f + 6.2f * zoomFactor;
|
||||
transform.localScale = new Vector3(scale, scale, 1);
|
||||
|
||||
if (zoomFactor != lastZoomFactor)
|
||||
{
|
||||
//Environment:
|
||||
float alpha = Mathf.Clamp01((zoomFactor - 0.75f) / 0.25f);
|
||||
foreach (SpriteRenderer sprite in environmentSprites)
|
||||
{
|
||||
Color color = sprite.color;
|
||||
color.a = alpha;
|
||||
sprite.color = color;
|
||||
}
|
||||
|
||||
if(alpha > 0f)
|
||||
{
|
||||
if(!environmentGO.activeSelf)
|
||||
{
|
||||
environmentGO.SetActive(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (environmentGO.activeSelf)
|
||||
{
|
||||
environmentGO.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
//Other:
|
||||
lastZoomFactor = zoomFactor;
|
||||
}
|
||||
|
||||
//Position:
|
||||
if(Demo_Display.selected != null)
|
||||
{
|
||||
currentPosition = Vector3.Lerp(currentPosition, -Demo_Display.selected.transform.localPosition, Time.unscaledDeltaTime * 10f);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
float movement = 0f;
|
||||
if(AllowMovement())
|
||||
{
|
||||
movement = 2f * (Screen.width * 0.5f - Input.mousePosition.x) / (float)Screen.width;
|
||||
if(Mathf.Abs(movement) < 0.6f)
|
||||
{
|
||||
movement = 0;
|
||||
}
|
||||
else if (Input.mousePosition.x < Screen.width && Input.mousePosition.x > 0)
|
||||
{
|
||||
movement += movement < 0 ? 0.6f : -0.6f;
|
||||
movement *= 2f;
|
||||
movement = Mathf.Clamp(movement, -1f, 1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
movement = 0;
|
||||
}
|
||||
}
|
||||
|
||||
currentPosition = Vector3.Lerp(currentPosition, new Vector3(currentPosition.x + movement, 0, 0), Time.unscaledDeltaTime * 14f / scale);
|
||||
}
|
||||
transform.position = currentPosition * scale;
|
||||
|
||||
//Controls:
|
||||
if(Demo_Display.selected != null)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
Demo_Display.selected.Deselect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool AllowMovement()
|
||||
{
|
||||
return zoomFactor < 0.1f;
|
||||
}
|
||||
|
||||
public bool FadeInGUI()
|
||||
{
|
||||
return zoomFactor > 0.9f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 464bb5c7a6036cf42b31b9063be08bc9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,55 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SpriteShadersUltimate.Demo
|
||||
{
|
||||
public class Demo_SpriteFader : MonoBehaviour
|
||||
{
|
||||
SpriteRenderer sr;
|
||||
bool fadeIn;
|
||||
|
||||
float fadeDelay;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
sr = GetComponent<SpriteRenderer>();
|
||||
fadeIn = true;
|
||||
fadeDelay = 0f;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
//Delay:
|
||||
if(fadeDelay > 0)
|
||||
{
|
||||
fadeDelay -= Time.unscaledDeltaTime;
|
||||
return;
|
||||
}
|
||||
|
||||
//Fading:
|
||||
Color color = sr.color;
|
||||
color.a = Mathf.Clamp01(Mathf.Lerp(color.a, fadeIn ? 1.1f : -0.1f, Time.deltaTime * (fadeIn ? 8f : 4f)));
|
||||
sr.color = color;
|
||||
|
||||
if((fadeIn && color.a >= 1f) || (!fadeIn && color.a <= 0f))
|
||||
{
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetFade(bool fadeState)
|
||||
{
|
||||
fadeIn = fadeState;
|
||||
enabled = true;
|
||||
|
||||
if(!fadeIn)
|
||||
{
|
||||
fadeDelay = 0.15f;
|
||||
}
|
||||
|
||||
sr.sortingOrder = fadeIn ? 4 : 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a5b0e314acd3d64f8a00ee70d0b6c44
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,104 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace SpriteShadersUltimate.Demo
|
||||
{
|
||||
public class Demo_Trigger : MonoBehaviour
|
||||
{
|
||||
ShaderFaderSSU fader;
|
||||
|
||||
public List<Demo_TriggerEvent> events;
|
||||
|
||||
void Start()
|
||||
{
|
||||
fader = GetComponent<ShaderFaderSSU>();
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if(collision.name == "Player")
|
||||
{
|
||||
ChangeState(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit2D(Collider2D collision)
|
||||
{
|
||||
if (collision.name == "Player")
|
||||
{
|
||||
ChangeState(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeState(bool isActive)
|
||||
{
|
||||
if (fader != null)
|
||||
{
|
||||
fader.isFaded = isActive;
|
||||
}
|
||||
|
||||
if (events != null && isActive)
|
||||
{
|
||||
foreach (Demo_TriggerEvent demoEvent in events)
|
||||
{
|
||||
StartCoroutine(PlayEvent(demoEvent));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator PlayEvent(Demo_TriggerEvent demoEvent)
|
||||
{
|
||||
yield return new WaitForSeconds(demoEvent.delay);
|
||||
demoEvent.Play(transform);
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class Demo_TriggerEvent
|
||||
{
|
||||
[Header("Delay:")]
|
||||
public float delay;
|
||||
|
||||
[Header("Change Fader:")]
|
||||
public ShaderFaderSSU fader;
|
||||
public bool faderState;
|
||||
public bool negateState;
|
||||
|
||||
[Header("Snap Player:")]
|
||||
public bool snapPlayer;
|
||||
public bool isRelative;
|
||||
public Vector3 snapPosition;
|
||||
|
||||
[Header("Hurt Player:")]
|
||||
public bool hurtPlayer;
|
||||
public Vector2 velocity;
|
||||
|
||||
public void Play(Transform source)
|
||||
{
|
||||
if(fader != null)
|
||||
{
|
||||
if(negateState)
|
||||
{
|
||||
fader.isFaded = !fader.isFaded;
|
||||
}
|
||||
else
|
||||
{
|
||||
fader.isFaded = faderState;
|
||||
}
|
||||
}
|
||||
|
||||
if(snapPlayer)
|
||||
{
|
||||
Demo_Player.instance.SnapPosition(isRelative ? source.position + snapPosition : snapPosition);
|
||||
}
|
||||
|
||||
if(hurtPlayer)
|
||||
{
|
||||
Demo_Player.instance.GetHurt(velocity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43b51e33e72fa5140be7c05bb406cab4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SpriteShadersUltimate.Demo
|
||||
{
|
||||
public class Demo_VectorFollow : MonoBehaviour
|
||||
{
|
||||
//Public:
|
||||
public string propertyName;
|
||||
public Transform trackedTransform;
|
||||
|
||||
//Internal:
|
||||
Material mat;
|
||||
|
||||
void Start()
|
||||
{
|
||||
Renderer renderer = GetComponentInChildren<Renderer>();
|
||||
|
||||
if(renderer.sharedMaterial.name.EndsWith("(Instance)"))
|
||||
{
|
||||
mat = renderer.sharedMaterial;
|
||||
}
|
||||
else
|
||||
{
|
||||
mat = renderer.material;
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
mat.SetVector(propertyName, trackedTransform.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 818e89473bfe65444a44bc1ad4725ed0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,118 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace SpriteShadersUltimate.Demo
|
||||
{
|
||||
public class Demo_VectorPicker : MonoBehaviour
|
||||
{
|
||||
public Material targetMaterial;
|
||||
public string propertyName;
|
||||
|
||||
Slider slider1;
|
||||
Slider slider2;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if(slider1 == null)
|
||||
{
|
||||
//References:
|
||||
slider1 = transform.Find("Slider 1").GetComponent<Slider>();
|
||||
slider2 = transform.Find("Slider 2").GetComponent<Slider>();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTarget(Material newMaterial, string newProperty, string shaderName)
|
||||
{
|
||||
Start();
|
||||
|
||||
targetMaterial = newMaterial;
|
||||
propertyName = newProperty;
|
||||
|
||||
//Limits:
|
||||
Vector2 vectorValue = targetMaterial.GetVector(propertyName);
|
||||
int propIndex = targetMaterial.shader.FindPropertyIndex(propertyName);
|
||||
|
||||
|
||||
float absValue = (Mathf.Abs(vectorValue.x) + Mathf.Abs(vectorValue.y) * 0.5f);
|
||||
|
||||
if (absValue < 1f)
|
||||
{
|
||||
slider1.minValue = slider2.minValue = -1;
|
||||
slider1.maxValue = slider2.maxValue = 1f;
|
||||
} else if (absValue < 2f)
|
||||
{
|
||||
slider1.minValue = slider2.minValue = -2;
|
||||
slider1.maxValue = slider2.maxValue = 2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
slider1.minValue = slider2.minValue = -absValue * 2;
|
||||
slider1.maxValue = slider2.maxValue = absValue * 2f;
|
||||
}
|
||||
|
||||
if(propertyName.EndsWith("Scale"))
|
||||
{
|
||||
slider1.minValue = slider2.minValue = 0f;
|
||||
}
|
||||
|
||||
//Load:
|
||||
LoadVector(vectorValue);
|
||||
|
||||
//Title:
|
||||
string displayString = newProperty.Replace("_" + shaderName.Replace(" ", ""), "");
|
||||
char[] displayChars = displayString.ToCharArray();
|
||||
displayString = "";
|
||||
for(int c = 0; c < displayChars.Length; c++)
|
||||
{
|
||||
if(c > 0 && displayChars[c].ToString().ToUpper() == displayChars[c].ToString())
|
||||
{
|
||||
displayString += " ";
|
||||
}
|
||||
|
||||
displayString += displayChars[c];
|
||||
}
|
||||
|
||||
if (displayString == "") displayString = "Value";
|
||||
transform.Find("Title").GetComponent<Text>().text = displayString;
|
||||
}
|
||||
|
||||
public void LoadVector(Vector2 vectorValue)
|
||||
{
|
||||
slider1.SetValueWithoutNotify(vectorValue.x);
|
||||
slider2.SetValueWithoutNotify(vectorValue.y);
|
||||
UpdateVector(vectorValue);
|
||||
}
|
||||
|
||||
public void UpdateVector(Vector2 vectorValue)
|
||||
{
|
||||
//String:
|
||||
SetSliderValue(slider1, vectorValue.x);
|
||||
SetSliderValue(slider2, vectorValue.y);
|
||||
|
||||
//Material:
|
||||
if (targetMaterial != null)
|
||||
{
|
||||
targetMaterial.SetVector(propertyName, vectorValue);
|
||||
}
|
||||
}
|
||||
|
||||
void SetSliderValue(Slider toSlider, float toValue)
|
||||
{
|
||||
string floatString = toValue.ToString().Replace(",", ".");
|
||||
string[] splitValues = floatString.Split('.');
|
||||
if (splitValues.Length > 1)
|
||||
{
|
||||
floatString = splitValues[0] + "." + splitValues[1].Substring(0, Mathf.Min(splitValues[1].Length, Mathf.Abs(toValue) >= 0.01f ? 2 : 3));
|
||||
}
|
||||
toSlider.transform.Find("Value").GetComponent<Text>().text = floatString;
|
||||
}
|
||||
|
||||
public void SliderChanged()
|
||||
{
|
||||
UpdateVector(new Vector2(slider1.value, slider2.value));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95711d15510f8cd4c80e4f6ae87a5580
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user