ui panel snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ICities; | |
using UnityEngine; | |
using ColossalFramework.UI; | |
namespace UIMod | |
{ | |
public class UIMod : IUserMod | |
{ | |
public string Name { get { return "UIMod"; } } | |
public string Description { get { return "UIMod"; } } | |
} | |
public class LoadingExtension : LoadingExtensionBase | |
{ | |
public override void OnLevelLoaded(LoadMode mode) | |
{ | |
// this seems to get the default UIView | |
UIView v = UIView.GetAView (); | |
//this adds an UIComponent to the view | |
UIComponent uic = v.AddUIComponent (typeof(ExamplePanel)); | |
// ALTERNATIVELY, this seems to work like the lines above, but is a bit longer: | |
// UIView v = UIView.GetAView (); | |
// GameObject go = new GameObject ("panelthing", typeof(ExamplePanel)); | |
// UIComponent uic = v.AttachUIComponent (go); | |
} | |
} | |
//whatever child class of UIComponent, here UIPanel | |
public class ExamplePanel : UIPanel { | |
//these overrides are not necessary, but obviously helpful | |
//this seems to be called initially | |
public override void Start () | |
{ | |
//this makes the panel "visible", I don't know what sprites are available, but found this value to work | |
this.backgroundSprite = "GenericPanel"; | |
this.color = new Color32(255,0,0,100); | |
this.width = 100; | |
this.height = 200; | |
// and then something like | |
// UILabel l = this.AddUIComponent<UILabel> (); | |
// l.text = "I am a label"; | |
// l.eventClick += FooBarClickHandler; | |
} | |
//this gets called every frame | |
public override void Update() | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment