Skip to content

Instantly share code, notes, and snippets.

@dcjulian
Created April 3, 2021 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcjulian/4be72f458a8acd81272f01d1f92e8151 to your computer and use it in GitHub Desktop.
Save dcjulian/4be72f458a8acd81272f01d1f92e8151 to your computer and use it in GitHub Desktop.
ui panel snippet
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