装备系统完结,修复并加入很多
This commit is contained in:
@@ -3,6 +3,9 @@ using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
public class equipItemPrefab : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerClickHandler
|
||||
{
|
||||
@@ -29,7 +32,11 @@ public class equipItemPrefab : MonoBehaviour, IBeginDragHandler, IDragHandler, I
|
||||
public bool allowDrag = true;
|
||||
public bool allowQuickTransfer = true;
|
||||
|
||||
[Header("equipperProfile")]
|
||||
public Image equipperProfileIcon;
|
||||
|
||||
private Action<equipmentSO> clickHandler;
|
||||
private Func<equipmentSO, bool> rightClickHandler;
|
||||
private GameObject spawnedDescription;
|
||||
private bool suppressNextClick;
|
||||
private Canvas rootCanvas;
|
||||
@@ -58,22 +65,25 @@ public class equipItemPrefab : MonoBehaviour, IBeginDragHandler, IDragHandler, I
|
||||
}
|
||||
}
|
||||
|
||||
public void Bind(equipmentSO so, Action<equipmentSO> onClick = null)
|
||||
public void Bind(equipmentSO so, Action<equipmentSO> onClick = null, Func<equipmentSO, bool> onRightClick = null)
|
||||
{
|
||||
itemSO = so;
|
||||
clickHandler = onClick;
|
||||
rightClickHandler = onRightClick;
|
||||
|
||||
if (itemSO == null)
|
||||
{
|
||||
ApplyProfileSprite(null);
|
||||
ApplyBottomColor(0);
|
||||
ApplyEquipperProfile(null);
|
||||
return;
|
||||
}
|
||||
|
||||
equipmentSO.EquipmentTierPresentation presentation = itemSO.GetCurrentTierPresentation();
|
||||
equipmentSO.EquipmentTierPresentation presentation = itemSO.GetVisualTierPresentation();
|
||||
Sprite displaySprite = presentation != null ? presentation.equipmentSprite : null;
|
||||
ApplyProfileSprite(displaySprite);
|
||||
ApplyBottomColor(GetQualityColorIndex(itemSO.level));
|
||||
ApplyBottomColor(itemSO.GetVisualQualityColorIndex());
|
||||
ApplyEquipperProfile(FindEquipper(itemSO));
|
||||
}
|
||||
|
||||
private void HandleClicked()
|
||||
@@ -214,7 +224,12 @@ public class equipItemPrefab : MonoBehaviour, IBeginDragHandler, IDragHandler, I
|
||||
isDraggingWithLeftButton = false;
|
||||
equipUpdate matchedUpdateTarget = FindMatchingUpdateTarget(eventData);
|
||||
equipIllusion matchedIllusionTarget = matchedUpdateTarget == null ? FindMatchingIllusionTarget(eventData) : null;
|
||||
equipSmelt matchedSmeltTarget = matchedUpdateTarget == null && matchedIllusionTarget == null ? FindMatchingSmeltTarget(eventData) : null;
|
||||
eFinalDream matchedFinalDreamTarget = matchedUpdateTarget == null && matchedIllusionTarget == null ? FindMatchingFinalDreamTarget(eventData) : null;
|
||||
equipTransfer matchedTransferTarget = matchedUpdateTarget == null && matchedIllusionTarget == null && matchedFinalDreamTarget == null ? FindMatchingTransferTarget(eventData) : null;
|
||||
equipTransfer.TransferDropSlot matchedTransferSlot = matchedTransferTarget != null
|
||||
? matchedTransferTarget.GetHoveredDropSlot(eventData != null ? eventData.position : (Vector2)Input.mousePosition, eventData != null && eventData.pressEventCamera != null ? eventData.pressEventCamera : uiCamera)
|
||||
: equipTransfer.TransferDropSlot.None;
|
||||
equipSmelt matchedSmeltTarget = matchedUpdateTarget == null && matchedIllusionTarget == null && matchedFinalDreamTarget == null && matchedTransferTarget == null ? FindMatchingSmeltTarget(eventData) : null;
|
||||
bool cameFromSmeltPool = equipSmelt.IsEquipmentAssignedToSmeltPool(itemSO);
|
||||
|
||||
SetAllDragTargetsVisible(false);
|
||||
@@ -232,6 +247,21 @@ public class equipItemPrefab : MonoBehaviour, IBeginDragHandler, IDragHandler, I
|
||||
return;
|
||||
}
|
||||
|
||||
if (matchedFinalDreamTarget != null)
|
||||
{
|
||||
matchedFinalDreamTarget.AcceptDraggedEquipment(itemSO);
|
||||
return;
|
||||
}
|
||||
|
||||
if (matchedTransferTarget != null)
|
||||
{
|
||||
if (matchedTransferSlot != equipTransfer.TransferDropSlot.None)
|
||||
{
|
||||
matchedTransferTarget.AcceptDraggedEquipment(itemSO, matchedTransferSlot);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (matchedSmeltTarget != null)
|
||||
{
|
||||
matchedSmeltTarget.AcceptDraggedEquipment(itemSO);
|
||||
@@ -246,17 +276,41 @@ public class equipItemPrefab : MonoBehaviour, IBeginDragHandler, IDragHandler, I
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (!allowQuickTransfer || eventData == null || eventData.button != PointerEventData.InputButton.Right || itemSO == null)
|
||||
if (eventData == null || itemSO == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (equipSmelt.TryHandleQuickTransfer(itemSO))
|
||||
if (eventData.button == PointerEventData.InputButton.Right)
|
||||
{
|
||||
isDraggingWithLeftButton = false;
|
||||
SetAllDragTargetsVisible(false);
|
||||
DestroyDragGhost();
|
||||
suppressNextClick = true;
|
||||
if (rightClickHandler != null && rightClickHandler.Invoke(itemSO))
|
||||
{
|
||||
isDraggingWithLeftButton = false;
|
||||
SetAllDragTargetsVisible(false);
|
||||
DestroyDragGhost();
|
||||
suppressNextClick = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!allowQuickTransfer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (equipSmelt.TryHandleQuickTransfer(itemSO))
|
||||
{
|
||||
isDraggingWithLeftButton = false;
|
||||
SetAllDragTargetsVisible(false);
|
||||
DestroyDragGhost();
|
||||
suppressNextClick = true;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (eventData.button != PointerEventData.InputButton.Left)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,6 +383,52 @@ public class equipItemPrefab : MonoBehaviour, IBeginDragHandler, IDragHandler, I
|
||||
return null;
|
||||
}
|
||||
|
||||
private equipTransfer FindMatchingTransferTarget(PointerEventData eventData)
|
||||
{
|
||||
equipTransfer[] targets = FindObjectsOfType<equipTransfer>(true);
|
||||
if (targets == null || targets.Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Vector2 pointerPosition = eventData != null ? eventData.position : (Vector2)Input.mousePosition;
|
||||
Camera eventCamera = eventData != null && eventData.pressEventCamera != null ? eventData.pressEventCamera : uiCamera;
|
||||
|
||||
for (int i = 0; i < targets.Length; i++)
|
||||
{
|
||||
equipTransfer target = targets[i];
|
||||
if (target != null && target.gameObject.activeInHierarchy && target.GetHoveredDropSlot(pointerPosition, eventCamera) != equipTransfer.TransferDropSlot.None)
|
||||
{
|
||||
return target;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private eFinalDream FindMatchingFinalDreamTarget(PointerEventData eventData)
|
||||
{
|
||||
eFinalDream[] targets = FindObjectsOfType<eFinalDream>(true);
|
||||
if (targets == null || targets.Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Vector2 pointerPosition = eventData != null ? eventData.position : (Vector2)Input.mousePosition;
|
||||
Camera eventCamera = eventData != null && eventData.pressEventCamera != null ? eventData.pressEventCamera : uiCamera;
|
||||
|
||||
for (int i = 0; i < targets.Length; i++)
|
||||
{
|
||||
eFinalDream target = targets[i];
|
||||
if (target != null && target.gameObject.activeInHierarchy && target.IsPointerOverDropArea(pointerPosition, eventCamera))
|
||||
{
|
||||
return target;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void CreateDragGhost()
|
||||
{
|
||||
DestroyDragGhost();
|
||||
@@ -467,6 +567,30 @@ public class equipItemPrefab : MonoBehaviour, IBeginDragHandler, IDragHandler, I
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
eFinalDream[] finalDreamTargets = FindObjectsOfType<eFinalDream>(true);
|
||||
if (finalDreamTargets != null)
|
||||
{
|
||||
for (int i = 0; i < finalDreamTargets.Length; i++)
|
||||
{
|
||||
if (finalDreamTargets[i] != null && finalDreamTargets[i].gameObject.activeInHierarchy)
|
||||
{
|
||||
finalDreamTargets[i].SetDragPreviewVisible(visible);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
equipTransfer[] transferTargets = FindObjectsOfType<equipTransfer>(true);
|
||||
if (transferTargets != null)
|
||||
{
|
||||
for (int i = 0; i < transferTargets.Length; i++)
|
||||
{
|
||||
if (transferTargets[i] != null && transferTargets[i].gameObject.activeInHierarchy)
|
||||
{
|
||||
transferTargets[i].SetDragPreviewVisible(visible);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyProfileSprite(Sprite sprite)
|
||||
@@ -495,29 +619,75 @@ public class equipItemPrefab : MonoBehaviour, IBeginDragHandler, IDragHandler, I
|
||||
itemBtm.color = color;
|
||||
}
|
||||
|
||||
private static int GetQualityColorIndex(int level)
|
||||
private void ApplyEquipperProfile(AllyHero_SO hero)
|
||||
{
|
||||
if (level >= 20)
|
||||
if (equipperProfileIcon == null)
|
||||
{
|
||||
return 5;
|
||||
return;
|
||||
}
|
||||
|
||||
if (level >= 15)
|
||||
Sprite sprite = hero != null ? hero.ally_hero_squareProfile : null;
|
||||
equipperProfileIcon.sprite = sprite;
|
||||
equipperProfileIcon.color = sprite != null ? Color.white : new Color(1f, 1f, 1f, 0f);
|
||||
equipperProfileIcon.enabled = true;
|
||||
}
|
||||
|
||||
private AllyHero_SO FindEquipper(equipmentSO equipment)
|
||||
{
|
||||
if (equipment == null)
|
||||
{
|
||||
return 4;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (level >= 10)
|
||||
AllyHero_SO[] heroes = LoadHeroAssets();
|
||||
for (int i = 0; i < heroes.Length; i++)
|
||||
{
|
||||
return 3;
|
||||
AllyHero_SO hero = heroes[i];
|
||||
if (hero == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
hero.LoadEquippedEquipmentFromLocal();
|
||||
equipmentSO equipped = hero.GetEquippedEquipmentResolved();
|
||||
if (equipped == equipment || (!string.IsNullOrWhiteSpace(equipped?.name) && equipped.name == equipment.name))
|
||||
{
|
||||
return hero;
|
||||
}
|
||||
}
|
||||
|
||||
if (level >= 5)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return 1;
|
||||
private AllyHero_SO[] LoadHeroAssets()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
string[] guids = AssetDatabase.FindAssets("t:AllyHero_SO", new[] { "Assets/Resources/so/ally" });
|
||||
var heroes = new AllyHero_SO[guids.Length];
|
||||
int count = 0;
|
||||
for (int i = 0; i < guids.Length; i++)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(guids[i]);
|
||||
AllyHero_SO hero = AssetDatabase.LoadAssetAtPath<AllyHero_SO>(path);
|
||||
if (hero != null)
|
||||
{
|
||||
heroes[count++] = hero;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == heroes.Length)
|
||||
{
|
||||
return heroes;
|
||||
}
|
||||
|
||||
Array.Resize(ref heroes, count);
|
||||
return heroes;
|
||||
}
|
||||
#endif
|
||||
|
||||
return Resources.LoadAll<AllyHero_SO>("so/ally");
|
||||
}
|
||||
|
||||
public void SetInteractionOptions(bool dragEnabled, bool quickTransferEnabled)
|
||||
|
||||
Reference in New Issue
Block a user