private void Awake() { if (instance == null) { instance = this; } else { Destroy(gameObject); } // Create all achievement instances and/or check for persistence achievementInstances = new AchievementInstance[allAchievements.Length]; if (PlayerPrefs.HasKey(ACHIEVEMENTS_SAVE_STRING)) { LoadAchievements(); } else { for (int i = 0; i < allAchievements.Length; i++) { achievementInstances[i] = new AchievementInstance(allAchievements[i]); } } pCustomizer = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerCustomization>(); }
protected override void InitPrefabItem(object data) { content = data as AchievementInstance; if (content == null) { MyDebug.LogYellow("AchievementInstance is null!!"); return; } Init(); bool notHasAchievement = string.IsNullOrEmpty(content.finishTime); achievementName.text = LanguageController.Instance.GetLanguage(content.mainTitleIndex); achievementItem_WithoutAchievement.SetActive(notHasAchievement); if (!notHasAchievement) { achievementImage.sprite = SkinController.Instance.GetSprite(content.imageIndex); } List <GameObject> stars = CommonTool.GetGameObjectsContainName(gameObject, "Star"); for (int i = 0; i < stars.Count; i++) { stars[i].SetActive((i + 1) <= content.star); } }
public void ClaimAchievement(string _achievementID, int _reward) { AchievementInstance achievementBeingUpdated = achievementInstances.Where((achievement) => { return(achievement.AchievementInternalID == _achievementID); }).FirstOrDefault(); if (achievementBeingUpdated.AlreadyClaimed) { Debug.Log("Achievement already claimed"); return; } if (achievementBeingUpdated.Claimable) { pCustomizer.addCurrency(_reward); achievementBeingUpdated.AlreadyClaimed = true; Debug.Log("Money added:" + _reward); PersistAchievements(); } else { Debug.Log("Achievement not completed yet"); } }
protected override void OnButtonClick(Button btn) { base.OnButtonClick(btn); switch (btn.name) { case "WeChatBtn": ShareImage(PlatformType.WeChat); break; case "WeChatMomentsBtn": ShareImage(PlatformType.WeChatMoments); break; case "SinaWeiboBtn": ShareImage(PlatformType.SinaWeibo); break; case "ShareFrameBg": shareBtnsBg.DOMoveY(endPos, duration, true); CommonTool.GuiScale(sharePage.gameObject, canvasGroup, false, () => GuiController.Instance.SwitchWrapper(GuiFrameID.None)); break; case "AchievementDetailBtn": AchievementInstance instance = AchievementController.Instance.CurAchievementInstance; RecordController.Instance.CurSaveFileInstance = RecordController.Instance.ReadRecord(instance.finishTime); GuiController.Instance.SwitchWrapper(GuiFrameID.SaveFileFrame, true); break; default: MyDebug.LogYellow("Can not find Button: " + btn.name); break; } }
private void WriteFinishTime(string achievementName, string finishTime, int star) { AchievementInstance instance = achievementList.Find(x => x.achievementName == achievementName); if (instance != null) { instance.finishTime = finishTime; instance.star = star; } }
public static void ExchangeAchievement() { string addressList = Application.dataPath + "/Achievement.txt"; string targetList = Application.dataPath + "/Resources/Achievement/Achievement.txt"; StreamReader mutiLanguageAsset = new StreamReader(addressList); if (mutiLanguageAsset == null) { MyDebug.LogYellow("Can not find: " + addressList); return; } char[] charSeparators = new char[] { "\r"[0], "\n"[0] }; string asset = mutiLanguageAsset.ReadToEnd(); string[] lineArray = asset.Split(charSeparators, System.StringSplitOptions.RemoveEmptyEntries); string[] lineList; List <AchievementInstance> achList = new List <AchievementInstance>(); for (int j = 1; j < lineArray.Length; j++) { AchievementInstance instance = new AchievementInstance(); lineList = lineArray[j].Split(','); instance.achievementName = lineList[0]; float.TryParse(lineList[1], out instance.accuracy); float.TryParse(lineList[2], out instance.meanTime); instance.mainTitleIndex = lineList[3]; instance.subTitleIndex = lineList[4]; instance.imageIndex = lineList[5]; instance.chapterImageIndex = lineList[6]; int patternID = 0; int amountID = 0; int symbolID = 0; int digitID = 0; int operandID = 0; int.TryParse(lineList[7], out patternID); int.TryParse(lineList[8], out amountID); int.TryParse(lineList[9], out symbolID); int.TryParse(lineList[10], out digitID); int.TryParse(lineList[11], out operandID); CategoryInstance cInstance = new CategoryInstance(patternID, amountID, symbolID, digitID, operandID); instance.cInstance = cInstance; int.TryParse(lineList[12], out instance.difficulty); instance.finishTime = ""; instance.star = 0; achList.Add(instance); } if (File.Exists(targetList)) { File.Delete(targetList); } string toSave = JsonHelper.ToListJson <AchievementInstance>(achList); CommonTool.SetData(targetList, toSave); }
private void InitItem(AchievementInstance instance) { content = instance; List <GameObject> stars = CommonTool.GetGameObjectsContainName(gameObject, "Star"); for (int i = 0; i < stars.Count; i++) { stars[i].SetActive((i + 1) <= content.star); } GetComponent <Image>().sprite = SkinController.Instance.GetSprite(content.chapterImageIndex); }
/// <summary> /// The Method to load the Achievements. The Achievements file has to be at %USERPROFILE%\Saved Games\Singularity\Achievements. If no one like this exists /// it will just create a new one. /// </summary> internal void LoadAchievements() { var achievements = XSerializer.Load(@"Achievements.xml", true); if (achievements.IsPresent()) { mAchievements = (AchievementInstance)achievements.Get(); } else { mAchievements = new AchievementInstance(); } mAchievements.LoadToStatic(); }
private void TrackIncrementalAchievementUsingInternalID(string _achievementID, float _incrementValue) { AchievementInstance achievementBeingUpdated = AchievementInstances.Where((achievement) => { return(achievement.AchievementInternalID == _achievementID); }).FirstOrDefault(); if (achievementBeingUpdated.AlreadyCompleted) { return; } achievementBeingUpdated.CurrentProgress += _incrementValue; if (achievementBeingUpdated.Complete) { achievementBeingUpdated.AlreadyCompleted = true; } }
private void TrackStandardAchievementUsingInternalID(string _achievementID, bool _isComplete) { AchievementInstance achievementBeingUpdated = achievementInstances.Where((achievement) => { return(achievement.AchievementInternalID == _achievementID); }).FirstOrDefault(); if (achievementBeingUpdated.AlreadyCompleted || !_isComplete) { return; } achievementBeingUpdated.CurrentProgress += 1; if (achievementBeingUpdated.Complete) { achievementBeingUpdated.AlreadyCompleted = true; } }
private void InitAchievement() { if (!string.IsNullOrEmpty(AchievementController.Instance.CurAchievementName) && GuiController.Instance.CompetitionGUI == GuiFrameID.ChapterFrame) { curAchievementBtn.SetActive(true); achievementDetailBgInSettlement.SetActive(true); achievementDetailPageInSettlement.SetActive(true); CommonTool.GuiScale(achievementDetailPageInSettlement, canvasGroup, true); curAchievementInstance = AchievementController.Instance.GetCurAchievement(); achievementDetailImageInSettlement.sprite = SkinController.Instance.GetSprite(curAchievementInstance.imageIndex); achievementDetailMainTitleInSettlement.text = LanguageController.Instance.GetLanguage(curAchievementInstance.mainTitleIndex); achievementDetailSubTitleInSettlement.text = LanguageController.Instance.GetLanguage(curAchievementInstance.subTitleIndex); achievementDetailFinishTimeInSettlement.text = GetFinishTime(curAchievementInstance.finishTime); } else { curAchievementBtn.SetActive(false); } }
private void InitAchievement() { AchievementInstance instance = AchievementController.Instance.CurAchievementInstance; if (instance == null) { return; } achievementDetailBtn.SetActive(GuiController.Instance.LastGUI != GuiFrameID.SaveFileFrame && GuiController.Instance.LastGUI != GuiFrameID.SettlementFrame); sharelTitle.text = LanguageController.Instance.GetLanguage("Text_20051"); achievementDetailImage.sprite = SkinController.Instance.GetSprite(instance.imageIndex); achievementDetailMainTitle.text = LanguageController.Instance.GetLanguage(instance.mainTitleIndex); achievementDetailSubTitle.text = LanguageController.Instance.GetLanguage(instance.subTitleIndex); achievementDetailFinishTime.text = GetFinishTime(instance.finishTime); bool isTimePattern = instance.cInstance.patternID == PatternID.Time; achievementDetailPattern_Time.SetActive(isTimePattern); achievementDetailPattern_Number.SetActive(!isTimePattern); achievementDetailTime.gameObject.SetActive(isTimePattern); achievementDetailAmount.gameObject.SetActive(!isTimePattern); if (isTimePattern) { int amount = FightController.Instance.GetTimeAmount(instance.cInstance.amountID); achievementDetailTime.text = string.Format(achievementDetailTime.text, amount); } else { int amount = FightController.Instance.GetNumberAmount(instance.cInstance.amountID); achievementDetailAmount.text = string.Format(achievementDetailAmount.text, amount); } string symbol = FightController.Instance.GetSymbol(instance.cInstance.symbolID); achievementDetailSymbol.text = string.Format(achievementDetailSymbol.text, symbol); achievementDetailDigit.text = string.Format(achievementDetailDigit.text, (int)(instance.cInstance.digitID + 2)); achievementDetailOperand.text = string.Format(achievementDetailOperand.text, (int)(instance.cInstance.operandID + 2)); achievementDetailCondition.text = string.Format(achievementDetailCondition.text, instance.accuracy, instance.meanTime); }
protected override void OnButtonClick(Button btn) { base.OnButtonClick(btn); switch (btn.name) { case "ShareBtn": var shareID = GuiController.Instance.LastGUI == GuiFrameID.RankFrame ? ShareID.Rank : ShareID.SaveFile; GameManager.Instance.CurShareInstance = new ShareInstance(shareID); GuiController.Instance.SwitchWrapper(GuiFrameID.ShareFrame, true); break; case "BluetoothShareBtn": GameManager.Instance.CurShareInstance = new ShareInstance(ShareID.Bluetooth); GuiController.Instance.SwitchWrapper(GuiFrameID.ShareFrame, true); break; case "OnlyWrongBtn": case "BluetoothOnlyWrongBtn": onlyWrong = !onlyWrong; RefreshSettlementGrid(); break; case "SaveFileDetailClosedBtn": CommonTool.GuiVerticalMove(saveFileDetailBg, Screen.height, MoveID.LeftOrDown, canvasGroup, false, () => GuiController.Instance.SwitchWrapper(GuiFrameID.None)); break; case "AchievementBtn": AchievementInstance instance = AchievementController.Instance.GetAchievement(content.achievementName); AchievementController.Instance.CurAchievementInstance = instance; GameManager.Instance.CurShareInstance = new ShareInstance(ShareID.Achievement); GuiController.Instance.SwitchWrapper(GuiFrameID.ShareFrame, true); break; case "UploadDataBtn": if (isUploading) { return; } if (string.IsNullOrEmpty(GameManager.Instance.UserName)) { GuiController.Instance.SwitchWrapper(GuiFrameID.NameBoardFrame, true); return; } if (content.isUpload) { string message = LanguageController.Instance.GetLanguage("Text_90008"); GuiController.Instance.CurCommonTipInstance = new CommonTipInstance(CommonTipID.Splash, message); GuiController.Instance.SwitchWrapper(GuiFrameID.CommonTipFrame, true); return; } isUploading = true; WWWForm form = new WWWForm(); form.AddField("userId", GameManager.Instance.UserID); form.AddField("jwttoken", GameManager.Instance.Token); form.AddField("model", (int)content.cInstance.patternID + 1); form.AddField("num", (int)content.cInstance.amountID + 1); form.AddField("calcu", (int)content.cInstance.symbolID + 1); form.AddField("digit", (int)content.cInstance.digitID + 2); form.AddField("operate", (int)content.cInstance.operandID + 2); form.AddField("timelast", RecordController.Instance.FillTimeLast(content)); form.AddField("accuracy", content.accuracy.ToString("f1")); form.AddField("version", GameManager.Instance.Version); content.achievementName = ""; //上传的战绩都没有成就 string data = JsonUtility.ToJson(content); form.AddField("data", data); GameManager.Instance.UploadRecord(form, OnUploadSucceed, OnUploadFail); break; default: MyDebug.LogYellow("Can not find Button: " + btn.name); break; } }
private void RefreshLastestAchievement() { AchievementInstance lastestAchievement = AchievementController.Instance.GetLastestAchievement(); lastestAchievementItem.SendMessage("InitPrefabItem", lastestAchievement); }