Added Cooldown button control and example scene.
Some other minor fixes includedpull/413/head
parent
290f550fc4
commit
9d6349a2a1
|
@ -1,9 +1,10 @@
|
|||
///Credit ChoMPHi
|
||||
///Sourced from - http://forum.unity3d.com/threads/accordion-type-layout.271818/
|
||||
|
||||
using UnityEngine.UI.Extensions;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UI;
|
||||
|
||||
namespace UnityEditor.UI
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
[CustomEditor(typeof(AccordionElement), true)]
|
||||
public class AccordionElementEditor : ToggleEditor {
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
/// Credit tanoshimi
|
||||
/// Sourced from - https://forum.unity3d.com/threads/read-only-fields.68976/
|
||||
///
|
||||
using UnityEditor;
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
|
||||
public class ReadOnlyDrawer : PropertyDrawer
|
||||
{
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
GUI.enabled = false;
|
||||
EditorGUI.PropertyField(position, property, label, true);
|
||||
GUI.enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 33c90f5149877a242981372f6cde9a35
|
||||
timeCreated: 1498392707
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e144d5ae849c2574ebe61b323b01d41d
|
||||
folderAsset: yes
|
||||
timeCreated: 1498408611
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,54 @@
|
|||
/// Credit SimonDarksideJ
|
||||
/// Sourced from my head
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
[RequireComponent(typeof(Image))]
|
||||
public class CooldownEffect_Image : MonoBehaviour
|
||||
{
|
||||
|
||||
public CooldownButton cooldown;
|
||||
public Text displayText;
|
||||
private Image target;
|
||||
|
||||
string originalText;
|
||||
|
||||
// Use this for initialization
|
||||
void Start()
|
||||
{
|
||||
if (cooldown == null)
|
||||
{
|
||||
Debug.LogError("Missing Cooldown Button assignment");
|
||||
}
|
||||
target = GetComponent<Image>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
target.fillAmount = Mathf.Lerp(0, 1, cooldown.CooldownTimeRemaining / cooldown.CooldownTimeout);
|
||||
if (displayText)
|
||||
{
|
||||
displayText.text = string.Format("{0}%", cooldown.CooldownPercentComplete);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (displayText)
|
||||
{
|
||||
displayText.text = originalText;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (displayText)
|
||||
{
|
||||
originalText = displayText.text;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1ca6e387bb13bff4d90528c055130c44
|
||||
timeCreated: 1498409243
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,26 @@
|
|||
/// Credit SimonDarksideJ
|
||||
/// Sourced from my head
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
[RequireComponent(typeof(SoftMaskScript))]
|
||||
public class CooldownEffect_SAUIM : MonoBehaviour {
|
||||
|
||||
public CooldownButton cooldown;
|
||||
private SoftMaskScript sauim;
|
||||
|
||||
// Use this for initialization
|
||||
void Start() {
|
||||
if (cooldown == null)
|
||||
{
|
||||
Debug.LogError("Missing Cooldown Button assignment");
|
||||
}
|
||||
sauim = GetComponent<SoftMaskScript>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
sauim.CutOff = Mathf.Lerp(0,1, cooldown.CooldownTimeElapsed / cooldown.CooldownTimeout);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ee97fdcaa3f5e8447a6bebb781fbe830
|
||||
timeCreated: 1498393575
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3dc06f5aa2fbb624fbec6c044cbcaa03
|
||||
timeCreated: 1498408627
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
After Width: | Height: | Size: 338 KiB |
|
@ -0,0 +1,57 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 53265fa76b3529848a7fb47f0f4a594b
|
||||
timeCreated: 1447969857
|
||||
licenseType: Store
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
serializedVersion: 2
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
linearTexture: 0
|
||||
correctGamma: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 0
|
||||
cubemapConvolution: 0
|
||||
cubemapConvolutionSteps: 4
|
||||
cubemapConvolutionExponent: 1.5
|
||||
seamlessCubemap: 0
|
||||
textureFormat: -1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
filterMode: -1
|
||||
aniso: 0
|
||||
mipBias: -1
|
||||
wrapMode: 0
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
rGBM: 0
|
||||
compressionQuality: 50
|
||||
allowsAlphaSplitting: 0
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 100
|
||||
alphaIsTransparency: 1
|
||||
textureType: 5
|
||||
buildTargetSettings: []
|
||||
spriteSheet:
|
||||
sprites: []
|
||||
outline: []
|
||||
spritePackingTag:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
|
@ -0,0 +1,57 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2b2d3cd4355b13b4699d3f1abf451cf7
|
||||
timeCreated: 1447970042
|
||||
licenseType: Store
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
serializedVersion: 2
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 1
|
||||
linearTexture: 0
|
||||
correctGamma: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 0
|
||||
cubemapConvolution: 0
|
||||
cubemapConvolutionSteps: 4
|
||||
cubemapConvolutionExponent: 1.5
|
||||
seamlessCubemap: 0
|
||||
textureFormat: -1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
filterMode: -1
|
||||
aniso: 0
|
||||
mipBias: -1
|
||||
wrapMode: 0
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
rGBM: 0
|
||||
compressionQuality: 50
|
||||
allowsAlphaSplitting: 0
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 100
|
||||
alphaIsTransparency: 1
|
||||
textureType: 5
|
||||
buildTargetSettings: []
|
||||
spriteSheet:
|
||||
sprites: []
|
||||
outline: []
|
||||
spritePackingTag:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
After Width: | Height: | Size: 242 KiB |
|
@ -0,0 +1,57 @@
|
|||
fileFormatVersion: 2
|
||||
guid: be862b17a8fa1544da2abdb50784ccf9
|
||||
timeCreated: 1447969667
|
||||
licenseType: Store
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
serializedVersion: 2
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
linearTexture: 0
|
||||
correctGamma: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 0
|
||||
cubemapConvolution: 0
|
||||
cubemapConvolutionSteps: 4
|
||||
cubemapConvolutionExponent: 1.5
|
||||
seamlessCubemap: 0
|
||||
textureFormat: -1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
filterMode: -1
|
||||
aniso: 0
|
||||
mipBias: -1
|
||||
wrapMode: 0
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
rGBM: 0
|
||||
compressionQuality: 50
|
||||
allowsAlphaSplitting: 0
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 100
|
||||
alphaIsTransparency: 1
|
||||
textureType: 5
|
||||
buildTargetSettings: []
|
||||
spriteSheet:
|
||||
sprites: []
|
||||
outline: []
|
||||
spritePackingTag:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Binary file not shown.
After Width: | Height: | Size: 166 KiB |
|
@ -0,0 +1,57 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 85b639891c9cfa54998a58964e8ef747
|
||||
timeCreated: 1447964200
|
||||
licenseType: Store
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
serializedVersion: 2
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
linearTexture: 0
|
||||
correctGamma: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 0
|
||||
cubemapConvolution: 0
|
||||
cubemapConvolutionSteps: 4
|
||||
cubemapConvolutionExponent: 1.5
|
||||
seamlessCubemap: 0
|
||||
textureFormat: -1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
filterMode: -1
|
||||
aniso: 0
|
||||
mipBias: -1
|
||||
wrapMode: 0
|
||||
nPOTScale: 1
|
||||
lightmap: 0
|
||||
rGBM: 0
|
||||
compressionQuality: 50
|
||||
allowsAlphaSplitting: 0
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 100
|
||||
alphaIsTransparency: 1
|
||||
textureType: 5
|
||||
buildTargetSettings: []
|
||||
spriteSheet:
|
||||
sprites: []
|
||||
outline: []
|
||||
spritePackingTag:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,184 @@
|
|||
/// Credit SimonDarksideJ
|
||||
/// Sourced from my head
|
||||
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
public class CooldownButton : MonoBehaviour, IPointerDownHandler
|
||||
{
|
||||
#region Sub-Classes
|
||||
[System.Serializable]
|
||||
public class CooldownButtonEvent : UnityEvent<PointerEventData.InputButton> { }
|
||||
#endregion
|
||||
|
||||
#region Private variables
|
||||
|
||||
[SerializeField]
|
||||
private float cooldownTimeout;
|
||||
[SerializeField]
|
||||
private float cooldownSpeed = 1;
|
||||
[SerializeField][ReadOnly]
|
||||
private bool cooldownActive;
|
||||
[SerializeField][ReadOnly]
|
||||
private bool cooldownInEffect;
|
||||
[SerializeField][ReadOnly]
|
||||
private float cooldownTimeElapsed;
|
||||
[SerializeField][ReadOnly]
|
||||
private float cooldownTimeRemaining;
|
||||
[SerializeField][ReadOnly]
|
||||
private int cooldownPercentRemaining;
|
||||
[SerializeField][ReadOnly]
|
||||
private int cooldownPercentComplete;
|
||||
|
||||
PointerEventData buttonSource;
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public float CooldownTimeout
|
||||
{
|
||||
get { return cooldownTimeout; }
|
||||
set { cooldownTimeout = value; }
|
||||
}
|
||||
|
||||
public float CooldownSpeed
|
||||
{
|
||||
get { return cooldownSpeed; }
|
||||
set { cooldownSpeed = value; }
|
||||
}
|
||||
|
||||
public bool CooldownInEffect
|
||||
{
|
||||
get { return cooldownInEffect; }
|
||||
}
|
||||
|
||||
public bool CooldownActive
|
||||
{
|
||||
get { return cooldownActive; }
|
||||
set { cooldownActive = value; }
|
||||
}
|
||||
|
||||
public float CooldownTimeElapsed
|
||||
{
|
||||
get { return cooldownTimeElapsed; }
|
||||
set { cooldownTimeElapsed = value; }
|
||||
}
|
||||
|
||||
public float CooldownTimeRemaining
|
||||
{
|
||||
get { return cooldownTimeRemaining; }
|
||||
}
|
||||
|
||||
public int CooldownPercentRemaining
|
||||
{
|
||||
get { return cooldownPercentRemaining; }
|
||||
}
|
||||
|
||||
public int CooldownPercentComplete
|
||||
{
|
||||
get { return cooldownPercentComplete; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
[Tooltip("Event that fires when a button is initially pressed down")]
|
||||
public CooldownButtonEvent OnCooldownStart;
|
||||
[Tooltip("Event that fires when a button is released")]
|
||||
public CooldownButtonEvent OnButtonClickDuringCooldown;
|
||||
[Tooltip("Event that continually fires while a button is held down")]
|
||||
public CooldownButtonEvent OnCoolDownFinish;
|
||||
#endregion
|
||||
|
||||
#region Update
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (CooldownActive)
|
||||
{
|
||||
cooldownTimeRemaining -= Time.deltaTime * cooldownSpeed;
|
||||
cooldownTimeElapsed = CooldownTimeout - CooldownTimeRemaining;
|
||||
if (cooldownTimeRemaining < 0)
|
||||
{
|
||||
StopCooldown();
|
||||
}
|
||||
else
|
||||
{
|
||||
cooldownPercentRemaining = (int)(100 * cooldownTimeRemaining * CooldownTimeout / 100);
|
||||
cooldownPercentComplete = (int)((CooldownTimeout - cooldownTimeRemaining) / CooldownTimeout * 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Pause Cooldown without resetting values, allows Restarting of cooldown
|
||||
/// </summary>
|
||||
public void PauseCooldown()
|
||||
{
|
||||
if (CooldownInEffect)
|
||||
{
|
||||
CooldownActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restart a paused cooldown
|
||||
/// </summary>
|
||||
public void RestartCooldown()
|
||||
{
|
||||
if (CooldownInEffect)
|
||||
{
|
||||
CooldownActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop a running Cooldown and reset all values
|
||||
/// </summary>
|
||||
public void StopCooldown()
|
||||
{
|
||||
cooldownTimeElapsed = CooldownTimeout;
|
||||
cooldownTimeRemaining = 0;
|
||||
cooldownPercentRemaining = 0;
|
||||
cooldownPercentComplete = 100;
|
||||
cooldownActive = cooldownInEffect = false;
|
||||
if (OnCoolDownFinish != null) OnCoolDownFinish.Invoke(buttonSource.button);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop a running Cooldown and retain current values
|
||||
/// </summary>
|
||||
public void CancelCooldown()
|
||||
{
|
||||
cooldownActive = cooldownInEffect = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IPointerDownHandler
|
||||
|
||||
void IPointerDownHandler.OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
buttonSource = eventData;
|
||||
if (CooldownInEffect)
|
||||
{
|
||||
if (OnButtonClickDuringCooldown != null) OnButtonClickDuringCooldown.Invoke(eventData.button);
|
||||
}
|
||||
if (!CooldownInEffect)
|
||||
{
|
||||
if(OnCooldownStart != null) OnCooldownStart.Invoke(eventData.button);
|
||||
cooldownTimeRemaining = cooldownTimeout;
|
||||
cooldownActive = cooldownInEffect = true;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 74a62d95b3be0fe47871dd48fca58b7d
|
||||
timeCreated: 1498387990
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
/// Credit tanoshimi
|
||||
/// Sourced from - https://forum.unity3d.com/threads/read-only-fields.68976/
|
||||
|
||||
using UnityEngine;
|
||||
namespace UnityEngine.UI.Extensions
|
||||
{
|
||||
public class ReadOnlyAttribute : PropertyAttribute { }
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 244394c76ae0d484d83567b74f4332cd
|
||||
timeCreated: 1498392707
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue