登录页调整 增加半圆角组件 基本完成路线列表功能 基本完成骑行列表 开始做编辑页
This commit is contained in:
1 parent
5156473bb2
commit
10e738f958
100 files changed
+20085
-11852
No files matched your search
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[ExecuteInEditMode]
|
||||
public class ImageWithIndependentRoundedCorners : MonoBehaviour {
|
||||
|
||||
public Vector4 r;
|
||||
private Material material;
|
||||
|
||||
// xy - position,
|
||||
// zw - halfSize
|
||||
[HideInInspector, SerializeField] private Vector4 rect2props;
|
||||
|
||||
private readonly int prop_halfSize = Shader.PropertyToID("_halfSize");
|
||||
private readonly int prop_radiuses = Shader.PropertyToID("_r");
|
||||
private readonly int prop_rect2props = Shader.PropertyToID("_rect2props");
|
||||
|
||||
// Vector2.right rotated clockwise by 45 degrees
|
||||
private static readonly Vector2 wNorm = new Vector2(.7071068f, -.7071068f);
|
||||
// Vector2.right rotated counter-clockwise by 45 degrees
|
||||
private static readonly Vector2 hNorm = new Vector2(.7071068f, .7071068f);
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Refresh();
|
||||
}
|
||||
void OnRectTransformDimensionsChange(){
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void OnValidate(){
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void RecalculateProps(Vector2 size){
|
||||
|
||||
// Vector that goes from left to right sides of rect2
|
||||
var aVec = new Vector2(size.x, -size.y + r.x + r.z);
|
||||
|
||||
// Project vector aVec to wNorm to get magnitude of rect2 width vector
|
||||
var halfWidth = Vector2.Dot(aVec, wNorm) * .5f;
|
||||
rect2props.z = halfWidth;
|
||||
|
||||
|
||||
// Vector that goes from bottom to top sides of rect2
|
||||
var bVec = new Vector2(size.x, size.y - r.w - r.y);
|
||||
|
||||
// Project vector bVec to hNorm to get magnitude of rect2 height vector
|
||||
var halfHeight = Vector2.Dot(bVec, hNorm) * .5f;
|
||||
rect2props.w = halfHeight;
|
||||
|
||||
|
||||
// Vector that goes from left to top sides of rect2
|
||||
var efVec = new Vector2(size.x - r.x - r.y, 0);
|
||||
// Vector that goes from point E to point G, which is top-left of rect2
|
||||
var egVec = hNorm * Vector2.Dot(efVec, hNorm);
|
||||
// Position of point E relative to center of coord system
|
||||
var ePoint = new Vector2(r.x - (size.x / 2), size.y / 2);
|
||||
// Origin of rect2 relative to center of coord system
|
||||
// ePoint + egVec == vector to top-left corner of rect2
|
||||
// wNorm * halfWidth + hNorm * -halfHeight == vector from top-left corner to center
|
||||
var origin = ePoint + egVec + wNorm * halfWidth + hNorm * -halfHeight;
|
||||
rect2props.x = origin.x;
|
||||
rect2props.y = origin.y;
|
||||
}
|
||||
|
||||
private void Refresh(){
|
||||
if (material == null)
|
||||
{
|
||||
material = Instantiate(Resources.Load<Material>("UI/Material/IndependentCornersMaterial"));
|
||||
}
|
||||
var rect = ((RectTransform) transform).rect;
|
||||
RecalculateProps(rect.size);
|
||||
material.SetVector(prop_rect2props, rect2props);
|
||||
material.SetVector(prop_halfSize, rect.size * .5f);
|
||||
material.SetVector(prop_radiuses, r);
|
||||
if (gameObject.GetComponent<Image>() != null)
|
||||
{
|
||||
gameObject.GetComponent<Image>().material = material;
|
||||
gameObject.GetComponent<Image>().sprite = null;
|
||||
}
|
||||
else if (gameObject.GetComponent<RawImage>() != null)
|
||||
{
|
||||
gameObject.GetComponent<RawImage>().material = material;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 109c41f08973846429af681aea0a30c4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,67 @@
|
||||
Shader "UI/RoundedCorners/IndependentRoundedCorners" {
|
||||
|
||||
Properties {
|
||||
[HideInInspector] _MainTex ("Texture", 2D) = "white" {}
|
||||
|
||||
// --- Mask support ---
|
||||
[HideInInspector] _StencilComp ("Stencil Comparison", Float) = 8
|
||||
[HideInInspector] _Stencil ("Stencil ID", Float) = 0
|
||||
[HideInInspector] _StencilOp ("Stencil Operation", Float) = 0
|
||||
[HideInInspector] _StencilWriteMask ("Stencil Write Mask", Float) = 255
|
||||
[HideInInspector] _StencilReadMask ("Stencil Read Mask", Float) = 255
|
||||
[HideInInspector] _ColorMask ("Color Mask", Float) = 15
|
||||
[HideInInspector] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
|
||||
// Definition in Properties section is required to Mask works properly
|
||||
_r ("r", Vector) = (0,0,0,0)
|
||||
_halfSize ("halfSize", Vector) = (0,0,0,0)
|
||||
_rect2props ("rect2props", Vector) = (0,0,0,0)
|
||||
// ---
|
||||
}
|
||||
|
||||
SubShader {
|
||||
Tags {
|
||||
"RenderType"="Transparent"
|
||||
"Queue"="Transparent"
|
||||
}
|
||||
|
||||
// --- Mask support ---
|
||||
Stencil {
|
||||
Ref [_Stencil]
|
||||
Comp [_StencilComp]
|
||||
Pass [_StencilOp]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
}
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZTest [unity_GUIZTestMode]
|
||||
ColorMask [_ColorMask]
|
||||
// ---
|
||||
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ZWrite Off
|
||||
|
||||
Pass {
|
||||
CGPROGRAM
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "SDFUtils.cginc"
|
||||
#include "ShaderSetup.cginc"
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
float4 _r;
|
||||
float4 _halfSize;
|
||||
float4 _rect2props;
|
||||
sampler2D _MainTex;
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target {
|
||||
float alpha = CalcAlphaForIndependentCorners(i.uv, _halfSize.xy, _rect2props, _r);
|
||||
return mixAlpha(tex2D(_MainTex, i.uv), i.color, alpha);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3beb88e61f88ca4393acdefb005fa70
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user