123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using DG.Tweening;
- using System;
- public static class ChivaExtensions
- {
- public static void SetWidth(this RectTransform rectTrans, float width)
- {
- var size = rectTrans.sizeDelta;
- size.x = width;
- rectTrans.sizeDelta = size;
- }
- public static void SetHeight(this RectTransform rectTrans, float height)
- {
- var size = rectTrans.sizeDelta;
- size.y = height;
- rectTrans.sizeDelta = size;
- }
- public static void DoWidth(this RectTransform rectTrans, float width, float duration, TweenCallback callBack = null)
- {
- var size = rectTrans.sizeDelta;
- size.x = width;
- Tween tween = rectTrans.DOSizeDelta(size, duration);
- tween.onComplete += callBack;
- }
- public static void DoHeight(this RectTransform rectTrans, float height, float duration, TweenCallback callBack = null)
- {
- var size = rectTrans.sizeDelta;
- size.y = height;
- Tween tween = rectTrans.DOSizeDelta(size, duration);
- tween.onComplete += callBack;
- }
- public static void SetPositionX(this Transform t, float newX)
- {
- t.position = new Vector3(newX, t.position.y, t.position.z);
- }
- public static void SetPositionY(this Transform t, float newY)
- {
- t.position = new Vector3(t.position.x, newY, t.position.z);
- }
- public static void SetLocalPositionX(this Transform t, float newX)
- {
- t.localPosition = new Vector3(newX, t.localPosition.y, t.localPosition.z);
- }
- public static void SetLocalPositionY(this Transform t, float newY)
- {
- t.localPosition = new Vector3(t.localPosition.x, newY, t.localPosition.z);
- }
- public static void SetPositionZ(this Transform t, float newZ)
- {
- t.position = new Vector3(t.position.x, t.position.y, newZ);
- }
- public static void SetLocalPositionZ(this Transform t, float newZ)
- {
- t.localPosition = new Vector3(t.localPosition.x, t.localPosition.y, newZ);
- }
- public static void SetLocalScale(this Transform t, Vector3 newScale)
- {
- t.localScale = newScale;
- }
- public static void SetLocalScaleZero(this Transform t)
- {
- t.localScale = Vector3.zero;
- }
- public static float GetPositionX(this Transform t)
- {
- return t.position.x;
- }
- public static float GetPositionY(this Transform t)
- {
- return t.position.y;
- }
- public static float GetPositionZ(this Transform t)
- {
- return t.position.z;
- }
- public static float GetLocalPositionX(this Transform t)
- {
- return t.localPosition.x;
- }
- public static float GetLocalPositionY(this Transform t)
- {
- return t.localPosition.y;
- }
- public static float GetLocalPositionZ(this Transform t)
- {
- return t.localPosition.z;
- }
- public static bool HasRigidbody(this GameObject gobj)
- {
- return (gobj.GetComponent<Rigidbody>() != null);
- }
- public static bool HasAnimation(this GameObject gobj)
- {
- return (gobj.GetComponent<Animation>() != null);
- }
- public static void SetSpeed(this Animation anim, float newSpeed)
- {
- anim[anim.clip.name].speed = newSpeed;
- }
- public static Vector2 ToVector2(this Vector3 vec)
- {
- return new Vector2(vec.x, vec.y);
- }
- }
|