/// <summary> /// 获取用户英雄 /// </summary> public void GetUserHero() { Debug.Log("HeroProxy GetUserHero"); // 打开数据库 OpenDB(); // 查询 string uid = GameController.instance.crtUser.uid; SqliteDataReader reader = db.Select("User_Hero", "UserId", GetStr(uid)); if (reader.HasRows) // 读取数据 { ArrayList list = new ArrayList(); while (reader.Read()) { UserHeroVO userHero = new UserHeroVO(); userHero.heroName = reader.GetString(reader.GetOrdinal("Name")); userHero.level = reader.GetInt32(reader.GetOrdinal("Lv")); userHero.exp = reader.GetInt32(reader.GetOrdinal("Exp")); userHero.money = reader.GetInt32(reader.GetOrdinal("Money")); userHero.force = reader.GetInt32(reader.GetOrdinal("Force")); list.Add(userHero); Debug.Log(userHero.heroName); } SendNotification(NotificationList.GET_USER_HERO + SUCCESS, list); } else { // 当前用户没有英雄,直接打开创建英雄面板新建英雄,而且此操作不能取消 SendNotification(NotificationList.GET_USER_HERO + SUCCESS, "cantCancel"); } // 关闭数据库 CloseDB(); }
/// <summary> /// 切换英雄 /// </summary> private void ChangeHero() { UserHeroVO crtHero = crtItem.GetComponent <HeroItem>().data; GameController.instance.crtHero = crtHero; SendNotification(NotificationList.UPDATE_HERO_DATA); }
/// <summary> /// 更新数据 /// </summary> public void UpdateData() { UserHeroVO userHero = GameController.instance.crtHero; if (userHero == null) { return; } nameText.text = userHero.name; lvText.text = "等级: " + userHero.lv; moneyText.text = "金币: " + userHero.money; expText.text = "经验值: " + userHero.exp; }
/// <summary> /// 创建新英雄 /// </summary> /// <param name="userHero"></param> public void CreateHero(UserHeroVO userHero) { // 打开数据库 OpenDB(); // 获取数据 SqliteDataReader reader = db.Select("User_Hero", "name", GetStr(userHero.heroName)); if (reader.HasRows) // 有重名 { SendNotification(NotificationList.CREATE_HERO + FAILURE, "英雄已存在!"); CloseDB(); return; } db.InsertInto("User_Hero", userHero.GetString()); SendNotification(NotificationList.CREATE_HERO + SUCCESS); // 关闭数据库 CloseDB(); }
/// <summary> /// 创建英雄 /// </summary> private void CreateHero() { if (nameText.text == "") { Debug.LogError("名称不能为空!"); return; } if (StringHelper.CheckBadWord(nameText.text) || !StringHelper.IsSafeSqlString(nameText.text)) { Debug.LogError("名称不能有非法字符!"); return; } UserHeroVO userHero = new UserHeroVO(); userHero.userID = GameController.instance.crtUser.uid; // 用户uid userHero.heroID = Guid.NewGuid().ToString("N"); // 英雄uid userHero.heroName = nameText.text; // 英雄名称 userHero.heroType = heroType; // 英雄类型 SendNotification(NotificationList.CREATE_HERO, userHero); }
/// <summary> /// 创建新英雄 /// </summary> private void CreateHero() { if (nameInput.text == "") { Alert.Show("出错了", "名称不能为空"); return; } if (StringHelper.CheckBadWord(nameInput.text) || !StringHelper.IsSafeSqlString(nameInput.text)) { Alert.Show("出错了", "不允许非法字符"); return; } UserHeroVO userHero = new UserHeroVO(); userHero.userID = GameController.instance.crtUser.uid; userHero.heroID = Guid.NewGuid().ToString("N"); userHero.name = nameInput.text; userHero.type = heroType; SendNotification(NotificationList.CREATE_HERO, userHero); }
public void SetData(UserHeroVO hero) { heroData = hero; nameText.text = hero.heroName; lvText.text = "等级:" + hero.level; }