using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.EventSystems;
namespace TyphoonUI
{
internal static class ExtensionInEditor
{
///
/// 保存配置
///
internal static void SaveAssetWithDirty(this T target) where T : ScriptableObject
{
EditorUtility.SetDirty(target);
AssetDatabase.SaveAssets();
}
internal static void ReloadSource(this CoreSource source)
{
source.UICamera = null;
source.EventSystem = null;
source.Canvases = new List();
var guids = AssetDatabase.FindAssets("t:prefab", new[] { Paths.CORE_SOURCE_ROOT_PATH });
foreach (var guid in guids)
{
var path = AssetDatabase.GUIDToAssetPath(guid);
var go = AssetDatabase.LoadAssetAtPath(path);
if (go.GetComponent() != null)
{
source.UICamera = go;
}
if (go.GetComponent() != null)
{
source.EventSystem = go;
}
if (go.GetComponent() != null)
{
source.Canvases.Add(go);
}
}
source.SaveAssetWithDirty();
}
internal static void ResetTransformParams(this Transform target)
{
target.localPosition = Vector3.zero;
target.localEulerAngles = Vector3.zero;
target.localScale = Vector3.one;
}
internal static T AddComponentIfNotExists(this GameObject target) where T : Component
{
var match = target.GetComponent();
if (match == null)
{
match = target.AddComponent();
}
return match;
}
}
}