-NOM DU SCRIPT : BarGUI et Bar3D
-AUTEUR(S): Titan
-DESCRIPTION : affiche une barre de vie, énergie, etc
-UTILISATION : voir le readme, rapidement: ajouter sur un quad, choisir une couleur, une texture de jauge, un gradient, une texture de contour, ensuite il suffit de bind _cutValue sur votre variable à afficher sur l’intervalle 0 à 1.
-SCRIPT : voir le package, sinon en 1er la version 3D et en 2eme la version pseudo-GUI
Code : Tout sélectionner
Shader "Bar/Bar3D"
{
Properties //
{
_Color ("Main Color", Color) = (1,1,1,0.5)
_CutValue ("Bar value", Range (0, 0.99)) = 0.99
_MainTex ("Main Texture", 2D) = ""
_Gradient ("Gradient", 2D) = ""
_Border ("Border", 2D) = ""
}
SubShader
{
Blend SrcAlpha OneMinusSrcAlpha
Tags {Queue=Transparent}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
float4 _Color;
float _CutValue;
sampler2D _MainTex;
sampler2D _Gradient;
sampler2D _Border;
uniform float4 _MainTex_ST;
uniform float4 _Gradient_ST;
uniform float4 _Border_ST;
struct v2f {
float4 pos : SV_POSITION;
float2 UV_MainTex : TEXCOORD0;
float2 UV_Gradient : TEXCOORD1;
float2 UV_Border : TEXCOORD2;
};
v2f vert (appdata_base v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.UV_MainTex = TRANSFORM_TEX (v.texcoord, _MainTex);
o.UV_Gradient = TRANSFORM_TEX (v.texcoord, _Gradient);
o.UV_Border = TRANSFORM_TEX (v.texcoord, _Border);
return o;
}
half4 frag (v2f i) : COLOR
{
half4 borderColor = tex2D(_Border, i.UV_Border);
half4 barColor = float4(0, 0, 0, 0);
if (tex2D(_Gradient, i.UV_Gradient).x < _CutValue)
barColor = tex2D(_MainTex, i.UV_MainTex) * _Color;
return barColor * (1 - borderColor.a) + borderColor * borderColor.a;
}
ENDCG
}
}
}
Code : Tout sélectionner
Shader "Bar/BarGUI"
{
Properties //
{
_Color ("Main Color", Color) = (1,1,1,0.5)
_CutValue ("Bar value", Range (0, 0.99)) = 0.99
_Position("Position", Vector) = (1,1,0,0)
_MainTex ("Main Texture", 2D) = ""
_Gradient ("Gradient", 2D) = ""
_Border ("Border", 2D) = ""
}
SubShader
{
Blend SrcAlpha OneMinusSrcAlpha
Tags {"Queue" = "Transparent+100" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
float4 _Color;
float4 _Position;
float _Depth1;
float _Depth2;
float _CutValue;
sampler2D _MainTex;
sampler2D _Gradient;
sampler2D _Border;
uniform float4 _MainTex_ST;
uniform float4 _Gradient_ST;
uniform float4 _Border_ST;
struct v2f {
float4 pos : SV_POSITION;
float2 UV_MainTex : TEXCOORD0;
float2 UV_Gradient : TEXCOORD1;
float2 UV_Border : TEXCOORD2;
};
v2f vert (appdata_base v)
{
v2f o;
o.pos = v.vertex;
o.pos.xy *= _Position.xy * 2;
o.pos.xy += _Position.zw;
o.pos.z = 1;
o.pos.w = 1;
o.UV_MainTex = TRANSFORM_TEX (v.texcoord, _MainTex);
o.UV_Gradient = TRANSFORM_TEX (v.texcoord, _Gradient);
o.UV_Border = TRANSFORM_TEX (v.texcoord, _Border);
return o;
}
half4 frag (v2f i) : COLOR
{
half4 borderColor = tex2D(_Border, i.UV_Border);
half4 barColor = float4(0, 0, 0, 0);
if (tex2D(_Gradient, i.UV_Gradient).x < _CutValue)
barColor = tex2D(_MainTex, i.UV_MainTex) * _Color;
return barColor * (1 - borderColor.a) + borderColor * borderColor.a;
}
ENDCG
}
}
}
J'ai essayer de mettre ce shader sur le store (gratuitement), mais ça fait plus d'une semaine que c'est en "pending review" alors qu'ils avaient dit 3 jours max . y'a rien d'extraordinaire c'était juste pour découvrir leur pipeline, et en même temps les seuls équivalent sur le store sont à 15 euro.
[mode parano]d’ailleurs peut être qu'ils le mettent pas pour éviter de perdre des ventes, puisque ils touchent 30% ?[/mode parano]
bref dites moi ce que vous en pensez, et si ça peut vous être utile tant mieux, mais tant que le nouveau système de GUI n'est pas dispo ça reste du bricolage d'appliquer un shader à l'interface.
https://www.dropbox.com/s/5xdd7gdkej4sp ... itypackage
Si ils se décident à le publier je vais voir pour ajouter un éditeur de jauge qui créerai le gradient dans une class editor, parce que j'ai un peut galérer pour le sample spirale.