using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using frame8.Logic.Misc.Other.Extensions;
using UnityEngine.Events;
using UnityEngine.Serialization;
namespace Com.ForbiddenByte.OSA.Util
{
///
/// Utility to expand an item when it's clicked, dispatching the size change request via for increased flexibility
/// Known issue when used with OSA: when during collapsing the item goes outside viewport, the animation stales, since the views are recycled.
/// This can be solved by having a separate resizing utility script that's not attached to a recycling-prone object.
///
[Obsolete("This script will soon be deprecated. Please use the ExpandCollapseAnimationState class instead, which handles several edge cases better.")]
public class ExpandCollapseOnClick : MonoBehaviour
{
///
/// The button to whose onClock to subscribe. If not specified, will try to GetComponent<Button> from the GO containing this script
///
[Tooltip("will be taken from this object, if not specified")]
public Button button = null;
/// When expanding, the initial size will be and the target size will be x ; opposite is true when collapsing
[NonSerialized] // must be set through code
public float expandFactor = 2f;
/// The duration of the expand(or collapse) animation
public float animDuration = .2f;
public NonExpandedSizeSource nonExpandedSizeSource = NonExpandedSizeSource.WAIT_FOR_EXTERNAL;
[Tooltip("Used in conjunction with NonExpandedSizeSource.PREDEFINED")]
public float nonExpandedSizePredefined = 0f;
public bool useUnscaledTime = true;
/// This is the size from which the item will start expanding
[HideInInspector]
public float nonExpandedSize = -1f;
/// This keeps track of the 'expanded' state. If true, on click the animation will set as the target size; else, x
[HideInInspector]
public bool expanded = false;
[Tooltip("Returns a value between 0 and 1, 1 meaning end of the progress")]
[FormerlySerializedAs("onExpandAmounChanged")] // correcting typo from pre-4.0 versions
public UnityFloatEvent onExpandAmountChanged = null;
[Tooltip("Returns a value between nonExpandedSize and nonExpandedSize * expandFactor")]
public UnityFloatEvent onExpandSizeChanged = null;
[Obsolete("Use onExpandAmountChanged, instead", true)]
[HideInInspector] // just to be sure unity's serialization system won't behave buggy
public UnityFloatEvent onExpandAmounChanged { get { return onExpandAmountChanged; } }
float Time { get { return useUnscaledTime ? UnityEngine.Time.unscaledTime : UnityEngine.Time.time; } }
float startSize;
float endSize;
float animStart;
//float animEnd;
bool animating = false;
RectTransform rectTransform;
public ISizeChangesHandler sizeChangesHandler;
public enum NonExpandedSizeSource
{
WAIT_FOR_EXTERNAL,
SELF_HEIGHT,
SELF_WIDTH,
PREDEFINED
}
void Awake()
{
rectTransform = transform as RectTransform;
if (button == null)
button = GetComponent