diff --git a/Scripts/Accordion/Editor.meta b/Scripts/Accordion/Editor.meta new file mode 100644 index 0000000..0d10c93 --- /dev/null +++ b/Scripts/Accordion/Editor.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: dc2df01d18eb92b49b30e7403cce8313 +folderAsset: yes +DefaultImporter: + userData: diff --git a/Scripts/Accordion/Editor/UIAccordionElementEditor.cs b/Scripts/Accordion/Editor/UIAccordionElementEditor.cs new file mode 100644 index 0000000..d672aae --- /dev/null +++ b/Scripts/Accordion/Editor/UIAccordionElementEditor.cs @@ -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(); + } + } +} \ No newline at end of file diff --git a/Scripts/Accordion/Editor/UIAccordionElementEditor.cs.meta b/Scripts/Accordion/Editor/UIAccordionElementEditor.cs.meta new file mode 100644 index 0000000..6473a75 --- /dev/null +++ b/Scripts/Accordion/Editor/UIAccordionElementEditor.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 53f48a76b4229da449e962fb3aa06279 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Scripts/Accordion/Tweening.meta b/Scripts/Accordion/Tweening.meta new file mode 100644 index 0000000..9447bb6 --- /dev/null +++ b/Scripts/Accordion/Tweening.meta @@ -0,0 +1,5 @@ +fileFormatVersion: 2 +guid: b9115417252d4cd42a5e167bdc1c2d3b +folderAsset: yes +DefaultImporter: + userData: diff --git a/Scripts/Accordion/Tweening/FloatTween.cs b/Scripts/Accordion/Tweening/FloatTween.cs new file mode 100644 index 0000000..506c5d7 --- /dev/null +++ b/Scripts/Accordion/Tweening/FloatTween.cs @@ -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 {} + 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; + + /// + /// Gets or sets the starting float. + /// + /// The start float. + public float startFloat + { + get { return m_StartFloat; } + set { m_StartFloat = value; } + } + + /// + /// Gets or sets the target float. + /// + /// The target float. + public float targetFloat + { + get { return m_TargetFloat; } + set { m_TargetFloat = value; } + } + + /// + /// Gets or sets the duration of the tween. + /// + /// The duration. + public float duration + { + get { return m_Duration; } + set { m_Duration = value; } + } + + /// + /// Gets or sets a value indicating whether this should ignore time scale. + /// + /// true if ignore time scale; otherwise, false. + public bool ignoreTimeScale + { + get { return m_IgnoreTimeScale; } + set { m_IgnoreTimeScale = value; } + } + + /// + /// Tweens the float based on percentage. + /// + /// Float percentage. + public void TweenValue(float floatPercentage) + { + if (!ValidTarget()) + return; + + m_Target.Invoke( Mathf.Lerp (m_StartFloat, m_TargetFloat, floatPercentage) ); + } + + /// + /// Adds a on changed callback. + /// + /// Callback. + public void AddOnChangedCallback(UnityAction callback) + { + if (m_Target == null) + m_Target = new FloatTweenCallback(); + + m_Target.AddListener(callback); + } + + /// + /// Adds a on finish callback. + /// + /// Callback. + 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; + } + + /// + /// Invokes the on finish callback. + /// + public void Finished() + { + if (m_Finish != null) + m_Finish.Invoke(); + } + } +} \ No newline at end of file diff --git a/Scripts/Accordion/Tweening/FloatTween.cs.meta b/Scripts/Accordion/Tweening/FloatTween.cs.meta new file mode 100644 index 0000000..1274e38 --- /dev/null +++ b/Scripts/Accordion/Tweening/FloatTween.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e28e1e9e18f7daa4db5d1ac279d6ce66 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Scripts/Accordion/Tweening/ITweenValue.cs b/Scripts/Accordion/Tweening/ITweenValue.cs new file mode 100644 index 0000000..75d904b --- /dev/null +++ b/Scripts/Accordion/Tweening/ITweenValue.cs @@ -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(); + } +} \ No newline at end of file diff --git a/Scripts/Accordion/Tweening/ITweenValue.cs.meta b/Scripts/Accordion/Tweening/ITweenValue.cs.meta new file mode 100644 index 0000000..ac402be --- /dev/null +++ b/Scripts/Accordion/Tweening/ITweenValue.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9edf9da4c14ad2843879a2331b00f738 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Scripts/Accordion/Tweening/TweenRunner.cs b/Scripts/Accordion/Tweening/TweenRunner.cs new file mode 100644 index 0000000..297a3d5 --- /dev/null +++ b/Scripts/Accordion/Tweening/TweenRunner.cs @@ -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 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); + } + } +} \ No newline at end of file diff --git a/Scripts/Accordion/Tweening/TweenRunner.cs.meta b/Scripts/Accordion/Tweening/TweenRunner.cs.meta new file mode 100644 index 0000000..a890a05 --- /dev/null +++ b/Scripts/Accordion/Tweening/TweenRunner.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d00ab96853b24074cb837ee70f07dddc +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Scripts/Accordion/UIAccordion.cs b/Scripts/Accordion/UIAccordion.cs new file mode 100644 index 0000000..03bec28 --- /dev/null +++ b/Scripts/Accordion/UIAccordion.cs @@ -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; + + /// + /// Gets or sets the transition. + /// + /// The transition. + public Transition transition + { + get { return this.m_Transition; } + set { this.m_Transition = value; } + } + + /// + /// Gets or sets the duration of the transition. + /// + /// The duration of the transition. + public float transitionDuration + { + get { return this.m_TransitionDuration; } + set { this.m_TransitionDuration = value; } + } + } +} \ No newline at end of file diff --git a/Scripts/Accordion/UIAccordion.cs.meta b/Scripts/Accordion/UIAccordion.cs.meta new file mode 100644 index 0000000..f6d184e --- /dev/null +++ b/Scripts/Accordion/UIAccordion.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 41b373e1e582f0c4286c09ce25cc7021 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Scripts/Accordion/UIAccordionElement.cs b/Scripts/Accordion/UIAccordionElement.cs new file mode 100644 index 0000000..7cf3a61 --- /dev/null +++ b/Scripts/Accordion/UIAccordionElement.cs @@ -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 m_FloatTweenRunner; + + protected UIAccordionElement() + { + if (this.m_FloatTweenRunner == null) + this.m_FloatTweenRunner = new TweenRunner(); + + 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(); + this.m_RectTransform = this.transform as RectTransform; + this.m_LayoutElement = this.gameObject.GetComponent(); + this.onValueChanged.AddListener(OnValueChanged); + } + + protected override void OnValidate() + { + base.OnValidate(); + + if (this.group == null) + { + ToggleGroup tg = this.GetComponentInParent(); + + if (tg != null) + { + this.group = tg; + } + } + + LayoutElement le = this.gameObject.GetComponent(); + + 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; + } + } +} \ No newline at end of file diff --git a/Scripts/Accordion/UIAccordionElement.cs.meta b/Scripts/Accordion/UIAccordionElement.cs.meta new file mode 100644 index 0000000..283b746 --- /dev/null +++ b/Scripts/Accordion/UIAccordionElement.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c77f1d511e8ee4445a42bc41d95bb11f +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Scripts/BestFitOutline.cs b/Scripts/BestFitOutline.cs new file mode 100644 index 0000000..dbcc0cf --- /dev/null +++ b/Scripts/BestFitOutline.cs @@ -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 verts) + { + if (!this.IsActive ()) + { + return; + } + + Text foundtext = GetComponent(); + + 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); + } + } +} diff --git a/Scripts/CanvasGroupActivator.cs b/Scripts/CanvasGroupActivator.cs new file mode 100644 index 0000000..45c3873 --- /dev/null +++ b/Scripts/CanvasGroupActivator.cs @@ -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(); + } + + List canvasGroups; + + void OnEnable() + { + ObtainCanvasGroups(); + } + + void OnFocus() + { + ObtainCanvasGroups(); + } + + void ObtainCanvasGroups() + { + canvasGroups = new List(); + canvasGroups = GameObject.FindObjectsOfType().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; + } + }); + } +} diff --git a/Scripts/ComboBox/ClickBtn.cs b/Scripts/ComboBox/ClickBtn.cs new file mode 100644 index 0000000..a06f2e5 --- /dev/null +++ b/Scripts/ComboBox/ClickBtn.cs @@ -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"); + } +} diff --git a/Scripts/ComboBox/ClickBtn.cs.meta b/Scripts/ComboBox/ClickBtn.cs.meta new file mode 100644 index 0000000..f15ec30 --- /dev/null +++ b/Scripts/ComboBox/ClickBtn.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 33a5d65e2f7d10648af0fde6d2de99cc +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Scripts/ComboBox/ComboBox.cs b/Scripts/ComboBox/ComboBox.cs new file mode 100644 index 0000000..42cca34 --- /dev/null +++ b/Scripts/ComboBox/ComboBox.cs @@ -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 _items; //conceptual items in the list + + private bool _interactable = true; + + + #region private rect transforms + /// All of these have to be properties so that the editor script can access them + + 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(); + overlayBtn = _overlay.gameObject.GetComponent