using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
namespace LNWY
{
public static class ClassNullSelf
{
public static bool IsNull<T>(this T self) where T : class
{
return null == self;
}
public static bool IsNotNull<T>(this T self) where T : class
{
return null != self;
}
}
public static class IOPathSelf
{
public static string PathCreateNull(this string dir)
{
if (Directory.Exists(dir) == false)
Directory.CreateDirectory(dir);
return dir;
}
public static void PathDelete(this string dir)
{
if (Directory.Exists(dir))
{
Directory.Delete(dir);
}
}
public static void PathDeleteNew(this string dir)
{
if (Directory.Exists(dir))
{
Directory.Delete(dir);
}
Directory.CreateDirectory(dir);
}
}
public static class MonoSelf
{
public static T ZeroOne<T>(this T t) where T : Component
{
t.transform.localPosition = Vector3.zero;
t.transform.localEulerAngles = Vector3.zero;
t.transform.localScale = Vector3.one;
return t;
}
public static T SetLocalPosition<T>(this T t, Vector3 pos) where T : Component
{
t.transform.localPosition = pos;
return t;
}
}
}
使用
public class Test : MonoBehaviour
{
int ty = 50;
public Transform t1;
void OnGUI()
{
if (GUI.Button(new Rect(10, 10, 5200, 45), "text"))
{
string tttT = "Assets/Resources";
tttT.PathCreateNull();
t1.ZeroOne();
}
if (GUI.Button(new Rect(10, ty + 10, 200,45), "text2"))
{
t1.SetLocalPosition(new Vector3(100, 100, 1));
}
}
}