using System.Collections;
using UnityEngine.UI;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using EventSystem = UnityEngine.EventSystems.EventSystem;
namespace Lean.Common
{
/// This class contains useful methods used in almost all LeanTouch code.
public static class LeanHelper
{
public const string HelpUrlPrefix = "https://carloswilkes.github.io/Documentation/LeanCommon#";
public const string PlusHelpUrlPrefix = "https://carloswilkes.github.io/Documentation/LeanCommonPlus#";
public const string ComponentPathPrefix = "Lean/Common/Lean ";
#if UNITY_EDITOR
/// This method creates an empty GameObject prefab at the current asset folder
public static GameObject CreateAsset(string name)
{
var gameObject = new GameObject(name);
var path = AssetDatabase.GetAssetPath(Selection.activeObject);
if (string.IsNullOrEmpty(path) == true)
{
path = "Assets";
}
path = AssetDatabase.GenerateUniqueAssetPath(path + "/" + name + ".prefab");
#if UNITY_2018_3_OR_NEWER
var prefab = PrefabUtility.SaveAsPrefabAsset(gameObject, path);
#else
var prefab = PrefabUtility.CreatePrefab(path, gameObject);
#endif
Object.DestroyImmediate(gameObject);
Selection.activeObject = prefab;
return prefab;
}
#endif
/// This method allows you to create a UI element with the specified component and specified parent, with behavior consistent with Unity's built-in UI element creation.
public static T CreateElement(Transform parent)
where T : Component
{
var gameObject = new GameObject(typeof(T).Name);
#if UNITY_EDITOR
Undo.RegisterCreatedObjectUndo(gameObject, "Create " + typeof(T).Name);
#endif
var component = gameObject.AddComponent();
// Auto attach to canvas?
if (parent == null || parent.GetComponentInParent