Added several new scripts from the forums and other sources.
Need to complete script validation and normalise scripts for repository Next tasks: #4 #5 Added new component for #3 --HG-- branch : developpull/413/head
parent
d9a5a42644
commit
a297f0d599
|
@ -0,0 +1,5 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: dc2df01d18eb92b49b30e7403cce8313
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
|
@ -0,0 +1,25 @@
|
||||||
|
///Credit ChoMPHi
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace UnityEditor.UI
|
||||||
|
{
|
||||||
|
[CustomEditor(typeof(UIAccordionElement), true)]
|
||||||
|
public class UIAccordionElementEditor : 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 53f48a76b4229da449e962fb3aa06279
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
|
@ -0,0 +1,5 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b9115417252d4cd42a5e167bdc1c2d3b
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
|
@ -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.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e28e1e9e18f7daa4db5d1ac279d6ce66
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
|
@ -0,0 +1,16 @@
|
||||||
|
///Credit ChoMPHi
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
|
||||||
|
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace UnityEngine.UI.Tweens
|
||||||
|
{
|
||||||
|
internal interface ITweenValue
|
||||||
|
{
|
||||||
|
void TweenValue(float floatPercentage);
|
||||||
|
bool ignoreTimeScale { get; }
|
||||||
|
float duration { get; }
|
||||||
|
bool ValidTarget();
|
||||||
|
void Finished();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9edf9da4c14ad2843879a2331b00f738
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
|
@ -0,0 +1,63 @@
|
||||||
|
///Credit ChoMPHi
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
|
||||||
|
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace UnityEngine.UI.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d00ab96853b24074cb837ee70f07dddc
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
|
@ -0,0 +1,41 @@
|
||||||
|
///Credit ChoMPHi
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace UnityEngine.UI
|
||||||
|
{
|
||||||
|
[RequireComponent(typeof(VerticalLayoutGroup)), RequireComponent(typeof(ContentSizeFitter)), RequireComponent(typeof(ToggleGroup))]
|
||||||
|
public class UIAccordion : 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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 41b373e1e582f0c4286c09ce25cc7021
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
|
@ -0,0 +1,139 @@
|
||||||
|
///Credit ChoMPHi
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Events;
|
||||||
|
using UnityEngine.UI.Tweens;
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace UnityEngine.UI
|
||||||
|
{
|
||||||
|
[RequireComponent(typeof(RectTransform)), RequireComponent(typeof(LayoutElement))]
|
||||||
|
public class UIAccordionElement : Toggle {
|
||||||
|
|
||||||
|
[SerializeField] private float m_MinHeight = 18f;
|
||||||
|
|
||||||
|
private UIAccordion m_Accordion;
|
||||||
|
private RectTransform m_RectTransform;
|
||||||
|
private LayoutElement m_LayoutElement;
|
||||||
|
|
||||||
|
[NonSerialized]
|
||||||
|
private readonly TweenRunner<FloatTween> m_FloatTweenRunner;
|
||||||
|
|
||||||
|
protected UIAccordionElement()
|
||||||
|
{
|
||||||
|
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<UIAccordion>();
|
||||||
|
this.m_RectTransform = this.transform as RectTransform;
|
||||||
|
this.m_LayoutElement = this.gameObject.GetComponent<LayoutElement>();
|
||||||
|
this.onValueChanged.AddListener(OnValueChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnValueChanged(bool state)
|
||||||
|
{
|
||||||
|
if (this.m_LayoutElement == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
UIAccordion.Transition transition = (this.m_Accordion != null) ? this.m_Accordion.transition : UIAccordion.Transition.Instant;
|
||||||
|
|
||||||
|
if (transition == UIAccordion.Transition.Instant)
|
||||||
|
{
|
||||||
|
if (state)
|
||||||
|
{
|
||||||
|
this.m_LayoutElement.preferredHeight = -1f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.m_LayoutElement.preferredHeight = this.m_MinHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (transition == UIAccordion.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c77f1d511e8ee4445a42bc41d95bb11f
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
|
@ -0,0 +1,53 @@
|
||||||
|
/// Credit Melang
|
||||||
|
/// Sourced from - http://forum.unity3d.com/members/melang.593409/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
namespace UnityEngine.UI
|
||||||
|
{
|
||||||
|
[AddComponentMenu ("UI/Effects/BestFit Outline", 15)]
|
||||||
|
public class BestFitOutline : Shadow
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Constructors
|
||||||
|
//
|
||||||
|
protected BestFitOutline ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Methods
|
||||||
|
//
|
||||||
|
public override void ModifyVertices (List<UIVertex> verts)
|
||||||
|
{
|
||||||
|
if (!this.IsActive ())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Text foundtext = GetComponent<Text>();
|
||||||
|
|
||||||
|
float best_fit_adjustment = 1f;
|
||||||
|
|
||||||
|
if (foundtext && foundtext.resizeTextForBestFit)
|
||||||
|
{
|
||||||
|
best_fit_adjustment = (float)foundtext.cachedTextGenerator.fontSizeUsedForBestFit / (foundtext.resizeTextMaxSize-1); //max size seems to be exclusive
|
||||||
|
//Debug.Log("best_fit_adjustment:"+best_fit_adjustment);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int start = 0;
|
||||||
|
int count = verts.Count;
|
||||||
|
base.ApplyShadow (verts, base.effectColor, start, verts.Count, base.effectDistance.x*best_fit_adjustment, base.effectDistance.y*best_fit_adjustment);
|
||||||
|
start = count;
|
||||||
|
count = verts.Count;
|
||||||
|
base.ApplyShadow (verts, base.effectColor, start, verts.Count, base.effectDistance.x*best_fit_adjustment, -base.effectDistance.y*best_fit_adjustment);
|
||||||
|
start = count;
|
||||||
|
count = verts.Count;
|
||||||
|
base.ApplyShadow (verts, base.effectColor, start, verts.Count, -base.effectDistance.x*best_fit_adjustment, base.effectDistance.y*best_fit_adjustment);
|
||||||
|
start = count;
|
||||||
|
count = verts.Count;
|
||||||
|
base.ApplyShadow (verts, base.effectColor, start, verts.Count, -base.effectDistance.x*best_fit_adjustment, -base.effectDistance.y*best_fit_adjustment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,117 @@
|
||||||
|
/// 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
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
public class CanvasGroupActivator : EditorWindow {
|
||||||
|
|
||||||
|
[MenuItem ("Window/Tools/Canvas Groups Activator")]
|
||||||
|
public static void InitWindow()
|
||||||
|
{
|
||||||
|
EditorWindow.GetWindow<CanvasGroupActivator>();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<CanvasGroup> canvasGroups;
|
||||||
|
|
||||||
|
void OnEnable()
|
||||||
|
{
|
||||||
|
ObtainCanvasGroups();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnFocus()
|
||||||
|
{
|
||||||
|
ObtainCanvasGroups();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObtainCanvasGroups()
|
||||||
|
{
|
||||||
|
canvasGroups = new List<CanvasGroup>();
|
||||||
|
canvasGroups = GameObject.FindObjectsOfType<CanvasGroup>().ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnGUI()
|
||||||
|
{
|
||||||
|
if (canvasGroups == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GUILayout.Space(10f);
|
||||||
|
GUILayout.Label("Canvas Groups");
|
||||||
|
|
||||||
|
for (int i = 0; i < canvasGroups.Count; 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()
|
||||||
|
{
|
||||||
|
canvasGroups.ForEach(x =>
|
||||||
|
{
|
||||||
|
if (x != null)
|
||||||
|
{
|
||||||
|
x.alpha = 1.0f;
|
||||||
|
x.interactable = true;
|
||||||
|
x.blocksRaycasts = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void HideAllGroups()
|
||||||
|
{
|
||||||
|
canvasGroups.ForEach(x =>
|
||||||
|
{
|
||||||
|
if (x != null)
|
||||||
|
{
|
||||||
|
x.alpha = 0f;
|
||||||
|
x.interactable = false;
|
||||||
|
x.blocksRaycasts = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
///Credit perchik
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
public class ClickBtn : MonoBehaviour
|
||||||
|
{
|
||||||
|
public void Click()
|
||||||
|
{
|
||||||
|
Debug.Log("Clicked");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 33a5d65e2f7d10648af0fde6d2de99cc
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
|
@ -0,0 +1,624 @@
|
||||||
|
///Credit perchik
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
[RequireComponent(typeof(RectTransform))]
|
||||||
|
public class ComboBox : MonoBehaviour
|
||||||
|
{
|
||||||
|
#region declarations
|
||||||
|
#region private members
|
||||||
|
|
||||||
|
private bool _isActive = false; //is the drop down panel active
|
||||||
|
|
||||||
|
private Button comboBtn;
|
||||||
|
private Image comboBtnImg;
|
||||||
|
private Text comboBtnText;
|
||||||
|
|
||||||
|
private Button overlayBtn;
|
||||||
|
|
||||||
|
private GridLayoutGroup itemLayout;
|
||||||
|
|
||||||
|
|
||||||
|
private float _scrollbarWidth = 20.0f;
|
||||||
|
|
||||||
|
private int scrollOffset; //offset of the selected item
|
||||||
|
|
||||||
|
private int _itemsToDisplay = 4; //how many items to show in the dropdown panel
|
||||||
|
|
||||||
|
private bool _hideFirstItem = false; //lets us hide the prompt after something is chosen
|
||||||
|
|
||||||
|
private int _selectedIndex = 0;
|
||||||
|
|
||||||
|
private List<ComboBoxItem> _items; //conceptual items in the list
|
||||||
|
|
||||||
|
private bool _interactable = true;
|
||||||
|
|
||||||
|
|
||||||
|
#region private rect transforms
|
||||||
|
/// <remarks> All of these have to be properties so that the editor script can access them</remarks>
|
||||||
|
|
||||||
|
private RectTransform _overlay; //overlayRT is a screensized box to handle clicks *not* on the button. (although this might have to change with multiple things on the screen.
|
||||||
|
private RectTransform overlayRT
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_overlay == null)
|
||||||
|
{
|
||||||
|
_overlay = rectTransform.FindChild("Overlay").GetComponent<RectTransform>();
|
||||||
|
overlayBtn = _overlay.gameObject.GetComponent<Button>();
|
||||||
|
}
|
||||||
|
return _overlay;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_overlay = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private RectTransform _rectTransform;
|
||||||
|
private RectTransform rectTransform
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_rectTransform == null)
|
||||||
|
{
|
||||||
|
_rectTransform = GetComponent<RectTransform>();
|
||||||
|
}
|
||||||
|
return _rectTransform;
|
||||||
|
}
|
||||||
|
set { _rectTransform = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private RectTransform _comboBtnRT;
|
||||||
|
private RectTransform comboBtnRT
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_comboBtnRT == null)
|
||||||
|
{
|
||||||
|
_comboBtnRT = rectTransform.FindChild("ComboButton").GetComponent<RectTransform>();
|
||||||
|
comboBtn = _comboBtnRT.GetComponent<Button>();
|
||||||
|
comboBtnImg = _comboBtnRT.FindChild("Image").GetComponent<Image>();
|
||||||
|
comboBtnText = _comboBtnRT.FindChild("Text").GetComponent<Text>();
|
||||||
|
}
|
||||||
|
return _comboBtnRT;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_comboBtnRT = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private GameObject _scrollPanel;
|
||||||
|
private GameObject scrollPanel
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_scrollPanel == null)
|
||||||
|
_scrollPanel = overlayRT.FindChild("ScrollPanel").gameObject;
|
||||||
|
return _scrollPanel;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_scrollPanel = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private RectTransform _scrollPanelRT;
|
||||||
|
private RectTransform scrollPanelRT
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_scrollPanelRT == null)
|
||||||
|
_scrollPanelRT = scrollPanel.GetComponent<RectTransform>();
|
||||||
|
return _scrollPanelRT;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_scrollPanelRT = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private RectTransform _itemsRT;
|
||||||
|
private RectTransform itemsRT
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_itemsRT == null)
|
||||||
|
{
|
||||||
|
_itemsRT = scrollPanelRT.Find("Items").GetComponent<RectTransform>();
|
||||||
|
itemLayout = _itemsRT.gameObject.GetComponent<GridLayoutGroup>();
|
||||||
|
}
|
||||||
|
return _itemsRT;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_itemsRT = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private RectTransform _scrollbarRT;
|
||||||
|
private RectTransform scrollbarRT
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_scrollbarRT == null)
|
||||||
|
_scrollbarRT = scrollPanelRT.Find("Scrollbar").GetComponent<RectTransform>();
|
||||||
|
return _scrollbarRT;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_scrollbarRT = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private RectTransform _slidingAreaRT;
|
||||||
|
private RectTransform slidingAreaRT
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_slidingAreaRT == null)
|
||||||
|
_slidingAreaRT = scrollbarRT.Find("SlidingArea").GetComponent<RectTransform>();
|
||||||
|
return _slidingAreaRT;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_slidingAreaRT = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private RectTransform _scrollHandleRT;
|
||||||
|
private RectTransform scrollHandleRT
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_scrollHandleRT == null)
|
||||||
|
_scrollHandleRT = slidingAreaRT.Find("Handle").GetComponent<RectTransform>();
|
||||||
|
return _scrollHandleRT;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_scrollHandleRT = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
#region public accessors
|
||||||
|
|
||||||
|
public string HeaderOption = "";
|
||||||
|
public Color32 disabledTextColor = new Color32(174, 174, 174, 255);
|
||||||
|
public bool Interactable
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _interactable;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_interactable = value;
|
||||||
|
|
||||||
|
comboBtn.interactable = _interactable;
|
||||||
|
if (comboBtnImg.sprite != null)
|
||||||
|
{
|
||||||
|
comboBtnImg.color = _interactable ?
|
||||||
|
comboBtn.colors.normalColor :
|
||||||
|
comboBtn.colors.disabledColor;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
comboBtnImg.color = new Color(1, 1, 1, 0); //transparent
|
||||||
|
}
|
||||||
|
if (!Application.isPlaying)//stop it from messing up in the editor
|
||||||
|
return;
|
||||||
|
if (!_interactable && _isActive)
|
||||||
|
ToggleComboBox(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int SelectedIndex
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _selectedIndex;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_selectedIndex == value)
|
||||||
|
return;
|
||||||
|
if (value > -1 && value < Items.Count)
|
||||||
|
{
|
||||||
|
_selectedIndex = value;
|
||||||
|
RefreshSelected();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<ComboBoxItem> Items
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_items == null)
|
||||||
|
{
|
||||||
|
_items = new List<ComboBoxItem>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return _items;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_items = value;
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HideFirstItem
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _hideFirstItem;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value)
|
||||||
|
scrollOffset--;
|
||||||
|
else
|
||||||
|
scrollOffset++;
|
||||||
|
_hideFirstItem = value;
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ItemsToDisplay
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _itemsToDisplay;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_itemsToDisplay == value)
|
||||||
|
return;
|
||||||
|
_itemsToDisplay = value;
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public System.Action<int> OnSelectionChanged;//fires when selection is changed.
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region public methods
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update the main button with the selected item's parameters
|
||||||
|
/// </summary>
|
||||||
|
public void RefreshSelected()
|
||||||
|
{
|
||||||
|
//get the selected item
|
||||||
|
ComboBoxItem item = (SelectedIndex > -1 && SelectedIndex < Items.Count) ? Items[SelectedIndex] : null;
|
||||||
|
if (item == null) return;
|
||||||
|
|
||||||
|
bool hasImage = (item.Image != null);
|
||||||
|
comboBtnImg.sprite = hasImage ? item.Image : null;
|
||||||
|
comboBtnImg.color = !hasImage ? new Color(1, 1, 1, 0)//transparent if there's no image.
|
||||||
|
: !Interactable ? new Color(1, 1, 1, .5f) //semitransparent if the combobox is disabled
|
||||||
|
: Color.white; //fully opaque if it has an image and the combobox is enabled
|
||||||
|
UpdateComboBoxText(comboBtnRT, hasImage);
|
||||||
|
comboBtnText.text = item.Caption;
|
||||||
|
|
||||||
|
comboBtn.onClick.RemoveAllListeners();
|
||||||
|
comboBtn.onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
ToggleComboBox(true);
|
||||||
|
});
|
||||||
|
if (!Application.isPlaying) return; //if it was running in editor we stop here.
|
||||||
|
|
||||||
|
for (int i = 0; i < itemsRT.childCount; i++)
|
||||||
|
{
|
||||||
|
Image tempImg = itemsRT.GetChild(i).GetComponent<Image>();
|
||||||
|
tempImg.color = (SelectedIndex == (i + (HideFirstItem ? 1 : 0))) ? comboBtn.colors.highlightedColor : comboBtn.colors.normalColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// what happens when an item in the list is selected
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="index"></param>
|
||||||
|
public void OnItemClicked(int index)
|
||||||
|
{
|
||||||
|
Debug.Log("item " + index + " was clicked");
|
||||||
|
bool selectionChanged = (index != SelectedIndex);
|
||||||
|
SelectedIndex = index;
|
||||||
|
ToggleComboBox(true);
|
||||||
|
if (selectionChanged && OnSelectionChanged != null) OnSelectionChanged(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add items to the dropdown list. Accepts any object of type ComboBoxItem, String, or Image
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="list"></param>
|
||||||
|
public void AddItems(params object[] list)
|
||||||
|
{
|
||||||
|
List<ComboBoxItem> cbItems = new List<ComboBoxItem>();
|
||||||
|
foreach (var obj in list)
|
||||||
|
{
|
||||||
|
if (obj is ComboBoxItem)
|
||||||
|
{
|
||||||
|
cbItems.Add((ComboBoxItem)obj);
|
||||||
|
}
|
||||||
|
else if (obj is string)
|
||||||
|
{
|
||||||
|
cbItems.Add(new ComboBoxItem(caption: (string)obj));
|
||||||
|
}
|
||||||
|
else if (obj is Sprite)
|
||||||
|
{
|
||||||
|
cbItems.Add(new ComboBoxItem(image: (Sprite)obj));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new System.Exception("Only ComboBoxItems, Strings, and Sprite types are allowed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Items.AddRange(cbItems);
|
||||||
|
Items = Items.Distinct().ToList();//remove any duplicates
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ClearItems()
|
||||||
|
{
|
||||||
|
Items.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Redraw the graphics (in response to something changing)
|
||||||
|
/// </summary>
|
||||||
|
public void UpdateGraphics()
|
||||||
|
{
|
||||||
|
//center the handle in the scrollbar
|
||||||
|
float scrollbarWidth = Items.Count - (HideFirstItem ? 1 : 0) > ItemsToDisplay ? _scrollbarWidth : 0.0f;
|
||||||
|
scrollHandleRT.offsetMin = -scrollbarWidth / 2 * Vector2.one;
|
||||||
|
scrollHandleRT.offsetMax = scrollbarWidth / 2 * Vector2.one;
|
||||||
|
|
||||||
|
if (rectTransform.sizeDelta != comboBtnRT.sizeDelta)
|
||||||
|
{
|
||||||
|
comboBtnRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, rectTransform.sizeDelta.x);
|
||||||
|
comboBtnRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, rectTransform.sizeDelta.y);
|
||||||
|
comboBtnText.rectTransform.offsetMax = new Vector2(4, 0);
|
||||||
|
|
||||||
|
scrollPanelRT.SetParent(transform, true);
|
||||||
|
scrollPanelRT.anchoredPosition = new Vector2(0, -comboBtnRT.sizeDelta.y);
|
||||||
|
|
||||||
|
|
||||||
|
//make hte overlay fill the whole screen
|
||||||
|
overlayRT.SetParent(UIManager.GetCanvas().transform, false);
|
||||||
|
overlayRT.offsetMax = Vector2.zero;
|
||||||
|
overlayRT.offsetMin = Vector2.zero;
|
||||||
|
|
||||||
|
//reattach to correct parents, maintining global position
|
||||||
|
overlayRT.SetParent(transform, true);
|
||||||
|
scrollPanelRT.SetParent(overlayRT, true);
|
||||||
|
|
||||||
|
scrollPanel.GetComponent<ScrollRect>().scrollSensitivity = comboBtnRT.sizeDelta.y;
|
||||||
|
|
||||||
|
UpdateComboBoxText(comboBtnRT, Items[SelectedIndex].Image != null);
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// toggle the drop down list
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="directClick">whether it was toggled by directly clicking on </param>
|
||||||
|
public void ToggleComboBox(bool directClick)
|
||||||
|
{
|
||||||
|
if (HeaderOption != "") HideFirstItem = true;
|
||||||
|
_isActive = !_isActive;
|
||||||
|
// Debug.Log("toggling combo box tp "+ _isActive);
|
||||||
|
overlayRT.gameObject.SetActive(_isActive);
|
||||||
|
if (_isActive)
|
||||||
|
{
|
||||||
|
transform.SetAsLastSibling();
|
||||||
|
FixScrollOffset();
|
||||||
|
}
|
||||||
|
else if (directClick)
|
||||||
|
{
|
||||||
|
scrollOffset = Mathf.RoundToInt(_itemsRT.anchoredPosition.y / rectTransform.sizeDelta.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region private methods
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initialize the control
|
||||||
|
/// </summary>
|
||||||
|
private void Initialize()
|
||||||
|
{
|
||||||
|
overlayRT.gameObject.SetActive(false);
|
||||||
|
overlayBtn.onClick.AddListener(() => { ToggleComboBox(false); });
|
||||||
|
|
||||||
|
if (HeaderOption != "") AddItems(HeaderOption);
|
||||||
|
|
||||||
|
//float dropdownHeight = comboBtnRT.sizeDelta.y * Mathf.Min(ItemsToDisplay, Items.Length - (HideFirstItem ? 1 : 0));
|
||||||
|
|
||||||
|
//scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
|
||||||
|
//scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, comboBtnRT.sizeDelta.x);
|
||||||
|
|
||||||
|
ScrollRect scrollPanelScrollRect = scrollPanel.GetComponent<ScrollRect>();
|
||||||
|
scrollPanelScrollRect.scrollSensitivity = comboBtnRT.sizeDelta.y;
|
||||||
|
scrollPanelScrollRect.content = itemsRT;
|
||||||
|
|
||||||
|
itemLayout.constraint = GridLayoutGroup.Constraint.FixedColumnCount;
|
||||||
|
itemLayout.constraintCount = 1;
|
||||||
|
|
||||||
|
//float scrollbarWidth = Items.Length - (HideFirstItem ? 1 : 0) > _itemsToDisplay ? _scrollbarWidth : 0.0f;
|
||||||
|
//itemsRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollPanelRT.sizeDelta.x - scrollbarWidth);
|
||||||
|
|
||||||
|
//itemLayout.cellSize = new Vector2(comboBtnRT.sizeDelta.x - scrollbarWidth, comboBtnRT.sizeDelta.y);
|
||||||
|
//itemLayout.constraint = GridLayoutGroup.Constraint.FixedColumnCount;
|
||||||
|
//itemLayout.constraintCount = 1;
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
//scrollHandleRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
|
||||||
|
//scrollHandleRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, scrollbarWidth);
|
||||||
|
|
||||||
|
Interactable = Interactable; //call the logic in the getter.
|
||||||
|
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Redraw the component, with realigning.
|
||||||
|
/// </summary>
|
||||||
|
public void Refresh()
|
||||||
|
{
|
||||||
|
// Debug.Log("Refreshing");
|
||||||
|
|
||||||
|
int itemsLength = Items.Count - (HideFirstItem ? 1 : 0);
|
||||||
|
if (itemsLength < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
float dropdownHeight = comboBtnRT.sizeDelta.y * Mathf.Min(_itemsToDisplay, itemsLength);
|
||||||
|
float scrollbarWidth = itemsLength > ItemsToDisplay ? _scrollbarWidth : 0.0f;
|
||||||
|
|
||||||
|
|
||||||
|
scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
|
||||||
|
scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, comboBtnRT.sizeDelta.x);
|
||||||
|
|
||||||
|
itemsRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollPanelRT.sizeDelta.x - scrollbarWidth);
|
||||||
|
|
||||||
|
itemLayout.cellSize = new Vector2(comboBtnRT.sizeDelta.x - scrollbarWidth, comboBtnRT.sizeDelta.y);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
scrollHandleRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, scrollbarWidth);
|
||||||
|
scrollHandleRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, scrollbarWidth);
|
||||||
|
|
||||||
|
for (int i = itemsRT.childCount - 1; i >= 0; i--)//delete in reverse to avoid having to re-allocate memory on each delete. (ie if I deleted child 0, everythign would get shifted forward in the array)
|
||||||
|
{
|
||||||
|
DestroyImmediate(itemsRT.GetChild(0).gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = (HideFirstItem ? 1 : 0); i < Items.Count; i++) //for each element to be shown in the dropdown list
|
||||||
|
{
|
||||||
|
ComboBoxItem item = Items[i];
|
||||||
|
item.OnUpdate = Refresh;
|
||||||
|
|
||||||
|
Transform itemTfm = Instantiate(comboBtnRT) as Transform;//copy the top level combo box
|
||||||
|
itemTfm.name += " " + i;
|
||||||
|
itemTfm.SetParent(itemsRT, false);
|
||||||
|
itemTfm.GetComponent<Image>().sprite = null; //hide the original background image (so that the dropdown box shows)
|
||||||
|
|
||||||
|
Text itemText = itemTfm.Find("Text").GetComponent<Text>();
|
||||||
|
itemText.text = item.Caption;
|
||||||
|
if (item.IsDisabled) itemText.color = disabledTextColor;
|
||||||
|
|
||||||
|
Image itemImg = itemTfm.Find("Image").GetComponent<Image>();
|
||||||
|
itemImg.sprite = item.Image;
|
||||||
|
itemImg.color = (item.Image == null) ? new Color(1, 1, 1, 0)
|
||||||
|
: item.IsDisabled ? new Color(1, 1, 1, .5f)
|
||||||
|
: Color.white;
|
||||||
|
Button itemBtn = itemTfm.GetComponent<Button>();
|
||||||
|
itemBtn.interactable = !item.IsDisabled;
|
||||||
|
|
||||||
|
int indx = i;
|
||||||
|
itemBtn.onClick.RemoveAllListeners();
|
||||||
|
itemBtn.onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
OnItemClicked(indx);
|
||||||
|
if (item.OnSelect != null) item.OnSelect();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
RefreshSelected();
|
||||||
|
UpdateComboBoxItems();
|
||||||
|
UpdateGraphics();
|
||||||
|
FixScrollOffset();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// adjusts all of the items in the dropdown list to account for any images
|
||||||
|
/// </summary>
|
||||||
|
private void UpdateComboBoxItems()
|
||||||
|
{
|
||||||
|
//decide if any item in the list has images
|
||||||
|
bool includeImages = false;
|
||||||
|
foreach (ComboBoxItem item in Items)
|
||||||
|
{
|
||||||
|
if (item.Image != null)
|
||||||
|
{
|
||||||
|
includeImages = true; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//either align all of the text 10 units from the side, or 8+image width.
|
||||||
|
foreach (Transform child in itemsRT)
|
||||||
|
{
|
||||||
|
UpdateComboBoxText(child, includeImages);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void UpdateComboBoxText(Transform child, bool includeImages)
|
||||||
|
{
|
||||||
|
child.Find("Text").GetComponent<RectTransform>().offsetMin = Vector2.right * (includeImages ? comboBtnImg.rectTransform.rect.width + 8.0f : 10.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void FixScrollOffset()
|
||||||
|
{
|
||||||
|
int selectedIndex = SelectedIndex + (HideFirstItem ? 1 : 0);
|
||||||
|
if (selectedIndex < scrollOffset)
|
||||||
|
scrollOffset = selectedIndex;
|
||||||
|
else
|
||||||
|
if (selectedIndex > scrollOffset + ItemsToDisplay - 1)
|
||||||
|
scrollOffset = selectedIndex - ItemsToDisplay + 1;
|
||||||
|
|
||||||
|
|
||||||
|
int itemsCount = Items.Count - (HideFirstItem ? 1 : 0);
|
||||||
|
if (scrollOffset > itemsCount - ItemsToDisplay)
|
||||||
|
scrollOffset = itemsCount - ItemsToDisplay;
|
||||||
|
if (scrollOffset < 0)
|
||||||
|
scrollOffset = 0;
|
||||||
|
|
||||||
|
_itemsRT.anchoredPosition = new Vector2(0.0f, scrollOffset * rectTransform.sizeDelta.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: cd26acd32e1be2747b9e5f3587b2b1d5
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
|
@ -0,0 +1,96 @@
|
||||||
|
///Credit perchik
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class ComboBoxItem
|
||||||
|
{
|
||||||
|
|
||||||
|
[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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Action OnSelect; //action to be called when this item is selected
|
||||||
|
|
||||||
|
internal Action OnUpdate; //action to be called when something changes.
|
||||||
|
|
||||||
|
///<remarks> Value 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 value could be the student's ID number</remarks>
|
||||||
|
private string _value;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor for ComboBoxOptions
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="caption">Caption for the item </param>
|
||||||
|
/// <param name="val">Value 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 ComboBoxItem(string caption="",string val="", Sprite image=null, bool disabled=false, Action onSelect=null)
|
||||||
|
{
|
||||||
|
_caption = caption;
|
||||||
|
_image = image;
|
||||||
|
_value = val;
|
||||||
|
_isDisabled = disabled;
|
||||||
|
OnSelect = onSelect;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 261044bc84e00294d9bcf19909da3aa2
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
Binary file not shown.
|
@ -0,0 +1,4 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e2a3ef238d1087247ac988b1c9552363
|
||||||
|
NativeFormatImporter:
|
||||||
|
userData:
|
|
@ -0,0 +1,19 @@
|
||||||
|
///Credit perchik
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/receive-onclick-event-and-pass-it-on-to-lower-ui-elements.293642/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
public class UIManager : MonoBehaviour
|
||||||
|
{
|
||||||
|
|
||||||
|
private static GameObject canvas;
|
||||||
|
|
||||||
|
public static GameObject GetCanvas()
|
||||||
|
{
|
||||||
|
|
||||||
|
canvas = FindObjectOfType<Canvas>().gameObject;
|
||||||
|
return canvas;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 65d9021f354adf14ab31e200546fb013
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
|
@ -1,4 +1,5 @@
|
||||||
//Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1777407
|
/// Credit Breyer
|
||||||
|
/// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1777407
|
||||||
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
//Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1780095
|
/// Credit Breyer
|
||||||
|
/// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1780095
|
||||||
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
///Credit judah4
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
public class ColorPickerTester : MonoBehaviour
|
||||||
|
{
|
||||||
|
|
||||||
|
public Renderer renderer;
|
||||||
|
public HSVPicker picker;
|
||||||
|
|
||||||
|
// Use this for initialization
|
||||||
|
void Start ()
|
||||||
|
{
|
||||||
|
picker.onValueChanged.AddListener(color =>
|
||||||
|
{
|
||||||
|
renderer.material.color = color;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update () {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 06851a815227e5044b0e3c1bf9b3a282
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
|
@ -0,0 +1,229 @@
|
||||||
|
///Credit judah4
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
using UnityEngine.Events;
|
||||||
|
|
||||||
|
public class HSVPicker : MonoBehaviour {
|
||||||
|
|
||||||
|
public HexRGB hexrgb;
|
||||||
|
|
||||||
|
public Color currentColor;
|
||||||
|
public Image colorImage;
|
||||||
|
public Image pointer;
|
||||||
|
public Image cursor;
|
||||||
|
public RawImage hsvSlider;
|
||||||
|
public RawImage hsvImage;
|
||||||
|
|
||||||
|
//public InputField inputR;
|
||||||
|
//public InputField inputG;
|
||||||
|
//public InputField inputB;
|
||||||
|
|
||||||
|
public Slider sliderR;
|
||||||
|
public Slider sliderG;
|
||||||
|
public Slider sliderB;
|
||||||
|
public Text sliderRText;
|
||||||
|
public Text sliderGText;
|
||||||
|
public Text sliderBText;
|
||||||
|
|
||||||
|
public float pointerPos = 0;
|
||||||
|
|
||||||
|
public float cursorX = 0;
|
||||||
|
public float cursorY = 0;
|
||||||
|
|
||||||
|
|
||||||
|
public HSVSliderEvent onValueChanged = new HSVSliderEvent();
|
||||||
|
|
||||||
|
private bool dontAssignUpdate = false;
|
||||||
|
|
||||||
|
void Awake()
|
||||||
|
{
|
||||||
|
hsvSlider.texture = HSVUtil.GenerateHSVTexture((int)hsvSlider.rectTransform.rect.width, (int)hsvSlider.rectTransform.rect.height);
|
||||||
|
|
||||||
|
sliderR.onValueChanged.AddListener(newValue =>
|
||||||
|
{
|
||||||
|
currentColor.r = newValue;
|
||||||
|
if (dontAssignUpdate == false)
|
||||||
|
{
|
||||||
|
AssignColor(currentColor);
|
||||||
|
}
|
||||||
|
sliderRText.text = "R:" + (int)(currentColor.r * 255f);
|
||||||
|
hexrgb.ManipulateViaRGB2Hex();
|
||||||
|
});
|
||||||
|
sliderG.onValueChanged.AddListener(newValue =>
|
||||||
|
{
|
||||||
|
currentColor.g = newValue;
|
||||||
|
if (dontAssignUpdate == false)
|
||||||
|
{
|
||||||
|
AssignColor(currentColor);
|
||||||
|
}
|
||||||
|
sliderGText.text = "G:" + (int)(currentColor.g * 255f);
|
||||||
|
hexrgb.ManipulateViaRGB2Hex();
|
||||||
|
});
|
||||||
|
sliderB.onValueChanged.AddListener(newValue =>
|
||||||
|
{
|
||||||
|
currentColor.b = newValue;
|
||||||
|
if (dontAssignUpdate == false)
|
||||||
|
{
|
||||||
|
AssignColor(currentColor);
|
||||||
|
}
|
||||||
|
sliderBText.text = "B:" + (int)(currentColor.b * 255f);
|
||||||
|
hexrgb.ManipulateViaRGB2Hex();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
hsvImage.texture = HSVUtil.GenerateColorTexture((int)hsvImage.rectTransform.rect.width, (int)hsvImage.rectTransform.rect.height, ((Texture2D)hsvSlider.texture).GetPixelBilinear(0, 0));
|
||||||
|
MoveCursor(cursorX, cursorY);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update () {
|
||||||
|
//if (Input.GetKeyDown(KeyCode.R))
|
||||||
|
//{
|
||||||
|
// var color = new Color(45f / 255, 200f / 255, 255f / 255);
|
||||||
|
// Debug.Log(color);
|
||||||
|
// AssignColor(color);
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void AssignColor(Color color)
|
||||||
|
{
|
||||||
|
|
||||||
|
var hsv = HSVUtil.ConvertRgbToHsv(color);
|
||||||
|
|
||||||
|
// Debug.Log(hsv.ToString());
|
||||||
|
|
||||||
|
float hOffset = (float)(hsv.H / 360);
|
||||||
|
|
||||||
|
//if (hsv.S > 1)
|
||||||
|
//{
|
||||||
|
// hsv.S %= 1f;
|
||||||
|
//}
|
||||||
|
//if (hsv.V > 1)
|
||||||
|
//{
|
||||||
|
// hsv.V %= 1f;
|
||||||
|
//}
|
||||||
|
|
||||||
|
MovePointer(hOffset, false);
|
||||||
|
MoveCursor((float)hsv.S, (float)hsv.V, false);
|
||||||
|
|
||||||
|
currentColor = color;
|
||||||
|
colorImage.color = currentColor;
|
||||||
|
|
||||||
|
onValueChanged.Invoke(currentColor);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Color MoveCursor(float posX, float posY, bool updateInputs=true)
|
||||||
|
{
|
||||||
|
dontAssignUpdate = updateInputs;
|
||||||
|
if (posX > 1)
|
||||||
|
{
|
||||||
|
posX %= 1;
|
||||||
|
}
|
||||||
|
if (posY > 1)
|
||||||
|
{
|
||||||
|
posY %= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
posY=Mathf.Clamp(posY, 0, .9999f);
|
||||||
|
posX =Mathf.Clamp(posX, 0, .9999f);
|
||||||
|
|
||||||
|
|
||||||
|
cursorX = posX;
|
||||||
|
cursorY = posY;
|
||||||
|
cursor.rectTransform.anchoredPosition = new Vector2(posX * hsvImage.rectTransform.rect.width, posY * hsvImage.rectTransform.rect.height - hsvImage.rectTransform.rect.height);
|
||||||
|
|
||||||
|
currentColor = GetColor(cursorX, cursorY);
|
||||||
|
colorImage.color = currentColor;
|
||||||
|
|
||||||
|
if (updateInputs)
|
||||||
|
{
|
||||||
|
UpdateInputs();
|
||||||
|
onValueChanged.Invoke(currentColor);
|
||||||
|
}
|
||||||
|
dontAssignUpdate = false;
|
||||||
|
return currentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color GetColor(float posX, float posY)
|
||||||
|
{
|
||||||
|
//Debug.Log(posX + " " + posY);
|
||||||
|
return ((Texture2D)hsvImage.texture).GetPixel((int)(cursorX * hsvImage.texture.width ), (int)(cursorY * hsvImage.texture.height));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color MovePointer(float newPos, bool updateInputs = true)
|
||||||
|
{
|
||||||
|
dontAssignUpdate = updateInputs;
|
||||||
|
if (newPos > 1)
|
||||||
|
{
|
||||||
|
newPos %= 1f;//hsv
|
||||||
|
}
|
||||||
|
pointerPos = newPos;
|
||||||
|
|
||||||
|
var mainColor =((Texture2D)hsvSlider.texture).GetPixelBilinear(0, pointerPos);
|
||||||
|
if (hsvImage.texture != null)
|
||||||
|
{
|
||||||
|
if ((int)hsvImage.rectTransform.rect.width != hsvImage.texture.width || (int)hsvImage.rectTransform.rect.height != hsvImage.texture.height)
|
||||||
|
{
|
||||||
|
Destroy(hsvImage.texture);
|
||||||
|
hsvImage.texture = null;
|
||||||
|
|
||||||
|
hsvImage.texture = HSVUtil.GenerateColorTexture((int)hsvImage.rectTransform.rect.width, (int)hsvImage.rectTransform.rect.height, mainColor);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HSVUtil.GenerateColorTexture(mainColor, (Texture2D)hsvImage.texture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
hsvImage.texture = HSVUtil.GenerateColorTexture((int)hsvImage.rectTransform.rect.width, (int)hsvImage.rectTransform.rect.height, mainColor);
|
||||||
|
}
|
||||||
|
pointer.rectTransform.anchoredPosition = new Vector2(0, -pointerPos * hsvSlider.rectTransform.rect.height);
|
||||||
|
|
||||||
|
currentColor = GetColor(cursorX, cursorY);
|
||||||
|
colorImage.color = currentColor;
|
||||||
|
|
||||||
|
if (updateInputs)
|
||||||
|
{
|
||||||
|
UpdateInputs();
|
||||||
|
onValueChanged.Invoke(currentColor);
|
||||||
|
}
|
||||||
|
dontAssignUpdate = false;
|
||||||
|
return currentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateInputs()
|
||||||
|
{
|
||||||
|
|
||||||
|
sliderR.value = currentColor.r;
|
||||||
|
sliderG.value = currentColor.g;
|
||||||
|
sliderB.value = currentColor.b;
|
||||||
|
|
||||||
|
sliderRText.text = "R:"+ (currentColor.r * 255f);
|
||||||
|
sliderGText.text = "G:" + (currentColor.g * 255f);
|
||||||
|
sliderBText.text = "B:" + (currentColor.b * 255f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnDestroy()
|
||||||
|
{
|
||||||
|
if (hsvSlider.texture != null)
|
||||||
|
{
|
||||||
|
Destroy(hsvSlider.texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hsvImage.texture != null)
|
||||||
|
{
|
||||||
|
Destroy(hsvImage.texture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8262e4a8322117f4da079921eaa72834
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
|
@ -0,0 +1,20 @@
|
||||||
|
///Credit judah4
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEngine.Events;
|
||||||
|
|
||||||
|
public class HSVSliderEvent : UnityEvent<Color>
|
||||||
|
{
|
||||||
|
|
||||||
|
// Use this for initialization
|
||||||
|
void Start () {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update () {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ff46fbecea7739f4690e4285c88f53c5
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
|
@ -0,0 +1,282 @@
|
||||||
|
///Credit judah4
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#region ColorUtilities
|
||||||
|
|
||||||
|
public static class HSVUtil
|
||||||
|
{
|
||||||
|
|
||||||
|
public static HsvColor ConvertRgbToHsv(Color color)
|
||||||
|
{
|
||||||
|
return ConvertRgbToHsv((int)(color.r * 255), (int)(color.g * 255), (int)(color.b * 255));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Converts an RGB color to an HSV color.
|
||||||
|
public static HsvColor ConvertRgbToHsv(double r, double b, double g)
|
||||||
|
{
|
||||||
|
|
||||||
|
double delta, min;
|
||||||
|
double h = 0, s, v;
|
||||||
|
|
||||||
|
min = Math.Min(Math.Min(r, g), b);
|
||||||
|
v = Math.Max(Math.Max(r, g), b);
|
||||||
|
delta = v - min;
|
||||||
|
|
||||||
|
if (v == 0.0)
|
||||||
|
{
|
||||||
|
s = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
s = delta / v;
|
||||||
|
|
||||||
|
if (s == 0)
|
||||||
|
h = 0.0f;
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (r == v)
|
||||||
|
h = (g - b) / delta;
|
||||||
|
else if (g == v)
|
||||||
|
h = 2 + (b - r) / delta;
|
||||||
|
else if (b == v)
|
||||||
|
h = 4 + (r - g) / delta;
|
||||||
|
|
||||||
|
h *= 60;
|
||||||
|
if (h < 0.0)
|
||||||
|
h = h + 360;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
HsvColor hsvColor = new HsvColor();
|
||||||
|
hsvColor.H = h;
|
||||||
|
hsvColor.S = s;
|
||||||
|
hsvColor.V = v / 255;
|
||||||
|
|
||||||
|
return hsvColor;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Color ConvertHsvToRgb(HsvColor color)
|
||||||
|
{
|
||||||
|
return ConvertHsvToRgb(color.H, color.S, color.V);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Converts an HSV color to an RGB color.
|
||||||
|
public static Color ConvertHsvToRgb(double h, double s, double v)
|
||||||
|
{
|
||||||
|
|
||||||
|
double r = 0, g = 0, b = 0;
|
||||||
|
|
||||||
|
if (s == 0)
|
||||||
|
{
|
||||||
|
r = v;
|
||||||
|
g = v;
|
||||||
|
b = v;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
double f, p, q, t;
|
||||||
|
|
||||||
|
|
||||||
|
if (h == 360)
|
||||||
|
h = 0;
|
||||||
|
else
|
||||||
|
h = h / 60;
|
||||||
|
|
||||||
|
i = (int)(h);
|
||||||
|
f = h - i;
|
||||||
|
|
||||||
|
p = v * (1.0 - s);
|
||||||
|
q = v * (1.0 - (s * f));
|
||||||
|
t = v * (1.0 - (s * (1.0f - f)));
|
||||||
|
|
||||||
|
switch (i)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
r = v;
|
||||||
|
g = t;
|
||||||
|
b = p;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
r = q;
|
||||||
|
g = v;
|
||||||
|
b = p;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
r = p;
|
||||||
|
g = v;
|
||||||
|
b = t;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
r = p;
|
||||||
|
g = q;
|
||||||
|
b = v;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
r = t;
|
||||||
|
g = p;
|
||||||
|
b = v;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
r = v;
|
||||||
|
g = p;
|
||||||
|
b = q;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return new Color((float)r, (float)g, (float)b, 1);//255, (byte)(r * 255), (byte)(g * 255), (byte)(b * 255));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generates a list of colors with hues ranging from 0 360
|
||||||
|
// and a saturation and value of 1.
|
||||||
|
public static List<Color> GenerateHsvSpectrum()
|
||||||
|
{
|
||||||
|
|
||||||
|
List<Color> colorsList = new List<Color>(8);
|
||||||
|
|
||||||
|
|
||||||
|
//for (int i = 0; i < 29; i++)
|
||||||
|
//{
|
||||||
|
|
||||||
|
// colorsList.Add(
|
||||||
|
// ConvertHsvToRgb(i * 12, 1, 1)
|
||||||
|
|
||||||
|
// );
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
|
for (int i = 0; i < 359; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
colorsList.Add(
|
||||||
|
ConvertHsvToRgb(i, 1, 1)
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
colorsList.Add(ConvertHsvToRgb(0, 1, 1));
|
||||||
|
|
||||||
|
|
||||||
|
return colorsList;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Texture2D GenerateHSVTexture(int width, int height)
|
||||||
|
{
|
||||||
|
var list = GenerateHsvSpectrum();
|
||||||
|
|
||||||
|
float interval = 1;
|
||||||
|
if (list.Count > height)
|
||||||
|
{
|
||||||
|
interval = (float)list.Count / height;
|
||||||
|
}
|
||||||
|
|
||||||
|
var texture = new Texture2D(width, height);
|
||||||
|
|
||||||
|
int ySize = Mathf.Max(1,(int)(1f/(list.Count/interval) * height));
|
||||||
|
|
||||||
|
int colorH = 0;
|
||||||
|
|
||||||
|
Color color = Color.white;
|
||||||
|
for (float cnt = 0; cnt < list.Count; cnt += interval)
|
||||||
|
{
|
||||||
|
color = list[(int)cnt];
|
||||||
|
Color[] colors = new Color[width *ySize];
|
||||||
|
for (int i = 0; i < width * ySize; i++)
|
||||||
|
{
|
||||||
|
colors[i] = color;
|
||||||
|
}
|
||||||
|
if (colorH < height)
|
||||||
|
{
|
||||||
|
texture.SetPixels(0, colorH, width, ySize, colors);
|
||||||
|
}
|
||||||
|
colorH += ySize;
|
||||||
|
}
|
||||||
|
|
||||||
|
texture.Apply();
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Texture2D GenerateColorTexture(Color mainColor, Texture2D texture)
|
||||||
|
{
|
||||||
|
int width = texture.width;
|
||||||
|
int height = texture.height;
|
||||||
|
|
||||||
|
var hsvColor = ConvertRgbToHsv((int)(mainColor.r * 255), (int)(mainColor.g * 255), (int)(mainColor.b * 255));
|
||||||
|
|
||||||
|
for (int y = 0; y < height; y++)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < width; x++)
|
||||||
|
{
|
||||||
|
var adjustedColor = hsvColor;
|
||||||
|
adjustedColor.V = (float)y / height;
|
||||||
|
adjustedColor.S = (float)x / width;
|
||||||
|
var color = ConvertHsvToRgb(adjustedColor.H, adjustedColor.S, adjustedColor.V);
|
||||||
|
texture.SetPixel(x, y, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
texture.Apply();
|
||||||
|
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Texture2D GenerateColorTexture(int width, int height, Color mainColor)
|
||||||
|
{
|
||||||
|
return GenerateColorTexture(mainColor, new Texture2D(width, height));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion ColorUtilities
|
||||||
|
|
||||||
|
|
||||||
|
// Describes a color in terms of
|
||||||
|
// Hue, Saturation, and Value (brightness)
|
||||||
|
#region HsvColor
|
||||||
|
public struct HsvColor
|
||||||
|
{
|
||||||
|
|
||||||
|
public double H;
|
||||||
|
public double S;
|
||||||
|
public double V;
|
||||||
|
|
||||||
|
public HsvColor(double h, double s, double v)
|
||||||
|
{
|
||||||
|
this.H = h;
|
||||||
|
this.S = s;
|
||||||
|
this.V = v;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return "{"+H+","+S+","+V+"}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion HsvColor
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4f3189246d7fc204faba7a1e9c08e0af
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
|
@ -0,0 +1,75 @@
|
||||||
|
///Credit judah4
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
using System.Text;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
public class HexRGB : MonoBehaviour {
|
||||||
|
|
||||||
|
public Text textColor;
|
||||||
|
|
||||||
|
public HSVPicker hsvpicker;
|
||||||
|
|
||||||
|
public void ManipulateViaRGB2Hex(){
|
||||||
|
Color color = hsvpicker.currentColor;
|
||||||
|
string hex = ColorToHex (color);
|
||||||
|
textColor.text = hex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string ColorToHex(Color color){
|
||||||
|
int r = (int)(color.r * 255);
|
||||||
|
int g = (int)(color.g * 255);
|
||||||
|
int b = (int)(color.b * 255);
|
||||||
|
return string.Format ("#{0:X2}{1:X2}{2:X2}", r, g, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ManipulateViaHex2RGB(){
|
||||||
|
string hex = textColor.text;
|
||||||
|
|
||||||
|
Vector3 rgb = Hex2RGB (hex);
|
||||||
|
Color color = NormalizeVector4 (rgb,255f,1f); print (rgb);
|
||||||
|
|
||||||
|
hsvpicker.AssignColor (color);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Color NormalizeVector4(Vector3 v,float r,float a){
|
||||||
|
float red = v.x / r;
|
||||||
|
float green = v.y / r;
|
||||||
|
float blue = v.z / r;
|
||||||
|
return new Color (red,green,blue,a);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3 Hex2RGB(string hexColor){
|
||||||
|
//Remove # if present
|
||||||
|
if (hexColor.IndexOf('#') != -1)
|
||||||
|
hexColor = hexColor.Replace("#", "");
|
||||||
|
|
||||||
|
int red = 0;
|
||||||
|
int green = 0;
|
||||||
|
int blue = 0;
|
||||||
|
|
||||||
|
if (hexColor.Length == 6)
|
||||||
|
{
|
||||||
|
//#RRGGBB
|
||||||
|
red = int.Parse(hexColor.Substring(0, 2), NumberStyles.AllowHexSpecifier);
|
||||||
|
green = int.Parse(hexColor.Substring(2, 2), NumberStyles.AllowHexSpecifier);
|
||||||
|
blue = int.Parse(hexColor.Substring(4, 2), NumberStyles.AllowHexSpecifier);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (hexColor.Length == 3)
|
||||||
|
{
|
||||||
|
//#RGB
|
||||||
|
red = int.Parse(hexColor[0].ToString() + hexColor[0].ToString(), NumberStyles.AllowHexSpecifier);
|
||||||
|
green = int.Parse(hexColor[1].ToString() + hexColor[1].ToString(), NumberStyles.AllowHexSpecifier);
|
||||||
|
blue = int.Parse(hexColor[2].ToString() + hexColor[2].ToString(), NumberStyles.AllowHexSpecifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Vector3 (red, green, blue);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
///Credit judah4
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
|
||||||
|
public class HsvBoxSelector : MonoBehaviour, IDragHandler, IPointerDownHandler {
|
||||||
|
|
||||||
|
public HSVPicker picker;
|
||||||
|
|
||||||
|
// Use this for initialization
|
||||||
|
void Start () {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update () {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlaceCursor(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
|
||||||
|
var pos = new Vector2(eventData.position.x - picker.hsvImage.rectTransform.position.x, picker.hsvImage.rectTransform.rect.height * picker.hsvImage.transform.lossyScale.y - (picker.hsvImage.rectTransform.position.y - eventData.position.y));
|
||||||
|
// Debug.Log(pos);
|
||||||
|
pos.x /= picker.hsvImage.rectTransform.rect.width * picker.hsvImage.transform.lossyScale.x;
|
||||||
|
pos.y /= picker.hsvImage.rectTransform.rect.height * picker.hsvImage.transform.lossyScale.y;
|
||||||
|
|
||||||
|
pos.x = Mathf.Clamp(pos.x, 0, .9999f); //1 is the same as 0
|
||||||
|
pos.y = Mathf.Clamp(pos.y, 0, .9999f);
|
||||||
|
|
||||||
|
//Debug.Log(pos);
|
||||||
|
picker.MoveCursor(pos.x, pos.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void OnDrag(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
PlaceCursor(eventData);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnPointerDown(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
PlaceCursor(eventData);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 95a3081947ad463418f853d27e477017
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
|
@ -0,0 +1,49 @@
|
||||||
|
///Credit judah4
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
|
||||||
|
public class HsvSliderPicker : MonoBehaviour, IDragHandler, IPointerDownHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
public HSVPicker picker;
|
||||||
|
|
||||||
|
// Use this for initialization
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlacePointer(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
|
||||||
|
var pos = new Vector2(eventData.position.x - picker.hsvSlider.rectTransform.position.x, picker.hsvSlider.rectTransform.position.y - eventData.position.y);
|
||||||
|
|
||||||
|
pos.y /= picker.hsvSlider.rectTransform.rect.height * picker.hsvSlider.canvas.transform.lossyScale.y;
|
||||||
|
|
||||||
|
//Debug.Log(eventData.position.ToString() + " " + picker.hsvSlider.rectTransform.position + " " + picker.hsvSlider.rectTransform.rect.height);
|
||||||
|
pos.y = Mathf.Clamp(pos.y, 0, 1f);
|
||||||
|
|
||||||
|
picker.MovePointer(pos.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void OnDrag(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
PlacePointer(eventData);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnPointerDown(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
PlacePointer(eventData);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7d5b03a797859a94989cdbcb68e37fb1
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
Binary file not shown.
|
@ -0,0 +1,4 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: be7385871d213f844981bd24e601eb98
|
||||||
|
NativeFormatImporter:
|
||||||
|
userData:
|
Binary file not shown.
|
@ -0,0 +1,4 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ce46c07f0028e314ab7767577ab5e7a6
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
|
@ -0,0 +1,281 @@
|
||||||
|
/// Credit BinaryX
|
||||||
|
/// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-1945602
|
||||||
|
/// Updated by ddreaper - removed dependency on a custom ScrollRect script. Now implements drag interfaces and standard Scroll Rect.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
[RequireComponent(typeof(ScrollRect))]
|
||||||
|
public class HorizontalScrollSnap : MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler
|
||||||
|
{
|
||||||
|
private Transform _screensContainer;
|
||||||
|
|
||||||
|
private int _screens = 1;
|
||||||
|
private int _startingScreen = 1;
|
||||||
|
|
||||||
|
private bool _fastSwipeTimer = false;
|
||||||
|
private int _fastSwipeCounter = 0;
|
||||||
|
private int _fastSwipeTarget = 30;
|
||||||
|
|
||||||
|
|
||||||
|
private System.Collections.Generic.List<Vector3> _positions;
|
||||||
|
private ScrollRect _scroll_rect;
|
||||||
|
private Vector3 _lerp_target;
|
||||||
|
private bool _lerp;
|
||||||
|
|
||||||
|
private int _containerSize;
|
||||||
|
|
||||||
|
[Tooltip("The gameobject that contains toggles which suggest pagination. THIS CAN BE MISSING")]
|
||||||
|
public GameObject Pagination;
|
||||||
|
|
||||||
|
[Tooltip("Button to go to the next page. (optional)")]
|
||||||
|
public GameObject NextButton;
|
||||||
|
[Tooltip("Button to go to the previous page. (optional)")]
|
||||||
|
public GameObject PrevButton;
|
||||||
|
|
||||||
|
public Boolean UseFastSwipe = true;
|
||||||
|
public int FastSwipeThreshold = 100;
|
||||||
|
|
||||||
|
private bool _startDrag = true;
|
||||||
|
private Vector3 _startPosition = new Vector3();
|
||||||
|
private int _currentScreen;
|
||||||
|
|
||||||
|
// Use this for initialization
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
_scroll_rect = gameObject.GetComponent<ScrollRect>();
|
||||||
|
_screensContainer = _scroll_rect.content;
|
||||||
|
DistributePages();
|
||||||
|
|
||||||
|
_screens = _screensContainer.childCount;
|
||||||
|
|
||||||
|
_lerp = false;
|
||||||
|
|
||||||
|
_positions = new System.Collections.Generic.List<Vector3>();
|
||||||
|
|
||||||
|
if (_screens > 0)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _screens; ++i)
|
||||||
|
{
|
||||||
|
_scroll_rect.horizontalNormalizedPosition = (float)i / (float)(_screens - 1);
|
||||||
|
_positions.Add(_screensContainer.localPosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_scroll_rect.horizontalNormalizedPosition = (float)(_startingScreen - 1) / (float)(_screens - 1);
|
||||||
|
|
||||||
|
_containerSize = (int)_screensContainer.gameObject.GetComponent<RectTransform>().offsetMax.x;
|
||||||
|
|
||||||
|
ChangeBulletsInfo(CurrentScreen());
|
||||||
|
|
||||||
|
if (NextButton)
|
||||||
|
NextButton.GetComponent<Button>().onClick.AddListener(() => { NextScreen(); });
|
||||||
|
|
||||||
|
if (PrevButton)
|
||||||
|
PrevButton.GetComponent<Button>().onClick.AddListener(() => { PreviousScreen(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
if (_lerp)
|
||||||
|
{
|
||||||
|
_screensContainer.localPosition = Vector3.Lerp(_screensContainer.localPosition, _lerp_target, 7.5f * Time.deltaTime);
|
||||||
|
if (Vector3.Distance(_screensContainer.localPosition, _lerp_target) < 0.005f)
|
||||||
|
{
|
||||||
|
_lerp = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//change the info bullets at the bottom of the screen. Just for visual effect
|
||||||
|
if (Vector3.Distance(_screensContainer.localPosition, _lerp_target) < 10f)
|
||||||
|
{
|
||||||
|
ChangeBulletsInfo(CurrentScreen());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_fastSwipeTimer)
|
||||||
|
{
|
||||||
|
_fastSwipeCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool fastSwipe = false; //to determine if a fast swipe was performed
|
||||||
|
|
||||||
|
|
||||||
|
//Function for switching screens with buttons
|
||||||
|
public void NextScreen()
|
||||||
|
{
|
||||||
|
if (CurrentScreen() < _screens - 1)
|
||||||
|
{
|
||||||
|
_lerp = true;
|
||||||
|
_lerp_target = _positions[CurrentScreen() + 1];
|
||||||
|
|
||||||
|
ChangeBulletsInfo(CurrentScreen() + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Function for switching screens with buttons
|
||||||
|
public void PreviousScreen()
|
||||||
|
{
|
||||||
|
if (CurrentScreen() > 0)
|
||||||
|
{
|
||||||
|
_lerp = true;
|
||||||
|
_lerp_target = _positions[CurrentScreen() - 1];
|
||||||
|
|
||||||
|
ChangeBulletsInfo(CurrentScreen() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Because the CurrentScreen function is not so reliable, these are the functions used for swipes
|
||||||
|
private void NextScreenCommand()
|
||||||
|
{
|
||||||
|
if (_currentScreen < _screens - 1)
|
||||||
|
{
|
||||||
|
_lerp = true;
|
||||||
|
_lerp_target = _positions[_currentScreen + 1];
|
||||||
|
|
||||||
|
ChangeBulletsInfo(_currentScreen + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Because the CurrentScreen function is not so reliable, these are the functions used for swipes
|
||||||
|
private void PrevScreenCommand()
|
||||||
|
{
|
||||||
|
if (_currentScreen > 0)
|
||||||
|
{
|
||||||
|
_lerp = true;
|
||||||
|
_lerp_target = _positions[_currentScreen - 1];
|
||||||
|
|
||||||
|
ChangeBulletsInfo(_currentScreen - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//find the closest registered point to the releasing point
|
||||||
|
private Vector3 FindClosestFrom(Vector3 start, System.Collections.Generic.List<Vector3> positions)
|
||||||
|
{
|
||||||
|
Vector3 closest = Vector3.zero;
|
||||||
|
float distance = Mathf.Infinity;
|
||||||
|
|
||||||
|
foreach (Vector3 position in _positions)
|
||||||
|
{
|
||||||
|
if (Vector3.Distance(start, position) < distance)
|
||||||
|
{
|
||||||
|
distance = Vector3.Distance(start, position);
|
||||||
|
closest = position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return closest;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//returns the current screen that the is seeing
|
||||||
|
public int CurrentScreen()
|
||||||
|
{
|
||||||
|
float absPoz = Math.Abs(_screensContainer.gameObject.GetComponent<RectTransform>().offsetMin.x);
|
||||||
|
|
||||||
|
absPoz = Mathf.Clamp(absPoz, 1, _containerSize - 1);
|
||||||
|
|
||||||
|
float calc = ( absPoz / _containerSize) * _screens;
|
||||||
|
|
||||||
|
return (int) calc;
|
||||||
|
}
|
||||||
|
|
||||||
|
//changes the bullets on the bottom of the page - pagination
|
||||||
|
private void ChangeBulletsInfo(int currentScreen)
|
||||||
|
{
|
||||||
|
if (Pagination)
|
||||||
|
for (int i = 0; i < Pagination.transform.childCount; i++)
|
||||||
|
{
|
||||||
|
Pagination.transform.GetChild(i).GetComponent<Toggle>().isOn = (currentScreen == i)
|
||||||
|
? true
|
||||||
|
: false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//used for changing between screen resolutions
|
||||||
|
private void DistributePages()
|
||||||
|
{
|
||||||
|
int _offset = 0;
|
||||||
|
int _step = Screen.width;
|
||||||
|
int _dimension = 0;
|
||||||
|
|
||||||
|
int currentXPosition = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < _screensContainer.transform.childCount; i++)
|
||||||
|
{
|
||||||
|
RectTransform child = _screensContainer.transform.GetChild(i).gameObject.GetComponent<RectTransform>();
|
||||||
|
currentXPosition = _offset + i * _step;
|
||||||
|
child.anchoredPosition = new Vector2(currentXPosition, 0f);
|
||||||
|
child.sizeDelta = new Vector2( gameObject.GetComponent<RectTransform>().sizeDelta.x, gameObject.GetComponent<RectTransform>().sizeDelta.y );
|
||||||
|
}
|
||||||
|
|
||||||
|
_dimension = currentXPosition + _offset * -1;
|
||||||
|
|
||||||
|
_screensContainer.GetComponent<RectTransform>().offsetMax = new Vector2(_dimension, 0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Interfaces
|
||||||
|
public void OnBeginDrag(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
_startPosition = _screensContainer.localPosition;
|
||||||
|
_fastSwipeCounter = 0;
|
||||||
|
_fastSwipeTimer = true;
|
||||||
|
_currentScreen = CurrentScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnEndDrag(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
_startDrag = true;
|
||||||
|
if (_scroll_rect.horizontal)
|
||||||
|
{
|
||||||
|
if (UseFastSwipe)
|
||||||
|
{
|
||||||
|
fastSwipe = false;
|
||||||
|
_fastSwipeTimer = false;
|
||||||
|
if (_fastSwipeCounter <= _fastSwipeTarget)
|
||||||
|
{
|
||||||
|
if (Math.Abs(_startPosition.x - _screensContainer.localPosition.x) > FastSwipeThreshold)
|
||||||
|
{
|
||||||
|
fastSwipe = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fastSwipe)
|
||||||
|
{
|
||||||
|
if (_startPosition.x - _screensContainer.localPosition.x > 0)
|
||||||
|
{
|
||||||
|
NextScreenCommand();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PrevScreenCommand();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_lerp = true;
|
||||||
|
_lerp_target = FindClosestFrom(_screensContainer.localPosition, _positions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_lerp = true;
|
||||||
|
_lerp_target = FindClosestFrom(_screensContainer.localPosition, _positions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnDrag(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
_lerp = false;
|
||||||
|
if (_startDrag)
|
||||||
|
{
|
||||||
|
OnBeginDrag(eventData);
|
||||||
|
_startDrag = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
|
@ -0,0 +1,156 @@
|
||||||
|
/// Credit Deeperbeige
|
||||||
|
/// Sourced from - http://forum.unity3d.com/threads/adjustable-character-spacing-free-script.288277/
|
||||||
|
/*
|
||||||
|
|
||||||
|
Produces an simple tracking/letter-spacing effect on UI Text components.
|
||||||
|
|
||||||
|
Set the spacing parameter to adjust letter spacing.
|
||||||
|
Negative values cuddle the text up tighter than normal. Go too far and it'll look odd.
|
||||||
|
Positive values spread the text out more than normal. This will NOT respect the text area you've defined.
|
||||||
|
Zero spacing will present the font with no changes.
|
||||||
|
|
||||||
|
Relies on counting off characters in your Text component's text property and
|
||||||
|
matching those against the quads passed in via the verts array. This is really
|
||||||
|
rather primitive, but I can't see any better way at the moment. It means that
|
||||||
|
all sorts of things can break the effect...
|
||||||
|
|
||||||
|
This component should be placed higher in component list than any other vertex
|
||||||
|
modifiers that alter the total number of vertices. Eg, place this above Shadow
|
||||||
|
or Outline effects. If you don't, the outline/shadow won't match the position
|
||||||
|
of the letters properly. If you place the outline/shadow effect second however,
|
||||||
|
it will just work on the altered vertices from this component, and function
|
||||||
|
as expected.
|
||||||
|
|
||||||
|
This component works best if you don't allow text to automatically wrap. It also
|
||||||
|
blows up outside of the given text area. Basically, it's a cheap and dirty effect,
|
||||||
|
not a clever text layout engine. It can't affect how Unity chooses to break up
|
||||||
|
your lines. If you manually use line breaks however, it should detect those and
|
||||||
|
function more or less as you'd expect.
|
||||||
|
|
||||||
|
The spacing parameter is measured in pixels multiplied by the font size. This was
|
||||||
|
chosen such that when you adjust the font size, it does not change the visual spacing
|
||||||
|
that you've dialed in. There's also a scale factor of 1/100 in this number to
|
||||||
|
bring it into a comfortable adjustable range. There's no limit on this parameter,
|
||||||
|
but obviously some values will look quite strange.
|
||||||
|
|
||||||
|
This component doesn't really work with Rich Text. You don't need to remember to
|
||||||
|
turn off Rich Text via the checkbox, but because it can't see what makes a
|
||||||
|
printable character and what doesn't, it will typically miscount characters when you
|
||||||
|
use HTML-like tags in your text. Try it out, you'll see what I mean. It doesn't
|
||||||
|
break down entirely, but it doesn't really do what you'd want either.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
|
||||||
|
namespace UnityEngine.UI
|
||||||
|
{
|
||||||
|
[AddComponentMenu("UI/Effects/Letter Spacing", 14)]
|
||||||
|
public class LetterSpacing : BaseVertexEffect
|
||||||
|
{
|
||||||
|
[SerializeField]
|
||||||
|
private float m_spacing = 0f;
|
||||||
|
|
||||||
|
protected LetterSpacing() { }
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
protected override void OnValidate()
|
||||||
|
{
|
||||||
|
spacing = m_spacing;
|
||||||
|
base.OnValidate();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public float spacing
|
||||||
|
{
|
||||||
|
get { return m_spacing; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (m_spacing == value) return;
|
||||||
|
m_spacing = value;
|
||||||
|
if (graphic != null) graphic.SetVerticesDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ModifyVertices(List<UIVertex> verts)
|
||||||
|
{
|
||||||
|
if (! IsActive()) return;
|
||||||
|
|
||||||
|
Text text = GetComponent<Text>();
|
||||||
|
if (text == null)
|
||||||
|
{
|
||||||
|
Debug.LogWarning("LetterSpacing: Missing Text component");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] lines = text.text.Split('\n');
|
||||||
|
Vector3 pos;
|
||||||
|
float letterOffset = spacing * (float)text.fontSize / 100f;
|
||||||
|
float alignmentFactor = 0;
|
||||||
|
int glyphIdx = 0;
|
||||||
|
|
||||||
|
switch (text.alignment)
|
||||||
|
{
|
||||||
|
case TextAnchor.LowerLeft:
|
||||||
|
case TextAnchor.MiddleLeft:
|
||||||
|
case TextAnchor.UpperLeft:
|
||||||
|
alignmentFactor = 0f;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TextAnchor.LowerCenter:
|
||||||
|
case TextAnchor.MiddleCenter:
|
||||||
|
case TextAnchor.UpperCenter:
|
||||||
|
alignmentFactor = 0.5f;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TextAnchor.LowerRight:
|
||||||
|
case TextAnchor.MiddleRight:
|
||||||
|
case TextAnchor.UpperRight:
|
||||||
|
alignmentFactor = 1f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int lineIdx=0; lineIdx < lines.Length; lineIdx++)
|
||||||
|
{
|
||||||
|
string line = lines[lineIdx];
|
||||||
|
float lineOffset = (line.Length -1) * letterOffset * alignmentFactor;
|
||||||
|
|
||||||
|
for (int charIdx = 0; charIdx < line.Length; charIdx++)
|
||||||
|
{
|
||||||
|
int idx1 = glyphIdx * 4 + 0;
|
||||||
|
int idx2 = glyphIdx * 4 + 1;
|
||||||
|
int idx3 = glyphIdx * 4 + 2;
|
||||||
|
int idx4 = glyphIdx * 4 + 3;
|
||||||
|
|
||||||
|
// Check for truncated text (doesn't generate verts for all characters)
|
||||||
|
if (idx4 > verts.Count - 1) return;
|
||||||
|
|
||||||
|
UIVertex vert1 = verts[idx1];
|
||||||
|
UIVertex vert2 = verts[idx2];
|
||||||
|
UIVertex vert3 = verts[idx3];
|
||||||
|
UIVertex vert4 = verts[idx4];
|
||||||
|
|
||||||
|
pos = Vector3.right * (letterOffset * charIdx - lineOffset);
|
||||||
|
|
||||||
|
vert1.position += pos;
|
||||||
|
vert2.position += pos;
|
||||||
|
vert3.position += pos;
|
||||||
|
vert4.position += pos;
|
||||||
|
|
||||||
|
verts[idx1] = vert1;
|
||||||
|
verts[idx2] = vert2;
|
||||||
|
verts[idx3] = vert3;
|
||||||
|
verts[idx4] = vert4;
|
||||||
|
|
||||||
|
glyphIdx++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset for carriage return character that still generates verts
|
||||||
|
glyphIdx++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,178 @@
|
||||||
|
/// Credit Melang
|
||||||
|
/// Sourced from - http://forum.unity3d.com/members/melang.593409/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
namespace UnityEngine.UI
|
||||||
|
{
|
||||||
|
//An outline that looks a bit nicer than the default one. It has less "holes" in the outline by drawing more copies of the effect
|
||||||
|
[AddComponentMenu ("UI/Effects/NicerOutline", 15)]
|
||||||
|
public class NicerOutline : BaseVertexEffect
|
||||||
|
{
|
||||||
|
[SerializeField]
|
||||||
|
private Color m_EffectColor = new Color (0f, 0f, 0f, 0.5f);
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private Vector2 m_EffectDistance = new Vector2 (1f, -1f);
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private bool m_UseGraphicAlpha = true;
|
||||||
|
//
|
||||||
|
// Properties
|
||||||
|
//
|
||||||
|
public Color effectColor
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return this.m_EffectColor;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
this.m_EffectColor = value;
|
||||||
|
if (base.graphic != null)
|
||||||
|
{
|
||||||
|
base.graphic.SetVerticesDirty ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector2 effectDistance
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return this.m_EffectDistance;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value.x > 600f)
|
||||||
|
{
|
||||||
|
value.x = 600f;
|
||||||
|
}
|
||||||
|
if (value.x < -600f)
|
||||||
|
{
|
||||||
|
value.x = -600f;
|
||||||
|
}
|
||||||
|
if (value.y > 600f)
|
||||||
|
{
|
||||||
|
value.y = 600f;
|
||||||
|
}
|
||||||
|
if (value.y < -600f)
|
||||||
|
{
|
||||||
|
value.y = -600f;
|
||||||
|
}
|
||||||
|
if (this.m_EffectDistance == value)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.m_EffectDistance = value;
|
||||||
|
if (base.graphic != null)
|
||||||
|
{
|
||||||
|
base.graphic.SetVerticesDirty ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool useGraphicAlpha
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return this.m_UseGraphicAlpha;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
this.m_UseGraphicAlpha = value;
|
||||||
|
if (base.graphic != null)
|
||||||
|
{
|
||||||
|
base.graphic.SetVerticesDirty ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Methods
|
||||||
|
//
|
||||||
|
protected void ApplyShadow (List<UIVertex> verts, Color32 color, int start, int end, float x, float y)
|
||||||
|
{
|
||||||
|
//Debug.Log("verts count: "+verts.Count);
|
||||||
|
int num = verts.Count * 2;
|
||||||
|
if (verts.Capacity < num)
|
||||||
|
{
|
||||||
|
verts.Capacity = num;
|
||||||
|
}
|
||||||
|
for (int i = start; i < end; i++)
|
||||||
|
{
|
||||||
|
UIVertex uIVertex = verts [i];
|
||||||
|
verts.Add (uIVertex);
|
||||||
|
|
||||||
|
Vector3 position = uIVertex.position;
|
||||||
|
//Debug.Log("vertex pos: "+position);
|
||||||
|
position.x += x;
|
||||||
|
position.y += y;
|
||||||
|
uIVertex.position = position;
|
||||||
|
Color32 color2 = color;
|
||||||
|
if (this.m_UseGraphicAlpha)
|
||||||
|
{
|
||||||
|
color2.a = (byte)(color2.a * verts [i].color.a / 255);
|
||||||
|
}
|
||||||
|
uIVertex.color = color2;
|
||||||
|
//uIVertex.color = (Color32)Color.blue;
|
||||||
|
verts [i] = uIVertex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ModifyVertices (List<UIVertex> verts)
|
||||||
|
{
|
||||||
|
if (!this.IsActive ())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Text foundtext = GetComponent<Text>();
|
||||||
|
|
||||||
|
float best_fit_adjustment = 1f;
|
||||||
|
|
||||||
|
if (foundtext && foundtext.resizeTextForBestFit)
|
||||||
|
{
|
||||||
|
best_fit_adjustment = (float)foundtext.cachedTextGenerator.fontSizeUsedForBestFit / (foundtext.resizeTextMaxSize-1); //max size seems to be exclusive
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
float distanceX = this.effectDistance.x * best_fit_adjustment;
|
||||||
|
float distanceY = this.effectDistance.y * best_fit_adjustment;
|
||||||
|
|
||||||
|
int start = 0;
|
||||||
|
int count = verts.Count;
|
||||||
|
this.ApplyShadow (verts, this.effectColor, start, verts.Count, distanceX, distanceY);
|
||||||
|
start = count;
|
||||||
|
count = verts.Count;
|
||||||
|
this.ApplyShadow (verts, this.effectColor, start, verts.Count, distanceX, -distanceY);
|
||||||
|
start = count;
|
||||||
|
count = verts.Count;
|
||||||
|
this.ApplyShadow (verts, this.effectColor, start, verts.Count, -distanceX, distanceY);
|
||||||
|
start = count;
|
||||||
|
count = verts.Count;
|
||||||
|
this.ApplyShadow (verts, this.effectColor, start, verts.Count, -distanceX, -distanceY);
|
||||||
|
|
||||||
|
start = count;
|
||||||
|
count = verts.Count;
|
||||||
|
this.ApplyShadow (verts, this.effectColor, start, verts.Count, distanceX, 0);
|
||||||
|
start = count;
|
||||||
|
count = verts.Count;
|
||||||
|
this.ApplyShadow (verts, this.effectColor, start, verts.Count, -distanceX, 0);
|
||||||
|
|
||||||
|
start = count;
|
||||||
|
count = verts.Count;
|
||||||
|
this.ApplyShadow (verts, this.effectColor, start, verts.Count, 0, distanceY);
|
||||||
|
start = count;
|
||||||
|
count = verts.Count;
|
||||||
|
this.ApplyShadow (verts, this.effectColor, start, verts.Count, 0, -distanceY);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnValidate ()
|
||||||
|
{
|
||||||
|
this.effectDistance = this.m_EffectDistance;
|
||||||
|
base.OnValidate ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,6 @@
|
||||||
//Sourced from - https://github.com/senritsu/unitility/blob/master/Assets/Unitility/GUI/RaycastMask.cs
|
/// Credit senritsu
|
||||||
|
/// Sourced from - https://github.com/senritsu/unitility/blob/master/Assets/Unitility/GUI/RaycastMask.cs
|
||||||
|
|
||||||
/***************************************************************************\
|
/***************************************************************************\
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
/// Credit Melang
|
||||||
|
/// Sourced from - http://forum.unity3d.com/members/melang.593409/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
public class ReturnKeyTriggersButton : MonoBehaviour {
|
||||||
|
|
||||||
|
EventSystem system;
|
||||||
|
InputField field;
|
||||||
|
|
||||||
|
public UnityEngine.UI.Button button;
|
||||||
|
public bool highlight = true;
|
||||||
|
public float highlightDuration = 0.2f;
|
||||||
|
|
||||||
|
void Start ()
|
||||||
|
{
|
||||||
|
|
||||||
|
system = EventSystemManager.currentSystem;
|
||||||
|
|
||||||
|
field = GetComponent<InputField>();
|
||||||
|
|
||||||
|
field.onSubmit.AddListener(new UnityEngine.Events.UnityAction<string>(OnSubmitField));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void OnSubmitField(string value)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (highlight) button.OnPointerEnter(new PointerEventData(system));
|
||||||
|
button.OnPointerClick(new PointerEventData(system));
|
||||||
|
|
||||||
|
if (highlight) Invoke("RemoveHighlight", highlightDuration);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveHighlight()
|
||||||
|
{
|
||||||
|
button.OnPointerExit(new PointerEventData(system));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
/// Original Credit Korindian
|
||||||
|
/// Sourced from - http://forum.unity3d.com/threads/rts-style-drag-selection-box.265739/
|
||||||
|
/// Updated Credit BenZed
|
||||||
|
/// Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
using UnityEngine.UI.Extensions;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
public class ExampleSelectable : MonoBehaviour, IBoxSelectable {
|
||||||
|
|
||||||
|
#region Implemented members of IBoxSelectable
|
||||||
|
bool _selected = false;
|
||||||
|
public bool selected {
|
||||||
|
get {
|
||||||
|
return _selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
_selected = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _preSelected = false;
|
||||||
|
public bool preSelected {
|
||||||
|
get {
|
||||||
|
return _preSelected;
|
||||||
|
}
|
||||||
|
|
||||||
|
set {
|
||||||
|
_preSelected = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
//We want the test object to be either a UI element, a 2D element or a 3D element, so we'll get the appropriate components
|
||||||
|
SpriteRenderer spriteRenderer;
|
||||||
|
Image image;
|
||||||
|
Text text;
|
||||||
|
|
||||||
|
void Start () {
|
||||||
|
spriteRenderer = transform.GetComponent<SpriteRenderer>();
|
||||||
|
image = transform.GetComponent<Image>();
|
||||||
|
text = transform.GetComponent<Text>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update () {
|
||||||
|
|
||||||
|
//What the game object does with the knowledge that it is selected is entirely up to it.
|
||||||
|
//In this case we're just going to change the color.
|
||||||
|
|
||||||
|
//White if deselected.
|
||||||
|
Color color = Color.white;
|
||||||
|
|
||||||
|
if (preSelected) {
|
||||||
|
//Yellow if preselected
|
||||||
|
color = Color.yellow;
|
||||||
|
}
|
||||||
|
if (selected) {
|
||||||
|
//And green if selected.
|
||||||
|
color = Color.green;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set the color depending on what the game object has.
|
||||||
|
if (spriteRenderer) {
|
||||||
|
spriteRenderer.color = color;
|
||||||
|
} else if (text) {
|
||||||
|
text.color = color;
|
||||||
|
} else if (image) {
|
||||||
|
image.color = color;
|
||||||
|
} else if (renderer) {
|
||||||
|
renderer.material.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d0644987412a04edd8105e64bdd008b2
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
|
@ -0,0 +1,33 @@
|
||||||
|
///Original Credit Korindian
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/rts-style-drag-selection-box.265739/
|
||||||
|
///Updated Credit BenZed
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace UnityEngine.UI.Extensions {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Implement this interface on any MonoBehaviour that you'd like to be considered selectable.
|
||||||
|
*/
|
||||||
|
public interface IBoxSelectable {
|
||||||
|
bool selected {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool preSelected {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
//This property doesn't actually need to be implemented, as this interface should already be placed on a MonoBehaviour, which will
|
||||||
|
//already have it. Defining it here only allows us access to the transform property by casting through the selectable interface.
|
||||||
|
Transform transform {
|
||||||
|
get;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 72b70b31ccbda4bae8dd5cda36d2e02d
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
Binary file not shown.
|
@ -0,0 +1,4 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e0944d7e4f0234f3fabb9b2f33fe073e
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
|
@ -0,0 +1,443 @@
|
||||||
|
///Original Credit Korindian
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/rts-style-drag-selection-box.265739/
|
||||||
|
///Updated Credit BenZed
|
||||||
|
///Sourced from - http://forum.unity3d.com/threads/color-picker.267043/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* What the SelectionBox component does is allow the game player to select objects using an RTS style click and drag interface:
|
||||||
|
*
|
||||||
|
* We want to be able to select Game Objects of any type,
|
||||||
|
* We want to be able to drag select a group of game objects to select them,
|
||||||
|
* We want to be able to hold the shift key and drag select a group of game objects to add them to the current selection,
|
||||||
|
* We want to be able to single click a game object to select it,
|
||||||
|
* We want to be able to hold the shift key and single click a game object to add it to the current selection,
|
||||||
|
* We want to be able to hold the shift key and single click an already selected game object to remove it from the current selection.
|
||||||
|
*
|
||||||
|
* Most importantly, we want this behaviour to work with UI, 2D or 3D gameObjects, so it has to be smart about considering their respective screen spaces.
|
||||||
|
*
|
||||||
|
* Add this component to a Gameobject with a Canvas with RenderMode.ScreenSpaceOverlay
|
||||||
|
* And implement the IBoxSelectable interface on any MonoBehaviour to make it selectable.
|
||||||
|
*
|
||||||
|
* Improvements that could be made:
|
||||||
|
*
|
||||||
|
* Control clicking a game object to select all objects of that type or tag.
|
||||||
|
* Compatibility with Canvas Scaling
|
||||||
|
* Filtering single click selections of objects occupying the same space. (So that, for example, you're only click selecting the game object found closest to the camera)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Events;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
|
||||||
|
namespace UnityEngine.UI.Extensions {
|
||||||
|
|
||||||
|
|
||||||
|
[RequireComponent(typeof(Canvas))]
|
||||||
|
public class SelectionBox : MonoBehaviour
|
||||||
|
{
|
||||||
|
|
||||||
|
// The color of the selection box.
|
||||||
|
public Color color;
|
||||||
|
|
||||||
|
// An optional parameter, but you can add a sprite to the selection box to give it a border or a stylized look.
|
||||||
|
// It's suggested you use a monochrome sprite so that the selection
|
||||||
|
// Box color is still relevent.
|
||||||
|
public Sprite art;
|
||||||
|
|
||||||
|
// Will store the location of wherever we first click before dragging.
|
||||||
|
private Vector2 origin;
|
||||||
|
|
||||||
|
// A rectTransform set by the User that can limit which part of the screen is eligable for drag selection
|
||||||
|
public RectTransform selectionMask;
|
||||||
|
|
||||||
|
//Stores the rectTransform connected to the generated gameObject being used for the selection box visuals
|
||||||
|
private RectTransform boxRect;
|
||||||
|
|
||||||
|
// Stores all of the selectable game objects
|
||||||
|
private IBoxSelectable[] selectables;
|
||||||
|
|
||||||
|
// A secondary storage of objects that the user can manually set.
|
||||||
|
private MonoBehaviour[] selectableGroup;
|
||||||
|
|
||||||
|
//Stores the selectable that was touched when the mouse button was pressed down
|
||||||
|
private IBoxSelectable clickedBeforeDrag;
|
||||||
|
|
||||||
|
//Stores the selectable that was touched when the mouse button was released
|
||||||
|
private IBoxSelectable clickedAfterDrag;
|
||||||
|
|
||||||
|
//Custom UnityEvent so we can add Listeners to this instance when Selections are changed.
|
||||||
|
public class SelectionEvent : UnityEvent<IBoxSelectable[]> {}
|
||||||
|
public SelectionEvent onSelectionChange = new SelectionEvent();
|
||||||
|
|
||||||
|
//Ensures that the canvas that this component is attached to is set to the correct render mode. If not, it will not render the selection box properly.
|
||||||
|
void ValidateCanvas(){
|
||||||
|
var canvas = gameObject.GetComponent<Canvas>();
|
||||||
|
|
||||||
|
if (canvas.renderMode != RenderMode.ScreenSpaceOverlay) {
|
||||||
|
throw new System.Exception("SelectionBox component must be placed on a canvas in Screen Space Overlay mode.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var canvasScaler = gameObject.GetComponent<CanvasScaler>();
|
||||||
|
|
||||||
|
if (canvasScaler && canvasScaler.enabled && (!Mathf.Approximately(canvasScaler.scaleFactor, 1f) || canvasScaler.uiScaleMode != CanvasScaler.ScaleMode.ConstantPixelSize)) {
|
||||||
|
Destroy(canvasScaler);
|
||||||
|
Debug.LogWarning("SelectionBox component is on a gameObject with a Canvas Scaler component. As of now, Canvas Scalers without the default settings throw off the coordinates of the selection box. Canvas Scaler has been removed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The user can manually set a group of objects with monoBehaviours to be the pool of objects considered to be selectable. The benefits of this are two fold:
|
||||||
|
*
|
||||||
|
* 1) The default behaviour is to check every game object in the scene, which is much slower.
|
||||||
|
* 2) The user can filter which objects should be selectable, for example units versus menu selections
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void SetSelectableGroup(IEnumerable<MonoBehaviour> behaviourCollection) {
|
||||||
|
|
||||||
|
// If null, the selectionbox reverts to it's default behaviour
|
||||||
|
if (behaviourCollection == null) {
|
||||||
|
selectableGroup = null;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Runs a double check to ensure each of the objects in the collection can be selectable, and doesn't include them if not.
|
||||||
|
var behaviourList = new List<MonoBehaviour>();
|
||||||
|
|
||||||
|
foreach(var behaviour in behaviourCollection) {
|
||||||
|
if (behaviour as IBoxSelectable != null) {
|
||||||
|
behaviourList.Add (behaviour);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
selectableGroup = behaviourList.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreateBoxRect(){
|
||||||
|
var selectionBoxGO = new GameObject();
|
||||||
|
|
||||||
|
selectionBoxGO.name = "Selection Box";
|
||||||
|
selectionBoxGO.transform.parent = transform;
|
||||||
|
selectionBoxGO.AddComponent<Image>();
|
||||||
|
|
||||||
|
boxRect = selectionBoxGO.transform as RectTransform;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set all of the relevant rectTransform properties to zero,
|
||||||
|
//finally deactivates the boxRect gameobject since it doesn't
|
||||||
|
//need to be enabled when not in a selection action.
|
||||||
|
void ResetBoxRect(){
|
||||||
|
|
||||||
|
//Update the art and color on the off chance they've changed
|
||||||
|
Image image = boxRect.GetComponent<Image>();
|
||||||
|
image.color = color;
|
||||||
|
image.sprite = art;
|
||||||
|
|
||||||
|
origin = Vector2.zero;
|
||||||
|
|
||||||
|
boxRect.anchoredPosition = Vector2.zero;
|
||||||
|
boxRect.sizeDelta = Vector2.zero;
|
||||||
|
boxRect.anchorMax = Vector2.zero;
|
||||||
|
boxRect.anchorMin = Vector2.zero;
|
||||||
|
boxRect.pivot = Vector2.zero;
|
||||||
|
boxRect.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void BeginSelection(){
|
||||||
|
// Click somewhere in the Game View.
|
||||||
|
if (!Input.GetMouseButtonDown(0))
|
||||||
|
return;
|
||||||
|
|
||||||
|
//The boxRect will be inactive up until the point we start selecting
|
||||||
|
boxRect.gameObject.SetActive(true);
|
||||||
|
|
||||||
|
// Get the initial click position of the mouse.
|
||||||
|
origin = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
|
||||||
|
|
||||||
|
//If the initial click point is not inside the selection mask, we abort the selection
|
||||||
|
if (!PointIsValidAgainstSelectionMask(origin)) {
|
||||||
|
ResetBoxRect();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The anchor is set to the same place.
|
||||||
|
boxRect.anchoredPosition = origin;
|
||||||
|
|
||||||
|
MonoBehaviour[] behavioursToGetSelectionsFrom;
|
||||||
|
|
||||||
|
// If we do not have a group of selectables already set, we'll just loop through every object that's a monobehaviour, and look for selectable interfaces in them
|
||||||
|
if (selectableGroup == null) {
|
||||||
|
behavioursToGetSelectionsFrom = GameObject.FindObjectsOfType<MonoBehaviour>();
|
||||||
|
} else {
|
||||||
|
behavioursToGetSelectionsFrom = selectableGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Temporary list to store the found selectables before converting to the main selectables array
|
||||||
|
List<IBoxSelectable> selectableList = new List<IBoxSelectable>();
|
||||||
|
|
||||||
|
foreach (MonoBehaviour behaviour in behavioursToGetSelectionsFrom) {
|
||||||
|
|
||||||
|
//If the behaviour implements the selectable interface, we add it to the selectable list
|
||||||
|
IBoxSelectable selectable = behaviour as IBoxSelectable;
|
||||||
|
if (selectable != null) {
|
||||||
|
selectableList.Add (selectable);
|
||||||
|
|
||||||
|
//We're using left shift to act as the "Add To Selection" command. So if left shift isn't pressed, we want everything to begin deselected
|
||||||
|
if (!Input.GetKey (KeyCode.LeftShift)) {
|
||||||
|
selectable.selected = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
selectables = selectableList.ToArray();
|
||||||
|
|
||||||
|
//For single-click actions, we need to get the selectable that was clicked when selection began (if any)
|
||||||
|
clickedBeforeDrag = GetSelectableAtMousePosition();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PointIsValidAgainstSelectionMask(Vector2 screenPoint){
|
||||||
|
//If there is no seleciton mask, any point is valid
|
||||||
|
if (!selectionMask) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Camera screenPointCamera = GetScreenPointCamera(selectionMask);
|
||||||
|
|
||||||
|
return RectTransformUtility.RectangleContainsScreenPoint(selectionMask, screenPoint, screenPointCamera);
|
||||||
|
}
|
||||||
|
|
||||||
|
IBoxSelectable GetSelectableAtMousePosition() {
|
||||||
|
//Firstly, we cannot click on something that is not inside the selection mask (if we have one)
|
||||||
|
if (!PointIsValidAgainstSelectionMask(Input.mousePosition)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//This gets a bit tricky, because we have to make considerations depending on the heirarchy of the selectable's gameObject
|
||||||
|
foreach (var selectable in selectables) {
|
||||||
|
|
||||||
|
//First we check to see if the selectable has a rectTransform
|
||||||
|
var rectTransform = (selectable.transform as RectTransform);
|
||||||
|
|
||||||
|
if (rectTransform) {
|
||||||
|
//Because if it does, the camera we use to calulate it's screen point will vary
|
||||||
|
var screenCamera = GetScreenPointCamera(rectTransform);
|
||||||
|
|
||||||
|
//Once we've found the rendering camera, we check if the selectables rectTransform contains the click. That way we
|
||||||
|
//Can click anywhere on a rectTransform to select it.
|
||||||
|
if (RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, screenCamera)) {
|
||||||
|
|
||||||
|
//And if it does, we select it and send it back
|
||||||
|
return selectable;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//If it doesn't have a rectTransform, we need to get the radius so we can use it as an area around the center to detect a click.
|
||||||
|
//This works because a 2D or 3D renderer will both return a radius
|
||||||
|
var radius = selectable.transform.renderer.bounds.extents.magnitude;
|
||||||
|
|
||||||
|
var selectableScreenPoint = GetScreenPointOfSelectable(selectable);
|
||||||
|
|
||||||
|
//Check that the click fits within the screen-radius of the selectable
|
||||||
|
if (Vector2.Distance(selectableScreenPoint, Input.mousePosition) <= radius) {
|
||||||
|
|
||||||
|
//And if it does, we select it and send it back
|
||||||
|
return selectable;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DragSelection(){
|
||||||
|
//Return if we're not dragging or if the selection has been aborted (BoxRect disabled)
|
||||||
|
if (!Input.GetMouseButton(0) || !boxRect.gameObject.activeSelf)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Store the current mouse position in screen space.
|
||||||
|
Vector2 currentMousePosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
|
||||||
|
|
||||||
|
// How far have we moved the mouse?
|
||||||
|
Vector2 difference = currentMousePosition - origin;
|
||||||
|
|
||||||
|
// Copy the initial click position to a new variable. Using the original variable will cause
|
||||||
|
// the anchor to move around to wherever the current mouse position is,
|
||||||
|
// which isn't desirable.
|
||||||
|
Vector2 startPoint = origin;
|
||||||
|
|
||||||
|
// The following code accounts for dragging in various directions.
|
||||||
|
if (difference.x < 0)
|
||||||
|
{
|
||||||
|
startPoint.x = currentMousePosition.x;
|
||||||
|
difference.x = -difference.x;
|
||||||
|
}
|
||||||
|
if (difference.y < 0)
|
||||||
|
{
|
||||||
|
startPoint.y = currentMousePosition.y;
|
||||||
|
difference.y = -difference.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the anchor, width and height every frame.
|
||||||
|
boxRect.anchoredPosition = startPoint;
|
||||||
|
boxRect.sizeDelta = difference;
|
||||||
|
|
||||||
|
//Then we check our list of Selectables to see if they're being preselected or not.
|
||||||
|
foreach(var selectable in selectables) {
|
||||||
|
|
||||||
|
Vector3 screenPoint = GetScreenPointOfSelectable(selectable);
|
||||||
|
|
||||||
|
//If the box Rect contains the selectabels screen point and that point is inside a valid selection mask, it's being preselected, otherwise it is not.
|
||||||
|
selectable.preSelected = RectTransformUtility.RectangleContainsScreenPoint(boxRect, screenPoint, null) && PointIsValidAgainstSelectionMask(screenPoint);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Finally, since it's possible for our first clicked object to not be within the bounds of the selection box
|
||||||
|
//If it exists, we always ensure that it is preselected.
|
||||||
|
if (clickedBeforeDrag != null) {
|
||||||
|
clickedBeforeDrag.preSelected = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApplySingleClickDeselection(){
|
||||||
|
|
||||||
|
//If we didn't touch anything with the original mouse press, we don't need to continue checking
|
||||||
|
if (clickedBeforeDrag == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
//If we clicked a selectable without dragging, and that selectable was previously selected, we must be trying to deselect it.
|
||||||
|
if (clickedAfterDrag != null && clickedBeforeDrag.selected && clickedBeforeDrag.transform == clickedAfterDrag.transform ) {
|
||||||
|
clickedBeforeDrag.selected = false;
|
||||||
|
clickedBeforeDrag.preSelected = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApplyPreSelections(){
|
||||||
|
|
||||||
|
foreach(var selectable in selectables) {
|
||||||
|
|
||||||
|
//If the selectable was preSelected, we finalize it as selected.
|
||||||
|
if (selectable.preSelected) {
|
||||||
|
selectable.selected = true;
|
||||||
|
selectable.preSelected = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2 GetScreenPointOfSelectable(IBoxSelectable selectable) {
|
||||||
|
//Getting the screen point requires it's own function, because we have to take into consideration the selectables heirarchy.
|
||||||
|
|
||||||
|
//Cast the transform as a rectTransform
|
||||||
|
var rectTransform = selectable.transform as RectTransform;
|
||||||
|
|
||||||
|
//If it has a rectTransform component, it must be in the heirarchy of a canvas, somewhere.
|
||||||
|
if (rectTransform) {
|
||||||
|
|
||||||
|
//And the camera used to calculate it's screen point will vary.
|
||||||
|
Camera renderingCamera = GetScreenPointCamera(rectTransform);
|
||||||
|
|
||||||
|
return RectTransformUtility.WorldToScreenPoint(renderingCamera, selectable.transform.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
//If it's no in the heirarchy of a canvas, the regular Camera.main.WorldToScreenPoint will do.
|
||||||
|
return Camera.main.WorldToScreenPoint(selectable.transform.position);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Finding the camera used to calculate the screenPoint of an object causes a couple of problems:
|
||||||
|
*
|
||||||
|
* If it has a rectTransform, the root Canvas that the rectTransform is a descendant of will give unusable
|
||||||
|
* screen points depending on the Canvas.RenderMode, if we don't do any further calculation.
|
||||||
|
*
|
||||||
|
* This function solves that problem.
|
||||||
|
*/
|
||||||
|
Camera GetScreenPointCamera(RectTransform rectTransform) {
|
||||||
|
|
||||||
|
Canvas rootCanvas = null;
|
||||||
|
RectTransform rectCheck = rectTransform;
|
||||||
|
|
||||||
|
//We're going to check all the canvases in the heirarchy of this rectTransform until we find the root.
|
||||||
|
do {
|
||||||
|
rootCanvas = rectCheck.GetComponent<Canvas>();
|
||||||
|
|
||||||
|
//If we found a canvas on this Object, and it's not the rootCanvas, then we don't want to keep it
|
||||||
|
if (rootCanvas && !rootCanvas.isRootCanvas) {
|
||||||
|
rootCanvas = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Then we promote the rect we're checking to it's parent.
|
||||||
|
rectCheck = (RectTransform)rectCheck.parent;
|
||||||
|
|
||||||
|
} while (rootCanvas == null);
|
||||||
|
|
||||||
|
//Once we've found the root Canvas, we return a camera depending on it's render mode.
|
||||||
|
switch (rootCanvas.renderMode) {
|
||||||
|
case RenderMode.ScreenSpaceOverlay:
|
||||||
|
//If we send back a camera when set to screen space overlay, the coordinates will not be accurate. If we return null, they will be.
|
||||||
|
return null;
|
||||||
|
|
||||||
|
case RenderMode.ScreenSpaceCamera:
|
||||||
|
//If it's set to screen space we use the world Camera that the Canvas is using.
|
||||||
|
//If it doesn't have one set, however, we have to send back the current camera. otherwise the coordinates will not be accurate.
|
||||||
|
return (rootCanvas.worldCamera) ? rootCanvas.worldCamera : Camera.main;
|
||||||
|
|
||||||
|
default:
|
||||||
|
case RenderMode.WorldSpace:
|
||||||
|
//World space always uses the current camera.
|
||||||
|
return Camera.main;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public IBoxSelectable[] GetAllSelected(){
|
||||||
|
if (selectables == null) {
|
||||||
|
return new IBoxSelectable[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
var selectedList = new List<IBoxSelectable>();
|
||||||
|
|
||||||
|
foreach(var selectable in selectables) {
|
||||||
|
if (selectable.selected) {
|
||||||
|
selectedList.Add (selectable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return selectedList.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndSelection(){
|
||||||
|
//Get out if we haven't finished selecting, or if the selection has been aborted (boxRect disabled)
|
||||||
|
if (!Input.GetMouseButtonUp(0) || !boxRect.gameObject.activeSelf)
|
||||||
|
return;
|
||||||
|
|
||||||
|
clickedAfterDrag = GetSelectableAtMousePosition();
|
||||||
|
|
||||||
|
ApplySingleClickDeselection();
|
||||||
|
ApplyPreSelections();
|
||||||
|
ResetBoxRect();
|
||||||
|
onSelectionChange.Invoke(GetAllSelected());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Start(){
|
||||||
|
ValidateCanvas();
|
||||||
|
CreateBoxRect();
|
||||||
|
ResetBoxRect();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update() {
|
||||||
|
BeginSelection ();
|
||||||
|
DragSelection ();
|
||||||
|
EndSelection ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 0f143353fa45b4df79a3722ad82431d5
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
|
@ -1,8 +1,10 @@
|
||||||
//Author: Melang http://forum.unity3d.com/members/melang.593409/
|
/// Credit Melang
|
||||||
//Updated omatase 10-18-14 - support for Shift + Tab as well
|
/// Sourced from - http://forum.unity3d.com/members/melang.593409/
|
||||||
// - bug fix to prevent crash if no control selected
|
/// Updated omatase 10-18-14 - support for Shift + Tab as well
|
||||||
// - updated to support new semantics for EventSystem in later 4.6 builds
|
/// - bug fix to prevent crash if no control selected
|
||||||
// - autoselect "firstSelectedGameObject" since it doesn't seem to work automatically
|
/// - updated to support new semantics for EventSystem in later 4.6 builds
|
||||||
|
/// - autoselect "firstSelectedGameObject" since it doesn't seem to work automatically
|
||||||
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
|
|
|
@ -0,0 +1,160 @@
|
||||||
|
/// Credit drHogan
|
||||||
|
/// Sourced from - http://forum.unity3d.com/threads/screenspace-camera-tooltip-controller-sweat-and-tears.293991/#post-1938929
|
||||||
|
|
||||||
|
//ToolTip is written by Emiliano Pastorelli, H&R Tallinn (Estonia), http://www.hammerandravens.com
|
||||||
|
//Copyright (c) 2015 Emiliano Pastorelli, H&R - Hammer&Ravens, Tallinn, Estonia.
|
||||||
|
//All rights reserved.
|
||||||
|
|
||||||
|
//Redistribution and use in source and binary forms are permitted
|
||||||
|
//provided that the above copyright notice and this paragraph are
|
||||||
|
//duplicated in all such forms and that any documentation,
|
||||||
|
//advertising materials, and other materials related to such
|
||||||
|
//distribution and use acknowledge that the software was developed
|
||||||
|
//by H&R, Hammer&Ravens. The name of the
|
||||||
|
//H&R, Hammer&Ravens may not be used to endorse or promote products derived
|
||||||
|
//from this software without specific prior written permission.
|
||||||
|
//THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||||
|
//IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||||
|
//WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class ToolTip : MonoBehaviour {
|
||||||
|
|
||||||
|
//text of the tooltip
|
||||||
|
public Text text;
|
||||||
|
|
||||||
|
//if the tooltip is inside a UI element
|
||||||
|
bool inside;
|
||||||
|
|
||||||
|
bool xShifted = false;
|
||||||
|
bool yShifted = false;
|
||||||
|
|
||||||
|
int textLength;
|
||||||
|
|
||||||
|
public float width;
|
||||||
|
public float height;
|
||||||
|
|
||||||
|
int screenWidth;
|
||||||
|
int screenHeight;
|
||||||
|
|
||||||
|
float canvasWidth;
|
||||||
|
float canvasHeight;
|
||||||
|
|
||||||
|
public float yShift;
|
||||||
|
public float xShift;
|
||||||
|
|
||||||
|
int canvasMode;
|
||||||
|
|
||||||
|
RenderMode GUIMode;
|
||||||
|
|
||||||
|
Camera GUICamera;
|
||||||
|
|
||||||
|
// Use this for initialization
|
||||||
|
public void Awake () {
|
||||||
|
|
||||||
|
GUICamera = GameObject.Find("GUICamera").GetComponent<Camera>();
|
||||||
|
|
||||||
|
text = this.gameObject.GetComponentInChildren<Text>();
|
||||||
|
|
||||||
|
inside=false;
|
||||||
|
|
||||||
|
//size of the screen
|
||||||
|
screenWidth = Screen.width;
|
||||||
|
screenHeight = Screen.height;
|
||||||
|
|
||||||
|
xShift = 0f;
|
||||||
|
yShift = -30f;
|
||||||
|
|
||||||
|
xShifted=yShifted=false;
|
||||||
|
|
||||||
|
GUIMode = this.transform.parent.GetComponent<Canvas>().renderMode;
|
||||||
|
|
||||||
|
this.gameObject.SetActive(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Call this function externally to set the text of the template and activate the tooltip
|
||||||
|
public void SetTooltip(string ttext){
|
||||||
|
|
||||||
|
if(GUIMode==RenderMode.ScreenSpaceCamera){
|
||||||
|
//set the text and fit the tooltip panel to the text size
|
||||||
|
text.text=ttext;
|
||||||
|
|
||||||
|
this.transform.GetComponent<RectTransform>().sizeDelta = new Vector2(text.preferredWidth+40f,text.preferredHeight+25f);
|
||||||
|
|
||||||
|
OnScreenSpaceCamera();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//call this function on mouse exit to deactivate the template
|
||||||
|
public void HideTooltip(){
|
||||||
|
if(GUIMode==RenderMode.ScreenSpaceCamera){
|
||||||
|
this.gameObject.SetActive(false);
|
||||||
|
inside=false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void FixedUpdate () {
|
||||||
|
if(inside){
|
||||||
|
if(GUIMode==RenderMode.ScreenSpaceCamera){
|
||||||
|
OnScreenSpaceCamera();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//main tooltip edge of screen guard and movement
|
||||||
|
public void OnScreenSpaceCamera(){
|
||||||
|
Vector3 newPos = GUICamera.ScreenToViewportPoint(Input.mousePosition-new Vector3(xShift,yShift,0f));
|
||||||
|
|
||||||
|
width = this.transform.GetComponent<RectTransform>().sizeDelta[0];
|
||||||
|
height = this.transform.GetComponent<RectTransform>().sizeDelta[1];
|
||||||
|
|
||||||
|
// check and solve problems for the tooltip that goes out of the screen on the horizontal axis
|
||||||
|
float val;
|
||||||
|
|
||||||
|
Vector3 lowerLeft = GUICamera.ViewportToWorldPoint(new Vector3(0.0f,0.0f,0.0f));
|
||||||
|
Vector3 upperRight = GUICamera.ViewportToWorldPoint(new Vector3(1.0f,1.0f,0.0f));
|
||||||
|
|
||||||
|
//check for right edge of screen
|
||||||
|
val = (GUICamera.ViewportToWorldPoint(newPos).x+width/2);
|
||||||
|
if(val>upperRight.x){
|
||||||
|
Vector3 shifter = new Vector3(val-upperRight.x,0f,0f);
|
||||||
|
Vector3 newWorldPos = new Vector3(GUICamera.ViewportToWorldPoint(newPos).x-shifter.x,newPos.y,0f);
|
||||||
|
newPos.x = GUICamera.WorldToViewportPoint(newWorldPos).x;
|
||||||
|
}
|
||||||
|
//check for left edge of screen
|
||||||
|
val = (GUICamera.ViewportToWorldPoint(newPos).x-width/2);
|
||||||
|
if(val<lowerLeft.x){
|
||||||
|
Vector3 shifter = new Vector3(lowerLeft.x-val,0f,0f);
|
||||||
|
Vector3 newWorldPos = new Vector3(GUICamera.ViewportToWorldPoint(newPos).x+shifter.x,newPos.y,0f);
|
||||||
|
newPos.x = GUICamera.WorldToViewportPoint(newWorldPos).x;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check and solve problems for the tooltip that goes out of the screen on the vertical axis
|
||||||
|
|
||||||
|
//check for upper edge of the screen
|
||||||
|
val = (GUICamera.ViewportToWorldPoint(newPos).y+height/2);
|
||||||
|
if(val>upperRight.y){
|
||||||
|
Vector3 shifter = new Vector3(0f,35f+height/2,0f);
|
||||||
|
Vector3 newWorldPos = new Vector3(newPos.x,GUICamera.ViewportToWorldPoint(newPos).y-shifter.y,0f);
|
||||||
|
newPos.y = GUICamera.WorldToViewportPoint(newWorldPos).y;
|
||||||
|
}
|
||||||
|
|
||||||
|
//check for lower edge of the screen (if the shifts of the tooltip are kept as in this code, no need for this as the tooltip always appears above the mouse bu default)
|
||||||
|
val = (GUICamera.ViewportToWorldPoint(newPos).y-height/2);
|
||||||
|
if(val<lowerLeft.y){
|
||||||
|
Vector3 shifter = new Vector3(0f,35f+height/2,0f);
|
||||||
|
Vector3 newWorldPos = new Vector3(newPos.x,GUICamera.ViewportToWorldPoint(newPos).y+shifter.y,0f);
|
||||||
|
newPos.y = GUICamera.WorldToViewportPoint(newWorldPos).y;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.transform.position= new Vector3(GUICamera.ViewportToWorldPoint(newPos).x,GUICamera.ViewportToWorldPoint(newPos).y,0f);
|
||||||
|
this.gameObject.SetActive(true);
|
||||||
|
inside=true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
/// Credit AriathTheWise
|
||||||
|
/// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-1796783
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Events;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UIButton
|
||||||
|
/// </summary>
|
||||||
|
public class UIButton : Button, IPointerDownHandler, IPointerUpHandler
|
||||||
|
{
|
||||||
|
#region Sub-Classes
|
||||||
|
[System.Serializable]
|
||||||
|
public class UIButtonEvent : UnityEvent<PointerEventData.InputButton> { }
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Events
|
||||||
|
public UIButtonEvent OnButtonClick;
|
||||||
|
public UIButtonEvent OnButtonPress;
|
||||||
|
public UIButtonEvent OnButtonRelease;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public override void OnPointerClick(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
base.OnSubmit(eventData);
|
||||||
|
|
||||||
|
if (OnButtonClick != null)
|
||||||
|
{
|
||||||
|
OnButtonClick.Invoke(eventData.button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void IPointerDownHandler.OnPointerDown (PointerEventData eventData)
|
||||||
|
{
|
||||||
|
DoStateTransition(SelectionState.Pressed, false);
|
||||||
|
|
||||||
|
if (OnButtonPress != null)
|
||||||
|
{
|
||||||
|
OnButtonPress.Invoke(eventData.button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void IPointerUpHandler.OnPointerUp (PointerEventData eventData)
|
||||||
|
{
|
||||||
|
DoStateTransition(SelectionState.Normal, false);
|
||||||
|
|
||||||
|
if (OnButtonRelease != null)
|
||||||
|
{
|
||||||
|
OnButtonRelease.Invoke(eventData.button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
/// Credit ChoMPHi
|
||||||
|
/// Sourced from - http://forum.unity3d.com/threads/script-flippable-for-ui-graphics.291711/
|
||||||
|
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace UnityEngine.UI
|
||||||
|
{
|
||||||
|
[RequireComponent(typeof(RectTransform)), RequireComponent(typeof(Graphic)), DisallowMultipleComponent, AddComponentMenu("UI/Flippable")]
|
||||||
|
public class UIFlippable : MonoBehaviour, IVertexModifier {
|
||||||
|
|
||||||
|
[SerializeField] private bool m_Horizontal = false;
|
||||||
|
[SerializeField] private bool m_Veritical = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether this <see cref="UnityEngine.UI.UIFlippable"/> should be flipped horizontally.
|
||||||
|
/// </summary>
|
||||||
|
/// <value><c>true</c> if horizontal; otherwise, <c>false</c>.</value>
|
||||||
|
public bool horizontal
|
||||||
|
{
|
||||||
|
get { return this.m_Horizontal; }
|
||||||
|
set { this.m_Horizontal = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether this <see cref="UnityEngine.UI.UIFlippable"/> should be flipped vertically.
|
||||||
|
/// </summary>
|
||||||
|
/// <value><c>true</c> if vertical; otherwise, <c>false</c>.</value>
|
||||||
|
public bool vertical
|
||||||
|
{
|
||||||
|
get { return this.m_Veritical; }
|
||||||
|
set { this.m_Veritical = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void OnValidate()
|
||||||
|
{
|
||||||
|
this.GetComponent<Graphic>().SetVerticesDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ModifyVertices(List<UIVertex> verts)
|
||||||
|
{
|
||||||
|
RectTransform rt = this.transform as RectTransform;
|
||||||
|
|
||||||
|
for (int i = 0; i < verts.Count; ++i)
|
||||||
|
{
|
||||||
|
UIVertex v = verts[i];
|
||||||
|
|
||||||
|
// Modify positions
|
||||||
|
v.position = new Vector3(
|
||||||
|
(this.m_Horizontal ? (v.position.x + (rt.rect.center.x - v.position.x) * 2) : v.position.x),
|
||||||
|
(this.m_Veritical ? (v.position.y + (rt.rect.center.y - v.position.y) * 2) : v.position.y),
|
||||||
|
v.position.z
|
||||||
|
);
|
||||||
|
|
||||||
|
// Apply
|
||||||
|
verts[i] = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-1834806 (with corrections)
|
/// Credit GXMark, alexzzzz, CaoMengde777, TroyDavis
|
||||||
// Scaling fixed for non overlay canvases - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1780612
|
/// Original Sourced from (GXMark) - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-1834806 (with corrections)
|
||||||
// Canvas border fix - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1781658
|
/// Scaling fixed for non overlay canvases (alexzzzz) - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1780612
|
||||||
// Canvas reset position fix - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1782214
|
/// Canvas border fix (CaoMengde777) - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1781658
|
||||||
|
/// Canvas reset position fix (TroyDavis)- http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/#post-1782214
|
||||||
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
//Sourced From - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/ (uGUITools link)
|
/// Credit Senshi
|
||||||
|
/// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/ (uGUITools link)
|
||||||
|
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
Loading…
Reference in New Issue