using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; using Newtonsoft.Json.Linq; public class PersonalPlayGameInfo { public string scoreType; public int playTime; public int currentGameType; } public class PersonalView : MonoBehaviour, MenuBackInterface { [SerializeField] Transform panelLeftContent; [SerializeField] GameObject gameRecordItem; [SerializeField] GameObject gameRecordContent; void Start() { PersistenHandler.ins?.menuBackCtr.views.Add(this); RenderUserInfo(); getPlayTimeByGameType(); ShowBoxPersonalProfile(true); //ShowBoxUserSettings(true); } void OnDestroy() { PersistenHandler.ins?.menuBackCtr.views.Remove(this); } public bool OnMenuBack() { ViewManager2.HideView(ViewManager2.Path_PersonalView); return true; } public void OnClick_PanelLeftItem(Transform target) { foreach (Transform item in panelLeftContent) { if (item == target) { item.Find("Text").GetComponent().fontStyle = FontStyle.Bold; item.Find("Text").GetComponent().color = Color.white; bool oldActive = item.Find("LightMask").gameObject.activeSelf; item.Find("LightMask").gameObject.SetActive(true); item.Find("IconOn").GetComponent().enabled = true; item.Find("IconOn/IconOff").GetComponent().enabled = false; if (!oldActive) { AudioMgr.ins.PlayBtn(); ShowBox(item.name); } } else { item.Find("Text").GetComponent().fontStyle = FontStyle.Normal; item.Find("Text").GetComponent().color = Color.gray; item.Find("LightMask").gameObject.SetActive(false); item.Find("IconOn").GetComponent().enabled = false; item.Find("IconOn/IconOff").GetComponent().enabled = true; } } } void ShowBox(string itemName) { ShowBoxPersonalProfile(itemName == "BtnPersonalProfile"); ShowBoxUserSettings(itemName == "BtnUserSettings"); } void ShowBoxPersonalProfile(bool show) { transform.Find("PanelContent/BoxPersonalProfile").gameObject.SetActive(show); } void ShowBoxUserSettings(bool show) { transform.Find("PanelContent/BoxUserSettings").gameObject.SetActive(show); } public void ShowModalDeleteAccount(bool show) { transform.Find("ModalDeleteAccount").gameObject.SetActive(show); } public void NotifyUserInfoRefresh() { RenderUserInfo(); HomeView.ins.RenderNameOrGender(); HomeView.ins.RenderMyAvatarSprite(); } void RenderUserInfo() { Transform userTitle = transform.Find("PanelLeft/UserTitle"); Image avatarImage = userTitle.Find("Avatar/Sprite").GetComponent(); RoleMgr.SetAvatarToImage(avatarImage, LoginMgr.myUserInfo.avatarID, LoginMgr.myUserInfo.avatarUrl); //userTitle.Find("Text").GetComponent().text = LoginMgr.myUserInfo.nickname; // + "’s Page" var tal = userTitle.Find("Text").gameObject.AddComponent(); tal.textFormatArgs = new object[] { LoginMgr.myUserInfo.nickname }; tal.SetTextKey("Personal_LeftName"); BoxPersonalProfile _BoxPersonalProfile = transform.Find("PanelContent/BoxPersonalProfile").GetComponent(); _BoxPersonalProfile.setProfileUserInfo(avatarImage.sprite, LoginMgr.myUserInfo.nickname, LoginMgr.myUserInfo.id); } public void OnClick_DeleteAccount() { AudioMgr.ins.PlayBtn(); ShowModalDeleteAccount(true); } public void OnClick_Back() { AudioMgr.ins.PlayBtn(); ViewManager2.HideView(ViewManager2.Path_PersonalView); } void getPlayTimeByGameType() { System.Action cb = delegate (JArray result) { //Debug.Log(result); //处理分数叠加的情况 List personalPlayGameInfos = new List(); foreach (var itemInfo in result) { string scoreType = ""; int currentGameType = -1; // 选一个 gameType用以查询数据 int time = itemInfo.Value("totalDuration"); int gameType = itemInfo.Value("gameType"); //Debug.Log(gameType+" = " + time); switch (gameType) { case 1: //静止靶 (单人) case 2: //静止靶 (本地PK) case 9: //静止靶 (联机PK) scoreType = "OlynpicArchery"; currentGameType = 1; break; case 3://兔子关卡 (单人) case 6://兔子关卡 (本地PK) case 10://兔子关卡 (联机PK) scoreType = "HareHunt"; currentGameType = 3; break; case 4: //野鸡关卡 (单人) case 7: //野鸡关卡 (本地PK) case 11://野鸡关卡 (联机PK) scoreType = "PheasuntHunt"; currentGameType = 4; break; case 5: //野狼关卡 (单人) case 8: //野狼关卡 (本地PK) case 12://野狼关卡 (联机PK) scoreType = "WolfHunt"; currentGameType = 5; break; case 13: //野鸭关卡 (单人) scoreType = "LevelDuckHunter"; currentGameType = 13; break; case 14: //荒野射击 (单人) scoreType = "LevelWildAttack"; currentGameType = 14; break; case 15: //水果达人 (单人) scoreType = "FruitExpert"; currentGameType = 15; break; } if (scoreType != "") { bool bCanAdd = true; foreach (PersonalPlayGameInfo _item in personalPlayGameInfos) { if (_item.scoreType == scoreType) { _item.playTime += time; bCanAdd = false; } } if (bCanAdd) { PersonalPlayGameInfo PersonalPlayGameInfo = new PersonalPlayGameInfo(); PersonalPlayGameInfo.playTime = time; PersonalPlayGameInfo.scoreType = scoreType; PersonalPlayGameInfo.currentGameType = currentGameType; personalPlayGameInfos.Add(PersonalPlayGameInfo); } } } foreach (var itemInfo in personalPlayGameInfos) { int gameType = itemInfo.currentGameType; if (gameType == -1) continue; //int time = itemInfo.Value("totalDuration"); //int gameType = itemInfo.Value("gameType"); int time = itemInfo.playTime; int hour = time / 3600; int minute = (time - hour * 3600) / 60; if (minute < 0) minute = 0; int second = time % 60; if (second < 0) second = 0; //Debug.Log(" = " + time); GameObject o = Instantiate(gameRecordItem, gameRecordContent.transform); o.SetActive(true); //o.transform.Find("time/Text").GetComponent().text = string.Format("{0} h {1} m {2} s",hour,minute,second); var tal = o.transform.Find("time/Text").GetComponent(); tal.textFormatArgs = new object[] { hour, minute, second }; tal.SetTextKey("Personal_RecordTime2"); Transform _name = o.transform.Find("name/Label"); Transform _sprite = o.transform.Find("Icon/Sprite"); GameInfo gameInfo = TextureMgr.ins.GetGameInfos(gameType); //_name.GetComponent().text = gameInfo.name; _name.gameObject.AddComponent().SetTextKey(gameInfo.textId); Sprite texSprite = Sprite.Create(gameInfo.texture2D, new Rect(0, 0, gameInfo.texture2D.width, gameInfo.texture2D.height), new Vector2(0.5f, 0.5f)); _sprite.GetComponent().sprite = texSprite; } }; UserPlayer.ins.call("UserGameAnalyseComp.getUserGamePlayTime", null, cb); } }