按钮动画
This commit is contained in:
parent
333f2a41d9
commit
18c29931b2
File diff suppressed because it is too large
Load Diff
81
Assets/Scripts/Anim.cs
Normal file
81
Assets/Scripts/Anim.cs
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
using DG.Tweening;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class Anim : MonoBehaviour
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 按钮放大倍数
|
||||||
|
/// </summary>
|
||||||
|
private float scaleMultiplier = 1.2f;
|
||||||
|
/// <summary>
|
||||||
|
/// 按钮放大缩小的时间
|
||||||
|
/// </summary>
|
||||||
|
private float scaleUpDuration = 0.2f;
|
||||||
|
private float scaleDownDuration = 0.2f;
|
||||||
|
/// <summary>
|
||||||
|
/// 按钮本身的缩放倍数
|
||||||
|
/// </summary>
|
||||||
|
private Vector3 originalScale;
|
||||||
|
/// <summary>
|
||||||
|
/// 按钮动画响应时间
|
||||||
|
/// </summary>
|
||||||
|
public int BTntimer = 500;
|
||||||
|
// Start is called before the first frame update
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 按钮
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ob"></param>
|
||||||
|
public void BTnmove(GameObject ob)
|
||||||
|
{
|
||||||
|
originalScale = transform.localScale;
|
||||||
|
|
||||||
|
ob.transform.DOScale(ob.transform.localScale * scaleMultiplier, scaleUpDuration)
|
||||||
|
.OnComplete(() =>
|
||||||
|
{
|
||||||
|
ob.transform.DOScale(originalScale, scaleDownDuration);
|
||||||
|
});
|
||||||
|
Task.Delay(BTntimer);
|
||||||
|
}
|
||||||
|
public void ShowPanel(GameObject panel)
|
||||||
|
{
|
||||||
|
if (panel == null)
|
||||||
|
{
|
||||||
|
Debug.Log("panel==null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
panel.SetActive(true);
|
||||||
|
panel.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
|
||||||
|
panel.transform.DOScale(1f, 0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HidePanel(GameObject panel, bool isdes)
|
||||||
|
{
|
||||||
|
panel.transform.DOScale(0.5f, 0.5f);
|
||||||
|
if (isdes)
|
||||||
|
{
|
||||||
|
Destroy(panel);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
panel.SetActive(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void MoveToOriginBy(GameObject target)
|
||||||
|
{
|
||||||
|
Vector3 currentPosition = target.transform.position;
|
||||||
|
target.transform.DOMove(new Vector3(540, 960, 0), 0.5f); // 使用 DOMove 直接移动到原点
|
||||||
|
}
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/Anim.cs.meta
Normal file
11
Assets/Scripts/Anim.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 121eb3bf7e6cab74ca5d8a01b8824b16
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -2,15 +2,23 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
public class Login : MonoBehaviour
|
public class Login : Anim
|
||||||
{
|
{
|
||||||
public Button btnRegister;
|
public Button btnRegister;
|
||||||
public Button btnSure;
|
public Button btnSure;
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
btnRegister.onClick.AddListener(OnClickRegister);
|
btnRegister.onClick.AddListener(() =>
|
||||||
btnSure.onClick.AddListener(OnClickSure);
|
{
|
||||||
|
BTnmove(btnRegister.gameObject);
|
||||||
|
Invoke("OnClickRegister",0.5f);
|
||||||
|
});
|
||||||
|
btnSure.onClick.AddListener ( ()=>
|
||||||
|
{
|
||||||
|
BTnmove(btnSure.gameObject);
|
||||||
|
Invoke("OnClickSure", 0.5f);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
|
@ -3,15 +3,71 @@ using System.Collections.Generic;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
public class MainPanel : MonoBehaviour
|
public class MainPanel : Anim
|
||||||
{
|
{
|
||||||
private bool isOpenBulindingHpuse;
|
private bool isOpenBulindingHpuse;
|
||||||
public Button btnBulidingHouse;
|
public Button btnBulidingHouse;
|
||||||
|
public Button btnstoreroom;
|
||||||
|
public Button btnEchange;
|
||||||
|
public Button btnmail;
|
||||||
|
|
||||||
|
public Button world;
|
||||||
|
public Button Ally;
|
||||||
|
public Button team;
|
||||||
|
public Button Private;
|
||||||
|
public Button FriendButton;
|
||||||
|
public Button SettingButton;
|
||||||
|
|
||||||
|
public Button SendButton;
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
btnBulidingHouse.onClick.AddListener(OnClickBulidingHouse);
|
btnBulidingHouse.onClick.AddListener((() =>
|
||||||
isOpenBulindingHpuse=true;
|
{
|
||||||
|
BTnmove(btnBulidingHouse.gameObject);
|
||||||
|
Invoke("OnClickBulidingHouse",0.5f);
|
||||||
|
}));
|
||||||
|
btnstoreroom.onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
BTnmove(btnstoreroom.gameObject);
|
||||||
|
});
|
||||||
|
btnEchange.onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
BTnmove(btnEchange.gameObject);
|
||||||
|
});
|
||||||
|
btnmail.onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
BTnmove(btnmail.gameObject);
|
||||||
|
});
|
||||||
|
world.onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
BTnmove(world.gameObject);
|
||||||
|
});
|
||||||
|
Ally.onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
BTnmove(Ally.gameObject);
|
||||||
|
});
|
||||||
|
team.onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
BTnmove(team.gameObject);
|
||||||
|
});
|
||||||
|
Private.onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
BTnmove(Private.gameObject);
|
||||||
|
});
|
||||||
|
FriendButton.onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
BTnmove(FriendButton.gameObject);
|
||||||
|
});
|
||||||
|
SettingButton.onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
BTnmove(SettingButton.gameObject);
|
||||||
|
});
|
||||||
|
SendButton.onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
BTnmove(SendButton.gameObject);
|
||||||
|
});
|
||||||
|
isOpenBulindingHpuse =true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
|
@ -4,18 +4,26 @@ using Unity.VisualScripting;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
public class Protocol : MonoBehaviour
|
public class Protocol : Anim
|
||||||
{
|
{
|
||||||
public Image imgUserPocol;
|
public Button YonghuxieyiButton;
|
||||||
public Button btnUserProtorotcol;
|
|
||||||
public Button btnEmail;
|
public Button btnEmail;
|
||||||
private bool isUserBool;
|
|
||||||
|
public Toggle YonghuToggle;
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
UIManager.Instance.CloseUI("Load");
|
UIManager.Instance.CloseUI("Load");
|
||||||
btnUserProtorotcol.onClick.AddListener(OnUserProtocolk);
|
YonghuxieyiButton.onClick.AddListener(() =>
|
||||||
btnEmail.onClick.AddListener(OnEmail);
|
{
|
||||||
|
BTnmove(YonghuxieyiButton.gameObject);
|
||||||
|
OnUserProtocolk();
|
||||||
|
});
|
||||||
|
btnEmail.onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
BTnmove(btnEmail.gameObject);
|
||||||
|
Invoke("OnEmail",0.5f);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
@ -25,19 +33,16 @@ public class Protocol : MonoBehaviour
|
|||||||
}
|
}
|
||||||
void OnUserProtocolk()
|
void OnUserProtocolk()
|
||||||
{
|
{
|
||||||
// 在这里添加你的逻辑
|
YonghuToggle.isOn = true;
|
||||||
Sprite go=UIManager.Instance.ResSprit("Protocol_UI/x");
|
|
||||||
imgUserPocol.sprite = go;
|
|
||||||
isUserBool = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OnEmail()
|
void OnEmail()
|
||||||
{
|
{
|
||||||
if (!isUserBool) {
|
if (YonghuToggle.isOn) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
UIManager.Instance.CloseUI("Protocol");
|
UIManager.Instance.CloseUI("Protocol");
|
||||||
UIManager.Instance.OPenUI("Login");
|
UIManager.Instance.OPenUI("Login");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,23 @@ using System.Collections.Generic;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
public class Register : MonoBehaviour
|
public class Register : Anim
|
||||||
{
|
{
|
||||||
public Button btnExit;
|
public Button btnExit;
|
||||||
public Button btnSure;
|
public Button btnSure;
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
btnExit.onClick.AddListener(OnClickExit);
|
btnExit.onClick.AddListener(() =>
|
||||||
btnSure.onClick.AddListener(OnClickSure);
|
{
|
||||||
|
BTnmove(btnExit.gameObject);
|
||||||
|
Invoke("OnClickExit",0.5f);
|
||||||
|
});
|
||||||
|
btnSure.onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
BTnmove(btnSure.gameObject);
|
||||||
|
Invoke("OnClickSure", 0.5f);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
public class Role : MonoBehaviour
|
public class Role : Anim
|
||||||
{
|
{
|
||||||
public Image imgMale;
|
public Image imgMale;
|
||||||
public Image imgFamale;
|
public Image imgFamale;
|
||||||
@ -12,10 +12,26 @@ public class Role : MonoBehaviour
|
|||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
btnMale.onClick.AddListener(OnClickMale);
|
btnMale.onClick.AddListener(() =>
|
||||||
btnFemale.onClick.AddListener(OnClickFemale);
|
{
|
||||||
btnSure.onClick.AddListener(OnClickSure);
|
BTnmove(btnMale.gameObject);
|
||||||
btnReturn.onClick.AddListener(OnClickReturn);
|
OnClickMale();
|
||||||
|
});
|
||||||
|
btnFemale.onClick.AddListener((() =>
|
||||||
|
{
|
||||||
|
BTnmove(btnFemale.gameObject);
|
||||||
|
OnClickFemale();
|
||||||
|
}));
|
||||||
|
btnSure.onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
BTnmove(btnFemale.gameObject);
|
||||||
|
Invoke("OnClickSure",0.5f);
|
||||||
|
});
|
||||||
|
btnReturn.onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
BTnmove(btnReturn.gameObject);
|
||||||
|
Invoke("OnClickReturn", 0.5f);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
|
Loading…
Reference in New Issue
Block a user