public UserInterface() { instance = this; UIView view = GameObject.FindObjectOfType<UIView> (); if (view == null) return; UIComponent bulldozerBar = UIView.Find ("BulldozerBar"); if (bulldozerBar == null) return; try { XmlSerializer serializer = new XmlSerializer (typeof(XmlData)); using (StreamReader reader = new StreamReader("V10Bulldoze.xml")) { data = (XmlData)serializer.Deserialize (reader); reader.Close (); } } catch (FileNotFoundException) { // No options file yet data = new XmlData (); data.needSave = true; } catch (Exception e) { Debug.Log ("V10Bulldoze: " + e.GetType ().Name + " while reading xml file: " + e.Message + "\n" + e.StackTrace + "\n\n"); if (e.InnerException != null) Debug.Log ("Caused by: " + e.InnerException.GetType ().Name + ": " + e.InnerException.Message + "\n" + e.InnerException.StackTrace); return; } //1.X -> 1.3 if (data.version < 1.3d) { // Everything has already been setted to its default value, so let's just adjust the version and save. data.version = 1.3d; data.needSave = true; } abandonedButton = new GameObject ("V10Bulldoze abandoned button"); burnedButton = new GameObject ("V10Bulldoze burned button"); audioButton = new GameObject ("V10Bulldoze audio button"); Transform parent = bulldozerBar.transform; abandonedButton.transform.parent = parent; burnedButton.transform.parent = parent; audioButton.transform.parent = parent; Shader shader = Shader.Find ("UI/Default UI Shader"); if (shader == null) { Debug.Log ("V10Bulldoze: Can't find default UI shader."); shader = new Shader (); shader.name = "V10Bulldoze dummy shader"; } UITextureAtlas atlas = ScriptableObject.CreateInstance<UITextureAtlas> (); atlas.name = "V10Bulldoze Atlas"; atlas.material = new Material (shader); atlas.material.mainTexture = new Texture2D (0, 0, TextureFormat.DXT5, false); FastList<Texture2D> list = new FastList<Texture2D> (); list.EnsureCapacity (18); UIButton button = abandonedButton.AddComponent<UIButton> (); button.relativePosition = new Vector3 (7.0f, -57.0f); initButton ("AbandonedButton", button, list, data.abandoned, "Demolish Abandoned", view); button.atlas = atlas; button = burnedButton.AddComponent<UIButton> (); button.relativePosition = new Vector3 ((float)(7 + buttonSize + 7), -57.0f); initButton ("BurnedButton", button, list, data.burned, "Demolish Burned", view); button.atlas = atlas; button = audioButton.AddComponent<UIButton> (); button.relativePosition = new Vector3 ((float)(7 + buttonSize + 7 + buttonSize + 7), -57.0f); initButton ("AudioButton", button, list, !data.disableEffect, "Mute Bulldozing", view); button.atlas = atlas; atlas.AddTextures (list.ToArray ()); }
public UserInterface() { instance = this; UIView view = GameObject.FindObjectOfType <UIView> (); if (view == null) { return; } UIComponent bulldozerBar = UIView.Find("BulldozerBar"); if (bulldozerBar == null) { return; } try { XmlSerializer serializer = new XmlSerializer(typeof(XmlData)); using (StreamReader reader = new StreamReader("V10Bulldoze.xml")) { data = (XmlData)serializer.Deserialize(reader); reader.Close(); } } catch (FileNotFoundException) { // No options file yet data = new XmlData(); data.needSave = true; } catch (Exception e) { Debug.Log("V10Bulldoze: " + e.GetType().Name + " while reading xml file: " + e.Message + "\n" + e.StackTrace + "\n\n"); if (e.InnerException != null) { Debug.Log("Caused by: " + e.InnerException.GetType().Name + ": " + e.InnerException.Message + "\n" + e.InnerException.StackTrace); } return; } //1.X -> 1.3 if (data.version < 1.3d) { // Everything has already been setted to its default value, so let's just adjust the version and save. data.version = 1.3d; data.needSave = true; } abandonedButton = new GameObject("V10Bulldoze abandoned button"); burnedButton = new GameObject("V10Bulldoze burned button"); audioButton = new GameObject("V10Bulldoze audio button"); Transform parent = bulldozerBar.transform; abandonedButton.transform.parent = parent; burnedButton.transform.parent = parent; audioButton.transform.parent = parent; Shader shader = Shader.Find("UI/Default UI Shader"); if (shader == null) { Debug.Log("V10Bulldoze: Can't find default UI shader."); shader = new Shader(); shader.name = "V10Bulldoze dummy shader"; } UITextureAtlas atlas = ScriptableObject.CreateInstance <UITextureAtlas> (); atlas.name = "V10Bulldoze Atlas"; atlas.material = new Material(shader); atlas.material.mainTexture = new Texture2D(0, 0, TextureFormat.DXT5, false); FastList <Texture2D> list = new FastList <Texture2D> (); list.EnsureCapacity(18); UIButton button = abandonedButton.AddComponent <UIButton> (); button.relativePosition = new Vector3(7.0f, -57.0f); initButton("AbandonedButton", button, list, data.abandoned, "Demolish Abandoned", view); button.atlas = atlas; button = burnedButton.AddComponent <UIButton> (); button.relativePosition = new Vector3((float)(7 + buttonSize + 7), -57.0f); initButton("BurnedButton", button, list, data.burned, "Demolish Burned", view); button.atlas = atlas; button = audioButton.AddComponent <UIButton> (); button.relativePosition = new Vector3((float)(7 + buttonSize + 7 + buttonSize + 7), -57.0f); initButton("AudioButton", button, list, !data.disableEffect, "Mute Bulldozing", view); button.atlas = atlas; atlas.AddTextures(list.ToArray()); }
public void destroy() { abandonedButton.SetActive (false); burnedButton.SetActive (false); audioButton.SetActive (false); abandonedButton = burnedButton = audioButton = null; if (UserInterface.bulldozeAudioClip != null) UserInterface.toggleEffects (); if (data.needSave) { try { XmlSerializer serializer = new XmlSerializer (typeof(XmlData)); using (StreamWriter writer = new StreamWriter("V10Bulldoze.xml")) { serializer.Serialize (writer, data); writer.Flush (); writer.Close (); } } catch (Exception e) { Debug.Log ("V10Bulldoze: " + e.GetType ().Name + " while writing xml file: " + e.Message + "\n" + e.StackTrace); if (e.InnerException != null) Debug.Log ("Caused by: " + e.InnerException.GetType ().Name + ": " + e.InnerException.Message + "\n" + e.InnerException.StackTrace); } } data = null; }