Created
March 29, 2012 18:58
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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