DoTween

作者: 萧非子 | 来源:发表于2017-08-14 17:51 被阅读43次

/*

  • 项目:
  • 脚本:校园导航管理脚本
  • 脚本:此脚本挂载在SchoolMenuPanel上
  • 脚本:点击二级导航按钮,播放按钮动画(缩放),然后跳转相应面板
  • 企业:
  • 版本:1.0
  • 作者:非子萧
  • 时间:201708
    */
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    using DG.Tweening;

public class SchoolMenuPanel : MonoBehaviour
{
public static SchoolMenuPanel _instance;//单例

private Button cefiroButton;//校园风采按钮
private Button studysectionButton;//学习园地按钮
private Button entertainmentButton;//休闲娱乐按钮
private Button testmodeButton;//考场模式按钮

private Image cefiroImage;//校园风采图标
private Image studysectionImage;//学习园地图标
private Image entertainmentImage;//休闲娱乐图标
private Image testmodeImage;//考场模式图标



private Tween cefiroButtonTweenPosition;
private Tween studysectionButtonTweenPosition;
private Tween entertainmentButtonTweenPosition;
private Tween testmodeButtonTweenPosition;
private Tween cefiroButtonTweenScale;
private Tween studysectionButtonTweenScale;
private Tween entertainmentButtonTweenScale;
private Tween testmodeButtonTweenScale;
void Awake()
{
    _instance = this;

    cefiroButton = transform.Find("CefiroButton").GetComponent<Button>();
    studysectionButton = transform.Find("StudysectionButton").GetComponent<Button>();
    entertainmentButton = transform.Find("EntertainmentButton").GetComponent<Button>();
    testmodeButton = transform.Find("TestmodeButton").GetComponent<Button>();

    cefiroImage = transform.Find("CefiroButton/Image").GetComponent<Image>();
    studysectionImage = transform.Find("StudysectionButton/Image").GetComponent<Image>();
    entertainmentImage = transform.Find("EntertainmentButton/Image").GetComponent<Image>();
    testmodeImage = transform.Find("TestmodeButton/Image").GetComponent<Image>();


    cefiroButtonTweenPosition = cefiroButton.transform.DOLocalMove(new Vector2(-281, 52), 0.5f).SetAutoKill(false).Pause().OnComplete(OncefiroImageShakePosition);
    studysectionButtonTweenPosition = studysectionButton.transform.DOLocalMove(new Vector2(-124, 120), 0.5f).SetAutoKill(false).Pause().OnComplete(OnstudysectionImageShakePosition);
    entertainmentButtonTweenPosition = entertainmentButton.transform.DOLocalMove(new Vector2(42, 70), 0.5f).SetAutoKill(false).Pause().OnComplete(OnentertainmentImageShakePosition);
    testmodeButtonTweenPosition = testmodeButton.transform.DOLocalMove(new Vector2(200, 110), 0.5f).SetAutoKill(false).Pause().OnComplete(OntestmodeImageShakePosition);
    cefiroButton.transform.localScale = Vector3.zero;
    cefiroButtonTweenScale = cefiroButton.transform.DOScale(1,0.5f).SetAutoKill(false).Pause();
    studysectionButton.transform.localScale = Vector3.zero;
    studysectionButtonTweenScale = studysectionButton.transform.DOScale(1,0.5f).SetAutoKill(false).Pause();
    entertainmentButton.transform.localScale = Vector3.zero;
    entertainmentButtonTweenScale = entertainmentButton.transform.DOScale(1,0.5f).SetAutoKill(false).Pause();
    testmodeButton.transform.localScale = Vector3.zero;
    testmodeButtonTweenScale = testmodeButton.transform.DOScale(1,0.5f).SetAutoKill(false).Pause();


    cefiroButton.onClick.AddListener(OnCefiroButtonClick);
    studysectionButton.onClick.AddListener(OnStudysectionButtonClick);
    entertainmentButton.onClick.AddListener(OnEntertainmentButtonClick);
    testmodeButton.onClick.AddListener(OnTestmodeButtonClick);

}
void Start () {
}
void Update () {
    
}
/// <summary>
/// 面板显示
/// </summary>
public void PanelShow()
{
    cefiroButtonTweenPosition.Restart();
    studysectionButtonTweenPosition.Restart();
    entertainmentButtonTweenPosition.Restart();
    testmodeButtonTweenPosition.Restart();

    cefiroButtonTweenScale.Restart();
    studysectionButtonTweenScale.Restart();
    entertainmentButtonTweenScale.Restart();
    testmodeButtonTweenScale.Restart();
}
/// <summary>
/// 面板隐藏
/// </summary>
public void PanelHide()
{
    //cefiroButton.transform.DOLocalMove(new Vector2(-90, -156), 0.5f);
    //studysectionButton.transform.DOLocalMove(new Vector2(-90, -156), 0.5f);
    //entertainmentButton.transform.DOLocalMove(new Vector2(-90, -156), 0.5f);
    //testmodeButton.transform.DOLocalMove(new Vector2(-90, -156), 0.5f);
    //print("隐藏了吗/");
    cefiroButtonTweenPosition.PlayBackwards();
    studysectionButtonTweenPosition.PlayBackwards();
    entertainmentButtonTweenPosition.PlayBackwards();
    testmodeButtonTweenPosition.PlayBackwards();

    cefiroButtonTweenScale.PlayBackwards();
    studysectionButtonTweenScale.PlayBackwards();
    entertainmentButtonTweenScale.PlayBackwards();
    testmodeButtonTweenScale.PlayBackwards();


}

region//按钮点击

/// <summary>
/// 校园风采按钮点击
/// </summary>
public void OnCefiroButtonClick()
{
    cefiroButton.transform.DOScale(1.5f,0.5f);//1.2倍大,0.5s时间
}
/// <summary>
/// 学习园地按钮点击
/// </summary>
public void OnStudysectionButtonClick()
{
    studysectionButton.transform.DOScale(1.5f, 0.5f);
}
/// <summary>
/// 休闲娱乐按钮点击
/// </summary>
public void OnEntertainmentButtonClick()
{
    entertainmentButton.transform.DOScale(1.5f, 0.5f);
}
/// <summary>
/// 考场模式
/// </summary>
public void OnTestmodeButtonClick()
{
    testmodeButton.transform.DOScale(1.5f, 0.5f);
}
#endregion
#region//图标晃动
/// <summary>
/// 校园风采图标晃动
/// </summary>
public void OncefiroImageShakePosition()
{
    cefiroImage.transform.DOShakeScale(0.6f, 0.5f);
}
/// <summary>
/// 学习园地图标晃动
/// </summary>
public void OnstudysectionImageShakePosition()
{
    studysectionImage.transform.DOShakeScale(0.5f, 0.5f);
}
/// <summary>
///  休闲娱乐图标晃动
/// </summary>
public void OnentertainmentImageShakePosition()
{
    entertainmentImage.transform.DOShakeRotation(0.4f, 50);
}
/// <summary>
/// 考场模式图标晃动
/// </summary>
public void OntestmodeImageShakePosition()
{
    testmodeImage.transform.DOShakeRotation(0.3f, 60);
}
#endregion

}

相关文章

网友评论

      本文标题:DoTween

      本文链接:https://www.haomeiwen.com/subject/ipzurxtx.html