Skip to content

@darktable /GUIMerge.cs
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.