123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Events;
- using UnityEngine.EventSystems;
- using DG.Tweening;
- public class Game3DButton : SCButton
- {
- [SerializeField]
- private Ease mTweenType = Ease.OutCubic;
-
-
- [SerializeField]
- private float wScale = 1.03f;
- [SerializeField]
- private float hScale = 1.05f;
- private AudioSource _audioSource;
- private Quaternion initRotation;
- private float transitionTime = 0.1f;
- private float forwardNum = 0.008f;
- [SerializeField]
- private Renderer mRenderer;
- private Color DefaultColor;
- private Color ClickColor;
- private Color FocusColor;
-
- public void Awake()
- {
- initPosition = transform.localPosition;
- initRotation = transform.localRotation;
- initScale = transform.localScale;
-
- }
- public override void Start()
- {
- _audioSource = (AudioSource)gameObject.GetComponent<AudioSource>();
- if (_audioSource != null)
- {
- _audioSource.playOnAwake = false;
- _audioSource.loop = false;
- }
- }
- private void OnEnable()
- {
-
- transform.localPosition = initPosition;
- transform.localRotation = initRotation;
-
- }
- protected virtual void ChangeColor(Color co)
- {
- if (mRenderer != null)
- {
-
- }
- }
- protected virtual void ChangeMetallic(float value)
- {
- if (mRenderer != null)
- {
-
- }
- }
- protected virtual void init()
- {
- if (mRenderer != null)
- {
-
- }
-
- }
- public override void OnPointerDown(PointerEventData data)
- {
- Debug.Log(GetType().Name + "OnPointerDown");
-
- }
- public override void OnPointerUp(PointerEventData data)
- {
- Debug.Log(GetType().Name + "OnPointerUp");
- }
- public override void OnPointerEnter(PointerEventData data)
- {
- OnEnterAnimation();
- ChangeMetallic(0.65f);
- }
- public override void OnPointerExit(PointerEventData data)
- {
- OnExitAnimation();
- ChangeMetallic(0);
- }
- public override void OnPointerClick(PointerEventData data)
- {
- Debug.Log(GetType().Name + "OnPointerClick");
- OnClickAnimation();
- }
- private void ClickFun()
- {
- ChangeColor(DefaultColor);
- if (onClick != null)
- {
- onClick.Invoke();
- }
- }
- public override void OnClickAnimation()
- {
- transform.DOLocalMove(initPosition + new Vector3(0, 0, forwardNum * 1), transitionTime).SetEase(Ease.InOutExpo).OnComplete(ClickFinish).SetAutoKill(true);
-
- }
- public override void ClickFinish()
- {
-
- transform.DOLocalMove(initPosition + new Vector3(0, 0, forwardNum * -1), transitionTime).SetEase(Ease.InOutExpo).OnComplete(ClickFun).SetAutoKill(true);
- }
- public override void OnEnterAnimation()
- {
- transform.DOScale(new Vector3(initScale.x * wScale,initScale.y * hScale, initScale.z), duration).SetEase(mTweenType);
- }
- public override void OnExitAnimation()
- {
- transform.DOScale(initScale, duration).SetEase(mTweenType);
- }
- }
|