Skip to content

Instantly share code, notes, and snippets.

@darktable
Created March 29, 2012 18:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save darktable/2242083 to your computer and use it in GitHub Desktop.
Save darktable/2242083 to your computer and use it in GitHub Desktop.
Unity3D: Script to merge multiple GUISkins into a single GUISkin with multiple custom styles.
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