Cute_demon_attacks/meng_yao/Assets/script/A_Fight/CharacterClick.cs

168 lines
5.6 KiB
C#
Raw Normal View History

2024-12-10 06:57:53 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2024-12-19 11:48:31 +08:00
using DG.Tweening;
2024-12-28 10:44:14 +08:00
using UnityEngine.EventSystems;
2024-12-30 17:50:50 +08:00
using System.Threading.Tasks;
2024-12-10 06:57:53 +08:00
public class CharacterClick : MonoBehaviour
{
2024-12-10 07:32:01 +08:00
public Role role;
2024-12-28 14:30:57 +08:00
public Character MyCharacter = null;
2024-12-10 07:32:01 +08:00
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD>")] public GameObject panelPrefab;
2024-12-19 11:48:31 +08:00
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵĹ<D6B5><C4B9><EFBFBD><EFBFBD><EFBFBD>Χ")] public GameObject attackRange;
2024-12-19 19:02:10 +08:00
[Header("<22>Ƿ<EFBFBD><C7B7>Ѿ<EFBFBD><D1BE><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>")] public bool isShowPanel = false;
[Header("<22><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>")] public GameObject instantiatedPanel;
2024-12-28 14:30:57 +08:00
public Vector3 OrigScale;
2024-12-28 15:46:21 +08:00
public float StartSizeX;
2024-12-28 16:23:07 +08:00
public float StartSizeY;
2024-12-28 14:30:57 +08:00
public float OrSizeX;
2024-12-28 16:23:07 +08:00
public float OrSizeY;
2024-12-19 11:48:31 +08:00
private bool isShowAttackRange=true;
2024-12-13 22:29:17 +08:00
public WaveData MyWaveData=null;
void Start()
{
2024-12-20 17:40:13 +08:00
if (attackRange!=null)
{
OrigScale = attackRange.transform.localScale;
2024-12-28 14:30:57 +08:00
OrSizeX = attackRange.GetComponent<SpriteRenderer>().bounds.size.x;
2024-12-28 16:23:07 +08:00
OrSizeY = attackRange.GetComponent<SpriteRenderer>().bounds.size.y;
2024-12-28 15:46:21 +08:00
StartSizeX = OrSizeX;
2024-12-28 16:23:07 +08:00
StartSizeY = OrSizeY;
2024-12-28 14:30:57 +08:00
role.attackClass.SetAttackRange();
2024-12-28 16:23:07 +08:00
attackRange.transform.DOScale(new Vector2(OrSizeX, OrSizeY), 0.3f).SetEase(Ease.InOutBack);
2024-12-28 15:46:21 +08:00
//attackRange.transform.localScale=new Vector3(OrSizeX, OrSizeX,1);
//ShowAttackRange(UIContorl.instance.NowAttackRange);
2024-12-20 17:40:13 +08:00
}
2024-12-20 16:29:02 +08:00
if (transform.GetComponent<enemy>()!=null)
{
IdForInfo(transform.GetComponent<enemy>().enemyId);
}
2024-12-19 11:48:31 +08:00
}
2024-12-10 06:57:53 +08:00
private void OnMouseDown()
{
2024-12-28 10:44:14 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UIԪ<49><D4AA><EFBFBD><EFBFBD>
if (EventSystem.current.IsPointerOverGameObject())
{
return; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UI<55><49>ֱ<EFBFBD>ӷ<EFBFBD><D3B7>أ<EFBFBD><D8A3><EFBFBD><EFBFBD>⴩͸<E2B4A9><CDB8>2D<32><44><EFBFBD><EFBFBD>
}
// ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD> Trigger <20><><EFBFBD><EFBFBD>
Collider2D parentCollider = GetComponent<Collider2D>();
if (parentCollider != null && parentCollider.isTrigger)
{
2024-12-12 17:05:28 +08:00
// parentCollider.enabled = true;
// <20><><EFBFBD>߼<EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǹ<EFBFBD><C7B8>ڵ<EFBFBD>
Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
RaycastHit2D hit = Physics2D.Raycast(mousePosition, Vector2.zero);
if (hit.collider != null && hit.collider.gameObject == gameObject)
{
2024-12-19 19:02:10 +08:00
//ShowAttackRange();
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD>˸<EFBFBD><CBB8>ڵ<EFBFBD>");
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFB4A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
2024-12-19 19:02:10 +08:00
ShowInfoPanel();
2024-12-13 22:29:17 +08:00
}
}
}
2024-12-19 19:02:10 +08:00
public void ShowInfoPanel()
{
if (instantiatedPanel == null)
{
2024-12-20 10:42:20 +08:00
if (UIContorl.instance.NowShowInfo!=null)
{
Destroy(UIContorl.instance.NowShowInfo._closePanel);
HideAttackRange(UIContorl.instance.NowAttackRange);
}
2024-12-19 19:02:10 +08:00
instantiatedPanel = GameObject.Instantiate(panelPrefab, GameObject.Find("Canvas").transform);
2024-12-20 10:42:20 +08:00
UIContorl.instance.NowShowInfo = instantiatedPanel.GetComponent<charainfoPanel>();
UIContorl.instance.NowAttackRange = attackRange;
2024-12-30 17:50:50 +08:00
2024-12-20 10:42:20 +08:00
ShowAttackRange(UIContorl.instance.NowAttackRange);
2024-12-30 17:50:50 +08:00
2024-12-20 10:42:20 +08:00
instantiatedPanel.GetComponent<charainfoPanel>().closeBtn.onClick.AddListener(() => {
2025-01-02 18:05:20 +08:00
HideInfoPanel();
2025-01-03 11:59:22 +08:00
HideAttackRange(UIContorl.instance.NowAttackRange);
2024-12-20 10:42:20 +08:00
});
2024-12-19 19:02:10 +08:00
RectTransform panelRect = instantiatedPanel.GetComponent<RectTransform>();
// ȷ<><C8B7><EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD><C9B5><EFBFBD><EFBFBD><EFBFBD>ס<E1B5B2><D7A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
panelRect.SetAsLastSibling(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵ<EFBFBD> Canvas <20><EFBFBD><E3BCB6><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD>
if (role.camp == Camp.Enemy)
{
//string eveText,string name,string def,string speed,string shanghai,string info,int hp,int maxHp
2024-12-30 12:40:25 +08:00
panelRect.GetComponent<charainfoPanel>().UpDateShow("1", "Enemy_001", "0", "3", "1", "<22><><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>һ", role.hp, role.maxHp);
2025-01-02 18:05:20 +08:00
panelRect.GetComponent<charainfoPanel>().role = role;
2024-12-19 19:02:10 +08:00
}
else
{
2025-01-02 16:36:21 +08:00
panelRect.GetComponent<charainfoPanel>().UpDateShow(role.Level.ToString(), role.Name, role.Info, role.MinAttack + "~" + role.MaxAttack, role.AttackRange.ToString(), role.AttackCD.ToString());
2025-01-02 18:05:20 +08:00
panelRect.GetComponent<charainfoPanel>().role = role;
2024-12-19 19:02:10 +08:00
}
2024-12-20 10:42:20 +08:00
2024-12-19 19:02:10 +08:00
}
else
{
2024-12-20 10:42:20 +08:00
//HideAttackRange();
2024-12-19 19:02:10 +08:00
}
}
2024-12-30 17:50:50 +08:00
public async void ShowAttackRange(GameObject attackRange)
2024-12-19 11:48:31 +08:00
{
2024-12-19 19:02:10 +08:00
if (attackRange!=null)
2024-12-30 17:50:50 +08:00
{
attackRange.transform.DOScale(new Vector2(OrSizeX, OrSizeY), 0.3f).SetEase(Ease.InOutBack);
}
2024-12-19 11:48:31 +08:00
}
2024-12-19 19:02:10 +08:00
2024-12-20 10:42:20 +08:00
public void HideAttackRange(GameObject attackRange)
2024-12-19 11:48:31 +08:00
{
if (attackRange != null )
{
attackRange.transform.DOScale(Vector3.zero, 0.3f).SetEase(Ease.InOutBack);
2024-12-19 19:02:10 +08:00
2024-12-19 11:48:31 +08:00
}
2024-12-19 11:48:31 +08:00
}
void IdForInfo(string id)
{
List<Character> mY = MengyaoInfo.Instance.m_Mengyao;
foreach (Character temp in mY)
{
if (temp.Id==id)
{
MyCharacter=temp;
break;
}
}
2024-12-10 06:57:53 +08:00
}
2025-01-02 18:05:20 +08:00
public void HideInfoPanel()
{
2025-01-03 18:03:35 +08:00
if (UIContorl.instance.NowShowInfo!=null)
2025-01-02 18:05:20 +08:00
{
2025-01-03 18:03:35 +08:00
UIContorl.instance.NowShowInfo.Id = -1;
UIContorl.instance.NowShowInfo.role = null;
if (instantiatedPanel != null && instantiatedPanel.GetComponent<charainfoPanel>()._closePanel != null)
{
Destroy(instantiatedPanel.GetComponent<charainfoPanel>()._closePanel);
}
2025-01-02 18:05:20 +08:00
}
2025-01-03 11:59:22 +08:00
2025-01-03 18:03:35 +08:00
2025-01-02 18:05:20 +08:00
//Debug.Log("<22>رչ<D8B1><D5B9><EFBFBD><EFBFBD><EFBFBD>Χ");
}
2024-12-10 06:57:53 +08:00
}