Properties Panel Overhaul
Marking player location on galaxy map Fixed non-input field focus disabling global key map Player start ship is now always the same Loadout generator now demands exact match for item dimensions Thermal damage now triggers ItemDamaged event = player can die from cockpit wear! Properties panel now has a much more attractive UI Implemented curve control for properties UI Centralized number formatting in player settings Moved significant digits to player settings Added temperature unit option in player settings
This commit is contained in:
parent
ec1f8f56d4
commit
54f7e3a66f
152 changed files with 8691 additions and 179 deletions
213
Assets/Plugins/AutoExpandGridLayoutGroup.cs
Normal file
213
Assets/Plugins/AutoExpandGridLayoutGroup.cs
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UnityEngine.UI
|
||||
{
|
||||
[AddComponentMenu("Layout/Auto Expand Grid Layout Group", 152)]
|
||||
public class AutoExpandGridLayoutGroup : LayoutGroup
|
||||
{
|
||||
public enum Corner { UpperLeft = 0, UpperRight = 1, LowerLeft = 2, LowerRight = 3 }
|
||||
public enum Axis { Horizontal = 0, Vertical = 1 }
|
||||
public enum Constraint { Flexible = 0, FixedColumnCount = 1, FixedRowCount = 2 }
|
||||
|
||||
[SerializeField]
|
||||
protected Corner m_StartCorner = Corner.UpperLeft;
|
||||
public Corner startCorner { get { return m_StartCorner; } set { SetProperty(ref m_StartCorner, value); } }
|
||||
|
||||
[SerializeField]
|
||||
protected Axis m_StartAxis = Axis.Horizontal;
|
||||
public Axis startAxis { get { return m_StartAxis; } set { SetProperty(ref m_StartAxis, value); } }
|
||||
|
||||
[SerializeField]
|
||||
protected Vector2 m_CellSize = new Vector2(100, 100);
|
||||
public Vector2 cellSize { get { return m_CellSize; } set { SetProperty(ref m_CellSize, value); } }
|
||||
|
||||
[SerializeField]
|
||||
protected Vector2 m_Spacing = Vector2.zero;
|
||||
public Vector2 spacing { get { return m_Spacing; } set { SetProperty(ref m_Spacing, value); } }
|
||||
|
||||
[SerializeField]
|
||||
protected Constraint m_Constraint = Constraint.Flexible;
|
||||
public Constraint constraint { get { return m_Constraint; } set { SetProperty(ref m_Constraint, value); } }
|
||||
|
||||
[SerializeField]
|
||||
protected int m_ConstraintCount = 2;
|
||||
public int constraintCount { get { return m_ConstraintCount; } set { SetProperty(ref m_ConstraintCount, Mathf.Max(1, value)); } }
|
||||
|
||||
protected AutoExpandGridLayoutGroup()
|
||||
{ }
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void OnValidate()
|
||||
{
|
||||
base.OnValidate();
|
||||
constraintCount = constraintCount;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void CalculateLayoutInputHorizontal()
|
||||
{
|
||||
base.CalculateLayoutInputHorizontal();
|
||||
|
||||
int minColumns = 0;
|
||||
int preferredColumns = 0;
|
||||
if (m_Constraint == Constraint.FixedColumnCount)
|
||||
{
|
||||
minColumns = preferredColumns = m_ConstraintCount;
|
||||
}
|
||||
else if (m_Constraint == Constraint.FixedRowCount)
|
||||
{
|
||||
minColumns = preferredColumns = Mathf.CeilToInt(rectChildren.Count / (float)m_ConstraintCount - 0.001f);
|
||||
}
|
||||
else
|
||||
{
|
||||
minColumns = 1;
|
||||
preferredColumns = Mathf.CeilToInt(Mathf.Sqrt(rectChildren.Count));
|
||||
}
|
||||
|
||||
SetLayoutInputForAxis(
|
||||
padding.horizontal + (cellSize.x + spacing.x) * minColumns - spacing.x,
|
||||
padding.horizontal + (cellSize.x + spacing.x) * preferredColumns - spacing.x,
|
||||
-1, 0);
|
||||
}
|
||||
|
||||
public override void CalculateLayoutInputVertical()
|
||||
{
|
||||
int minRows = 0;
|
||||
if (m_Constraint == Constraint.FixedColumnCount)
|
||||
{
|
||||
minRows = Mathf.CeilToInt(rectChildren.Count / (float)m_ConstraintCount - 0.001f);
|
||||
}
|
||||
else if (m_Constraint == Constraint.FixedRowCount)
|
||||
{
|
||||
minRows = m_ConstraintCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
float width = rectTransform.rect.size.x;
|
||||
int cellCountX = Mathf.Max(1, Mathf.FloorToInt((width - padding.horizontal + spacing.x + 0.001f) / (cellSize.x + spacing.x)));
|
||||
minRows = Mathf.CeilToInt(rectChildren.Count / (float)cellCountX);
|
||||
}
|
||||
|
||||
float minSpace = padding.vertical + (cellSize.y + spacing.y) * minRows - spacing.y;
|
||||
SetLayoutInputForAxis(minSpace, minSpace, -1, 1);
|
||||
}
|
||||
|
||||
public override void SetLayoutHorizontal()
|
||||
{
|
||||
SetCellsAlongAxis(0);
|
||||
}
|
||||
|
||||
public override void SetLayoutVertical()
|
||||
{
|
||||
SetCellsAlongAxis(1);
|
||||
}
|
||||
|
||||
private void SetCellsAlongAxis(int axis)
|
||||
{
|
||||
// Normally a Layout Controller should only set horizontal values when invoked for the horizontal axis
|
||||
// and only vertical values when invoked for the vertical axis.
|
||||
// However, in this case we set both the horizontal and vertical position when invoked for the vertical axis.
|
||||
// Since we only set the horizontal position and not the size, it shouldn't affect children's layout,
|
||||
// and thus shouldn't break the rule that all horizontal layout must be calculated before all vertical layout.
|
||||
|
||||
if (axis == 0)
|
||||
{
|
||||
// Only set the sizes when invoked for horizontal axis, not the positions.
|
||||
for (int i = 0; i < rectChildren.Count; i++)
|
||||
{
|
||||
RectTransform rect = rectChildren[i];
|
||||
|
||||
m_Tracker.Add(this, rect,
|
||||
DrivenTransformProperties.Anchors |
|
||||
DrivenTransformProperties.AnchoredPosition |
|
||||
DrivenTransformProperties.SizeDelta);
|
||||
|
||||
rect.anchorMin = Vector2.up;
|
||||
rect.anchorMax = Vector2.up;
|
||||
rect.sizeDelta = cellSize;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
float width = rectTransform.rect.size.x;
|
||||
float height = rectTransform.rect.size.y;
|
||||
|
||||
int cellCountX = 1;
|
||||
int cellCountY = 1;
|
||||
if (m_Constraint == Constraint.FixedColumnCount)
|
||||
{
|
||||
cellCountX = m_ConstraintCount;
|
||||
cellCountY = Mathf.CeilToInt(rectChildren.Count / (float)cellCountX - 0.001f);
|
||||
}
|
||||
else if (m_Constraint == Constraint.FixedRowCount)
|
||||
{
|
||||
cellCountY = m_ConstraintCount;
|
||||
cellCountX = Mathf.CeilToInt(rectChildren.Count / (float)cellCountY - 0.001f);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cellSize.x + spacing.x <= 0)
|
||||
cellCountX = int.MaxValue;
|
||||
else
|
||||
cellCountX = Mathf.Max(1, Mathf.FloorToInt((width - padding.horizontal + spacing.x + 0.001f) / (cellSize.x + spacing.x)));
|
||||
|
||||
if (cellSize.y + spacing.y <= 0)
|
||||
cellCountY = int.MaxValue;
|
||||
else
|
||||
cellCountY = Mathf.Max(1, Mathf.FloorToInt((height - padding.vertical + spacing.y + 0.001f) / (cellSize.y + spacing.y)));
|
||||
}
|
||||
|
||||
int cornerX = (int)startCorner % 2;
|
||||
int cornerY = (int)startCorner / 2;
|
||||
|
||||
int cellsPerMainAxis, actualCellCountX, actualCellCountY;
|
||||
if (startAxis == Axis.Horizontal)
|
||||
{
|
||||
cellsPerMainAxis = cellCountX;
|
||||
actualCellCountX = Mathf.Clamp(cellCountX, 1, rectChildren.Count);
|
||||
actualCellCountY = Mathf.Clamp(cellCountY, 1, Mathf.CeilToInt(rectChildren.Count / (float)cellsPerMainAxis));
|
||||
}
|
||||
else
|
||||
{
|
||||
cellsPerMainAxis = cellCountY;
|
||||
actualCellCountY = Mathf.Clamp(cellCountY, 1, rectChildren.Count);
|
||||
actualCellCountX = Mathf.Clamp(cellCountX, 1, Mathf.CeilToInt(rectChildren.Count / (float)cellsPerMainAxis));
|
||||
}
|
||||
|
||||
Vector2 requiredSpace = new Vector2(
|
||||
actualCellCountX * cellSize.x + (actualCellCountX - 1) * spacing.x,
|
||||
actualCellCountY * cellSize.y + (actualCellCountY - 1) * spacing.y
|
||||
);
|
||||
Vector2 startOffset = new Vector2(
|
||||
GetStartOffset(0, requiredSpace.x),
|
||||
GetStartOffset(1, requiredSpace.y)
|
||||
);
|
||||
|
||||
for (int i = 0; i < rectChildren.Count; i++)
|
||||
{
|
||||
int positionX;
|
||||
int positionY;
|
||||
if (startAxis == Axis.Horizontal)
|
||||
{
|
||||
positionX = i % cellsPerMainAxis;
|
||||
positionY = i / cellsPerMainAxis;
|
||||
}
|
||||
else
|
||||
{
|
||||
positionX = i / cellsPerMainAxis;
|
||||
positionY = i % cellsPerMainAxis;
|
||||
}
|
||||
|
||||
if (cornerX == 1)
|
||||
positionX = actualCellCountX - 1 - positionX;
|
||||
if (cornerY == 1)
|
||||
positionY = actualCellCountY - 1 - positionY;
|
||||
|
||||
float realsize = ((width - (spacing[0] * (actualCellCountX - 1))) / actualCellCountX);
|
||||
SetChildAlongAxis(rectChildren[i], 0, startOffset.x + (realsize + spacing[0]) * positionX, realsize);
|
||||
SetChildAlongAxis(rectChildren[i], 1, startOffset.y + (cellSize[1] + spacing[1]) * positionY, cellSize[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Plugins/AutoExpandGridLayoutGroup.cs.meta
Normal file
11
Assets/Plugins/AutoExpandGridLayoutGroup.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d29c5f8f94f596d4f8316387788ae810
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Plugins/com.unity.uiextensions.meta
Normal file
8
Assets/Plugins/com.unity.uiextensions.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 450fd99bb24cb1648938099cfa8efc00
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
9
Assets/Plugins/com.unity.uiextensions/Editor.meta
Normal file
9
Assets/Plugins/com.unity.uiextensions/Editor.meta
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b95396d565a2a7f478b12f8b9648ed8f
|
||||
folderAsset: yes
|
||||
timeCreated: 1467468503
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
///Credit Jason Horsburgh
|
||||
///Sourced from - https://bitbucket.org/UnityUIExtensions/unity-ui-extensions/issues/127/uilinerenderer-mesh-not-updating-in-editor
|
||||
|
||||
using UnityEditor;
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
[CustomEditor(typeof(UILineRenderer))]
|
||||
public class BezierLineRendererEditor : Editor
|
||||
{
|
||||
void OnSceneGUI()
|
||||
{
|
||||
UILineRenderer curveRenderer = target as UILineRenderer;
|
||||
|
||||
if (!curveRenderer || curveRenderer.drivenExternally || curveRenderer.Points == null || curveRenderer.Points.Length < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var oldMatrix = Handles.matrix;
|
||||
var transform = curveRenderer.GetComponent<RectTransform>();
|
||||
//Pivot must be 0,0 to edit
|
||||
//transform.pivot = Vector2.zero;
|
||||
Handles.matrix = transform.localToWorldMatrix;
|
||||
|
||||
var sizeX = curveRenderer.rectTransform.rect.width;
|
||||
var sizeY = curveRenderer.rectTransform.rect.height;
|
||||
var offsetX = -curveRenderer.rectTransform.pivot.x * sizeX;
|
||||
var offsetY = -curveRenderer.rectTransform.pivot.y * sizeY;
|
||||
|
||||
Vector2[] points = new Vector2[curveRenderer.Points.Length];
|
||||
for (int i = 0; i < curveRenderer.Points.Length; i++)
|
||||
{
|
||||
points[i] = curveRenderer.Points[i];
|
||||
}
|
||||
|
||||
//Need to transform points to worldspace! when set to Relative
|
||||
if (curveRenderer.RelativeSize)
|
||||
{
|
||||
for (int i = 0; i < points.Length; i++)
|
||||
{
|
||||
points[i] = new Vector2(points[i].x * sizeX + offsetX, points[i].y * sizeY + offsetY);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < points.Length - 1; i += 2)
|
||||
{
|
||||
Handles.DrawLine(points[i], points[i + 1]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < points.Length; ++i)
|
||||
{
|
||||
using (var check = new EditorGUI.ChangeCheckScope())
|
||||
{
|
||||
var p = Handles.PositionHandle(points[i], Quaternion.identity);
|
||||
|
||||
if (check.changed)
|
||||
{
|
||||
Undo.RecordObject(curveRenderer, "Changed Curve Position");
|
||||
if (curveRenderer.RelativeSize)
|
||||
{
|
||||
curveRenderer.Points[i] = new Vector2((p.x - offsetX) / sizeX, (p.y - offsetY) / sizeY);
|
||||
}
|
||||
else
|
||||
{
|
||||
curveRenderer.Points[i] = p;
|
||||
}
|
||||
curveRenderer.transform.gameObject.SetActive(false);
|
||||
curveRenderer.transform.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Handles.matrix = oldMatrix;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4ef6a0d3c3259384982ae3974fe7e618
|
||||
timeCreated: 1492258093
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Plugins/com.unity.uiextensions/Runtime.meta
Normal file
8
Assets/Plugins/com.unity.uiextensions/Runtime.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: dae773db9d022de4b891928437a0c082
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Assets/Plugins/com.unity.uiextensions/Runtime/Resources.meta
Normal file
10
Assets/Plugins/com.unity.uiextensions/Runtime/Resources.meta
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a7296bad073428c4796089b44a48cab9
|
||||
folderAsset: yes
|
||||
timeCreated: 1521742084
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0873351fdb3a65f43901b3ec088375b0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
||||
|
|
@ -0,0 +1,150 @@
|
|||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "UI Extensions/SoftMaskShader"
|
||||
{
|
||||
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
|
||||
_AlphaMask("AlphaMask - Must be Wrapped",2D) = "white"{}
|
||||
_CutOff("CutOff",Float) = 0
|
||||
[MaterialToggle]
|
||||
_HardBlend("HardBlend",Float) = 0
|
||||
_FlipAlphaMask("Flip Alpha Mask",int) = 0
|
||||
_NoOuterClip("Outer Clip",int) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"Queue" = "Transparent"
|
||||
"IgnoreProjector" = "True"
|
||||
"RenderType" = "Transparent"
|
||||
"PreviewType" = "Plane"
|
||||
"CanUseSpriteAtlas" = "True"
|
||||
}
|
||||
|
||||
Stencil
|
||||
{
|
||||
Ref[_Stencil]
|
||||
Comp[_StencilComp]
|
||||
Pass[_StencilOp]
|
||||
ReadMask[_StencilReadMask]
|
||||
WriteMask[_StencilWriteMask]
|
||||
}
|
||||
|
||||
LOD 0
|
||||
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
ZTest[unity_GUIZTestMode]
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ColorMask[_ColorMask]
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata_t
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
fixed4 color : COLOR;
|
||||
half2 texcoord : TEXCOORD0;
|
||||
float2 maskTexcoord : TEXCOORD1;
|
||||
};
|
||||
|
||||
inline float UnityGet2DClipping (in float2 position, in float4 clipRect)
|
||||
{
|
||||
float2 inside = step(clipRect.xy, position.xy) * step(position.xy, clipRect.zw);
|
||||
return inside.x * inside.y;
|
||||
}
|
||||
|
||||
fixed4 _Color;
|
||||
fixed4 _TextureSampleAdd;
|
||||
sampler2D _MainTex;
|
||||
|
||||
bool _UseAlphaClip;
|
||||
int _FlipAlphaMask = 0;
|
||||
float4 _AlphaMask_ST;
|
||||
sampler2D _AlphaMask;
|
||||
|
||||
v2f vert(appdata_t IN)
|
||||
{
|
||||
v2f OUT;
|
||||
float4 wolrdPos = IN.vertex;
|
||||
OUT.maskTexcoord = TRANSFORM_TEX(wolrdPos.xy, _AlphaMask);
|
||||
OUT.vertex = UnityObjectToClipPos(IN.vertex);
|
||||
OUT.texcoord = IN.texcoord;
|
||||
|
||||
#ifdef UNITY_HALF_TEXEL_OFFSET
|
||||
OUT.vertex.xy += (_ScreenParams.zw - 1.0)*float2(-1,1);
|
||||
#endif
|
||||
|
||||
OUT.color = IN.color * _Color;
|
||||
return OUT;
|
||||
}
|
||||
|
||||
float _CutOff;
|
||||
bool _HardBlend = false;
|
||||
bool _NoOuterClip = false;
|
||||
|
||||
fixed4 frag(v2f IN) : SV_Target
|
||||
{
|
||||
half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
|
||||
float4 inMask = float4(
|
||||
step(float2(0.0f, 0.0f), IN.maskTexcoord),
|
||||
step(IN.maskTexcoord, float2(1.0f, 1.0f)) );
|
||||
|
||||
// Do we want to clip the image to the Mask Rectangle?
|
||||
if (_NoOuterClip == false && all(inMask) == false )
|
||||
{
|
||||
color.a = 0;
|
||||
}
|
||||
else // It's in the mask rectangle, so apply the alpha of the mask provided.
|
||||
{
|
||||
|
||||
float a = tex2D(_AlphaMask, IN.maskTexcoord).a;
|
||||
|
||||
if (a <= _CutOff)
|
||||
a = 0;
|
||||
else
|
||||
{
|
||||
if(_HardBlend)
|
||||
a = 1;
|
||||
}
|
||||
|
||||
if (_FlipAlphaMask == 1)
|
||||
a = 1 - a;
|
||||
|
||||
color.a *= a;
|
||||
}
|
||||
|
||||
if (_UseAlphaClip)
|
||||
clip(color.a - 0.001);
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 947afae4d36f1274ea2e4098262ceef6
|
||||
timeCreated: 1444851202
|
||||
licenseType: Pro
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
Shader "UI Extensions/Particles/Additive" {
|
||||
Properties {
|
||||
_TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
|
||||
_MainTex ("Particle Texture", 2D) = "white" {}
|
||||
_InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
|
||||
|
||||
_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
|
||||
}
|
||||
|
||||
Category {
|
||||
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }
|
||||
Blend SrcAlpha One
|
||||
ColorMask RGB
|
||||
Cull Off Lighting Off ZWrite Off
|
||||
ZTest [unity_GUIZTestMode]
|
||||
|
||||
SubShader {
|
||||
|
||||
Stencil
|
||||
{
|
||||
Ref [_Stencil]
|
||||
Comp [_StencilComp]
|
||||
Pass [_StencilOp]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
}
|
||||
|
||||
Pass {
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma target 2.0
|
||||
#pragma multi_compile_particles
|
||||
#pragma multi_compile_fog
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityUI.cginc"
|
||||
|
||||
#pragma multi_compile __ UNITY_UI_ALPHACLIP
|
||||
|
||||
sampler2D _MainTex;
|
||||
fixed4 _TintColor;
|
||||
|
||||
struct appdata_t {
|
||||
float4 vertex : POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f {
|
||||
float4 vertex : SV_POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
UNITY_FOG_COORDS(1)
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
float4 projPos : TEXCOORD2;
|
||||
#endif
|
||||
};
|
||||
|
||||
float4 _MainTex_ST;
|
||||
|
||||
v2f vert (appdata_t IN)
|
||||
{
|
||||
v2f v;
|
||||
v.vertex = UnityObjectToClipPos(IN.vertex);
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
v.projPos = ComputeScreenPos (v.vertex);
|
||||
COMPUTE_EYEDEPTH(v.projPos.z);
|
||||
#endif
|
||||
v.color = IN.color;
|
||||
v.texcoord = TRANSFORM_TEX(IN.texcoord,_MainTex);
|
||||
UNITY_TRANSFER_FOG(v,v.vertex);
|
||||
return v;
|
||||
}
|
||||
|
||||
sampler2D_float _CameraDepthTexture;
|
||||
float _InvFade;
|
||||
|
||||
fixed4 frag (v2f IN) : SV_Target
|
||||
{
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(IN.projPos)));
|
||||
float partZ = IN.projPos.z;
|
||||
float fade = saturate (_InvFade * (sceneZ-partZ));
|
||||
IN.color.a *= fade;
|
||||
#endif
|
||||
|
||||
fixed4 col = 2.0f * IN.color * _TintColor * tex2D(_MainTex, IN.texcoord);
|
||||
UNITY_APPLY_FOG_COLOR(IN.fogCoord, col, fixed4(0,0,0,0)); // fog towards black due to our blend mode
|
||||
return col;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e064104788d94b349ab13141a30b5660
|
||||
timeCreated: 1502443970
|
||||
licenseType: Free
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
Shader "UI Extensions/Particles/~Additive-Multiply" {
|
||||
Properties {
|
||||
_TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
|
||||
_MainTex ("Particle Texture", 2D) = "white" {}
|
||||
_InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
|
||||
|
||||
_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
|
||||
}
|
||||
|
||||
Category {
|
||||
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }
|
||||
Blend One OneMinusSrcAlpha
|
||||
ColorMask RGB
|
||||
Cull Off Lighting Off ZWrite Off
|
||||
ZTest [unity_GUIZTestMode]
|
||||
|
||||
SubShader {
|
||||
|
||||
Stencil
|
||||
{
|
||||
Ref [_Stencil]
|
||||
Comp [_StencilComp]
|
||||
Pass [_StencilOp]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
}
|
||||
|
||||
Pass {
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma target 2.0
|
||||
#pragma multi_compile_particles
|
||||
#pragma multi_compile_fog
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityUI.cginc"
|
||||
|
||||
#pragma multi_compile __ UNITY_UI_ALPHACLIP
|
||||
|
||||
sampler2D _MainTex;
|
||||
fixed4 _TintColor;
|
||||
|
||||
struct appdata_t {
|
||||
float4 vertex : POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f {
|
||||
float4 vertex : SV_POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
UNITY_FOG_COORDS(1)
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
float4 projPos : TEXCOORD2;
|
||||
#endif
|
||||
};
|
||||
|
||||
float4 _MainTex_ST;
|
||||
|
||||
v2f vert (appdata_t IN)
|
||||
{
|
||||
v2f v;
|
||||
v.vertex = UnityObjectToClipPos(IN.vertex);
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
v.projPos = ComputeScreenPos (v.vertex);
|
||||
COMPUTE_EYEDEPTH(v.projPos.z);
|
||||
#endif
|
||||
v.color = IN.color;
|
||||
v.texcoord = TRANSFORM_TEX(IN.texcoord,_MainTex);
|
||||
UNITY_TRANSFER_FOG(v,v.vertex);
|
||||
return v;
|
||||
}
|
||||
|
||||
sampler2D_float _CameraDepthTexture;
|
||||
float _InvFade;
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
|
||||
float partZ = i.projPos.z;
|
||||
float fade = saturate (_InvFade * (sceneZ-partZ));
|
||||
i.color *= fade;
|
||||
#endif
|
||||
|
||||
fixed4 tex = tex2D(_MainTex, i.texcoord);
|
||||
fixed4 col;
|
||||
col.rgb = _TintColor.rgb * tex.rgb * i.color.rgb * 2.0f;
|
||||
col.a = (1 - tex.a) * (_TintColor.a * i.color.a * 2.0f);
|
||||
UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fixed4(0,0,0,0)); // fog towards black due to our blend mode
|
||||
return col;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 088bbfd9222ee044cb4e4699336e9ff1
|
||||
timeCreated: 1502443969
|
||||
licenseType: Free
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
Shader "UI Extensions/Particles/Additive (Soft)" {
|
||||
Properties {
|
||||
_MainTex ("Particle Texture", 2D) = "white" {}
|
||||
_InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
|
||||
|
||||
_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
|
||||
}
|
||||
|
||||
Category {
|
||||
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }
|
||||
Blend One OneMinusSrcColor
|
||||
ColorMask RGB
|
||||
Cull Off Lighting Off ZWrite Off
|
||||
ZTest [unity_GUIZTestMode]
|
||||
|
||||
SubShader {
|
||||
|
||||
Stencil
|
||||
{
|
||||
Ref [_Stencil]
|
||||
Comp [_StencilComp]
|
||||
Pass [_StencilOp]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
}
|
||||
|
||||
Pass {
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma target 2.0
|
||||
#pragma multi_compile_particles
|
||||
#pragma multi_compile_fog
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityUI.cginc"
|
||||
|
||||
#pragma multi_compile __ UNITY_UI_ALPHACLIP
|
||||
|
||||
sampler2D _MainTex;
|
||||
fixed4 _TintColor;
|
||||
|
||||
struct appdata_t {
|
||||
float4 vertex : POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f {
|
||||
float4 vertex : SV_POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
UNITY_FOG_COORDS(1)
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
float4 projPos : TEXCOORD2;
|
||||
#endif
|
||||
};
|
||||
|
||||
float4 _MainTex_ST;
|
||||
|
||||
v2f vert (appdata_t IN)
|
||||
{
|
||||
v2f v;
|
||||
v.vertex = UnityObjectToClipPos(IN.vertex);
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
v.projPos = ComputeScreenPos (v.vertex);
|
||||
COMPUTE_EYEDEPTH(v.projPos.z);
|
||||
#endif
|
||||
v.color = IN.color;
|
||||
v.texcoord = TRANSFORM_TEX(IN.texcoord,_MainTex);
|
||||
UNITY_TRANSFER_FOG(v,v.vertex);
|
||||
return v;
|
||||
}
|
||||
|
||||
sampler2D_float _CameraDepthTexture;
|
||||
float _InvFade;
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
|
||||
float partZ = i.projPos.z;
|
||||
float fade = saturate (_InvFade * (sceneZ-partZ));
|
||||
i.color.a *= fade;
|
||||
#endif
|
||||
|
||||
half4 col = i.color * tex2D(_MainTex, i.texcoord);
|
||||
col.rgb *= col.a;
|
||||
UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fixed4(0,0,0,0)); // fog towards black due to our blend mode
|
||||
return col;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4c2211b120168e44db4a3a8417013615
|
||||
timeCreated: 1502443969
|
||||
licenseType: Free
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
Shader "UI Extensions/Particles/Alpha Blended" {
|
||||
Properties {
|
||||
_TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
|
||||
_MainTex ("Particle Texture", 2D) = "white" {}
|
||||
_InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
|
||||
|
||||
_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
|
||||
}
|
||||
|
||||
Category {
|
||||
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ColorMask RGB
|
||||
Cull Off Lighting Off ZWrite Off
|
||||
ZTest [unity_GUIZTestMode]
|
||||
|
||||
SubShader {
|
||||
|
||||
Stencil
|
||||
{
|
||||
Ref [_Stencil]
|
||||
Comp [_StencilComp]
|
||||
Pass [_StencilOp]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
}
|
||||
|
||||
Pass {
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma target 2.0
|
||||
#pragma multi_compile_particles
|
||||
#pragma multi_compile_fog
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityUI.cginc"
|
||||
|
||||
#pragma multi_compile __ UNITY_UI_ALPHACLIP
|
||||
|
||||
sampler2D _MainTex;
|
||||
fixed4 _TintColor;
|
||||
|
||||
struct appdata_t {
|
||||
float4 vertex : POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f {
|
||||
float4 vertex : SV_POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
UNITY_FOG_COORDS(1)
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
float4 projPos : TEXCOORD2;
|
||||
#endif
|
||||
};
|
||||
|
||||
float4 _MainTex_ST;
|
||||
|
||||
v2f vert (appdata_t IN)
|
||||
{
|
||||
v2f v;
|
||||
v.vertex = UnityObjectToClipPos(IN.vertex);
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
v.projPos = ComputeScreenPos (v.vertex);
|
||||
COMPUTE_EYEDEPTH(v.projPos.z);
|
||||
#endif
|
||||
v.color = IN.color;
|
||||
v.texcoord = TRANSFORM_TEX(IN.texcoord,_MainTex);
|
||||
UNITY_TRANSFER_FOG(v,v.vertex);
|
||||
return v;
|
||||
}
|
||||
|
||||
sampler2D_float _CameraDepthTexture;
|
||||
float _InvFade;
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
|
||||
float partZ = i.projPos.z;
|
||||
float fade = saturate (_InvFade * (sceneZ-partZ));
|
||||
i.color.a *= fade;
|
||||
#endif
|
||||
|
||||
fixed4 col = 2.0f * i.color * _TintColor * tex2D(_MainTex, i.texcoord);
|
||||
UNITY_APPLY_FOG(i.fogCoord, col);
|
||||
return col;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c3d7d8d71a91071469ad7019e77864d6
|
||||
timeCreated: 1502443970
|
||||
licenseType: Free
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
Shader "UI Extensions/Particles/Blend" {
|
||||
Properties {
|
||||
_MainTex ("Particle Texture", 2D) = "white" {}
|
||||
_InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
|
||||
|
||||
_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
|
||||
}
|
||||
|
||||
Category {
|
||||
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }
|
||||
Blend DstColor One
|
||||
ColorMask RGB
|
||||
Cull Off Lighting Off ZWrite Off
|
||||
ZTest [unity_GUIZTestMode]
|
||||
|
||||
SubShader {
|
||||
|
||||
Stencil
|
||||
{
|
||||
Ref [_Stencil]
|
||||
Comp [_StencilComp]
|
||||
Pass [_StencilOp]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
}
|
||||
|
||||
Pass {
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma target 2.0
|
||||
#pragma multi_compile_particles
|
||||
#pragma multi_compile_fog
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityUI.cginc"
|
||||
|
||||
#pragma multi_compile __ UNITY_UI_ALPHACLIP
|
||||
|
||||
sampler2D _MainTex;
|
||||
fixed4 _TintColor;
|
||||
|
||||
struct appdata_t {
|
||||
float4 vertex : POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f {
|
||||
float4 vertex : SV_POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
UNITY_FOG_COORDS(1)
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
float4 projPos : TEXCOORD2;
|
||||
#endif
|
||||
};
|
||||
|
||||
float4 _MainTex_ST;
|
||||
|
||||
v2f vert (appdata_t IN)
|
||||
{
|
||||
v2f v;
|
||||
v.vertex = UnityObjectToClipPos(IN.vertex);
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
v.projPos = ComputeScreenPos (v.vertex);
|
||||
COMPUTE_EYEDEPTH(v.projPos.z);
|
||||
#endif
|
||||
v.color = IN.color;
|
||||
v.texcoord = TRANSFORM_TEX(IN.texcoord,_MainTex);
|
||||
UNITY_TRANSFER_FOG(v,v.vertex);
|
||||
return v;
|
||||
}
|
||||
|
||||
sampler2D_float _CameraDepthTexture;
|
||||
float _InvFade;
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
|
||||
float partZ = i.projPos.z;
|
||||
float fade = saturate (_InvFade * (sceneZ-partZ));
|
||||
i.color *= fade;
|
||||
#endif
|
||||
|
||||
fixed4 col = i.color * tex2D(_MainTex, i.texcoord);
|
||||
UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fixed4(0,0,0,0)); // fog towards black due to our blend mode
|
||||
return col;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 98fed5ba500a9a04a80325266b9911bb
|
||||
timeCreated: 1502443970
|
||||
licenseType: Free
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
Shader "UI Extensions/Particles/Multiply" {
|
||||
Properties {
|
||||
_MainTex ("Particle Texture", 2D) = "white" {}
|
||||
_InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
|
||||
|
||||
_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
|
||||
}
|
||||
|
||||
Category {
|
||||
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }
|
||||
Blend Zero SrcColor
|
||||
Cull Off Lighting Off ZWrite Off
|
||||
ZTest [unity_GUIZTestMode]
|
||||
|
||||
SubShader {
|
||||
|
||||
Stencil
|
||||
{
|
||||
Ref [_Stencil]
|
||||
Comp [_StencilComp]
|
||||
Pass [_StencilOp]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
}
|
||||
|
||||
Pass {
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma target 2.0
|
||||
#pragma multi_compile_particles
|
||||
#pragma multi_compile_fog
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityUI.cginc"
|
||||
|
||||
#pragma multi_compile __ UNITY_UI_ALPHACLIP
|
||||
|
||||
sampler2D _MainTex;
|
||||
fixed4 _TintColor;
|
||||
|
||||
struct appdata_t {
|
||||
float4 vertex : POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f {
|
||||
float4 vertex : SV_POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
UNITY_FOG_COORDS(1)
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
float4 projPos : TEXCOORD2;
|
||||
#endif
|
||||
};
|
||||
|
||||
float4 _MainTex_ST;
|
||||
|
||||
v2f vert (appdata_t IN)
|
||||
{
|
||||
v2f v;
|
||||
v.vertex = UnityObjectToClipPos(IN.vertex);
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
v.projPos = ComputeScreenPos (v.vertex);
|
||||
COMPUTE_EYEDEPTH(v.projPos.z);
|
||||
#endif
|
||||
v.color = IN.color;
|
||||
v.texcoord = TRANSFORM_TEX(IN.texcoord,_MainTex);
|
||||
UNITY_TRANSFER_FOG(v,v.vertex);
|
||||
return v;
|
||||
}
|
||||
|
||||
sampler2D_float _CameraDepthTexture;
|
||||
float _InvFade;
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
|
||||
float partZ = i.projPos.z;
|
||||
float fade = saturate (_InvFade * (sceneZ-partZ));
|
||||
i.color.a *= fade;
|
||||
#endif
|
||||
|
||||
half4 prev = i.color * tex2D(_MainTex, i.texcoord);
|
||||
fixed4 col = lerp(half4(1,1,1,1), prev, prev.a);
|
||||
UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fixed4(1,1,1,1)); // fog towards white due to our blend mode
|
||||
return col;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 320f6bb7bde369b4a85c9d89a9ba5268
|
||||
timeCreated: 1502443969
|
||||
licenseType: Free
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
Shader "UI Extensions/Particles/Multiply (Double)" {
|
||||
Properties {
|
||||
_MainTex ("Particle Texture", 2D) = "white" {}
|
||||
_InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
|
||||
|
||||
_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
|
||||
}
|
||||
|
||||
Category {
|
||||
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }
|
||||
Blend DstColor SrcColor
|
||||
ColorMask RGB
|
||||
Cull Off Lighting Off ZWrite Off
|
||||
ZTest [unity_GUIZTestMode]
|
||||
|
||||
SubShader {
|
||||
|
||||
Stencil
|
||||
{
|
||||
Ref [_Stencil]
|
||||
Comp [_StencilComp]
|
||||
Pass [_StencilOp]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
}
|
||||
|
||||
Pass {
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma target 2.0
|
||||
#pragma multi_compile_particles
|
||||
#pragma multi_compile_fog
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityUI.cginc"
|
||||
|
||||
#pragma multi_compile __ UNITY_UI_ALPHACLIP
|
||||
|
||||
sampler2D _MainTex;
|
||||
fixed4 _TintColor;
|
||||
|
||||
struct appdata_t {
|
||||
float4 vertex : POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f {
|
||||
float4 vertex : SV_POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
UNITY_FOG_COORDS(1)
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
float4 projPos : TEXCOORD2;
|
||||
#endif
|
||||
};
|
||||
|
||||
float4 _MainTex_ST;
|
||||
|
||||
v2f vert (appdata_t IN)
|
||||
{
|
||||
v2f v;
|
||||
v.vertex = UnityObjectToClipPos(IN.vertex);
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
v.projPos = ComputeScreenPos (v.vertex);
|
||||
COMPUTE_EYEDEPTH(v.projPos.z);
|
||||
#endif
|
||||
v.color = IN.color;
|
||||
v.texcoord = TRANSFORM_TEX(IN.texcoord,_MainTex);
|
||||
UNITY_TRANSFER_FOG(v,v.vertex);
|
||||
return v;
|
||||
}
|
||||
|
||||
sampler2D_float _CameraDepthTexture;
|
||||
float _InvFade;
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
|
||||
float partZ = i.projPos.z;
|
||||
float fade = saturate (_InvFade * (sceneZ-partZ));
|
||||
i.color.a *= fade;
|
||||
#endif
|
||||
|
||||
fixed4 col;
|
||||
fixed4 tex = tex2D(_MainTex, i.texcoord);
|
||||
col.rgb = tex.rgb * i.color.rgb * 2;
|
||||
col.a = i.color.a * tex.a;
|
||||
col = lerp(fixed4(0.5f,0.5f,0.5f,0.5f), col, col.a);
|
||||
UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fixed4(0.5,0.5,0.5,0.5)); // fog towards gray due to our blend mode
|
||||
return col;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0765ecef58833c3429346a1fee45e4e0
|
||||
timeCreated: 1502443969
|
||||
licenseType: Free
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
Shader "UI Extensions/Particles/Alpha Blended Premultiply" {
|
||||
Properties {
|
||||
|
||||
_MainTex ("Particle Texture", 2D) = "white" {}
|
||||
_InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
|
||||
|
||||
_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
|
||||
}
|
||||
|
||||
Category {
|
||||
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }
|
||||
Blend One OneMinusSrcAlpha
|
||||
ColorMask RGB
|
||||
Cull Off Lighting Off ZWrite Off
|
||||
ZTest [unity_GUIZTestMode]
|
||||
|
||||
SubShader {
|
||||
|
||||
Stencil
|
||||
{
|
||||
Ref [_Stencil]
|
||||
Comp [_StencilComp]
|
||||
Pass [_StencilOp]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
}
|
||||
|
||||
Pass {
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#pragma target 2.0
|
||||
#pragma multi_compile_particles
|
||||
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "UnityUI.cginc"
|
||||
|
||||
#pragma multi_compile __ UNITY_UI_ALPHACLIP
|
||||
|
||||
sampler2D _MainTex;
|
||||
fixed4 _TintColor;
|
||||
|
||||
struct appdata_t {
|
||||
float4 vertex : POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f {
|
||||
float4 vertex : SV_POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
float4 projPos : TEXCOORD1;
|
||||
#endif
|
||||
};
|
||||
|
||||
float4 _MainTex_ST;
|
||||
|
||||
v2f vert (appdata_t IN)
|
||||
{
|
||||
v2f v;
|
||||
v.vertex = UnityObjectToClipPos(IN.vertex);
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
v.projPos = ComputeScreenPos (v.vertex);
|
||||
COMPUTE_EYEDEPTH(v.projPos.z);
|
||||
#endif
|
||||
v.color = IN.color;
|
||||
v.texcoord = TRANSFORM_TEX(IN.texcoord,_MainTex);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
sampler2D_float _CameraDepthTexture;
|
||||
float _InvFade;
|
||||
|
||||
fixed4 frag (v2f IN) : SV_Target
|
||||
{
|
||||
#ifdef SOFTPARTICLES_ON
|
||||
float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(IN.projPos)));
|
||||
float partZ = IN.projPos.z;
|
||||
float fade = saturate (_InvFade * (sceneZ-partZ));
|
||||
IN.color.a *= fade;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
return IN.color * tex2D(_MainTex, IN.texcoord) * IN.color.a;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0596a6838d78f624397b642817cf20bc
|
||||
timeCreated: 1502443969
|
||||
licenseType: Free
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
Shader "UI Extensions/Particles/VertexLit Blended" {
|
||||
Properties {
|
||||
_EmisColor ("Emissive Color", Color) = (.2,.2,.2,0)
|
||||
_MainTex ("Particle Texture", 2D) = "white" {}
|
||||
|
||||
_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
|
||||
}
|
||||
|
||||
SubShader {
|
||||
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" }
|
||||
Tags { "LightMode" = "Vertex" }
|
||||
Cull Off
|
||||
Lighting On
|
||||
Material { Emission [_EmisColor] }
|
||||
ColorMaterial AmbientAndDiffuse
|
||||
ZWrite Off
|
||||
ColorMask RGB
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
|
||||
Stencil
|
||||
{
|
||||
Ref [_Stencil]
|
||||
Comp [_StencilComp]
|
||||
Pass [_StencilOp]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
}
|
||||
|
||||
Pass {
|
||||
|
||||
SetTexture [_MainTex] { combine primary * texture }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 65bbb789ada58ab44aaedbe09687f089
|
||||
timeCreated: 1502443969
|
||||
licenseType: Free
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "UI Extensions/UIAdditive"
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"Queue"="Transparent"
|
||||
"IgnoreProjector"="True"
|
||||
"RenderType"="Transparent"
|
||||
"PreviewType"="Plane"
|
||||
"CanUseSpriteAtlas"="True"
|
||||
}
|
||||
|
||||
Stencil
|
||||
{
|
||||
Ref [_Stencil]
|
||||
Comp [_StencilComp]
|
||||
Pass [_StencilOp]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
}
|
||||
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
ZTest [unity_GUIZTestMode]
|
||||
Fog { Mode Off }
|
||||
Blend One One
|
||||
ColorMask [_ColorMask]
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata_t
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
fixed4 color : COLOR;
|
||||
half2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
fixed4 _Color;
|
||||
|
||||
v2f vert(appdata_t IN)
|
||||
{
|
||||
v2f OUT;
|
||||
OUT.vertex = UnityObjectToClipPos(IN.vertex);
|
||||
OUT.texcoord = IN.texcoord;
|
||||
#ifdef UNITY_HALF_TEXEL_OFFSET
|
||||
OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
|
||||
#endif
|
||||
OUT.color = IN.color * _Color;
|
||||
return OUT;
|
||||
}
|
||||
|
||||
sampler2D _MainTex;
|
||||
|
||||
fixed4 frag(v2f IN) : SV_Target
|
||||
{
|
||||
half4 color = tex2D(_MainTex, IN.texcoord) * IN.color;
|
||||
color.rgb *= color.a;
|
||||
clip (color.a - 0.01);
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 20fb5fa09d4675a4e94314a228763c23
|
||||
timeCreated: 1464629199
|
||||
licenseType: Pro
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
/// Credit 00christian00
|
||||
/// Sourced from - http://forum.unity3d.com/threads/any-way-to-show-part-of-an-image-without-using-mask.360085/#post-2332030
|
||||
|
||||
Shader "UI Extensions/UI Image Crop" {
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Base (RGB)", 2D) = "white" {}
|
||||
|
||||
_XCrop ("X Crop", Range(0.0,1.0)) = 1
|
||||
_YCrop ("Y Crop", Range(0.0,1.0)) = 1
|
||||
}
|
||||
|
||||
SubShader {
|
||||
|
||||
ZWrite Off
|
||||
Tags
|
||||
{
|
||||
"Queue" = "Transparent"
|
||||
"RenderType" = "Transparent"
|
||||
"IgnoreProjector" = "True"
|
||||
}
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
|
||||
Pass {
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct v2f {
|
||||
float4 pos : POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 uv : TEXCOORD0; //UV1 coord
|
||||
};
|
||||
|
||||
uniform sampler2D _MainTex;
|
||||
float4 _MainTex_ST;
|
||||
uniform float _XCrop;
|
||||
uniform float _YCrop;
|
||||
|
||||
v2f vert (v2f v)
|
||||
{
|
||||
|
||||
v2f o;
|
||||
o.color=v.color;
|
||||
o.color.a=0.1;
|
||||
o.pos = UnityObjectToClipPos (v.pos);
|
||||
|
||||
o.uv=TRANSFORM_TEX(v.uv, _MainTex);
|
||||
|
||||
return o;
|
||||
}
|
||||
fixed4 frag (v2f i) : COLOR
|
||||
{
|
||||
|
||||
//return fixed4(0.25,0,0,1);
|
||||
i.color.a=step(i.uv.x,_XCrop);
|
||||
//I don't like the bottom up ordering,so I reverse it
|
||||
i.color.a=i.color.a*step(1-i.uv.y,_YCrop);
|
||||
return i.color * tex2D (_MainTex, i.uv);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ccf5a0c8f87d3c547aff3daecb3164a4
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "UI Extensions/UILinearDodge"
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"Queue"="Transparent"
|
||||
"IgnoreProjector"="True"
|
||||
"RenderType"="Transparent"
|
||||
"PreviewType"="Plane"
|
||||
"CanUseSpriteAtlas"="True"
|
||||
}
|
||||
|
||||
Stencil
|
||||
{
|
||||
Ref [_Stencil]
|
||||
Comp [_StencilComp]
|
||||
Pass [_StencilOp]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
}
|
||||
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
ZTest [unity_GUIZTestMode]
|
||||
Fog { Mode Off }
|
||||
BlendOp Add
|
||||
Blend SrcAlpha One, One Zero
|
||||
ColorMask [_ColorMask]
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata_t
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
fixed4 color : COLOR;
|
||||
half2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
fixed4 _Color;
|
||||
|
||||
v2f vert(appdata_t IN)
|
||||
{
|
||||
v2f OUT;
|
||||
OUT.vertex = UnityObjectToClipPos(IN.vertex);
|
||||
OUT.texcoord = IN.texcoord;
|
||||
#ifdef UNITY_HALF_TEXEL_OFFSET
|
||||
OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
|
||||
#endif
|
||||
OUT.color = IN.color * _Color;
|
||||
return OUT;
|
||||
}
|
||||
|
||||
sampler2D _MainTex;
|
||||
|
||||
fixed4 frag(v2f IN) : SV_Target
|
||||
{
|
||||
half4 color = tex2D(_MainTex, IN.texcoord) * IN.color;
|
||||
color.rgb *= color.a;
|
||||
clip (color.a - 0.01);
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c3c3af59790cf3749ba49fe1c838c94e
|
||||
timeCreated: 1464629199
|
||||
licenseType: Pro
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "UI Extensions/UIMultiply"
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"Queue"="Transparent"
|
||||
"IgnoreProjector"="True"
|
||||
"RenderType"="Transparent"
|
||||
"PreviewType"="Plane"
|
||||
"CanUseSpriteAtlas"="True"
|
||||
}
|
||||
|
||||
Stencil
|
||||
{
|
||||
Ref [_Stencil]
|
||||
Comp [_StencilComp]
|
||||
Pass [_StencilOp]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
}
|
||||
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
ZTest [unity_GUIZTestMode]
|
||||
Fog { Mode Off }
|
||||
Blend DstColor Zero
|
||||
ColorMask [_ColorMask]
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata_t
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
fixed4 color : COLOR;
|
||||
half2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
fixed4 _Color;
|
||||
|
||||
v2f vert(appdata_t IN)
|
||||
{
|
||||
v2f OUT;
|
||||
OUT.vertex = UnityObjectToClipPos(IN.vertex);
|
||||
OUT.texcoord = IN.texcoord;
|
||||
#ifdef UNITY_HALF_TEXEL_OFFSET
|
||||
OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
|
||||
#endif
|
||||
OUT.color = IN.color * _Color;
|
||||
return OUT;
|
||||
}
|
||||
|
||||
sampler2D _MainTex;
|
||||
|
||||
fixed4 frag(v2f IN) : SV_Target
|
||||
{
|
||||
half4 color = tex2D(_MainTex, IN.texcoord) * IN.color;
|
||||
clip (color.a - 0.01);
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d287872ca8fd776418c28d332df585c3
|
||||
timeCreated: 1464629200
|
||||
licenseType: Pro
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
Shader "UI/Particles/Hidden"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "Queue"="Geometry" "RenderType"="Opaque" }
|
||||
Cull Off Lighting Off ZWrite Off Fog { Mode Off }
|
||||
LOD 100
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
v2f vert ()
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = fixed4(0, 0, 0, 0);
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
discard;
|
||||
return fixed4(0, 0, 0, 0);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cf73a0a4b5ea8994f916cd18a97c564b
|
||||
timeCreated: 1464476220
|
||||
licenseType: Pro
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "UI Extensions/UIScreen"
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"Queue"="Transparent"
|
||||
"IgnoreProjector"="True"
|
||||
"RenderType"="Transparent"
|
||||
"PreviewType"="Plane"
|
||||
"CanUseSpriteAtlas"="True"
|
||||
}
|
||||
|
||||
Stencil
|
||||
{
|
||||
Ref [_Stencil]
|
||||
Comp [_StencilComp]
|
||||
Pass [_StencilOp]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
}
|
||||
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
ZTest [unity_GUIZTestMode]
|
||||
Fog { Mode Off }
|
||||
BlendOp Add
|
||||
Blend OneMinusDstColor One, One Zero
|
||||
ColorMask [_ColorMask]
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata_t
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
fixed4 color : COLOR;
|
||||
half2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
fixed4 _Color;
|
||||
|
||||
v2f vert(appdata_t IN)
|
||||
{
|
||||
v2f OUT;
|
||||
OUT.vertex = UnityObjectToClipPos(IN.vertex);
|
||||
OUT.texcoord = IN.texcoord;
|
||||
#ifdef UNITY_HALF_TEXEL_OFFSET
|
||||
OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
|
||||
#endif
|
||||
OUT.color = IN.color * _Color;
|
||||
return OUT;
|
||||
}
|
||||
|
||||
sampler2D _MainTex;
|
||||
|
||||
fixed4 frag(v2f IN) : SV_Target
|
||||
{
|
||||
half4 color = tex2D(_MainTex, IN.texcoord) * IN.color;
|
||||
color.rgb *= color.a;
|
||||
clip (color.a - 0.01);
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 227ac21f7763c00489cc458e3938e326
|
||||
timeCreated: 1464629199
|
||||
licenseType: Pro
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
|
||||
|
||||
Shader "UI Extensions/UISoftAdditive"
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"Queue"="Transparent"
|
||||
"IgnoreProjector"="True"
|
||||
"RenderType"="Transparent"
|
||||
"PreviewType"="Plane"
|
||||
"CanUseSpriteAtlas"="True"
|
||||
}
|
||||
|
||||
Stencil
|
||||
{
|
||||
Ref [_Stencil]
|
||||
Comp [_StencilComp]
|
||||
Pass [_StencilOp]
|
||||
ReadMask [_StencilReadMask]
|
||||
WriteMask [_StencilWriteMask]
|
||||
}
|
||||
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
ZTest [unity_GUIZTestMode]
|
||||
Fog { Mode Off }
|
||||
Blend OneMinusDstColor One
|
||||
ColorMask [_ColorMask]
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata_t
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float4 color : COLOR;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
fixed4 color : COLOR;
|
||||
half2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
fixed4 _Color;
|
||||
|
||||
v2f vert(appdata_t IN)
|
||||
{
|
||||
v2f OUT;
|
||||
OUT.vertex = UnityObjectToClipPos(IN.vertex);
|
||||
OUT.texcoord = IN.texcoord;
|
||||
#ifdef UNITY_HALF_TEXEL_OFFSET
|
||||
OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
|
||||
#endif
|
||||
OUT.color = IN.color * _Color;
|
||||
return OUT;
|
||||
}
|
||||
|
||||
sampler2D _MainTex;
|
||||
|
||||
fixed4 frag(v2f IN) : SV_Target
|
||||
{
|
||||
half4 color = tex2D(_MainTex, IN.texcoord) * IN.color;
|
||||
color.rgb *= color.a;
|
||||
clip (color.a - 0.01);
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fb2e16a3d1280334a9e05394e1890f09
|
||||
timeCreated: 1464629200
|
||||
licenseType: Pro
|
||||
ShaderImporter:
|
||||
defaultTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9d40233b1c5add641bb2f4f7f12af05e
|
||||
folderAsset: yes
|
||||
timeCreated: 1438724032
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3b6b8774345aa954fb85ec83184b9095
|
||||
folderAsset: yes
|
||||
timeCreated: 1445521682
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,463 @@
|
|||
/// Credit jack.sydorenko, firagon
|
||||
/// Sourced from - http://forum.unity3d.com/threads/new-ui-and-line-drawing.253772/
|
||||
/// Updated/Refactored from - http://forum.unity3d.com/threads/new-ui-and-line-drawing.253772/#post-2528050
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
[AddComponentMenu("UI/Extensions/Primitives/UILineRenderer")]
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
public class UILineRenderer : UIPrimitiveBase
|
||||
{
|
||||
private enum SegmentType
|
||||
{
|
||||
Start,
|
||||
Middle,
|
||||
End,
|
||||
Full,
|
||||
}
|
||||
|
||||
public enum JoinType
|
||||
{
|
||||
Bevel,
|
||||
Miter
|
||||
}
|
||||
|
||||
public enum BezierType
|
||||
{
|
||||
None,
|
||||
Quick,
|
||||
Basic,
|
||||
Improved,
|
||||
Catenary,
|
||||
}
|
||||
|
||||
private const float MIN_MITER_JOIN = 15 * Mathf.Deg2Rad;
|
||||
|
||||
// A bevel 'nice' join displaces the vertices of the line segment instead of simply rendering a
|
||||
// quad to connect the endpoints. This improves the look of textured and transparent lines, since
|
||||
// there is no overlapping.
|
||||
private const float MIN_BEVEL_NICE_JOIN = 30 * Mathf.Deg2Rad;
|
||||
|
||||
private static Vector2 UV_TOP_LEFT, UV_BOTTOM_LEFT, UV_TOP_CENTER_LEFT, UV_TOP_CENTER_RIGHT, UV_BOTTOM_CENTER_LEFT, UV_BOTTOM_CENTER_RIGHT, UV_TOP_RIGHT, UV_BOTTOM_RIGHT;
|
||||
private static Vector2[] startUvs, middleUvs, endUvs, fullUvs;
|
||||
|
||||
[SerializeField, Tooltip("Points to draw lines between\n Can be improved using the Resolution Option")]
|
||||
internal Vector2[] m_points;
|
||||
[SerializeField, Tooltip("Segments to be drawn\n This is a list of arrays of points")]
|
||||
internal List<Vector2[]> m_segments;
|
||||
|
||||
[SerializeField, Tooltip("Thickness of the line")]
|
||||
internal float lineThickness = 2;
|
||||
[SerializeField, Tooltip("Use the relative bounds of the Rect Transform (0,0 -> 0,1) or screen space coordinates")]
|
||||
internal bool relativeSize;
|
||||
[SerializeField, Tooltip("Do the points identify a single line or split pairs of lines")]
|
||||
internal bool lineList;
|
||||
[SerializeField, Tooltip("Add end caps to each line\nMultiple caps when used with Line List")]
|
||||
internal bool lineCaps;
|
||||
[SerializeField, Tooltip("Resolution of the Bezier curve, different to line Resolution")]
|
||||
internal int bezierSegmentsPerCurve = 10;
|
||||
|
||||
public float LineThickness
|
||||
{
|
||||
get { return lineThickness; }
|
||||
set { lineThickness = value; SetAllDirty(); }
|
||||
}
|
||||
|
||||
public bool RelativeSize
|
||||
{
|
||||
get { return relativeSize; }
|
||||
set { relativeSize = value; SetAllDirty(); }
|
||||
}
|
||||
|
||||
public bool LineList
|
||||
{
|
||||
get { return lineList; }
|
||||
set { lineList = value; SetAllDirty(); }
|
||||
}
|
||||
|
||||
public bool LineCaps
|
||||
{
|
||||
get { return lineCaps; }
|
||||
set { lineCaps = value; SetAllDirty(); }
|
||||
}
|
||||
|
||||
[Tooltip("The type of Join used between lines, Square/Mitre or Curved/Bevel")]
|
||||
public JoinType LineJoins = JoinType.Bevel;
|
||||
|
||||
[Tooltip("Bezier method to apply to line, see docs for options\nCan't be used in conjunction with Resolution as Bezier already changes the resolution")]
|
||||
public BezierType BezierMode = BezierType.None;
|
||||
|
||||
public int BezierSegmentsPerCurve
|
||||
{
|
||||
get { return bezierSegmentsPerCurve; }
|
||||
set { bezierSegmentsPerCurve = value; }
|
||||
}
|
||||
|
||||
[HideInInspector]
|
||||
public bool drivenExternally = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Points to be drawn in the line.
|
||||
/// </summary>
|
||||
public Vector2[] Points
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_points;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (m_points == value)
|
||||
return;
|
||||
m_points = value;
|
||||
SetAllDirty();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List of Segments to be drawn.
|
||||
/// </summary>
|
||||
public List<Vector2[]> Segments
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_segments;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
m_segments = value;
|
||||
SetAllDirty();
|
||||
}
|
||||
}
|
||||
|
||||
private void PopulateMesh(VertexHelper vh, Vector2[] pointsToDraw)
|
||||
{
|
||||
//If Bezier is desired, pick the implementation
|
||||
if (BezierMode != BezierType.None && BezierMode != BezierType.Catenary && pointsToDraw.Length > 3) {
|
||||
BezierPath bezierPath = new BezierPath ();
|
||||
|
||||
bezierPath.SetControlPoints (pointsToDraw);
|
||||
bezierPath.SegmentsPerCurve = bezierSegmentsPerCurve;
|
||||
List<Vector2> drawingPoints;
|
||||
switch (BezierMode) {
|
||||
case BezierType.Basic:
|
||||
drawingPoints = bezierPath.GetDrawingPoints0 ();
|
||||
break;
|
||||
case BezierType.Improved:
|
||||
drawingPoints = bezierPath.GetDrawingPoints1 ();
|
||||
break;
|
||||
default:
|
||||
drawingPoints = bezierPath.GetDrawingPoints2 ();
|
||||
break;
|
||||
}
|
||||
|
||||
pointsToDraw = drawingPoints.ToArray ();
|
||||
}
|
||||
if (BezierMode == BezierType.Catenary && pointsToDraw.Length == 2) {
|
||||
CableCurve cable = new CableCurve (pointsToDraw);
|
||||
cable.slack = Resolution;
|
||||
cable.steps = BezierSegmentsPerCurve;
|
||||
pointsToDraw = cable.Points ();
|
||||
}
|
||||
|
||||
if (ImproveResolution != ResolutionMode.None) {
|
||||
pointsToDraw = IncreaseResolution (pointsToDraw);
|
||||
}
|
||||
|
||||
// scale based on the size of the rect or use absolute, this is switchable
|
||||
var sizeX = !relativeSize ? 1 : rectTransform.rect.width;
|
||||
var sizeY = !relativeSize ? 1 : rectTransform.rect.height;
|
||||
var offsetX = -rectTransform.pivot.x * sizeX;
|
||||
var offsetY = -rectTransform.pivot.y * sizeY;
|
||||
|
||||
// Generate the quads that make up the wide line
|
||||
var segments = new List<UIVertex[]> ();
|
||||
if (lineList) {
|
||||
for (var i = 1; i < pointsToDraw.Length; i += 2) {
|
||||
var start = pointsToDraw [i - 1];
|
||||
var end = pointsToDraw [i];
|
||||
start = new Vector2 (start.x * sizeX + offsetX, start.y * sizeY + offsetY);
|
||||
end = new Vector2 (end.x * sizeX + offsetX, end.y * sizeY + offsetY);
|
||||
|
||||
if (lineCaps) {
|
||||
segments.Add (CreateLineCap (start, end, SegmentType.Start));
|
||||
}
|
||||
|
||||
segments.Add(CreateLineSegment(start, end, SegmentType.Middle, segments.Count > 1 ? segments[segments.Count - 2] : null));
|
||||
|
||||
if (lineCaps) {
|
||||
segments.Add (CreateLineCap (start, end, SegmentType.End));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var i = 1; i < pointsToDraw.Length; i++) {
|
||||
var start = pointsToDraw [i - 1];
|
||||
var end = pointsToDraw [i];
|
||||
start = new Vector2 (start.x * sizeX + offsetX, start.y * sizeY + offsetY);
|
||||
end = new Vector2 (end.x * sizeX + offsetX, end.y * sizeY + offsetY);
|
||||
|
||||
if (lineCaps && i == 1) {
|
||||
segments.Add (CreateLineCap (start, end, SegmentType.Start));
|
||||
}
|
||||
|
||||
segments.Add (CreateLineSegment (start, end, SegmentType.Middle));
|
||||
|
||||
if (lineCaps && i == pointsToDraw.Length - 1) {
|
||||
segments.Add (CreateLineCap (start, end, SegmentType.End));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the line segments to the vertex helper, creating any joins as needed
|
||||
for (var i = 0; i < segments.Count; i++) {
|
||||
if (!lineList && i < segments.Count - 1) {
|
||||
var vec1 = segments [i] [1].position - segments [i] [2].position;
|
||||
var vec2 = segments [i + 1] [2].position - segments [i + 1] [1].position;
|
||||
var angle = Vector2.Angle (vec1, vec2) * Mathf.Deg2Rad;
|
||||
|
||||
// Positive sign means the line is turning in a 'clockwise' direction
|
||||
var sign = Mathf.Sign (Vector3.Cross (vec1.normalized, vec2.normalized).z);
|
||||
|
||||
// Calculate the miter point
|
||||
var miterDistance = lineThickness / (2 * Mathf.Tan (angle / 2));
|
||||
var miterPointA = segments [i] [2].position - vec1.normalized * miterDistance * sign;
|
||||
var miterPointB = segments [i] [3].position + vec1.normalized * miterDistance * sign;
|
||||
|
||||
var joinType = LineJoins;
|
||||
if (joinType == JoinType.Miter) {
|
||||
// Make sure we can make a miter join without too many artifacts.
|
||||
if (miterDistance < vec1.magnitude / 2 && miterDistance < vec2.magnitude / 2 && angle > MIN_MITER_JOIN) {
|
||||
segments [i] [2].position = miterPointA;
|
||||
segments [i] [3].position = miterPointB;
|
||||
segments [i + 1] [0].position = miterPointB;
|
||||
segments [i + 1] [1].position = miterPointA;
|
||||
} else {
|
||||
joinType = JoinType.Bevel;
|
||||
}
|
||||
}
|
||||
|
||||
if (joinType == JoinType.Bevel) {
|
||||
if (miterDistance < vec1.magnitude / 2 && miterDistance < vec2.magnitude / 2 && angle > MIN_BEVEL_NICE_JOIN) {
|
||||
if (sign < 0) {
|
||||
segments [i] [2].position = miterPointA;
|
||||
segments [i + 1] [1].position = miterPointA;
|
||||
} else {
|
||||
segments [i] [3].position = miterPointB;
|
||||
segments [i + 1] [0].position = miterPointB;
|
||||
}
|
||||
}
|
||||
|
||||
var join = new UIVertex[] { segments [i] [2], segments [i] [3], segments [i + 1] [0], segments [i + 1] [1] };
|
||||
vh.AddUIVertexQuad (join);
|
||||
}
|
||||
}
|
||||
|
||||
vh.AddUIVertexQuad (segments [i]);
|
||||
}
|
||||
if (vh.currentVertCount > 64000) {
|
||||
Debug.LogError ("Max Verticies size is 64000, current mesh verticies count is [" + vh.currentVertCount + "] - Cannot Draw");
|
||||
vh.Clear ();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected override void OnPopulateMesh(VertexHelper vh)
|
||||
{
|
||||
if (m_points != null && m_points.Length > 0) {
|
||||
GeneratedUVs ();
|
||||
vh.Clear ();
|
||||
|
||||
PopulateMesh (vh, m_points);
|
||||
|
||||
}
|
||||
else if (m_segments != null && m_segments.Count > 0) {
|
||||
GeneratedUVs ();
|
||||
vh.Clear ();
|
||||
|
||||
for (int s = 0; s < m_segments.Count; s++) {
|
||||
Vector2[] pointsToDraw = m_segments [s];
|
||||
PopulateMesh (vh, pointsToDraw);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private UIVertex[] CreateLineCap(Vector2 start, Vector2 end, SegmentType type)
|
||||
{
|
||||
if (type == SegmentType.Start)
|
||||
{
|
||||
var capStart = start - ((end - start).normalized * lineThickness / 2);
|
||||
return CreateLineSegment(capStart, start, SegmentType.Start);
|
||||
}
|
||||
else if (type == SegmentType.End)
|
||||
{
|
||||
var capEnd = end + ((end - start).normalized * lineThickness / 2);
|
||||
return CreateLineSegment(end, capEnd, SegmentType.End);
|
||||
}
|
||||
|
||||
Debug.LogError("Bad SegmentType passed in to CreateLineCap. Must be SegmentType.Start or SegmentType.End");
|
||||
return null;
|
||||
}
|
||||
|
||||
private UIVertex[] CreateLineSegment(Vector2 start, Vector2 end, SegmentType type, UIVertex[] previousVert = null)
|
||||
{
|
||||
Vector2 offset = new Vector2((start.y - end.y), end.x - start.x).normalized * lineThickness / 2;
|
||||
|
||||
Vector2 v1 = Vector2.zero;
|
||||
Vector2 v2 = Vector2.zero;
|
||||
if (previousVert != null) {
|
||||
v1 = new Vector2(previousVert[3].position.x, previousVert[3].position.y);
|
||||
v2 = new Vector2(previousVert[2].position.x, previousVert[2].position.y);
|
||||
} else {
|
||||
v1 = start - offset;
|
||||
v2 = start + offset;
|
||||
}
|
||||
|
||||
var v3 = end + offset;
|
||||
var v4 = end - offset;
|
||||
//Return the VDO with the correct uvs
|
||||
switch (type)
|
||||
{
|
||||
case SegmentType.Start:
|
||||
return SetVbo(new[] { v1, v2, v3, v4 }, startUvs);
|
||||
case SegmentType.End:
|
||||
return SetVbo(new[] { v1, v2, v3, v4 }, endUvs);
|
||||
case SegmentType.Full:
|
||||
return SetVbo(new[] { v1, v2, v3, v4 }, fullUvs);
|
||||
default:
|
||||
return SetVbo(new[] { v1, v2, v3, v4 }, middleUvs);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void GeneratedUVs()
|
||||
{
|
||||
if (activeSprite != null)
|
||||
{
|
||||
var outer = Sprites.DataUtility.GetOuterUV(activeSprite);
|
||||
var inner = Sprites.DataUtility.GetInnerUV(activeSprite);
|
||||
UV_TOP_LEFT = new Vector2(outer.x, outer.y);
|
||||
UV_BOTTOM_LEFT = new Vector2(outer.x, outer.w);
|
||||
UV_TOP_CENTER_LEFT = new Vector2(inner.x, inner.y);
|
||||
UV_TOP_CENTER_RIGHT = new Vector2(inner.z, inner.y);
|
||||
UV_BOTTOM_CENTER_LEFT = new Vector2(inner.x, inner.w);
|
||||
UV_BOTTOM_CENTER_RIGHT = new Vector2(inner.z, inner.w);
|
||||
UV_TOP_RIGHT = new Vector2(outer.z, outer.y);
|
||||
UV_BOTTOM_RIGHT = new Vector2(outer.z, outer.w);
|
||||
}
|
||||
else
|
||||
{
|
||||
UV_TOP_LEFT = Vector2.zero;
|
||||
UV_BOTTOM_LEFT = new Vector2(0, 1);
|
||||
UV_TOP_CENTER_LEFT = new Vector2(0.5f, 0);
|
||||
UV_TOP_CENTER_RIGHT = new Vector2(0.5f, 0);
|
||||
UV_BOTTOM_CENTER_LEFT = new Vector2(0.5f, 1);
|
||||
UV_BOTTOM_CENTER_RIGHT = new Vector2(0.5f, 1);
|
||||
UV_TOP_RIGHT = new Vector2(1, 0);
|
||||
UV_BOTTOM_RIGHT = Vector2.one;
|
||||
}
|
||||
|
||||
|
||||
startUvs = new[] { UV_TOP_LEFT, UV_BOTTOM_LEFT, UV_BOTTOM_CENTER_LEFT, UV_TOP_CENTER_LEFT };
|
||||
middleUvs = new[] { UV_TOP_CENTER_LEFT, UV_BOTTOM_CENTER_LEFT, UV_BOTTOM_CENTER_RIGHT, UV_TOP_CENTER_RIGHT };
|
||||
endUvs = new[] { UV_TOP_CENTER_RIGHT, UV_BOTTOM_CENTER_RIGHT, UV_BOTTOM_RIGHT, UV_TOP_RIGHT };
|
||||
fullUvs = new[] { UV_TOP_LEFT, UV_BOTTOM_LEFT, UV_BOTTOM_RIGHT, UV_TOP_RIGHT };
|
||||
}
|
||||
|
||||
protected override void ResolutionToNativeSize(float distance)
|
||||
{
|
||||
if (UseNativeSize)
|
||||
{
|
||||
m_Resolution = distance / (activeSprite.rect.width / pixelsPerUnit);
|
||||
lineThickness = activeSprite.rect.height / pixelsPerUnit;
|
||||
}
|
||||
}
|
||||
|
||||
private int GetSegmentPointCount()
|
||||
{
|
||||
if (Segments?.Count > 0)
|
||||
{
|
||||
int pointCount = 0;
|
||||
foreach (var segment in Segments)
|
||||
{
|
||||
pointCount += segment.Length;
|
||||
}
|
||||
return pointCount;
|
||||
}
|
||||
return Points.Length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the Vector2 position of a line index
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Positive numbers should be used to specify Index and Segment
|
||||
/// </remarks>
|
||||
/// <param name="index">Required Index of the point, starting from point 1</param>
|
||||
/// <param name="segmentIndex">(optional) Required Segment the point is held in, Starting from Segment 1</param>
|
||||
/// <returns>Vector2 position of the point within UI Space</returns>
|
||||
public Vector2 GetPosition(int index, int segmentIndex = 0)
|
||||
{
|
||||
if (segmentIndex > 0)
|
||||
{
|
||||
return Segments[segmentIndex - 1][index - 1];
|
||||
}
|
||||
else if (Segments.Count > 0)
|
||||
{
|
||||
var segmentIndexCount = 0;
|
||||
var indexCount = index;
|
||||
foreach (var segment in Segments)
|
||||
{
|
||||
if (indexCount - segment.Length > 0)
|
||||
{
|
||||
indexCount -= segment.Length;
|
||||
segmentIndexCount += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Segments[segmentIndexCount][indexCount - 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
return Points[index - 1];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the Vector2 position of a line within a specific segment
|
||||
/// </summary>
|
||||
/// <param name="index">Required Index of the point, starting from point 1</param>
|
||||
/// <param name="segmentIndex"> Required Segment the point is held in, Starting from Segment 1</param>
|
||||
/// <returns>Vector2 position of the point within UI Space</returns>
|
||||
public Vector2 GetPositionBySegment(int index, int segment)
|
||||
{
|
||||
return Segments[segment][index - 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the closest point between two given Vector2s from a given Vector2 point
|
||||
/// </summary>
|
||||
/// <param name="p1">Starting position</param>
|
||||
/// <param name="p2">End position</param>
|
||||
/// <param name="p3">Desired / Selected point</param>
|
||||
/// <returns>Closest Vector2 position of the target within UI Space</returns>
|
||||
public Vector2 GetClosestPoint(Vector2 p1, Vector2 p2, Vector2 p3)
|
||||
{
|
||||
Vector2 from_p1_to_p3 = p3 - p1;
|
||||
Vector2 from_p1_to_p2 = p2 - p1;
|
||||
float dot = Vector2.Dot(from_p1_to_p3, from_p1_to_p2.normalized);
|
||||
dot /= from_p1_to_p2.magnitude;
|
||||
float t = Mathf.Clamp01(dot);
|
||||
return p1 + from_p1_to_p2 * t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5b33b2e663e78774c9f0c9af55018725
|
||||
timeCreated: 1440845580
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,394 @@
|
|||
/// Credit jack.sydorenko, firagon
|
||||
/// Sourced from - http://forum.unity3d.com/threads/new-ui-and-line-drawing.253772/
|
||||
/// Updated/Refactored from - http://forum.unity3d.com/threads/new-ui-and-line-drawing.253772/#post-2528050
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
[AddComponentMenu("UI/Extensions/Primitives/UILineRendererList")]
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
public class UILineRendererList : UIPrimitiveBase
|
||||
{
|
||||
private enum SegmentType
|
||||
{
|
||||
Start,
|
||||
Middle,
|
||||
End,
|
||||
Full,
|
||||
}
|
||||
|
||||
public enum JoinType
|
||||
{
|
||||
Bevel,
|
||||
Miter
|
||||
}
|
||||
|
||||
public enum BezierType
|
||||
{
|
||||
None,
|
||||
Quick,
|
||||
Basic,
|
||||
Improved,
|
||||
Catenary,
|
||||
}
|
||||
|
||||
private const float MIN_MITER_JOIN = 15 * Mathf.Deg2Rad;
|
||||
|
||||
// A bevel 'nice' join displaces the vertices of the line segment instead of simply rendering a
|
||||
// quad to connect the endpoints. This improves the look of textured and transparent lines, since
|
||||
// there is no overlapping.
|
||||
private const float MIN_BEVEL_NICE_JOIN = 30 * Mathf.Deg2Rad;
|
||||
|
||||
private static Vector2 UV_TOP_LEFT, UV_BOTTOM_LEFT, UV_TOP_CENTER_LEFT, UV_TOP_CENTER_RIGHT, UV_BOTTOM_CENTER_LEFT, UV_BOTTOM_CENTER_RIGHT, UV_TOP_RIGHT, UV_BOTTOM_RIGHT;
|
||||
private static Vector2[] startUvs, middleUvs, endUvs, fullUvs;
|
||||
|
||||
[SerializeField, Tooltip("Points to draw lines between\n Can be improved using the Resolution Option")]
|
||||
internal List<Vector2> m_points;
|
||||
// [SerializeField, Tooltip("Segments to be drawn\n This is a list of arrays of points")]
|
||||
//internal List<Vector2[]> m_segments;
|
||||
|
||||
[SerializeField, Tooltip("Thickness of the line")]
|
||||
internal float lineThickness = 2;
|
||||
[SerializeField, Tooltip("Use the relative bounds of the Rect Transform (0,0 -> 0,1) or screen space coordinates")]
|
||||
internal bool relativeSize;
|
||||
[SerializeField, Tooltip("Do the points identify a single line or split pairs of lines")]
|
||||
internal bool lineList;
|
||||
[SerializeField, Tooltip("Add end caps to each line\nMultiple caps when used with Line List")]
|
||||
internal bool lineCaps;
|
||||
[SerializeField, Tooltip("Resolution of the Bezier curve, different to line Resolution")]
|
||||
internal int bezierSegmentsPerCurve = 10;
|
||||
|
||||
public float LineThickness
|
||||
{
|
||||
get { return lineThickness; }
|
||||
set { lineThickness = value; SetAllDirty(); }
|
||||
}
|
||||
|
||||
public bool RelativeSize
|
||||
{
|
||||
get { return relativeSize; }
|
||||
set { relativeSize = value; SetAllDirty(); }
|
||||
}
|
||||
|
||||
public bool LineList
|
||||
{
|
||||
get { return lineList; }
|
||||
set { lineList = value; SetAllDirty(); }
|
||||
}
|
||||
|
||||
public bool LineCaps
|
||||
{
|
||||
get { return lineCaps; }
|
||||
set { lineCaps = value; SetAllDirty(); }
|
||||
}
|
||||
|
||||
[Tooltip("The type of Join used between lines, Square/Mitre or Curved/Bevel")]
|
||||
public JoinType LineJoins = JoinType.Bevel;
|
||||
|
||||
[Tooltip("Bezier method to apply to line, see docs for options\nCan't be used in conjunction with Resolution as Bezier already changes the resolution")]
|
||||
public BezierType BezierMode = BezierType.None;
|
||||
|
||||
public int BezierSegmentsPerCurve
|
||||
{
|
||||
get { return bezierSegmentsPerCurve; }
|
||||
set { bezierSegmentsPerCurve = value; }
|
||||
}
|
||||
|
||||
[HideInInspector]
|
||||
public bool drivenExternally = false;
|
||||
|
||||
/// <summary>
|
||||
/// Points to be drawn in the line.
|
||||
/// </summary>
|
||||
/// <remarks>Don't add points to the list directly, use the add / remove functions</remarks>
|
||||
public List<Vector2> Points
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_points;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (m_points == value)
|
||||
return;
|
||||
m_points = value;
|
||||
SetAllDirty();
|
||||
}
|
||||
}
|
||||
|
||||
// /// <summary>
|
||||
// /// List of Segments to be drawn.
|
||||
// /// </summary>
|
||||
// public List<Vector2[]> Segments
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return m_segments;
|
||||
// }
|
||||
|
||||
// set
|
||||
// {
|
||||
// m_segments = value;
|
||||
// SetAllDirty();
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
public void AddPoint(Vector2 pointToAdd)
|
||||
{
|
||||
m_points.Add(pointToAdd);
|
||||
SetAllDirty();
|
||||
}
|
||||
|
||||
public void RemovePoint(Vector2 pointToRemove)
|
||||
{
|
||||
m_points.Remove(pointToRemove);
|
||||
SetAllDirty();
|
||||
}
|
||||
|
||||
public void ClearPoints()
|
||||
{
|
||||
m_points.Clear();
|
||||
SetAllDirty();
|
||||
}
|
||||
|
||||
private void PopulateMesh(VertexHelper vh, List<Vector2> pointsToDraw)
|
||||
{
|
||||
//If Bezier is desired, pick the implementation
|
||||
if (BezierMode != BezierType.None && BezierMode != BezierType.Catenary && pointsToDraw.Count > 3) {
|
||||
BezierPath bezierPath = new BezierPath ();
|
||||
|
||||
bezierPath.SetControlPoints (pointsToDraw);
|
||||
bezierPath.SegmentsPerCurve = bezierSegmentsPerCurve;
|
||||
List<Vector2> drawingPoints;
|
||||
switch (BezierMode) {
|
||||
case BezierType.Basic:
|
||||
drawingPoints = bezierPath.GetDrawingPoints0 ();
|
||||
break;
|
||||
case BezierType.Improved:
|
||||
drawingPoints = bezierPath.GetDrawingPoints1 ();
|
||||
break;
|
||||
default:
|
||||
drawingPoints = bezierPath.GetDrawingPoints2 ();
|
||||
break;
|
||||
}
|
||||
|
||||
pointsToDraw = drawingPoints;
|
||||
}
|
||||
if (BezierMode == BezierType.Catenary && pointsToDraw.Count == 2) {
|
||||
CableCurve cable = new CableCurve (pointsToDraw);
|
||||
cable.slack = Resolution;
|
||||
cable.steps = BezierSegmentsPerCurve;
|
||||
pointsToDraw.Clear();
|
||||
pointsToDraw.AddRange(cable.Points());
|
||||
}
|
||||
|
||||
if (ImproveResolution != ResolutionMode.None) {
|
||||
pointsToDraw = IncreaseResolution (pointsToDraw);
|
||||
}
|
||||
|
||||
// scale based on the size of the rect or use absolute, this is switchable
|
||||
var sizeX = !relativeSize ? 1 : rectTransform.rect.width;
|
||||
var sizeY = !relativeSize ? 1 : rectTransform.rect.height;
|
||||
var offsetX = -rectTransform.pivot.x * sizeX;
|
||||
var offsetY = -rectTransform.pivot.y * sizeY;
|
||||
|
||||
// Generate the quads that make up the wide line
|
||||
var segments = new List<UIVertex[]> ();
|
||||
if (lineList) {
|
||||
for (var i = 1; i < pointsToDraw.Count; i += 2) {
|
||||
var start = pointsToDraw [i - 1];
|
||||
var end = pointsToDraw [i];
|
||||
start = new Vector2 (start.x * sizeX + offsetX, start.y * sizeY + offsetY);
|
||||
end = new Vector2 (end.x * sizeX + offsetX, end.y * sizeY + offsetY);
|
||||
|
||||
if (lineCaps) {
|
||||
segments.Add (CreateLineCap (start, end, SegmentType.Start));
|
||||
}
|
||||
|
||||
//segments.Add(CreateLineSegment(start, end, SegmentType.Full));
|
||||
segments.Add (CreateLineSegment (start, end, SegmentType.Middle));
|
||||
|
||||
if (lineCaps) {
|
||||
segments.Add (CreateLineCap (start, end, SegmentType.End));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (var i = 1; i < pointsToDraw.Count; i++) {
|
||||
var start = pointsToDraw [i - 1];
|
||||
var end = pointsToDraw [i];
|
||||
start = new Vector2 (start.x * sizeX + offsetX, start.y * sizeY + offsetY);
|
||||
end = new Vector2 (end.x * sizeX + offsetX, end.y * sizeY + offsetY);
|
||||
|
||||
if (lineCaps && i == 1) {
|
||||
segments.Add (CreateLineCap (start, end, SegmentType.Start));
|
||||
}
|
||||
|
||||
segments.Add (CreateLineSegment (start, end, SegmentType.Middle));
|
||||
//segments.Add(CreateLineSegment(start, end, SegmentType.Full));
|
||||
|
||||
if (lineCaps && i == pointsToDraw.Count - 1) {
|
||||
segments.Add (CreateLineCap (start, end, SegmentType.End));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the line segments to the vertex helper, creating any joins as needed
|
||||
for (var i = 0; i < segments.Count; i++) {
|
||||
if (!lineList && i < segments.Count - 1) {
|
||||
var vec1 = segments [i] [1].position - segments [i] [2].position;
|
||||
var vec2 = segments [i + 1] [2].position - segments [i + 1] [1].position;
|
||||
var angle = Vector2.Angle (vec1, vec2) * Mathf.Deg2Rad;
|
||||
|
||||
// Positive sign means the line is turning in a 'clockwise' direction
|
||||
var sign = Mathf.Sign (Vector3.Cross (vec1.normalized, vec2.normalized).z);
|
||||
|
||||
// Calculate the miter point
|
||||
var miterDistance = lineThickness / (2 * Mathf.Tan (angle / 2));
|
||||
var miterPointA = segments [i] [2].position - vec1.normalized * miterDistance * sign;
|
||||
var miterPointB = segments [i] [3].position + vec1.normalized * miterDistance * sign;
|
||||
|
||||
var joinType = LineJoins;
|
||||
if (joinType == JoinType.Miter) {
|
||||
// Make sure we can make a miter join without too many artifacts.
|
||||
if (miterDistance < vec1.magnitude / 2 && miterDistance < vec2.magnitude / 2 && angle > MIN_MITER_JOIN) {
|
||||
segments [i] [2].position = miterPointA;
|
||||
segments [i] [3].position = miterPointB;
|
||||
segments [i + 1] [0].position = miterPointB;
|
||||
segments [i + 1] [1].position = miterPointA;
|
||||
} else {
|
||||
joinType = JoinType.Bevel;
|
||||
}
|
||||
}
|
||||
|
||||
if (joinType == JoinType.Bevel) {
|
||||
if (miterDistance < vec1.magnitude / 2 && miterDistance < vec2.magnitude / 2 && angle > MIN_BEVEL_NICE_JOIN) {
|
||||
if (sign < 0) {
|
||||
segments [i] [2].position = miterPointA;
|
||||
segments [i + 1] [1].position = miterPointA;
|
||||
} else {
|
||||
segments [i] [3].position = miterPointB;
|
||||
segments [i + 1] [0].position = miterPointB;
|
||||
}
|
||||
}
|
||||
|
||||
var join = new UIVertex[] { segments [i] [2], segments [i] [3], segments [i + 1] [0], segments [i + 1] [1] };
|
||||
vh.AddUIVertexQuad (join);
|
||||
}
|
||||
}
|
||||
|
||||
vh.AddUIVertexQuad (segments [i]);
|
||||
}
|
||||
if (vh.currentVertCount > 64000) {
|
||||
Debug.LogError ("Max Verticies size is 64000, current mesh verticies count is [" + vh.currentVertCount + "] - Cannot Draw");
|
||||
vh.Clear ();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected override void OnPopulateMesh(VertexHelper vh)
|
||||
{
|
||||
if (m_points != null && m_points.Count > 0) {
|
||||
GeneratedUVs ();
|
||||
vh.Clear ();
|
||||
|
||||
PopulateMesh (vh, m_points);
|
||||
|
||||
}
|
||||
//else if (m_segments != null && m_segments.Count > 0) {
|
||||
// GeneratedUVs ();
|
||||
// vh.Clear ();
|
||||
|
||||
// for (int s = 0; s < m_segments.Count; s++) {
|
||||
// Vector2[] pointsToDraw = m_segments [s];
|
||||
// PopulateMesh (vh, pointsToDraw);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
private UIVertex[] CreateLineCap(Vector2 start, Vector2 end, SegmentType type)
|
||||
{
|
||||
if (type == SegmentType.Start)
|
||||
{
|
||||
var capStart = start - ((end - start).normalized * lineThickness / 2);
|
||||
return CreateLineSegment(capStart, start, SegmentType.Start);
|
||||
}
|
||||
else if (type == SegmentType.End)
|
||||
{
|
||||
var capEnd = end + ((end - start).normalized * lineThickness / 2);
|
||||
return CreateLineSegment(end, capEnd, SegmentType.End);
|
||||
}
|
||||
|
||||
Debug.LogError("Bad SegmentType passed in to CreateLineCap. Must be SegmentType.Start or SegmentType.End");
|
||||
return null;
|
||||
}
|
||||
|
||||
private UIVertex[] CreateLineSegment(Vector2 start, Vector2 end, SegmentType type)
|
||||
{
|
||||
Vector2 offset = new Vector2((start.y - end.y), end.x - start.x).normalized * lineThickness / 2;
|
||||
|
||||
var v1 = start - offset;
|
||||
var v2 = start + offset;
|
||||
var v3 = end + offset;
|
||||
var v4 = end - offset;
|
||||
//Return the VDO with the correct uvs
|
||||
switch (type)
|
||||
{
|
||||
case SegmentType.Start:
|
||||
return SetVbo(new[] { v1, v2, v3, v4 }, startUvs);
|
||||
case SegmentType.End:
|
||||
return SetVbo(new[] { v1, v2, v3, v4 }, endUvs);
|
||||
case SegmentType.Full:
|
||||
return SetVbo(new[] { v1, v2, v3, v4 }, fullUvs);
|
||||
default:
|
||||
return SetVbo(new[] { v1, v2, v3, v4 }, middleUvs);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void GeneratedUVs()
|
||||
{
|
||||
if (activeSprite != null)
|
||||
{
|
||||
var outer = Sprites.DataUtility.GetOuterUV(activeSprite);
|
||||
var inner = Sprites.DataUtility.GetInnerUV(activeSprite);
|
||||
UV_TOP_LEFT = new Vector2(outer.x, outer.y);
|
||||
UV_BOTTOM_LEFT = new Vector2(outer.x, outer.w);
|
||||
UV_TOP_CENTER_LEFT = new Vector2(inner.x, inner.y);
|
||||
UV_TOP_CENTER_RIGHT = new Vector2(inner.z, inner.y);
|
||||
UV_BOTTOM_CENTER_LEFT = new Vector2(inner.x, inner.w);
|
||||
UV_BOTTOM_CENTER_RIGHT = new Vector2(inner.z, inner.w);
|
||||
UV_TOP_RIGHT = new Vector2(outer.z, outer.y);
|
||||
UV_BOTTOM_RIGHT = new Vector2(outer.z, outer.w);
|
||||
}
|
||||
else
|
||||
{
|
||||
UV_TOP_LEFT = Vector2.zero;
|
||||
UV_BOTTOM_LEFT = new Vector2(0, 1);
|
||||
UV_TOP_CENTER_LEFT = new Vector2(0.5f, 0);
|
||||
UV_TOP_CENTER_RIGHT = new Vector2(0.5f, 0);
|
||||
UV_BOTTOM_CENTER_LEFT = new Vector2(0.5f, 1);
|
||||
UV_BOTTOM_CENTER_RIGHT = new Vector2(0.5f, 1);
|
||||
UV_TOP_RIGHT = new Vector2(1, 0);
|
||||
UV_BOTTOM_RIGHT = Vector2.one;
|
||||
}
|
||||
|
||||
|
||||
startUvs = new[] { UV_TOP_LEFT, UV_BOTTOM_LEFT, UV_BOTTOM_CENTER_LEFT, UV_TOP_CENTER_LEFT };
|
||||
middleUvs = new[] { UV_TOP_CENTER_LEFT, UV_BOTTOM_CENTER_LEFT, UV_BOTTOM_CENTER_RIGHT, UV_TOP_CENTER_RIGHT };
|
||||
endUvs = new[] { UV_TOP_CENTER_RIGHT, UV_BOTTOM_CENTER_RIGHT, UV_BOTTOM_RIGHT, UV_TOP_RIGHT };
|
||||
fullUvs = new[] { UV_TOP_LEFT, UV_BOTTOM_LEFT, UV_BOTTOM_RIGHT, UV_TOP_RIGHT };
|
||||
}
|
||||
|
||||
protected override void ResolutionToNativeSize(float distance)
|
||||
{
|
||||
if (UseNativeSize)
|
||||
{
|
||||
m_Resolution = distance / (activeSprite.rect.width / pixelsPerUnit);
|
||||
lineThickness = activeSprite.rect.height / pixelsPerUnit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 34861a5dcec3dbf438f8288be97dd133
|
||||
timeCreated: 1440845580
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,159 @@
|
|||
/// Credit jonbro5556
|
||||
/// Based on original LineRender script by jack.sydorenko
|
||||
/// Sourced from - http://forum.unity3d.com/threads/new-ui-and-line-drawing.253772/
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
[AddComponentMenu("UI/Extensions/Primitives/UILineTextureRenderer")]
|
||||
public class UILineTextureRenderer : UIPrimitiveBase
|
||||
{
|
||||
[SerializeField]
|
||||
Rect m_UVRect = new Rect(0f, 0f, 1f, 1f);
|
||||
[SerializeField]
|
||||
private Vector2[] m_points;
|
||||
|
||||
public float LineThickness = 2;
|
||||
public bool UseMargins;
|
||||
public Vector2 Margin;
|
||||
public bool relativeSize;
|
||||
|
||||
/// <summary>
|
||||
/// UV rectangle used by the texture.
|
||||
/// </summary>
|
||||
public Rect uvRect
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_UVRect;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (m_UVRect == value)
|
||||
return;
|
||||
m_UVRect = value;
|
||||
SetVerticesDirty();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Points to be drawn in the line.
|
||||
/// </summary>
|
||||
public Vector2[] Points
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_points;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (m_points == value)
|
||||
return;
|
||||
m_points = value;
|
||||
SetAllDirty();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPopulateMesh(VertexHelper vh)
|
||||
{
|
||||
// requires sets of quads
|
||||
if (m_points == null || m_points.Length < 2)
|
||||
m_points = new[] { new Vector2(0, 0), new Vector2(1, 1) };
|
||||
var capSize = 24;
|
||||
var sizeX = rectTransform.rect.width;
|
||||
var sizeY = rectTransform.rect.height;
|
||||
var offsetX = -rectTransform.pivot.x * rectTransform.rect.width;
|
||||
var offsetY = -rectTransform.pivot.y * rectTransform.rect.height;
|
||||
|
||||
// don't want to scale based on the size of the rect, so this is switchable now
|
||||
if (!relativeSize)
|
||||
{
|
||||
sizeX = 1;
|
||||
sizeY = 1;
|
||||
}
|
||||
// build a new set of m_points taking into account the cap sizes.
|
||||
// would be cool to support corners too, but that might be a bit tough :)
|
||||
var pointList = new List<Vector2>();
|
||||
pointList.Add(m_points[0]);
|
||||
var capPoint = m_points[0] + (m_points[1] - m_points[0]).normalized * capSize;
|
||||
pointList.Add(capPoint);
|
||||
|
||||
// should bail before the last point to add another cap point
|
||||
for (int i = 1; i < m_points.Length - 1; i++)
|
||||
{
|
||||
pointList.Add(m_points[i]);
|
||||
}
|
||||
capPoint = m_points[m_points.Length - 1] - (m_points[m_points.Length - 1] - m_points[m_points.Length - 2]).normalized * capSize;
|
||||
pointList.Add(capPoint);
|
||||
pointList.Add(m_points[m_points.Length - 1]);
|
||||
|
||||
var Tempm_points = pointList.ToArray();
|
||||
if (UseMargins)
|
||||
{
|
||||
sizeX -= Margin.x;
|
||||
sizeY -= Margin.y;
|
||||
offsetX += Margin.x / 2f;
|
||||
offsetY += Margin.y / 2f;
|
||||
}
|
||||
|
||||
vh.Clear();
|
||||
|
||||
Vector2 prevV1 = Vector2.zero;
|
||||
Vector2 prevV2 = Vector2.zero;
|
||||
|
||||
for (int i = 1; i < Tempm_points.Length; i++)
|
||||
{
|
||||
var prev = Tempm_points[i - 1];
|
||||
var cur = Tempm_points[i];
|
||||
prev = new Vector2(prev.x * sizeX + offsetX, prev.y * sizeY + offsetY);
|
||||
cur = new Vector2(cur.x * sizeX + offsetX, cur.y * sizeY + offsetY);
|
||||
|
||||
float angle = Mathf.Atan2(cur.y - prev.y, cur.x - prev.x) * 180f / Mathf.PI;
|
||||
|
||||
var v1 = prev + new Vector2(0, -LineThickness / 2);
|
||||
var v2 = prev + new Vector2(0, +LineThickness / 2);
|
||||
var v3 = cur + new Vector2(0, +LineThickness / 2);
|
||||
var v4 = cur + new Vector2(0, -LineThickness / 2);
|
||||
|
||||
v1 = RotatePointAroundPivot(v1, prev, new Vector3(0, 0, angle));
|
||||
v2 = RotatePointAroundPivot(v2, prev, new Vector3(0, 0, angle));
|
||||
v3 = RotatePointAroundPivot(v3, cur, new Vector3(0, 0, angle));
|
||||
v4 = RotatePointAroundPivot(v4, cur, new Vector3(0, 0, angle));
|
||||
|
||||
Vector2 uvTopLeft = Vector2.zero;
|
||||
Vector2 uvBottomLeft = new Vector2(0, 1);
|
||||
|
||||
Vector2 uvTopCenter = new Vector2(0.5f, 0);
|
||||
Vector2 uvBottomCenter = new Vector2(0.5f, 1);
|
||||
|
||||
Vector2 uvTopRight = new Vector2(1, 0);
|
||||
Vector2 uvBottomRight = new Vector2(1, 1);
|
||||
|
||||
Vector2[] uvs = new[] { uvTopCenter, uvBottomCenter, uvBottomCenter, uvTopCenter };
|
||||
|
||||
if (i > 1)
|
||||
vh.AddUIVertexQuad(SetVbo(new[] { prevV1, prevV2, v1, v2 }, uvs));
|
||||
|
||||
if (i == 1)
|
||||
uvs = new[] { uvTopLeft, uvBottomLeft, uvBottomCenter, uvTopCenter };
|
||||
else if (i == Tempm_points.Length - 1)
|
||||
uvs = new[] { uvTopCenter, uvBottomCenter, uvBottomRight, uvTopRight };
|
||||
|
||||
vh.AddUIVertexQuad(SetVbo(new[] { v1, v2, v3, v4 }, uvs));
|
||||
|
||||
|
||||
prevV1 = v3;
|
||||
prevV2 = v4;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles)
|
||||
{
|
||||
Vector3 dir = point - pivot; // get point direction relative to pivot
|
||||
dir = Quaternion.Euler(angles) * dir; // rotate it
|
||||
point = dir + pivot; // calculate rotated point
|
||||
return point; // return it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b801876ddb189f94f905cd1646564fbf
|
||||
timeCreated: 1440845581
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,362 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
public enum ResolutionMode
|
||||
{
|
||||
None,
|
||||
PerSegment,
|
||||
PerLine
|
||||
}
|
||||
|
||||
[RequireComponent(typeof(CanvasRenderer))]
|
||||
public class UIPrimitiveBase : MaskableGraphic, ILayoutElement, ICanvasRaycastFilter
|
||||
{
|
||||
static protected Material s_ETC1DefaultUI = null;
|
||||
List<Vector2> outputList = new List<Vector2>();
|
||||
|
||||
[SerializeField] private Sprite m_Sprite;
|
||||
public Sprite sprite { get { return m_Sprite; } set { if (SetPropertyUtility.SetClass(ref m_Sprite, value)) GeneratedUVs(); SetAllDirty(); } }
|
||||
|
||||
[NonSerialized]
|
||||
private Sprite m_OverrideSprite;
|
||||
public Sprite overrideSprite { get { return activeSprite; } set { if (SetPropertyUtility.SetClass(ref m_OverrideSprite, value)) GeneratedUVs(); SetAllDirty(); } }
|
||||
|
||||
protected Sprite activeSprite { get { return m_OverrideSprite != null ? m_OverrideSprite : sprite; } }
|
||||
|
||||
// Not serialized until we support read-enabled sprites better.
|
||||
internal float m_EventAlphaThreshold = 1;
|
||||
public float eventAlphaThreshold { get { return m_EventAlphaThreshold; } set { m_EventAlphaThreshold = value; } }
|
||||
|
||||
[SerializeField]
|
||||
private ResolutionMode m_improveResolution;
|
||||
public ResolutionMode ImproveResolution { get { return m_improveResolution; } set { m_improveResolution = value; SetAllDirty(); } }
|
||||
|
||||
[SerializeField]
|
||||
protected float m_Resolution;
|
||||
public float Resolution { get { return m_Resolution; } set { m_Resolution = value; SetAllDirty(); } }
|
||||
|
||||
[SerializeField]
|
||||
private bool m_useNativeSize;
|
||||
public bool UseNativeSize { get { return m_useNativeSize; } set { m_useNativeSize = value; SetAllDirty(); } }
|
||||
|
||||
protected UIPrimitiveBase()
|
||||
{
|
||||
useLegacyMeshGeneration = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Default material used to draw everything if no explicit material was specified.
|
||||
/// </summary>
|
||||
|
||||
static public Material defaultETC1GraphicMaterial
|
||||
{
|
||||
get
|
||||
{
|
||||
if (s_ETC1DefaultUI == null)
|
||||
s_ETC1DefaultUI = Canvas.GetETC1SupportedCanvasMaterial();
|
||||
return s_ETC1DefaultUI;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Image's texture comes from the UnityEngine.Image.
|
||||
/// </summary>
|
||||
public override Texture mainTexture
|
||||
{
|
||||
get
|
||||
{
|
||||
if (activeSprite == null)
|
||||
{
|
||||
if (material != null && material.mainTexture != null)
|
||||
{
|
||||
return material.mainTexture;
|
||||
}
|
||||
return s_WhiteTexture;
|
||||
}
|
||||
|
||||
return activeSprite.texture;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the Image has a border to work with.
|
||||
/// </summary>
|
||||
|
||||
public bool hasBorder
|
||||
{
|
||||
get
|
||||
{
|
||||
if (activeSprite != null)
|
||||
{
|
||||
Vector4 v = activeSprite.border;
|
||||
return v.sqrMagnitude > 0f;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public float pixelsPerUnit
|
||||
{
|
||||
get
|
||||
{
|
||||
float spritePixelsPerUnit = 100;
|
||||
if (activeSprite)
|
||||
spritePixelsPerUnit = activeSprite.pixelsPerUnit;
|
||||
|
||||
float referencePixelsPerUnit = 100;
|
||||
if (canvas)
|
||||
referencePixelsPerUnit = canvas.referencePixelsPerUnit;
|
||||
|
||||
return spritePixelsPerUnit / referencePixelsPerUnit;
|
||||
}
|
||||
}
|
||||
|
||||
public override Material material
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_Material != null)
|
||||
return m_Material;
|
||||
|
||||
if (activeSprite && activeSprite.associatedAlphaSplitTexture != null)
|
||||
return defaultETC1GraphicMaterial;
|
||||
|
||||
return defaultMaterial;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
base.material = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected UIVertex[] SetVbo(Vector2[] vertices, Vector2[] uvs)
|
||||
{
|
||||
UIVertex[] vbo = new UIVertex[4];
|
||||
for (int i = 0; i < vertices.Length; i++)
|
||||
{
|
||||
var vert = UIVertex.simpleVert;
|
||||
vert.color = color;
|
||||
vert.position = vertices[i];
|
||||
vert.uv0 = uvs[i];
|
||||
vbo[i] = vert;
|
||||
}
|
||||
return vbo;
|
||||
}
|
||||
|
||||
protected Vector2[] IncreaseResolution(Vector2[] input)
|
||||
{
|
||||
return IncreaseResolution(new List<Vector2>(input)).ToArray();
|
||||
}
|
||||
|
||||
protected List<Vector2> IncreaseResolution(List<Vector2> input)
|
||||
{
|
||||
outputList.Clear();
|
||||
|
||||
switch (ImproveResolution)
|
||||
{
|
||||
case ResolutionMode.PerLine:
|
||||
float totalDistance = 0, increments = 0;
|
||||
for (int i = 0; i < input.Count - 1; i++)
|
||||
{
|
||||
totalDistance += Vector2.Distance(input[i], input[i + 1]);
|
||||
}
|
||||
ResolutionToNativeSize(totalDistance);
|
||||
increments = totalDistance / m_Resolution;
|
||||
var incrementCount = 0;
|
||||
for (int i = 0; i < input.Count - 1; i++)
|
||||
{
|
||||
var p1 = input[i];
|
||||
outputList.Add(p1);
|
||||
var p2 = input[i + 1];
|
||||
var segmentDistance = Vector2.Distance(p1, p2) / increments;
|
||||
var incrementTime = 1f / segmentDistance;
|
||||
for (int j = 0; j < segmentDistance; j++)
|
||||
{
|
||||
outputList.Add(Vector2.Lerp(p1, (Vector2)p2, j * incrementTime));
|
||||
incrementCount++;
|
||||
}
|
||||
outputList.Add(p2);
|
||||
}
|
||||
break;
|
||||
case ResolutionMode.PerSegment:
|
||||
for (int i = 0; i < input.Count - 1; i++)
|
||||
{
|
||||
var p1 = input[i];
|
||||
outputList.Add(p1);
|
||||
var p2 = input[i + 1];
|
||||
ResolutionToNativeSize(Vector2.Distance(p1, p2));
|
||||
increments = 1f / m_Resolution;
|
||||
for (Single j = 1; j < m_Resolution; j++)
|
||||
{
|
||||
outputList.Add(Vector2.Lerp(p1, (Vector2)p2, increments * j));
|
||||
}
|
||||
outputList.Add(p2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return outputList;
|
||||
}
|
||||
|
||||
protected virtual void GeneratedUVs() { }
|
||||
|
||||
protected virtual void ResolutionToNativeSize(float distance) { }
|
||||
|
||||
|
||||
#region ILayoutElement Interface
|
||||
|
||||
public virtual void CalculateLayoutInputHorizontal() { }
|
||||
public virtual void CalculateLayoutInputVertical() { }
|
||||
|
||||
public virtual float minWidth { get { return 0; } }
|
||||
|
||||
public virtual float preferredWidth
|
||||
{
|
||||
get
|
||||
{
|
||||
if (overrideSprite == null)
|
||||
return 0;
|
||||
return overrideSprite.rect.size.x / pixelsPerUnit;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual float flexibleWidth { get { return -1; } }
|
||||
|
||||
public virtual float minHeight { get { return 0; } }
|
||||
|
||||
public virtual float preferredHeight
|
||||
{
|
||||
get
|
||||
{
|
||||
if (overrideSprite == null)
|
||||
return 0;
|
||||
return overrideSprite.rect.size.y / pixelsPerUnit;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual float flexibleHeight { get { return -1; } }
|
||||
|
||||
public virtual int layoutPriority { get { return 0; } }
|
||||
|
||||
#endregion
|
||||
|
||||
#region ICanvasRaycastFilter Interface
|
||||
public virtual bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera)
|
||||
{
|
||||
// add test for line check
|
||||
if (m_EventAlphaThreshold >= 1)
|
||||
return true;
|
||||
|
||||
Sprite sprite = overrideSprite;
|
||||
if (sprite == null)
|
||||
return true;
|
||||
|
||||
Vector2 local;
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, screenPoint, eventCamera, out local);
|
||||
|
||||
Rect rect = GetPixelAdjustedRect();
|
||||
|
||||
// Convert to have lower left corner as reference point.
|
||||
local.x += rectTransform.pivot.x * rect.width;
|
||||
local.y += rectTransform.pivot.y * rect.height;
|
||||
|
||||
local = MapCoordinate(local, rect);
|
||||
|
||||
//test local coord with Mesh
|
||||
|
||||
// Normalize local coordinates.
|
||||
Rect spriteRect = sprite.textureRect;
|
||||
Vector2 normalized = new Vector2(local.x / spriteRect.width, local.y / spriteRect.height);
|
||||
|
||||
// Convert to texture space.
|
||||
float x = Mathf.Lerp(spriteRect.x, spriteRect.xMax, normalized.x) / sprite.texture.width;
|
||||
float y = Mathf.Lerp(spriteRect.y, spriteRect.yMax, normalized.y) / sprite.texture.height;
|
||||
|
||||
try
|
||||
{
|
||||
return sprite.texture.GetPixelBilinear(x, y).a >= m_EventAlphaThreshold;
|
||||
}
|
||||
catch (UnityException e)
|
||||
{
|
||||
Debug.LogError("Using clickAlphaThreshold lower than 1 on Image whose sprite texture cannot be read. " + e.Message + " Also make sure to disable sprite packing for this sprite.", this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return image adjusted position
|
||||
/// **Copied from Unity's Image component for now and simplified for UI Extensions primitives
|
||||
/// </summary>
|
||||
/// <param name="local"></param>
|
||||
/// <param name="rect"></param>
|
||||
/// <returns></returns>
|
||||
private Vector2 MapCoordinate(Vector2 local, Rect rect)
|
||||
{
|
||||
Rect spriteRect = sprite.rect;
|
||||
//if (type == Type.Simple || type == Type.Filled)
|
||||
return new Vector2(local.x * rect.width, local.y * rect.height);
|
||||
|
||||
//Vector4 border = sprite.border;
|
||||
//Vector4 adjustedBorder = GetAdjustedBorders(border / pixelsPerUnit, rect);
|
||||
|
||||
//for (int i = 0; i < 2; i++)
|
||||
//{
|
||||
// if (local[i] <= adjustedBorder[i])
|
||||
// continue;
|
||||
|
||||
// if (rect.size[i] - local[i] <= adjustedBorder[i + 2])
|
||||
// {
|
||||
// local[i] -= (rect.size[i] - spriteRect.size[i]);
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// if (type == Type.Sliced)
|
||||
// {
|
||||
// float lerp = Mathf.InverseLerp(adjustedBorder[i], rect.size[i] - adjustedBorder[i + 2], local[i]);
|
||||
// local[i] = Mathf.Lerp(border[i], spriteRect.size[i] - border[i + 2], lerp);
|
||||
// continue;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// local[i] -= adjustedBorder[i];
|
||||
// local[i] = Mathf.Repeat(local[i], spriteRect.size[i] - border[i] - border[i + 2]);
|
||||
// local[i] += border[i];
|
||||
// continue;
|
||||
// }
|
||||
//}
|
||||
|
||||
//return local;
|
||||
}
|
||||
|
||||
Vector4 GetAdjustedBorders(Vector4 border, Rect rect)
|
||||
{
|
||||
for (int axis = 0; axis <= 1; axis++)
|
||||
{
|
||||
// If the rect is smaller than the combined borders, then there's not room for the borders at their normal size.
|
||||
// In order to avoid artefact's with overlapping borders, we scale the borders down to fit.
|
||||
float combinedBorders = border[axis] + border[axis + 2];
|
||||
if (rect.size[axis] < combinedBorders && combinedBorders != 0)
|
||||
{
|
||||
float borderScaleRatio = rect.size[axis] / combinedBorders;
|
||||
border[axis] *= borderScaleRatio;
|
||||
border[axis + 2] *= borderScaleRatio;
|
||||
}
|
||||
}
|
||||
return border;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region onEnable
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
SetAllDirty();
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 65af11d29c6cb8c45b3d78d97d98440d
|
||||
timeCreated: 1464131942
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8ed31929d883df147b53ffeddcb4f25c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
userData:
|
||||
|
|
@ -0,0 +1,350 @@
|
|||
/**
|
||||
|
||||
This class demonstrates the code discussed in these two articles:
|
||||
|
||||
http://devmag.org.za/2011/04/05/bzier-curves-a-tutorial/
|
||||
http://devmag.org.za/2011/06/23/bzier-path-algorithms/
|
||||
|
||||
Use this code as you wish, at your own risk. If it blows up
|
||||
your computer, makes a plane crash, or otherwise cause damage,
|
||||
injury, or death, it is not my fault.
|
||||
|
||||
@author Herman Tulleken, dev.mag.org.za
|
||||
|
||||
*/
|
||||
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
/**
|
||||
Class for representing a Bezier path, and methods for getting suitable points to
|
||||
draw the curve with line segments.
|
||||
*/
|
||||
public class BezierPath
|
||||
{
|
||||
public int SegmentsPerCurve = 10;
|
||||
public float MINIMUM_SQR_DISTANCE = 0.01f;
|
||||
|
||||
// This corresponds to about 172 degrees, 8 degrees from a straight line
|
||||
public float DIVISION_THRESHOLD = -0.99f;
|
||||
|
||||
private List<Vector2> controlPoints;
|
||||
|
||||
private int curveCount; //how many bezier curves in this path?
|
||||
|
||||
/**
|
||||
Constructs a new empty Bezier curve. Use one of these methods
|
||||
to add points: SetControlPoints, Interpolate, SamplePoints.
|
||||
*/
|
||||
public BezierPath()
|
||||
{
|
||||
controlPoints = new List<Vector2>();
|
||||
}
|
||||
|
||||
/**
|
||||
Sets the control points of this Bezier path.
|
||||
Points 0-3 forms the first Bezier curve, points
|
||||
3-6 forms the second curve, etc.
|
||||
*/
|
||||
public void SetControlPoints(List<Vector2> newControlPoints)
|
||||
{
|
||||
controlPoints.Clear();
|
||||
controlPoints.AddRange(newControlPoints);
|
||||
curveCount = (controlPoints.Count - 1) / 3;
|
||||
}
|
||||
|
||||
public void SetControlPoints(Vector2[] newControlPoints)
|
||||
{
|
||||
controlPoints.Clear();
|
||||
controlPoints.AddRange(newControlPoints);
|
||||
curveCount = (controlPoints.Count - 1) / 3;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the control points for this Bezier curve.
|
||||
*/
|
||||
public List<Vector2> GetControlPoints()
|
||||
{
|
||||
return controlPoints;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Calculates a Bezier interpolated path for the given points.
|
||||
*/
|
||||
public void Interpolate(List<Vector2> segmentPoints, float scale)
|
||||
{
|
||||
controlPoints.Clear();
|
||||
|
||||
if (segmentPoints.Count < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < segmentPoints.Count; i++)
|
||||
{
|
||||
if (i == 0) // is first
|
||||
{
|
||||
Vector2 p1 = segmentPoints[i];
|
||||
Vector2 p2 = segmentPoints[i + 1];
|
||||
|
||||
Vector2 tangent = (p2 - p1);
|
||||
Vector2 q1 = p1 + scale * tangent;
|
||||
|
||||
controlPoints.Add(p1);
|
||||
controlPoints.Add(q1);
|
||||
}
|
||||
else if (i == segmentPoints.Count - 1) //last
|
||||
{
|
||||
Vector2 p0 = segmentPoints[i - 1];
|
||||
Vector2 p1 = segmentPoints[i];
|
||||
Vector2 tangent = (p1 - p0);
|
||||
Vector2 q0 = p1 - scale * tangent;
|
||||
|
||||
controlPoints.Add(q0);
|
||||
controlPoints.Add(p1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 p0 = segmentPoints[i - 1];
|
||||
Vector2 p1 = segmentPoints[i];
|
||||
Vector2 p2 = segmentPoints[i + 1];
|
||||
Vector2 tangent = (p2 - p0).normalized;
|
||||
Vector2 q0 = p1 - scale * tangent * (p1 - p0).magnitude;
|
||||
Vector2 q1 = p1 + scale * tangent * (p2 - p1).magnitude;
|
||||
|
||||
controlPoints.Add(q0);
|
||||
controlPoints.Add(p1);
|
||||
controlPoints.Add(q1);
|
||||
}
|
||||
}
|
||||
|
||||
curveCount = (controlPoints.Count - 1) / 3;
|
||||
}
|
||||
|
||||
/**
|
||||
Sample the given points as a Bezier path.
|
||||
*/
|
||||
public void SamplePoints(List<Vector2> sourcePoints, float minSqrDistance, float maxSqrDistance, float scale)
|
||||
{
|
||||
if (sourcePoints.Count < 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Stack<Vector2> samplePoints = new Stack<Vector2>();
|
||||
|
||||
samplePoints.Push(sourcePoints[0]);
|
||||
|
||||
Vector2 potentialSamplePoint = sourcePoints[1];
|
||||
|
||||
int i = 2;
|
||||
|
||||
for (i = 2; i < sourcePoints.Count; i++)
|
||||
{
|
||||
if (
|
||||
((potentialSamplePoint - sourcePoints[i]).sqrMagnitude > minSqrDistance) &&
|
||||
((samplePoints.Peek() - sourcePoints[i]).sqrMagnitude > maxSqrDistance))
|
||||
{
|
||||
samplePoints.Push(potentialSamplePoint);
|
||||
}
|
||||
|
||||
potentialSamplePoint = sourcePoints[i];
|
||||
}
|
||||
|
||||
//now handle last bit of curve
|
||||
Vector2 p1 = samplePoints.Pop(); //last sample point
|
||||
Vector2 p0 = samplePoints.Peek(); //second last sample point
|
||||
Vector2 tangent = (p0 - potentialSamplePoint).normalized;
|
||||
float d2 = (potentialSamplePoint - p1).magnitude;
|
||||
float d1 = (p1 - p0).magnitude;
|
||||
p1 = p1 + tangent * ((d1 - d2) / 2);
|
||||
|
||||
samplePoints.Push(p1);
|
||||
samplePoints.Push(potentialSamplePoint);
|
||||
|
||||
|
||||
Interpolate(new List<Vector2>(samplePoints), scale);
|
||||
}
|
||||
|
||||
/**
|
||||
Calculates a point on the path.
|
||||
|
||||
@param curveIndex The index of the curve that the point is on. For example,
|
||||
the second curve (index 1) is the curve with control points 3, 4, 5, and 6.
|
||||
|
||||
@param t The parameter indicating where on the curve the point is. 0 corresponds
|
||||
to the "left" point, 1 corresponds to the "right" end point.
|
||||
*/
|
||||
public Vector2 CalculateBezierPoint(int curveIndex, float t)
|
||||
{
|
||||
int nodeIndex = curveIndex * 3;
|
||||
|
||||
Vector2 p0 = controlPoints[nodeIndex];
|
||||
Vector2 p1 = controlPoints[nodeIndex + 1];
|
||||
Vector2 p2 = controlPoints[nodeIndex + 2];
|
||||
Vector2 p3 = controlPoints[nodeIndex + 3];
|
||||
|
||||
return CalculateBezierPoint(t, p0, p1, p2, p3);
|
||||
}
|
||||
|
||||
/**
|
||||
Gets the drawing points. This implementation simply calculates a certain number
|
||||
of points per curve.
|
||||
*/
|
||||
public List<Vector2> GetDrawingPoints0()
|
||||
{
|
||||
List<Vector2> drawingPoints = new List<Vector2>();
|
||||
|
||||
for (int curveIndex = 0; curveIndex < curveCount; curveIndex++)
|
||||
{
|
||||
if (curveIndex == 0) //Only do this for the first end point.
|
||||
//When i != 0, this coincides with the
|
||||
//end point of the previous segment,
|
||||
{
|
||||
drawingPoints.Add(CalculateBezierPoint(curveIndex, 0));
|
||||
}
|
||||
|
||||
for (int j = 1; j <= SegmentsPerCurve; j++)
|
||||
{
|
||||
float t = j / (float)SegmentsPerCurve;
|
||||
drawingPoints.Add(CalculateBezierPoint(curveIndex, t));
|
||||
}
|
||||
}
|
||||
|
||||
return drawingPoints;
|
||||
}
|
||||
|
||||
/**
|
||||
Gets the drawing points. This implementation simply calculates a certain number
|
||||
of points per curve.
|
||||
|
||||
This is a slightly different implementation from the one above.
|
||||
*/
|
||||
public List<Vector2> GetDrawingPoints1()
|
||||
{
|
||||
List<Vector2> drawingPoints = new List<Vector2>();
|
||||
|
||||
for (int i = 0; i < controlPoints.Count - 3; i += 3)
|
||||
{
|
||||
Vector2 p0 = controlPoints[i];
|
||||
Vector2 p1 = controlPoints[i + 1];
|
||||
Vector2 p2 = controlPoints[i + 2];
|
||||
Vector2 p3 = controlPoints[i + 3];
|
||||
|
||||
if (i == 0) //only do this for the first end point. When i != 0, this coincides with the end point of the previous segment,
|
||||
{
|
||||
drawingPoints.Add(CalculateBezierPoint(0, p0, p1, p2, p3));
|
||||
}
|
||||
|
||||
for (int j = 1; j <= SegmentsPerCurve; j++)
|
||||
{
|
||||
float t = j / (float)SegmentsPerCurve;
|
||||
drawingPoints.Add(CalculateBezierPoint(t, p0, p1, p2, p3));
|
||||
}
|
||||
}
|
||||
|
||||
return drawingPoints;
|
||||
}
|
||||
|
||||
/**
|
||||
This gets the drawing points of a bezier curve, using recursive division,
|
||||
which results in less points for the same accuracy as the above implementation.
|
||||
*/
|
||||
public List<Vector2> GetDrawingPoints2()
|
||||
{
|
||||
List<Vector2> drawingPoints = new List<Vector2>();
|
||||
|
||||
for (int curveIndex = 0; curveIndex < curveCount; curveIndex++)
|
||||
{
|
||||
List<Vector2> bezierCurveDrawingPoints = FindDrawingPoints(curveIndex);
|
||||
|
||||
if (curveIndex != 0)
|
||||
{
|
||||
//remove the fist point, as it coincides with the last point of the previous Bezier curve.
|
||||
bezierCurveDrawingPoints.RemoveAt(0);
|
||||
}
|
||||
|
||||
drawingPoints.AddRange(bezierCurveDrawingPoints);
|
||||
}
|
||||
|
||||
return drawingPoints;
|
||||
}
|
||||
|
||||
List<Vector2> FindDrawingPoints(int curveIndex)
|
||||
{
|
||||
List<Vector2> pointList = new List<Vector2>();
|
||||
|
||||
Vector2 left = CalculateBezierPoint(curveIndex, 0);
|
||||
Vector2 right = CalculateBezierPoint(curveIndex, 1);
|
||||
|
||||
pointList.Add(left);
|
||||
pointList.Add(right);
|
||||
|
||||
FindDrawingPoints(curveIndex, 0, 1, pointList, 1);
|
||||
|
||||
return pointList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@returns the number of points added.
|
||||
*/
|
||||
int FindDrawingPoints(int curveIndex, float t0, float t1,
|
||||
List<Vector2> pointList, int insertionIndex)
|
||||
{
|
||||
Vector2 left = CalculateBezierPoint(curveIndex, t0);
|
||||
Vector2 right = CalculateBezierPoint(curveIndex, t1);
|
||||
|
||||
if ((left - right).sqrMagnitude < MINIMUM_SQR_DISTANCE)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
float tMid = (t0 + t1) / 2;
|
||||
Vector2 mid = CalculateBezierPoint(curveIndex, tMid);
|
||||
|
||||
Vector2 leftDirection = (left - mid).normalized;
|
||||
Vector2 rightDirection = (right - mid).normalized;
|
||||
|
||||
if (Vector2.Dot(leftDirection, rightDirection) > DIVISION_THRESHOLD || Mathf.Abs(tMid - 0.5f) < 0.0001f)
|
||||
{
|
||||
int pointsAddedCount = 0;
|
||||
|
||||
pointsAddedCount += FindDrawingPoints(curveIndex, t0, tMid, pointList, insertionIndex);
|
||||
pointList.Insert(insertionIndex + pointsAddedCount, mid);
|
||||
pointsAddedCount++;
|
||||
pointsAddedCount += FindDrawingPoints(curveIndex, tMid, t1, pointList, insertionIndex + pointsAddedCount);
|
||||
|
||||
return pointsAddedCount;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Calculates a point on the Bezier curve represented with the four control points given.
|
||||
*/
|
||||
private Vector2 CalculateBezierPoint(float t, Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3)
|
||||
{
|
||||
float u = 1 - t;
|
||||
float tt = t * t;
|
||||
float uu = u * u;
|
||||
float uuu = uu * u;
|
||||
float ttt = tt * t;
|
||||
|
||||
Vector2 p = uuu * p0; //first term
|
||||
|
||||
p += 3 * uu * t * p1; //second term
|
||||
p += 3 * u * tt * p2; //third term
|
||||
p += ttt * p3; //fourth term
|
||||
|
||||
return p;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 89b61e0416e1256469165fca78d5ed21
|
||||
timeCreated: 1463598733
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,233 @@
|
|||
/// Credit Farfarer
|
||||
/// Sourced from - https://gist.github.com/Farfarer/a765cd07920d48a8713a0c1924db6d70
|
||||
/// Updated for UI / 2D - SimonDarksideJ
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
[System.Serializable]
|
||||
public class CableCurve
|
||||
{
|
||||
[SerializeField]
|
||||
Vector2 m_start;
|
||||
[SerializeField]
|
||||
Vector2 m_end;
|
||||
[SerializeField]
|
||||
float m_slack;
|
||||
[SerializeField]
|
||||
int m_steps;
|
||||
[SerializeField]
|
||||
bool m_regen;
|
||||
|
||||
static Vector2[] emptyCurve = new Vector2[] { new Vector2(0.0f, 0.0f), new Vector2(0.0f, 0.0f) };
|
||||
[SerializeField]
|
||||
Vector2[] points;
|
||||
|
||||
public bool regenPoints
|
||||
{
|
||||
get { return m_regen; }
|
||||
set
|
||||
{
|
||||
m_regen = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 start
|
||||
{
|
||||
get { return m_start; }
|
||||
set
|
||||
{
|
||||
if (value != m_start)
|
||||
m_regen = true;
|
||||
m_start = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 end
|
||||
{
|
||||
get { return m_end; }
|
||||
set
|
||||
{
|
||||
if (value != m_end)
|
||||
m_regen = true;
|
||||
m_end = value;
|
||||
}
|
||||
}
|
||||
public float slack
|
||||
{
|
||||
get { return m_slack; }
|
||||
set
|
||||
{
|
||||
if (value != m_slack)
|
||||
m_regen = true;
|
||||
m_slack = Mathf.Max(0.0f, value);
|
||||
}
|
||||
}
|
||||
public int steps
|
||||
{
|
||||
get { return m_steps; }
|
||||
set
|
||||
{
|
||||
if (value != m_steps)
|
||||
m_regen = true;
|
||||
m_steps = Mathf.Max(2, value);
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2 midPoint
|
||||
{
|
||||
get
|
||||
{
|
||||
Vector2 mid = Vector2.zero;
|
||||
if (m_steps == 2)
|
||||
{
|
||||
return (points[0] + points[1]) * 0.5f;
|
||||
}
|
||||
else if (m_steps > 2)
|
||||
{
|
||||
int m = m_steps / 2;
|
||||
if ((m_steps % 2) == 0)
|
||||
{
|
||||
mid = (points[m] + points[m + 1]) * 0.5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
mid = points[m];
|
||||
}
|
||||
}
|
||||
return mid;
|
||||
}
|
||||
}
|
||||
|
||||
public CableCurve()
|
||||
{
|
||||
points = emptyCurve;
|
||||
m_start = Vector2.up;
|
||||
m_end = Vector2.up + Vector2.right;
|
||||
m_slack = 0.5f;
|
||||
m_steps = 20;
|
||||
m_regen = true;
|
||||
}
|
||||
|
||||
public CableCurve(Vector2[] inputPoints)
|
||||
{
|
||||
points = inputPoints;
|
||||
m_start = inputPoints[0];
|
||||
m_end = inputPoints[1];
|
||||
m_slack = 0.5f;
|
||||
m_steps = 20;
|
||||
m_regen = true;
|
||||
}
|
||||
|
||||
public CableCurve(List<Vector2> inputPoints)
|
||||
{
|
||||
points = inputPoints.ToArray();
|
||||
m_start = inputPoints[0];
|
||||
m_end = inputPoints[1];
|
||||
m_slack = 0.5f;
|
||||
m_steps = 20;
|
||||
m_regen = true;
|
||||
}
|
||||
|
||||
public CableCurve(CableCurve v)
|
||||
{
|
||||
points = v.Points();
|
||||
m_start = v.start;
|
||||
m_end = v.end;
|
||||
m_slack = v.slack;
|
||||
m_steps = v.steps;
|
||||
m_regen = v.regenPoints;
|
||||
}
|
||||
|
||||
public Vector2[] Points()
|
||||
{
|
||||
if (!m_regen)
|
||||
return points;
|
||||
|
||||
if (m_steps < 2)
|
||||
return emptyCurve;
|
||||
|
||||
float lineDist = Vector2.Distance(m_end, m_start);
|
||||
float lineDistH = Vector2.Distance(new Vector2(m_end.x, m_start.y), m_start);
|
||||
float l = lineDist + Mathf.Max(0.0001f, m_slack);
|
||||
float r = 0.0f;
|
||||
float s = m_start.y;
|
||||
float u = lineDistH;
|
||||
float v = end.y;
|
||||
|
||||
if ((u - r) == 0.0f)
|
||||
return emptyCurve;
|
||||
|
||||
float ztarget = Mathf.Sqrt(Mathf.Pow(l, 2.0f) - Mathf.Pow(v - s, 2.0f)) / (u - r);
|
||||
|
||||
int loops = 30;
|
||||
int iterationCount = 0;
|
||||
int maxIterations = loops * 10; // For safety.
|
||||
bool found = false;
|
||||
|
||||
float z = 0.0f;
|
||||
float ztest = 0.0f;
|
||||
float zstep = 100.0f;
|
||||
float ztesttarget = 0.0f;
|
||||
for (int i = 0; i < loops; i++)
|
||||
{
|
||||
for (int j = 0; j < 10; j++)
|
||||
{
|
||||
iterationCount++;
|
||||
ztest = z + zstep;
|
||||
ztesttarget = (float)Math.Sinh(ztest) / ztest;
|
||||
|
||||
if (float.IsInfinity(ztesttarget))
|
||||
continue;
|
||||
|
||||
if (ztesttarget == ztarget)
|
||||
{
|
||||
found = true;
|
||||
z = ztest;
|
||||
break;
|
||||
}
|
||||
else if (ztesttarget > ztarget)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
z = ztest;
|
||||
}
|
||||
|
||||
if (iterationCount > maxIterations)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (found)
|
||||
break;
|
||||
|
||||
zstep *= 0.1f;
|
||||
}
|
||||
|
||||
float a = (u - r) / 2.0f / z;
|
||||
float p = (r + u - a * Mathf.Log((l + v - s) / (l - v + s))) / 2.0f;
|
||||
float q = (v + s - l * (float)Math.Cosh(z) / (float)Math.Sinh(z)) / 2.0f;
|
||||
|
||||
points = new Vector2[m_steps];
|
||||
float stepsf = m_steps - 1;
|
||||
float stepf;
|
||||
for (int i = 0; i < m_steps; i++)
|
||||
{
|
||||
stepf = i / stepsf;
|
||||
Vector2 pos = Vector2.zero;
|
||||
pos.x = Mathf.Lerp(start.x, end.x, stepf);
|
||||
pos.y = a * (float)Math.Cosh(((stepf * lineDistH) - p) / a) + q;
|
||||
points[i] = pos;
|
||||
}
|
||||
|
||||
m_regen = false;
|
||||
return points;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2444f085ab49ff24b888b175f46b55c7
|
||||
timeCreated: 1501871616
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/// <summary>
|
||||
/// Tool script taken from the UI source as it's set to Internal for some reason. So to use in the extensions project it is needed here also.
|
||||
/// </summary>
|
||||
///
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
internal static class SetPropertyUtility
|
||||
{
|
||||
public static bool SetColor(ref Color currentValue, Color newValue)
|
||||
{
|
||||
if (currentValue.r == newValue.r && currentValue.g == newValue.g && currentValue.b == newValue.b && currentValue.a == newValue.a)
|
||||
return false;
|
||||
|
||||
currentValue = newValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool SetStruct<T>(ref T currentValue, T newValue) where T: struct
|
||||
{
|
||||
if (currentValue.Equals(newValue))
|
||||
return false;
|
||||
|
||||
currentValue = newValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool SetClass<T>(ref T currentValue, T newValue) where T: class
|
||||
{
|
||||
if ((currentValue == null && newValue == null) || (currentValue != null && currentValue.Equals(newValue)))
|
||||
return false;
|
||||
|
||||
currentValue = newValue;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d373cce4b1f361a40a126bd74d26ebc9
|
||||
timeCreated: 1440851864
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue