Beispiel #1
0
    public override void OnFirstOpen()
    {
        base.OnFirstOpen();

        playerModel = ModelManager.Get <PlayerModel>("PlayerModel");

        talentItemGo = GetGameObject("container/list/talentItem");
        listTrasf    = GetRectTransform("container/list");

        talentModel = ModelManager.Get <TalentModel>("TalentModel");
        //int count = talentModel.talentIds.Count;

        //生成go,并且让go具备点击效果
        //随机让go绑定3个天赋

        //var talants = DataHelp.GetRandom<int>(talentModel.canUseTalent, 3);

        for (int i = 0; i < 3; i++)
        {
            var itemGo = GameObject.Instantiate(talentItemGo, listTrasf);
            talentGos[i] = itemGo;
        }

        talentItemGo.SetActive(false);
    }
        public IActionResult Post([FromBody] TalentModel talentModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var talent = new TalentsManager(context).AddTalent(talentModel.Name);

            return(Ok(new { success = talent.Success, message = talent.Message, data = talent.Data }));
        }
        public IActionResult Put([FromRoute] int id, TalentModel talent)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (id != talent.Id)
            {
                return(BadRequest(ModelState));
            }
            var updateTalent = new TalentsManager(context).UpdateTalent(talent);

            return(Ok(new { success = updateTalent.Result.Success, message = updateTalent.Result.Message, data = updateTalent.Result.Data }));
        }
        public async Task <GenericActionResult <TalentModel> > UpdateTalent(TalentModel talentModel)
        {
            context.Entry(new Talent {
                Id = talentModel.Id, Name = talentModel.Name
            }).State = EntityState.Modified;
            try
            {
                await context.SaveChangesAsync();

                return(new GenericActionResult <TalentModel>(true, "Talent updated successfully", talentModel));
            }
            catch (DbUpdateConcurrencyException)
            {
                return(new GenericActionResult <TalentModel>("Failed to update talent, please try again or contact the administrator."));
            }
        }