public void OnEndDrag(PointerEventData eventData) { if (SplitDataFromServe._heroSkill.Contains(dataSkill) && !dataSkill.data["type"].Value.Equals("passive")) { if (itemBeingDragged != null) { string tempIdhk = this.dataSkill.data["idhk"].Value; if (eventData.pointerEnter.tag.Equals("SkillSlot") && !this.gameObject.tag.Equals("SkillInList")) { Transform finishDrag = eventData.pointerEnter.transform; if (eventData.pointerEnter.transform.childCount == 0) { this.transform.parent = null; this.transform.parent = finishDrag; this.transform.localScale = Vector3.one; this.GetComponent <RectTransform>().localPosition = Vector3.zero; PlayerPrefs.SetInt(this.dataSkill.data["idhk"].Value, int.Parse(finishDrag.name)); Destroy(itemBeingDragged); itemBeingDragged = null; } else { Destroy(itemBeingDragged); itemBeingDragged = null; } } else if (eventData.pointerEnter.tag.Equals("SkillSlot") && this.gameObject.tag.Equals("SkillInList")) { Transform finishDrag = eventData.pointerEnter.transform; //Debug.Log("wear skill"); StartCoroutine(ServerAdapter.EquipSkill(CharacterInfo._instance._baseProperties.idHero, CharacterInfo._instance._baseProperties.idCodeHero, this.dataSkill.data["idhk"].AsInt, result => { Debug.Log(result.ToString()); if (result.StartsWith("Error")) { //Debug.Log("Do nothing"); Destroy(itemBeingDragged); itemBeingDragged = null; } else { Debug.Log("wear ok skill level " + this.dataSkill.data["level"].AsInt); GameObject skillObj = Instantiate(Resources.Load("Prefabs/Skill") as GameObject); skillObj.transform.parent = finishDrag; PlayerPrefs.SetInt(this.dataSkill.data["idhk"].Value, finishDrag.GetSiblingIndex()); skillObj.transform.localPosition = Vector3.zero; skillObj.GetComponent <RectTransform>().localScale = new Vector3(1f, 1f, 1f); skillObj.transform.GetComponent <Image>().sprite = Resources.Load <Sprite>("Textures/skillAss/" + this.dataSkill.data["sprite"].Value); skillObj.AddComponent <DragHandeler>().dataSkill = this.dataSkill; skillObj.AddComponent <DropHandle>().dataSkill = this.dataSkill; skillObj.tag = "Skill"; foreach (NewSkill _tempSkill in SplitDataFromServe._heroSkill) { if (this.dataSkill.data["idhk"].AsInt == _tempSkill.data["idhk"].AsInt) { _tempSkill.addField("typewear", 1); break; } } Destroy(itemBeingDragged); itemBeingDragged = null; } })); } else if (!eventData.pointerEnter.tag.Equals("Skill") && !eventData.pointerEnter.tag.Equals("SkillSlot") && !this.gameObject.tag.Equals("SkillInList")) { //Debug.Log("unwear skill"); StartCoroutine(ServerAdapter.UnEquipSkill(CharacterInfo._instance._baseProperties.idHero, CharacterInfo._instance._baseProperties.idCodeHero, this.dataSkill.data["idhk"].AsInt, result => { if (result.StartsWith("Error")) { //Debug.Log("Do nothing"); Destroy(itemBeingDragged); } else { //Debug.Log(result); PlayerPrefs.DeleteKey(tempIdhk); foreach (NewSkill _tempSkill in SplitDataFromServe._heroSkill) { if (this.dataSkill.data["idhk"].AsInt == _tempSkill.data["idhk"].AsInt) { _tempSkill.addField("typewear", 0); break; } } Destroy(itemBeingDragged); itemBeingDragged = null; Destroy(this.gameObject); } })); } else { Destroy(itemBeingDragged); itemBeingDragged = null; } } } }
public void OnDrop(PointerEventData eventData) { if (GetDropObject(eventData) != null && GetDropObject(eventData).tag == "Skill") { Debug.Log("switch skill slot"); Sprite dropSprite = gameObject.GetComponent <Image>().sprite; Sprite dragSprite = GetDropObject(eventData).GetComponent <Image>().sprite; NewSkill dropSkill = gameObject.GetComponent <DropHandle>().dataSkill; NewSkill dragSkill = GetDropObject(eventData).GetComponent <DragHandeler>().dataSkill; int indexDropSkill = PlayerPrefs.GetInt(gameObject.GetComponent <DropHandle>().dataSkill.data["idhk"].Value); int indexDragSkill = PlayerPrefs.GetInt(GetDropObject(eventData).GetComponent <DragHandeler>().dataSkill.data["idhk"].Value); PlayerPrefs.SetInt(GetDropObject(eventData).GetComponent <DropHandle>().dataSkill.data["idhk"].Value, indexDropSkill); PlayerPrefs.SetInt(gameObject.GetComponent <DropHandle>().dataSkill.data["idhk"].Value, indexDragSkill); this.gameObject.GetComponent <Image>().sprite = dragSprite; GetDropObject(eventData).GetComponent <Image>().sprite = dropSprite; this.gameObject.GetComponent <DragHandeler>().SetDataSkill(dragSkill); this.gameObject.GetComponent <DropHandle>().SetDataSkill(dragSkill); GetDropObject(eventData).GetComponent <DragHandeler>().SetDataSkill(dropSkill); GetDropObject(eventData).GetComponent <DropHandle>().SetDataSkill(dropSkill); } else if (GetDropObject(eventData) != null && GetDropObject(eventData).tag == "SkillInList") { Sprite dragSprite = GetDropObject(eventData).GetComponent <Image>().sprite; NewSkill dragSkill = GetDropObject(eventData).GetComponent <DragHandeler>().dataSkill; NewSkill dropSkill = gameObject.GetComponent <DropHandle>().dataSkill; int indexDropSkill = PlayerPrefs.GetInt(gameObject.GetComponent <DropHandle>().dataSkill.data["idhk"].Value); if (dragSkill.data["idInit"].AsInt != dropSkill.data["idInit"].AsInt && !checkHeroWearedSkill(dragSkill)) { StartCoroutine(ServerAdapter.UnEquipSkill(CharacterInfo._instance._baseProperties.idHero, CharacterInfo._instance._baseProperties.idCodeHero, dropSkill.data["idhk"].AsInt, result => { Debug.Log(result.ToString()); if (result.StartsWith("Error")) { Debug.Log("Do nothing"); } else { Debug.Log("remove old skill ok"); foreach (NewSkill _tempSkill in SplitDataFromServe._heroSkill) { if (dropSkill.data["idhk"].AsInt == _tempSkill.data["idhk"].AsInt) { _tempSkill.addField("typewear", 0); break; } } StartCoroutine(ServerAdapter.EquipSkill(CharacterInfo._instance._baseProperties.idHero, CharacterInfo._instance._baseProperties.idCodeHero, dragSkill.data["idhk"].AsInt, result1 => { Debug.Log(result1.ToString()); if (result1.StartsWith("Error")) { Debug.Log("Do nothing"); } else { Debug.Log("change skill ok"); foreach (NewSkill _tempSkill in SplitDataFromServe._heroSkill) { if (dragSkill.data["idhk"].AsInt == _tempSkill.data["idhk"].AsInt) { _tempSkill.addField("typewear", 1); break; } } PlayerPrefs.DeleteKey(dropSkill.data["idhk"].Value); PlayerPrefs.SetInt(dragSkill.data["idhk"].Value, indexDropSkill); this.gameObject.GetComponent <Image>().sprite = dragSprite; this.gameObject.GetComponent <DragHandeler>().SetDataSkill(dragSkill); this.gameObject.GetComponent <DropHandle>().SetDataSkill(dragSkill); } })); } })); } else { Debug.Log("Do nothing"); } } }