Readd missing import files

This commit is contained in:
Lucien
2026-05-07 10:14:44 +02:00
parent ecb44e63d8
commit cd608d5796
810 changed files with 263144 additions and 1 deletions
@@ -0,0 +1,208 @@
using UnityEngine;
using System.Collections;
namespace Wing.Utils
{
public class AnimationComponent : MonoBehaviour
{
/// <summary>
///
/// </summary>
/// <returns>true will play more once</returns>
public delegate bool TweenCompleteEventHandler();
public delegate void TweenUpdateEventHandler(float scale);
public event TweenCompleteEventHandler OnComplete;
public event TweenUpdateEventHandler OnUpdate;
public AnimationCurve m_pCurve;
private bool m_bPlaying = false;
public float Duration = 0;
private float m_fLastTime = 0;
private bool m_bAutoManager = false;
private float m_fMinValue = 0;
private float m_fMaxValue = 1;
/// <summary>
/// set replay times,default one times,equals zero means loop
/// </summary>
public uint RepeatTimes = 1;
private uint m_iHadRepeatTimes = 0;
public bool Revert { get; set; }
void Update()
{
if (m_pCurve == null)
{
m_pCurve = AnimationCurve.Linear(0, m_fMinValue, Duration, m_fMaxValue);
}
if (m_bPlaying)
{
if (m_fLastTime < Duration)
{
float time = Revert ? Duration - m_fLastTime : m_fLastTime;
float scale = m_pCurve.Evaluate(time);
if (OnUpdate != null)
{
OnUpdate(scale);
}
}
else
{
m_bPlaying = false;
if (OnUpdate != null)
{
OnUpdate(Revert ? m_fMinValue : m_fMaxValue);
}
bool end = true;
m_iHadRepeatTimes++;
if (RepeatTimes > 0)
{
if (RepeatTimes > m_iHadRepeatTimes)
{
end = false;
}
}
else
{
Play();
return;
}
if (end)
{
bool moreOnce = false;
if (OnComplete != null)
{
moreOnce = OnComplete();
if (moreOnce)
{
m_iHadRepeatTimes = RepeatTimes - 1;
Play();
}
}
if (m_bAutoManager && !moreOnce)
{
Destroy(this);
}
}
}
m_fLastTime += Time.deltaTime;
}
}
public void SetCurve(AnimationCurve curve, float duration = -1)
{
if (duration > 0)
{
SetDuration(duration);
}
float maxTime = float.MinValue;
float minTime = float.MaxValue;
float maxValue = float.MinValue;
float minValue = float.MaxValue;
foreach (Keyframe key in curve.keys)
{
if (maxTime < key.time)
{
maxTime = key.time;
}
if (minTime > key.time)
{
minTime = key.time;
}
if (maxValue < key.value)
{
maxValue = key.value;
}
if (minValue > key.value)
{
minValue = key.value;
}
}
float offsetTime = maxTime - minTime;
offsetTime = offsetTime == 0 ? 1 : maxTime - minTime;
float offsetValue = maxValue - minValue;
offsetValue = offsetValue == 0 ? 1 : offsetValue;
Keyframe[] keys = new Keyframe[curve.keys.Length];
float tv = offsetValue / offsetTime / Duration;
for (int i = 0; i < curve.keys.Length; i++)
{
Keyframe key = curve.keys[i];
float time = (key.time - minTime) * Duration / offsetTime;
float value = (key.value - minValue) / offsetValue;
keys[i] = new Keyframe(time, value, key.inTangent * tv, key.outTangent * tv);
}
if (keys.Length > 0)
{
m_pCurve = new AnimationCurve(keys);
m_pCurve.preWrapMode = curve.preWrapMode;
m_pCurve.postWrapMode = curve.postWrapMode;
}
}
public void SetDuration(float duration)
{
Duration = duration;
}
public AnimationComponent Play()
{
m_bPlaying = true;
m_fLastTime = 0;
m_iHadRepeatTimes = 0;
return this;
}
public void Stop()
{
m_bPlaying = false;
}
public static AnimationComponent AutoManagerTween(GameObject go, float duration)
{
AnimationComponent tween = go.AddComponent<AnimationComponent>();
tween.Duration = duration;
tween.m_bAutoManager = true;
return tween;
}
public AnimationComponent SetUpdate(TweenUpdateEventHandler handler)
{
OnUpdate += handler;
return this;
}
public AnimationComponent SetComplete(TweenCompleteEventHandler handler)
{
OnComplete += handler;
return this;
}
}
public static class AnimationComponentExt
{
public static AnimationComponent Tween(this GameObject go, float duration)
{
return AnimationComponent.AutoManagerTween(go, duration);
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e298cadf9846cd84b87633c6759bb064
timeCreated: 1481866179
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,17 @@
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class Billiboard : MonoBehaviour {
public Camera RenderCamera;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
this.transform.forward = RenderCamera.transform.forward;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d2c65d1d75ecf844a95768ec4c1f6333
timeCreated: 1481863066
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,12 @@
using UnityEngine;
namespace Wing.Utils
{
public class ElementTag : MonoBehaviour
{
public string ModuleName = "";
public string ID = "";
public int ElementType = 0;
public GameObject Target;
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: fac47bebf754d3844ab3afb3937686f8
timeCreated: 1481861944
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,66 @@
using UnityEngine;
using System.Collections;
namespace Wing.Utils
{
public class FreeCamera : MonoBehaviour
{
//for rotate
private float m_deltX = 0f;
private float m_deltY = 0f;
//for zoom
private float m_distance = 10f;
private float m_mSpeed = 5f;
void Start()
{
//GetComponent<Camera>().transform.localPosition = new Vector3(0, m_distance, 0);
}
void Update()
{
//鼠标右键点下控制相机旋转;
if (Input.GetMouseButton(1))
{
m_deltX += Input.GetAxis("Mouse X") * m_mSpeed;
m_deltY -= Input.GetAxis("Mouse Y") * m_mSpeed;
m_deltX = ClampAngle(m_deltX, -360, 360);
m_deltY = ClampAngle(m_deltY, -70, 70);
GetComponent<Camera>().transform.rotation = Quaternion.Euler(m_deltY, m_deltX, 0);
}
//鼠标中键点下场景缩放;
if (Input.GetAxis("Mouse ScrollWheel") != 0)
{
//自由缩放方式;
m_distance = Input.GetAxis("Mouse ScrollWheel") * 10f;
GetComponent<Camera>().transform.localPosition = GetComponent<Camera>().transform.position + GetComponent<Camera>().transform.forward * m_distance;
}
//鼠标点击场景移动;
if (Input.GetMouseButton(2))
{
var dx = -Input.GetAxis("Mouse X") * m_mSpeed * 0.1f;
var dy = -Input.GetAxis("Mouse Y") * m_mSpeed * 0.1f;
GetComponent<Camera>().transform.Translate(new Vector3(dx, dy));
}
//相机复位远点;
if (Input.GetKey(KeyCode.Space))
{
m_distance = 10.0f;
GetComponent<Camera>().transform.localPosition = new Vector3(0, m_distance, 0);
}
}
//规划角度;
float ClampAngle(float angle, float minAngle, float maxAgnle)
{
if (angle <= -360)
angle += 360;
if (angle >= 360)
angle -= 360;
return Mathf.Clamp(angle, minAngle, maxAgnle);
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a68dd72103bf88243af592974a4c92bf
timeCreated: 1481708155
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Wing.Utils
{
public class GemetryHelper
{
/// <summary>
/// 重新计算中心点
/// </summary>
/// <param name="raw"></param>
/// <param name="bounds"></param>
/// <returns></returns>
public static List<Vector3> PivotToZero(List<Vector3> raw, out Bounds bounds)
{
Vector3 min = Vector3.one * float.MaxValue;
Vector3 max = Vector3.one * float.MinValue;
for (int i = 0; i < raw.Count; i++)
{
Vector3 pt = raw[i];
min = Vector3.Min(pt, min);
max = Vector3.Max(pt, max);
}
Vector3 center = (max + min) / 2;
List<Vector3> pts = new List<Vector3>();
for (int i = 0; i < raw.Count; i++)
{
pts.Add(raw[i] - center);
}
bounds = new Bounds(center, max - min);
return pts;
}
public static float ValueMod(float value, float modValue)
{
float df = value / modValue;
int sign = df == 0 ? 1 : (int)(df / Mathf.Abs(df));
return ((int)(df + sign * 0.5f)) * modValue;
}
public static Vector3 Vector3Mod(Vector3 value, float modValue)
{
float dx = ValueMod(value.x, modValue);
float dy = ValueMod(value.y, modValue);
float dz = ValueMod(value.z, modValue);
return new Vector3(dx, dy, dz);
}
public static float VectorAngle(Vector2 from, Vector2 to)
{
float angle;
Vector3 cross = Vector3.Cross(from, to);
angle = Vector2.Angle(from, to);
return cross.y > 0 ? angle : -angle;
}
public static float VectorAngle(Vector3 from, Vector3 to)
{
float angle;
Vector3 cross = Vector3.Cross(from, to);
angle = Vector3.Angle(from, to);
return cross.y > 0 ? angle : -angle;
}
public static Vector3 ClosestPointOnLineExt(Vector3 a, Vector3 b, Vector3 point)
{
Vector3 v1 = point - a;
Vector3 v2 = (b - a).normalized;
float t = Vector3.Dot(v2, v1);
Vector3 v3 = v2 * t;
Vector3 closestPoint = a + v3;
return closestPoint;
}
public static Vector3 Mirror(Vector3 a, Vector3 b, Vector3 point)
{
Vector3 closestPoint = ClosestPointOnLineExt(a, b, point);
Vector3 v4 = closestPoint - point;
return v4 * 2 + point;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a2c4e1ac0e8006c448c6a9eb497a5d8e
timeCreated: 1481859113
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,58 @@
using UnityEngine;
using System.Collections;
using System;
namespace Wing.Utils
{
public class MonoSingleton<T> : MonoBehaviour where T : MonoBehaviour
{
protected static bool s_bEnableAutoCreate = true;
protected static T s_pInstance;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public virtual void Initialize()
{
}
public static T Instance
{
get
{
if (s_pInstance == null)
{
s_pInstance = GameObject.FindObjectOfType<T>();
if (s_pInstance == null && s_bEnableAutoCreate)
{
GameObject singleGO = GameObject.Find("Singletion");
if (singleGO == null)
{
singleGO = new GameObject("Singletion");
}
GameObject instanceObject = new GameObject(typeof(T).Name);
instanceObject.transform.SetParent(singleGO.transform);
s_pInstance = instanceObject.AddComponent<T>();
}
else if (s_pInstance == null)
{
//Debug.LogError("empty refrenced in this scene : " + typeof(T).Name);
}
}
return s_pInstance;
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 2ad23da74c9198f49ae86589dc322328
timeCreated: 1481706132
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,17 @@
using UnityEngine;
using System.Collections;
namespace Wing.Utils
{
public class NormalSingleton<T> where T : new()
{
protected static T s_pInstance = new T();
public static T Instance
{
get
{
return s_pInstance;
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 07fa2347ede9ded42a7662568a48edf4
timeCreated: 1481706131
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,232 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
namespace Wing.Utils
{
public enum EMouseButton
{
None = -1,
Left = 0,
Right = 1,
Middle = 2,
}
public class TouchInteraction : MonoBehaviour
{
public delegate void InteractionEventHandler(ElementTag tag);
public event InteractionEventHandler SelectedEvent;
public event InteractionEventHandler HoverTargetChangedEvent;
public delegate void InteractionEventHandlerEx(GameObject go);
public event InteractionEventHandlerEx SelectedGoEvent;
public event InteractionEventHandlerEx HoverGoTargetChangedEvent;
private Camera m_camera = null;
private int m_layerMask = 0;
private ElementTag m_currentTag = null;
private ElementTag m_lastTag = null;
private GameObject m_currentGameObject = null;
private bool mMouseDown = false;
private Vector3 mMousePos;
public KeyCode CurrentCode
{
get;
private set;
}
public EMouseButton CurrentMouseCode
{
get;
private set;
}
public bool IsShift
{
get;
private set;
}
public void Set(Camera camera, int layerMask)
{
m_camera = camera;
m_layerMask = layerMask;
}
void Awake()
{
m_camera = Camera.main;
m_layerMask = int.MaxValue;
}
void OnGUI()
{
if (Event.current != null && Input.anyKey)
{
IsShift = Event.current.shift;
if (Event.current.isKey)
{
CurrentCode = Event.current.keyCode;
}
if(Event.current.isMouse)
{
CurrentMouseCode = (EMouseButton)Event.current.button;
}
}
else
{
IsShift = false;
}
}
private void checkClick()
{
if (Input.GetMouseButtonDown(0))
{
mMouseDown = true;
mMousePos = Input.mousePosition;
}
else if (Input.GetMouseButtonUp(0))
{
var df = Input.mousePosition - mMousePos;
var dx = Mathf.Abs(df.x);
var dy = Mathf.Abs(df.y);
if (mMouseDown && (dx < 2f && dy < 2f))
{
OnClick();
}
mMouseDown = false;
}
}
void Update()
{
if (EventSystem.current != null && EventSystem.current.IsPointerOverGameObject())
{
return;
}
checkClick();
GameObject go = null;
if (Input.touches.Length > 0)
{
go = DetectiveGameObject(Input.touches[0].position);
}
else
{
go = DetectiveGameObject(Input.mousePosition);
}
if (go != m_currentGameObject)
{
if(HoverGoTargetChangedEvent != null)
{
HoverGoTargetChangedEvent(go);
}
ElementTag newTag = m_currentTag;
if (go != null)
{
newTag = go.GetComponent<ElementTag>();
}
else
{
newTag = null;
}
if(newTag != m_currentTag)
{
m_lastTag = m_currentTag;
m_currentTag = newTag;
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
if (m_lastTag != m_currentTag)
{
if (HoverTargetChangedEvent != null)
{
HoverTargetChangedEvent(m_currentTag);
}
}
#endif
}
}
m_currentGameObject = go;
}
public ElementTag CurrentSelectedTag
{
get
{
return m_currentTag;
}
}
public ElementTag LastSelectedTag
{
get
{
return m_lastTag;
}
}
public void Destroy()
{
GameObject.Destroy(this);
}
private void OnClick()
{
if(SelectedGoEvent != null)
{
SelectedGoEvent(m_currentGameObject);
}
if (m_currentTag != null && SelectedEvent != null)
{
SelectedEvent(m_currentTag);
}
}
public GameObject DetectiveGameObject(Vector2 screenPoint)
{
Ray ray = m_camera.ScreenPointToRay(new Vector3(screenPoint.x, screenPoint.y, 0));
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo, 1000 , m_layerMask))
{
GameObject go = hitInfo.collider.gameObject;
return go;
}
return null;
}
public ElementTag DetectiveTag(Vector2 screenPoint)
{
Ray ray = m_camera.ScreenPointToRay(new Vector3(screenPoint.x, screenPoint.y, 0));
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo, 1000, m_layerMask))
{
GameObject go = hitInfo.collider.gameObject;
ElementTag tag = go.GetComponent<ElementTag>();
//MaterialSetter setter = new MaterialSetter(tag.Element.ObjInstance);
//setter.Set("Custom/Outline");
return tag;
}
return null;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 699d5a36f36a84548a12b43db6237424
timeCreated: 1481861921
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Wing.Utils
{
public static class UnityExt
{
public static Mesh GetMesh(this GameObject go)
{
var filter = go.GetComponent<MeshFilter>();
if (filter == null)
{
return null;
}
return filter.mesh;
}
public static void SetRectTransformSize(this RectTransform trans, Vector2 newSize)
{
Vector2 oldSize = trans.rect.size;
Vector2 deltaSize = newSize - oldSize;
trans.offsetMin = trans.offsetMin - new Vector2(deltaSize.x * trans.pivot.x, deltaSize.y * trans.pivot.y);
trans.offsetMax = trans.offsetMax + new Vector2(deltaSize.x * (1f - trans.pivot.x), deltaSize.y * (1f - trans.pivot.y));
}
public static void SetLayerWithChildren(this GameObject go, string layer)
{
var lyr = LayerMask.NameToLayer(layer);
go.layer = lyr;
var children = go.transform.GetComponentsInChildren<Transform>();
foreach(var c in children)
{
c.gameObject.layer = lyr;
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 20e480b51978648408644331c61e4b1b
timeCreated: 1481707497
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Wing.Utils
{
public static class UtilsExt
{
public static int ToInt(this string s)
{
int ret = 0;
int.TryParse(s, out ret);
return ret;
}
public static float ToFloat(this string s)
{
float ret = 0;
float.TryParse(s, out ret);
return ret;
}
public static Color32 Encode2Color32(this int value,bool renderBack = true)
{
Color32 c = new Color32();
c.r = (byte)((value & 0x000000FF) >> 0);
c.g = (byte)((value & 0x0000FF00) >> 8);
c.b = (byte)((value & 0x00FF0000) >> 16);
c.a = (byte)(renderBack ? 0xFF : 0);
return c;
}
public static int Encode2Int(this Color32 value)
{
int r = value.r << 0;
int g = value.g << 8;
int b = value.b << 16;
return r | g | b;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cc7ef0dd44821e74683d228d898c2081
timeCreated: 1481706627
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,176 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using UnityEngine;
namespace Wing.Utils
{
public class UtilsHelper
{
public static string GetDataPath()
{
string path = "";
if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
{
path = Application.persistentDataPath + "/";
}
else if (Application.platform == RuntimePlatform.WindowsPlayer)
{
path = Application.dataPath + "/";
}
else if (Application.platform == RuntimePlatform.WindowsEditor)
{
path = Application.dataPath + "/../";
}
else
{
path = Application.persistentDataPath + "/";
}
return path;
}
public static string GetResourcePath()
{
return GetDataPath() + "ResData";
}
public static IEnumerator LoadTexture(string url, Action<Texture2D> cb)
{
//这里的url可以是web路径也可以是本地路径file://
WWW www = new WWW(url);
//挂起程序段,等资源下载完成后,继续执行下去
yield return www;
//判断是否有错误产生
if (string.IsNullOrEmpty(www.error))
{
//把下载好的图片回调给调用者
cb.Invoke(www.texture);
//释放资源
www.Dispose();
}
}
public static IEnumerator Load(string url, Action<WWW> cb)
{
//这里的url可以是web路径也可以是本地路径file://
WWW www = new WWW(url);
//挂起程序段,等资源下载完成后,继续执行下去
yield return www;
//判断是否有错误产生
if (string.IsNullOrEmpty(www.error))
{
//把下载好的图片回调给调用者
cb.Invoke(www);
//释放资源
www.Dispose();
}
}
public static IEnumerator Load(string url, Action<WWW,object> cb, object data)
{
//这里的url可以是web路径也可以是本地路径file://
WWW www = new WWW(url);
//挂起程序段,等资源下载完成后,继续执行下去
yield return www;
//判断是否有错误产生
if (string.IsNullOrEmpty(www.error))
{
//把下载好的图片回调给调用者
cb.Invoke(www, data);
//释放资源
www.Dispose();
}
}
public static IEnumerator LoadAssetBundle(string url, Action<AssetBundle> ab)
{
WWW www = new WWW(url);
yield return www;
if (string.IsNullOrEmpty(www.error))
{
ab.Invoke(www.assetBundle);
www.Dispose();
}
}
public static string StringMD5(string data)
{
byte[] result = Encoding.Default.GetBytes(data.Trim());
MD5 md5 = new MD5CryptoServiceProvider();
byte[] output = md5.ComputeHash(result);
return BitConverter.ToString(output).Replace("-", "");
}
public static void SaveTextureFile(Texture2D incomingTexture, string filename)
{
byte[] bytes = incomingTexture.EncodeToPNG();
string dir = Path.GetDirectoryName(filename);
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
File.WriteAllBytes(filename, bytes);
}
public static bool SaveRenderTextureToPNG(Texture inputTex, Material mat, string filename)
{
RenderTexture temp = RenderTexture.GetTemporary(inputTex.width, inputTex.height, 0, RenderTextureFormat.ARGB32);
Graphics.Blit(inputTex, temp, mat);
bool ret = SaveRenderTextureToPNG(temp, filename);
RenderTexture.ReleaseTemporary(temp);
return ret;
}
public static bool SaveRenderTextureToPNG(RenderTexture rt, string filename)
{
Texture2D png = CreateTexture2DFromRT(rt);
SaveTextureFile(png, filename);
Texture2D.DestroyImmediate(png);
png = null;
return true;
}
public static Texture2D CreateTexture2DFromRT(RenderTexture rt, Rect? rect = null)
{
RenderTexture prev = RenderTexture.active;
RenderTexture.active = rt;
if(rect == null)
{
rect = new Rect(0, 0, rt.width, rt.height);
}
else
{
float width = rect.Value.width;
if(rect.Value.width + rect.Value.x > rt.width)
{
width = rt.width - rect.Value.x;
}
float height = rect.Value.height;
if(rect.Value.height + rect.Value.y > rt.height)
{
height = rt.height - rect.Value.y;
}
rect = new Rect(rect.Value.x, rect.Value.y, width, height);
}
Texture2D texture = new Texture2D((int)rect.Value.width, (int)rect.Value.height, TextureFormat.ARGB32, false);
texture.ReadPixels(rect.Value, 0 , 0);
texture.Apply();
RenderTexture.active = prev;
return texture;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 37a9d8249de2a464782f47451e9b5336
timeCreated: 1481706748
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: