public bool IsValidConfiguration(GameConfiguration config) { Type t = config.GetType(); foreach (PropertyInfo p in t.GetProperties()) { Debug.Log(p.Name + " " + p.GetValue(config).ToString()); if (p.GetCustomAttribute(typeof(PropertyOptional)) == null) { if (p.PropertyType == typeof(int) || p.PropertyType == typeof(float)) { if (p.GetCustomAttribute(typeof(PropertyRange)) != null) { int min = (p.GetCustomAttribute(typeof(PropertyRange)) as PropertyRange).min; int max = (p.GetCustomAttribute(typeof(PropertyRange)) as PropertyRange).max; if (float.Parse(p.GetValue(config).ToString()) > max || float.Parse(p.GetValue(config).ToString()) < min) { return(false); } } } if (p.PropertyType == typeof(string)) { if (p.GetValue(config).ToString() == null || p.GetValue(config).ToString() == "") { Debug.Log("empty string"); return(false); } if (p.GetCustomAttribute(typeof(PropertyLimitedSet)) != null) { string[] values = (p.GetCustomAttribute(typeof(PropertyLimitedSet)) as PropertyLimitedSet).values; if (!values.Contains(p.GetValue(config).ToString())) { Debug.Log("value not in list"); return(false); } } if (p.GetCustomAttribute(typeof(PropertyReferenceFolder)) != null) { PropertyReferenceFolder prf = (PropertyReferenceFolder)p.GetCustomAttribute(typeof(PropertyReferenceFolder)); string filename = p.GetValue(config).ToString(); Debug.Log(Application.streamingAssetsPath + "/" + prf.folder + "/" + filename + "." + prf.extension); Debug.Log(File.Exists(Application.streamingAssetsPath + "/" + prf.folder + "/" + filename + "." + prf.extension)); Debug.Log(MagicRoomManager.instance.systemConfiguration.resourcesPath + "\\" + prf.folder + "\\" + filename + "." + prf.extension); Debug.Log(File.Exists(MagicRoomManager.instance.systemConfiguration.resourcesPath + "\\" + prf.folder + "\\" + filename + "." + prf.extension)); return(File.Exists(Application.streamingAssetsPath + "/" + prf.folder + "/" + filename + "." + prf.extension) || File.Exists(MagicRoomManager.instance.systemConfiguration.resourcesPath + "\\" + prf.folder + "\\" + filename + "." + prf.extension)); } } } else { if (p.GetCustomAttribute(typeof(PropertyDefaultValue)) != null) { PropertyDefaultValue pdv = (PropertyDefaultValue)p.GetCustomAttribute(typeof(PropertyDefaultValue)); if (p.PropertyType == typeof(int)) { p.SetValue(config, pdv.intvalue); } if (p.PropertyType == typeof(float)) { p.SetValue(config, pdv.floatvalue); } if (p.PropertyType == typeof(string)) { p.SetValue(config, pdv.stringvalue); } if (p.PropertyType == typeof(Enum)) { p.SetValue(config, pdv.enumvalue); } if (p.PropertyType == typeof(bool)) { p.SetValue(config, pdv.boolvalue); } } } } return(true); }
public void generateMenu() { blocks = new List <PropertyMenuBlockManager>(); int count = transform.childCount; for (int i = 0; i < count; i++) { GameObject.DestroyImmediate(transform.GetChild(0).gameObject); } grid = GameObject.Instantiate(Resources.Load("UI/PropertyPanel") as GameObject, transform); PropertyInfo[] props = GetProperties(); GridLayoutGroup gridlayout = grid.GetComponent <GridLayoutGroup>(); float screenwidth = generateAtRuntime ? Screen.width : 1920; float screenheight = generateAtRuntime ? Screen.height : 1080; float blocky = Mathf.Max(80, screenheight / (props.Length + 1)); gridlayout.cellSize = new Vector2(screenwidth * 0.4f, blocky); gridlayout.spacing = new Vector2(screenwidth * 0.1f, -(screenheight - blocky * (props.Length + 1)) / 2); gridlayout.padding = new RectOffset((int)(screenwidth * 0.05f), 0, (int)blocky / 2, (int)blocky / 2); foreach (PropertyInfo p in props) { string propertyname = p.Name; string easyname = ""; if (propertyname != ThemePropertyName) { object[] attrs = p.GetCustomAttributes(true); foreach (Attribute a in attrs) { if (a.GetType().ToString() == "PropertyRename") { PropertyRename rnm = a as PropertyRename; easyname = rnm.easyname; } } GameObject g = null; if (p.PropertyType == typeof(int)) { g = GameObject.Instantiate(Resources.Load("UI/PropertyMenuBlockNumber") as GameObject, transform.GetChild(0)); g.GetComponent <PropertyMenuBlockManager>().SetUp <int>(propertyname, (int)p.GetValue(configurationschema), generateAtRuntime, easyname); foreach (Attribute a in attrs) { if (a.GetType().ToString() == "PropertyRange") { PropertyRange r = a as PropertyRange; g.GetComponent <PropertyMenuBlockManager>().SetUpLimits(r.min, r.max); } } } if (p.PropertyType == typeof(float)) { g = GameObject.Instantiate(Resources.Load("UI/PropertyMenuBlockNumber") as GameObject, transform.GetChild(0)); g.GetComponent <PropertyMenuBlockManager>().SetUp <float>(propertyname, (float)p.GetValue(configurationschema), generateAtRuntime, easyname); foreach (Attribute a in attrs) { if (a.GetType().ToString() == "PropertyRange") { PropertyRange r = a as PropertyRange; g.GetComponent <PropertyMenuBlockManager>().SetUpLimits(r.min, r.max); } } } if (p.PropertyType == typeof(string)) { foreach (Attribute a in attrs) { if (a.GetType().ToString() == "PropertyLimitedSet") { PropertyLimitedSet s = a as PropertyLimitedSet; g = GameObject.Instantiate(Resources.Load("UI/PropertyMenuBlockDropdown") as GameObject, transform.GetChild(0)); List <string> ls = new List <string>(); ls.AddRange(s.values); g.GetComponent <PropertyMenuBlockManager>().SetUp <string>(propertyname, s.values[0], generateAtRuntime, easyname, ls); } else if (a.GetType().ToString() == "PropertyReferenceFolder") { PropertyReferenceFolder prf = a as PropertyReferenceFolder; g = GameObject.Instantiate(Resources.Load("UI/PropertyMenuBlockDropdown") as GameObject, transform.GetChild(0)); List <string> ls = new List <string>(); foreach (string f in Directory.GetFiles(Application.streamingAssetsPath + "/" + prf.folder)) { string file = f.Split('/').Last().Split('\\').Last(); if (file.EndsWith(prf.extension)) { ls.Add(file); } } g.GetComponent <PropertyMenuBlockManager>().SetUp <string>(propertyname, ls.First(), generateAtRuntime, easyname, ls); } else { g = GameObject.Instantiate(Resources.Load("UI/PropertyMenuBlockText") as GameObject, transform.GetChild(0)); g.GetComponent <PropertyMenuBlockManager>().SetUp <string>(propertyname, "", generateAtRuntime, easyname); } } } if (p.PropertyType == typeof(bool)) { g = GameObject.Instantiate(Resources.Load("UI/PropertyMenuBlockBool") as GameObject, transform.GetChild(0)); g.GetComponent <PropertyMenuBlockManager>().SetUp <bool>(propertyname, (bool)p.GetValue(configurationschema), generateAtRuntime, easyname); } if (p.PropertyType.IsEnum) { g = GameObject.Instantiate(Resources.Load("UI/PropertyMenuBlockDropdown") as GameObject, transform.GetChild(0)); g.GetComponent <PropertyMenuBlockManager>().SetUp <System.Enum>(propertyname, (System.Enum)p.GetValue(configurationschema), generateAtRuntime, easyname); } blocks.Add(g.GetComponent <PropertyMenuBlockManager>()); } } if (ThemePropertyName == "") { GameObject title = Instantiate(Resources.Load("UI/MenuApplicationTitle") as GameObject, transform); title.GetComponentInChildren <Text>().text = Application.productName; } else { GameObject title = Instantiate(Resources.Load("UI/MenuApplicationTitleAndTheme") as GameObject, transform); ThemeManager.StartUp(); title.GetComponent <PropertyMenuBlockManager>().SetupTheme(ThemePropertyName, generateAtRuntime); theme = title.GetComponent <PropertyMenuBlockManager>(); blocks.Add(theme); } GameObject PlayButton = Instantiate(Resources.Load("UI/PlayButton") as GameObject, transform); playgame = PlayButton.GetComponentInChildren <Button>(); if (generateAtRuntime) { PlayButton.GetComponentInChildren <Button>().onClick.AddListener(delegate { PlayGame(); }); } }