Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Unity3D: Script to merge multiple GUISkins into a single GUISkin with multiple custom styles.

View GUIMerge.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
 
public class GUIMerge : MonoBehaviour {
 
public GUISkin primary;
 
public GUISkin[] skins;
 
// Use this for initialization
void Start () {
var skin = skins[0];
 
foreach(PropertyInfo propertyInfo in typeof(GUISkin).GetProperties()) {
 
if (propertyInfo.PropertyType == typeof(GUISettings)) {
var settings = (GUISettings) propertyInfo.GetValue(skin, null);
 
primary.settings.cursorColor = settings.cursorColor;
primary.settings.cursorFlashSpeed = settings.cursorFlashSpeed;
primary.settings.doubleClickSelectsWord = settings.doubleClickSelectsWord;
primary.settings.selectionColor = settings.selectionColor;
primary.settings.tripleClickSelectsLine = settings.tripleClickSelectsLine;
}
else {
propertyInfo.SetValue(primary, propertyInfo.GetValue(skin, null), null);
}
}
 
 
var styleList = new List<GUIStyle>();
 
for (int i=0; i< skins.Length; i++) {
skin = skins[i];
 
var name = skin.name;
 
foreach(PropertyInfo propertyInfo in typeof(GUISkin).GetProperties()) {
if (propertyInfo.PropertyType != typeof(GUIStyle))
continue;
 
var style = (GUIStyle) propertyInfo.GetValue(skin, null);
 
Debug.Log(style.name);
 
var newname = name + "_" + style.name;
 
var newstyle = new GUIStyle(style);
 
newstyle.name = newname;
 
styleList.Add(newstyle);
}
}
 
primary.customStyles = styleList.ToArray();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.