【Unity ライブラリ】Easy Save 2 : DateTime型のデータを保存
EasySave2でDateTime型は保存できないので、string型で保存する。
public string _sCurTimeIsLeft{ get{ if (ES2.Exists ("curTimeIsLeft" + _id)) { return ES2.Load<string> ("curTimeIsLeft" + _id); } else { return null; } } set{ ES2.Save (value, "curTimeIsLeft" + _id); } } public string _sTimeIsClicked{ get{ if (ES2.Exists ("timeIsClicked" + _id)) { return ES2.Load<string> ("timeIsClicked" + _id); } else { return null; } } set{ ES2.Save (value, "timeIsClicked" + _id); } }
呼び出す側で、intやDateTime型に変換してあげる。
void Update () { if(SkillSource._item[_id]._bOnUseSkill){ if( _curTimeIsLeft > 0){ _curTimeIsLeft = Convert.ToInt64(SkillSource._item[_id]._sCurTimeIsLeft); TimeSpan pastTime = DateTime.Now - Convert.ToDateTime(SkillSource._item[_id]._sTimeIsClicked); _curTimeIsLeft = _timeCoolDown - pastTime.Seconds; SkillSource._item[_id]._sCurTimeIsLeft = Convert.ToString(_curTimeIsLeft); UpdateContent(); }else{ SkillSource._item[_id]._bOnUseSkill = false; _curTimeIsLeft = _timeCoolDown; _bIcon.enabled = true; } } } public void SetContent(int id) { List<SkillContents> _item = SkillSource._item; _id = id; _type = _item[_id]._type; _curLevel = _item[_id]._curLevel; _levelRequirement = _item[_id]._stageRequirement; _iSkill.SetSprite ( _item[_id]._spriteName); Utility.ChangeTextMesh(_tName , _item[_id]._name); Utility.ChangeTextMesh(_tDescription, _item[_id]._description); UpdateContent(_id); }