void SwitchCategory(Globals.Categories cat) { if (currState != Globals.MainMenu.Dialog && currState != Globals.MainMenu.Dialog) { categoriesPanel.SetActive(false); previousType = type; type = cat; for (int xx = 0; xx < categories.Count; xx++) { if (categories [xx].type == previousType) { for (int yy = 0; yy < categories [xx].buttons.Count; yy++) { categories [xx].buttons [yy].gameObject.SetActive(false); categories [xx].buttons [yy].transform.SetParent(null); } } } for (int xx = 0; xx < categories.Count; xx++) { if (categories [xx].type == type) { for (int yy = 0; yy < categories [xx].buttons.Count; yy++) { categories [xx].buttons [yy].gameObject.SetActive(true); categories [xx].buttons [yy].transform.SetParent(spritePanel.transform); } } } spritePanel.SetActive(true); LayoutRebuilder.MarkLayoutForRebuild(spritePanel.GetComponent <RectTransform> ()); lastState = currState; currState = Globals.MainMenu.Sprites; } }
public void AssignCategory(string type) { System.Array typeNums = System.Enum.GetValues(typeof(Globals.Categories)); Globals.Categories[] types = new Globals.Categories[typeNums.Length]; System.Array.Copy(typeNums, types, typeNums.Length); Globals.Categories theEnum = Globals.Categories.Misc; for (int xx = 0; xx < types.Length; xx++) { if (type == types[xx].ToString()) { theEnum = types[xx]; break; } } dataObjects [currIndex].type = theEnum; UnityEditor.AssetDatabase.Refresh(); UnityEditor.EditorUtility.SetDirty(dataObjects[currIndex]); UnityEditor.AssetDatabase.SaveAssets(); currIndex++; if (currIndex < dataObjects.Length) { texObj.GetComponent <MeshRenderer> ().material.mainTexture = dataObjects [currIndex].thumb; } }
IEnumerator InitializeData() { yield return(null); Object[] sprites = Resources.LoadAll("Sprite Objects", typeof(SpriteData)); List <SpriteButton> allButtons = new List <SpriteButton> (); for (int xx = 0; xx < sprites.Length; xx++) { SpriteButton newButton = Instantiate(spriteButton); newButton.data = sprites [xx] as SpriteData; allButtons.Add(newButton); if (File.Exists(Application.persistentDataPath + "/LevelData/" + newButton.data.myName + ".lev")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/LevelData/" + newButton.data.myName + ".lev", FileMode.Open); ProgressData dat = (ProgressData)bf.Deserialize(file); file.Close(); newButton.progress = dat; } if (File.Exists(Application.persistentDataPath + "/Thumbs/" + newButton.data.myName + ".png")) { byte[] imageData = File.ReadAllBytes(Application.persistentDataPath + "/Thumbs/" + newButton.data.myName + ".png"); Texture2D newTex = new Texture2D(0, 0); newTex.LoadImage(imageData); newTex.filterMode = FilterMode.Point; newTex.wrapMode = TextureWrapMode.Clamp; newTex.Apply(); newButton.myCol.sprite = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 100); } else { newButton.myCol.sprite = Sprite.Create(newButton.data.thumb, new Rect(0, 0, newButton.data.thumb.width, newButton.data.thumb.height), Vector2.zero, 100); } newButton.myButton.onClick.AddListener(delegate { LoadLevel(newButton); }); } System.Array typeNums = System.Enum.GetValues(typeof(Globals.Categories)); Globals.Categories[] types = new Globals.Categories[typeNums.Length]; System.Array.Copy(typeNums, types, typeNums.Length); for (int xx = 0; xx < types.Length; xx++) { Globals.CategoryCollection coll = new Globals.CategoryCollection(); coll.buttons = new List <SpriteButton> (); coll.type = types [xx]; for (int yy = 0; yy < allButtons.Count; yy++) { if (coll.type != Globals.Categories.Started && coll.type != Globals.Categories.Completed) { if (allButtons [yy].data.type == types [xx]) { if (allButtons [yy].progress == null) { coll.buttons.Add(allButtons [yy]); } else if (!allButtons [yy].progress.started && !allButtons [yy].progress.completed) { coll.buttons.Add(allButtons [yy]); } } } else { if (coll.type == Globals.Categories.Completed) { if (allButtons [yy].progress != null) { if (allButtons [yy].progress.completed) { coll.buttons.Add(allButtons [yy]); } } } else if (coll.type == Globals.Categories.Started) { if (allButtons [yy].progress != null) { if (!allButtons [yy].progress.completed) { if (allButtons [yy].progress.started) { coll.buttons.Add(allButtons [yy]); } } } } } } coll.buttons = SortByDifficulty(true, coll.buttons); categories.Add(coll); } LayoutRebuilder.MarkLayoutForRebuild(spritePanel.GetComponent <RectTransform> ()); initialized = true; state = Globals.MainLoadState.InitialUnlock; }