Initial Commit (broken due to version update)

This commit is contained in:
Reinier Vens 2020-09-25 07:12:38 +01:00
commit 3f7b3b7440
3132 changed files with 1103305 additions and 0 deletions

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: b95396d565a2a7f478b12f8b9648ed8f
folderAsset: yes
timeCreated: 1467468503
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,23 @@
///Credit ChoMPHi
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
using UnityEngine.UI.Extensions;
namespace UnityEditor.UI
{
[CustomEditor(typeof(AccordionElement), true)]
public class AccordionElementEditor : ToggleEditor {
public override void OnInspectorGUI()
{
this.serializedObject.Update();
EditorGUILayout.PropertyField(this.serializedObject.FindProperty("m_MinHeight"));
this.serializedObject.ApplyModifiedProperties();
base.serializedObject.Update();
EditorGUILayout.PropertyField(base.serializedObject.FindProperty("m_IsOn"));
EditorGUILayout.PropertyField(base.serializedObject.FindProperty("m_Interactable"));
base.serializedObject.ApplyModifiedProperties();
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8882b502b0c65b24ba4623d6a383815b
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,116 @@
/// Credit dakka
/// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1752415
/// Notes - Mod from Yilmaz Kiymaz's editor scripts presentation at Unite 2013
/// Updated ddreaper - removed Linq use, not required.
using UnityEditor;
namespace UnityEngine.UI.Extensions
{
public class CanvasGroupActivator : EditorWindow
{
[MenuItem("Window/UI/Extensions/Canvas Groups Activator")]
public static void InitWindow()
{
EditorWindow.GetWindow<CanvasGroupActivator>();
}
CanvasGroup[] canvasGroups;
void OnEnable()
{
ObtainCanvasGroups();
}
void OnFocus()
{
ObtainCanvasGroups();
}
void ObtainCanvasGroups()
{
canvasGroups = GameObject.FindObjectsOfType<CanvasGroup>();
}
void OnGUI()
{
if (canvasGroups == null)
{
return;
}
GUILayout.Space(10f);
GUILayout.Label("Canvas Groups");
for (int i = 0; i < canvasGroups.Length; i++)
{
if (canvasGroups[i] == null) { continue; }
bool initialActive = false;
if (canvasGroups[i].alpha == 1.0f)
initialActive = true;
bool active = EditorGUILayout.Toggle(canvasGroups[i].name, initialActive);
if (active != initialActive)
{
//If deactivated and initially active
if (!active && initialActive)
{
//Deactivate this
canvasGroups[i].alpha = 0f;
canvasGroups[i].interactable = false;
canvasGroups[i].blocksRaycasts = false;
}
//If activated and initially deactive
else if (active && !initialActive)
{
//Deactivate all others and activate this
HideAllGroups();
canvasGroups[i].alpha = 1.0f;
canvasGroups[i].interactable = true;
canvasGroups[i].blocksRaycasts = true;
}
}
}
GUILayout.Space(5f);
if (GUILayout.Button("Show All"))
{
ShowAllGroups();
}
if (GUILayout.Button("Hide All"))
{
HideAllGroups();
}
}
void ShowAllGroups()
{
foreach (var group in canvasGroups)
{
if (group != null)
{
group.alpha = 1.0f;
group.interactable = true;
group.blocksRaycasts = true;
}
}
}
void HideAllGroups()
{
foreach (var group in canvasGroups)
{
if (group != null)
{
group.alpha = 0;
group.interactable = false;
group.blocksRaycasts = false;
}
}
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f60a419e63d329f43ba1bf57e98b34bf
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,219 @@
#if UNITY_5_3_OR_NEWER
using NUnit.Framework;
using System;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using UnityEngine;
using UnityEngine.UI.Extensions;
public class CompressionTests {
[Test]
public void RandomGUIDCompressionTestLength()
{
string x = string.Empty;
using (var sequence = Enumerable.Range(1, 100).GetEnumerator())
{
while(sequence.MoveNext()) // string length 3600
{
x += Guid.NewGuid();
}
}
byte[] byteText = Encoding.Unicode.GetBytes(x);
var compressed = CLZF2.Compress(byteText);
var decompressed = CLZF2.Decompress(compressed);
Assert.AreEqual(byteText.Length, decompressed.Length);
}
[Test]
public void RandomGUIDCompressionTestBytes()
{
string x = string.Empty;
using (var sequence = Enumerable.Range(1, 100).GetEnumerator())
{
while (sequence.MoveNext()) // string length 3600
{
x += Guid.NewGuid();
}
}
byte[] byteText = Encoding.Unicode.GetBytes(x);
var compressed = CLZF2.Compress(byteText);
var decompressed = CLZF2.Decompress(compressed);
Assert.AreEqual(byteText, decompressed);
}
[Test]
public void RandomGUIDCompressionTestString()
{
string x = string.Empty;
using (var sequence = Enumerable.Range(1, 100).GetEnumerator())
{
while (sequence.MoveNext()) // string length 3600
{
x += Guid.NewGuid();
}
}
byte[] byteText = Encoding.Unicode.GetBytes(x);
var compressed = CLZF2.Compress(byteText);
var decompressed = CLZF2.Decompress(compressed);
var outString = Encoding.Unicode.GetString(decompressed);
Assert.AreEqual(outString, x);
}
[Test]
public void ThousandCharacterCompressionTest()
{
var x = new string('X', 10000);
byte[] byteText = Encoding.Unicode.GetBytes(x);
byte[] compressed = CLZF2.Compress(byteText);
byte[] decompressed = CLZF2.Decompress(compressed);
var outString = Encoding.Unicode.GetString(decompressed);
Assert.AreEqual(byteText.Length, decompressed.Length);
Assert.AreEqual(byteText, decompressed);
Assert.AreEqual(outString, x);
}
[Test]
public void LongFormattedStringCompressionTest()
{
string longstring = "defined input is deluciously delicious.14 And here and Nora called The reversal from ground from here and executed with touch the country road, Nora made of, reliance on, can’t publish the goals of grandeur, said to his book and encouraging an envelope, and enable entry into the chryssial shimmering of hers, so God of information in her hands Spiros sits down the sign of winter? —It’s kind of Spice Christ. It is one hundred birds circle above the text: They did we said. 69 percent dead. Sissy Cogan’s shadow. —Are you x then sings.) I’m 96 percent dead humanoid figure,";
byte[] byteText = Encoding.Unicode.GetBytes(longstring);
byte[] compressed = CLZF2.Compress(byteText);
byte[] decompressed = CLZF2.Decompress(compressed);
var outString = Encoding.Unicode.GetString(decompressed);
Assert.AreEqual(byteText.Length, decompressed.Length);
Assert.AreEqual(byteText, decompressed);
Assert.AreEqual(outString, longstring);
}
[Test]
public void SavingSimpleObject()
{
Vector3[] MySaveItem = new Vector3[1000];
for (int i = 0; i < MySaveItem.Length; i++)
{
MySaveItem[i] = Vector3.one * i;
}
var mySaveObject = ObjectToByteArray(MySaveItem);
byte[] compressed = CLZF2.Compress(mySaveObject);
byte[] decompressed = CLZF2.Decompress(compressed);
var outSaveObject = ObjectToByteArray<Vector3[]>(decompressed);
Assert.AreEqual(mySaveObject.Length, decompressed.Length);
Assert.AreEqual(mySaveObject, decompressed);
Assert.AreEqual(outSaveObject, MySaveItem);
}
[Test]
public void SavingComplexObject()
{
MyComplexObject[] MySaveItem = new MyComplexObject[1000];
for (int i = 0; i < MySaveItem.Length; i++)
{
var item = new MyComplexObject();
item.myPosition = Vector3.one * i;
item.myPositionHistory = new Vector3[100];
item.myChatHistory = new string[100];
for (int j = 0; j < 100; j++)
{
item.myPositionHistory[j] = Vector3.one * j;
item.myChatHistory[j] = "Chat line: " + j;
}
}
var mySaveObject = ObjectToByteArray(MySaveItem);
byte[] compressed = CLZF2.Compress(mySaveObject);
byte[] decompressed = CLZF2.Decompress(compressed);
var outSaveObject = ObjectToByteArray<MyComplexObject[]>(decompressed);
Assert.AreEqual(mySaveObject.Length, decompressed.Length);
Assert.AreEqual(mySaveObject, decompressed);
Assert.AreEqual(outSaveObject, MySaveItem);
}
[Serializable]
struct MyComplexObject
{
public Vector3 myPosition;
public Vector3[] myPositionHistory;
public string[] myChatHistory;
}
byte[] ObjectToByteArray(object obj)
{
if (obj == null)
return null;
BinaryFormatter bf = new BinaryFormatter();
// 1. Construct a SurrogateSelector object
SurrogateSelector ss = new SurrogateSelector();
// 2. Add the ISerializationSurrogates to our new SurrogateSelector
AddSurrogates(ref ss);
// 3. Have the formatter use our surrogate selector
bf.SurrogateSelector = ss;
using (MemoryStream ms = new MemoryStream())
{
bf.Serialize(ms, obj);
return ms.ToArray();
}
}
T ObjectToByteArray<T>(byte[] arrBytes)
{
if (arrBytes == null)
return default(T);
using (MemoryStream memStream = new MemoryStream())
{
BinaryFormatter bf = new BinaryFormatter();
// 1. Construct a SurrogateSelector object
SurrogateSelector ss = new SurrogateSelector();
// 2. Add the ISerializationSurrogates to our new SurrogateSelector
AddSurrogates(ref ss);
// 3. Have the formatter use our surrogate selector
bf.SurrogateSelector = ss;
memStream.Write(arrBytes, 0, arrBytes.Length);
memStream.Seek(0, SeekOrigin.Begin);
T obj = (T)bf.Deserialize(memStream);
return obj;
}
}
private static void AddSurrogates(ref SurrogateSelector ss)
{
Vector2Surrogate Vector2_SS = new Vector2Surrogate();
ss.AddSurrogate(typeof(Vector2),
new StreamingContext(StreamingContextStates.All),
Vector2_SS);
Vector3Surrogate Vector3_SS = new Vector3Surrogate();
ss.AddSurrogate(typeof(Vector3),
new StreamingContext(StreamingContextStates.All),
Vector3_SS);
Vector4Surrogate Vector4_SS = new Vector4Surrogate();
ss.AddSurrogate(typeof(Vector4),
new StreamingContext(StreamingContextStates.All),
Vector4_SS);
ColorSurrogate Color_SS = new ColorSurrogate();
ss.AddSurrogate(typeof(Color),
new StreamingContext(StreamingContextStates.All),
Color_SS);
QuaternionSurrogate Quaternion_SS = new QuaternionSurrogate();
ss.AddSurrogate(typeof(Quaternion),
new StreamingContext(StreamingContextStates.All),
Quaternion_SS);
}
}
#endif

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ff5c7cf8d5ccd284482327cd78debc20
timeCreated: 1464888738
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 9cac1e572d83dad488ea068b606f4033
folderAsset: yes
timeCreated: 1509646237
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 2379eab8e1f1c41d3a999c4eec534e4e
timeCreated: 18446744011573954816
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,215 @@
//C# Example
using UnityEditor;
using UnityEngine;
[ExecuteInEditMode]
public class Screenshot : EditorWindow
{
int resWidth = Screen.width*4;
int resHeight = Screen.height*4;
public Camera myCamera;
int scale = 1;
string path = "";
bool showPreview = true;
RenderTexture renderTexture;
bool isTransparent = false;
// Add menu item named "My Window" to the Window menu
[MenuItem("Tools/Saad Khawaja/Instant High-Res Screenshot")]
public static void ShowWindow()
{
//Show existing window instance. If one doesn't exist, make one.
EditorWindow editorWindow = EditorWindow.GetWindow(typeof(Screenshot));
editorWindow.autoRepaintOnSceneChange = true;
editorWindow.Show();
editorWindow.title = "Screenshot";
}
float lastTime;
void OnGUI()
{
EditorGUILayout.LabelField ("Resolution", EditorStyles.boldLabel);
resWidth = EditorGUILayout.IntField ("Width", resWidth);
resHeight = EditorGUILayout.IntField ("Height", resHeight);
EditorGUILayout.Space();
scale = EditorGUILayout.IntSlider ("Scale", scale, 1, 15);
EditorGUILayout.HelpBox("The default mode of screenshot is crop - so choose a proper width and height. The scale is a factor " +
"to multiply or enlarge the renders without loosing quality.",MessageType.None);
EditorGUILayout.Space();
GUILayout.Label ("Save Path", EditorStyles.boldLabel);
EditorGUILayout.BeginHorizontal();
EditorGUILayout.TextField(path,GUILayout.ExpandWidth(false));
if(GUILayout.Button("Browse",GUILayout.ExpandWidth(false)))
path = EditorUtility.SaveFolderPanel("Path to Save Images",path,Application.dataPath);
EditorGUILayout.EndHorizontal();
EditorGUILayout.HelpBox("Choose the folder in which to save the screenshots ",MessageType.None);
EditorGUILayout.Space();
//isTransparent = EditorGUILayout.Toggle(isTransparent,"Transparent Background");
GUILayout.Label ("Select Camera", EditorStyles.boldLabel);
myCamera = EditorGUILayout.ObjectField(myCamera, typeof(Camera), true,null) as Camera;
if(myCamera == null)
{
myCamera = Camera.main;
}
isTransparent = EditorGUILayout.Toggle("Transparent Background", isTransparent);
EditorGUILayout.HelpBox("Choose the camera of which to capture the render. You can make the background transparent using the transparency option.",MessageType.None);
EditorGUILayout.Space();
EditorGUILayout.BeginVertical();
EditorGUILayout.LabelField ("Default Options", EditorStyles.boldLabel);
if(GUILayout.Button("Set To Screen Size"))
{
resHeight = (int)Handles.GetMainGameViewSize().y;
resWidth = (int)Handles.GetMainGameViewSize().x;
}
if(GUILayout.Button("Default Size"))
{
resHeight = 1440;
resWidth = 2560;
scale = 1;
}
EditorGUILayout.EndVertical();
EditorGUILayout.Space();
EditorGUILayout.LabelField ("Screenshot will be taken at " + resWidth*scale + " x " + resHeight*scale + " px", EditorStyles.boldLabel);
if(GUILayout.Button("Take Screenshot",GUILayout.MinHeight(60)))
{
if(path == "")
{
path = EditorUtility.SaveFolderPanel("Path to Save Images",path,Application.dataPath);
Debug.Log("Path Set");
TakeHiResShot();
}
else
{
TakeHiResShot();
}
}
EditorGUILayout.Space();
EditorGUILayout.BeginHorizontal();
if(GUILayout.Button("Open Last Screenshot",GUILayout.MaxWidth(160),GUILayout.MinHeight(40)))
{
if(lastScreenshot != "")
{
Application.OpenURL("file://" + lastScreenshot);
Debug.Log("Opening File " + lastScreenshot);
}
}
if(GUILayout.Button("Open Folder",GUILayout.MaxWidth(100),GUILayout.MinHeight(40)))
{
Application.OpenURL("file://" + path);
}
if(GUILayout.Button("More Assets",GUILayout.MaxWidth(100),GUILayout.MinHeight(40)))
{
Application.OpenURL("https://www.assetstore.unity3d.com/en/#!/publisher/5951");
}
EditorGUILayout.EndHorizontal();
if (takeHiResShot)
{
int resWidthN = resWidth*scale;
int resHeightN = resHeight*scale;
RenderTexture rt = new RenderTexture(resWidthN, resHeightN, 24);
myCamera.targetTexture = rt;
TextureFormat tFormat;
if(isTransparent)
tFormat = TextureFormat.ARGB32;
else
tFormat = TextureFormat.RGB24;
Texture2D screenShot = new Texture2D(resWidthN, resHeightN, tFormat,false);
myCamera.Render();
RenderTexture.active = rt;
screenShot.ReadPixels(new Rect(0, 0, resWidthN, resHeightN), 0, 0);
myCamera.targetTexture = null;
RenderTexture.active = null;
byte[] bytes = screenShot.EncodeToPNG();
string filename = ScreenShotName(resWidthN, resHeightN);
System.IO.File.WriteAllBytes(filename, bytes);
Debug.Log(string.Format("Took screenshot to: {0}", filename));
Application.OpenURL(filename);
takeHiResShot = false;
}
EditorGUILayout.HelpBox("In case of any error, make sure you have Unity Pro as the plugin requires Unity Pro to work.",MessageType.Info);
}
private bool takeHiResShot = false;
public string lastScreenshot = "";
public string ScreenShotName(int width, int height) {
string strPath="";
strPath = string.Format("{0}/screen_{1}x{2}_{3}.png",
path,
width, height,
System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));
lastScreenshot = strPath;
return strPath;
}
public void TakeHiResShot() {
Debug.Log("Taking Screenshot");
takeHiResShot = true;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1f43438d3f4cd402f8f372cbb8930f66
timeCreated: 18446744011573954816
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,21 @@
/// Credit Slipp Douglas Thompson
/// Sourced from - https://gist.github.com/capnslipp/349c18283f2fea316369
///
using UnityEditor;
using UnityEditor.UI;
namespace UnityEngine.UI.Extensions
{
[CanEditMultipleObjects, CustomEditor(typeof(NonDrawingGraphic), false)]
public class NonDrawingGraphicEditor : GraphicEditor
{
public override void OnInspectorGUI()
{
base.serializedObject.Update();
EditorGUILayout.PropertyField(base.m_Script, new GUILayoutOption[0]);
// skipping AppearanceControlsGUI
base.RaycastControlsGUI();
base.serializedObject.ApplyModifiedProperties();
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ee2802949feca4c4c934331b6a0dc379
timeCreated: 1483566748
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,38 @@
/// Credit drobina, w34edrtfg, playemgames
/// Sourced from - http://forum.unity3d.com/threads/sprite-icons-with-text-e-g-emoticons.265927/
using UnityEditor;
namespace UnityEngine.UI.Extensions
{
[CanEditMultipleObjects]
[CustomEditor(typeof(TextPic))]
public class TextPicEditor : UnityEditor.UI.TextEditor
{
private SerializedProperty ImageScalingFactorProp;
private SerializedProperty hyperlinkColorProp;
private SerializedProperty imageOffsetProp;
private SerializedProperty iconList;
protected override void OnEnable()
{
base.OnEnable();
ImageScalingFactorProp = serializedObject.FindProperty("ImageScalingFactor");
hyperlinkColorProp = serializedObject.FindProperty("hyperlinkColor");
imageOffsetProp = serializedObject.FindProperty("imageOffset");
iconList = serializedObject.FindProperty("inspectorIconList");
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
serializedObject.Update();
EditorGUILayout.PropertyField(imageOffsetProp, new GUIContent("Image Offset"));
EditorGUILayout.PropertyField(ImageScalingFactorProp, new GUIContent("Image Scaling Factor"));
EditorGUILayout.PropertyField(hyperlinkColorProp, new GUIContent("Hyperlink Color"));
EditorGUILayout.PropertyField(iconList, new GUIContent("Icon List"), true);
serializedObject.ApplyModifiedProperties();
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5fe8e67609bbee14d8ad0805aac72799
timeCreated: 1468515486
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3cac6d35505037446b512aea22d40688
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,115 @@
/// Credit Senshi
/// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/ (uGUITools link)
using UnityEditor;
namespace UnityEngine.UI.Extensions
{
public static class uGUITools
{
[MenuItem("uGUI/Anchors to Corners %[")]
static void AnchorsToCorners()
{
foreach (Transform transform in Selection.transforms)
{
RectTransform t = transform as RectTransform;
RectTransform pt = Selection.activeTransform.parent as RectTransform;
if (t == null || pt == null) return;
Vector2 newAnchorsMin = new Vector2(t.anchorMin.x + t.offsetMin.x / pt.rect.width,
t.anchorMin.y + t.offsetMin.y / pt.rect.height);
Vector2 newAnchorsMax = new Vector2(t.anchorMax.x + t.offsetMax.x / pt.rect.width,
t.anchorMax.y + t.offsetMax.y / pt.rect.height);
t.anchorMin = newAnchorsMin;
t.anchorMax = newAnchorsMax;
t.offsetMin = t.offsetMax = new Vector2(0, 0);
}
}
[MenuItem("uGUI/Corners to Anchors %]")]
static void CornersToAnchors()
{
foreach (Transform transform in Selection.transforms)
{
RectTransform t = transform as RectTransform;
if (t == null) return;
t.offsetMin = t.offsetMax = new Vector2(0, 0);
}
}
[MenuItem("uGUI/Mirror Horizontally Around Anchors %;")]
static void MirrorHorizontallyAnchors()
{
MirrorHorizontally(false);
}
[MenuItem("uGUI/Mirror Horizontally Around Parent Center %:")]
static void MirrorHorizontallyParent()
{
MirrorHorizontally(true);
}
static void MirrorHorizontally(bool mirrorAnchors)
{
foreach (Transform transform in Selection.transforms)
{
RectTransform t = transform as RectTransform;
RectTransform pt = Selection.activeTransform.parent as RectTransform;
if (t == null || pt == null) return;
if (mirrorAnchors)
{
Vector2 oldAnchorMin = t.anchorMin;
t.anchorMin = new Vector2(1 - t.anchorMax.x, t.anchorMin.y);
t.anchorMax = new Vector2(1 - oldAnchorMin.x, t.anchorMax.y);
}
Vector2 oldOffsetMin = t.offsetMin;
t.offsetMin = new Vector2(-t.offsetMax.x, t.offsetMin.y);
t.offsetMax = new Vector2(-oldOffsetMin.x, t.offsetMax.y);
t.localScale = new Vector3(-t.localScale.x, t.localScale.y, t.localScale.z);
}
}
[MenuItem("uGUI/Mirror Vertically Around Anchors %'")]
static void MirrorVerticallyAnchors()
{
MirrorVertically(false);
}
[MenuItem("uGUI/Mirror Vertically Around Parent Center %\"")]
static void MirrorVerticallyParent()
{
MirrorVertically(true);
}
static void MirrorVertically(bool mirrorAnchors)
{
foreach (Transform transform in Selection.transforms)
{
RectTransform t = transform as RectTransform;
RectTransform pt = Selection.activeTransform.parent as RectTransform;
if (t == null || pt == null) return;
if (mirrorAnchors)
{
Vector2 oldAnchorMin = t.anchorMin;
t.anchorMin = new Vector2(t.anchorMin.x, 1 - t.anchorMax.y);
t.anchorMax = new Vector2(t.anchorMax.x, 1 - oldAnchorMin.y);
}
Vector2 oldOffsetMin = t.offsetMin;
t.offsetMin = new Vector2(t.offsetMin.x, -t.offsetMax.y);
t.offsetMax = new Vector2(t.offsetMax.x, -oldOffsetMin.y);
t.localScale = new Vector3(t.localScale.x, -t.localScale.y, t.localScale.z);
}
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b896154a8dbdc524092e78923478d27a
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 5a0b1710131366b4f82f636d29814556
folderAsset: yes
timeCreated: 1467468503
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: a45157cd1cb5ccd439f3cf178dd2c359
folderAsset: yes
timeCreated: 1480012406
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 53b194f66900add419869c57ffbe7b85
timeCreated: 1480025159
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d2365a7a72fdea14f9eaba13cf14f570
timeCreated: 1480025159
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: d80c37ed1c91b6f4c87ea91bb292f8c1
folderAsset: yes
timeCreated: 1467468503
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 6a0cecb173b794c3bb33e379defdeeb0
folderAsset: yes
timeCreated: 1449409914
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,207 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &137556
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 4
m_Component:
- 224: {fileID: 22421816}
- 222: {fileID: 22220394}
- 114: {fileID: 11499114}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &138598
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 4
m_Component:
- 224: {fileID: 22453926}
- 222: {fileID: 22252292}
- 114: {fileID: 11415048}
- 114: {fileID: 11471022}
m_Layer: 5
m_Name: DaysVertical
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &11415048
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 138598}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
--- !u!114 &11471022
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 138598}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1392445389, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: .960784316, g: .960784316, b: .960784316, a: 1}
m_PressedColor: {r: .784313738, g: .784313738, b: .784313738, a: 1}
m_DisabledColor: {r: .784313738, g: .784313738, b: .784313738, a: .501960814}
m_ColorMultiplier: 1
m_FadeDuration: .100000001
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 11415048}
m_OnClick:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!114 &11499114
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 137556}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: .196078435, g: .196078435, b: .196078435, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 1
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 4
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Button
--- !u!222 &22220394
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 137556}
--- !u!222 &22252292
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 138598}
--- !u!224 &22421816
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 137556}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 22453926}
m_RootOrder: 0
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: .5, y: .5}
--- !u!224 &22453926
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 138598}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 22421816}
m_Father: {fileID: 0}
m_RootOrder: 0
m_AnchorMin: {x: 0, y: .5}
m_AnchorMax: {x: 1, y: .5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 80}
m_Pivot: {x: .5, y: .5}
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 0}
propertyPath: m_SizeDelta.y
value: 80
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 138598}
m_IsPrefabParent: 1

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ec6f9b1230e4a4896b7be2e60d3be758
timeCreated: 1448815288
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,207 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &139176
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 4
m_Component:
- 224: {fileID: 22488808}
- 222: {fileID: 22208232}
- 114: {fileID: 11466432}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &194106
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 4
m_Component:
- 224: {fileID: 22496698}
- 222: {fileID: 22250104}
- 114: {fileID: 11448172}
- 114: {fileID: 11464628}
m_Layer: 5
m_Name: MonthsVertical
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &11448172
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 194106}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
--- !u!114 &11464628
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 194106}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1392445389, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: .960784316, g: .960784316, b: .960784316, a: 1}
m_PressedColor: {r: .784313738, g: .784313738, b: .784313738, a: 1}
m_DisabledColor: {r: .784313738, g: .784313738, b: .784313738, a: .501960814}
m_ColorMultiplier: 1
m_FadeDuration: .100000001
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 11448172}
m_OnClick:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!114 &11466432
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 139176}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: .196078435, g: .196078435, b: .196078435, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 1
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 4
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Button
--- !u!222 &22208232
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 139176}
--- !u!222 &22250104
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 194106}
--- !u!224 &22488808
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 139176}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 22496698}
m_RootOrder: 0
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: .5, y: .5}
--- !u!224 &22496698
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 194106}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 22488808}
m_Father: {fileID: 0}
m_RootOrder: 0
m_AnchorMin: {x: 0, y: .5}
m_AnchorMax: {x: 1, y: .5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 80}
m_Pivot: {x: .5, y: .5}
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 0}
propertyPath: m_SizeDelta.y
value: 80
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 194106}
m_IsPrefabParent: 1

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6d45e8f0aa19044ffb3553ca52febef2
timeCreated: 1448814882
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,207 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &118010
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 4
m_Component:
- 224: {fileID: 22496654}
- 222: {fileID: 22201990}
- 114: {fileID: 11434666}
- 114: {fileID: 11483478}
m_Layer: 5
m_Name: YearsVertical
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &154304
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 4
m_Component:
- 224: {fileID: 22441182}
- 222: {fileID: 22293210}
- 114: {fileID: 11490688}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &11434666
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 118010}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
--- !u!114 &11483478
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 118010}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1392445389, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: .960784316, g: .960784316, b: .960784316, a: 1}
m_PressedColor: {r: .784313738, g: .784313738, b: .784313738, a: 1}
m_DisabledColor: {r: .784313738, g: .784313738, b: .784313738, a: .501960814}
m_ColorMultiplier: 1
m_FadeDuration: .100000001
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 11434666}
m_OnClick:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!114 &11490688
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 154304}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: .196078435, g: .196078435, b: .196078435, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 1
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 4
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Button
--- !u!222 &22201990
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 118010}
--- !u!222 &22293210
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 154304}
--- !u!224 &22441182
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 154304}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 22496654}
m_RootOrder: 0
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: .5, y: .5}
--- !u!224 &22496654
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 118010}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 22441182}
m_Father: {fileID: 0}
m_RootOrder: 0
m_AnchorMin: {x: 0, y: .5}
m_AnchorMax: {x: 1, y: .5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 80}
m_Pivot: {x: .5, y: .5}
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 0}
propertyPath: m_SizeDelta.y
value: 80
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 118010}
m_IsPrefabParent: 1

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 65ce75600991941569988ab4538a21a6
timeCreated: 1448814778
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 573635efe02d54e20a59cd3023afa514
folderAsset: yes
timeCreated: 1449409946
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: dc87f62a4e5c94019904b8b6037818b5
timeCreated: 1449409834
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: f1caec3cabf7c4eaaa5b2ad30cf018a9
folderAsset: yes
timeCreated: 1449409928
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,231 @@
/// <summary>
/// Brought you by Mrs. YakaYocha
/// https://www.youtube.com/channel/UCHp8LZ_0-iCvl-5pjHATsgw
///
/// Please donate: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RJ8D9FRFQF9VS
/// </summary>
using UnityEngine;
using UnityEngine.UI;
using System;
using UnityEngine.UI.Extensions;
public class ScrollingCalendar : MonoBehaviour
{
public RectTransform monthsScrollingPanel;
public RectTransform yearsScrollingPanel;
public RectTransform daysScrollingPanel;
public GameObject yearsButtonPrefab;
public GameObject monthsButtonPrefab;
public GameObject daysButtonPrefab;
private GameObject[] monthsButtons;
private GameObject[] yearsButtons;
private GameObject[] daysButtons;
public RectTransform monthCenter;
public RectTransform yearsCenter;
public RectTransform daysCenter;
UIVerticalScroller yearsVerticalScroller;
UIVerticalScroller monthsVerticalScroller;
UIVerticalScroller daysVerticalScroller;
public InputField inputFieldDays;
public InputField inputFieldMonths;
public InputField inputFieldYears;
public Text dateText;
private int daysSet;
private int monthsSet;
private int yearsSet;
private void InitializeYears()
{
int currentYear = int.Parse(System.DateTime.Now.ToString("yyyy"));
int[] arrayYears = new int[currentYear+1 - 1900];
yearsButtons = new GameObject[arrayYears.Length];
for (int i = 0; i < arrayYears.Length; i++)
{
arrayYears[i] = 1900 + i;
GameObject clone = (GameObject)Instantiate(yearsButtonPrefab, new Vector3(0, i*80, 0), Quaternion.Euler(new Vector3(0, 0, 0))) as GameObject;
clone.transform.SetParent(yearsScrollingPanel,false);
clone.transform.localScale = new Vector3(1, 1, 1);
clone.GetComponentInChildren<Text>().text = "" + arrayYears[i];
clone.name = "Year_" + arrayYears[i];
clone.AddComponent<CanvasGroup>();
yearsButtons[i] = clone;
}
}
//Initialize Months
private void InitializeMonths()
{
int[] months = new int[12];
monthsButtons = new GameObject[months.Length];
for (int i = 0; i < months.Length; i++)
{
string month = "";
months[i] = i;
GameObject clone = (GameObject)Instantiate(monthsButtonPrefab, new Vector3(0, i * 80, 0), Quaternion.Euler(new Vector3(0, 0, 0))) as GameObject;
clone.transform.SetParent(monthsScrollingPanel,false);
clone.transform.localScale = new Vector3(1, 1, 1);
switch(i)
{
case 0:
month = "Jan";
break;
case 1:
month = "Feb";
break;
case 2:
month = "Mar";
break;
case 3:
month = "Apr";
break;
case 4:
month = "May";
break;
case 5:
month = "Jun";
break;
case 6:
month = "Jul";
break;
case 7:
month = "Aug";
break;
case 8:
month = "Sep";
break;
case 9:
month = "Oct";
break;
case 10:
month = "Nov";
break;
case 11:
month = "Dec";
break;
}
clone.GetComponentInChildren<Text>().text = month;
clone.name = "Month_" + months[i];
clone.AddComponent<CanvasGroup>();
monthsButtons[i] = clone;
}
}
private void InitializeDays()
{
int[] days = new int[31];
daysButtons = new GameObject[days.Length];
for (var i = 0; i < days.Length; i++)
{
days[i] = i+1;
GameObject clone = (GameObject)Instantiate(daysButtonPrefab, new Vector3(0, i * 80, 0), Quaternion.Euler(new Vector3(0, 0, 0))) as GameObject;
clone.transform.SetParent(daysScrollingPanel,false);
clone.transform.localScale = new Vector3(1, 1, 1);
clone.GetComponentInChildren<Text>().text = "" + days[i];
clone.name = "Day_" + days[i];
clone.AddComponent<CanvasGroup>();
daysButtons[i] = clone;
}
}
// Use this for initialization
public void Awake()
{
InitializeYears();
InitializeMonths();
InitializeDays();
//Yes Unity complains about this but it doesn't matter in this case.
monthsVerticalScroller = new UIVerticalScroller(monthsScrollingPanel, monthsButtons, monthCenter);
yearsVerticalScroller = new UIVerticalScroller (yearsScrollingPanel, yearsButtons, yearsCenter);
daysVerticalScroller = new UIVerticalScroller (daysScrollingPanel, daysButtons, daysCenter);
monthsVerticalScroller.Start();
yearsVerticalScroller.Start();
daysVerticalScroller.Start();
}
public void SetDate()
{
daysSet = int.Parse(inputFieldDays.text) - 1;
monthsSet = int.Parse(inputFieldMonths.text) - 1;
yearsSet = int.Parse(inputFieldYears.text) - 1900;
daysVerticalScroller.SnapToElement(daysSet);
monthsVerticalScroller.SnapToElement(monthsSet);
yearsVerticalScroller.SnapToElement(yearsSet);
}
void Update ()
{
monthsVerticalScroller.Update();
yearsVerticalScroller.Update();
daysVerticalScroller.Update();
string dayString = daysVerticalScroller.GetResults();
string monthString = monthsVerticalScroller.GetResults();
string yearsString = yearsVerticalScroller.GetResults();
if (dayString.EndsWith("1") && dayString != "11")
dayString = dayString + "st";
else if (dayString.EndsWith("2") && dayString != "12")
dayString = dayString + "nd";
else if (dayString.EndsWith("3") && dayString != "13")
dayString = dayString + "rd";
else
dayString = dayString + "th";
dateText.text = monthString + " " + dayString + " " + yearsString;
}
public void DaysScrollUp()
{
daysVerticalScroller.ScrollUp();
}
public void DaysScrollDown()
{
daysVerticalScroller.ScrollDown();
}
public void MonthsScrollUp()
{
monthsVerticalScroller.ScrollUp();
}
public void MonthsScrollDown()
{
monthsVerticalScroller.ScrollDown();
}
public void YearsScrollUp()
{
yearsVerticalScroller.ScrollUp();
}
public void YearsScrollDown()
{
yearsVerticalScroller.ScrollDown();
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e0185937f87604a7497a35019c125107
timeCreated: 1449409849
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 7ffd04bf6a590424fb623c185d6f6ec5
folderAsset: yes
timeCreated: 1450208395
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

View file

@ -0,0 +1,94 @@
fileFormatVersion: 2
guid: 1e2d444ae9d5a4ff1b47ffec28d5165c
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 1
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
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
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}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 1
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,30 @@
/// Credit playemgames
/// Sourced from - http://forum.unity3d.com/threads/sprite-icons-with-text-e-g-emoticons.265927/
using UnityEngine;
using UnityEngine.UI.Extensions;
public class testHref : MonoBehaviour
{
public TextPic textPic;
void Awake()
{
textPic = GetComponent<TextPic>();
}
void OnEnable()
{
textPic.onHrefClick.AddListener(OnHrefClick);
}
void OnDisable()
{
textPic.onHrefClick.RemoveListener(OnHrefClick);
}
private void OnHrefClick(string hrefName)
{
Debug.Log("Click on the " + hrefName);
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 87d264f28a3959240b775c19c0d11013
timeCreated: 1468515487
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,19 @@
Copyright (c) 2015
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e9a81748fac51154f8688d2e3c46fd56
timeCreated: 1438724032
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,197 @@
# README #
This is an extension project for the new Unity UI system which can be found at: [Unity UI Source](https://bitbucket.org/Unity-Technologies/ui)
-----
#[Supporting the UI Extensions project](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=89L8T9N6BR7LJ)#
If you wish to support the Unity UI Extensions project itself, then you can using the PayPal link below.
All funds go to support the project, no matter the amount.
> Donations in code are also extremely welcome :D
(PayPal account not required and you can remain anonymous if you wish)
##[>> Donate <<](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=89L8T9N6BR7LJ)##
-----
#[Intro](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/GettingStarted)#
For more info, here's a little introduction video for the project:
[![View Intro Video](http://img.youtube.com/vi/njoIeE4akq0/0.jpg)](http://www.youtube.com/watch?v=njoIeE4akq0 "Unity UI Extensions intro video")
You can follow the UI Extensions team for updates and news on:
### [Twitter](https://twitter.com/search?q=%23unityuiextensions) / [Facebook](https://www.facebook.com/UnityUIExtensions/) / [YouTube](https://www.youtube.com/channel/UCG3gZOkmL-2rmZat4ufv28Q)###
-----
#[ What is this repository for? ](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/About)#
In this repository is a collection of extension scripts to enhance your Unity UI experience. These scripts have been gathered from many sources and combined and improved over time.
> The majority of the scripts came from the Scripts thread on the [Unity UI forum here](http://bit.ly/UnityUIScriptsForumPost)
You can either download / fork this project to access the scripts, or you can also download these pre-compiled Unity Assets, chock full of goodness for each release:
#[Download](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/Downloads)#
The asset has been full tested on all current versions of Unity 5 (for versions prior to Unity 5.3, please see the [archive](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/Downloads))
* [Unity UI Extensions Asset](https://bitbucket.org/ddreaper/unity-ui-extensions/downloads/UnityUIExtensions.unitypackage)
To view previous releases, visit the [release archive](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/Downloads)
-----
#[Getting Started](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/GettingStarted)#
To get started with the project, here's a little guide:
[![View Getting Started Video](http://img.youtube.com/vi/sVLeYmsNQAI/0.jpg)](http://www.youtube.com/watch?v=sVLeYmsNQAI "Unity UI getting started video")
-----
#[Updates:](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/ReleaseNotes/RELEASENOTES)#
##Update 1.2##
[![View 1.2 update Video](http://img.youtube.com/vi/cWv0A6rEEc8/0.jpg)](https://www.youtube.com/watch?v=cWv0A6rEEc8 "Update 1.2 for the Unity UI Extensions Project")
###New / updated features###
* Major updates to the Horizontal and Vertical Scroll Snap controls
* Replacement HSV/Color picker control (and new Box Slider control)
* Fixes / updates to the TextPic control
* Updates to SoftAlphaUI script - improved Text / worldspace support
* Updates to Extensions Toggle - Adds ID and event to publish ID on change
* New Gadient control (gradient 2)
* New UI ScrollRect Occlusion utility
* New UI Tween Scale utility
* New UI Infinite ScrollRect
* New Table Layout Group
* New Non Drawing Graphic Control
###Fixes###
* H&V Scroll Snap indexing issues
* H&V Scroll Snap performance updates
* H&V Scroll Snap Long swipe behavior updated
* H&V Scroll Snap support for Rect Resizing
* TextPic Set set before draw issues
* HSV picker replaced with more generic color picker
###Known issues###
* The Image_Extended control has been removed due to Unity upgrade issues. Will return in a future update.
##Upgrade Notes##
Although not specifically required, it is recommended to remove the old UI Extensions folder before importing the new asset
The HSS picker especially had a lot of file changes in this update.
>**Note** In Unity 5.5 the particle system was overhauled and several methods were marked for removal. However, the UI Particle System script currently still uses them
> Either ignore these errors or remove the *_UIParticleSystem_* script in the "*Unity UI Extensions / Scripts / Effects*" folder
-------------------
##Release History##
For the full release history, follow the below link to the full release notes page.
### [Release Notes](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/ReleaseNotes/RELEASENOTES)###
---
#[Controls and extensions listed in this project](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/Controls):#
There are almost 70 extension controls / effect and other utilities in the project which are listed on the following page:
##[UI Extensions controls list](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/Controls)##
[Controls](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/Controls#Controls)|||||
------|------|------|------|
Accordion|ColorPicker|SelectionBox|UIButton|UIFlippable
ComboBox|AutoCompleteComboBox|DropDownList|BoundToolTip|UIWindowBase
UI_Knob|TextPic|InputFocus|Box Slider
||||
[Primitives](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/Controls#Primitives)|||||
------|------|------|------|
UILineRenderer|UILineTextureRenderer|UICircle|DiamondGraph|UICornerCut
UIPolygon||||
||||
[Layouts](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/Controls#Layouts)|||||
------|------|------|------|
Horizontal Scroll Snap|Vertical Scroll Snap|Flow Layout Group|Radial Layout|Tile Size Fitter
Scroll Snap (alt implementation)|Reorderable List|UI Vertical Scroller|Curved Layout|Table Layout
||||
[Effects](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/Controls#Effects)|||||
------|------|------|------|
Best Fit Outline|Curved Text|Gradient|Gradient2|Letter Spacing|
NicerOutline|RaycastMask|UIFlippable|UIImageCrop|SoftAlphaMask
CylinderText|UIParticleSystem|||
||||
[VR Components](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/Controls#VR)|||||
------|------|------|------|
VRCursor|VRInputModule|||
||||
[Input Modules](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/Controls#InputModules)|||||
------|------|------|------|
AimerInputModule|GamePadInputModule|||
||||
[Additional Components](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/Controls#Additional_Components)|||||
------|------|------|------|
ReturnKeyTrigger|TabNavigation|uGUITools|ScrollRectTweener|ScrollRectLinker
ScrollRectEx|UI_InfiniteScroll|UI_ScrollRectOcclusion|UIScrollToSelection|UISelectableExtension
switchToRectTransform|ScrollConflictManager|CLFZ2 (Encryption)|Serialization|DragCorrector
PPIViewer|UI_TweenScale|UI_InfiniteScroll|UI_ScrollRectOcclusion|
||||
*More to come*
---
#[ How do I get set up? ](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/GettingStarted)#
Either clone / download this repository to your machine and then copy the scripts in, or use the pre-packaged .UnityPackage for your version of Unity and import it as a custom package in to your project.
#[ Contribution guidelines ](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/ContributionGuidelines)#
Got a script you want added? Then just fork the bitbucket repository and submit a PR. All contributions accepted (including fixes)
Just ensure
* The header of the script matches the standard used in all scripts
* The script uses the **Unity.UI.Extensions** namespace so they do not affect any other developments
* (optional) Add Component and Editor options where possible (editor options are in the Editor\UIExtensionsMenuOptions.cs file)
#[ License ](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/License)#
All scripts conform to the BSD license and are free to use / distribute. See the [LICENSE](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/License) file for more information
#[ Like what you see? ](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/FurtherInfo)#
All these scripts were put together for my latest book Unity3D UI Essentials
Check out the [page on my blog](http://bit.ly/Unity3DUIEssentials) for more details and learn all about the inner workings of the new Unity UI System.
#[ The downloads ](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/Downloads)#
As this repo was created to support my new Unity UI Title ["Unity 3D UI Essentials"](http://bit.ly/Unity3DUIEssentials), in the downloads section you will find two custom assets (SpaceShip-DemoScene-Start.unitypackage and RollABallSample-Start.unitypackage). These are just here as starter scenes for doing UI tasks in the book.
I will add more sample scenes for the UI examples in this repository and detail them above over time.
#[Previous Releases](https://bitbucket.org/ddreaper/unity-ui-extensions/wiki/Downloads)#
* [Unity UI Extensions Unity 4.x Asset](https://bitbucket.org/ddreaper/unity-ui-extensions/downloads/UnityUIExtensions-4.x.unitypackage)
* [Unity UI Extensions Unity 5.1 Asset](https://bitbucket.org/ddreaper/unity-ui-extensions/downloads/UnityUIExtensions-5.1.unitypackage)
* [Unity UI Extensions Unity 5.2 Asset](https://bitbucket.org/ddreaper/unity-ui-extensions/downloads/UnityUIExtensions-5.2.unitypackage) <- 5.2.0 - 5.2.1 base releases ONLY
* [Unity UI Extensions Unity 5.3 (5.2.1P+) Asset](https://bitbucket.org/ddreaper/unity-ui-extensions/downloads/UnityUIExtensions-5.3.unitypackage) <- use this for 5.2.1P+ releases
> **Note** To retain 5.2 compatibility in the 5.3 package, you will see two warnings related to:
> ```
> `UnityEngine.UI.InputField.onValueChange' is obsolete.
> ```
> This has no effect on the package working in 5.4 plus and is only there to maintain backwards compatibility. We will look to update/remove this in a future release, likely after 5.4.
If you have any concerns, feel free to update your code in your project to add the missing "d". Unity have ensured it still works as they have mapped the API change for now.

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f6cbd6c26357c6a40947224e172bfdf6
timeCreated: 1438724032
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,121 @@
# Unity UI Extensions release notes #
This file contains the up to date release notes for each release of the UI Extensions project including release videos where required.
----------------
##Update 1.2##
[![View 1.2 update Video](http://img.youtube.com/vi/cWv0A6rEEc8/0.jpg)](https://www.youtube.com/watch?v=cWv0A6rEEc8 "Update 1.2 for the Unity UI Extensions Project")
###New / updated features###
* Major updates to the Horizontal and Vertical Scroll Snap controls
* Replacement HSV/Color picker control (and new Box Slider control)
* Fixes / updates to the TextPic control
* Updates to SoftAlphaUI script - improved Text / worldspace support
* Updates to Extensions Toggle - Adds ID and event to publish ID on change
* New Gadient control (gradient 2)
* New UI ScrollRect Occlusion utility
* New UI Tween Scale utility
* New UI Infinite ScrollRect
* New Table Layout Group
* New Non Drawing Graphic Control
###Fixes###
* H&V Scroll Snap indexing issues
* H&V Scroll Snap performance updates
* H&V Scroll Snap Long swipe behavior updated
* H&V Scroll Snap support for Rect Resizing
* TextPic Set set before draw issues
* HSV picker replaced with more generic color picker
###Known issues###
* The Image_Extended control has been removed due to Unity upgrade issues. Will return in a future update.
##Upgrade Notes##
Although not specifically required, it is recommended to remove the old UI Extensions folder before importing the new asset
The HSS picker especially had a lot of file changes in this update.
>**Note** In Unity 5.5 the particle system was overhauled and several methods were marked for removal. However, the UI Particle System script currently still uses them
> Either ignore these errors or remove the *_UIParticleSystem_* script in the "*Unity UI Extensions / Scripts / Effects*" folder
----------------
##Update 1.1##
[![View 1.1 update Video](http://img.youtube.com/vi/JuE0ja5DmV4/0.jpg)](https://www.youtube.com/watch?v=JuE0ja5DmV4 "Update 1.1 for the Unity UI Extensions Project")
> **Note** for 4.6 / 5.1, some features will not be available due to their incompatibility.
> Also the Line Renderer remains unchanged in these releases as the updates do not work with the older system
###New / updated features###
* New Polygon primitive
* New UI Vertical Scroller control
* New Curved layout component
* New Shining effect
* New UI Particle system **<-5.3+ only**
* New Scroll Conflict Manager
* Soft Alpha Mask updated in line with SAUI 1.3 release
* Line Renderer has had a complete overhaul, including full programmatic support, Line list and Bezier line rendering
* Horizontal and Vertical Scroll Snaps updated to include a Starting page, current page and transition speed parameters. Plus a new GoToPage, Add and Remove page functions
* Added some script helper functions for LZF compression and Serialization
* Two utilities to help manage drag thresholds on high PPI systems
###Fixes###
* Line Render almost completely re-written with tons of fixes
* Radial layout updated to avoid 360 overlap (first and last)
* Scroll Snaps updates to better handle children.
* Scroll Snaps distribute function updated so it can be called onDirty more efficiently.
##Upgrade Notes##
Two scripts were moved and need their originals need deleting post upgrade. Please remove the following files:
* Scripts\ImageExtended
* Scripts\UIImageCrop
----------------
##Update 1.0.6.1##
- Minor update to enhance soft alpha mask and add cylinder text plus a fix to letter spacing
----------------
##Update 1.0.6##
[![View 1.0.6 update Video](http://img.youtube.com/vi/jpyFiRvSmbg/0.jpg)](http://www.youtube.com/watch?v=jpyFiRvSmbg "Update 1.0.6 for the Unity UI Extensions Project")
* Added the awesome ReOrderable List control, plus some other minor bugfixes / changes.
* Added a new version of the Scroll Snap control as an alternative to the fixed versions.
* New set of controls including some shader enhanced solutions
* I've added a donate column to the lists. If you are getting great use out of a control, help out the dev who created it. Optional of course. Will update with links as I get them.
----------------
##Update 1.0.5##
Few minor fixes and a couple of additional scripts. Predominately created the new 5.3 branch to maintain the UI API changes from the 5.2.1 Patch releases. 5.3 package is 100% compatible with 5.2.1 Patch releases.
----------------
##Update 1.0.4##
[![View Getting Started Video](http://img.youtube.com/vi/oF48Qpaq3ls/0.jpg)](http://www.youtube.com/watch?v=oF48Qpaq3ls "Update 1.0.0.4 for the Unity UI Extensions Project")
---
=======================
#Additional Info#
=======================
### How do I get set up? ###
Either clone / download this repository to your machine and then copy the scripts in, or use the pre-packaged .UnityPackage for your version of Unity and import it as a custom package in to your project.
### Contribution guidelines ###
Got a script you want added, then just fork and submit a PR. All contributions accepted (including fixes)
Just ensure
* The header of the script matches the standard used in all scripts
* The script uses the **Unity.UI.Extensions** namespace so they do not affect any other developments
* (optional) Add Component and Editor options where possible (editor options are in the Editor\UIExtensionsMenuOptions.cs file)
### License ###
All scripts conform to the BSD license and are free to use / distribute. See the [LICENSE](https://bitbucket.org/ddreaper/unity-ui-extensions/src/6d03f25b0150994afa97c6a55854d6ae696cad13/LICENSE?at=default) file for more information
### Like what you see? ###
All these scripts were put together for my latest book Unity3D UI Essentials
Check out the [page on my blog](http://bit.ly/Unity3DUIEssentials) for more details and learn all about the inner workings of the new Unity UI System.
### The downloads ###
As this repo was created to support my new Unity UI Title ["Unity 3D UI Essentials"](http://bit.ly/Unity3DUIEssentials), in the downloads section you will find two custom assets (SpaceShip-DemoScene-Start.unitypackage and RollABallSample-Start.unitypackage). These are just here as starter scenes for doing UI tasks in the book.
I will add more sample scenes for the UI examples in this repository and detail them above over time.

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 295bdc5c9df74e146bd5fa63aa5aeaf8
timeCreated: 1463598733
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 9d40233b1c5add641bb2f4f7f12af05e
folderAsset: yes
timeCreated: 1438724032
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: fab8c1b6e538fad489513f03e0418451
folderAsset: yes
timeCreated: 1468775610
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 82ea50ac9a6ea8940a71f86ea8d13bf0
folderAsset: yes
DefaultImporter:
userData:

View file

@ -0,0 +1,41 @@
///Credit ChoMPHi
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(VerticalLayoutGroup), typeof(ContentSizeFitter), typeof(ToggleGroup))]
[AddComponentMenu("UI/Extensions/Accordion/Accordion Group")]
public class Accordion : MonoBehaviour
{
public enum Transition
{
Instant,
Tween
}
[SerializeField] private Transition m_Transition = Transition.Instant;
[SerializeField] private float m_TransitionDuration = 0.3f;
/// <summary>
/// Gets or sets the transition.
/// </summary>
/// <value>The transition.</value>
public Transition transition
{
get { return this.m_Transition; }
set { this.m_Transition = value; }
}
/// <summary>
/// Gets or sets the duration of the transition.
/// </summary>
/// <value>The duration of the transition.</value>
public float transitionDuration
{
get { return this.m_TransitionDuration; }
set { this.m_TransitionDuration = value; }
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4387cc9950f37044c92f9d144a2b1002
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,140 @@
///Credit ChoMPHi
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
using System;
using UnityEngine.UI.Extensions.Tweens;
namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(RectTransform), typeof(LayoutElement))]
[AddComponentMenu("UI/Extensions/Accordion/Accordion Element")]
public class AccordionElement : Toggle
{
[SerializeField] private float m_MinHeight = 18f;
private Accordion m_Accordion;
private RectTransform m_RectTransform;
private LayoutElement m_LayoutElement;
[NonSerialized]
private readonly TweenRunner<FloatTween> m_FloatTweenRunner;
protected AccordionElement()
{
if (this.m_FloatTweenRunner == null)
this.m_FloatTweenRunner = new TweenRunner<FloatTween>();
this.m_FloatTweenRunner.Init(this);
}
protected override void Awake()
{
base.Awake();
base.transition = Transition.None;
base.toggleTransition = ToggleTransition.None;
this.m_Accordion = this.gameObject.GetComponentInParent<Accordion>();
this.m_RectTransform = this.transform as RectTransform;
this.m_LayoutElement = this.gameObject.GetComponent<LayoutElement>();
this.onValueChanged.AddListener(OnValueChanged);
}
#if UNITY_EDITOR
protected override void OnValidate()
{
base.OnValidate();
if (this.group == null)
{
ToggleGroup tg = this.GetComponentInParent<ToggleGroup>();
if (tg != null)
{
this.group = tg;
}
}
LayoutElement le = this.gameObject.GetComponent<LayoutElement>();
if (le != null)
{
if (this.isOn)
{
le.preferredHeight = -1f;
}
else
{
le.preferredHeight = this.m_MinHeight;
}
}
}
#endif
public void OnValueChanged(bool state)
{
if (this.m_LayoutElement == null)
return;
Accordion.Transition transition = (this.m_Accordion != null) ? this.m_Accordion.transition : Accordion.Transition.Instant;
if (transition == Accordion.Transition.Instant)
{
if (state)
{
this.m_LayoutElement.preferredHeight = -1f;
}
else
{
this.m_LayoutElement.preferredHeight = this.m_MinHeight;
}
}
else if (transition == Accordion.Transition.Tween)
{
if (state)
{
this.StartTween(this.m_MinHeight, this.GetExpandedHeight());
}
else
{
this.StartTween(this.m_RectTransform.rect.height, this.m_MinHeight);
}
}
}
protected float GetExpandedHeight()
{
if (this.m_LayoutElement == null)
return this.m_MinHeight;
float originalPrefH = this.m_LayoutElement.preferredHeight;
this.m_LayoutElement.preferredHeight = -1f;
float h = LayoutUtility.GetPreferredHeight(this.m_RectTransform);
this.m_LayoutElement.preferredHeight = originalPrefH;
return h;
}
protected void StartTween(float startFloat, float targetFloat)
{
float duration = (this.m_Accordion != null) ? this.m_Accordion.transitionDuration : 0.3f;
FloatTween info = new FloatTween
{
duration = duration,
startFloat = startFloat,
targetFloat = targetFloat
};
info.AddOnChangedCallback(SetHeight);
info.ignoreTimeScale = true;
this.m_FloatTweenRunner.StartTween(info);
}
protected void SetHeight(float height)
{
if (this.m_LayoutElement == null)
return;
this.m_LayoutElement.preferredHeight = height;
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3c9d341c4bc7de548937508e6f837144
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: b9115417252d4cd42a5e167bdc1c2d3b
folderAsset: yes
DefaultImporter:
userData:

View file

@ -0,0 +1,121 @@
///Credit ChoMPHi
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
using System.Collections;
using UnityEngine.Events;
namespace UnityEngine.UI.Extensions.Tweens
{
public struct FloatTween : ITweenValue
{
public class FloatTweenCallback : UnityEvent<float> {}
public class FloatFinishCallback : UnityEvent {}
private float m_StartFloat;
private float m_TargetFloat;
private float m_Duration;
private bool m_IgnoreTimeScale;
private FloatTweenCallback m_Target;
private FloatFinishCallback m_Finish;
/// <summary>
/// Gets or sets the starting float.
/// </summary>
/// <value>The start float.</value>
public float startFloat
{
get { return m_StartFloat; }
set { m_StartFloat = value; }
}
/// <summary>
/// Gets or sets the target float.
/// </summary>
/// <value>The target float.</value>
public float targetFloat
{
get { return m_TargetFloat; }
set { m_TargetFloat = value; }
}
/// <summary>
/// Gets or sets the duration of the tween.
/// </summary>
/// <value>The duration.</value>
public float duration
{
get { return m_Duration; }
set { m_Duration = value; }
}
/// <summary>
/// Gets or sets a value indicating whether this <see cref="UnityEngine.UI.Tweens.ColorTween"/> should ignore time scale.
/// </summary>
/// <value><c>true</c> if ignore time scale; otherwise, <c>false</c>.</value>
public bool ignoreTimeScale
{
get { return m_IgnoreTimeScale; }
set { m_IgnoreTimeScale = value; }
}
/// <summary>
/// Tweens the float based on percentage.
/// </summary>
/// <param name="floatPercentage">Float percentage.</param>
public void TweenValue(float floatPercentage)
{
if (!ValidTarget())
return;
m_Target.Invoke( Mathf.Lerp (m_StartFloat, m_TargetFloat, floatPercentage) );
}
/// <summary>
/// Adds a on changed callback.
/// </summary>
/// <param name="callback">Callback.</param>
public void AddOnChangedCallback(UnityAction<float> callback)
{
if (m_Target == null)
m_Target = new FloatTweenCallback();
m_Target.AddListener(callback);
}
/// <summary>
/// Adds a on finish callback.
/// </summary>
/// <param name="callback">Callback.</param>
public void AddOnFinishCallback(UnityAction callback)
{
if (m_Finish == null)
m_Finish = new FloatFinishCallback();
m_Finish.AddListener(callback);
}
public bool GetIgnoreTimescale()
{
return m_IgnoreTimeScale;
}
public float GetDuration()
{
return m_Duration;
}
public bool ValidTarget()
{
return m_Target != null;
}
/// <summary>
/// Invokes the on finish callback.
/// </summary>
public void Finished()
{
if (m_Finish != null)
m_Finish.Invoke();
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e28e1e9e18f7daa4db5d1ac279d6ce66
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,16 @@
///Credit ChoMPHi
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
using System.Collections;
namespace UnityEngine.UI.Extensions.Tweens
{
internal interface ITweenValue
{
void TweenValue(float floatPercentage);
bool ignoreTimeScale { get; }
float duration { get; }
bool ValidTarget();
void Finished();
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9edf9da4c14ad2843879a2331b00f738
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,63 @@
///Credit ChoMPHi
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
using System.Collections;
namespace UnityEngine.UI.Extensions.Tweens
{
// Tween runner, executes the given tween.
// The coroutine will live within the given
// behaviour container.
internal class TweenRunner<T> where T : struct, ITweenValue
{
protected MonoBehaviour m_CoroutineContainer;
protected IEnumerator m_Tween;
// utility function for starting the tween
private static IEnumerator Start(T tweenInfo)
{
if (!tweenInfo.ValidTarget())
yield break;
float elapsedTime = 0.0f;
while (elapsedTime < tweenInfo.duration)
{
elapsedTime += tweenInfo.ignoreTimeScale ? Time.unscaledDeltaTime : Time.deltaTime;
var percentage = Mathf.Clamp01 (elapsedTime / tweenInfo.duration);
tweenInfo.TweenValue (percentage);
yield return null;
}
tweenInfo.TweenValue (1.0f);
tweenInfo.Finished();
}
public void Init(MonoBehaviour coroutineContainer)
{
m_CoroutineContainer = coroutineContainer;
}
public void StartTween(T info)
{
if (m_CoroutineContainer == null)
{
Debug.LogWarning ("Coroutine container not configured... did you forget to call Init?");
return;
}
if (m_Tween != null)
{
m_CoroutineContainer.StopCoroutine (m_Tween);
m_Tween = null;
}
if (!m_CoroutineContainer.gameObject.activeInHierarchy)
{
info.TweenValue(1.0f);
return;
}
m_Tween = Start (info);
m_CoroutineContainer.StartCoroutine (m_Tween);
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d00ab96853b24074cb837ee70f07dddc
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,361 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
using System;
using UnityEngine.Events;
using UnityEngine.EventSystems;
namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(RectTransform))]
[AddComponentMenu("UI/Extensions/BoxSlider")]
public class BoxSlider : Selectable, IDragHandler, IInitializePotentialDragHandler, ICanvasElement
{
public enum Direction
{
LeftToRight,
RightToLeft,
BottomToTop,
TopToBottom,
}
[Serializable]
public class BoxSliderEvent : UnityEvent<float, float> { }
[SerializeField]
private RectTransform m_HandleRect;
public RectTransform HandleRect { get { return m_HandleRect; } set { if (SetClass(ref m_HandleRect, value)) { UpdateCachedReferences(); UpdateVisuals(); } } }
[Space(6)]
[SerializeField]
private float m_MinValue = 0;
public float MinValue { get { return m_MinValue; } set { if (SetStruct(ref m_MinValue, value)) { SetX(m_ValueX); SetY(m_ValueY); UpdateVisuals(); } } }
[SerializeField]
private float m_MaxValue = 1;
public float MaxValue { get { return m_MaxValue; } set { if (SetStruct(ref m_MaxValue, value)) { SetX(m_ValueX); SetY(m_ValueY); UpdateVisuals(); } } }
[SerializeField]
private bool m_WholeNumbers = false;
public bool WholeNumbers { get { return m_WholeNumbers; } set { if (SetStruct(ref m_WholeNumbers, value)) { SetX(m_ValueX); SetY(m_ValueY); UpdateVisuals(); } } }
[SerializeField]
private float m_ValueX = 1f;
public float ValueX
{
get
{
if (WholeNumbers)
return Mathf.Round(m_ValueX);
return m_ValueX;
}
set
{
SetX(value);
}
}
public float NormalizedValueX
{
get
{
if (Mathf.Approximately(MinValue, MaxValue))
return 0;
return Mathf.InverseLerp(MinValue, MaxValue, ValueX);
}
set
{
this.ValueX = Mathf.Lerp(MinValue, MaxValue, value);
}
}
[SerializeField]
private float m_ValueY = 1f;
public float ValueY
{
get
{
if (WholeNumbers)
return Mathf.Round(m_ValueY);
return m_ValueY;
}
set
{
SetY(value);
}
}
public float NormalizedValueY
{
get
{
if (Mathf.Approximately(MinValue, MaxValue))
return 0;
return Mathf.InverseLerp(MinValue, MaxValue, ValueY);
}
set
{
this.ValueY = Mathf.Lerp(MinValue, MaxValue, value);
}
}
[Space(6)]
// Allow for delegate-based subscriptions for faster events than 'eventReceiver', and allowing for multiple receivers.
[SerializeField]
private BoxSliderEvent m_OnValueChanged = new BoxSliderEvent();
public BoxSliderEvent OnValueChanged { get { return m_OnValueChanged; } set { m_OnValueChanged = value; } }
// Private fields
private Transform m_HandleTransform;
private RectTransform m_HandleContainerRect;
// The offset from handle position to mouse down position
private Vector2 m_Offset = Vector2.zero;
private DrivenRectTransformTracker m_Tracker;
// Size of each step.
float StepSize { get { return WholeNumbers ? 1 : (MaxValue - MinValue) * 0.1f; } }
protected BoxSlider()
{ }
#if UNITY_EDITOR
protected override void OnValidate()
{
base.OnValidate();
if (WholeNumbers)
{
m_MinValue = Mathf.Round(m_MinValue);
m_MaxValue = Mathf.Round(m_MaxValue);
}
UpdateCachedReferences();
SetX(m_ValueX, false);
SetY(m_ValueY, false);
// Update rects since other things might affect them even if value didn't change.
UpdateVisuals();
var prefabType = UnityEditor.PrefabUtility.GetPrefabType(this);
if (prefabType != UnityEditor.PrefabType.Prefab && !Application.isPlaying)
CanvasUpdateRegistry.RegisterCanvasElementForLayoutRebuild(this);
}
#endif // if UNITY_EDITOR
public virtual void Rebuild(CanvasUpdate executing)
{
#if UNITY_EDITOR
if (executing == CanvasUpdate.Prelayout)
OnValueChanged.Invoke(ValueX, ValueY);
#endif
}
public void LayoutComplete()
{
}
public void GraphicUpdateComplete()
{
}
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;
}
public static bool SetStruct<T>(ref T currentValue, T newValue) where T : struct
{
if (currentValue.Equals(newValue))
return false;
currentValue = newValue;
return true;
}
protected override void OnEnable()
{
base.OnEnable();
UpdateCachedReferences();
SetX(m_ValueX, false);
SetY(m_ValueY, false);
// Update rects since they need to be initialized correctly.
UpdateVisuals();
}
protected override void OnDisable()
{
m_Tracker.Clear();
base.OnDisable();
}
void UpdateCachedReferences()
{
if (m_HandleRect)
{
m_HandleTransform = m_HandleRect.transform;
if (m_HandleTransform.parent != null)
m_HandleContainerRect = m_HandleTransform.parent.GetComponent<RectTransform>();
}
else
{
m_HandleContainerRect = null;
}
}
// Set the valueUpdate the visible Image.
void SetX(float input)
{
SetX(input, true);
}
void SetX(float input, bool sendCallback)
{
// Clamp the input
float newValue = Mathf.Clamp(input, MinValue, MaxValue);
if (WholeNumbers)
newValue = Mathf.Round(newValue);
// If the stepped value doesn't match the last one, it's time to update
if (m_ValueX == newValue)
return;
m_ValueX = newValue;
UpdateVisuals();
if (sendCallback)
m_OnValueChanged.Invoke(newValue, ValueY);
}
void SetY(float input)
{
SetY(input, true);
}
void SetY(float input, bool sendCallback)
{
// Clamp the input
float newValue = Mathf.Clamp(input, MinValue, MaxValue);
if (WholeNumbers)
newValue = Mathf.Round(newValue);
// If the stepped value doesn't match the last one, it's time to update
if (m_ValueY == newValue)
return;
m_ValueY = newValue;
UpdateVisuals();
if (sendCallback)
m_OnValueChanged.Invoke(ValueX, newValue);
}
protected override void OnRectTransformDimensionsChange()
{
base.OnRectTransformDimensionsChange();
UpdateVisuals();
}
enum Axis
{
Horizontal = 0,
Vertical = 1
}
// Force-update the slider. Useful if you've changed the properties and want it to update visually.
private void UpdateVisuals()
{
#if UNITY_EDITOR
if (!Application.isPlaying)
UpdateCachedReferences();
#endif
m_Tracker.Clear();
//to business!
if (m_HandleContainerRect != null)
{
m_Tracker.Add(this, m_HandleRect, DrivenTransformProperties.Anchors);
Vector2 anchorMin = Vector2.zero;
Vector2 anchorMax = Vector2.one;
anchorMin[0] = anchorMax[0] = (NormalizedValueX);
anchorMin[1] = anchorMax[1] = (NormalizedValueY);
m_HandleRect.anchorMin = anchorMin;
m_HandleRect.anchorMax = anchorMax;
}
}
// Update the slider's position based on the mouse.
void UpdateDrag(PointerEventData eventData, Camera cam)
{
RectTransform clickRect = m_HandleContainerRect;
if (clickRect != null && clickRect.rect.size[0] > 0)
{
Vector2 localCursor;
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(clickRect, eventData.position, cam, out localCursor))
return;
localCursor -= clickRect.rect.position;
float val = Mathf.Clamp01((localCursor - m_Offset)[0] / clickRect.rect.size[0]);
NormalizedValueX = (val);
float valY = Mathf.Clamp01((localCursor - m_Offset)[1] / clickRect.rect.size[1]);
NormalizedValueY = (valY);
}
}
private bool CanDrag(PointerEventData eventData)
{
return IsActive() && IsInteractable() && eventData.button == PointerEventData.InputButton.Left;
}
public override void OnPointerDown(PointerEventData eventData)
{
if (!CanDrag(eventData))
return;
base.OnPointerDown(eventData);
m_Offset = Vector2.zero;
if (m_HandleContainerRect != null && RectTransformUtility.RectangleContainsScreenPoint(m_HandleRect, eventData.position, eventData.enterEventCamera))
{
Vector2 localMousePos;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_HandleRect, eventData.position, eventData.pressEventCamera, out localMousePos))
m_Offset = localMousePos;
m_Offset.y = -m_Offset.y;
}
else
{
// Outside the slider handle - jump to this point instead
UpdateDrag(eventData, eventData.pressEventCamera);
}
}
public virtual void OnDrag(PointerEventData eventData)
{
if (!CanDrag(eventData))
return;
UpdateDrag(eventData, eventData.pressEventCamera);
}
public virtual void OnInitializePotentialDrag(PointerEventData eventData)
{
eventData.useDragThreshold = false;
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a3fd655d1aa9c684d88cdfdd0da9aa34
timeCreated: 1480011174
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 7ab63fe1b000c254ebed3937038bb01b
folderAsset: yes
timeCreated: 1480011199
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,31 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
using System.Globalization;
namespace UnityEngine.UI.Extensions.ColorPicker
{
[RequireComponent(typeof(Image))]
public class ColorImage : MonoBehaviour
{
public ColorPickerControl picker;
private Image image;
private void Awake()
{
image = GetComponent<Image>();
picker.onValueChanged.AddListener(ColorChanged);
}
private void OnDestroy()
{
picker.onValueChanged.RemoveListener(ColorChanged);
}
private void ColorChanged(Color newColor)
{
image.color = newColor;
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4210a64d2ce72e9488cf2ad174e9df5b
timeCreated: 1480011173
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,88 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
using System.Globalization;
namespace UnityEngine.UI.Extensions.ColorPicker
{
[RequireComponent(typeof(Text))]
public class ColorLabel : MonoBehaviour
{
public ColorPickerControl picker;
public ColorValues type;
public string prefix = "R: ";
public float minValue = 0;
public float maxValue = 255;
public int precision = 0;
private Text label;
private void Awake()
{
label = GetComponent<Text>();
}
private void OnEnable()
{
if (Application.isPlaying && picker != null)
{
picker.onValueChanged.AddListener(ColorChanged);
picker.onHSVChanged.AddListener(HSVChanged);
}
}
private void OnDestroy()
{
if (picker != null)
{
picker.onValueChanged.RemoveListener(ColorChanged);
picker.onHSVChanged.RemoveListener(HSVChanged);
}
}
#if UNITY_EDITOR
private void OnValidate()
{
label = GetComponent<Text>();
UpdateValue();
}
#endif
private void ColorChanged(Color color)
{
UpdateValue();
}
private void HSVChanged(float hue, float sateration, float value)
{
UpdateValue();
}
private void UpdateValue()
{
if (picker == null)
{
label.text = prefix + "-";
}
else
{
float value = minValue + (picker.GetValue(type) * (maxValue - minValue));
label.text = prefix + ConvertToDisplayString(value);
}
}
private string ConvertToDisplayString(float value)
{
if (precision > 0)
return value.ToString("f " + precision);
else
return Mathf.FloorToInt(value).ToString();
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b32edf53f1ae84f479c9439b4b5f5b91
timeCreated: 1480011174
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,261 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
namespace UnityEngine.UI.Extensions.ColorPicker
{
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 _alpha = 1;
public Image SVHandle;
public ColorChangedEvent onValueChanged = new ColorChangedEvent();
public HSVChangedEvent onHSVChanged = new HSVChangedEvent();
public Color CurrentColor
{
get
{
return new Color(_red, _green, _blue, _alpha);
}
set
{
if (CurrentColor == value)
return;
_red = value.r;
_green = value.g;
_blue = value.b;
_alpha = value.a;
RGBChanged();
SendChangedEvent();
}
}
private void Start()
{
SendChangedEvent();
}
public float H
{
get
{
return _hue;
}
set
{
if (_hue == value)
return;
_hue = value;
HSVChanged();
SendChangedEvent();
}
}
public float S
{
get
{
return _saturation;
}
set
{
if (_saturation == value)
return;
_saturation = value;
HSVChanged();
SendChangedEvent();
}
}
public float V
{
get
{
return _brightness;
}
set
{
if (_brightness == value)
return;
_brightness = value;
HSVChanged();
SendChangedEvent();
}
}
public float R
{
get
{
return _red;
}
set
{
if (_red == value)
return;
_red = value;
RGBChanged();
SendChangedEvent();
}
}
public float G
{
get
{
return _green;
}
set
{
if (_green == value)
return;
_green = value;
RGBChanged();
SendChangedEvent();
}
}
public float B
{
get
{
return _blue;
}
set
{
if (_blue == value)
return;
_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);
SVHandle.color = color;
_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("");
}
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7e448480810b55843aefa91c1ab74cd2
timeCreated: 1483197306
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,49 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
using System.Globalization;
namespace UnityEngine.UI.Extensions.ColorPicker
{
public class ColorPickerPresets : MonoBehaviour
{
public ColorPickerControl picker;
public GameObject[] presets;
public Image createPresetImage;
void Awake()
{
// picker.onHSVChanged.AddListener(HSVChanged);
picker.onValueChanged.AddListener(ColorChanged);
}
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;
}
}
}
public void PresetSelect(Image sender)
{
picker.CurrentColor = sender.color;
}
// 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;
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 502205da447ca7a479ce5ae45e5c19d2
timeCreated: 1480011173
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,93 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
namespace UnityEngine.UI.Extensions.ColorPicker
{
/// <summary>
/// Displays one of the color values of aColorPicker
/// </summary>
[RequireComponent(typeof(Slider))]
public class ColorSlider : MonoBehaviour
{
public ColorPickerControl ColorPicker;
/// <summary>
/// Which value this slider can edit.
/// </summary>
public ColorValues type;
private Slider slider;
private bool listen = true;
private void Awake()
{
slider = GetComponent<Slider>();
ColorPicker.onValueChanged.AddListener(ColorChanged);
ColorPicker.onHSVChanged.AddListener(HSVChanged);
slider.onValueChanged.AddListener(SliderChanged);
}
private void OnDestroy()
{
ColorPicker.onValueChanged.RemoveListener(ColorChanged);
ColorPicker.onHSVChanged.RemoveListener(HSVChanged);
slider.onValueChanged.RemoveListener(SliderChanged);
}
private void ColorChanged(Color newColor)
{
listen = false;
switch (type)
{
case ColorValues.R:
slider.normalizedValue = newColor.r;
break;
case ColorValues.G:
slider.normalizedValue = newColor.g;
break;
case ColorValues.B:
slider.normalizedValue = newColor.b;
break;
case ColorValues.A:
slider.normalizedValue = newColor.a;
break;
default:
break;
}
}
private void HSVChanged(float hue, float saturation, float value)
{
listen = false;
switch (type)
{
case ColorValues.Hue:
slider.normalizedValue = hue; //1 - hue;
break;
case ColorValues.Saturation:
slider.normalizedValue = saturation;
break;
case ColorValues.Value:
slider.normalizedValue = value;
break;
default:
break;
}
}
private void SliderChanged(float newValue)
{
if (listen)
{
newValue = slider.normalizedValue;
//if (type == ColorValues.Hue)
// newValue = 1 - newValue;
ColorPicker.AssignColor(type, newValue);
}
listen = true;
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 91558da930270ac4a960ba03b81c836a
timeCreated: 1480011173
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,231 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
namespace UnityEngine.UI.Extensions.ColorPicker
{
[RequireComponent(typeof(RawImage)), ExecuteInEditMode()]
public class ColorSliderImage : MonoBehaviour
{
public ColorPickerControl picker;
/// <summary>
/// Which value this slider can edit.
/// </summary>
public ColorValues type;
public Slider.Direction direction;
private RawImage image;
private RectTransform RectTransform
{
get
{
return transform as RectTransform;
}
}
private void Awake()
{
image = GetComponent<RawImage>();
if (image)
{
RegenerateTexture();
}
else
{
Debug.LogWarning("Missing RawImage on object [" + name + "]");
}
}
private void OnEnable()
{
if (picker != null && Application.isPlaying)
{
picker.onValueChanged.AddListener(ColorChanged);
picker.onHSVChanged.AddListener(ColorChanged);
}
}
private void OnDisable()
{
if (picker != null)
{
picker.onValueChanged.RemoveListener(ColorChanged);
picker.onHSVChanged.RemoveListener(ColorChanged);
}
}
private void OnDestroy()
{
if (image.texture != null)
DestroyImmediate(image.texture);
}
#if UNITY_EDITOR
private void OnValidate()
{
image = GetComponent<RawImage>();
if (image)
{
RegenerateTexture();
}
else
{
Debug.LogWarning("Missing RawImage on object [" + name + "]");
}
}
#endif
private void ColorChanged(Color newColor)
{
switch (type)
{
case ColorValues.R:
case ColorValues.G:
case ColorValues.B:
case ColorValues.Saturation:
case ColorValues.Value:
RegenerateTexture();
break;
case ColorValues.A:
case ColorValues.Hue:
default:
break;
}
}
private void ColorChanged(float hue, float saturation, float value)
{
switch (type)
{
case ColorValues.R:
case ColorValues.G:
case ColorValues.B:
case ColorValues.Saturation:
case ColorValues.Value:
RegenerateTexture();
break;
case ColorValues.A:
case ColorValues.Hue:
default:
break;
}
}
private void RegenerateTexture()
{
if (!picker)
{
Debug.LogWarning("Missing Picker on object [" + name + "]");
}
Color32 baseColor = picker != null ? picker.CurrentColor : Color.black;
float h = picker != null ? picker.H : 0;
float s = picker != null ? picker.S : 0;
float v = picker != null ? picker.V : 0;
Texture2D texture;
Color32[] colors;
bool vertical = direction == Slider.Direction.BottomToTop || direction == Slider.Direction.TopToBottom;
bool inverted = direction == Slider.Direction.TopToBottom || direction == Slider.Direction.RightToLeft;
int size;
switch (type)
{
case ColorValues.R:
case ColorValues.G:
case ColorValues.B:
case ColorValues.A:
size = 255;
break;
case ColorValues.Hue:
size = 360;
break;
case ColorValues.Saturation:
case ColorValues.Value:
size = 100;
break;
default:
throw new System.NotImplementedException("");
}
if (vertical)
texture = new Texture2D(1, size);
else
texture = new Texture2D(size, 1);
texture.hideFlags = HideFlags.DontSave;
colors = new Color32[size];
switch (type)
{
case ColorValues.R:
for (byte i = 0; i < size; i++)
{
colors[inverted ? size - 1 - i : i] = new Color32(i, baseColor.g, baseColor.b, 255);
}
break;
case ColorValues.G:
for (byte i = 0; i < size; i++)
{
colors[inverted ? size - 1 - i : i] = new Color32(baseColor.r, i, baseColor.b, 255);
}
break;
case ColorValues.B:
for (byte i = 0; i < size; i++)
{
colors[inverted ? size - 1 - i : i] = new Color32(baseColor.r, baseColor.g, i, 255);
}
break;
case ColorValues.A:
for (byte i = 0; i < size; i++)
{
colors[inverted ? size - 1 - i : i] = new Color32(i, i, i, 255);
}
break;
case ColorValues.Hue:
for (int i = 0; i < size; i++)
{
colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(i, 1, 1, 1);
}
break;
case ColorValues.Saturation:
for (int i = 0; i < size; i++)
{
colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(h * 360, (float)i / size, v, 1);
}
break;
case ColorValues.Value:
for (int i = 0; i < size; i++)
{
colors[inverted ? size - 1 - i : i] = HSVUtil.ConvertHsvToRgb(h * 360, s, (float)i / size, 1);
}
break;
default:
throw new System.NotImplementedException("");
}
texture.SetPixels32(colors);
texture.Apply();
if (image.texture != null)
DestroyImmediate(image.texture);
image.texture = texture;
switch (direction)
{
case Slider.Direction.BottomToTop:
case Slider.Direction.TopToBottom:
image.uvRect = new Rect(0, 0, 2, 1);
break;
case Slider.Direction.LeftToRight:
case Slider.Direction.RightToLeft:
image.uvRect = new Rect(0, 0, 1, 2);
break;
default:
break;
}
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cd3cce5a27f2db94fa394c4719bddecd
timeCreated: 1480011174
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,17 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
namespace UnityEngine.UI.Extensions.ColorPicker
{
public enum ColorValues
{
R,
G,
B,
A,
Hue,
Saturation,
Value
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0f473590aed5e3f4ab5a0157b2a53dbd
timeCreated: 1480011173
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,101 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
using System.Globalization;
namespace UnityEngine.UI.Extensions.ColorPicker
{
[RequireComponent(typeof(InputField))]
public class HexColorField : MonoBehaviour
{
public ColorPickerControl ColorPicker;
public bool displayAlpha;
private InputField hexInputField;
private const string hexRegex = "^#?(?:[0-9a-fA-F]{3,4}){1,2}$";
private void Awake()
{
hexInputField = GetComponent<InputField>();
// Add listeners to keep text (and color) up to date
hexInputField.onEndEdit.AddListener(UpdateColor);
ColorPicker.onValueChanged.AddListener(UpdateHex);
}
private void OnDestroy()
{
hexInputField.onValueChanged.RemoveListener(UpdateColor);
ColorPicker.onValueChanged.RemoveListener(UpdateHex);
}
private void UpdateHex(Color newColor)
{
hexInputField.text = ColorToHex(newColor);
}
private void UpdateColor(string newHex)
{
Color32 color;
if (HexToColor(newHex, out color))
ColorPicker.CurrentColor = color;
else
Debug.Log("hex value is in the wrong format, valid formats are: #RGB, #RGBA, #RRGGBB and #RRGGBBAA (# is optional)");
}
private string ColorToHex(Color32 color)
{
if (displayAlpha)
return string.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", color.r, color.g, color.b, color.a);
else
return string.Format("#{0:X2}{1:X2}{2:X2}", color.r, color.g, color.b);
}
public static bool HexToColor(string hex, out Color32 color)
{
// Check if this is a valid hex string (# is optional)
if (System.Text.RegularExpressions.Regex.IsMatch(hex, hexRegex))
{
int startIndex = hex.StartsWith("#") ? 1 : 0;
if (hex.Length == startIndex + 8) //#RRGGBBAA
{
color = new Color32(byte.Parse(hex.Substring(startIndex, 2), NumberStyles.AllowHexSpecifier),
byte.Parse(hex.Substring(startIndex + 2, 2), NumberStyles.AllowHexSpecifier),
byte.Parse(hex.Substring(startIndex + 4, 2), NumberStyles.AllowHexSpecifier),
byte.Parse(hex.Substring(startIndex + 6, 2), NumberStyles.AllowHexSpecifier));
}
else if (hex.Length == startIndex + 6) //#RRGGBB
{
color = new Color32(byte.Parse(hex.Substring(startIndex, 2), NumberStyles.AllowHexSpecifier),
byte.Parse(hex.Substring(startIndex + 2, 2), NumberStyles.AllowHexSpecifier),
byte.Parse(hex.Substring(startIndex + 4, 2), NumberStyles.AllowHexSpecifier),
255);
}
else if (hex.Length == startIndex + 4) //#RGBA
{
color = new Color32(byte.Parse("" + hex[startIndex] + hex[startIndex], NumberStyles.AllowHexSpecifier),
byte.Parse("" + hex[startIndex + 1] + hex[startIndex + 1], NumberStyles.AllowHexSpecifier),
byte.Parse("" + hex[startIndex + 2] + hex[startIndex + 2], NumberStyles.AllowHexSpecifier),
byte.Parse("" + hex[startIndex + 3] + hex[startIndex + 3], NumberStyles.AllowHexSpecifier));
}
else //#RGB
{
color = new Color32(byte.Parse("" + hex[startIndex] + hex[startIndex], NumberStyles.AllowHexSpecifier),
byte.Parse("" + hex[startIndex + 1] + hex[startIndex + 1], NumberStyles.AllowHexSpecifier),
byte.Parse("" + hex[startIndex + 2] + hex[startIndex + 2], NumberStyles.AllowHexSpecifier),
255);
}
return true;
}
else
{
color = new Color32();
return false;
}
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7343402602909bd4f928d58433c5c87f
timeCreated: 1480011173
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,124 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
using System.Globalization;
namespace UnityEngine.UI.Extensions.ColorPicker
{
[RequireComponent(typeof(BoxSlider), typeof(RawImage)), ExecuteInEditMode()]
public class SVBoxSlider : MonoBehaviour
{
public ColorPickerControl picker;
private BoxSlider slider;
private RawImage image;
private float lastH = -1;
private bool listen = true;
public RectTransform RectTransform
{
get
{
return transform as RectTransform;
}
}
private void Awake()
{
slider = GetComponent<BoxSlider>();
image = GetComponent<RawImage>();
RegenerateSVTexture();
}
private void OnEnable()
{
if (Application.isPlaying && picker != null)
{
slider.OnValueChanged.AddListener(SliderChanged);
picker.onHSVChanged.AddListener(HSVChanged);
}
}
private void OnDisable()
{
if (picker != null)
{
slider.OnValueChanged.RemoveListener(SliderChanged);
picker.onHSVChanged.RemoveListener(HSVChanged);
}
}
private void OnDestroy()
{
if (image.texture != null)
DestroyImmediate(image.texture);
}
#if UNITY_EDITOR
private void OnValidate()
{
image = GetComponent<RawImage>();
RegenerateSVTexture();
}
#endif
private void SliderChanged(float saturation, float value)
{
if (listen)
{
picker.AssignColor(ColorValues.Saturation, saturation);
picker.AssignColor(ColorValues.Value, value);
}
listen = true;
}
private void HSVChanged(float h, float s, float v)
{
if (lastH != h)
{
lastH = h;
RegenerateSVTexture();
}
if (s != slider.NormalizedValueX)
{
listen = false;
slider.NormalizedValueX = s;
}
if (v != slider.NormalizedValueY)
{
listen = false;
slider.NormalizedValueY = v;
}
}
private void RegenerateSVTexture()
{
double h = picker != null ? picker.H * 360 : 0;
if (image.texture != null)
DestroyImmediate(image.texture);
Texture2D texture = new Texture2D(128, 128)
{
hideFlags = HideFlags.DontSave,
wrapMode = TextureWrapMode.Clamp
};
for (int s = 0; s < 128; s++)
{
Color32[] colors = new Color32[128];
for (int v = 0; v < 128; v++)
{
colors[v] = HSVUtil.ConvertHsvToRgb(h, (float)s / 128, (float)v / 128, 1);
}
texture.SetPixels32(s, 0, 1, 128, colors);
}
texture.Apply();
image.texture = texture;
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7a0647785ed421e449239dbd6512e156
timeCreated: 1480011173
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,35 @@
///Credit judah4
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
using System.Globalization;
namespace UnityEngine.UI.Extensions
{
public class TiltWindow : MonoBehaviour
{
public Vector2 range = new Vector2(5f, 3f);
Transform mTrans;
Quaternion mStart;
Vector2 mRot = Vector2.zero;
void Start ()
{
mTrans = transform;
mStart = mTrans.localRotation;
}
void Update ()
{
Vector3 pos = Input.mousePosition;
float halfWidth = Screen.width * 0.5f;
float halfHeight = Screen.height * 0.5f;
float x = Mathf.Clamp((pos.x - halfWidth) / halfWidth, -1f, 1f);
float y = Mathf.Clamp((pos.y - halfHeight) / halfHeight, -1f, 1f);
mRot = Vector2.Lerp(mRot, new Vector2(x, y), Time.deltaTime * 5f);
mTrans.localRotation = mStart * Quaternion.Euler(-mRot.y * range.y, mRot.x * range.x, 0f);
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c7be5109ea5b91e4b856621023b15168
timeCreated: 1480011174
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 726a11b8d64fa0143b34f417f5453f80
folderAsset: yes
DefaultImporter:
userData:

View file

@ -0,0 +1,344 @@
///Credit perchik
///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/
using System.Collections.Generic;
using System.Linq;
namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(RectTransform))]
[AddComponentMenu("UI/Extensions/AutoComplete ComboBox")]
public class AutoCompleteComboBox : MonoBehaviour
{
public Color disabledTextColor;
public DropDownListItem SelectedItem { get; private set; } //outside world gets to get this, not set it
public List<string> AvailableOptions;
public System.Action<int> OnSelectionChanged; // fires when selection is changed;
//private bool isInitialized = false;
private bool _isPanelActive = false;
private bool _hasDrawnOnce = false;
private InputField _mainInput;
private RectTransform _inputRT;
private RectTransform _rectTransform;
private RectTransform _overlayRT;
private RectTransform _scrollPanelRT;
private RectTransform _scrollBarRT;
private RectTransform _slidingAreaRT;
// private RectTransform scrollHandleRT;
private RectTransform _itemsPanelRT;
private Canvas _canvas;
private RectTransform _canvasRT;
private ScrollRect _scrollRect;
private List<string> _panelItems; //items that will get shown in the dropdown
private List<string> _prunedPanelItems; //items that used to show in the dropdown
private Dictionary<string, GameObject> panelObjects;
private GameObject itemTemplate;
public string Text { get; private set; }
[SerializeField]
private float _scrollBarWidth = 20.0f;
public float ScrollBarWidth
{
get { return _scrollBarWidth; }
set
{
_scrollBarWidth = value;
RedrawPanel();
}
}
// private int scrollOffset; //offset of the selected item
// private int _selectedIndex = 0;
[SerializeField]
private int _itemsToDisplay;
public int ItemsToDisplay
{
get { return _itemsToDisplay; }
set
{
_itemsToDisplay = value;
RedrawPanel();
}
}
public void Awake()
{
Initialize();
}
private bool Initialize()
{
bool success = true;
try
{
_rectTransform = GetComponent<RectTransform>();
_inputRT = _rectTransform.Find("InputField").GetComponent<RectTransform>();
_mainInput = _inputRT.GetComponent<InputField>();
_overlayRT = _rectTransform.Find("Overlay").GetComponent<RectTransform>();
_overlayRT.gameObject.SetActive(false);
_scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>();
_scrollBarRT = _scrollPanelRT.Find("Scrollbar").GetComponent<RectTransform>();
_slidingAreaRT = _scrollBarRT.Find("SlidingArea").GetComponent<RectTransform>();
// scrollHandleRT = slidingAreaRT.FindChild("Handle").GetComponent<RectTransform>();
_itemsPanelRT = _scrollPanelRT.Find("Items").GetComponent<RectTransform>();
//itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>();
_canvas = GetComponentInParent<Canvas>();
_canvasRT = _canvas.GetComponent<RectTransform>();
_scrollRect = _scrollPanelRT.GetComponent<ScrollRect>();
_scrollRect.scrollSensitivity = _rectTransform.sizeDelta.y / 2;
_scrollRect.movementType = ScrollRect.MovementType.Clamped;
_scrollRect.content = _itemsPanelRT;
itemTemplate = _rectTransform.Find("ItemTemplate").gameObject;
itemTemplate.SetActive(false);
}
catch (System.NullReferenceException ex)
{
Debug.LogException(ex);
Debug.LogError("Something is setup incorrectly with the dropdownlist component causing a Null Refernece Exception");
success = false;
}
panelObjects = new Dictionary<string, GameObject>();
_prunedPanelItems = new List<string>();
_panelItems = AvailableOptions.ToList();
RebuildPanel();
//RedrawPanel(); - causes an initialisation failure in U5
return success;
}
/* currently just using items in the list instead of being able to add to it.
public void AddItems(params object[] list)
{
List<DropDownListItem> ddItems = new List<DropDownListItem>();
foreach (var obj in list)
{
if (obj is DropDownListItem)
{
ddItems.Add((DropDownListItem)obj);
}
else if (obj is string)
{
ddItems.Add(new DropDownListItem(caption: (string)obj));
}
else if (obj is Sprite)
{
ddItems.Add(new DropDownListItem(image: (Sprite)obj));
}
else
{
throw new System.Exception("Only ComboBoxItems, Strings, and Sprite types are allowed");
}
}
Items.AddRange(ddItems);
Items = Items.Distinct().ToList();//remove any duplicates
RebuildPanel();
}
*/
/// <summary>
/// Rebuilds the contents of the panel in response to items being added.
/// </summary>
private void RebuildPanel()
{
//panel starts with all options
_panelItems.Clear();
foreach (string option in AvailableOptions)
{
_panelItems.Add(option.ToLower());
}
_panelItems.Sort();
_prunedPanelItems.Clear();
List<GameObject> itemObjs = new List<GameObject>(panelObjects.Values);
panelObjects.Clear();
int indx = 0;
while (itemObjs.Count < AvailableOptions.Count)
{
GameObject newItem = Instantiate(itemTemplate) as GameObject;
newItem.name = "Item " + indx;
newItem.transform.SetParent(_itemsPanelRT, false);
itemObjs.Add(newItem);
indx++;
}
for (int i = 0; i < itemObjs.Count; i++)
{
itemObjs[i].SetActive(i <= AvailableOptions.Count);
if (i < AvailableOptions.Count)
{
itemObjs[i].name = "Item " + i + " " + _panelItems[i];
itemObjs[i].transform.Find("Text").GetComponent<Text>().text = _panelItems[i]; //set the text value
Button itemBtn = itemObjs[i].GetComponent<Button>();
itemBtn.onClick.RemoveAllListeners();
string textOfItem = _panelItems[i]; //has to be copied for anonymous function or it gets garbage collected away
itemBtn.onClick.AddListener(() =>
{
OnItemClicked(textOfItem);
});
panelObjects[_panelItems[i]] = itemObjs[i];
}
}
}
/// <summary>
/// what happens when an item in the list is selected
/// </summary>
/// <param name="item"></param>
private void OnItemClicked(string item)
{
//Debug.Log("item " + item + " clicked");
Text = item;
_mainInput.text = Text;
ToggleDropdownPanel(true);
}
//private void UpdateSelected()
//{
// SelectedItem = (_selectedIndex > -1 && _selectedIndex < Items.Count) ? Items[_selectedIndex] : null;
// if (SelectedItem == null) return;
// bool hasImage = SelectedItem.Image != null;
// if (hasImage)
// {
// mainButton.img.sprite = SelectedItem.Image;
// mainButton.img.color = Color.white;
// //if (Interactable) mainButton.img.color = Color.white;
// //else mainButton.img.color = new Color(1, 1, 1, .5f);
// }
// else
// {
// mainButton.img.sprite = null;
// }
// mainButton.txt.text = SelectedItem.Caption;
// //update selected index color
// for (int i = 0; i < itemsPanelRT.childCount; i++)
// {
// panelItems[i].btnImg.color = (_selectedIndex == i) ? mainButton.btn.colors.highlightedColor : new Color(0, 0, 0, 0);
// }
//}
private void RedrawPanel()
{
float scrollbarWidth = _panelItems.Count > ItemsToDisplay ? _scrollBarWidth : 0f;//hide the scrollbar if there's not enough items
_scrollBarRT.gameObject.SetActive(_panelItems.Count > ItemsToDisplay);
if (!_hasDrawnOnce || _rectTransform.sizeDelta != _inputRT.sizeDelta)
{
_hasDrawnOnce = true;
_inputRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
_inputRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _rectTransform.sizeDelta.y);
_scrollPanelRT.SetParent(transform, true);//break the scroll panel from the overlay
_scrollPanelRT.anchoredPosition = new Vector2(0, -_rectTransform.sizeDelta.y); //anchor it to the bottom of the button
//make the overlay fill the screen
_overlayRT.SetParent(_canvas.transform, false); //attach it to top level object
_overlayRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _canvasRT.sizeDelta.x);
_overlayRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _canvasRT.sizeDelta.y);
_overlayRT.SetParent(transform, true);//reattach to this object
_scrollPanelRT.SetParent(_overlayRT, true); //reattach the scrollpanel to the overlay
}
if (_panelItems.Count < 1) return;
float dropdownHeight = _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, _panelItems.Count);
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
_itemsPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _scrollPanelRT.sizeDelta.x - scrollbarWidth - 5);
_itemsPanelRT.anchoredPosition = new Vector2(5, 0);
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - _scrollBarRT.sizeDelta.x);
}
public void OnValueChanged(string currText)
{
Text = currText;
PruneItems(currText);
RedrawPanel();
//Debug.Log("value changed to: " + currText);
if (_panelItems.Count == 0)
{
_isPanelActive = true;//this makes it get turned off
ToggleDropdownPanel(false);
}
else if (!_isPanelActive)
{
ToggleDropdownPanel(false);
}
}
/// <summary>
/// Toggle the drop down list
/// </summary>
/// <param name="directClick"> whether an item was directly clicked on</param>
public void ToggleDropdownPanel(bool directClick)
{
_isPanelActive = !_isPanelActive;
_overlayRT.gameObject.SetActive(_isPanelActive);
if (_isPanelActive)
{
transform.SetAsLastSibling();
}
else if (directClick)
{
// scrollOffset = Mathf.RoundToInt(itemsPanelRT.anchoredPosition.y / _rectTransform.sizeDelta.y);
}
}
private void PruneItems(string currText)
{
List<string> notToPrune = _panelItems.Where(x => x.ToLower().Contains(currText.ToLower())).ToList();
List<string> toPrune = _panelItems.Except(notToPrune).ToList();
foreach (string key in toPrune)
{
// Debug.Log("pruning key " + key);
panelObjects[key].SetActive(false);
_panelItems.Remove(key);
_prunedPanelItems.Add(key);
}
List<string> toAddBack = _prunedPanelItems.Where(x => x.ToLower().Contains(currText)).ToList();
foreach (string key in toAddBack)
{
// Debug.Log("adding back key " + key);
panelObjects[key].SetActive(true);
_panelItems.Add(key);
_prunedPanelItems.Remove(key);
}
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ef22b091ebae52c47aa3e86ad9040c05
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,318 @@
///Credit perchik
///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/
using System.Collections.Generic;
using System.Linq;
namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(RectTransform))]
[AddComponentMenu("UI/Extensions/ComboBox")]
public class ComboBox : MonoBehaviour
{
public Color disabledTextColor;
public DropDownListItem SelectedItem { get; private set; } //outside world gets to get this, not set it
public List<string> AvailableOptions;
public System.Action<int> OnSelectionChanged; // fires when selection is changed;
//private bool isInitialized = false;
private bool _isPanelActive = false;
private bool _hasDrawnOnce = false;
private InputField _mainInput;
private RectTransform _inputRT;
private RectTransform _rectTransform;
private RectTransform _overlayRT;
private RectTransform _scrollPanelRT;
private RectTransform _scrollBarRT;
private RectTransform _slidingAreaRT;
// private RectTransform scrollHandleRT;
private RectTransform _itemsPanelRT;
private Canvas _canvas;
private RectTransform _canvasRT;
private ScrollRect _scrollRect;
private List<string> _panelItems; //items that will get shown in the dropdown
private Dictionary<string, GameObject> panelObjects;
private GameObject itemTemplate;
public string Text { get; private set; }
[SerializeField]
private float _scrollBarWidth = 20.0f;
public float ScrollBarWidth
{
get { return _scrollBarWidth; }
set
{
_scrollBarWidth = value;
RedrawPanel();
}
}
// private int scrollOffset; //offset of the selected item
// private int _selectedIndex = 0;
[SerializeField]
private int _itemsToDisplay;
public int ItemsToDisplay
{
get { return _itemsToDisplay; }
set
{
_itemsToDisplay = value;
RedrawPanel();
}
}
public void Awake()
{
Initialize();
}
private bool Initialize()
{
bool success = true;
try
{
_rectTransform = GetComponent<RectTransform>();
_inputRT = _rectTransform.Find("InputField").GetComponent<RectTransform>();
_mainInput = _inputRT.GetComponent<InputField>();
_overlayRT = _rectTransform.Find("Overlay").GetComponent<RectTransform>();
_overlayRT.gameObject.SetActive(false);
_scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>();
_scrollBarRT = _scrollPanelRT.Find("Scrollbar").GetComponent<RectTransform>();
_slidingAreaRT = _scrollBarRT.Find("SlidingArea").GetComponent<RectTransform>();
// scrollHandleRT = slidingAreaRT.FindChild("Handle").GetComponent<RectTransform>();
_itemsPanelRT = _scrollPanelRT.Find("Items").GetComponent<RectTransform>();
//itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>();
_canvas = GetComponentInParent<Canvas>();
_canvasRT = _canvas.GetComponent<RectTransform>();
_scrollRect = _scrollPanelRT.GetComponent<ScrollRect>();
_scrollRect.scrollSensitivity = _rectTransform.sizeDelta.y / 2;
_scrollRect.movementType = ScrollRect.MovementType.Clamped;
_scrollRect.content = _itemsPanelRT;
itemTemplate = _rectTransform.Find("ItemTemplate").gameObject;
itemTemplate.SetActive(false);
}
catch (System.NullReferenceException ex)
{
Debug.LogException(ex);
Debug.LogError("Something is setup incorrectly with the dropdownlist component causing a Null Refernece Exception");
success = false;
}
panelObjects = new Dictionary<string, GameObject>();
_panelItems = AvailableOptions.ToList();
RebuildPanel();
//RedrawPanel(); - causes an initialisation failure in U5
return success;
}
/* currently just using items in the list instead of being able to add to it.
public void AddItems(params object[] list)
{
List<DropDownListItem> ddItems = new List<DropDownListItem>();
foreach (var obj in list)
{
if (obj is DropDownListItem)
{
ddItems.Add((DropDownListItem)obj);
}
else if (obj is string)
{
ddItems.Add(new DropDownListItem(caption: (string)obj));
}
else if (obj is Sprite)
{
ddItems.Add(new DropDownListItem(image: (Sprite)obj));
}
else
{
throw new System.Exception("Only ComboBoxItems, Strings, and Sprite types are allowed");
}
}
Items.AddRange(ddItems);
Items = Items.Distinct().ToList();//remove any duplicates
RebuildPanel();
}
*/
/// <summary>
/// Rebuilds the contents of the panel in response to items being added.
/// </summary>
private void RebuildPanel()
{
//panel starts with all options
_panelItems.Clear();
foreach (string option in AvailableOptions)
{
_panelItems.Add(option.ToLower());
}
_panelItems.Sort();
List<GameObject> itemObjs = new List<GameObject>(panelObjects.Values);
panelObjects.Clear();
int indx = 0;
while (itemObjs.Count < AvailableOptions.Count)
{
GameObject newItem = Instantiate(itemTemplate) as GameObject;
newItem.name = "Item " + indx;
newItem.transform.SetParent(_itemsPanelRT, false);
itemObjs.Add(newItem);
indx++;
}
for (int i = 0; i < itemObjs.Count; i++)
{
itemObjs[i].SetActive(i <= AvailableOptions.Count);
if (i < AvailableOptions.Count)
{
itemObjs[i].name = "Item " + i + " " + _panelItems[i];
itemObjs[i].transform.Find("Text").GetComponent<Text>().text = _panelItems[i]; //set the text value
Button itemBtn = itemObjs[i].GetComponent<Button>();
itemBtn.onClick.RemoveAllListeners();
string textOfItem = _panelItems[i]; //has to be copied for anonymous function or it gets garbage collected away
itemBtn.onClick.AddListener(() =>
{
OnItemClicked(textOfItem);
});
panelObjects[_panelItems[i]] = itemObjs[i];
}
}
}
/// <summary>
/// what happens when an item in the list is selected
/// </summary>
/// <param name="item"></param>
private void OnItemClicked(string item)
{
//Debug.Log("item " + item + " clicked");
Text = item;
_mainInput.text = Text;
ToggleDropdownPanel(true);
}
//private void UpdateSelected()
//{
// SelectedItem = (_selectedIndex > -1 && _selectedIndex < Items.Count) ? Items[_selectedIndex] : null;
// if (SelectedItem == null) return;
// bool hasImage = SelectedItem.Image != null;
// if (hasImage)
// {
// mainButton.img.sprite = SelectedItem.Image;
// mainButton.img.color = Color.white;
// //if (Interactable) mainButton.img.color = Color.white;
// //else mainButton.img.color = new Color(1, 1, 1, .5f);
// }
// else
// {
// mainButton.img.sprite = null;
// }
// mainButton.txt.text = SelectedItem.Caption;
// //update selected index color
// for (int i = 0; i < itemsPanelRT.childCount; i++)
// {
// panelItems[i].btnImg.color = (_selectedIndex == i) ? mainButton.btn.colors.highlightedColor : new Color(0, 0, 0, 0);
// }
//}
private void RedrawPanel()
{
float scrollbarWidth = _panelItems.Count > ItemsToDisplay ? _scrollBarWidth : 0f;//hide the scrollbar if there's not enough items
_scrollBarRT.gameObject.SetActive(_panelItems.Count > ItemsToDisplay);
if (!_hasDrawnOnce || _rectTransform.sizeDelta != _inputRT.sizeDelta)
{
_hasDrawnOnce = true;
_inputRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
_inputRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _rectTransform.sizeDelta.y);
_scrollPanelRT.SetParent(transform, true);//break the scroll panel from the overlay
_scrollPanelRT.anchoredPosition = new Vector2(0, -_rectTransform.sizeDelta.y); //anchor it to the bottom of the button
//make the overlay fill the screen
_overlayRT.SetParent(_canvas.transform, false); //attach it to top level object
_overlayRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _canvasRT.sizeDelta.x);
_overlayRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _canvasRT.sizeDelta.y);
_overlayRT.SetParent(transform, true);//reattach to this object
_scrollPanelRT.SetParent(_overlayRT, true); //reattach the scrollpanel to the overlay
}
if (_panelItems.Count < 1) return;
float dropdownHeight = _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, _panelItems.Count);
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
_itemsPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _scrollPanelRT.sizeDelta.x - scrollbarWidth - 5);
_itemsPanelRT.anchoredPosition = new Vector2(5, 0);
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - _scrollBarRT.sizeDelta.x);
}
public void OnValueChanged(string currText)
{
Text = currText;
RedrawPanel();
//Debug.Log("value changed to: " + currText);
if (_panelItems.Count == 0)
{
_isPanelActive = true;//this makes it get turned off
ToggleDropdownPanel(false);
}
else if (!_isPanelActive)
{
ToggleDropdownPanel(false);
}
}
/// <summary>
/// Toggle the drop down list
/// </summary>
/// <param name="directClick"> whether an item was directly clicked on</param>
public void ToggleDropdownPanel(bool directClick)
{
_isPanelActive = !_isPanelActive;
_overlayRT.gameObject.SetActive(_isPanelActive);
if (_isPanelActive)
{
transform.SetAsLastSibling();
}
else if (directClick)
{
// scrollOffset = Mathf.RoundToInt(itemsPanelRT.anchoredPosition.y / _rectTransform.sizeDelta.y);
}
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: cd26acd32e1be2747b9e5f3587b2b1d5
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,299 @@
///Credit perchik
///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/
using System.Collections.Generic;
namespace UnityEngine.UI.Extensions
{
/// <summary>
/// Extension to the UI class which creates a dropdown list
/// </summary>
[RequireComponent(typeof(RectTransform))]
[AddComponentMenu("UI/Extensions/Dropdown List")]
public class DropDownList : MonoBehaviour
{
public Color disabledTextColor;
public DropDownListItem SelectedItem { get; private set; } //outside world gets to get this, not set it
public List<DropDownListItem> Items;
public System.Action<int> OnSelectionChanged; // fires when selection is changed;
public bool OverrideHighlighted = true;
//private bool isInitialized = false;
private bool _isPanelActive = false;
private bool _hasDrawnOnce = false;
private DropDownListButton _mainButton;
private RectTransform _rectTransform;
private RectTransform _overlayRT;
private RectTransform _scrollPanelRT;
private RectTransform _scrollBarRT;
private RectTransform _slidingAreaRT;
// private RectTransform scrollHandleRT;
private RectTransform _itemsPanelRT;
private Canvas _canvas;
private RectTransform _canvasRT;
private ScrollRect _scrollRect;
private List<DropDownListButton> _panelItems;
private GameObject _itemTemplate;
[SerializeField]
private float _scrollBarWidth = 20.0f;
public float ScrollBarWidth
{
get { return _scrollBarWidth; }
set
{
_scrollBarWidth = value;
RedrawPanel();
}
}
// private int scrollOffset; //offset of the selected item
private int _selectedIndex = 0;
[SerializeField]
private int _itemsToDisplay;
public int ItemsToDisplay
{
get { return _itemsToDisplay; }
set
{
_itemsToDisplay = value;
RedrawPanel();
}
}
public void Start()
{
Initialize();
}
private bool Initialize()
{
bool success = true;
try
{
_rectTransform = GetComponent<RectTransform>();
_mainButton = new DropDownListButton(_rectTransform.Find("MainButton").gameObject);
_overlayRT = _rectTransform.Find("Overlay").GetComponent<RectTransform>();
_overlayRT.gameObject.SetActive(false);
_scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>();
_scrollBarRT = _scrollPanelRT.Find("Scrollbar").GetComponent<RectTransform>();
_slidingAreaRT = _scrollBarRT.Find("SlidingArea").GetComponent<RectTransform>();
// scrollHandleRT = slidingAreaRT.FindChild("Handle").GetComponent<RectTransform>();
_itemsPanelRT = _scrollPanelRT.Find("Items").GetComponent<RectTransform>();
//itemPanelLayout = itemsPanelRT.gameObject.GetComponent<LayoutGroup>();
_canvas = GetComponentInParent<Canvas>();
_canvasRT = _canvas.GetComponent<RectTransform>();
_scrollRect = _scrollPanelRT.GetComponent<ScrollRect>();
_scrollRect.scrollSensitivity = _rectTransform.sizeDelta.y / 2;
_scrollRect.movementType = ScrollRect.MovementType.Clamped;
_scrollRect.content = _itemsPanelRT;
_itemTemplate = _rectTransform.Find("ItemTemplate").gameObject;
_itemTemplate.SetActive(false);
}
catch (System.NullReferenceException ex)
{
Debug.LogException(ex);
Debug.LogError("Something is setup incorrectly with the dropdownlist component causing a Null Reference Exception");
success = false;
}
_panelItems = new List<DropDownListButton>();
RebuildPanel();
RedrawPanel();
return success;
}
/* currently just using items in the list instead of being able to add to it.
public void AddItems(params object[] list)
{
List<DropDownListItem> ddItems = new List<DropDownListItem>();
foreach (var obj in list)
{
if (obj is DropDownListItem)
{
ddItems.Add((DropDownListItem)obj);
}
else if (obj is string)
{
ddItems.Add(new DropDownListItem(caption: (string)obj));
}
else if (obj is Sprite)
{
ddItems.Add(new DropDownListItem(image: (Sprite)obj));
}
else
{
throw new System.Exception("Only ComboBoxItems, Strings, and Sprite types are allowed");
}
}
Items.AddRange(ddItems);
Items = Items.Distinct().ToList();//remove any duplicates
RebuildPanel();
}
*/
/// <summary>
/// Rebuilds the contents of the panel in response to items being added.
/// </summary>
private void RebuildPanel()
{
if (Items.Count == 0) return;
int indx = _panelItems.Count;
while (_panelItems.Count < Items.Count)
{
GameObject newItem = Instantiate(_itemTemplate) as GameObject;
newItem.name = "Item " + indx;
newItem.transform.SetParent(_itemsPanelRT, false);
_panelItems.Add(new DropDownListButton(newItem));
indx++;
}
for (int i = 0; i < _panelItems.Count; i++)
{
if (i < Items.Count)
{
DropDownListItem item = Items[i];
_panelItems[i].txt.text = item.Caption;
if (item.IsDisabled) _panelItems[i].txt.color = disabledTextColor;
if (_panelItems[i].btnImg != null) _panelItems[i].btnImg.sprite = null;//hide the button image
_panelItems[i].img.sprite = item.Image;
_panelItems[i].img.color = (item.Image == null) ? new Color(1, 1, 1, 0)
: item.IsDisabled ? new Color(1, 1, 1, .5f)
: Color.white;
int ii = i; //have to copy the variable for use in anonymous function
_panelItems[i].btn.onClick.RemoveAllListeners();
_panelItems[i].btn.onClick.AddListener(() =>
{
OnItemClicked(ii);
if (item.OnSelect != null) item.OnSelect();
});
}
_panelItems[i].gameobject.SetActive(i < Items.Count);// if we have more thanks in the panel than Items in the list hide them
}
}
private void OnItemClicked(int indx)
{
Debug.Log("item " + indx + " clicked");
if (indx != _selectedIndex && OnSelectionChanged != null) OnSelectionChanged(indx);
_selectedIndex = indx;
ToggleDropdownPanel(true);
UpdateSelected();
}
private void UpdateSelected()
{
SelectedItem = (_selectedIndex > -1 && _selectedIndex < Items.Count) ? Items[_selectedIndex] : null;
if (SelectedItem == null) return;
bool hasImage = SelectedItem.Image != null;
if (hasImage)
{
_mainButton.img.sprite = SelectedItem.Image;
_mainButton.img.color = Color.white;
//if (Interactable) mainButton.img.color = Color.white;
//else mainButton.img.color = new Color(1, 1, 1, .5f);
}
else
{
_mainButton.img.sprite = null;
}
_mainButton.txt.text = SelectedItem.Caption;
//update selected index color
if (OverrideHighlighted)
{
for (int i = 0; i < _itemsPanelRT.childCount; i++)
{
_panelItems[i].btnImg.color = (_selectedIndex == i) ? _mainButton.btn.colors.highlightedColor : new Color(0, 0, 0, 0);
}
}
}
private void RedrawPanel()
{
float scrollbarWidth = Items.Count > ItemsToDisplay ? _scrollBarWidth : 0f;//hide the scrollbar if there's not enough items
if (!_hasDrawnOnce || _rectTransform.sizeDelta != _mainButton.rectTransform.sizeDelta)
{
_hasDrawnOnce = true;
_mainButton.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
_mainButton.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _rectTransform.sizeDelta.y);
_mainButton.txt.rectTransform.offsetMax = new Vector2(4, 0);
_scrollPanelRT.SetParent(transform, true);//break the scroll panel from the overlay
_scrollPanelRT.anchoredPosition = new Vector2(0, -_rectTransform.sizeDelta.y); //anchor it to the bottom of the button
//make the overlay fill the screen
_overlayRT.SetParent(_canvas.transform, false); //attach it to top level object
_overlayRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _canvasRT.sizeDelta.x);
_overlayRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _canvasRT.sizeDelta.y);
_overlayRT.SetParent(transform, true);//reattach to this object
_scrollPanelRT.SetParent(_overlayRT, true); //reattach the scrollpanel to the overlay
}
if (Items.Count < 1) return;
float dropdownHeight = _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, Items.Count);
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
_itemsPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _scrollPanelRT.sizeDelta.x - scrollbarWidth - 5);
_itemsPanelRT.anchoredPosition = new Vector2(5, 0);
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
_scrollBarRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 0);
_slidingAreaRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight - _scrollBarRT.sizeDelta.x);
}
/// <summary>
/// Toggle the drop down list
/// </summary>
/// <param name="directClick"> whether an item was directly clicked on</param>
public void ToggleDropdownPanel(bool directClick)
{
_overlayRT.transform.localScale = new Vector3(1, 1, 1);
_scrollBarRT.transform.localScale = new Vector3(1, 1, 1);
_isPanelActive = !_isPanelActive;
_overlayRT.gameObject.SetActive(_isPanelActive);
if (_isPanelActive)
{
transform.SetAsLastSibling();
}
else if (directClick)
{
// scrollOffset = Mathf.RoundToInt(itemsPanelRT.anchoredPosition.y / _rectTransform.sizeDelta.y);
}
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7a00cad80d8a47b438b394bebe77d0d2
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,26 @@
///Credit perchik
///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/
namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(RectTransform), typeof(Button))]
public class DropDownListButton
{
public RectTransform rectTransform;
public Button btn;
public Text txt;
public Image btnImg;
public Image img;
public GameObject gameobject;
public DropDownListButton(GameObject btnObj)
{
gameobject = btnObj;
rectTransform = btnObj.GetComponent<RectTransform>();
btnImg = btnObj.GetComponent<Image>();
btn = btnObj.GetComponent<Button>();
txt = rectTransform.Find("Text").GetComponent<Text>();
img = rectTransform.Find("Image").GetComponent<Image>();
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 491c635e1f309294187ff24b5c71e8cb
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,100 @@
///Credit perchik
///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/
using System;
namespace UnityEngine.UI.Extensions
{
[Serializable]
public class DropDownListItem
{
[SerializeField]
private string _caption;
/// <summary>
/// Caption of the Item
/// </summary>
public string Caption
{
get
{
return _caption;
}
set
{
_caption = value;
if (OnUpdate != null)
OnUpdate();
}
}
[SerializeField]
private Sprite _image;
/// <summary>
/// Image component of the Item
/// </summary>
public Sprite Image
{
get
{
return _image;
}
set
{
_image = value;
if (OnUpdate != null)
OnUpdate();
}
}
[SerializeField]
private bool _isDisabled;
/// <summary>
/// Is the Item currently enabled?
/// </summary>
public bool IsDisabled
{
get
{
return _isDisabled;
}
set
{
_isDisabled = value;
if (OnUpdate != null)
OnUpdate();
}
}
[SerializeField]
private string _id;
///<summary>
///ID exists so that an item can have a caption and a value like in traditional windows forms. Ie. an item may be a student's name, and the ID can be the student's ID number
///</summary>
public string ID
{
get { return _id; }
set { _id = value; }
}
public Action OnSelect; //action to be called when this item is selected
internal Action OnUpdate; //action to be called when something changes.
/// <summary>
/// Constructor for Drop Down List panelItems
/// </summary>
/// <param name="caption">Caption for the item </param>
/// <param name="val">ID of the item </param>
/// <param name="image"></param>
/// <param name="disabled">Should the item start disabled</param>
/// <param name="onSelect">Action to be called when this item is selected</param>
public DropDownListItem(string caption = "", string inId = "", Sprite image = null, bool disabled = false, Action onSelect = null)
{
_caption = caption;
_image = image;
_id = inId;
_isDisabled = disabled;
OnSelect = onSelect;
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e1dd512d0ed874740902b01df530b2dc
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,83 @@
/// Credit Zelek
/// Sourced from - http://forum.unity3d.com/threads/inputfield-focus-and-unfocus.306634/
/// Usage, assign component to Input field, set OnEndEdit function to the one in this script and the Click for the submit button to the buttonPressed function.
namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(InputField))]
[AddComponentMenu("UI/Extensions/InputFocus")]
public class InputFocus : MonoBehaviour
{
#region Private Variables
// The input field we use for chat
protected InputField _inputField;
// When set to true, we will ignore the next time the "Enter" key is released
public bool _ignoreNextActivation = false;
#endregion
void Start()
{
_inputField = GetComponent<InputField>();
}
void Update()
{
// Check if the "Enter" key was just released with the chat input not focused
if (Input.GetKeyUp(KeyCode.Return) && !_inputField.isFocused)
{
// If we need to ignore the keypress, do nothing - otherwise activate the input field
if (_ignoreNextActivation)
{
_ignoreNextActivation = false;
}
else
{
_inputField.Select();
_inputField.ActivateInputField();
}
}
}
public void buttonPressed()
{
// Do whatever you want with the input field text here
// Make note of whether the input string was empty, and then clear it out
bool wasEmpty = _inputField.text == "";
_inputField.text = "";
// If the string was not empty, we should reactivate the input field
if (!wasEmpty)
{
_inputField.Select();
_inputField.ActivateInputField();
}
}
public void OnEndEdit(string textString)
{
// If the edit ended because we clicked away, don't do anything extra
if (!Input.GetKeyDown(KeyCode.Return))
{
return;
}
// Do whatever you want with the input field text here
// Make note of whether the input string was empty, and then clear it out
bool wasEmpty = _inputField.text == "";
_inputField.text = "";
// if the input string was empty, then allow the field to deactivate
if (wasEmpty)
{
_ignoreNextActivation = true;
}
}
}
}

Some files were not shown because too many files have changed in this diff Show more