public void DeleteCurrentUnit() { UIUnitSlot selectedSlot = SelectedSlot; if (selectedSlot != null) { selectedSlot.SetUnitData(null); } }
public void ChangeCurrentUnit() { UIUnitSlot selectedSlot = SelectedSlot; if (selectedSlot != null) { selectedSlot.ShowUnitSelect(); } }
public void Awake() { for (int i = 0; i < UnitSlotsRO.Length; i++) { UIUnitSlot slot = UnitSlotsRO[i]; if (slot != null) { slot.SlotIsSelected += new EventHandler(slot_SlotIsSelected); } } }
UIUnitSlot GetUIUnitSlot(UnitPlace place) { for (int i = 0; i < UnitSlotsRO.Length; i++) { UIUnitSlot slot = UnitSlotsRO[i]; if (slot != null && slot.Place.Range == place.Range && slot.Place.Position == place.Position) { return(slot); } } return(null); }
public void Update() { if (_unitData == null) { _slotPosition = transform.position; return; } if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary) { Vector2 position = touch.position; if (_touchSlot == null) { List <UIUnitSlot> slots = GetSlots(position); if (slots.Contains(this)) { _touchSlot = this; } } if (_touchSlot == this) { _targetSlot = GetTargetSlot(position); Vector3 targetPosition = new Vector3(position.x, position.y, transform.position.z); transform.position = targetPosition; } } } else { if (_targetSlot != null) { BaseSoldierData targetData = _targetSlot.UnitData; _targetSlot.SetUnitData(_unitData); _targetSlot.SelectSlot(true); SetUnitData(targetData); _targetSlot = null; } transform.position = _slotPosition; _touchSlot = null; } }
public void Update() { if (_unitData == null) { _slotPosition = transform.position; return; } if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary) { Vector2 position = touch.position; if (_touchSlot == null) { List<UIUnitSlot> slots = GetSlots(position); if (slots.Contains(this)) _touchSlot = this; } if (_touchSlot == this) { _targetSlot = GetTargetSlot(position); Vector3 targetPosition = new Vector3(position.x, position.y, transform.position.z); transform.position = targetPosition; } } } else { if (_targetSlot != null) { BaseSoldierData targetData = _targetSlot.UnitData; _targetSlot.SetUnitData(_unitData); _targetSlot.SelectSlot(true); SetUnitData(targetData); _targetSlot = null; } transform.position = _slotPosition; _touchSlot = null; } }
List <UIUnitSlot> GetSlots(Vector2 position) { List <UIUnitSlot> slots = new List <UIUnitSlot>(); Canvas canvas = Utils.UI.GetCanvas(RenderMode.ScreenSpaceOverlay); if (canvas != null) { GraphicRaycaster rayCaster = canvas.GetComponent <GraphicRaycaster>(); List <RaycastResult> results = new List <RaycastResult>(); PointerEventData eventData = new PointerEventData(null); eventData.position = position; rayCaster.Raycast(eventData, results); foreach (RaycastResult result in results) { UIUnitSlot slot = result.gameObject.GetComponent <UIUnitSlot>(); if (slot != null) { slots.Add(slot); } } } return(slots); }
public void SetHeroTemplate() { UIUnitSlot firstUISlot = null; BaseHeroData heroData = Global.Instance.Player.Heroes.Current.Data; for (int i = 0; i < heroData.SlotTemplate.Length; i++) { UnitSlot slot = heroData.SlotTemplate[i]; if (slot != null) { UIUnitSlot uiSlot = GetUIUnitSlot(slot.Place); if (uiSlot != null) { BaseSoldierData soldierData = UnitsConfig.Instance.GetSoldierData(slot.Unit); uiSlot.SetUnitData(soldierData); if (firstUISlot == null) { uiSlot.SelectSlot(true); firstUISlot = uiSlot; } } } } }