void LoadHeroesButtons() { selectedClass = (GameClasses)Enum.GetValues(typeof(GameClasses)).GetValue(Random.Range(0, 6)); Account.CurrentAccount.AddNewHero(new Hero() { Class = selectedClass, Gender = true, State = HeroState.NotCreated }); Account.CurrentAccount.SetCurrentHero(Account.CurrentAccount.ListOfHeroes.Count - 1); #region ClassButtons var classesArray = new[] { "Barbarian", "Crusader", "Demon Hunter", "Monk", "Witch Doctor", "Wizard" }; for (int i = 0; i < classesArray.Length; i++) { if (!gameObject.transform.FindChild(string.Format("{0}Button", classesArray[i]))) { var button = StaticScripts.CreateGameObj(string.Format("{0}Button", classesArray[i]), @"Buttons/BattleNetButton_ClearUp_397x66", new Vector3(0.65f, 0.85f), new Vector3(-8.3f, 1.9f - 0.59f * i, 10f), true, 1, true, typeof(CreateCharacterClassMouseEvents), child: true, parentName: "CharacterCreationSceneObject"); button.GetComponent <ButtonBaseMouseEvents>()._State = selectedClass.ToString() == classesArray[i].Replace(" ", string.Empty) ? ButtonState.Selected : ButtonState.Up; var text = StaticScripts.CreateTextObj(string.Format("{0}ButtonText", classesArray[i]), classesArray[i], new Vector3(0.02f, 0.02f), new Vector3(0f, 0f, 0f), FontType.DiabloFont, 100, new Color32(243, 170, 85, 255), TextAlignment.Center, child: true, parentName: string.Format("{0}Button", classesArray[i]), style: FontStyle.Bold); text.transform.position = new Vector3((button.transform.position.x + (button.GetComponent <SpriteRenderer>().bounds.size.x / 2f)) - (text.GetComponent <TextMesh>().GetComponent <Renderer>().bounds.size.x / 2f), (button.transform.position.y + (button.GetComponent <SpriteRenderer>().bounds.size.y / 2f)) + (text.GetComponent <TextMesh>().GetComponent <Renderer>().bounds.size.y / 2f)); if (classesArray[i].Replace(" ", string.Empty) == selectedClass.ToString()) { StaticScripts.CreateGameObj("ClassPortrait", string.Format("Portraits/Heroes/Portrait_{0}_{1}", classesArray[i].Replace(" ", ""), Account.CurrentAccount.GetCurrentHero().Gender ? "Male" : "Female"), new Vector3(1.5f, 1.5f), new Vector3(-1.65f, -1.15f), child: true, parentName: "CharacterCreationSceneObject"); } } else { var button = GameObject.Find(string.Format("{0}Button", classesArray[i])); button.GetComponent <ButtonBaseMouseEvents>()._State = selectedClass.ToString() == classesArray[i].Replace(" ", string.Empty) ? ButtonState.Selected : ButtonState.Up; if (classesArray[i].Replace(" ", string.Empty) == selectedClass.ToString()) { var portraitObject = gameObject.transform.FindChild("ClassPortrait"); if (portraitObject) { DestroyImmediate(portraitObject.gameObject); } StaticScripts.CreateGameObj("ClassPortrait", string.Format("Portraits/Heroes/Portrait_{0}_{1}", classesArray[i].Replace(" ", ""), Account.CurrentAccount.GetCurrentHero().Gender ? "Male" : "Female"), new Vector3(1.5f, 1.5f), new Vector3(-1.65f, -1.15f), child: true, parentName: "CharacterCreationSceneObject"); } } } #endregion }
void LoadHeroesButtons() { selectedClass = (GameClasses)Enum.GetValues(typeof(GameClasses)).GetValue(Random.Range(0, 6)); Account.CurrentAccount.AddNewHero(new Hero() { Class = selectedClass, Gender = true, State = HeroState.NotCreated }); Account.CurrentAccount.SetCurrentHero(Account.CurrentAccount.ListOfHeroes.Count - 1); #region ClassButtons var classesArray = new[] { "Barbarian", "Crusader", "Demon Hunter", "Monk", "Witch Doctor", "Wizard" }; for (int i = 0; i < classesArray.Length; i++) { if(!gameObject.transform.FindChild(string.Format("{0}Button", classesArray[i]))) { var button = StaticScripts.CreateGameObj(string.Format("{0}Button", classesArray[i]), @"Buttons/BattleNetButton_ClearUp_397x66", new Vector3(0.65f, 0.85f), new Vector3(-8.3f, 1.9f - 0.59f*i, 10f), true, 1, true, typeof (CreateCharacterClassMouseEvents), child: true, parentName: "CharacterCreationSceneObject"); button.GetComponent<ButtonBaseMouseEvents>()._State = selectedClass.ToString() == classesArray[i].Replace(" ", string.Empty) ? ButtonState.Selected : ButtonState.Up; var text = StaticScripts.CreateTextObj(string.Format("{0}ButtonText", classesArray[i]), classesArray[i], new Vector3(0.02f, 0.02f), new Vector3(0f, 0f, 0f), FontType.DiabloFont, 100, new Color32(243, 170, 85, 255), TextAlignment.Center, child: true, parentName: string.Format("{0}Button", classesArray[i]), style:FontStyle.Bold); text.transform.position = new Vector3((button.transform.position.x + (button.GetComponent<SpriteRenderer>().bounds.size.x/2f)) - (text.GetComponent<TextMesh>().GetComponent<Renderer>().bounds.size.x/2f), (button.transform.position.y + (button.GetComponent<SpriteRenderer>().bounds.size.y/2f)) + (text.GetComponent<TextMesh>().GetComponent<Renderer>().bounds.size.y/2f)); if (classesArray[i].Replace(" ", string.Empty) == selectedClass.ToString()) { StaticScripts.CreateGameObj("ClassPortrait", string.Format("Portraits/Heroes/Portrait_{0}_{1}", classesArray[i].Replace(" ", ""), Account.CurrentAccount.GetCurrentHero().Gender ? "Male" : "Female"), new Vector3(1.5f, 1.5f), new Vector3(-1.65f, -1.15f), child: true, parentName: "CharacterCreationSceneObject"); } } else { var button = GameObject.Find(string.Format("{0}Button", classesArray[i])); button.GetComponent<ButtonBaseMouseEvents>()._State = selectedClass.ToString() == classesArray[i].Replace(" ", string.Empty) ? ButtonState.Selected : ButtonState.Up; if (classesArray[i].Replace(" ", string.Empty) == selectedClass.ToString()) { var portraitObject = gameObject.transform.FindChild("ClassPortrait"); if(portraitObject) DestroyImmediate(portraitObject.gameObject); StaticScripts.CreateGameObj("ClassPortrait", string.Format("Portraits/Heroes/Portrait_{0}_{1}", classesArray[i].Replace(" ", ""), Account.CurrentAccount.GetCurrentHero().Gender ? "Male" : "Female"), new Vector3(1.5f, 1.5f), new Vector3(-1.65f, -1.15f), child: true, parentName: "CharacterCreationSceneObject"); } } } #endregion }