public void CollectClick(GameObject from) { List collects = CollectSceen.transform.GetChild(CollectSceen.transform.childCount - 1).GetComponentInChildren <List>(); if (collects.itemCount == 0) { collects.InitList(ConstValue.GetInstance().levelStrings.Count); } else { ListElement[] elements = collects.GetComponentsInChildren <ListElement>(); foreach (var item in elements) { item.UpdateTitle(); //点击界面的时候回更新所有标题 //if (item.RedDot != null && item.RedDot.activeSelf) //{ // from.transform.FindChild("Collect").FindChild("RedDot").gameObject.SetActive(false); //} } } CollectSceen.SetActive(true); from.SetActive(false); OriginGameObject = from; AudioContorller._Instance.PlayAudioOneTimeNotStopLast(6, 0.8f); }
public int PlayerCurrentScore; //玩家当前的分数 void Awake() { _Instance = this; m_TimeLine = PlayScreen.GetComponentInChildren <Scrollbar>(); m_LifeIndicate = PlayScreen.transform.GetChild(PlayScreen.transform.childCount - 1) .GetChild(0).GetComponent <Image>(); //初始化收集列表item List collects = CollectSceen.transform.GetChild(CollectSceen.transform.childCount - 1).GetComponentInChildren <List>(); if (collects.itemCount == 0) { collects.InitList(ConstValue.GetInstance().levelStrings.Count); } m_collects = collects; foreach (var item in collects.GetComponentsInChildren <ListElement>()) { if (item.RedDot.activeSelf) { MainScreenRedDot.SetActive(true); GameOverScreenRedDot.SetActive(true); break; } } if (PlayerPrefs.GetString("ShowMainCollect") == "true") { MainScreen.transform.FindChild("Collect").gameObject.SetActive(true); } }
public void UpdatePlayerCharacter(int big, int small) { char[] words = PlayerPrefs.GetString(ConstValue.GetInstance().levelStrings[big]).ToCharArray(); for (int i = 0; i < words.Length; i++) { if (words[i] != '1') { break; } else if (i == words.Length - 1) { return; //这个词条已经被收集过了 } } for (int i = 0; i < words.Length; i++) { if (i == small && words[i] != '1') { words[i] = '1'; //正确收集到的字符标注为1,没有收集到的标注为0 } } PlayerPrefs.SetString(ConstValue.GetInstance().levelStrings[big], new string(words)); //收集情况 string result = PlayerPrefs.GetString(ConstValue.GetInstance().levelStrings[big]); if (IsAllStringRight(result)) { //展示收集完成的奖励窗口 UIController._Instance.CollectedSuccess(ConstValue.GetInstance().levelStrings[big]); UIController._Instance.ShowRedDot(big); //收集完成的红点 } }
public void UpdateTitle() //更新局部标题 { char[] title = PlayerPrefs.GetString(ConstValue.GetInstance().levelStrings[m_WordIndex]).ToCharArray(); char[] words = ConstValue.GetInstance().levelStrings[m_WordIndex].ToCharArray(); m_StringBuilder.Remove(0, m_StringBuilder.Length); for (int i = 0; i < title.Length; i++) { if (title[i] == '1') { m_StringBuilder.Append(words[i]); } else { m_StringBuilder.Append('?'); } } m_Content.text = m_StringBuilder.ToString(); if (m_Content.transform.childCount == 0) { for (int i = 0; i < title.Length; i++) { GameObject m_word = Instantiate(WordInstance); m_word.transform.SetParent(m_Content.transform); } } for (int i = 0; i < m_Content.transform.childCount; i++) { m_Content.transform.GetChild(i).GetChild(0).GetComponent <Text>().text = m_StringBuilder[i] == '?' ? "" : m_StringBuilder[i].ToString(); } }
public void GameNextLevel() //成功之后升级 abolish { Camera.main.GetComponent <CameraController>().CorrectPosition(); int wordCount = Random.Range(2, 5); map.InitMap(CenterCube.transform.position, wordCount, false); //多少个字多少个轨道 CenterCube.ReStartAnimation(); UpdateCenterLevelString(ConstValue.GetInstance().GetCharacter(wordCount)); }
/// <summary> /// 获取在给定词条内未被收集到的汉字序号 /// </summary> /// <param name="big"></param> /// <returns></returns> public List <int> GetZeroWordInCharacter(int big) { List <int> result = new List <int>(); char[] words = PlayerPrefs.GetString(ConstValue.GetInstance().levelStrings[big]).ToCharArray(); for (int i = 0; i < words.Length; i++) { if (words[i] == '0') { result.Add(i); } } return(result); }
public void ElementClick() //展开收藏列表 //if (PlayerPrefs.GetString(ConstValue.GetInstance().levelStrings[m_WordIndex]) != "1111") //完成收集 //{ // return; //} { if (!PlayerData.GetInstance().IsAllStringRight(PlayerPrefs.GetString(ConstValue.GetInstance().levelStrings[m_WordIndex]))) { return; } if (!IsElementExpand) { AudioContorller._Instance.PlayAudioOneTimeNotStopLast(7, 0.8f); //m_RectTransform.sizeDelta = new Vector2(mRect.width, mRect.height + 300f); m_RectTransform.DOSizeDelta(new Vector2(mOriginRect.width, mOriginRect.height + 540f), 0.5f).SetUpdate(true); IsElementExpand = true; //BuildContent(SealCharacter, ConstValue.GetInstance().levelStrings[m_WordIndex]); //BuildContent(Simplified, ConstValue.GetInstance().levelStrings[m_WordIndex]); BuildContent(SealCharacter, WordInstanceSeal, ConstValue.GetInstance().levelStrings[m_WordIndex]); BuildContent(Simplified, WordInstance, ConstValue.GetInstance().levelStrings[m_WordIndex]); BuildContent(English, ConstValue.GetInstance().levelEngLishStrings[m_WordIndex]); //content.DOColor(Color.white, 0.5f); //content.gameObject.SetActive(false); content.transform.DOScale(Vector3.zero, 0.3f).SetUpdate(true); transform.parent.GetComponent <List>().ExpandList(540f); if (RedDot != null && RedDot.activeSelf) { PlayerPrefs.SetString("Number" + m_WordIndex.ToString(), "false"); RedDot.SetActive(false); } } else { //m_RectTransform.sizeDelta = new Vector2(mRect.width, mOriginRect.height); ToShrinkElement(); AudioContorller._Instance.PlayAudioOneTimeNotStopLast(8, 0.8f); } }
public void InitMap(Vector3 centerPointPos, int RoadCount, bool IsBuildCenterCube) { centerPoint = centerPointPos; Tools._Instance.ScreenSize(); if (IsBuildCenterCube) { GameObject center = Instantiate(GameController._Instance.CenterCubeInstance, centerPointPos, Quaternion.identity); GameController._Instance.CenterCube = center.GetComponent <CenterCube>(); if (!PlayerData.GetInstance().IsAllStringRight(PlayerPrefs.GetString(ConstValue.GetInstance().levelStrings[0]))) //第一个词条没有收集完成 { if (PlayerPrefs.GetInt(ConstValue.XmlDataKeyName.PlayerInGameSuccessCount) < 2) { RoadCount = 1; GameController._Instance .UpdateCenterLevelString(ConstValue.GetInstance().GetCharacter(0 , ConstValue.GetInstance(). GetZeroWordInCharacter(0)[Random.Range(0, ConstValue.GetInstance().GetZeroWordInCharacter(0).Count)] )); } else { RoadCount = ConstValue.GetInstance().GetZeroWordInCharacter(0).Count; GameController._Instance .UpdateCenterLevelString(ConstValue.GetInstance().GetCharacter(0 , ConstValue.GetInstance().GetZeroWordInCharacter(0).ToArray() )); } } else { GameController._Instance.UpdateCenterLevelString(ConstValue.GetInstance().GetCharacter(RoadCount)); //这里可以随机给定的 } } if (finalRoad != null) { finalRoad.Clear(); UpRoad.Clear(); DownRoad.Clear(); LeftRoad.Clear(); RightRoad.Clear(); UpRoadInstance.Clear(); DownRoadInstance.Clear(); LeftRoadInstance.Clear(); RightRoadInstance.Clear(); } Vector3 farsetPointUp = centerPoint + RoadLength * (new Vector3(0f, MapPointSize, 0f)); Vector3 farsetPointDown = centerPoint + RoadLength * (new Vector3(0f, -MapPointSize, 0f)); Vector3 farsetPointLeft = centerPoint + RoadLength * (new Vector3(-MapPointSize, 0f, 0f)); Vector3 farsetPointRight = centerPoint + RoadLength * (new Vector3(MapPointSize, 0f, 0f)); Dictionary <int, List <Vector3> > roads = BuildRoadIndex(RoadCount); for (int i = 0; i < RoadLength; i++) { //UpRoad.Add(farsetPointUp - new Vector3(0f, MapPointSize, 0f) * i); //DownRoad.Add(farsetPointDown + new Vector3(0f, MapPointSize, 0f) * i); //LeftRoad.Add(farsetPointLeft + new Vector3(MapPointSize, 0f, 0f) * i); //RightRoad.Add(farsetPointRight - new Vector3(MapPointSize, 0f, 0f) * i); foreach (var item in roads.Keys) //对随机出的路 配置路径点 { switch (item) { case 0: //上 roads[item].Add(farsetPointUp - new Vector3(0f, MapPointSize, 0f) * i); break; case 1: //下 roads[item].Add(farsetPointDown + new Vector3(0f, MapPointSize, 0f) * i); break; case 2: //左 roads[item].Add(farsetPointLeft + new Vector3(MapPointSize, 0f, 0f) * i); break; case 3: //右 roads[item].Add(farsetPointRight - new Vector3(MapPointSize, 0f, 0f) * i); break; default: break; } } } finalRoad = roads; hadBuildLength = -1; }
// Update is called once per frame void Update() { if (CurrentGameState == GameState.GamePlaying) { // Vector2 clickPoint = Vector2.zero; //#if UNITY_EDITOR // if (Input.GetMouseButtonDown(1)) // { // clickPoint = Input.mousePosition; // } //#else // if (Input.touchCount == 1) { // clickPoint = Input.touches[0].position; // } //#endif // Ray ray = Camera.main.ScreenPointToRay(clickPoint); // RaycastHit2D hit2D = Physics2D.Raycast(ray.origin, ray.direction,100,1 << LayerMask.NameToLayer(ConstValue.LayerName.MAP)); // if (hit2D.collider != null) // { // Operation(hit2D); // } if (PlayerPrefs.GetInt(ConstValue.XmlDataKeyName.PlayerInGameSuccessCount) > 0 && //玩家顺利通过第一关 !UIController._Instance.UpdateGameTimeLine(-GameTimeLineSpeed * Time.deltaTime)) { GameOver(); } //第二种玩法 if (Input.GetMouseButtonDown(0) && !CenterCube.IsRotating) { Vector2 clickPoint = Vector2.zero; #if UNITY_EDITOR clickPoint = Input.mousePosition; #else if (Input.touchCount == 1) { clickPoint = Input.touches[0].position; } #endif clickPoint = Camera.main.ScreenToWorldPoint(clickPoint); if (clickPoint.y < Tools._Instance.topBorder - Tools._Instance.height * (1f / 7f)) { if (clickPoint.x >= Tools._Instance.leftBorder + Tools._Instance.width / 2f) { CenterCube.RotateSelf(+1); } else { CenterCube.RotateSelf(-1); } AudioContorller._Instance.PlayAudioOneTimeNotStopLast(9, 0.65f); //音效 } } } if (CurrentGameState == GameState.GameCheck && !CenterCube.IsRotating && currentMoveCube != null) { if (currentMoveCube.GetComponent <MoveCube>().IsArrive) { Check center = CenterCube.GetComponent <Check>(); if (!IsRightResult(CenterCube.transform, currentMoveCube.transform)) { //GameOver(); GameReLevel(); GameStart(); AudioContorller._Instance.PlayAudioOneTimeNotStopLast(4, 1f); //音效 } else { UIController._Instance.PlayerCurrentScore++; AudioContorller._Instance.PlayAudioOneTimeNotStopLast(3, 1f); //音效 if (PlayerPrefs.GetInt(ConstValue.XmlDataKeyName.PlayerBestScore) == 0) { PlayerPrefs.SetInt(ConstValue.XmlDataKeyName.PlayerBestScore, UIController._Instance.PlayerCurrentScore); } else if (PlayerPrefs.GetInt(ConstValue.XmlDataKeyName.PlayerBestScore) < UIController._Instance.PlayerCurrentScore) { PlayerPrefs.SetInt(ConstValue.XmlDataKeyName.PlayerBestScore, UIController._Instance.PlayerCurrentScore); } UIController._Instance.UpdateGameTimeLine(GameTimeLineSpeed * 2f); //for (int i = 0; i < center.innerCheck.Count; i++) //{ // if (!center.innerCheck[i].HaveCheck) // { // break; // } // if (i == center.innerCheck.Count - 1) //四个数字全队 // { // //LevelUp // CurrentGameState = GameState.GameLeveling; //游戏进入升级状态 // GameRightRoundCount++; //这个数值需要持久化 // GameRightRoundCount %= 3; // //UpdateCenterLevelString(ConstValue.GetInstance().levelStrings[GameRightRoundCount]); // //BuildMoveCube(); // //全部正确之后初始化新的背景 和 文字 在此处插入对背景和移动方块的颜色控制 // StartCoroutine(ScenesController._Instance // .DestroyScenes(new Color(Random.Range(0f,1f),Random.Range(0f,1f),Random.Range(0f,1f)))); // } //} if (center.IsFinishLevel()) { //LevelUp CurrentGameState = GameState.GameLeveling; //游戏进入升级状态 if (!PlayerData.GetInstance().IsAllStringRight(ConstValue.GetInstance().levelStrings[0])) //第一个词条没有收集完成 { if (PlayerPrefs.GetInt(ConstValue.XmlDataKeyName.PlayerInGameSuccessCount) != 0) { GameRightRoundCount = PlayerPrefs.GetInt(ConstValue.XmlDataKeyName.PlayerInGameSuccessCount); } GameRightRoundCount++; //这个数值需要持久化 PlayerPrefs.SetInt(ConstValue.XmlDataKeyName.PlayerInGameSuccessCount, GameRightRoundCount); //更新用户数据 } //UpdateCenterLevelString(ConstValue.GetInstance().levelStrings[GameRightRoundCount]); //BuildMoveCube(); //全部正确之后初始化新的背景 和 文字 在此处插入对背景和移动方块的颜色控制 //StartCoroutine(ScenesController._Instance // .DestroyScenes(new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f)))); center.GetComponent <Check>().RightWordEffect(); StartCoroutine(StartNextLevel(0.45f)); } else { center.GetComponent <Check>().RightWordEffect(); GameStart(); } } } } }