void MoveFightSkill(AddFightSkill e) { GameModel gm = GetModel <GameModel>(); if (e.pos.x >= leftLimit && e.pos.x <= rightLimit && e.pos.y <= upLimit && e.pos.y >= downLimit) //移动的位置在技能框内 { float MinDistance = 100; int targetIndex = 0; for (int i = 0; i < 5; i++) //找到最近的技能框 { if (Vector2.Distance(e.pos, SkillPos[i].position) <= MinDistance) { MinDistance = Vector2.Distance(e.pos, SkillPos[i].position); targetIndex = i; } } if (gm.FightSkill.Count < targetIndex + 1) { targetIndex = gm.FightSkill.Count - 1; } gm.FightSkill.Remove(e.id); gm.FightSkill.Insert(targetIndex, e.id); ShowFightSkill(); } else { gm.FightSkill.Remove(e.id); ShowFightSkill(); } }
public override void HandleEvent(string eventName, object data) { switch (eventName) { case Consts.E_EnterScene: SceneArgs e = data as SceneArgs; int scenceID = e.SceneIndex; if (scenceID == 2) { initialize(); } break; case Consts.E_ShowSkillInfo: int skillID = (int)data; ShowSkillInfo(skillID); break; case Consts.E_AddFightSkill: AddFightSkill addskill = data as AddFightSkill; AddFightSkill(addskill); break; case Consts.E_MoveFightSkill: AddFightSkill moveskill = data as AddFightSkill; MoveFightSkill(moveskill); break; } }
void AddFightSkill(AddFightSkill e) { if (e.pos.x >= leftLimit && e.pos.x <= rightLimit && e.pos.y <= upLimit && e.pos.y >= downLimit) { GameModel gm = GetModel <GameModel>(); if (!gm.FightSkill.Contains(e.id) && gm.FightSkill.Count <= 5 && gm.m_Skill.ContainsKey(e.id)) { GameObject skill = (GameObject)Instantiate(Resources.Load("Prefab/SkillIcon")); Image Icon = skill.GetComponent <Image>(); string path = "Icon/Skill/Skill_" + e.id; Icon.sprite = Resources.Load <Sprite>(path); skill.transform.parent = SkillIconPanel.transform; skill.transform.position = SkillPos[gm.FightSkill.Count].position; skill.GetComponent <DragFightSkill>().SkillID = e.id; gm.FightSkill.Add(e.id); } } }