SHARE
TWEET

add slider example

lencH Jul 14th, 2016 33 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using spaar.ModLoader;
  3. using UnityEngine;
  4. using System.Reflection;
  5.  
  6. namespace testMod
  7. {
  8.  
  9.     // If you need documentation about any of these values or the mod loader
  10.     // in general, take a look at https://spaar.github.io/besiege-modloader.
  11.  
  12.     public class TestMod : Mod
  13.     {
  14.         public override string Name { get; } = "Test Slider";
  15.         public override string DisplayName { get; } = "Test Slider";
  16.         public override string Author { get; } = "Lench";
  17.         public override Version Version { get; } = new Version(1, 0, 0);
  18.  
  19.         public override void OnLoad()
  20.         {
  21.             // subscribe to OnBlockPaced event
  22.             Game.OnBlockPlaced += AddSlider;
  23.         }
  24.  
  25.         public override void OnUnload()
  26.         {
  27.             // unsubscribe
  28.             Game.OnBlockPlaced -= AddSlider;
  29.         }
  30.  
  31.         public void AddSlider(Transform block)
  32.         {
  33.             // create new slider
  34.             var newSlider = new MSlider("Test slider", "test", 1, 0, 2);
  35.             newSlider.DisplayInMapper = true;
  36.  
  37.             // get placed block
  38.             var b = block.GetComponent<BlockBehaviour>();
  39.  
  40.             // property returns a new list
  41.             var currentMapperTypes = b.MapperTypes;
  42.  
  43.             // add slider
  44.             currentMapperTypes.Add(newSlider);
  45.  
  46.             // set the new mapper types list
  47.             typeof(BlockBehaviour)
  48.                .GetField("mapperTypes", BindingFlags.Instance | BindingFlags.NonPublic)
  49.                .SetValue(b, currentMapperTypes);
  50.  
  51.             // print all mapper types in console
  52.             Debug.Log("MapperTypes:");
  53.             foreach (var s in b.MapperTypes)
  54.                 Debug.Log(s.DisplayName);
  55.         }
  56.     }
  57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top