/// <summary> /// 自身slot为空 /// 1. isPickedUnit != false 直接放在这个空的slot槽下 /// 2. isPickedUnit == false 不做任何处理 /// /// 自身slot不为空 /// 1. isPickedUnit != false /// ① 当前slot下的unit.id == pickedUnit.id,不做任何处理 /// ② 当前slot下的unit.id != pickedUnit.id, pickedUnit与当前物品交换 /// 2. isPickedUnit == false 把当前物品槽下的Unit放到鼠标下 /// </summary> public void OnPointerDown(PointerEventData eventData) { Debug.Log("鼠标"); if (eventData.button != PointerEventData.InputButton.Left) { return; } Debug.Log("鼠标左键"); if (transform.childCount > 0) { //TODO 自身不为空 //获取当前自身slot下的Unit UnitUI currentItemUI = transform.GetChild(0).GetComponent <UnitUI>(); if (UnitManager.Instance.IsPickedUnit == false) { UnitManager.Instance.PickedUpUnit(currentItemUI); //调用此函数用于鼠标"捡起"当前slot下的unit Destroy(currentItemUI.gameObject); //摧毁slot下已经被鼠标"捡起"的unit } else { //TODO 自身不为空, 当前slot下的unit.id != pickedUnit.id, pickedUnit与当前物品交换 } } else { //TODO 自身为空 if (UnitManager.Instance.IsPickedUnit == true) { StoreItem(UnitManager.Instance.PickedUnit); UnitManager.Instance.RemoveAllItem(); } } }
private void Start() { canvas = GameObject.Find("UnitUI").GetComponent <Canvas>(); pickedUnit = GameObject.Find("PickedUnit").GetComponent <NBearUnit.UnitUI>(); pickedUnit.Hide(); IsInstantiation = false; }
/// <summary> /// “抓起” Unit /// </summary> /// <param name="unitUI">目标拾起的单位,用于传递信息</param> public void PickedUpUnit(NBearUnit.UnitUI unitUI) { //TODO “拾起” 单位 pickedUnit.SetUnit(); isPickedUnit = true; pickedUnit.Show(); }
/// <summary> /// 存储Unit到slot下 /// </summary> /// <param name="unit"></param> public void StoreItem(UnitUI unit) { GameObject itemGameObject = Instantiate(unitPrefab) as GameObject; itemGameObject.transform.SetParent(transform); itemGameObject.transform.localPosition = new Vector3(0.0f, -21.0f, 0.0f); itemGameObject.GetComponent <UnitUI>().SetUnit(/*unit*/); //设置Item Debug.Log("StoreItem"); }