public static SkillSaveData SkillToSave(SkillData data) { SkillSaveData saveData = new SkillSaveData(); saveData.id = data.id; saveData.level = data.level; saveData.coolTimeLeft = data.coolTimeLeft; return(saveData); }
/// <summary> /// Load the skill data from the serialized object and /// reapply the loaded data to the active player. /// </summary> /// <param name="serializedObj">object with the player's saved data</param> public override void Load(object serializedObj) { SkillSaveData data = serializedObj as SkillSaveData; // Give the player their unlocked skills and unlocked skill states back // Shapes int[] shapeStates = data.GetShapeUnlockStates(); UnlockSkillStatesForPlayer(SkillController.SkillEnum.Shape, shapeStates); // Colors int[] colorStates = data.GetColorUnlockStates(); UnlockSkillStatesForPlayer(SkillController.SkillEnum.Color, colorStates); // Set the active states without using the skills SkillBase <ShapeData> shapeSkill = skillController.GetSkill(SkillController.SkillEnum.Shape) as SkillBase <ShapeData>; SkillBase <ColorData> colorSkill = skillController.GetSkill(SkillController.SkillEnum.Color) as SkillBase <ColorData>; shapeSkill.FakeUse(data.GetActiveShapeState()); colorSkill.FakeUse(data.GetActiveColorState()); // Set the shape size scaleController.ShapeScale = data.GetShapeSize(); }
/// <summary> /// Skill Save /// </summary> public void Save() { SkillSaveData[] datas = new SkillSaveData[skills.Length]; for (int i = 0; i < skills.Length; i++) { if (skills[i].skill) { datas[i] = SkillSaveData.SkillToSave(skills[i].skill.data); Debug.Log("Skill Saved" + datas[i].id + "id " + datas[i].level + "level"); } else { datas[i] = new SkillSaveData(); datas[i].id = -1; } } string str = JsonHelper.ToJson <SkillSaveData>(datas); PlayerPrefs.SetString("skill", str); //Debug.Log("Save Skills : " + str); }