59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
using UnityEngine;
|
|
using UnityEditor;
|
|
using System.Linq;
|
|
using System;
|
|
|
|
public class UnityResourcesEditor : EditorWindow {
|
|
public string resourcesAssetPath = @"Assets/unity editor resources.asset";
|
|
public GUISkin LightSkin;
|
|
public GUISkin DarkSkin;
|
|
|
|
[MenuItem ("L/UnityResourcesEditor")]
|
|
static void Init () {
|
|
UnityResourcesEditor window = (UnityResourcesEditor)EditorWindow.GetWindow (typeof (UnityResourcesEditor));
|
|
window.Show();
|
|
}
|
|
|
|
void CopyProperties<T>(T from, T to, string[] exclude = null){
|
|
var props = typeof(T).GetProperties ().Where(v=>v.CanWrite && v.CanWrite).ToArray();
|
|
foreach (var p in props) {
|
|
Debug.Log(p.Name);
|
|
if(exclude != null && exclude.Any(v => v == p.Name)){
|
|
Debug.Log("Skin property: " + p.Name);
|
|
continue;
|
|
}
|
|
p.SetValue(to, p.GetValue(from, null), null);
|
|
}
|
|
}
|
|
|
|
void CopyGuiSkin(GUISkin from, GUISkin to){
|
|
Debug.Log ("Copy skins");
|
|
CopyProperties (from, to, new []{"name"});
|
|
|
|
CopyProperties (from.settings, to.settings);
|
|
}
|
|
|
|
void OnGUI () {
|
|
GUILayout.Label ("Asset path", EditorStyles.boldLabel);
|
|
resourcesAssetPath = GUILayout.TextField (resourcesAssetPath);
|
|
|
|
if (GUILayout.Button ("Load resources")) {
|
|
var resources = AssetDatabase.LoadAllAssetsAtPath (resourcesAssetPath);
|
|
var skins = resources.Where(v=>v is GUISkin).Cast<GUISkin>().ToArray();
|
|
|
|
var lightSkin = skins.First(v=>v.name.ToLower() == "LightSkin".ToLower());
|
|
var darkSkin = skins.First(v=>v.name.ToLower() == "DarkSkin".ToLower());
|
|
|
|
CopyGuiSkin(darkSkin, lightSkin);
|
|
|
|
Debug.Log("Light skin name: " + lightSkin.name);
|
|
Debug.Log("Dark skin name: " + darkSkin.name);
|
|
|
|
AssetDatabase.SaveAssets();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
} |