Unity SKFramework框架(十四)、Extension 扩展函数
【摘要】
目录
简介
一、DotNet
Array
bool
Class
DateTime
Dictionary
int
List
Queue
Stack
string
二、Unity
AudioSource
Transform
RectTransform
简介
该部分是框架中...
目录
简介
该部分是框架中使用this关键字给一些类型做的拓展函数,为了支持链式编程或记录、封装一些功能,内容会持续补充,本文给出其中部分示例。
一、DotNet
Array
-
/// <summary>
-
/// 遍历
-
/// </summary>
-
/// <param name="action">遍历事件</param>
-
public static T[] ForEach<T>(this T[] self, Action<int, T> action);
-
/// <summary>
-
/// 倒序遍历
-
/// </summary>
-
/// <param name="action">遍历事件</param>
-
public static T[] ForEachReverse<T>(this T[] self, Action<T> action);
-
/// <summary>
-
/// 倒序遍历
-
/// </summary>
-
/// <param name="action">遍历事件</param>
-
public static T[] ForEachReverse<T>(this T[] self, Action<int, T> action);
-
/// <summary>
-
/// 合并
-
/// </summary>
-
/// <param name="target">合并的目标</param>
-
/// <returns>返回一个新的Array 包含被合并的两个Array中的所有元素</returns>
-
public static T[] Merge<T>(this T[] self, T[] target);
-
/// <summary>
-
/// 插入排序
-
/// </summary>
-
/// <returns>返回排序后的数组</returns>
-
public static int[] SortInsertion(this int[] self);
-
/// <summary>
-
/// 希尔排序
-
/// </summary>
-
/// <returns>返回排序后的数组</returns>
-
public static int[] SortShell(this int[] self);
-
/// <summary>
-
/// 选择排序
-
/// </summary>
-
/// <returns>返回排序后的数组</returns>
-
public static int[] SortSelection(this int[] self);
-
/// <summary>
-
/// 冒泡排序
-
/// </summary>
-
/// <returns>返回排序后的数组</returns>
-
public static int[] SortBubble(this int[] self);
Example
-
using UnityEngine;
-
using SK.Framework;
-
-
public class Example : MonoBehaviour
-
{
-
private void Start()
-
{
-
string[] exampleArray = new string[] { "AAA", "BBB" };
-
//遍历
-
exampleArray.ForEach((i, s) => Debug.Log(string.Format("{0}.{1}", i + 1, s)));
-
//倒序遍历
-
exampleArray.ForEachReverse(m => Debug.Log(m));
-
//倒序遍历
-
exampleArray.ForEachReverse((i, s) => Debug.Log(string.Format("{0}.{1}", i + 1, s)));
-
-
//Array合并
-
string[] target = new string[] { "CCC", "DDD" };
-
string[] merge = exampleArray.Merge(target);
-
-
int[] intArray = new int[] { 55, 32, 57, 89, 13, 87 , 9, 21};
-
//希尔排序
-
intArray.SortInsertion();
-
//选择排序
-
intArray.SortSelection();
-
//冒泡排序
-
intArray.SortBubble();
-
}
-
}
bool
-
/// <summary>
-
/// 如果bool值为true 则执行事件
-
/// </summary>
-
/// <param name="action">事件</param>
-
public static bool Execute(this bool self, Action action);
-
/// <summary>
-
/// 根据bool值执行Action<bool>类型事件
-
/// </summary>
-
/// <param name="action">事件</param>
-
public static bool Execute(this bool self, Action<bool> action);
-
/// <summary>
-
/// bool值为true则执行第一个事件 否则执行第二个事件
-
/// </summary>
-
public static bool Execute(this bool self, Action actionIfTrue, Action actionIfFalse);
-
/// <summary>
-
/// bool值取反
-
/// </summary>
-
public static bool Reverse(this bool self);
Example
-
using UnityEngine;
-
using SK.Framework;
-
-
public class Example : MonoBehaviour
-
{
-
private bool flag;
-
-
private void Start()
-
{
-
//如果flag为true 则会打印日志true
-
flag.Execute(() => Debug.Log("true"));
-
//如果flag为true 则会打印日志true 否则打印日志false
-
flag.Execute(isTrue => Debug.Log(isTrue));
-
//如果flag为true 则会打印日志true 否则打印日志false
-
flag.Execute(() => Debug.Log("true"), () => Debug.Log("false"));
-
}
-
}
Class
-
/// <summary>
-
/// 如果对象不为null则执行事件
-
/// </summary>
-
/// <param name="action">事件</param>
-
/// <returns>执行成功返回true 否则返回false</returns>
-
public static bool Execute<T>(this T self, Action<T> action);
Example
-
using UnityEngine;
-
using SK.Framework;
-
-
public class Example : MonoBehaviour
-
{
-
public class Person
-
{
-
public string name;
-
}
-
private Person person;
-
-
private void Start()
-
{
-
person.Execute(m => Debug.Log(m.name));
-
}
-
}
DateTime
-
/// <summary>
-
/// 获取时间戳
-
/// </summary>
-
/// <returns>时间戳</returns>
-
public static double GetTimeStamp(this DateTime self);
-
/// <summary>
-
/// 转换为中文
-
/// </summary>
-
/// <param name="prefix">前缀 周/星期</param>
-
/// <returns>中文字符串</returns>
-
public static string ToChinese(this DayOfWeek self, string prefix);
Example
-
using System;
-
using UnityEngine;
-
using SK.Framework;
-
-
public class Example : MonoBehaviour
-
{
-
private void Start()
-
{
-
DateTime now = DateTime.Now;
-
//获取时间戳
-
double timeStamp = now.GetTimeStamp();
-
-
DayOfWeek day = DayOfWeek.Monday;
-
//转化为中文 周一
-
string chinese = day.ToChinese("周");
-
//转化为中文 星期一
-
chinese = day.ToChinese("星期");
-
}
-
}
Dictionary
-
/// <summary>
-
/// 拷贝字典
-
/// </summary>
-
public static Dictionary<K, V> Copy<K, V>(this Dictionary<K, V> self);
-
/// <summary>
-
/// 遍历字典
-
/// </summary>
-
/// <param name="action">遍历事件</param>
-
public static Dictionary<K, V> ForEach<K, V>(this Dictionary<K, V> self, Action<K, V> action);
-
/// <summary>
-
/// 合并字典
-
/// </summary>
-
/// <param name="target">被合并的字典</param>
-
/// <param name="isOverride">若存在相同键,是否覆盖对应值</param>
-
/// <returns>合并后的字典</returns>
-
public static Dictionary<K, V> AddRange<K, V>(this Dictionary<K, V> self, Dictionary<K, V> target, bool isOverride = false);
-
/// <summary>
-
/// 将字典的所有值放入一个列表
-
/// </summary>
-
/// <returns>列表</returns>
-
public static List<V> Value2List<K, V>(this Dictionary<K, V> self);
-
/// <summary>
-
/// 将字典的所有值放入一个数组
-
/// </summary>
-
/// <returns>数组</returns>
-
public static V[] Value2Array<K, V>(this Dictionary<K, V> self);
-
/// <summary>
-
/// 尝试添加
-
/// </summary>
-
/// <param name="k">键</param>
-
/// <param name="v">值</param>
-
/// <returns>若不存在相同键,添加成功并返回true,否则返回false</returns>
-
public static bool TryAdd<K, V>(this Dictionary<K, V> self, K k, V v);
Example
-
using UnityEngine;
-
using SK.Framework;
-
using System.Collections.Generic;
-
-
public class Example : MonoBehaviour
-
{
-
private void Start()
-
{
-
Dictionary<int, string> dic = new Dictionary<int, string>() { { 5, "AAA" }, { 10, "BBB" } };
-
-
//拷贝字典
-
Dictionary<int, string> copy = dic.Copy();
-
//遍历字典
-
dic.ForEach(m => Debug.Log(string.Format("Key{0} Value{1}", m.Key, m.Value)));
-
-
Dictionary<int, string> target = new Dictionary<int, string>() { { 11, "CCC" }, { 20, "DDD" } };
-
//合并字典
-
dic.AddRange(target);
-
-
//将字典的所有值放入到一个列表中
-
List<string> list = dic.Value2List();
-
//将字典的所有值放入到一个Array中
-
string[] array = dic.Value2Array();
-
-
//尝试添加
-
if (dic.TryAdd(20, "DDD")) Debug.Log("添加成功");
-
}
-
}
int
-
/// <summary>
-
/// 转化为字母 (1-26表示字母A-Z)
-
/// </summary>
-
/// <returns>字母字符</returns>
-
public static char ToLetter(this int self);
-
/// <summary>
-
/// 阶乘
-
/// </summary>
-
/// <returns>阶乘结果</returns>
-
public static int Fact(this int self);
Example
-
using UnityEngine;
-
using SK.Framework;
-
-
public class Example : MonoBehaviour
-
{
-
private void Start()
-
{
-
//转化为字母 => B
-
char letter = 2.ToLetter();
-
//阶乘 => 5 * 4 * 3 * 2 * 1
-
int fact = 5.Fact();
-
}
-
}
List
-
/// <summary>
-
/// 遍历
-
/// </summary>
-
/// <param name="action">遍历事件</param>
-
public static List<T> ForEach<T>(this List<T> self, Action<T> action);
-
/// <summary>
-
/// 遍历
-
/// </summary>
-
/// <param name="action">遍历事件</param>
-
public static List<T> ForEach<T>(this List<T> self, Action<int, T> action);
-
/// <summary>
-
/// 倒序遍历
-
/// </summary>
-
/// <param name="action">遍历事件</param>
-
public static List<T> ForEachReverse<T>(this List<T> self, Action<T> action);
-
/// <summary>
-
/// 倒序遍历
-
/// </summary>
-
/// <param name="action">遍历事件</param>
-
public static List<T> ForEachReverse<T>(this List<T> self, Action<int, T> action);
-
/// <summary>
-
/// 拷贝
-
/// </summary>
-
/// <returns>返回一个具有相同元素的新的列表</returns>
-
public static List<T> Copy<T>(this List<T> self);
-
/// <summary>
-
/// 尝试添加
-
/// </summary>
-
/// <param name="t">添加的目标</param>
-
/// <returns>添加成功返回true 否则返回false</returns>
-
public static bool TryAdd<T>(this List<T> self, T t);
Example
-
using UnityEngine;
-
using SK.Framework;
-
using System.Collections.Generic;
-
-
public class Example : MonoBehaviour
-
{
-
private void Start()
-
{
-
List<string> list = new List<string>() { "AAA", "BBB" };
-
-
//遍历
-
list.ForEach(m => Debug.Log(m));
-
//遍历
-
list.ForEach((i, m) => Debug.Log(string.Format("{0}.{1}", i + 1, m)));
-
//倒序遍历
-
list.ForEachReverse(m => Debug.Log(m));
-
//倒序遍历
-
list.ForEachReverse((i, m) => Debug.Log(string.Format("{0}.{1}", i + 1, m)));
-
-
//拷贝列表
-
List<string> copy = list.Copy();
-
-
//尝试添加
-
if (list.TryAdd("CCC")) Debug.Log("添加成功");
-
}
-
}
Queue
-
/// <summary>
-
/// 遍历
-
/// </summary>
-
/// <param name="action">遍历事件</param>
-
public static Queue<T> ForEach<T>(this Queue<T> self, Action<T> action);
-
/// <summary>
-
/// 合并 目标队列中的元素将依次出列被合并
-
/// </summary>
-
/// <param name="target">合并的目标</param>
-
public static Queue<T> Merge<T>(this Queue<T> self, Queue<T> target);
-
/// <summary>
-
/// 拷贝
-
/// </summary>
-
/// <returns>返回一个包含相同元素的新的队列</returns>
-
public static Queue<T> Copy<T>(this Queue<T> self);
Example
-
using UnityEngine;
-
using SK.Framework;
-
using System.Collections.Generic;
-
-
public class Example : MonoBehaviour
-
{
-
private void Start()
-
{
-
Queue<string> queue = new Queue<string>();
-
-
//遍历队列
-
queue.ForEach(m => Debug.Log(m));
-
-
Queue<string> target = new Queue<string>();
-
//合并队列
-
queue.Merge(target);
-
-
//拷贝队列
-
Queue<string> copy = queue.Copy();
-
}
-
}
Stack
-
/// <summary>
-
/// 遍历
-
/// </summary>
-
/// <param name="action">遍历事件</param>
-
public static Stack<T> ForEach<T>(this Stack<T> self, Action<T> action);
Example
-
using UnityEngine;
-
using SK.Framework;
-
using System.Collections.Generic;
-
-
public class Example : MonoBehaviour
-
{
-
private void Start()
-
{
-
Stack<string> stack = new Stack<string>();
-
//遍历
-
stack.ForEach(m => Debug.Log(m));
-
}
-
}
string
-
/// <summary>
-
/// 计算目标字符在字符串中出现的次数 不区分大小写
-
/// </summary>
-
/// <param name="target">目标字符</param>
-
/// <returns>次数</returns>
-
public static int CharCount(this string self, char target);
-
/// <summary>
-
/// 尝试转化为枚举
-
/// </summary>
-
/// <typeparam name="T">枚举类型</typeparam>
-
/// <returns>转化结果</returns>
-
public static T ToEnum<T>(this string self);
-
/// <summary>
-
/// 尝试转化为枚举
-
/// </summary>
-
/// <typeparam name="T">枚举类型</typeparam>
-
/// <param name="ignoreCase">是否忽略大小写</param>
-
/// <returns>转化结果</returns>
-
public static T ToEnum<T>(this string self, bool ignoreCase);
-
/// <summary>
-
/// 首字母大写
-
/// </summary>
-
/// <returns>字符串</returns>
-
public static string UppercaseFirst(this string self);
-
/// <summary>
-
/// 判断文件是否存在
-
/// </summary>
-
/// <returns>是否存在</returns>
-
public static bool FileExists(this string self);
-
/// <summary>
-
/// 根据路径删除文件
-
/// </summary>
-
/// <returns>删除结果</returns>
-
public static bool DeleteFile(this string self);
-
/// <summary>
-
/// 判断文件夹是否存在
-
/// </summary>
-
/// <returns>是否存在</returns>
-
public static bool DirectoryExists(this string self);
-
/// <summary>
-
/// 根据路径创建文件夹
-
/// </summary>
-
/// <returns>文件夹路径</returns>
-
public static string CreateDirectory(this string self);
-
/// <summary>
-
/// 根据路径删除文件夹
-
/// </summary>
-
/// <returns>删除结果</returns>
-
public static bool DeleteDirectory(this string self);
-
/// <summary>
-
/// 合并路径
-
/// </summary>
-
/// <param name="beCombined">被合并的路径</param>
-
/// <returns>合并后的路径</returns>
-
public static string PathCombine(this string self, string beCombined);
-
/// <summary>
-
/// 转化为base64字符串
-
/// </summary>
-
/// <returns>base64字符串</returns>
-
public static string ToBase64String(this string self);
-
/// <summary>
-
/// 判断字符串是否包含中文
-
/// </summary>
-
/// <param name="self">字符串</param>
-
/// <returns>若字符串包含中文返回true,否则返回false</returns>
-
public static bool IsContainChinese(this string self);
-
/// <summary>
-
/// 判断字符串是否为16进制数据
-
/// </summary>
-
/// <returns>若字符串符合16进制数据格式返回true,否则返回false</returns>
-
public static bool IsMatchHexadecimal(this string self);
-
/// <summary>
-
/// 判断字符串是否为url
-
/// </summary>
-
/// <returns>若字符串符合url地址格式返回true,否则返回false</returns>
-
public static bool IsMatchURL(this string self);
-
/// <summary>
-
/// 判断字符串是否为IP地址
-
/// </summary>
-
/// <returns>若字符串符合IP地址格式返回true,否则返回false</returns>
-
public static bool IsMatchIPAddress(this string self);
-
/// <summary>
-
/// 判断字符串是否为Email邮箱
-
/// </summary>
-
/// <returns>若字符串符合Email邮箱格式返回true,否则返回false</returns>
-
public static bool IsMatchEmail(this string self);
-
/// <summary>
-
/// 判断字符串是否为手机号码
-
/// </summary>
-
/// <returns>若字符串符合手机号码格式返回true,否则返回false</returns>
-
public static bool IsMatchMobilePhoneNumber(this string self);
Example
-
using UnityEngine;
-
using SK.Framework;
-
-
public class Example : MonoBehaviour
-
{
-
private void Start()
-
{
-
string str = "ABcaD";
-
//字符a在字符串中出现的次数 => 2
-
int count = str.CharCount('a');
-
//字符串转枚举
-
KeyCode a = "a".ToEnum<KeyCode>(true);
-
//首字母大写 => CoderZ
-
string fuc = "coderZ".UppercaseFirst();
-
-
string path = Application.dataPath + "/SKFramework/Cube.prefab";
-
//判断文件是否存在
-
bool fileExists = path.FileExists();
-
//根据路径删除文件
-
path.DeleteFile();
-
-
path = Application.dataPath + "/SKFramework";
-
//文件夹是否存在
-
bool dirExists = path.DirectoryExists();
-
//根据路径创建文件夹
-
path.CreateDirectory();
-
//根据路径删除文件夹
-
path.DeleteDirectory();
-
-
//路径合并
-
Application.dataPath.PathCombine("SKFramework");
-
-
//转化为Base64字符串
-
string base64 = str.ToBase64String();
-
-
//字符串是否包含中文
-
str.IsContainChinese();
-
//字符串是否为16进制数据
-
str.IsMatchHexadecimal();
-
//字符串是否是url链接
-
str.IsMatchURL();
-
//字符串是否是ip地址
-
str.IsMatchIPAddress();
-
//字符串是否为Eamil邮箱
-
str.IsMatchEmail();
-
//字符串是否为手机号码
-
str.IsMatchMobilePhoneNumber();
-
}
-
}
二、Unity
AudioSource
-
public static AudioSource SetClip(this AudioSource source, AudioClip clip);
-
public static AudioSource SetPitch(this AudioSource source, float pitch);
-
public static AudioSource SetPriority(this AudioSource source, int priority);
-
public static AudioSource SetLoop(this AudioSource source, bool loop);
-
public static AudioSource SetPlayOnAwake(this AudioSource source, bool playOnAwake);
-
public static AudioSource SetVolume(this AudioSource source, float volume);
-
public static AudioSource SetPanStereo(this AudioSource source, float panStereo);
-
public static AudioSource SetSpatialBlend(this AudioSource source, float spatialBlend);
-
public static AudioSource Play(this AudioSource source, AudioClip clip);
Example
-
using UnityEngine;
-
using SK.Framework;
-
-
public class Example : MonoBehaviour
-
{
-
private void Start()
-
{
-
new GameObject().AddComponent<AudioSource>()
-
.SetClip(null)
-
.SetVolume(.5f)
-
.SetPitch(1f)
-
.SetLoop(true)
-
.SetPlayOnAwake(false)
-
.SetPanStereo(0)
-
.SetSpatialBlend(0)
-
.SetPriority(128)
-
.Play();
-
}
-
}
Transform
-
public static T SetSiblingIndex<T>(this T self, int index) where T : Component;
-
public static T SetAsFirstSibling<T>(this T self) where T : Component;
-
public static T SetAsLastSibling<T>(this T self) where T : Component;
-
public static T GetSiblingIndex<T>(this T self, out int index) where T : Component;
-
public static T GetPosition<T>(this T self, out Vector3 position) where T : Component;
-
public static T SetPosition<T>(this T self, Vector3 pos) where T : Component;
-
public static T SetPosition<T>(this T self, float x, float y, float z) where T : Component;
-
public static T SetPositionX<T>(this T self, float x) where T : Component;
-
public static T SetPositionY<T>(this T self, float y) where T : Component;
-
public static T SetPositionZ<T>(this T self, float z) where T : Component;
-
public static T PositionIdentity<T>(this T self) where T : Component;
-
public static T RotationIdentity<T>(this T self) where T : Component;
-
public static T SetEulerAngles<T>(this T self, Vector3 eulerAngles) where T : Component;
-
public static T SetEulerAngles<T>(this T self, float x, float y, float z) where T : Component;
-
public static T SetEulerAnglesX<T>(this T self, float x) where T : Component;
-
public static T SetEulerAnglesY<T>(this T self, float y) where T : Component;
-
public static T SetEulerAnglesZ<T>(this T self, float z) where T : Component;
-
public static T EulerAnglesIdentity<T>(this T self) where T : Component;
-
public static T SetLocalPosition<T>(this T self, Vector3 localPos) where T : Component;
-
public static T SetLocalPosition<T>(this T self, float x, float y, float z) where T : Component;
-
public static T SetLocalPositionX<T>(this T self, float x) where T : Component;
-
public static T SetLocalPositionY<T>(this T self, float y) where T : Component;
-
public static T SetLocalPositionZ<T>(this T self, float z) where T : Component;
-
public static T LocalPositionIdentity<T>(this T self) where T : Component;
-
public static T LocalRotationIdentity<T>(this T self) where T : Component;
-
public static T SetLocalEulerAngles<T>(this T self, Vector3 localEulerAngles) where T : Component;
-
public static T SetLocalEulerAngles<T>(this T self, float x, float y, float z) where T : Component;
-
public static T SetLocalEulerAnglesX<T>(this T self, float x) where T : Component;
-
public static T SetLocalEulerAnglesY<T>(this T self, float y) where T : Component;
-
public static T SetLocalEulerAnglesZ<T>(this T self, float z) where T : Component;
-
public static T LocalEulerAnglesIdentity<T>(this T self) where T : Component;
-
public static T SetLocalScale<T>(this T self, Vector3 localScale) where T : Component;
-
public static T SetLocalScale<T>(this T self, float x, float y, float z) where T : Component;
-
public static T SetLocalScaleX<T>(this T self, float x) where T : Component;
-
public static T SetLocalScaleY<T>(this T self, float y) where T : Component;
-
public static T SetLocalScaleZ<T>(this T self, float z) where T : Component;
-
public static T LocalScaleIdentity<T>(this T self) where T : Component;
-
public static T Identity<T>(this T self) where T : Component;
-
public static T LocalIdentity<T>(this T self) where T : Component;
-
public static T SetParent<T>(this T self, Component parent, bool worldPositionStays = true) where T : Component;
-
public static T SetAsRootTransform<T>(this T self) where T : Component;
-
public static T DetachChildren<T>(this T self) where T : Component;
-
public static T LookAt<T>(this T self, Vector3 worldPosition) where T : Component;
-
public static T LookAt<T>(this T self, Vector3 worldPosition, Vector3 worldUp) where T : Component;
-
public static T LookAt<T>(this T self, Transform target) where T : Component;
-
public static T LookAt<T>(this T self, Transform target, Vector3 worldUp) where T : Component;
-
public static T Rotate<T>(this T self, Vector3 eulers) where T : Component;
-
public static T Rotate<T>(this T self, Vector3 eulers, Space relativeTo) where T : Component;
-
public static T Rotate<T>(this T self, Vector3 axis, float angle) where T : Component;
-
public static T Rotate<T>(this T self, Vector3 axis, float angle, Space relativeTo) where T : Component;
-
public static T Rotate<T>(this T self, float xAngle, float yAngle, float zAngle) where T : Component;
-
public static T Rotate<T>(this T self, float xAngle, float yAngle, float zAngle, Space relativeTo) where T : Component;
-
public static T CopyTransformValues<T>(this T self, Component target) where T : Component;
-
public static T GetFullName<T>(this T self, out string fullName) where T : Component;
-
public static T GetComponentOnChild<T>(this Transform self, int childIndex) where T : Component;
Example
-
using UnityEngine;
-
using SK.Framework;
-
-
public class Example : MonoBehaviour
-
{
-
private void Start()
-
{
-
new GameObject().transform
-
.SetPositionX(0f)
-
.SetPositionY(0f)
-
.SetPositionZ(0f)
-
.SetPosition(Vector3.zero)
-
.SetPosition(0f, 0f, 0f)
-
.PositionIdentity()
-
.SetEulerAnglesX(0f)
-
.SetEulerAnglesY(0f)
-
.SetEulerAnglesZ(0f)
-
.SetEulerAngles(Vector3.zero)
-
.SetEulerAngles(0f, 0f, 0f)
-
.EulerAnglesIdentity()
-
.SetLocalScaleX(1f)
-
.SetLocalScaleY(1f)
-
.SetLocalScaleZ(1f)
-
.SetLocalScale(Vector3.one)
-
.SetLocalScale(1f, 1f, 1f)
-
.LocalIdentity()
-
.Identity()
-
.LocalIdentity();
-
}
-
}
RectTransform
-
public static RectTransform SetAnchoredPosition(this RectTransform self, Vector2 anchoredPosition);
-
public static RectTransform SetAnchoredPosition(this RectTransform self, float x, float y);
-
public static RectTransform SetAnchoredPositionX(this RectTransform self, float x);
-
public static RectTransform SetAnchoredPositionY(this RectTransform self, float y);
-
public static RectTransform SetOffsetMax(this RectTransform self, Vector2 offsetMax);
-
public static RectTransform SetOffsetMax(this RectTransform self, float x, float y);
-
public static RectTransform SetOffsetMaxX(this RectTransform self, float x);
-
public static RectTransform SetOffsetMaxY(this RectTransform self, float y);
-
public static RectTransform SetOffsetMin(this RectTransform self, Vector2 offsetMin);
-
public static RectTransform SetOffsetMin(this RectTransform self, float x, float y);
-
public static RectTransform SetOffsetMinX(this RectTransform self, float x);
-
public static RectTransform SetOffsetMinY(this RectTransform self, float y);
-
public static RectTransform SetAnchoredPosition3D(this RectTransform self, Vector3 anchoredPosition3D);
-
public static RectTransform SetAnchoredPosition3D(this RectTransform self, float x, float y);
-
public static RectTransform SetAnchoredPosition3DX(this RectTransform self, float x);
-
public static RectTransform SetAnchoredPosition3DY(this RectTransform self, float y);
-
public static RectTransform SetAnchorMin(this RectTransform self, Vector2 anchorMin);
-
public static RectTransform SetAnchorMin(this RectTransform self, float x, float y);
-
public static RectTransform SetAnchorMinX(this RectTransform self, float x);
-
public static RectTransform SetAnchorMinY(this RectTransform self, float y);
-
public static RectTransform SetAnchorMax(this RectTransform self, Vector2 anchorMax);
-
public static RectTransform SetAnchorMax(this RectTransform self, float x, float y);
-
public static RectTransform SetAnchorMaxX(this RectTransform self, float x);
-
public static RectTransform SetAnchorMaxY(this RectTransform self, float y);
-
public static RectTransform SetPivot(this RectTransform self, Vector2 pivot);
-
public static RectTransform SetPivot(this RectTransform self, float x, float y);
-
public static RectTransform SetPivotX(this RectTransform self, float x);
-
public static RectTransform SetPivotY(this RectTransform self, float y);
-
public static RectTransform SetSizeDelta(this RectTransform self, Vector2 sizeDelta);
-
public static RectTransform SetSizeDelta(this RectTransform self, float x, float y);
-
public static RectTransform SetSizeDeltaX(this RectTransform self, float x);
-
public static RectTransform SetSizeDeltaY(this RectTransform self, float y);
-
public static RectTransform SetWidthWithCurrentAnchors(this RectTransform self, float width);
-
public static RectTransform SetHeightWithCurrentAnchors(this RectTransform self, float height);
Example
-
using UnityEngine;
-
using SK.Framework;
-
-
public class Example : MonoBehaviour
-
{
-
private void Start()
-
{
-
GetComponent<RectTransform>()
-
.SetAnchoredPositionX(0f)
-
.SetAnchoredPositionY(0f)
-
.SetAnchoredPosition(0f, 0f)
-
.SetAnchoredPosition(Vector2.zero)
-
.SetOffsetMaxX(0f)
-
.SetOffsetMaxY(0f)
-
.SetOffsetMax(0f, 0f)
-
.SetOffsetMax(Vector2.zero)
-
.SetOffsetMinX(0f)
-
.SetOffsetMinY(0f)
-
.SetOffsetMin(0f, 0f)
-
.SetOffsetMin(Vector2.zero)
-
.SetAnchoredPosition3DX(0f)
-
.SetAnchoredPosition3DY(0f)
-
.SetAnchoredPosition3D(0f, 0f)
-
.SetAnchoredPosition(Vector2.zero)
-
.SetAnchorMinX(0f)
-
.SetAnchorMinY(0f)
-
.SetAnchorMin(0f, 0f)
-
.SetAnchorMin(Vector2.zero)
-
.SetAnchorMaxX(0f)
-
.SetAnchorMaxY(0f)
-
.SetAnchorMax(0f, 0f)
-
.SetAnchorMax(Vector2.zero)
-
.SetPivotX(0f)
-
.SetPivotY(0f)
-
.SetPivot(0f, 0f)
-
.SetPivot(Vector2.zero)
-
.SetSizeDeltaX(0f)
-
.SetSizeDeltaY(0f)
-
.SetSizeDelta(0f, 0f)
-
.SetSizeDelta(Vector2.zero)
-
.SetWidthWithCurrentAnchors(0f)
-
.SetHeightWithCurrentAnchors(0f);
-
}
-
}
文章来源: coderz.blog.csdn.net,作者:CoderZ1010,版权归原作者所有,如需转载,请联系作者。
原文链接:coderz.blog.csdn.net/article/details/125064527
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)