按钮动画
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.UI;
|
||||
|
||||
public class Login : MonoBehaviour
|
||||
public class Login : Anim
|
||||
{
|
||||
public Button btnRegister;
|
||||
public Button btnSure;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
btnRegister.onClick.AddListener(OnClickRegister);
|
||||
btnSure.onClick.AddListener(OnClickSure);
|
||||
btnRegister.onClick.AddListener(() =>
|
||||
{
|
||||
BTnmove(btnRegister.gameObject);
|
||||
Invoke("OnClickRegister",0.5f);
|
||||
});
|
||||
btnSure.onClick.AddListener ( ()=>
|
||||
{
|
||||
BTnmove(btnSure.gameObject);
|
||||
Invoke("OnClickSure", 0.5f);
|
||||
});
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
@ -3,15 +3,71 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class MainPanel : MonoBehaviour
|
||||
public class MainPanel : Anim
|
||||
{
|
||||
private bool isOpenBulindingHpuse;
|
||||
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
|
||||
void Start()
|
||||
{
|
||||
btnBulidingHouse.onClick.AddListener(OnClickBulidingHouse);
|
||||
isOpenBulindingHpuse=true;
|
||||
btnBulidingHouse.onClick.AddListener((() =>
|
||||
{
|
||||
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
|
||||
|
@ -4,18 +4,26 @@ using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Protocol : MonoBehaviour
|
||||
public class Protocol : Anim
|
||||
{
|
||||
public Image imgUserPocol;
|
||||
public Button btnUserProtorotcol;
|
||||
public Button YonghuxieyiButton;
|
||||
public Button btnEmail;
|
||||
private bool isUserBool;
|
||||
|
||||
public Toggle YonghuToggle;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
UIManager.Instance.CloseUI("Load");
|
||||
btnUserProtorotcol.onClick.AddListener(OnUserProtocolk);
|
||||
btnEmail.onClick.AddListener(OnEmail);
|
||||
YonghuxieyiButton.onClick.AddListener(() =>
|
||||
{
|
||||
BTnmove(YonghuxieyiButton.gameObject);
|
||||
OnUserProtocolk();
|
||||
});
|
||||
btnEmail.onClick.AddListener(() =>
|
||||
{
|
||||
BTnmove(btnEmail.gameObject);
|
||||
Invoke("OnEmail",0.5f);
|
||||
});
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@ -25,19 +33,16 @@ public class Protocol : MonoBehaviour
|
||||
}
|
||||
void OnUserProtocolk()
|
||||
{
|
||||
// ÔÚÕâÀïÌí¼ÓÄãµÄÂß¼
|
||||
Sprite go=UIManager.Instance.ResSprit("Protocol_UI/x");
|
||||
imgUserPocol.sprite = go;
|
||||
isUserBool = true;
|
||||
YonghuToggle.isOn = true;
|
||||
}
|
||||
|
||||
|
||||
void OnEmail()
|
||||
{
|
||||
if (!isUserBool) {
|
||||
return;
|
||||
if (YonghuToggle.isOn) {
|
||||
UIManager.Instance.CloseUI("Protocol");
|
||||
UIManager.Instance.OPenUI("Login");
|
||||
}
|
||||
UIManager.Instance.CloseUI("Protocol");
|
||||
UIManager.Instance.OPenUI("Login");
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -3,15 +3,23 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Register : MonoBehaviour
|
||||
public class Register : Anim
|
||||
{
|
||||
public Button btnExit;
|
||||
public Button btnSure;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
btnExit.onClick.AddListener(OnClickExit);
|
||||
btnSure.onClick.AddListener(OnClickSure);
|
||||
btnExit.onClick.AddListener(() =>
|
||||
{
|
||||
BTnmove(btnExit.gameObject);
|
||||
Invoke("OnClickExit",0.5f);
|
||||
});
|
||||
btnSure.onClick.AddListener(() =>
|
||||
{
|
||||
BTnmove(btnSure.gameObject);
|
||||
Invoke("OnClickSure", 0.5f);
|
||||
});
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
@ -1,7 +1,7 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Role : MonoBehaviour
|
||||
public class Role : Anim
|
||||
{
|
||||
public Image imgMale;
|
||||
public Image imgFamale;
|
||||
@ -12,10 +12,26 @@ public class Role : MonoBehaviour
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
btnMale.onClick.AddListener(OnClickMale);
|
||||
btnFemale.onClick.AddListener(OnClickFemale);
|
||||
btnSure.onClick.AddListener(OnClickSure);
|
||||
btnReturn.onClick.AddListener(OnClickReturn);
|
||||
btnMale.onClick.AddListener(() =>
|
||||
{
|
||||
BTnmove(btnMale.gameObject);
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user