public static void ClearUserDataByPrefs() { PlayerPrefs.SetInt("loading_mail", 0); //清理方式是新建一个新类,实际是清理了数据,而没有清理内存 Class4Save o = new Class4Save(); PlayerPrefsExtend.Clear("loginData", o); }
protected override void Init() { bool useTunningVars = PlayerPrefsExtend.GetBool("useTunningVars", SaveVar); SaveVar = useTunningVars; if (TunningManager.UseTunningVars) { LoadVarsPrivate(); } }
public static void SaveUserDataByPrefs(Class4Save userData) { PlayerPrefsExtend.Save("loginData", userData); }
public static Class4Save LoadUserDataByPrefs() { return(PlayerPrefsExtend.GetValue <Class4Save>("loginData")); }
public override void OnCreate() { base.OnCreate(); m_newStageNumber = -1; m_heartUI = UIWindowManager.Singleton.CreateWindow <UIWindow>("UIMapHeart", UIWindowManager.Anchor.TopLeft); m_backGroundTrans = mUIObject.transform; m_stageBtns = new Transform[GlobalVars.TotalStageCount]; m_stageNumbers = new Transform[GlobalVars.TotalStageCount]; GlobalVars.AvailabeStageCount = PlayerPrefs.GetInt("StageAvailableCount"); GlobalVars.HeadStagePos = PlayerPrefs.GetInt("HeadStagePos"); if (GlobalVars.AvailabeStageCount == 0) { GlobalVars.AvailabeStageCount = 1; } if (GlobalVars.AvailabeStageCount > GlobalVars.TotalStageCount) { GlobalVars.AvailabeStageCount = GlobalVars.TotalStageCount; } if (GlobalVars.HeadStagePos > GlobalVars.TotalStageCount) { GlobalVars.HeadStagePos = GlobalVars.TotalStageCount; } if (GlobalVars.HeadStagePos == 0) { GlobalVars.HeadStagePos = 1; } GlobalVars.StageStarArray = PlayerPrefsExtend.GetIntArray("StageStars", 0, 100); GlobalVars.StageScoreArray = PlayerPrefsExtend.GetIntArray("StageScores", 0, 100); GlobalVars.StageFailedArray = PlayerPrefsExtend.GetIntArray("StageFailed", 0, 100); GlobalVars.LastStage = GlobalVars.AvailabeStageCount; if (!PlayerPrefs.HasKey("Coins")) { GlobalVars.Coins = 10; PlayerPrefs.SetInt("Coins", 0); } else { GlobalVars.Coins = PlayerPrefs.GetInt("Coins"); } GlobalVars.PurchasedItemArray = PlayerPrefsExtend.GetIntArray("PurchasedItemArray", 0, 2); m_mapObj = mUIObject.transform.FindChild("MapObj").gameObject; springPanel = m_mapObj.AddComponent <SpringPanel>(); springPanel.strength = 1000; UIPanel panel = m_mapObj.GetComponent <UIPanel>(); //panel.baseClipRegion = new Vector4(0, 0, CapsApplication.Singleton.Width, CapsApplication.Singleton.Height); //心面板 m_timeNumber = UIToolkits.FindChild(m_heartUI.mUIObject.transform, "TimeNumber").gameObject; m_minNumber = m_heartUI.GetChildComponent <NumberDrawer>("MinNumber"); m_secNumber = m_heartUI.GetChildComponent <NumberDrawer>("SecNumber"); UIButton heartBtn = m_heartUI.GetChildComponent <UIButton>("HeartBtn"); EventDelegate.Set(heartBtn.onClick, delegate() { if (GlobalVars.HeartCount == 5) { return; } if (GlobalVars.UseSFX) { NGUITools.PlaySound(CapsConfig.CurAudioList.ButtonClip); } UINoMoreHearts noMoreHeartUI = UIWindowManager.Singleton.GetUIWindow <UINoMoreHearts>(); UIStageInfo stageInfoUI = UIWindowManager.Singleton.GetUIWindow <UIStageInfo>(); if (stageInfoUI.Visible) { stageInfoUI.HideWindow(); } noMoreHeartUI.NeedOpenStageInfoAfterClose = false; noMoreHeartUI.ShowWindow(); }); //金币面板 m_coinNumber = m_heartUI.GetChildComponent <NumberDrawer>("MoneyNumber"); UIButton button = m_heartUI.GetChildComponent <UIButton>("StoreBtn"); EventDelegate.Set(button.onClick, delegate() { if (GlobalVars.UseSFX) { NGUITools.PlaySound(CapsConfig.CurAudioList.ButtonClip); } UIStore storeUI = UIWindowManager.Singleton.GetUIWindow <UIStore>(); UIStageInfo stageInfoUI = UIWindowManager.Singleton.GetUIWindow <UIStageInfo>(); if (stageInfoUI.Visible) { stageInfoUI.HideWindow(); GlobalVars.OnCancelFunc = delegate() { stageInfoUI.ShowWindow(); }; GlobalVars.OnPurchaseFunc = delegate() { stageInfoUI.ShowWindow(); }; } storeUI.ShowWindow(); } ); m_headSprite = GetChildComponent <UISprite>("Head"); GameObject obj = GameObject.Find("Cloud"); m_cloudSprite = obj.GetComponent <UISprite>(); m_cloudSprite.gameObject.SetActive(false); obj = GameObject.Find("Cloud2"); m_cloud2Sprite = obj.GetComponent <UISprite>(); m_cloud2Sprite.gameObject.SetActive(false); m_inputBlocker = mUIObject.transform.Find("Blocker").gameObject; m_stageUI = UIWindowManager.Singleton.GetUIWindow <UIStageInfo>(); for (int i = 0; i < 3; ++i) { m_blurSprites[i] = UIToolkits.FindChild(mUIObject.transform, "MapPicBlur" + i).gameObject; m_blurSprites[i].SetActive(false); } for (int i = 0; i < GlobalVars.TotalStageCount; ++i) { Transform transform = UIToolkits.FindChild(mUIObject.transform, "Stage" + (i + 1)); //找到对象 if (transform == null) { Debug.LogError("There's no " + "Stage" + (i + 1).ToString() + " Button"); continue; } m_stageBtns[i] = transform; m_stageNumbers[i] = transform.FindChild("StageNumber"); } }
public void RefreshData() { if (GameLogic.Singleton.IsStageFinish() && GameLogic.Singleton.CheckGetEnoughScore()) //检查关卡是否结束 { m_bWin = true; } else { m_bWin = false; if (GlobalVars.CurStageData.Target == GameTarget.ClearJelly) { m_infoLabel.text = Localization.instance.Get("DidNotClearIce"); } else if (GlobalVars.CurStageData.Target == GameTarget.BringFruitDown) { m_infoLabel.text = Localization.instance.Get("DidNotBringNuts"); } else if (GlobalVars.CurStageData.Target == GameTarget.Collect) { m_infoLabel.text = Localization.instance.Get("DidNotCollectEnough"); } else if (GlobalVars.CurStageData.Target == GameTarget.GetScore) //分数要求的情况 { m_infoLabel.text = Localization.instance.Get("NotEnoughScore"); } else { m_infoLabel.text = Localization.instance.Get("EndGameByHimSelf"); } } if (m_bWin) { GlobalVars.AddHeart(1); //若关卡成功,需要把之前扣的心恢复回来 } if (m_bWin) { if (GlobalVars.AvailabeStageCount == GlobalVars.CurStageNum) { if (GlobalVars.AvailabeStageCount < GlobalVars.TotalStageCount) { ++GlobalVars.AvailabeStageCount; //开启下一关 } //UIWindowManager.Singleton.GetUIWindow<UIMap>().OpenNewButton(GlobalVars.AvailabeStageCount); } for (int i = 2; i >= 0; --i) { if (GameLogic.Singleton.GetProgress() >= GlobalVars.CurStageData.StarScore[i]) { m_starCount = i + 1; break; } } if (GlobalVars.StageStarArray[GlobalVars.CurStageNum] == 0) //if it's the first time of finishing the stage { float scorePercent = (float)GameLogic.Singleton.GetProgress() / GameLogic.Singleton.PlayingStageData.StarScore[0]; if (CapsConfig.EnableGA) //游戏过关后的记录 { GA.API.Design.NewEvent("Stage" + GlobalVars.CurStageNum + ":FirstSucceed:StepLeft", GameLogic.Singleton.m_stepCountWhenReachTarget); // GA.API.Design.NewEvent("Stage" + GlobalVars.CurStageNum + ":FirstSucceed:Score_Percent", scorePercent); //记录当前开始的关卡的百分比 GA.API.Design.NewEvent("Stage" + GlobalVars.CurStageNum + ":FirstSucceed:StarCount", m_starCount); GA.API.Design.NewEvent("Stage" + GlobalVars.CurStageNum + ":FirstSucceed:FailedTimes", GlobalVars.StageFailedArray[GlobalVars.CurStageNum]); GA.API.Design.NewEvent("Stage" + GlobalVars.CurStageNum + ":FirstSucceed:PlayTime", GameLogic.Singleton.GetStagePlayTime()); } #if UNITY_ANDROID || UNITY_IPHONE if (CapsConfig.EnableTalkingData) { Dictionary <string, object> param = new Dictionary <string, object>(); if (GameLogic.Singleton.m_stepCountWhenReachTarget > 10) { param["StepLeft"] = ">10"; } else if (GameLogic.Singleton.m_stepCountWhenReachTarget > 5) { param["StepLeft"] = ">5"; } else { param["StepLeft"] = GameLogic.Singleton.m_stepCountWhenReachTarget.ToString(); } param["StarCount"] = m_starCount.ToString(); if (scorePercent > 5) { param["ScorePercent"] = ">5"; } else if (scorePercent > 3) { param["ScorePercent"] = ">3"; } else if (scorePercent > 2) { param["ScorePercent"] = ">2"; } else if (scorePercent > 1.5) { param["ScorePercent"] = ">1.5"; } else { param["ScorePercent"] = ">1"; } float playTime = GameLogic.Singleton.GetStagePlayTime(); if (playTime > 600) { param["PlayTime"] = ">10min"; } else if (playTime > 60) { param["PlayTime"] = ((int)(playTime / 60)).ToString() + "min"; } else { param["PlayTime"] = "<1min"; } int failedTimes = GlobalVars.StageFailedArray[GlobalVars.CurStageNum]; if (failedTimes > 20) { param["FailedTime"] = ">20"; } else if (failedTimes > 10) { param["PlayTime"] = ">10"; } else if (failedTimes > 5) { param["PlayTime"] = ">5"; } else { param["PlayTime"] = failedTimes.ToString(); } TalkingDataPlugin.TrackEventWithParameters("Stage" + GlobalVars.CurStageNum + ":FirstSucceed", "", param); } #endif } PlayerPrefs.SetInt("StageAvailableCount", GlobalVars.AvailabeStageCount); //保存进度 if (m_starCount > GlobalVars.StageStarArray[GlobalVars.CurStageNum - 1]) { GlobalVars.StageStarArray[GlobalVars.CurStageNum - 1] = m_starCount; //保存星数 PlayerPrefsExtend.SetIntArray("StageStars", GlobalVars.StageStarArray); //保存进度 } if (GameLogic.Singleton.GetProgress() > GlobalVars.StageScoreArray[GlobalVars.CurStageNum - 1]) //记录分数记录 { GlobalVars.StageScoreArray[GlobalVars.CurStageNum - 1] = GameLogic.Singleton.GetProgress(); PlayerPrefsExtend.SetIntArray("StageScores", GlobalVars.StageScoreArray); } UIWindowManager.Singleton.GetUIWindow <UIMap>().RefreshButtonStar(GlobalVars.CurStageNum); //刷新当前关卡的星星 UIWindowManager.Singleton.GetUIWindow <UIMap>().RefreshButton(GlobalVars.CurStageNum - 1); //刷新当前关卡的星星 } else { GlobalVars.StageFailedArray[GlobalVars.CurStageNum]++; PlayerPrefsExtend.SetIntArray("StageFailed", GlobalVars.StageFailedArray); } m_levelLabel.SetNumberRapid(GlobalVars.CurStageNum); }