Merged UnityUIExtensions/unity-ui-extensions into master
commit
3b6339f67d
|
@ -32,3 +32,4 @@ sysinfo.txt
|
||||||
# Builds
|
# Builds
|
||||||
*.apk
|
*.apk
|
||||||
*.unitypackage
|
*.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
|
fileFormatVersion: 2
|
||||||
guid: 53b194f66900add419869c57ffbe7b85
|
guid: 53b194f66900add419869c57ffbe7b85
|
||||||
timeCreated: 1480025159
|
timeCreated: 1519012868
|
||||||
licenseType: Pro
|
licenseType: Pro
|
||||||
NativeFormatImporter:
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 100100000
|
||||||
userData:
|
userData:
|
||||||
assetBundleName:
|
assetBundleName:
|
||||||
assetBundleVariant:
|
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_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
m_AnchorMin: {x: 0, y: 0}
|
m_AnchorMin: {x: 0, y: 0}
|
||||||
m_AnchorMax: {x: 1, y: 1}
|
m_AnchorMax: {x: 1, y: 1}
|
||||||
m_AnchoredPosition: {x: 225.10002, y: -99.100006}
|
m_AnchoredPosition: {x: 298, y: -155.1}
|
||||||
m_SizeDelta: {x: -496.4, y: -233.4}
|
m_SizeDelta: {x: -642.3, y: -345.4}
|
||||||
m_Pivot: {x: 0.5, y: 0.5}
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
--- !u!114 &2641525
|
--- !u!114 &2641525
|
||||||
MonoBehaviour:
|
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,11 +1,12 @@
|
||||||
///Credit judah4
|
///Credit judah4
|
||||||
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
|
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace UnityEngine.UI.Extensions.ColorPicker
|
namespace UnityEngine.UI.Extensions.ColorPicker
|
||||||
{
|
{
|
||||||
|
[ExecuteInEditMode]
|
||||||
public class ColorPickerControl : MonoBehaviour
|
public class ColorPickerControl : MonoBehaviour
|
||||||
{
|
{
|
||||||
private float _hue = 0;
|
private float _hue = 0;
|
||||||
private float _saturation = 0;
|
private float _saturation = 0;
|
||||||
private float _brightness = 0;
|
private float _brightness = 0;
|
||||||
|
@ -19,6 +20,51 @@ namespace UnityEngine.UI.Extensions.ColorPicker
|
||||||
public ColorChangedEvent onValueChanged = new ColorChangedEvent();
|
public ColorChangedEvent onValueChanged = new ColorChangedEvent();
|
||||||
public HSVChangedEvent onHSVChanged = new HSVChangedEvent();
|
public HSVChangedEvent onHSVChanged = new HSVChangedEvent();
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
bool hsvSlidersOn = true;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
List<GameObject> hsvSliders = new List<GameObject>();
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
bool rgbSlidersOn = true;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
List<GameObject> rgbSliders = new List<GameObject>();
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
GameObject alphaSlider;
|
||||||
|
|
||||||
|
public void SetHSVSlidersOn(bool value)
|
||||||
|
{
|
||||||
|
hsvSlidersOn = value;
|
||||||
|
|
||||||
|
foreach (var item in hsvSliders)
|
||||||
|
item.SetActive(value);
|
||||||
|
|
||||||
|
if (alphaSlider)
|
||||||
|
alphaSlider.SetActive(hsvSlidersOn || rgbSlidersOn);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetRGBSlidersOn(bool value)
|
||||||
|
{
|
||||||
|
rgbSlidersOn = value;
|
||||||
|
foreach (var item in rgbSliders)
|
||||||
|
item.SetActive(value);
|
||||||
|
|
||||||
|
if (alphaSlider)
|
||||||
|
alphaSlider.SetActive(hsvSlidersOn || rgbSlidersOn);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
SetHSVSlidersOn(hsvSlidersOn);
|
||||||
|
SetRGBSlidersOn(rgbSlidersOn);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
public Color CurrentColor
|
public Color CurrentColor
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -253,5 +299,5 @@ namespace UnityEngine.UI.Extensions.ColorPicker
|
||||||
throw new System.NotImplementedException("");
|
throw new System.NotImplementedException("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,48 +1,194 @@
|
||||||
///Credit judah4
|
///Credit judah4
|
||||||
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
|
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace UnityEngine.UI.Extensions.ColorPicker
|
namespace UnityEngine.UI.Extensions.ColorPicker
|
||||||
{
|
{
|
||||||
public class ColorPickerPresets : MonoBehaviour
|
public class ColorPickerPresets : MonoBehaviour
|
||||||
{
|
{
|
||||||
public ColorPickerControl picker;
|
public ColorPickerControl picker;
|
||||||
public GameObject[] presets;
|
|
||||||
|
[SerializeField]
|
||||||
|
protected GameObject presetPrefab;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
protected int maxPresets = 16;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
protected Color[] predefinedPresets;
|
||||||
|
|
||||||
|
protected List<Color> presets = new List<Color>();
|
||||||
public Image createPresetImage;
|
public Image createPresetImage;
|
||||||
|
public Transform createButton;
|
||||||
|
|
||||||
void Awake()
|
public enum SaveType { None, PlayerPrefs, JsonFile }
|
||||||
|
[SerializeField]
|
||||||
|
public SaveType saveMode = SaveType.None;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
protected string playerPrefsKey;
|
||||||
|
|
||||||
|
public virtual string JsonFilePath
|
||||||
{
|
{
|
||||||
// picker.onHSVChanged.AddListener(HSVChanged);
|
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.onValueChanged.AddListener(ColorChanged);
|
||||||
|
picker.CurrentColor = Color.white;
|
||||||
|
presetPrefab.SetActive(false);
|
||||||
|
|
||||||
|
presets.AddRange(predefinedPresets);
|
||||||
|
LoadPresets(saveMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CreatePresetButton()
|
public virtual void CreatePresetButton()
|
||||||
{
|
{
|
||||||
for (var i = 0; i < presets.Length; i++)
|
CreatePreset(picker.CurrentColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void LoadPresets(SaveType saveType)
|
||||||
{
|
{
|
||||||
if (!presets[i].activeSelf)
|
string jsonData = "";
|
||||||
|
switch (saveType)
|
||||||
{
|
{
|
||||||
presets[i].SetActive(true);
|
case SaveType.None:
|
||||||
presets[i].GetComponent<Image>().color = picker.CurrentColor;
|
|
||||||
break;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PresetSelect(Image sender)
|
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;
|
picker.CurrentColor = sender.color;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not working, it seems ConvertHsvToRgb() is broken. It doesn't work when fed
|
protected virtual void HSVChanged(float h, float s, float v)
|
||||||
// input h, s, v as shown below.
|
{
|
||||||
// private void HSVChanged(float h, float s, float v)
|
createPresetImage.color = HSVUtil.ConvertHsvToRgb(h * 360, s, v, 1);
|
||||||
// {
|
//Debug.Log("hsv util color: " + createPresetImage.color);
|
||||||
// createPresetImage.color = HSVUtil.ConvertHsvToRgb(h, s, v, 1);
|
}
|
||||||
// }
|
|
||||||
private void ColorChanged(Color color)
|
protected virtual void ColorChanged(Color color)
|
||||||
{
|
{
|
||||||
createPresetImage.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
|
namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
|
|
||||||
[RequireComponent(typeof(RectTransform))]
|
[RequireComponent(typeof(RectTransform), typeof(LayoutElement))]
|
||||||
public class ReorderableListElement : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
|
public class ReorderableListElement : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
|
||||||
{
|
{
|
||||||
[Tooltip("Can this element be dragged?")]
|
[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.
|
/// - 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.
|
/// - snapToPosition - snap to step. NOTE: max value will override the step.
|
||||||
/// - snapStepsPerLoop - how many snap positions are in one knob loop;
|
/// - 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
|
/// NOTES
|
||||||
/// - script works only in images rotation on Z axis;
|
/// - 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>
|
/// </summary>
|
||||||
///
|
///
|
||||||
namespace UnityEngine.UI.Extensions
|
namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
[RequireComponent(typeof(Image))]
|
[RequireComponent(typeof(Image))]
|
||||||
[AddComponentMenu("UI/Extensions/UI_Knob")]
|
[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 };
|
public enum Direction { CW, CCW };
|
||||||
[Tooltip("Direction of rotation CW - clockwise, CCW - counterClockwise")]
|
[Tooltip("Direction of rotation CW - clockwise, CCW - counterClockwise")]
|
||||||
|
@ -36,7 +36,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
public float maxValue = 0;
|
public float maxValue = 0;
|
||||||
[Tooltip("How many rotations knob can do, if higher than max value, the latter will limit max value")]
|
[Tooltip("How many rotations knob can do, if higher than max value, the latter will limit max value")]
|
||||||
public int loops = 1;
|
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;
|
public bool clampOutput01 = false;
|
||||||
[Tooltip("snap to position?")]
|
[Tooltip("snap to position?")]
|
||||||
public bool snapToPosition = false;
|
public bool snapToPosition = false;
|
||||||
|
@ -51,43 +51,65 @@ namespace UnityEngine.UI.Extensions
|
||||||
private Vector2 _currentVector;
|
private Vector2 _currentVector;
|
||||||
private Quaternion _initRotation;
|
private Quaternion _initRotation;
|
||||||
private bool _canDrag = false;
|
private bool _canDrag = false;
|
||||||
|
[SerializeField]
|
||||||
|
private bool experimental = false;
|
||||||
|
|
||||||
//ONLY ALLOW ROTATION WITH POINTER OVER THE CONTROL
|
private RectTransform m_HandleRect;
|
||||||
public void OnPointerDown(PointerEventData eventData)
|
|
||||||
|
|
||||||
|
protected override void Awake()
|
||||||
{
|
{
|
||||||
_canDrag = true;
|
m_HandleRect = GetComponent<RectTransform>();
|
||||||
}
|
}
|
||||||
public void OnPointerUp(PointerEventData eventData)
|
|
||||||
|
public override void OnPointerUp(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
_canDrag = false;
|
_canDrag = false;
|
||||||
}
|
}
|
||||||
public void OnPointerEnter(PointerEventData eventData)
|
public override void OnPointerEnter(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
_canDrag = true;
|
_canDrag = true;
|
||||||
}
|
}
|
||||||
public void OnPointerExit(PointerEventData eventData)
|
public override void OnPointerExit(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
_canDrag = false;
|
_canDrag = false;
|
||||||
}
|
}
|
||||||
public void OnBeginDrag(PointerEventData eventData)
|
|
||||||
{
|
|
||||||
SetInitPointerData(eventData);
|
public override void OnPointerDown(PointerEventData eventData)
|
||||||
}
|
|
||||||
void SetInitPointerData(PointerEventData eventData)
|
|
||||||
{
|
{
|
||||||
|
_canDrag = true;
|
||||||
|
|
||||||
|
base.OnPointerDown(eventData);
|
||||||
|
|
||||||
_initRotation = transform.rotation;
|
_initRotation = transform.rotation;
|
||||||
|
if (experimental)
|
||||||
|
{
|
||||||
|
RectTransformUtility.ScreenPointToLocalPointInRectangle(m_HandleRect, eventData.position, eventData.pressEventCamera, out _currentVector);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
_currentVector = eventData.position - (Vector2)transform.position;
|
_currentVector = eventData.position - (Vector2)transform.position;
|
||||||
|
}
|
||||||
_initAngle = Mathf.Atan2(_currentVector.y, _currentVector.x) * Mathf.Rad2Deg;
|
_initAngle = Mathf.Atan2(_currentVector.y, _currentVector.x) * Mathf.Rad2Deg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnDrag(PointerEventData eventData)
|
public void OnDrag(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
//CHECK IF CAN DRAG
|
//CHECK IF CAN DRAG
|
||||||
if (!_canDrag)
|
if (!_canDrag)
|
||||||
{
|
{
|
||||||
SetInitPointerData(eventData);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (experimental)
|
||||||
|
{
|
||||||
|
RectTransformUtility.ScreenPointToLocalPointInRectangle(m_HandleRect, eventData.position, eventData.pressEventCamera, out _currentVector);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
_currentVector = eventData.position - (Vector2)transform.position;
|
_currentVector = eventData.position - (Vector2)transform.position;
|
||||||
|
}
|
||||||
_currentAngle = Mathf.Atan2(_currentVector.y, _currentVector.x) * Mathf.Rad2Deg;
|
_currentAngle = Mathf.Atan2(_currentVector.y, _currentVector.x) * Mathf.Rad2Deg;
|
||||||
|
|
||||||
Quaternion addRotation = Quaternion.AngleAxis(_currentAngle - _initAngle, this.transform.forward);
|
Quaternion addRotation = Quaternion.AngleAxis(_currentAngle - _initAngle, this.transform.forward);
|
||||||
|
@ -133,7 +155,6 @@ namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
knobValue = 0;
|
knobValue = 0;
|
||||||
transform.localEulerAngles = Vector3.zero;
|
transform.localEulerAngles = Vector3.zero;
|
||||||
SetInitPointerData(eventData);
|
|
||||||
InvokeEvents(knobValue + _currentLoops);
|
InvokeEvents(knobValue + _currentLoops);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -141,7 +162,6 @@ namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
knobValue = 1;
|
knobValue = 1;
|
||||||
transform.localEulerAngles = Vector3.zero;
|
transform.localEulerAngles = Vector3.zero;
|
||||||
SetInitPointerData(eventData);
|
|
||||||
InvokeEvents(knobValue + _currentLoops);
|
InvokeEvents(knobValue + _currentLoops);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -156,7 +176,6 @@ namespace UnityEngine.UI.Extensions
|
||||||
knobValue = maxValue;
|
knobValue = maxValue;
|
||||||
float maxAngle = direction == Direction.CW ? 360f - 360f * maxValue : 360f * maxValue;
|
float maxAngle = direction == Direction.CW ? 360f - 360f * maxValue : 360f * maxValue;
|
||||||
transform.localEulerAngles = new Vector3(0, 0, maxAngle);
|
transform.localEulerAngles = new Vector3(0, 0, maxAngle);
|
||||||
SetInitPointerData(eventData);
|
|
||||||
InvokeEvents(knobValue);
|
InvokeEvents(knobValue);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -179,6 +198,11 @@ namespace UnityEngine.UI.Extensions
|
||||||
value /= loops;
|
value /= loops;
|
||||||
OnValueChanged.Invoke(value);
|
OnValueChanged.Invoke(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void OnInitializePotentialDrag(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
eventData.useDragThreshold = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
|
|
|
@ -239,13 +239,26 @@ namespace UnityEngine.UI.Extensions
|
||||||
if (_scroll_rect.horizontal)
|
if (_scroll_rect.horizontal)
|
||||||
{
|
{
|
||||||
var distance = Vector3.Distance(_startPosition, _screensContainer.localPosition);
|
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;
|
_scroll_rect.velocity = Vector3.zero;
|
||||||
if (_startPosition.x - _screensContainer.localPosition.x > 0)
|
if (_startPosition.x - _screensContainer.localPosition.x > 0)
|
||||||
|
{
|
||||||
|
if (_startPosition.x - _screensContainer.localPosition.x > _childSize / 3)
|
||||||
|
{
|
||||||
|
ScrollToClosestElement();
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
NextScreen();
|
NextScreen();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_startPosition.x - _screensContainer.localPosition.x > -_childSize / 3)
|
||||||
|
{
|
||||||
|
ScrollToClosestElement();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PreviousScreen();
|
PreviousScreen();
|
||||||
|
@ -253,6 +266,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -31,7 +31,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
internal int _previousPage;
|
internal int _previousPage;
|
||||||
internal int _halfNoVisibleItems;
|
internal int _halfNoVisibleItems;
|
||||||
internal bool _moveStarted;
|
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 int _infiniteWindow; // The infinite window the control is in
|
||||||
internal float _infiniteOffset; // How much to offset a repositioning
|
internal float _infiniteOffset; // How much to offset a repositioning
|
||||||
private int _bottomItem, _topItem;
|
private int _bottomItem, _topItem;
|
||||||
|
@ -64,6 +64,9 @@ namespace UnityEngine.UI.Extensions
|
||||||
[Tooltip("Transition speed between pages. (optional)")]
|
[Tooltip("Transition speed between pages. (optional)")]
|
||||||
public float transitionSpeed = 7.5f;
|
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)")]
|
[Tooltip("Fast Swipe makes swiping page next / previous (optional)")]
|
||||||
public Boolean UseFastSwipe = false;
|
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)")]
|
[Tooltip("The visible bounds area, controls which items are visible/enabled. *Note Should use a RectMask. (optional)")]
|
||||||
public RectTransform MaskArea;
|
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 float MaskBuffer = 1;
|
||||||
|
|
||||||
public int CurrentPage
|
public int CurrentPage
|
||||||
|
@ -90,7 +93,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
if (_isInfinate)
|
if (_isInfinate)
|
||||||
{
|
{
|
||||||
//Work out which infinate window we are in
|
//Work out which infinite window we are in
|
||||||
_infiniteWindow = value / _screensContainer.childCount;
|
_infiniteWindow = value / _screensContainer.childCount;
|
||||||
//Invert the value if negative and differentiate from Window 0
|
//Invert the value if negative and differentiate from Window 0
|
||||||
_infiniteWindow = value < 0 ? (-_infiniteWindow) + 1 : _infiniteWindow;
|
_infiniteWindow = value < 0 ? (-_infiniteWindow) + 1 : _infiniteWindow;
|
||||||
|
@ -417,7 +420,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
/// <param name="targetScreen"></param>
|
/// <param name="targetScreen"></param>
|
||||||
private void ToggleNavigationButtons(int targetScreen)
|
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 (!_isInfinate)
|
||||||
{
|
{
|
||||||
if (PrevButton)
|
if (PrevButton)
|
||||||
|
@ -509,7 +512,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the Transform of the Currentpage
|
/// Returns the Transform of the Current page
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Currently selected Page Transform</returns>
|
/// <returns>Currently selected Page Transform</returns>
|
||||||
public Transform CurrentPageObject()
|
public Transform CurrentPageObject()
|
||||||
|
@ -518,7 +521,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
/// <param name="returnObject">Currently selected Page Transform</param>
|
/// <param name="returnObject">Currently selected Page Transform</param>
|
||||||
public void CurrentPageObject(out Transform returnObject)
|
public void CurrentPageObject(out Transform returnObject)
|
||||||
|
|
|
@ -239,13 +239,26 @@ namespace UnityEngine.UI.Extensions
|
||||||
if (_scroll_rect.vertical)
|
if (_scroll_rect.vertical)
|
||||||
{
|
{
|
||||||
var distance = Vector3.Distance(_startPosition, _screensContainer.localPosition);
|
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;
|
_scroll_rect.velocity = Vector3.zero;
|
||||||
if (_startPosition.y - _screensContainer.localPosition.y > 0)
|
if (_startPosition.y - _screensContainer.localPosition.y > 0)
|
||||||
|
{
|
||||||
|
if (_startPosition.y - _screensContainer.localPosition.y > _childSize / 3)
|
||||||
|
{
|
||||||
|
ScrollToClosestElement();
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
NextScreen();
|
NextScreen();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_startPosition.y - _screensContainer.localPosition.y > -_childSize / 3)
|
||||||
|
{
|
||||||
|
ScrollToClosestElement();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PreviousScreen();
|
PreviousScreen();
|
||||||
|
@ -253,6 +266,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue