Merged UnityUIExtensions/unity-ui-extensions into master
commit
3b6339f67d
|
@ -32,3 +32,4 @@ sysinfo.txt
|
|||
# Builds
|
||||
*.apk
|
||||
*.unitypackage
|
||||
/.vs
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace UnityEngine.UI.Extensions.ColorPicker
|
||||
{
|
||||
[CustomEditor(typeof(ColorPickerPresets))]
|
||||
public class ColorPickerPresetsEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
base.OnInspectorGUI();
|
||||
|
||||
var colorPickerPresets = (ColorPickerPresets)target;
|
||||
if (colorPickerPresets.saveMode != ColorPickerPresets.SaveType.JsonFile)
|
||||
return;
|
||||
|
||||
string fileLocation = colorPickerPresets.JsonFilePath;
|
||||
|
||||
if (!System.IO.File.Exists(fileLocation))
|
||||
return;
|
||||
|
||||
if (GUILayout.Button("Open JSON file."))
|
||||
{
|
||||
Application.OpenURL(fileLocation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0dc729b738fb01043ac4c04b78575a98
|
||||
timeCreated: 1520733906
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
|
@ -1,8 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 53b194f66900add419869c57ffbe7b85
|
||||
timeCreated: 1480025159
|
||||
timeCreated: 1519012868
|
||||
licenseType: Pro
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 100100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
After Width: | Height: | Size: 691 B |
|
@ -0,0 +1,117 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b2ef02fbd2da4554ebbac497ca14bb8d
|
||||
timeCreated: 1519009670
|
||||
licenseType: Pro
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
externalObjects: {}
|
||||
serializedVersion: 4
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: -1
|
||||
aniso: -1
|
||||
mipBias: -1
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: -1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 1
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 100
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 8
|
||||
textureShape: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
platformSettings:
|
||||
- buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- buildTarget: iPhone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- buildTarget: Windows Store Apps
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
spritePackingTag:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
|
@ -150,8 +150,8 @@ RectTransform:
|
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
m_AnchorMin: {x: 0, y: 0}
|
||||
m_AnchorMax: {x: 1, y: 1}
|
||||
m_AnchoredPosition: {x: 225.10002, y: -99.100006}
|
||||
m_SizeDelta: {x: -496.4, y: -233.4}
|
||||
m_AnchoredPosition: {x: 298, y: -155.1}
|
||||
m_SizeDelta: {x: -642.3, y: -345.4}
|
||||
m_Pivot: {x: 0.5, y: 0.5}
|
||||
--- !u!114 &2641525
|
||||
MonoBehaviour:
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 65272187a39b1a64cb82bb9a55cdb703
|
||||
folderAsset: yes
|
||||
timeCreated: 1521741350
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6de6e08d11a51d14c97c4f7c647a1fca
|
||||
timeCreated: 1521741378
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,10 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a7296bad073428c4796089b44a48cab9
|
||||
folderAsset: yes
|
||||
timeCreated: 1521742084
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,69 +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
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,38 +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
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,257 +1,303 @@
|
|||
///Credit judah4
|
||||
///Credit judah4
|
||||
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UnityEngine.UI.Extensions.ColorPicker
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
public class ColorPickerControl : MonoBehaviour
|
||||
{
|
||||
private float _hue = 0;
|
||||
private float _saturation = 0;
|
||||
private float _brightness = 0;
|
||||
|
||||
public class ColorPickerControl : MonoBehaviour
|
||||
{
|
||||
private float _hue = 0;
|
||||
private float _saturation = 0;
|
||||
private float _brightness = 0;
|
||||
private float _red = 0;
|
||||
private float _green = 0;
|
||||
private float _blue = 0;
|
||||
|
||||
private float _red = 0;
|
||||
private float _green = 0;
|
||||
private float _blue = 0;
|
||||
private float _alpha = 1;
|
||||
|
||||
private float _alpha = 1;
|
||||
public ColorChangedEvent onValueChanged = new ColorChangedEvent();
|
||||
public HSVChangedEvent onHSVChanged = new HSVChangedEvent();
|
||||
|
||||
public ColorChangedEvent onValueChanged = new ColorChangedEvent();
|
||||
public HSVChangedEvent onHSVChanged = new HSVChangedEvent();
|
||||
[SerializeField]
|
||||
bool hsvSlidersOn = true;
|
||||
|
||||
public Color CurrentColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Color(_red, _green, _blue, _alpha);
|
||||
}
|
||||
set
|
||||
{
|
||||
if (CurrentColor == value)
|
||||
return;
|
||||
[SerializeField]
|
||||
List<GameObject> hsvSliders = new List<GameObject>();
|
||||
|
||||
_red = value.r;
|
||||
_green = value.g;
|
||||
_blue = value.b;
|
||||
_alpha = value.a;
|
||||
[SerializeField]
|
||||
bool rgbSlidersOn = true;
|
||||
|
||||
RGBChanged();
|
||||
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
[SerializeField]
|
||||
List<GameObject> rgbSliders = new List<GameObject>();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SendChangedEvent();
|
||||
}
|
||||
[SerializeField]
|
||||
GameObject alphaSlider;
|
||||
|
||||
public float H
|
||||
{
|
||||
get
|
||||
{
|
||||
return _hue;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_hue == value)
|
||||
return;
|
||||
public void SetHSVSlidersOn(bool value)
|
||||
{
|
||||
hsvSlidersOn = value;
|
||||
|
||||
_hue = value;
|
||||
foreach (var item in hsvSliders)
|
||||
item.SetActive(value);
|
||||
|
||||
HSVChanged();
|
||||
if (alphaSlider)
|
||||
alphaSlider.SetActive(hsvSlidersOn || rgbSlidersOn);
|
||||
}
|
||||
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
public void SetRGBSlidersOn(bool value)
|
||||
{
|
||||
rgbSlidersOn = value;
|
||||
foreach (var item in rgbSliders)
|
||||
item.SetActive(value);
|
||||
|
||||
public float S
|
||||
{
|
||||
get
|
||||
{
|
||||
return _saturation;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_saturation == value)
|
||||
return;
|
||||
if (alphaSlider)
|
||||
alphaSlider.SetActive(hsvSlidersOn || rgbSlidersOn);
|
||||
}
|
||||
|
||||
_saturation = value;
|
||||
|
||||
HSVChanged();
|
||||
void Update()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
SetHSVSlidersOn(hsvSlidersOn);
|
||||
SetRGBSlidersOn(rgbSlidersOn);
|
||||
#endif
|
||||
}
|
||||
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
public Color CurrentColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Color(_red, _green, _blue, _alpha);
|
||||
}
|
||||
set
|
||||
{
|
||||
if (CurrentColor == value)
|
||||
return;
|
||||
|
||||
public float V
|
||||
{
|
||||
get
|
||||
{
|
||||
return _brightness;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_brightness == value)
|
||||
return;
|
||||
_red = value.r;
|
||||
_green = value.g;
|
||||
_blue = value.b;
|
||||
_alpha = value.a;
|
||||
|
||||
_brightness = value;
|
||||
RGBChanged();
|
||||
|
||||
HSVChanged();
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
SendChangedEvent();
|
||||
}
|
||||
|
||||
public float R
|
||||
{
|
||||
get
|
||||
{
|
||||
return _red;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_red == value)
|
||||
return;
|
||||
public float H
|
||||
{
|
||||
get
|
||||
{
|
||||
return _hue;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_hue == value)
|
||||
return;
|
||||
|
||||
_red = value;
|
||||
_hue = value;
|
||||
|
||||
RGBChanged();
|
||||
HSVChanged();
|
||||
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
public float G
|
||||
{
|
||||
get
|
||||
{
|
||||
return _green;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_green == value)
|
||||
return;
|
||||
public float S
|
||||
{
|
||||
get
|
||||
{
|
||||
return _saturation;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_saturation == value)
|
||||
return;
|
||||
|
||||
_green = value;
|
||||
_saturation = value;
|
||||
|
||||
RGBChanged();
|
||||
HSVChanged();
|
||||
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
public float B
|
||||
{
|
||||
get
|
||||
{
|
||||
return _blue;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_blue == value)
|
||||
return;
|
||||
public float V
|
||||
{
|
||||
get
|
||||
{
|
||||
return _brightness;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_brightness == value)
|
||||
return;
|
||||
|
||||
_blue = value;
|
||||
_brightness = value;
|
||||
|
||||
RGBChanged();
|
||||
HSVChanged();
|
||||
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
private float A
|
||||
{
|
||||
get
|
||||
{
|
||||
return _alpha;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_alpha == value)
|
||||
return;
|
||||
public float R
|
||||
{
|
||||
get
|
||||
{
|
||||
return _red;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_red == value)
|
||||
return;
|
||||
|
||||
_alpha = value;
|
||||
_red = value;
|
||||
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
RGBChanged();
|
||||
|
||||
private void RGBChanged()
|
||||
{
|
||||
HsvColor color = HSVUtil.ConvertRgbToHsv(CurrentColor);
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
_hue = color.NormalizedH;
|
||||
_saturation = color.NormalizedS;
|
||||
_brightness = color.NormalizedV;
|
||||
}
|
||||
public float G
|
||||
{
|
||||
get
|
||||
{
|
||||
return _green;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_green == value)
|
||||
return;
|
||||
|
||||
private void HSVChanged()
|
||||
{
|
||||
Color color = HSVUtil.ConvertHsvToRgb(_hue * 360, _saturation, _brightness, _alpha);
|
||||
_green = value;
|
||||
|
||||
_red = color.r;
|
||||
_green = color.g;
|
||||
_blue = color.b;
|
||||
}
|
||||
RGBChanged();
|
||||
|
||||
private void SendChangedEvent()
|
||||
{
|
||||
onValueChanged.Invoke(CurrentColor);
|
||||
onHSVChanged.Invoke(_hue, _saturation, _brightness);
|
||||
}
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
public void AssignColor(ColorValues type, float value)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ColorValues.R:
|
||||
R = value;
|
||||
break;
|
||||
case ColorValues.G:
|
||||
G = value;
|
||||
break;
|
||||
case ColorValues.B:
|
||||
B = value;
|
||||
break;
|
||||
case ColorValues.A:
|
||||
A = value;
|
||||
break;
|
||||
case ColorValues.Hue:
|
||||
H = value;
|
||||
break;
|
||||
case ColorValues.Saturation:
|
||||
S = value;
|
||||
break;
|
||||
case ColorValues.Value:
|
||||
V = value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
public float B
|
||||
{
|
||||
get
|
||||
{
|
||||
return _blue;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_blue == value)
|
||||
return;
|
||||
|
||||
public float GetValue(ColorValues type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ColorValues.R:
|
||||
return R;
|
||||
case ColorValues.G:
|
||||
return G;
|
||||
case ColorValues.B:
|
||||
return B;
|
||||
case ColorValues.A:
|
||||
return A;
|
||||
case ColorValues.Hue:
|
||||
return H;
|
||||
case ColorValues.Saturation:
|
||||
return S;
|
||||
case ColorValues.Value:
|
||||
return V;
|
||||
default:
|
||||
throw new System.NotImplementedException("");
|
||||
}
|
||||
}
|
||||
}
|
||||
_blue = value;
|
||||
|
||||
RGBChanged();
|
||||
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
private float A
|
||||
{
|
||||
get
|
||||
{
|
||||
return _alpha;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_alpha == value)
|
||||
return;
|
||||
|
||||
_alpha = value;
|
||||
|
||||
SendChangedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
private void RGBChanged()
|
||||
{
|
||||
HsvColor color = HSVUtil.ConvertRgbToHsv(CurrentColor);
|
||||
|
||||
_hue = color.NormalizedH;
|
||||
_saturation = color.NormalizedS;
|
||||
_brightness = color.NormalizedV;
|
||||
}
|
||||
|
||||
private void HSVChanged()
|
||||
{
|
||||
Color color = HSVUtil.ConvertHsvToRgb(_hue * 360, _saturation, _brightness, _alpha);
|
||||
|
||||
_red = color.r;
|
||||
_green = color.g;
|
||||
_blue = color.b;
|
||||
}
|
||||
|
||||
private void SendChangedEvent()
|
||||
{
|
||||
onValueChanged.Invoke(CurrentColor);
|
||||
onHSVChanged.Invoke(_hue, _saturation, _brightness);
|
||||
}
|
||||
|
||||
public void AssignColor(ColorValues type, float value)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ColorValues.R:
|
||||
R = value;
|
||||
break;
|
||||
case ColorValues.G:
|
||||
G = value;
|
||||
break;
|
||||
case ColorValues.B:
|
||||
B = value;
|
||||
break;
|
||||
case ColorValues.A:
|
||||
A = value;
|
||||
break;
|
||||
case ColorValues.Hue:
|
||||
H = value;
|
||||
break;
|
||||
case ColorValues.Saturation:
|
||||
S = value;
|
||||
break;
|
||||
case ColorValues.Value:
|
||||
V = value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public float GetValue(ColorValues type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ColorValues.R:
|
||||
return R;
|
||||
case ColorValues.G:
|
||||
return G;
|
||||
case ColorValues.B:
|
||||
return B;
|
||||
case ColorValues.A:
|
||||
return A;
|
||||
case ColorValues.Hue:
|
||||
return H;
|
||||
case ColorValues.Saturation:
|
||||
return S;
|
||||
case ColorValues.Value:
|
||||
return V;
|
||||
default:
|
||||
throw new System.NotImplementedException("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,48 +1,194 @@
|
|||
///Credit judah4
|
||||
///Credit judah4
|
||||
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UnityEngine.UI.Extensions.ColorPicker
|
||||
{
|
||||
public class ColorPickerPresets : MonoBehaviour
|
||||
{
|
||||
public ColorPickerControl picker;
|
||||
public GameObject[] presets;
|
||||
public Image createPresetImage;
|
||||
public class ColorPickerPresets : MonoBehaviour
|
||||
{
|
||||
public ColorPickerControl picker;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
// picker.onHSVChanged.AddListener(HSVChanged);
|
||||
picker.onValueChanged.AddListener(ColorChanged);
|
||||
}
|
||||
[SerializeField]
|
||||
protected GameObject presetPrefab;
|
||||
|
||||
public void CreatePresetButton()
|
||||
{
|
||||
for (var i = 0; i < presets.Length; i++)
|
||||
{
|
||||
if (!presets[i].activeSelf)
|
||||
{
|
||||
presets[i].SetActive(true);
|
||||
presets[i].GetComponent<Image>().color = picker.CurrentColor;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
[SerializeField]
|
||||
protected int maxPresets = 16;
|
||||
|
||||
public void PresetSelect(Image sender)
|
||||
{
|
||||
picker.CurrentColor = sender.color;
|
||||
}
|
||||
[SerializeField]
|
||||
protected Color[] predefinedPresets;
|
||||
|
||||
// Not working, it seems ConvertHsvToRgb() is broken. It doesn't work when fed
|
||||
// input h, s, v as shown below.
|
||||
// private void HSVChanged(float h, float s, float v)
|
||||
// {
|
||||
// createPresetImage.color = HSVUtil.ConvertHsvToRgb(h, s, v, 1);
|
||||
// }
|
||||
private void ColorChanged(Color color)
|
||||
{
|
||||
createPresetImage.color = color;
|
||||
}
|
||||
}
|
||||
protected List<Color> presets = new List<Color>();
|
||||
public Image createPresetImage;
|
||||
public Transform createButton;
|
||||
|
||||
public enum SaveType { None, PlayerPrefs, JsonFile }
|
||||
[SerializeField]
|
||||
public SaveType saveMode = SaveType.None;
|
||||
|
||||
[SerializeField]
|
||||
protected string playerPrefsKey;
|
||||
|
||||
public virtual string JsonFilePath
|
||||
{
|
||||
get { return Application.persistentDataPath + "/" + playerPrefsKey + ".json"; }
|
||||
}
|
||||
|
||||
protected virtual void Reset()
|
||||
{
|
||||
playerPrefsKey = "colorpicker_" + GetInstanceID().ToString();
|
||||
}
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
picker.onHSVChanged.AddListener(HSVChanged);
|
||||
picker.onValueChanged.AddListener(ColorChanged);
|
||||
picker.CurrentColor = Color.white;
|
||||
presetPrefab.SetActive(false);
|
||||
|
||||
presets.AddRange(predefinedPresets);
|
||||
LoadPresets(saveMode);
|
||||
}
|
||||
|
||||
public virtual void CreatePresetButton()
|
||||
{
|
||||
CreatePreset(picker.CurrentColor);
|
||||
}
|
||||
|
||||
public virtual void LoadPresets(SaveType saveType)
|
||||
{
|
||||
string jsonData = "";
|
||||
switch (saveType)
|
||||
{
|
||||
case SaveType.None:
|
||||
break;
|
||||
case SaveType.PlayerPrefs:
|
||||
if (PlayerPrefs.HasKey(playerPrefsKey))
|
||||
{
|
||||
jsonData = PlayerPrefs.GetString(playerPrefsKey);
|
||||
}
|
||||
break;
|
||||
case SaveType.JsonFile:
|
||||
if (System.IO.File.Exists(JsonFilePath))
|
||||
{
|
||||
jsonData = System.IO.File.ReadAllText(JsonFilePath);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new System.NotImplementedException(saveType.ToString());
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(jsonData))
|
||||
{
|
||||
try
|
||||
{
|
||||
var jsonColors = JsonUtility.FromJson<JsonColor>(jsonData);
|
||||
presets.AddRange(jsonColors.GetColors());
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in presets)
|
||||
{
|
||||
CreatePreset(item, true);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void SavePresets(SaveType saveType)
|
||||
{
|
||||
if (presets == null || presets.Count <= 0)
|
||||
{
|
||||
Debug.LogError(
|
||||
"presets cannot be null or empty: " + (presets == null ? "NULL" : "EMPTY"));
|
||||
return;
|
||||
}
|
||||
|
||||
var jsonColor = new JsonColor();
|
||||
jsonColor.SetColors(presets.ToArray());
|
||||
|
||||
|
||||
string jsonData = JsonUtility.ToJson(jsonColor);
|
||||
|
||||
switch (saveType)
|
||||
{
|
||||
case SaveType.None:
|
||||
Debug.LogWarning("Called SavePresets with SaveType = None...");
|
||||
break;
|
||||
case SaveType.PlayerPrefs:
|
||||
PlayerPrefs.SetString(playerPrefsKey, jsonData);
|
||||
break;
|
||||
case SaveType.JsonFile:
|
||||
System.IO.File.WriteAllText(JsonFilePath, jsonData);
|
||||
//Application.OpenURL(JsonFilePath);
|
||||
break;
|
||||
default:
|
||||
throw new System.NotImplementedException(saveType.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
protected class JsonColor
|
||||
{
|
||||
public Color32[] colors;
|
||||
public void SetColors(Color[] colorsIn)
|
||||
{
|
||||
this.colors = new Color32[colorsIn.Length];
|
||||
for (int i = 0; i < colorsIn.Length; i++)
|
||||
{
|
||||
this.colors[i] = colorsIn[i];
|
||||
}
|
||||
}
|
||||
|
||||
public Color[] GetColors()
|
||||
{
|
||||
Color[] colorsOut = new Color[colors.Length];
|
||||
for (int i = 0; i < colors.Length; i++)
|
||||
{
|
||||
colorsOut[i] = colors[i];
|
||||
}
|
||||
return colorsOut;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void CreatePreset(Color color, bool loading)
|
||||
{
|
||||
createButton.gameObject.SetActive(presets.Count < maxPresets);
|
||||
|
||||
var newPresetButton = Instantiate(presetPrefab, presetPrefab.transform.parent);
|
||||
newPresetButton.transform.SetAsLastSibling();
|
||||
newPresetButton.SetActive(true);
|
||||
newPresetButton.GetComponent<Image>().color = color;
|
||||
|
||||
createPresetImage.color = Color.white;
|
||||
|
||||
if (!loading)
|
||||
{
|
||||
presets.Add(color);
|
||||
SavePresets(saveMode);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void CreatePreset(Color color)
|
||||
{
|
||||
CreatePreset(color, false);
|
||||
}
|
||||
|
||||
public virtual void PresetSelect(Image sender)
|
||||
{
|
||||
picker.CurrentColor = sender.color;
|
||||
}
|
||||
|
||||
protected virtual void HSVChanged(float h, float s, float v)
|
||||
{
|
||||
createPresetImage.color = HSVUtil.ConvertHsvToRgb(h * 360, s, v, 1);
|
||||
//Debug.Log("hsv util color: " + createPresetImage.color);
|
||||
}
|
||||
|
||||
protected virtual void ColorChanged(Color color)
|
||||
{
|
||||
createPresetImage.color = color;
|
||||
//Debug.Log("color changed: " + color);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
namespace UnityEngine.UI.Extensions.ColorPicker
|
||||
{
|
||||
/// <summary>
|
||||
/// Samples colors from a screen capture.
|
||||
/// Warning! In the editor if you're not in Free aspect mode then
|
||||
/// the captured area includes the grey areas to the left and right of the game view window.
|
||||
/// In a build this will not be an issue.
|
||||
///
|
||||
/// This does not work well with a world space UI as positioning is working with screen space.
|
||||
/// </summary>
|
||||
public class ColorSampler : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
protected Button sampler;
|
||||
|
||||
[SerializeField]
|
||||
protected Outline samplerOutline;
|
||||
|
||||
protected Texture2D screenCapture;
|
||||
|
||||
public ColorChangedEvent oncolorSelected = new ColorChangedEvent();
|
||||
|
||||
protected Color color;
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
screenCapture = ScreenCapture.CaptureScreenshotAsTexture();
|
||||
sampler.gameObject.SetActive(true);
|
||||
sampler.onClick.AddListener(SelectColor);
|
||||
}
|
||||
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
Destroy(screenCapture);
|
||||
sampler.gameObject.SetActive(false);
|
||||
sampler.onClick.RemoveListener(SelectColor);
|
||||
}
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
if (screenCapture == null)
|
||||
return;
|
||||
|
||||
sampler.transform.position = Input.mousePosition;
|
||||
color = screenCapture.GetPixel((int)Input.mousePosition.x, (int)Input.mousePosition.y);
|
||||
|
||||
HandleSamplerColoring();
|
||||
}
|
||||
|
||||
protected virtual void HandleSamplerColoring()
|
||||
{
|
||||
sampler.image.color = color;
|
||||
|
||||
if (samplerOutline)
|
||||
{
|
||||
var c = Color.Lerp(Color.white, Color.black, color.grayscale > 0.5f ? 1 : 0);
|
||||
c.a = samplerOutline.effectColor.a;
|
||||
samplerOutline.effectColor = c;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void SelectColor()
|
||||
{
|
||||
if (oncolorSelected != null)
|
||||
oncolorSelected.Invoke(color);
|
||||
|
||||
enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 01c80b26fb6519c4ea3f410dc08f5814
|
||||
timeCreated: 1519007668
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -9,7 +9,7 @@ using UnityEngine.EventSystems;
|
|||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
[RequireComponent(typeof(RectTransform), typeof(LayoutElement))]
|
||||
public class ReorderableListElement : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
|
||||
{
|
||||
[Tooltip("Can this element be dragged?")]
|
||||
|
|
|
@ -15,17 +15,17 @@ using UnityEngine.EventSystems;
|
|||
/// - clampOutput01 - if true the output knobValue will be clamped between 0 and 1 regardless of number of loops.
|
||||
/// - snapToPosition - snap to step. NOTE: max value will override the step.
|
||||
/// - snapStepsPerLoop - how many snap positions are in one knob loop;
|
||||
/// - OnValueChanged - event that is called every frame while rotationg knob, sends <float> argument of knobValue
|
||||
/// - OnValueChanged - event that is called every frame while rotating knob, sends <float> argument of knobValue
|
||||
/// NOTES
|
||||
/// - script works only in images rotation on Z axis;
|
||||
/// - while dragging outside of control, the rotation will be cancelled
|
||||
/// - while dragging outside of control, the rotation will be canceled
|
||||
/// </summary>
|
||||
///
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
[RequireComponent(typeof(Image))]
|
||||
[AddComponentMenu("UI/Extensions/UI_Knob")]
|
||||
public class UI_Knob : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, IBeginDragHandler, IDragHandler
|
||||
public class UI_Knob : Selectable, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, IDragHandler, IInitializePotentialDragHandler
|
||||
{
|
||||
public enum Direction { CW, CCW };
|
||||
[Tooltip("Direction of rotation CW - clockwise, CCW - counterClockwise")]
|
||||
|
@ -36,7 +36,7 @@ namespace UnityEngine.UI.Extensions
|
|||
public float maxValue = 0;
|
||||
[Tooltip("How many rotations knob can do, if higher than max value, the latter will limit max value")]
|
||||
public int loops = 1;
|
||||
[Tooltip("Clamp output value between 0 and 1, usefull with loops > 1")]
|
||||
[Tooltip("Clamp output value between 0 and 1, useful with loops > 1")]
|
||||
public bool clampOutput01 = false;
|
||||
[Tooltip("snap to position?")]
|
||||
public bool snapToPosition = false;
|
||||
|
@ -51,43 +51,65 @@ namespace UnityEngine.UI.Extensions
|
|||
private Vector2 _currentVector;
|
||||
private Quaternion _initRotation;
|
||||
private bool _canDrag = false;
|
||||
[SerializeField]
|
||||
private bool experimental = false;
|
||||
|
||||
//ONLY ALLOW ROTATION WITH POINTER OVER THE CONTROL
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
private RectTransform m_HandleRect;
|
||||
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
_canDrag = true;
|
||||
m_HandleRect = GetComponent<RectTransform>();
|
||||
}
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
|
||||
public override void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
_canDrag = false;
|
||||
}
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
public override void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
_canDrag = true;
|
||||
}
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
public override void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
_canDrag = false;
|
||||
}
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
SetInitPointerData(eventData);
|
||||
}
|
||||
void SetInitPointerData(PointerEventData eventData)
|
||||
|
||||
|
||||
public override void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
_canDrag = true;
|
||||
|
||||
base.OnPointerDown(eventData);
|
||||
|
||||
_initRotation = transform.rotation;
|
||||
_currentVector = eventData.position - (Vector2)transform.position;
|
||||
if (experimental)
|
||||
{
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(m_HandleRect, eventData.position, eventData.pressEventCamera, out _currentVector);
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentVector = eventData.position - (Vector2)transform.position;
|
||||
}
|
||||
_initAngle = Mathf.Atan2(_currentVector.y, _currentVector.x) * Mathf.Rad2Deg;
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
//CHECK IF CAN DRAG
|
||||
if (!_canDrag)
|
||||
{
|
||||
SetInitPointerData(eventData);
|
||||
return;
|
||||
}
|
||||
_currentVector = eventData.position - (Vector2)transform.position;
|
||||
|
||||
if (experimental)
|
||||
{
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(m_HandleRect, eventData.position, eventData.pressEventCamera, out _currentVector);
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentVector = eventData.position - (Vector2)transform.position;
|
||||
}
|
||||
_currentAngle = Mathf.Atan2(_currentVector.y, _currentVector.x) * Mathf.Rad2Deg;
|
||||
|
||||
Quaternion addRotation = Quaternion.AngleAxis(_currentAngle - _initAngle, this.transform.forward);
|
||||
|
@ -133,7 +155,6 @@ namespace UnityEngine.UI.Extensions
|
|||
{
|
||||
knobValue = 0;
|
||||
transform.localEulerAngles = Vector3.zero;
|
||||
SetInitPointerData(eventData);
|
||||
InvokeEvents(knobValue + _currentLoops);
|
||||
return;
|
||||
}
|
||||
|
@ -141,7 +162,6 @@ namespace UnityEngine.UI.Extensions
|
|||
{
|
||||
knobValue = 1;
|
||||
transform.localEulerAngles = Vector3.zero;
|
||||
SetInitPointerData(eventData);
|
||||
InvokeEvents(knobValue + _currentLoops);
|
||||
return;
|
||||
}
|
||||
|
@ -156,7 +176,6 @@ namespace UnityEngine.UI.Extensions
|
|||
knobValue = maxValue;
|
||||
float maxAngle = direction == Direction.CW ? 360f - 360f * maxValue : 360f * maxValue;
|
||||
transform.localEulerAngles = new Vector3(0, 0, maxAngle);
|
||||
SetInitPointerData(eventData);
|
||||
InvokeEvents(knobValue);
|
||||
return;
|
||||
}
|
||||
|
@ -179,6 +198,11 @@ namespace UnityEngine.UI.Extensions
|
|||
value /= loops;
|
||||
OnValueChanged.Invoke(value);
|
||||
}
|
||||
|
||||
public virtual void OnInitializePotentialDrag(PointerEventData eventData)
|
||||
{
|
||||
eventData.useDragThreshold = false;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
|
|
|
@ -239,16 +239,30 @@ namespace UnityEngine.UI.Extensions
|
|||
if (_scroll_rect.horizontal)
|
||||
{
|
||||
var distance = Vector3.Distance(_startPosition, _screensContainer.localPosition);
|
||||
if (UseFastSwipe && distance < panelDimensions.width && distance >= FastSwipeThreshold)
|
||||
if ((UseFastSwipe && distance < panelDimensions.width && distance >= FastSwipeThreshold) || UseHardSwipe)
|
||||
{
|
||||
_scroll_rect.velocity = Vector3.zero;
|
||||
if (_startPosition.x - _screensContainer.localPosition.x > 0)
|
||||
{
|
||||
NextScreen();
|
||||
if (_startPosition.x - _screensContainer.localPosition.x > _childSize / 3)
|
||||
{
|
||||
ScrollToClosestElement();
|
||||
}
|
||||
else
|
||||
{
|
||||
NextScreen();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PreviousScreen();
|
||||
if (_startPosition.x - _screensContainer.localPosition.x > -_childSize / 3)
|
||||
{
|
||||
ScrollToClosestElement();
|
||||
}
|
||||
else
|
||||
{
|
||||
PreviousScreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace UnityEngine.UI.Extensions
|
|||
internal int _previousPage;
|
||||
internal int _halfNoVisibleItems;
|
||||
internal bool _moveStarted;
|
||||
internal bool _isInfinate; // Is a UI Infinate scroller attached to the control
|
||||
internal bool _isInfinate; // Is a UI Infinite scroller attached to the control
|
||||
internal int _infiniteWindow; // The infinite window the control is in
|
||||
internal float _infiniteOffset; // How much to offset a repositioning
|
||||
private int _bottomItem, _topItem;
|
||||
|
@ -64,6 +64,9 @@ namespace UnityEngine.UI.Extensions
|
|||
[Tooltip("Transition speed between pages. (optional)")]
|
||||
public float transitionSpeed = 7.5f;
|
||||
|
||||
[Tooltip("Hard Swipe forces to swiping to the next / previous page (optional)")]
|
||||
public Boolean UseHardSwipe = false;
|
||||
|
||||
[Tooltip("Fast Swipe makes swiping page next / previous (optional)")]
|
||||
public Boolean UseFastSwipe = false;
|
||||
|
||||
|
@ -76,7 +79,7 @@ namespace UnityEngine.UI.Extensions
|
|||
[Tooltip("The visible bounds area, controls which items are visible/enabled. *Note Should use a RectMask. (optional)")]
|
||||
public RectTransform MaskArea;
|
||||
|
||||
[Tooltip("Pixel size to buffer arround Mask Area. (optional)")]
|
||||
[Tooltip("Pixel size to buffer around Mask Area. (optional)")]
|
||||
public float MaskBuffer = 1;
|
||||
|
||||
public int CurrentPage
|
||||
|
@ -90,7 +93,7 @@ namespace UnityEngine.UI.Extensions
|
|||
{
|
||||
if (_isInfinate)
|
||||
{
|
||||
//Work out which infinate window we are in
|
||||
//Work out which infinite window we are in
|
||||
_infiniteWindow = value / _screensContainer.childCount;
|
||||
//Invert the value if negative and differentiate from Window 0
|
||||
_infiniteWindow = value < 0 ? (-_infiniteWindow) + 1 : _infiniteWindow;
|
||||
|
@ -417,7 +420,7 @@ namespace UnityEngine.UI.Extensions
|
|||
/// <param name="targetScreen"></param>
|
||||
private void ToggleNavigationButtons(int targetScreen)
|
||||
{
|
||||
//Ifthis is using an Infinate Scoll, then don't disable
|
||||
//If this is using an Infinite Scroll, then don't disable
|
||||
if (!_isInfinate)
|
||||
{
|
||||
if (PrevButton)
|
||||
|
@ -509,7 +512,7 @@ namespace UnityEngine.UI.Extensions
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Transform of the Currentpage
|
||||
/// Returns the Transform of the Current page
|
||||
/// </summary>
|
||||
/// <returns>Currently selected Page Transform</returns>
|
||||
public Transform CurrentPageObject()
|
||||
|
@ -518,7 +521,7 @@ namespace UnityEngine.UI.Extensions
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Transform of the Currentpage in an out param for performance
|
||||
/// Returns the Transform of the Current page in an out parameter for performance
|
||||
/// </summary>
|
||||
/// <param name="returnObject">Currently selected Page Transform</param>
|
||||
public void CurrentPageObject(out Transform returnObject)
|
||||
|
|
|
@ -239,16 +239,30 @@ namespace UnityEngine.UI.Extensions
|
|||
if (_scroll_rect.vertical)
|
||||
{
|
||||
var distance = Vector3.Distance(_startPosition, _screensContainer.localPosition);
|
||||
if (UseFastSwipe && distance < panelDimensions.height + FastSwipeThreshold && distance >=1f)
|
||||
if ((UseFastSwipe && distance < panelDimensions.height + FastSwipeThreshold && distance >=1f) || UseHardSwipe)
|
||||
{
|
||||
_scroll_rect.velocity = Vector3.zero;
|
||||
if (_startPosition.y - _screensContainer.localPosition.y > 0)
|
||||
{
|
||||
NextScreen();
|
||||
if (_startPosition.y - _screensContainer.localPosition.y > _childSize / 3)
|
||||
{
|
||||
ScrollToClosestElement();
|
||||
}
|
||||
else
|
||||
{
|
||||
NextScreen();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PreviousScreen();
|
||||
if (_startPosition.y - _screensContainer.localPosition.y > -_childSize / 3)
|
||||
{
|
||||
ScrollToClosestElement();
|
||||
}
|
||||
else
|
||||
{
|
||||
PreviousScreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue