init
53
Assets/Dreamteck/Utilities/ArrayUtility.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
namespace Dreamteck
|
||||
{
|
||||
public static class ArrayUtility
|
||||
{
|
||||
public static void Add<T>(ref T[] array, T item)
|
||||
{
|
||||
T[] newArray = new T[array.Length + 1];
|
||||
array.CopyTo(newArray, 0);
|
||||
newArray[newArray.Length - 1] = item;
|
||||
array = newArray;
|
||||
}
|
||||
public static bool Contains<T>(T[] array, T item)
|
||||
{
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
if (array[i].Equals(item)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static int IndexOf<T>(T[] array, T value)
|
||||
{
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
if (array[i].Equals(value)) return i;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public static void Insert<T>(ref T[] array, int index, T item)
|
||||
{
|
||||
T[] newArray = new T[array.Length + 1];
|
||||
for (int i = 0; i < newArray.Length; i++)
|
||||
{
|
||||
if (i < index) newArray[i] = array[i];
|
||||
else if (i > index) newArray[i] = array[i - 1];
|
||||
else newArray[i] = item;
|
||||
}
|
||||
array = newArray;
|
||||
}
|
||||
|
||||
|
||||
public static void RemoveAt<T>(ref T[] array, int index)
|
||||
{
|
||||
if (array.Length == 0) return;
|
||||
T[] newArray = new T[array.Length - 1];
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
if (i < index) newArray[i] = array[i];
|
||||
else if (i > index) newArray[i-1] = array[i];
|
||||
}
|
||||
array = newArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Dreamteck/Utilities/ArrayUtility.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82febc9d0aa4907478f53a8dd5e86318
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
126
Assets/Dreamteck/Utilities/DMath.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System;
|
||||
|
||||
namespace Dreamteck
|
||||
{
|
||||
public static class DMath
|
||||
{
|
||||
public static double Sin(double a)
|
||||
{
|
||||
return Math.Sin(a);
|
||||
}
|
||||
|
||||
public static double Cos(double a)
|
||||
{
|
||||
return Math.Cos(a);
|
||||
}
|
||||
|
||||
public static double Tan(double a)
|
||||
{
|
||||
return Math.Tan(a);
|
||||
}
|
||||
|
||||
public static double Pow(double x, double y)
|
||||
{
|
||||
return Math.Pow(x, y);
|
||||
}
|
||||
|
||||
public static double Log(double a, double newBase)
|
||||
{
|
||||
return Math.Log(a, newBase);
|
||||
}
|
||||
|
||||
public static double Log10(double a)
|
||||
{
|
||||
return Math.Log10(a);
|
||||
}
|
||||
|
||||
public static double Clamp01(double a)
|
||||
{
|
||||
if (a > 1.0) return 1.0;
|
||||
if (a < 0.0) return 0.0;
|
||||
return a;
|
||||
}
|
||||
|
||||
public static double Clamp(double a, double min, double max)
|
||||
{
|
||||
if (a > max) return max;
|
||||
if (a < min) return min;
|
||||
return a;
|
||||
}
|
||||
|
||||
public static double Lerp(double a, double b, double t)
|
||||
{
|
||||
t = Clamp01(t);
|
||||
return a + (b - a) * t;
|
||||
}
|
||||
|
||||
public static double InverseLerp(double a, double b, double t)
|
||||
{
|
||||
if (a == b) return 0.0;
|
||||
return Clamp01((t-a)/(b-a));
|
||||
}
|
||||
|
||||
public static Vector3 LerpVector3(Vector3 a, Vector3 b, double t)
|
||||
{
|
||||
t = Clamp01(t);
|
||||
Vector3 delta = (b - a);
|
||||
double x = a.x + delta.x * t;
|
||||
double y = a.y + delta.y * t;
|
||||
double z = a.z + delta.z * t;
|
||||
return new Vector3((float)x, (float)y, (float)z);
|
||||
}
|
||||
|
||||
public static double Round(double a)
|
||||
{
|
||||
return Math.Round(a);
|
||||
}
|
||||
|
||||
public static int RoundInt(double a)
|
||||
{
|
||||
return (int)Math.Round(a);
|
||||
}
|
||||
|
||||
public static double Ceil(double a)
|
||||
{
|
||||
return Math.Ceiling(a);
|
||||
}
|
||||
|
||||
public static int CeilInt(double a)
|
||||
{
|
||||
return (int)Math.Ceiling(a);
|
||||
}
|
||||
|
||||
public static double Floor(double a)
|
||||
{
|
||||
return Math.Floor(a);
|
||||
}
|
||||
|
||||
public static int FloorInt(double a)
|
||||
{
|
||||
return (int)Math.Floor(a);
|
||||
}
|
||||
|
||||
public static double Move(double current, double target, double amount)
|
||||
{
|
||||
if (target > current)
|
||||
{
|
||||
current += amount;
|
||||
if (current > target) return target;
|
||||
}
|
||||
else
|
||||
{
|
||||
current -= amount;
|
||||
if (current < target) return target;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
public static double Abs(double a)
|
||||
{
|
||||
if (a < 0.0) return a * -1.0;
|
||||
return a;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Dreamteck/Utilities/DMath.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 012b8f43a890d8248b810901033c66a3
|
||||
timeCreated: 1460233822
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
24
Assets/Dreamteck/Utilities/DuplicateUtility.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Dreamteck
|
||||
{
|
||||
public static class DuplicateUtility
|
||||
{
|
||||
public static AnimationCurve DuplicateCurve(AnimationCurve input)
|
||||
{
|
||||
AnimationCurve target = new AnimationCurve();
|
||||
target.postWrapMode = input.postWrapMode;
|
||||
target.preWrapMode = input.preWrapMode;
|
||||
for (int i = 0; i < input.keys.Length; i++) target.AddKey(input.keys[i]);
|
||||
return target;
|
||||
}
|
||||
|
||||
public static Gradient DuplicateGradient(Gradient input)
|
||||
{
|
||||
//yet to implement
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Dreamteck/Utilities/DuplicateUtility.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a72578399b94604b8ad3f608ef130ea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Assets/Dreamteck/Utilities/Editor.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 749c0646beaeed74da9787854fe67f79
|
||||
folderAsset: yes
|
||||
timeCreated: 1522397143
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
743
Assets/Dreamteck/Utilities/Editor/AudioUtility.cs
Normal file
@@ -0,0 +1,743 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Dreamteck.Blenda.Editor {
|
||||
public static class AudioUtility {
|
||||
|
||||
public static void PlayClip(AudioClip clip , int startSample , bool loop) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"PlayClip",
|
||||
BindingFlags.Static | BindingFlags.Public,
|
||||
null,
|
||||
new System.Type[] {
|
||||
typeof(AudioClip),
|
||||
typeof(Int32),
|
||||
typeof(Boolean)
|
||||
},
|
||||
null
|
||||
);
|
||||
method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip,
|
||||
startSample,
|
||||
loop
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static void PlayClip(AudioClip clip , int startSample) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"PlayClip",
|
||||
BindingFlags.Static | BindingFlags.Public,
|
||||
null,
|
||||
new System.Type[] {
|
||||
typeof(AudioClip),
|
||||
typeof(Int32)
|
||||
},
|
||||
null
|
||||
);
|
||||
method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip,
|
||||
startSample
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static void PlayClip(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"PlayClip",
|
||||
BindingFlags.Static | BindingFlags.Public,
|
||||
null,
|
||||
new System.Type[] {
|
||||
typeof(AudioClip)
|
||||
},
|
||||
null
|
||||
);
|
||||
method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static void StopClip(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"StopClip",
|
||||
BindingFlags.Static | BindingFlags.Public,
|
||||
null,
|
||||
new System.Type[] {
|
||||
typeof(AudioClip)
|
||||
},
|
||||
null
|
||||
);
|
||||
method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static void PauseClip(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"PauseClip",
|
||||
BindingFlags.Static | BindingFlags.Public,
|
||||
null,
|
||||
new System.Type[] {
|
||||
typeof(AudioClip)
|
||||
},
|
||||
null
|
||||
);
|
||||
method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static void ResumeClip(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"ResumeClip",
|
||||
BindingFlags.Static | BindingFlags.Public,
|
||||
null,
|
||||
new System.Type[] {
|
||||
typeof(AudioClip)
|
||||
},
|
||||
null
|
||||
);
|
||||
method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static void LoopClip(AudioClip clip , bool on) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"LoopClip",
|
||||
BindingFlags.Static | BindingFlags.Public,
|
||||
null,
|
||||
new System.Type[] {
|
||||
typeof(AudioClip),
|
||||
typeof(bool)
|
||||
},
|
||||
null
|
||||
);
|
||||
method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip,
|
||||
on
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static bool IsClipPlaying(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"IsClipPlaying",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
bool playing = (bool)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip,
|
||||
}
|
||||
);
|
||||
|
||||
return playing;
|
||||
}
|
||||
|
||||
public static void StopAllClips () {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"StopAllClips",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
method.Invoke(
|
||||
null,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
public static float GetClipPosition(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetClipPosition",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
float position = (float)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip
|
||||
}
|
||||
);
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
public static int GetClipSamplePosition(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetClipSamplePosition",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
int position = (int)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip
|
||||
}
|
||||
);
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
public static void SetClipSamplePosition(AudioClip clip , int iSamplePosition) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"SetClipSamplePosition",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip,
|
||||
iSamplePosition
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static int GetSampleCount(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetSampleCount",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
int samples = (int)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip
|
||||
}
|
||||
);
|
||||
|
||||
return samples;
|
||||
}
|
||||
|
||||
public static int GetChannelCount(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetChannelCount",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
int channels = (int)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip
|
||||
}
|
||||
);
|
||||
|
||||
return channels;
|
||||
}
|
||||
|
||||
public static int GetBitRate(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetChannelCount",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
int bitRate = (int)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip
|
||||
}
|
||||
);
|
||||
|
||||
return bitRate;
|
||||
}
|
||||
|
||||
public static int GetBitsPerSample(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetBitsPerSample",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
int bits = (int)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip
|
||||
}
|
||||
);
|
||||
|
||||
return bits;
|
||||
}
|
||||
|
||||
public static int GetFrequency(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetFrequency",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
int frequency = (int)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip
|
||||
}
|
||||
);
|
||||
|
||||
return frequency;
|
||||
}
|
||||
|
||||
public static int GetSoundSize(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetSoundSize",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
int size = (int)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip
|
||||
}
|
||||
);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
public static Texture2D GetWaveForm(AudioClip clip , int channel , float width , float height) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod("GetWaveForm", BindingFlags.Static | BindingFlags.Public);
|
||||
string path = AssetDatabase.GetAssetPath(clip);
|
||||
AudioImporter importer = (AudioImporter)AssetImporter.GetAtPath(path);
|
||||
Texture2D texture = (Texture2D)method.Invoke(null, new object[] {clip, importer, channel, width, height});
|
||||
return texture;
|
||||
}
|
||||
|
||||
public static Texture2D GetWaveFormFast(AudioClip clip , int channel , int fromSample , int toSample, float width , float height) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod("GetWaveFormFast", BindingFlags.Static | BindingFlags.Public);
|
||||
Texture2D texture = (Texture2D)method.Invoke(null, new object[] { clip, channel, fromSample, toSample, width, height });
|
||||
return texture;
|
||||
}
|
||||
|
||||
public static void ClearWaveForm(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod("ClearWaveForm", BindingFlags.Static | BindingFlags.Public);
|
||||
method.Invoke(null, new object[] { clip });
|
||||
}
|
||||
|
||||
public static bool HasPreview(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetSoundSize",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
bool hasPreview = (bool)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip
|
||||
}
|
||||
);
|
||||
|
||||
return hasPreview;
|
||||
}
|
||||
|
||||
public static bool IsCompressed(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"IsCompressed",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
bool isCompressed = (bool)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip
|
||||
}
|
||||
);
|
||||
|
||||
return isCompressed;
|
||||
}
|
||||
|
||||
public static bool IsStramed(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"IsStramed",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
bool isStreamed = (bool)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip
|
||||
}
|
||||
);
|
||||
|
||||
return isStreamed;
|
||||
}
|
||||
|
||||
public static double GetDuration(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetDuration",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
double duration = (double)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip
|
||||
}
|
||||
);
|
||||
|
||||
return duration;
|
||||
}
|
||||
|
||||
public static int GetFMODMemoryAllocated() {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetFMODMemoryAllocated",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
int memoryAllocated = (int)method.Invoke(
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
return memoryAllocated;
|
||||
}
|
||||
|
||||
public static float GetFMODCPUUsage() {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetFMODCPUUsage",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
float cpuUsage = (float)method.Invoke(
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
return cpuUsage;
|
||||
}
|
||||
|
||||
public static bool Is3D(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"Is3D",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
bool is3D = (bool)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip
|
||||
}
|
||||
);
|
||||
|
||||
return is3D;
|
||||
}
|
||||
|
||||
public static bool IsMovieAudio(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"IsMovieAudio",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
bool isMovieAudio = (bool)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip
|
||||
}
|
||||
);
|
||||
|
||||
return isMovieAudio;
|
||||
}
|
||||
|
||||
public static bool IsMOD(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"IsMOD",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
bool isMOD = (bool)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip
|
||||
}
|
||||
);
|
||||
|
||||
return isMOD;
|
||||
}
|
||||
|
||||
public static int GetMODChannelCount() {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetMODChannelCount",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
int channels = (int)method.Invoke(
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
return channels;
|
||||
}
|
||||
|
||||
public static AnimationCurve GetLowpassCurve(AudioLowPassFilter lowPassFilter) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetLowpassCurve",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
AnimationCurve curve = (AnimationCurve)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
lowPassFilter
|
||||
}
|
||||
);
|
||||
|
||||
return curve;
|
||||
}
|
||||
|
||||
public static Vector3 GetListenerPos() {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetListenerPos",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
Vector3 position = (Vector3)method.Invoke(
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
public static void UpdateAudio() {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"UpdateAudio",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
method.Invoke(
|
||||
null,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
public static void SetListenerTransform(Transform t) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"SetListenerTransform",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
t
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public static AudioType GetClipType(AudioClip clip) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetClipType",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
AudioType type = (AudioType)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
clip
|
||||
}
|
||||
);
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
public static AudioType GetPlatformConversionType(AudioType inType , BuildTargetGroup targetGroup , AudioCompressionFormat format) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetPlatformConversionType",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
AudioType type = (AudioType)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
inType,
|
||||
targetGroup,
|
||||
format
|
||||
}
|
||||
);
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
public static bool HaveAudioCallback(MonoBehaviour behaviour) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"HaveAudioCallback",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
bool hasCallback = (bool)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
behaviour
|
||||
}
|
||||
);
|
||||
|
||||
return hasCallback;
|
||||
}
|
||||
|
||||
public static int GetCustomFilterChannelCount(MonoBehaviour behaviour) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetCustomFilterChannelCount",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
int channels = (int)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
behaviour
|
||||
}
|
||||
);
|
||||
|
||||
return channels;
|
||||
}
|
||||
|
||||
public static int GetCustomFilterProcessTime(MonoBehaviour behaviour) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetCustomFilterProcessTime",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
int processTime = (int)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
behaviour
|
||||
}
|
||||
);
|
||||
|
||||
return processTime;
|
||||
}
|
||||
|
||||
public static float GetCustomFilterMaxIn(MonoBehaviour behaviour , int channel) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetCustomFilterMaxIn",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
float maxIn = (float)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
behaviour,
|
||||
channel
|
||||
}
|
||||
);
|
||||
|
||||
return maxIn;
|
||||
}
|
||||
|
||||
public static float GetCustomFilterMaxOut(MonoBehaviour behaviour , int channel) {
|
||||
Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
|
||||
Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
|
||||
MethodInfo method = audioUtilClass.GetMethod(
|
||||
"GetCustomFilterMaxOut",
|
||||
BindingFlags.Static | BindingFlags.Public
|
||||
);
|
||||
|
||||
float maxOut = (float)method.Invoke(
|
||||
null,
|
||||
new object[] {
|
||||
behaviour,
|
||||
channel
|
||||
}
|
||||
);
|
||||
|
||||
return maxOut;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Assets/Dreamteck/Utilities/Editor/AudioUtility.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7999cc19883fd6488211f59f41f4ae1
|
||||
timeCreated: 1511002726
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
199
Assets/Dreamteck/Utilities/Editor/DreamteckEditorGUI.cs
Normal file
@@ -0,0 +1,199 @@
|
||||
namespace Dreamteck
|
||||
{
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
using System.Reflection;
|
||||
using Type = System.Type;
|
||||
#endif
|
||||
|
||||
public static class DreamteckEditorGUI
|
||||
{
|
||||
public static Texture2D blankImage
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_blankImage == null)
|
||||
{
|
||||
_blankImage = new Texture2D(1, 1);
|
||||
_blankImage.SetPixel(0, 0, Color.white);
|
||||
_blankImage.Apply();
|
||||
}
|
||||
return _blankImage;
|
||||
}
|
||||
}
|
||||
private static Texture2D _blankImage = null;
|
||||
|
||||
public static readonly Color backgroundColor = new Color(0.95f, 0.95f, 0.95f);
|
||||
public static Color iconColor = Color.black;
|
||||
|
||||
public static readonly Color highlightColor = new Color(0f, 0.564f, 1f, 1f);
|
||||
public static readonly Color highlightContentColor = new Color(1f, 1f, 1f, 0.95f);
|
||||
|
||||
|
||||
public static readonly Color inactiveColor = new Color(0.7f, 0.7f, 0.7f, 0.5f);
|
||||
public static readonly Color activeColor = new Color(1f, 1f, 1f, 1f);
|
||||
|
||||
public static readonly Color baseColor = Color.white;
|
||||
public static readonly Color lightColor = Color.white;
|
||||
public static readonly Color lightDarkColor = Color.white;
|
||||
public static readonly Color darkColor = Color.white;
|
||||
public static readonly Color borderColor = Color.white;
|
||||
|
||||
private static string[] layerNames = new string[0];
|
||||
private static int[] layerIndices = new int[0];
|
||||
|
||||
public static readonly GUIStyle labelText = null;
|
||||
private static float scale = -1f;
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
private static MethodInfo gradientFieldMethod;
|
||||
#endif
|
||||
|
||||
static DreamteckEditorGUI()
|
||||
{
|
||||
baseColor = EditorGUIUtility.isProSkin ? new Color32(56, 56, 56, 255) : new Color32(194, 194, 194, 255);
|
||||
lightColor = EditorGUIUtility.isProSkin ? new Color32(84, 84, 84, 255) : new Color32(222, 222, 222, 255);
|
||||
lightDarkColor = EditorGUIUtility.isProSkin ? new Color32(30, 30, 30, 255) : new Color32(180, 180, 180, 255);
|
||||
darkColor = EditorGUIUtility.isProSkin ? new Color32(15, 15, 15, 255) : new Color32(152, 152, 152, 255);
|
||||
borderColor = EditorGUIUtility.isProSkin ? new Color32(5, 5, 5, 255) : new Color32(100, 100, 100, 255);
|
||||
backgroundColor = baseColor;
|
||||
backgroundColor -= new Color(0.1f, 0.1f, 0.1f, 0f);
|
||||
iconColor = GUI.skin.label.normal.textColor;
|
||||
|
||||
labelText = new GUIStyle(GUI.skin.GetStyle("label"));
|
||||
labelText.fontStyle = FontStyle.Bold;
|
||||
labelText.alignment = TextAnchor.MiddleRight;
|
||||
labelText.normal.textColor = Color.white;
|
||||
SetScale(1f);
|
||||
|
||||
#if !UNITY_2018_3_OR_NEWER
|
||||
Type tyEditorGUILayout = typeof(EditorGUILayout);
|
||||
gradientFieldMethod = tyEditorGUILayout.GetMethod("GradientField", BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { typeof(string), typeof(Gradient), typeof(GUILayoutOption[]) }, null);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void SetScale(float newScale)
|
||||
{
|
||||
if (scale == newScale) return;
|
||||
scale = newScale;
|
||||
labelText.fontSize = Mathf.RoundToInt(12f * scale);
|
||||
}
|
||||
|
||||
public static void Label(Rect position, string text, bool active = true, GUIStyle style = null)
|
||||
{
|
||||
if (style == null) style = labelText;
|
||||
if (!active) GUI.color = inactiveColor;
|
||||
else GUI.color = activeColor;
|
||||
GUI.color = new Color(0f, 0f, 0f, GUI.color.a * 0.5f);
|
||||
GUI.Label(new Rect(position.x - 1, position.y + 1, position.width, position.height), text, style);
|
||||
if (!active) GUI.color = inactiveColor;
|
||||
else GUI.color = activeColor;
|
||||
GUI.Label(position, text, style);
|
||||
}
|
||||
|
||||
public static LayerMask LayermaskField(string name, LayerMask input)
|
||||
{
|
||||
int layersCount = 0;
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
if (LayerMask.LayerToName(i) != "") layersCount++;
|
||||
}
|
||||
if(layerNames.Length != layersCount)
|
||||
{
|
||||
layerNames = new string[layersCount];
|
||||
layerIndices = new int[layersCount];
|
||||
}
|
||||
int index = 0;
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
string layerName = LayerMask.LayerToName(i);
|
||||
if (layerName != null)
|
||||
{
|
||||
if (index >= layerName.Length) continue;
|
||||
layerNames[index] = layerName;
|
||||
layerIndices[index] = i;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
int maskWithoutEmpty = 0;
|
||||
for (int i = 0; i < layerIndices.Length; i++)
|
||||
{
|
||||
if (((1 << layerIndices[i]) & input.value) > 0)
|
||||
maskWithoutEmpty |= (1 << i);
|
||||
}
|
||||
maskWithoutEmpty = EditorGUILayout.MaskField(name, maskWithoutEmpty, layerNames);
|
||||
int mask = 0;
|
||||
for (int i = 0; i < layerIndices.Length; i++)
|
||||
{
|
||||
if ((maskWithoutEmpty & (1 << i)) > 0)
|
||||
mask |= (1 << layerIndices[i]);
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
public static bool DropArea<T>(Rect rect, out T[] content)
|
||||
{
|
||||
content = new T[0];
|
||||
switch (Event.current.type)
|
||||
{
|
||||
case EventType.DragUpdated:
|
||||
case EventType.DragPerform:
|
||||
if (!rect.Contains(Event.current.mousePosition)) return false;
|
||||
|
||||
DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
|
||||
|
||||
if (Event.current.type == EventType.DragPerform)
|
||||
{
|
||||
DragAndDrop.AcceptDrag();
|
||||
List<T> contentList = new List<T>();
|
||||
foreach (object dragged_object in DragAndDrop.objectReferences)
|
||||
{
|
||||
if (dragged_object is GameObject)
|
||||
{
|
||||
GameObject gameObject = (GameObject)dragged_object;
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
bool isNotAprefab = PrefabUtility.GetPrefabAssetType(gameObject) == PrefabAssetType.NotAPrefab;
|
||||
#else
|
||||
bool isNotAprefab = PrefabUtility.GetPrefabType(gameObject) == PrefabType.None;
|
||||
#endif
|
||||
|
||||
if (isNotAprefab)
|
||||
{
|
||||
if (gameObject.GetComponent<T>() != null) contentList.Add(gameObject.GetComponent<T>());
|
||||
}
|
||||
}
|
||||
}
|
||||
content = contentList.ToArray();
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static Gradient GradientField(string label, Gradient gradient, params GUILayoutOption[] options)
|
||||
{
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
return EditorGUILayout.GradientField(label, gradient, options);
|
||||
#else
|
||||
gradient = (Gradient)gradientFieldMethod.Invoke(null, new object[] { label, gradient, options });
|
||||
return gradient;
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void DrawSeparator()
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.FlexibleSpace();
|
||||
Rect rect = GUILayoutUtility.GetRect(Screen.width / 2f, 2f);
|
||||
EditorGUI.DrawRect(rect, darkColor);
|
||||
GUILayout.FlexibleSpace();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Dreamteck/Utilities/Editor/DreamteckEditorGUI.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee0eafe76311d094680308d7a6735a26
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
110
Assets/Dreamteck/Utilities/Editor/EditorGUIEvents.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Dreamteck
|
||||
{
|
||||
public class EditorGUIEvents
|
||||
{
|
||||
public bool mouseLeft = false;
|
||||
public bool mouseRight = false;
|
||||
public bool mouseLeftDown = false;
|
||||
public bool mouseRightDown = false;
|
||||
public bool mouseLeftUp = false;
|
||||
public bool mouseRightUp = false;
|
||||
public bool control = false;
|
||||
public bool shift = false;
|
||||
public bool alt = false;
|
||||
public bool enterDown = false;
|
||||
public Vector2 mousPos = Vector2.zero;
|
||||
public Vector2 lastClickPoint = Vector2.zero;
|
||||
public Vector2 mouseClickDelta
|
||||
{
|
||||
get
|
||||
{
|
||||
return Event.current.mousePosition - lastClickPoint;
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void CommandHandler(string command);
|
||||
public delegate void KeyCodeHandler(KeyCode code);
|
||||
public delegate void MouseHandler(int button);
|
||||
public delegate void EmptyHandler();
|
||||
|
||||
public event CommandHandler onCommand;
|
||||
public event KeyCodeHandler onkeyDown;
|
||||
public event KeyCodeHandler onKeyUp;
|
||||
public event MouseHandler onMouseDown;
|
||||
public event MouseHandler onMouseUp;
|
||||
|
||||
public void Use()
|
||||
{
|
||||
mouseLeft = false;
|
||||
mouseRight = false;
|
||||
mouseLeftDown = false;
|
||||
mouseRightDown = false;
|
||||
mouseLeftUp = false;
|
||||
mouseRightUp = false;
|
||||
control = false;
|
||||
shift = false;
|
||||
alt = false;
|
||||
Event.current.Use();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
ListenInput(Event.current);
|
||||
}
|
||||
|
||||
public void Update(Event current)
|
||||
{
|
||||
ListenInput(current);
|
||||
}
|
||||
|
||||
void ListenInput(Event e)
|
||||
{
|
||||
//int controlID = GUIUtility.GetControlID(FocusType.Passive);
|
||||
mousPos = e.mousePosition;
|
||||
mouseLeftDown = mouseLeftUp = mouseRightDown = mouseRightUp = false;
|
||||
control = e.control;
|
||||
shift = e.shift;
|
||||
alt = e.alt;
|
||||
enterDown = false;
|
||||
switch (e.type)
|
||||
{
|
||||
case EventType.MouseDown:
|
||||
if (e.button == 0)
|
||||
{
|
||||
mouseLeftDown = true;
|
||||
mouseLeft = true;
|
||||
lastClickPoint = e.mousePosition;
|
||||
}
|
||||
if (e.button == 1) mouseRightDown = mouseRight = true;
|
||||
if (onMouseDown != null) onMouseDown(e.button);
|
||||
break;
|
||||
case EventType.MouseUp:
|
||||
if (e.button == 0)
|
||||
{
|
||||
mouseLeftUp = true;
|
||||
mouseLeft = false;
|
||||
}
|
||||
if (e.button == 1)
|
||||
{
|
||||
mouseRightDown = true;
|
||||
mouseRight = false;
|
||||
}
|
||||
if (onMouseUp != null) onMouseUp(e.button);
|
||||
break;
|
||||
|
||||
case EventType.KeyDown:
|
||||
if (onkeyDown != null) onkeyDown(e.keyCode);
|
||||
if (e.keyCode == KeyCode.Return || e.keyCode == KeyCode.KeypadEnter) enterDown = true;
|
||||
break;
|
||||
|
||||
case EventType.KeyUp:
|
||||
if (onKeyUp != null) onKeyUp(e.keyCode);
|
||||
break;
|
||||
}
|
||||
if (onCommand != null && e.commandName != "") onCommand(e.commandName);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Dreamteck/Utilities/Editor/EditorGUIEvents.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15a36dd80a7895246ae6870b7124a571
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
53
Assets/Dreamteck/Utilities/Editor/FindDerivedClasses.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Dreamteck
|
||||
{
|
||||
public static class FindDerivedClasses
|
||||
{
|
||||
public static List<Type> GetAllDerivedClasses(this Type aBaseClass, string[] aExcludeAssemblies)
|
||||
{
|
||||
List<Type> result = new List<Type>();
|
||||
foreach (Assembly A in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
if (A is System.Reflection.Emit.AssemblyBuilder) continue;
|
||||
bool exclude = false;
|
||||
foreach (string S in aExcludeAssemblies)
|
||||
{
|
||||
if (A.GetName().FullName.StartsWith(S))
|
||||
{
|
||||
exclude = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (exclude)
|
||||
continue;
|
||||
if (aBaseClass.IsInterface)
|
||||
{
|
||||
foreach (Type C in A.GetExportedTypes())
|
||||
foreach (Type I in C.GetInterfaces())
|
||||
if (aBaseClass == I)
|
||||
{
|
||||
result.Add(C);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (Type C in A.GetExportedTypes())
|
||||
if (C.IsSubclassOf(aBaseClass))
|
||||
result.Add(C);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<Type> GetAllDerivedClasses(this Type aBaseClass)
|
||||
{
|
||||
return GetAllDerivedClasses(aBaseClass, new string[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Dreamteck/Utilities/Editor/FindDerivedClasses.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 12a29dbe4d6c3f648aae86fce0402487
|
||||
timeCreated: 1450553632
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
10
Assets/Dreamteck/Utilities/Editor/Images.meta
Normal file
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa46a23fd0180d240bea350783ff82b5
|
||||
folderAsset: yes
|
||||
timeCreated: 1522493680
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Dreamteck/Utilities/Editor/Images/changelog.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
107
Assets/Dreamteck/Utilities/Editor/Images/changelog.png.meta
Normal file
@@ -0,0 +1,107 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 703957d2518de2c47a715a045b142ec6
|
||||
timeCreated: 1522535496
|
||||
licenseType: Store
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
externalObjects: {}
|
||||
serializedVersion: 4
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 0
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: -1
|
||||
aniso: 1
|
||||
mipBias: -1
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: -1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 100
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 2
|
||||
textureShape: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
platformSettings:
|
||||
- buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- buildTarget: WebGL
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
spritePackingTag:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Dreamteck/Utilities/Editor/Images/discord.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
107
Assets/Dreamteck/Utilities/Editor/Images/discord.png.meta
Normal file
@@ -0,0 +1,107 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca2ec96e04914514ca532b6d55c85db4
|
||||
timeCreated: 1522493758
|
||||
licenseType: Store
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
externalObjects: {}
|
||||
serializedVersion: 4
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 0
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: -1
|
||||
aniso: 1
|
||||
mipBias: -1
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: -1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 1
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 100
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 2
|
||||
textureShape: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
platformSettings:
|
||||
- buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- buildTarget: WebGL
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
spritePackingTag:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Dreamteck/Utilities/Editor/Images/examples.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
107
Assets/Dreamteck/Utilities/Editor/Images/examples.png.meta
Normal file
@@ -0,0 +1,107 @@
|
||||
fileFormatVersion: 2
|
||||
guid: efab8674905315440a387b05c0ce5ff4
|
||||
timeCreated: 1522534229
|
||||
licenseType: Store
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
externalObjects: {}
|
||||
serializedVersion: 4
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 0
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: -1
|
||||
aniso: 1
|
||||
mipBias: -1
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: -1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 100
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 2
|
||||
textureShape: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
platformSettings:
|
||||
- buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- buildTarget: WebGL
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
spritePackingTag:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Dreamteck/Utilities/Editor/Images/get_started.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
107
Assets/Dreamteck/Utilities/Editor/Images/get_started.png.meta
Normal file
@@ -0,0 +1,107 @@
|
||||
fileFormatVersion: 2
|
||||
guid: af24004f75afd39469d2be2087678650
|
||||
timeCreated: 1522495632
|
||||
licenseType: Store
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
externalObjects: {}
|
||||
serializedVersion: 4
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 0
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: -1
|
||||
aniso: 1
|
||||
mipBias: -1
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: -1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 100
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 2
|
||||
textureShape: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
platformSettings:
|
||||
- buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- buildTarget: WebGL
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
spritePackingTag:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Dreamteck/Utilities/Editor/Images/manual.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
112
Assets/Dreamteck/Utilities/Editor/Images/manual.png.meta
Normal file
@@ -0,0 +1,112 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7004b4ab0ebf5ea43bd227e21913ba75
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 10
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: -1
|
||||
aniso: 1
|
||||
mipBias: -100
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: -1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 2
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 2
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- serializedVersion: 2
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- serializedVersion: 2
|
||||
buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Dreamteck/Utilities/Editor/Images/playmaker.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
107
Assets/Dreamteck/Utilities/Editor/Images/playmaker.png.meta
Normal file
@@ -0,0 +1,107 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ad88cea831f74448b8fbce9f906c4ae
|
||||
timeCreated: 1522495786
|
||||
licenseType: Store
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
externalObjects: {}
|
||||
serializedVersion: 4
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 0
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: -1
|
||||
aniso: 1
|
||||
mipBias: -1
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: -1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 100
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 2
|
||||
textureShape: 1
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
platformSettings:
|
||||
- buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- buildTarget: WebGL
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
spritePackingTag:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Dreamteck/Utilities/Editor/Images/rate.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
59
Assets/Dreamteck/Utilities/Editor/Images/rate.png.meta
Normal file
@@ -0,0 +1,59 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d408c4aeee3cf742a05436998ade025
|
||||
timeCreated: 1477248547
|
||||
licenseType: Store
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
serializedVersion: 2
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
linearTexture: 1
|
||||
correctGamma: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 0
|
||||
cubemapConvolution: 0
|
||||
cubemapConvolutionSteps: 7
|
||||
cubemapConvolutionExponent: 1.5
|
||||
seamlessCubemap: 0
|
||||
textureFormat: -1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
filterMode: -1
|
||||
aniso: 1
|
||||
mipBias: -1
|
||||
wrapMode: 1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
rGBM: 0
|
||||
compressionQuality: 50
|
||||
allowsAlphaSplitting: 0
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 100
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 2
|
||||
buildTargetSettings: []
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
spritePackingTag:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Dreamteck/Utilities/Editor/Images/support.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
59
Assets/Dreamteck/Utilities/Editor/Images/support.png.meta
Normal file
@@ -0,0 +1,59 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 645a8bd65986fe24d863511d1d8ddc60
|
||||
timeCreated: 1477247161
|
||||
licenseType: Store
|
||||
TextureImporter:
|
||||
fileIDToRecycleName: {}
|
||||
serializedVersion: 2
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
linearTexture: 1
|
||||
correctGamma: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 0
|
||||
cubemapConvolution: 0
|
||||
cubemapConvolutionSteps: 7
|
||||
cubemapConvolutionExponent: 1.5
|
||||
seamlessCubemap: 0
|
||||
textureFormat: -1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
filterMode: -1
|
||||
aniso: 1
|
||||
mipBias: -1
|
||||
wrapMode: 1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
rGBM: 0
|
||||
compressionQuality: 50
|
||||
allowsAlphaSplitting: 0
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spritePixelsToUnits: 100
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 2
|
||||
buildTargetSettings: []
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
spritePackingTag:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Dreamteck/Utilities/Editor/Images/tutorials.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
112
Assets/Dreamteck/Utilities/Editor/Images/tutorials.png.meta
Normal file
@@ -0,0 +1,112 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c2813fa4a97ab442b80f29592282375
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 10
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: -1
|
||||
aniso: 1
|
||||
mipBias: -100
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: -1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 0
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 2
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 2
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- serializedVersion: 2
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
- serializedVersion: 2
|
||||
buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID:
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
55
Assets/Dreamteck/Utilities/Editor/Toolbar.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
namespace Dreamteck.Editor
|
||||
{
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
public class Toolbar
|
||||
{
|
||||
GUIContent[] shownContent;
|
||||
GUIContent[] allContent;
|
||||
public bool center = true;
|
||||
public bool newLine = true;
|
||||
public float elementWidth = 0f;
|
||||
public float elementHeight = 23f;
|
||||
|
||||
public Toolbar(GUIContent[] iconsNormal, GUIContent[] iconsSelected, float elementWidth = 0f)
|
||||
{
|
||||
this.elementWidth = elementWidth;
|
||||
if(iconsNormal.Length != iconsSelected.Length)
|
||||
{
|
||||
Debug.LogError("Invalid icon count for toolbar ");
|
||||
return;
|
||||
}
|
||||
allContent = new GUIContent[iconsNormal.Length * 2];
|
||||
shownContent = new GUIContent[iconsNormal.Length];
|
||||
iconsNormal.CopyTo(allContent, 0);
|
||||
iconsSelected.CopyTo(allContent, iconsNormal.Length);
|
||||
}
|
||||
|
||||
public void SetContent(int index, GUIContent content)
|
||||
{
|
||||
allContent[index] = content;
|
||||
allContent[shownContent.Length + index] = content;
|
||||
}
|
||||
|
||||
public void SetContent(int index, GUIContent content, GUIContent contentSelected)
|
||||
{
|
||||
allContent[index] = content;
|
||||
allContent[shownContent.Length + index] = contentSelected;
|
||||
}
|
||||
|
||||
public void Draw(ref int selected)
|
||||
{
|
||||
for (int i = 0; i < shownContent.Length; i++)
|
||||
{
|
||||
shownContent[i] = selected == i ? allContent[shownContent.Length + i] : allContent[i];
|
||||
}
|
||||
if(newLine) EditorGUILayout.BeginHorizontal();
|
||||
if(center) GUILayout.FlexibleSpace();
|
||||
if(elementWidth > 0f) selected = GUILayout.Toolbar(selected, shownContent, GUILayout.Width(elementWidth * shownContent.Length), GUILayout.Height(elementHeight));
|
||||
else selected = GUILayout.Toolbar(selected, shownContent, GUILayout.Height(elementHeight));
|
||||
if (center) GUILayout.FlexibleSpace();
|
||||
if (newLine) EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Dreamteck/Utilities/Editor/Toolbar.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a9993d76bca1dcd47a94ad14a6eaf2f5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
377
Assets/Dreamteck/Utilities/Editor/WelcomeWindow.cs
Normal file
@@ -0,0 +1,377 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Dreamteck
|
||||
{
|
||||
public class WelcomeWindow : EditorWindow
|
||||
{
|
||||
public delegate void EmptyHandler();
|
||||
protected WindowPanel[] panels = new WindowPanel[0];
|
||||
protected Texture2D header;
|
||||
private bool init = false;
|
||||
protected static GUIStyle wrapText;
|
||||
protected static GUIStyle buttonTitleText;
|
||||
protected static GUIStyle warningText;
|
||||
protected static GUIStyle titleText;
|
||||
protected string headerTitle = "";
|
||||
|
||||
public virtual void Load()
|
||||
{
|
||||
init = false;
|
||||
minSize = maxSize = new Vector2(450, 500);
|
||||
}
|
||||
|
||||
protected virtual void SetTitle(string titleBar, string header)
|
||||
{
|
||||
titleContent = new GUIContent(titleBar);
|
||||
headerTitle = header;
|
||||
}
|
||||
|
||||
protected virtual void GetHeader()
|
||||
{
|
||||
header = null;
|
||||
}
|
||||
|
||||
protected void OnGUI()
|
||||
{
|
||||
if (!init)
|
||||
{
|
||||
buttonTitleText = new GUIStyle(GUI.skin.GetStyle("label"));
|
||||
buttonTitleText.fontStyle = FontStyle.Bold;
|
||||
titleText = new GUIStyle(GUI.skin.GetStyle("label"));
|
||||
titleText.fontSize = 25;
|
||||
titleText.fontStyle = FontStyle.Bold;
|
||||
titleText.alignment = TextAnchor.MiddleLeft;
|
||||
titleText.normal.textColor = Color.white;
|
||||
warningText = new GUIStyle(GUI.skin.GetStyle("label"));
|
||||
warningText.fontSize = 18;
|
||||
warningText.fontStyle = FontStyle.Bold;
|
||||
warningText.normal.textColor = Color.red;
|
||||
warningText.alignment = TextAnchor.MiddleCenter;
|
||||
wrapText = new GUIStyle(GUI.skin.GetStyle("label"));
|
||||
wrapText.wordWrap = true;
|
||||
Load();
|
||||
init = true;
|
||||
}
|
||||
|
||||
if (header == null) GetHeader();
|
||||
GUI.DrawTexture(new Rect(0, 0, maxSize.x, 82), header, ScaleMode.StretchToFill);
|
||||
GUI.Label(new Rect(90, 15, Screen.width - 95, 50), headerTitle, titleText);
|
||||
for (int i = 0; i < panels.Length; i++) panels[i].Draw();
|
||||
|
||||
Repaint();
|
||||
}
|
||||
|
||||
public class WindowPanel
|
||||
{
|
||||
public WindowPanel back = null;
|
||||
public float slideStart = 0f;
|
||||
public float slideDuration = 1f;
|
||||
public enum SlideDiretion { Left, Right, Up, Down }
|
||||
public SlideDiretion openDirection = SlideDiretion.Left;
|
||||
public SlideDiretion closeDirection = SlideDiretion.Right;
|
||||
private Vector2 origin = Vector2.zero;
|
||||
private bool open = false;
|
||||
private bool goingBack = false;
|
||||
public List<Element> elements = new List<Element>();
|
||||
|
||||
public WindowPanel(string title, bool o, float slideDur = 1f)
|
||||
{
|
||||
slideDuration = slideDur;
|
||||
SetState(o, false);
|
||||
}
|
||||
|
||||
public WindowPanel(string title, bool o, WindowPanel backPanel, float slideDur = 1f)
|
||||
{
|
||||
slideDuration = slideDur;
|
||||
SetState(o, false);
|
||||
back = backPanel;
|
||||
}
|
||||
|
||||
public bool isActive
|
||||
{
|
||||
get
|
||||
{
|
||||
return open || Time.realtimeSinceStartup - slideStart <= slideDuration;
|
||||
}
|
||||
}
|
||||
|
||||
public void Back()
|
||||
{
|
||||
Close(true, true);
|
||||
back.Open(true, true);
|
||||
}
|
||||
|
||||
public void Close(bool useTransition, bool goBack = false)
|
||||
{
|
||||
SetState(false, useTransition, goBack);
|
||||
}
|
||||
|
||||
public void Open(bool useTransition, bool goBack = false)
|
||||
{
|
||||
goingBack = false;
|
||||
SetState(true, useTransition, goBack);
|
||||
}
|
||||
|
||||
Vector2 GetSize()
|
||||
{
|
||||
return new Vector2(Screen.width, Screen.height- 82);
|
||||
}
|
||||
|
||||
void HandleOrigin()
|
||||
{
|
||||
float percent = Mathf.Clamp01((Time.realtimeSinceStartup - slideStart) / slideDuration);
|
||||
Vector2 size = GetSize();
|
||||
SlideDiretion dir = openDirection;
|
||||
if (goingBack) dir = closeDirection;
|
||||
if (open)
|
||||
{
|
||||
switch (dir)
|
||||
{
|
||||
case SlideDiretion.Left:
|
||||
origin.x = Mathf.SmoothStep(size.x, 0f, percent);
|
||||
origin.y = 0f;
|
||||
break;
|
||||
|
||||
case SlideDiretion.Right:
|
||||
origin.x = Mathf.SmoothStep(-size.x, 0f, percent);
|
||||
origin.y = 0f;
|
||||
break;
|
||||
|
||||
case SlideDiretion.Up:
|
||||
origin.x = 0f;
|
||||
origin.y = Mathf.SmoothStep(size.y, 0f, percent);
|
||||
break;
|
||||
|
||||
case SlideDiretion.Down:
|
||||
origin.x = 0f;
|
||||
origin.y = Mathf.SmoothStep(-size.y, 0f, percent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (dir)
|
||||
{
|
||||
case SlideDiretion.Left:
|
||||
origin.x = Mathf.SmoothStep(0f, -size.x, percent);
|
||||
origin.y = 0f;
|
||||
break;
|
||||
|
||||
case SlideDiretion.Right:
|
||||
origin.x = Mathf.SmoothStep(0f, size.x, percent);
|
||||
origin.y = 0f;
|
||||
break;
|
||||
|
||||
case SlideDiretion.Up:
|
||||
origin.x = 0f;
|
||||
origin.y = Mathf.SmoothStep(0f, -size.y, percent);
|
||||
break;
|
||||
|
||||
case SlideDiretion.Down:
|
||||
origin.x = 0f;
|
||||
origin.y = Mathf.SmoothStep(0f, -size.y, percent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SetState(bool state, bool useTransition, bool goBack = false)
|
||||
{
|
||||
if (open == state) return;
|
||||
open = state;
|
||||
if (useTransition) slideStart = Time.realtimeSinceStartup;
|
||||
else slideStart = Time.realtimeSinceStartup + slideDuration;
|
||||
goingBack = goBack;
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
if (!isActive) return;
|
||||
HandleOrigin();
|
||||
Vector2 size = GetSize();
|
||||
GUILayout.BeginArea(new Rect(origin.x + 25, origin.y + 85, size.x - 25, size.y));
|
||||
//Back button
|
||||
if (back != null)
|
||||
{
|
||||
if (GUILayout.Button("◄", GUILayout.Width(45), GUILayout.Height(25)))
|
||||
{
|
||||
Back();
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < elements.Count; i++) elements[i].Draw();
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
|
||||
|
||||
public class Element
|
||||
{
|
||||
protected Vector2 size = Vector2.zero;
|
||||
public ActionLink action = null;
|
||||
|
||||
public Element(float x, float y, ActionLink a = null)
|
||||
{
|
||||
size = new Vector2(x, y);
|
||||
action = a;
|
||||
}
|
||||
|
||||
internal virtual void Draw()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class Space : Element
|
||||
{
|
||||
public Space(float x, float y) : base(x, y)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal override void Draw()
|
||||
{
|
||||
GUILayoutUtility.GetRect(size.x, size.y);
|
||||
}
|
||||
}
|
||||
|
||||
public class Button : Element
|
||||
{
|
||||
string text = "";
|
||||
|
||||
public Button(float x, float y, string t, ActionLink a) : base(x, y, a)
|
||||
{
|
||||
text = t;
|
||||
}
|
||||
|
||||
internal override void Draw()
|
||||
{
|
||||
base.Draw();
|
||||
if(GUILayout.Button(text, GUILayout.Width(size.x), GUILayout.Height(size.y)))
|
||||
{
|
||||
if (action != null) action.Do();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class Thumbnail : Element
|
||||
{
|
||||
private string thumbnailPath = "";
|
||||
private string thumbnailName = "";
|
||||
private Texture2D thumbnail = null;
|
||||
public string title = "";
|
||||
public string description = "";
|
||||
|
||||
public Thumbnail(string path, string fileName, string t, string d, ActionLink a, float x = 400, float y = 50) : base(x, y, a)
|
||||
{
|
||||
title = t;
|
||||
description = d;
|
||||
thumbnailPath = path;
|
||||
thumbnailName = fileName;
|
||||
thumbnail = ImageDB.GetImage(thumbnailName, thumbnailPath);
|
||||
}
|
||||
|
||||
internal override void Draw()
|
||||
{
|
||||
Rect rect = GUILayoutUtility.GetRect(size.x, size.y);
|
||||
Color buttonColor = Color.clear;
|
||||
if (rect.Contains(Event.current.mousePosition)) buttonColor = Color.white;
|
||||
GUI.BeginGroup(rect);
|
||||
GUI.color = buttonColor;
|
||||
if (GUI.Button(new Rect(0, 0, size.x, size.y), "")) action.Do();
|
||||
GUI.color = Color.white;
|
||||
if (thumbnail != null) GUI.DrawTexture(new Rect(0, 0, 50, 50), thumbnail, ScaleMode.StretchToFill);
|
||||
GUI.Label(new Rect(60, 5, 370 - 65, 16), title, buttonTitleText);
|
||||
GUI.Label(new Rect(60, 20, 370 - 65, 40), description, wrapText);
|
||||
GUI.EndGroup();
|
||||
GUILayout.Space(10);
|
||||
}
|
||||
}
|
||||
|
||||
public class ScrollText : Element
|
||||
{
|
||||
Vector2 scroll = Vector2.zero;
|
||||
string text = "";
|
||||
|
||||
public ScrollText(float x, float y, string t) : base(x, y)
|
||||
{
|
||||
text = t;
|
||||
}
|
||||
|
||||
internal override void Draw()
|
||||
{
|
||||
base.Draw();
|
||||
scroll = GUILayout.BeginScrollView(scroll, GUILayout.Width(size.x), GUILayout.MaxHeight(size.y));
|
||||
EditorGUILayout.LabelField(text, wrapText, GUILayout.Width(size.x - 30));
|
||||
GUILayout.EndScrollView();
|
||||
}
|
||||
}
|
||||
|
||||
public class Label : Element
|
||||
{
|
||||
string text = "";
|
||||
Color color;
|
||||
GUIStyle style = null;
|
||||
public Label(string t, GUIStyle s, Color col) : base(400, 30)
|
||||
{
|
||||
color = col;
|
||||
text = t;
|
||||
style = s;
|
||||
}
|
||||
|
||||
public Label(string t, GUIStyle s, Color col, float x, float y) : base(x, y)
|
||||
{
|
||||
color = col;
|
||||
text = t;
|
||||
style = s;
|
||||
}
|
||||
|
||||
internal override void Draw()
|
||||
{
|
||||
base.Draw();
|
||||
Color prev = GUI.color;
|
||||
GUI.color = color;
|
||||
if(style == null) EditorGUILayout.LabelField(text, GUILayout.Width(size.x), GUILayout.Height(size.y));
|
||||
else EditorGUILayout.LabelField(text, style, GUILayout.Width(size.x), GUILayout.Height(size.y));
|
||||
GUI.color = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ActionLink {
|
||||
private string URL = "";
|
||||
private WindowPanel currentPanel = null;
|
||||
private WindowPanel targetPanel = null;
|
||||
private EmptyHandler customHandler = null;
|
||||
|
||||
public ActionLink(string u)
|
||||
{
|
||||
URL = u;
|
||||
}
|
||||
|
||||
public ActionLink(EmptyHandler handler)
|
||||
{
|
||||
customHandler = handler;
|
||||
}
|
||||
|
||||
public ActionLink(WindowPanel target, WindowPanel current)
|
||||
{
|
||||
currentPanel = current;
|
||||
targetPanel = target;
|
||||
}
|
||||
|
||||
public void Do()
|
||||
{
|
||||
if (customHandler != null) customHandler();
|
||||
else if(URL != "") Application.OpenURL(URL);
|
||||
else if(targetPanel != null && currentPanel != null)
|
||||
{
|
||||
currentPanel.Close(true);
|
||||
targetPanel.Open(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
13
Assets/Dreamteck/Utilities/Editor/WelcomeWindow.cs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bada76b30269a9144848e487cf253360
|
||||
timeCreated: 1522397149
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
74
Assets/Dreamteck/Utilities/ImageDB.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Dreamteck
|
||||
{
|
||||
public static class ImageDB
|
||||
{
|
||||
private static List<Texture2D> images = new List<Texture2D>();
|
||||
|
||||
public static Texture2D GetImage(string name, string searchDir = "")
|
||||
{
|
||||
for (int i = 0; i < images.Count; i++)
|
||||
{
|
||||
if (images[i] == null)
|
||||
{
|
||||
images.RemoveAt(i);
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
if (images[i].name.ToLower() == name.ToLower()) return images[i];
|
||||
}
|
||||
if (searchDir != "") return LoadImage(searchDir, name);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Texture2D LoadImage(string localDirectory, string filename)
|
||||
{
|
||||
Texture2D image = ResourceUtility.LoadTexture(localDirectory, filename);
|
||||
if (image != null)
|
||||
{
|
||||
images.Add(image);
|
||||
return images[images.Count - 1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void LoadImages(string localDirectory, string[] names)
|
||||
{
|
||||
for (int i = 0; i < names.Length; i++)
|
||||
{
|
||||
images.Add(ResourceUtility.LoadTexture(localDirectory, names[i]));
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadImages(string localDirectory)
|
||||
{
|
||||
string path = ResourceUtility.FindFolder(Application.dataPath, "Dreamteck/" + localDirectory);
|
||||
List<string> files = new List<string>();
|
||||
string[] extensions = new string[] { "png", "PNG", "jpg", "JPG", "jpeg", "JPEG" };
|
||||
for (int i = 0; i < extensions.Length; i++) files.AddRange(Directory.GetFiles(path, "*."+extensions[i], SearchOption.TopDirectoryOnly));
|
||||
for (int i =0; i < files.Count; i++) images.Add(ResourceUtility.LoadTexture(files[i]));
|
||||
}
|
||||
|
||||
public static void UnloadImages(string[] imageNames)
|
||||
{
|
||||
for(int i = images.Count-1; i >= 0 ; i--)
|
||||
{
|
||||
for(int n = 0; n < imageNames.Length; n++)
|
||||
{
|
||||
if(images[i].name.ToLower() == imageNames[n].ToLower())
|
||||
{
|
||||
images.RemoveAt(i);
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
12
Assets/Dreamteck/Utilities/ImageDB.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0e56af4c64d27e48be19d6b7de4e88c
|
||||
timeCreated: 1483119339
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
29
Assets/Dreamteck/Utilities/LinearAlgebraUtility.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
|
||||
namespace Dreamteck
|
||||
{
|
||||
public static class LinearAlgebraUtility
|
||||
{
|
||||
public static Vector3 ProjectOnLine(Vector3 fromPoint, Vector3 toPoint, Vector3 project)
|
||||
{
|
||||
Vector3 projectedPoint = Vector3.Project((project - fromPoint), (toPoint - fromPoint)) + fromPoint;
|
||||
Vector3 dir = toPoint - fromPoint;
|
||||
Vector3 projectedDir = projectedPoint - fromPoint;
|
||||
float dot = Vector3.Dot(projectedDir, dir);
|
||||
if(dot > 0f)
|
||||
{
|
||||
if(projectedDir.sqrMagnitude <= dir.sqrMagnitude) return projectedPoint;
|
||||
else return toPoint;
|
||||
} else return fromPoint;
|
||||
}
|
||||
|
||||
public static float InverseLerp(Vector3 a, Vector3 b, Vector3 value)
|
||||
{
|
||||
Vector3 ab = b - a;
|
||||
Vector3 av = value - a;
|
||||
return Vector3.Dot(av, ab) / Vector3.Dot(ab, ab);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Dreamteck/Utilities/LinearAlgebraUtility.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9db18633d04e91409973e2ca7ab9c76
|
||||
timeCreated: 1458246009
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
702
Assets/Dreamteck/Utilities/MeshUtility.cs
Normal file
@@ -0,0 +1,702 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Dreamteck
|
||||
{
|
||||
public class MeshUtility
|
||||
{
|
||||
private static Vector3[] tan1 = new Vector3[0];
|
||||
private static Vector3[] tan2 = new Vector3[0];
|
||||
|
||||
public static int[] GeneratePlaneTriangles(int x, int z, bool flip, int startTriangleIndex = 0, int startVertex = 0)
|
||||
{
|
||||
int nbFaces = x * (z - 1);
|
||||
int[] triangles = new int[nbFaces * 6];
|
||||
GeneratePlaneTriangles(ref triangles, x, z, flip);
|
||||
return triangles;
|
||||
}
|
||||
|
||||
public static int[] GeneratePlaneTriangles(ref int[] triangles, int x, int z, bool flip, int startTriangleIndex = 0, int startVertex = 0, bool reallocateArray = false)
|
||||
{
|
||||
int nbFaces = x * (z - 1);
|
||||
if (reallocateArray && triangles.Length != nbFaces * 6)
|
||||
{
|
||||
if(startTriangleIndex > 0)
|
||||
{
|
||||
int[] newTris = new int[startTriangleIndex + nbFaces * 6];
|
||||
for(int i = 0; i < startTriangleIndex; i++) newTris[i] = triangles[i];
|
||||
triangles = newTris;
|
||||
} else triangles = new int[nbFaces * 6];
|
||||
}
|
||||
int g = x + 1;
|
||||
int t = startTriangleIndex;
|
||||
for (int face = 0; face < nbFaces + z - 2; face++)
|
||||
{
|
||||
if ((float)(face + 1) % (float)g == 0f && face != 0) face++;
|
||||
if (flip)
|
||||
{
|
||||
triangles[t++] = face + x + 1 + startVertex;
|
||||
triangles[t++] = face + 1 + startVertex;
|
||||
triangles[t++] = face + startVertex;
|
||||
|
||||
triangles[t++] = face + x + 1 + startVertex;
|
||||
triangles[t++] = face + x + 2 + startVertex;
|
||||
triangles[t++] = face + 1 + startVertex;
|
||||
}
|
||||
else
|
||||
{
|
||||
triangles[t++] = face + startVertex;
|
||||
triangles[t++] = face + 1 + startVertex;
|
||||
triangles[t++] = face + x + 1 + startVertex;
|
||||
|
||||
triangles[t++] = face + 1 + startVertex;
|
||||
triangles[t++] = face + x + 2 + startVertex;
|
||||
triangles[t++] = face + x + 1 + startVertex;
|
||||
}
|
||||
}
|
||||
return triangles;
|
||||
}
|
||||
|
||||
public static void CalculateTangents(TS_Mesh mesh)
|
||||
{
|
||||
int triangleCount = mesh.triangles.Length / 3;
|
||||
if (mesh.tangents.Length != mesh.vertexCount) mesh.tangents = new Vector4[mesh.vertexCount];
|
||||
if (tan1.Length != mesh.vertexCount)
|
||||
{
|
||||
tan1 = new Vector3[mesh.vertexCount];
|
||||
tan2 = new Vector3[mesh.vertexCount];
|
||||
}
|
||||
|
||||
int tri = 0;
|
||||
for (int i = 0; i < triangleCount; i++)
|
||||
{
|
||||
int i1 = mesh.triangles[tri];
|
||||
int i2 = mesh.triangles[tri + 1];
|
||||
int i3 = mesh.triangles[tri + 2];
|
||||
|
||||
float x1 = mesh.vertices[i2].x - mesh.vertices[i1].x;
|
||||
float x2 = mesh.vertices[i3].x - mesh.vertices[i1].x;
|
||||
float y1 = mesh.vertices[i2].y - mesh.vertices[i1].y;
|
||||
float y2 = mesh.vertices[i3].y - mesh.vertices[i1].y;
|
||||
float z1 = mesh.vertices[i2].z - mesh.vertices[i1].z;
|
||||
float z2 = mesh.vertices[i3].z - mesh.vertices[i1].z;
|
||||
|
||||
float s1 = mesh.uv[i2].x - mesh.uv[i1].x;
|
||||
float s2 = mesh.uv[i3].x - mesh.uv[i1].x;
|
||||
float t1 = mesh.uv[i2].y - mesh.uv[i1].y;
|
||||
float t2 = mesh.uv[i3].y - mesh.uv[i1].y;
|
||||
|
||||
float div = s1 * t2 - s2 * t1;
|
||||
float r = div == 0f ? 0f : 1f / div;
|
||||
|
||||
Vector3 sdir = new Vector3((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r, (t2 * z1 - t1 * z2) * r);
|
||||
Vector3 tdir = new Vector3((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r, (s1 * z2 - s2 * z1) * r);
|
||||
|
||||
tan1[i1] += sdir;
|
||||
tan1[i2] += sdir;
|
||||
tan1[i3] += sdir;
|
||||
|
||||
tan2[i1] += tdir;
|
||||
tan2[i2] += tdir;
|
||||
tan2[i3] += tdir;
|
||||
|
||||
tri += 3;
|
||||
}
|
||||
|
||||
for (int i = 0; i < mesh.vertexCount; i++)
|
||||
{
|
||||
Vector3 n = mesh.normals[i];
|
||||
Vector3 t = tan1[i];
|
||||
Vector3.OrthoNormalize(ref n, ref t);
|
||||
mesh.tangents[i].x = t.x;
|
||||
mesh.tangents[i].y = t.y;
|
||||
mesh.tangents[i].z = t.z;
|
||||
mesh.tangents[i].w = (Vector3.Dot(Vector3.Cross(n, t), tan2[i]) < 0.0f) ? -1.0f : 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MakeDoublesided(Mesh input)
|
||||
{
|
||||
Vector3[] vertices = input.vertices;
|
||||
Vector3[] normals = input.normals;
|
||||
Vector2[] uvs = input.uv;
|
||||
Color[] colors = input.colors;
|
||||
int[] triangles = input.triangles;
|
||||
List<int[]> submeshes = new List<int[]>();
|
||||
for (int i = 0; i < input.subMeshCount; i++) submeshes.Add(input.GetTriangles(i));
|
||||
|
||||
Vector3[] newVertices = new Vector3[vertices.Length * 2];
|
||||
Vector3[] newNormals = new Vector3[normals.Length * 2];
|
||||
Vector2[] newUvs = new Vector2[uvs.Length * 2];
|
||||
Color[] newColors = new Color[colors.Length * 2];
|
||||
int[] newTris = new int[triangles.Length * 2];
|
||||
List<int[]> newSubmeshes = new List<int[]>();
|
||||
for (int i = 0; i < submeshes.Count; i++)
|
||||
{
|
||||
newSubmeshes.Add(new int[submeshes[i].Length * 2]);
|
||||
submeshes[i].CopyTo(newSubmeshes[i], 0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < vertices.Length; i++)
|
||||
{
|
||||
newVertices[i] = vertices[i];
|
||||
newNormals[i] = normals[i];
|
||||
newUvs[i] = uvs[i];
|
||||
if (colors.Length > i) newColors[i] = colors[i];
|
||||
|
||||
newVertices[i + vertices.Length] = vertices[i];
|
||||
newNormals[i + vertices.Length] = -normals[i];
|
||||
newUvs[i + vertices.Length] = uvs[i];
|
||||
if (colors.Length > i) newColors[i + vertices.Length] = colors[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < triangles.Length; i += 3)
|
||||
{
|
||||
int index1 = triangles[i];
|
||||
int index2 = triangles[i + 1];
|
||||
int index3 = triangles[i + 2];
|
||||
newTris[i] = index1;
|
||||
newTris[i + 1] = index2;
|
||||
newTris[i + 2] = index3;
|
||||
|
||||
newTris[i + triangles.Length] = index3 + vertices.Length;
|
||||
newTris[i + triangles.Length + 1] = index2 + vertices.Length;
|
||||
newTris[i + triangles.Length + 2] = index1 + vertices.Length;
|
||||
}
|
||||
|
||||
for (int i = 0; i < submeshes.Count; i++)
|
||||
{
|
||||
for (int n = 0; n < submeshes[i].Length; n += 3)
|
||||
{
|
||||
int index1 = submeshes[i][n];
|
||||
int index2 = submeshes[i][n + 1];
|
||||
int index3 = submeshes[i][n + 2];
|
||||
newSubmeshes[i][n] = index1;
|
||||
newSubmeshes[i][n + 1] = index2;
|
||||
newSubmeshes[i][n + 2] = index3;
|
||||
|
||||
newSubmeshes[i][n + submeshes[i].Length] = index3 + vertices.Length;
|
||||
newSubmeshes[i][n + submeshes[i].Length + 1] = index2 + vertices.Length;
|
||||
newSubmeshes[i][n + submeshes[i].Length + 2] = index1 + vertices.Length;
|
||||
}
|
||||
}
|
||||
|
||||
input.vertices = newVertices;
|
||||
input.normals = newNormals;
|
||||
input.uv = newUvs;
|
||||
input.colors = newColors;
|
||||
input.triangles = newTris;
|
||||
for (int i = 0; i < newSubmeshes.Count; i++) input.SetTriangles(newSubmeshes[i], i);
|
||||
}
|
||||
|
||||
public static void MakeDoublesided(TS_Mesh input)
|
||||
{
|
||||
Vector3[] vertices = input.vertices;
|
||||
Vector3[] normals = input.normals;
|
||||
Vector2[] uvs = input.uv;
|
||||
Color[] colors = input.colors;
|
||||
int[] triangles = input.triangles;
|
||||
List<int[]> submeshes = input.subMeshes;
|
||||
|
||||
Vector3[] newVertices = new Vector3[vertices.Length * 2];
|
||||
Vector3[] newNormals = new Vector3[normals.Length * 2];
|
||||
Vector2[] newUvs = new Vector2[uvs.Length * 2];
|
||||
Color[] newColors = new Color[colors.Length * 2];
|
||||
int[] newTris = new int[triangles.Length * 2];
|
||||
List<int[]> newSubmeshes = new List<int[]>();
|
||||
for(int i = 0; i < submeshes.Count; i++)
|
||||
{
|
||||
newSubmeshes.Add(new int[submeshes[i].Length * 2]);
|
||||
submeshes[i].CopyTo(newSubmeshes[i], 0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < vertices.Length; i++)
|
||||
{
|
||||
newVertices[i] = vertices[i];
|
||||
newNormals[i] = normals[i];
|
||||
newUvs[i] = uvs[i];
|
||||
if(colors.Length > i) newColors[i] = colors[i];
|
||||
|
||||
newVertices[i + vertices.Length] = vertices[i];
|
||||
newNormals[i + vertices.Length] = -normals[i];
|
||||
newUvs[i + vertices.Length] = uvs[i];
|
||||
if (colors.Length > i) newColors[i + vertices.Length] = colors[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < triangles.Length; i += 3)
|
||||
{
|
||||
int index1 = triangles[i];
|
||||
int index2 = triangles[i + 1];
|
||||
int index3 = triangles[i + 2];
|
||||
newTris[i] = index1;
|
||||
newTris[i + 1] = index2;
|
||||
newTris[i + 2] = index3;
|
||||
|
||||
newTris[i + triangles.Length] = index3 + vertices.Length;
|
||||
newTris[i + triangles.Length + 1] = index2 + vertices.Length;
|
||||
newTris[i + triangles.Length + 2] = index1 + vertices.Length;
|
||||
}
|
||||
|
||||
for(int i = 0; i < submeshes.Count; i++)
|
||||
{
|
||||
for(int n = 0; n < submeshes[i].Length; n+= 3)
|
||||
{
|
||||
int index1 = submeshes[i][n];
|
||||
int index2 = submeshes[i][n + 1];
|
||||
int index3 = submeshes[i][n + 2];
|
||||
newSubmeshes[i][n] = index1;
|
||||
newSubmeshes[i][n + 1] = index2;
|
||||
newSubmeshes[i][n + 2] = index3;
|
||||
|
||||
newSubmeshes[i][n + submeshes[i].Length] = index3 + vertices.Length;
|
||||
newSubmeshes[i][n + submeshes[i].Length + 1] = index2 + vertices.Length;
|
||||
newSubmeshes[i][n + submeshes[i].Length + 2] = index1 + vertices.Length;
|
||||
}
|
||||
}
|
||||
|
||||
input.vertices = newVertices;
|
||||
input.normals = newNormals;
|
||||
input.uv = newUvs;
|
||||
input.colors = newColors;
|
||||
input.triangles = newTris;
|
||||
input.subMeshes = newSubmeshes;
|
||||
}
|
||||
|
||||
public static void MakeDoublesidedHalf(TS_Mesh input)
|
||||
{
|
||||
int vertexHalf = input.vertices.Length / 2;
|
||||
int trisHalf = input.triangles.Length / 2;
|
||||
for (int i = 0; i < vertexHalf; i++)
|
||||
{
|
||||
input.vertices[i + vertexHalf] = input.vertices[i];
|
||||
if (input.normals.Length > i) input.normals[i + vertexHalf] = -input.normals[i];
|
||||
if (input.tangents.Length > i) input.tangents[i + vertexHalf] = input.tangents[i];
|
||||
if (input.uv.Length > i) input.uv[i + vertexHalf] = input.uv[i];
|
||||
if (input.uv2.Length > i) input.uv2[i + vertexHalf] = input.uv2[i];
|
||||
if (input.uv3.Length > i) input.uv3[i + vertexHalf] = input.uv3[i];
|
||||
if (input.uv4.Length > i) input.uv4[i + vertexHalf] = input.uv4[i];
|
||||
if (input.colors.Length > i) input.colors[i + vertexHalf] = input.colors[i];
|
||||
}
|
||||
|
||||
for (int i = 0; i < trisHalf; i += 3)
|
||||
{
|
||||
input.triangles[i + trisHalf + 2] = input.triangles[i] + vertexHalf;
|
||||
input.triangles[i + trisHalf + 1] = input.triangles[i + 1] + vertexHalf;
|
||||
input.triangles[i + trisHalf] = input.triangles[i + 2] + vertexHalf;
|
||||
}
|
||||
|
||||
for (int i = 0; i < input.subMeshes.Count; i++)
|
||||
{
|
||||
trisHalf = input.subMeshes[i].Length / 2;
|
||||
for (int n = 0; n < trisHalf; n += 3)
|
||||
{
|
||||
input.subMeshes[i][n + trisHalf + 2] = input.subMeshes[i][n] + vertexHalf;
|
||||
input.subMeshes[i][n + trisHalf + 1] = input.subMeshes[i][n + 1] + vertexHalf;
|
||||
input.subMeshes[i][n + trisHalf] = input.subMeshes[i][n + 2] + vertexHalf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void InverseTransformMesh(TS_Mesh input, TS_Transform transform)
|
||||
{
|
||||
if (input.vertices == null || input.normals == null) return;
|
||||
for (int i = 0; i < input.vertices.Length; i++)
|
||||
{
|
||||
input.vertices[i] = transform.InverseTransformPoint(input.vertices[i]);
|
||||
input.normals[i] = transform.InverseTransformDirection(input.normals[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void TransformMesh(TS_Mesh input, TS_Transform transform)
|
||||
{
|
||||
if (input.vertices == null || input.normals == null) return;
|
||||
for (int i = 0; i < input.vertices.Length; i++)
|
||||
{
|
||||
input.vertices[i] = transform.TransformPoint(input.vertices[i]);
|
||||
input.normals[i] = transform.TransformDirection(input.normals[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void InverseTransformMesh(TS_Mesh input, Transform transform)
|
||||
{
|
||||
if (input.vertices == null || input.normals == null) return;
|
||||
for (int i = 0; i < input.vertices.Length; i++)
|
||||
{
|
||||
input.vertices[i] = transform.InverseTransformPoint(input.vertices[i]);
|
||||
input.normals[i] = transform.InverseTransformDirection(input.normals[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void TransformMesh(TS_Mesh input, Transform transform)
|
||||
{
|
||||
if (input.vertices == null || input.normals == null) return;
|
||||
for (int i = 0; i < input.vertices.Length; i++)
|
||||
{
|
||||
input.vertices[i] = transform.TransformPoint(input.vertices[i]);
|
||||
input.normals[i] = transform.TransformDirection(input.normals[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void InverseTransformMesh(Mesh input, Transform transform)
|
||||
{
|
||||
Vector3[] vertices = input.vertices;
|
||||
Vector3[] normals = input.vertices;
|
||||
Matrix4x4 matrix = transform.worldToLocalMatrix;
|
||||
for (int i = 0; i < vertices.Length; i++)
|
||||
{
|
||||
vertices[i] = matrix.MultiplyPoint3x4(vertices[i]);
|
||||
normals[i] = matrix.MultiplyVector(normals[i]);
|
||||
}
|
||||
input.vertices = vertices;
|
||||
input.normals = normals;
|
||||
}
|
||||
|
||||
public static void TransformMesh(Mesh input, Transform transform)
|
||||
{
|
||||
Vector3[] vertices = input.vertices;
|
||||
Vector3[] normals = input.vertices;
|
||||
Matrix4x4 matrix = transform.localToWorldMatrix;
|
||||
if (input.vertices == null || input.normals == null) return;
|
||||
for (int i = 0; i < input.vertices.Length; i++)
|
||||
{
|
||||
vertices[i] = matrix.MultiplyPoint3x4(vertices[i]);
|
||||
normals[i] = matrix.MultiplyVector(normals[i]);
|
||||
}
|
||||
input.vertices = vertices;
|
||||
input.normals = normals;
|
||||
}
|
||||
|
||||
|
||||
public static void TransformVertices(Vector3[] vertices, Transform transform)
|
||||
{
|
||||
for (int i = 0; i < vertices.Length; i++)
|
||||
{
|
||||
vertices[i] = transform.TransformPoint(vertices[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void InverseTransformVertices(Vector3[] vertices, Transform transform)
|
||||
{
|
||||
for (int i = 0; i < vertices.Length; i++)
|
||||
{
|
||||
vertices[i] = transform.InverseTransformPoint(vertices[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void TransformNormals(Vector3[] normals, Transform transform)
|
||||
{
|
||||
for (int i = 0; i < normals.Length; i++)
|
||||
{
|
||||
normals[i] = transform.TransformDirection(normals[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void InverseTransformNormals(Vector3[] normals, Transform transform)
|
||||
{
|
||||
for (int i = 0; i < normals.Length; i++)
|
||||
{
|
||||
normals[i] = transform.InverseTransformDirection(normals[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static string ToOBJString(Mesh mesh, Material[] materials)
|
||||
{
|
||||
int numVertices = 0;
|
||||
if (mesh == null)
|
||||
{
|
||||
return "####Error####";
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("g " + mesh.name +"\n");
|
||||
foreach (Vector3 v in mesh.vertices)
|
||||
{
|
||||
numVertices++;
|
||||
sb.Append(string.Format("v {0} {1} {2}\n", -v.x, v.y, v.z));
|
||||
}
|
||||
sb.Append("\n");
|
||||
foreach (Vector3 n in mesh.normals)
|
||||
{
|
||||
sb.Append(string.Format("vn {0} {1} {2}\n", -n.x, n.y, n.z));
|
||||
}
|
||||
sb.Append("\n");
|
||||
foreach (Vector3 v in mesh.uv)
|
||||
{
|
||||
sb.Append(string.Format("vt {0} {1}\n", v.x, v.y));
|
||||
}
|
||||
sb.Append("\n");
|
||||
foreach (Vector2 v in mesh.uv2)
|
||||
{
|
||||
sb.Append(string.Format("vt2 {0} {1}\n", v.x, v.y));
|
||||
}
|
||||
sb.Append("\n");
|
||||
foreach (Vector2 v in mesh.uv3)
|
||||
{
|
||||
sb.Append(string.Format("vt2 {0} {1}\n", v.x, v.y));
|
||||
}
|
||||
sb.Append("\n");
|
||||
foreach (Color c in mesh.colors)
|
||||
{
|
||||
sb.Append(string.Format("vc {0} {1} {2} {3}\n", c.r, c.g, c.b, c.a));
|
||||
}
|
||||
for (int material = 0; material < mesh.subMeshCount; material++)
|
||||
{
|
||||
sb.Append("\n");
|
||||
sb.Append("usemtl ").Append(materials[material].name).Append("\n");
|
||||
sb.Append("usemap ").Append(materials[material].name).Append("\n");
|
||||
|
||||
int[] triangles = mesh.GetTriangles(material);
|
||||
for (int i = 0; i < triangles.Length; i += 3)
|
||||
{
|
||||
sb.Append(string.Format("f {2}/{2}/{2} {1}/{1}/{1} {0}/{0}/{0}\n",
|
||||
triangles[i] + 1, triangles[i + 1] + 1, triangles[i + 2] + 1));
|
||||
}
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static Mesh Copy(Mesh input)
|
||||
{
|
||||
Mesh copy = new Mesh();
|
||||
copy.name = input.name;
|
||||
copy.vertices = input.vertices;
|
||||
copy.normals = input.normals;
|
||||
copy.colors = input.colors;
|
||||
copy.uv = input.uv;
|
||||
copy.uv2 = input.uv2;
|
||||
copy.uv3 = input.uv3;
|
||||
copy.uv4 = input.uv4;
|
||||
copy.tangents = input.tangents;
|
||||
copy.triangles = input.triangles;
|
||||
copy.subMeshCount = input.subMeshCount;
|
||||
for (int i = 0; i < input.subMeshCount; i++)
|
||||
{
|
||||
copy.SetTriangles(input.GetTriangles(i), i);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
|
||||
public static void Triangulate(Vector2[] points, ref int[] output)
|
||||
{
|
||||
List<int> indices = new List<int>();
|
||||
int pointsLength = points.Length;
|
||||
if (pointsLength < 3)
|
||||
{
|
||||
output = new int[0];
|
||||
return;
|
||||
}
|
||||
|
||||
int[] V = new int[pointsLength];
|
||||
if (Area(points, pointsLength) > 0)
|
||||
{
|
||||
for (int v = 0; v < pointsLength; v++)
|
||||
V[v] = v;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int v = 0; v < pointsLength; v++)
|
||||
V[v] = (pointsLength - 1) - v;
|
||||
}
|
||||
|
||||
int nv = pointsLength;
|
||||
int count = 2 * nv;
|
||||
for (int m = 0, v = nv - 1; nv > 2;)
|
||||
{
|
||||
if ((count--) <= 0) {
|
||||
if (output.Length != indices.Count) output = new int[indices.Count];
|
||||
indices.CopyTo(output, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
int u = v;
|
||||
if (nv <= u)
|
||||
u = 0;
|
||||
v = u + 1;
|
||||
if (nv <= v)
|
||||
v = 0;
|
||||
int w = v + 1;
|
||||
if (nv <= w)
|
||||
w = 0;
|
||||
|
||||
if (Snip(points, u, v, w, nv, V))
|
||||
{
|
||||
int a, b, c, s, t;
|
||||
a = V[u];
|
||||
b = V[v];
|
||||
c = V[w];
|
||||
indices.Add(c);
|
||||
indices.Add(b);
|
||||
indices.Add(a);
|
||||
m++;
|
||||
for (s = v, t = v + 1; t < nv; s++, t++)
|
||||
V[s] = V[t];
|
||||
nv--;
|
||||
count = 2 * nv;
|
||||
}
|
||||
}
|
||||
|
||||
indices.Reverse();
|
||||
if (output.Length != indices.Count) output = new int[indices.Count];
|
||||
indices.CopyTo(output, 0);
|
||||
}
|
||||
|
||||
public static void FlipTriangles(ref int[] triangles)
|
||||
{
|
||||
for (int i = 0; i < triangles.Length; i += 3)
|
||||
{
|
||||
int temp = triangles[i];
|
||||
triangles[i] = triangles[i + 2];
|
||||
triangles[i + 2] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
public static void FlipFaces(TS_Mesh input)
|
||||
{
|
||||
for(int i =0; i < input.subMeshes.Count; i++)
|
||||
{
|
||||
int[] array = input.subMeshes[i];
|
||||
FlipTriangles(ref array);
|
||||
}
|
||||
FlipTriangles(ref input.triangles);
|
||||
for(int i = 0; i < input.normals.Length; i++)
|
||||
{
|
||||
input.normals[i] *= -1f;
|
||||
}
|
||||
}
|
||||
|
||||
public static void BreakMesh(Mesh input, bool keepNormals = true)
|
||||
{
|
||||
Vector3[] newVertices = new Vector3[input.triangles.Length];
|
||||
Vector3[] newNormals = new Vector3[newVertices.Length];
|
||||
Vector2[] newUVs = new Vector2[newVertices.Length];
|
||||
Vector4[] newTangents = new Vector4[newVertices.Length];
|
||||
Color[] newColors = new Color[newVertices.Length];
|
||||
|
||||
Vector3[] oldVertices = input.vertices;
|
||||
Vector2[] oldUvs = input.uv;
|
||||
Vector3[] oldNormals = input.normals;
|
||||
Vector4[] oldTangents = input.tangents;
|
||||
Color[] oldColors = input.colors;
|
||||
|
||||
if (oldColors.Length != oldVertices.Length)
|
||||
{
|
||||
oldColors = new Color[oldVertices.Length];
|
||||
for (int i = 0; i < oldColors.Length; i++) oldColors[i] = Color.white;
|
||||
}
|
||||
|
||||
List<int[]> submeshList = new List<int[]>();
|
||||
int submeshes = input.subMeshCount;
|
||||
int vertIndex = 0;
|
||||
for (int i = 0; i < submeshes; i++)
|
||||
{
|
||||
int[] submesh = input.GetTriangles(i);
|
||||
for (int n = 0; n < submesh.Length; n += 3)
|
||||
{
|
||||
newVertices[vertIndex] = oldVertices[submesh[n]];
|
||||
newVertices[vertIndex + 1] = oldVertices[submesh[n + 1]];
|
||||
newVertices[vertIndex + 2] = oldVertices[submesh[n + 2]];
|
||||
|
||||
if (oldNormals.Length > submesh[n + 2])
|
||||
{
|
||||
if (!keepNormals)
|
||||
{
|
||||
newNormals[vertIndex] = newNormals[vertIndex + 1] = newNormals[vertIndex + 2] = (oldNormals[submesh[n]] + oldNormals[submesh[n + 1]] + oldNormals[submesh[n + 2]]).normalized;
|
||||
}
|
||||
else
|
||||
{
|
||||
newNormals[vertIndex] = oldNormals[submesh[n]];
|
||||
newNormals[vertIndex + 1] = oldNormals[submesh[n + 1]];
|
||||
newNormals[vertIndex + 2] = oldNormals[submesh[n + 2]];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (oldColors.Length > submesh[n + 2])
|
||||
newColors[vertIndex] = newColors[vertIndex + 1] = newColors[vertIndex + 2] = (oldColors[submesh[n]] + oldColors[submesh[n + 1]] + oldColors[submesh[n + 2]]) / 3f;
|
||||
|
||||
if (oldUvs.Length > submesh[n + 2])
|
||||
{
|
||||
newUVs[vertIndex] = oldUvs[submesh[n]];
|
||||
newUVs[vertIndex + 1] = oldUvs[submesh[n + 1]];
|
||||
newUVs[vertIndex + 2] = oldUvs[submesh[n + 2]];
|
||||
}
|
||||
|
||||
if (oldTangents.Length > submesh[n + 2])
|
||||
{
|
||||
newTangents[vertIndex] = oldTangents[submesh[n]];
|
||||
newTangents[vertIndex + 1] = oldTangents[submesh[n + 1]];
|
||||
newTangents[vertIndex + 2] = oldTangents[submesh[n + 2]];
|
||||
}
|
||||
|
||||
submesh[n] = vertIndex;
|
||||
submesh[n + 1] = vertIndex + 1;
|
||||
submesh[n + 2] = vertIndex + 2;
|
||||
vertIndex += 3;
|
||||
}
|
||||
submeshList.Add(submesh);
|
||||
}
|
||||
|
||||
input.vertices = newVertices;
|
||||
input.normals = newNormals;
|
||||
input.colors = newColors;
|
||||
input.uv = newUVs;
|
||||
input.tangents = newTangents;
|
||||
input.subMeshCount = submeshList.Count;
|
||||
for (int i = 0; i < submeshList.Count; i++) input.SetTriangles(submeshList[i], i);
|
||||
}
|
||||
|
||||
private static float Area(Vector2[] points, int maxCount)
|
||||
{
|
||||
float A = 0.0f;
|
||||
for (int p = maxCount - 1, q = 0; q < maxCount; p = q++)
|
||||
{
|
||||
Vector2 pval = points[p];
|
||||
Vector2 qval = points[q];
|
||||
A += pval.x * qval.y - qval.x * pval.y;
|
||||
}
|
||||
return (A * 0.5f);
|
||||
}
|
||||
|
||||
private static bool Snip(Vector2[] points, int u, int v, int w, int n, int[] V)
|
||||
{
|
||||
int p;
|
||||
Vector2 A = points[V[u]];
|
||||
Vector2 B = points[V[v]];
|
||||
Vector2 C = points[V[w]];
|
||||
if (Mathf.Epsilon > (((B.x - A.x) * (C.y - A.y)) - ((B.y - A.y) * (C.x - A.x))))
|
||||
return false;
|
||||
for (p = 0; p < n; p++)
|
||||
{
|
||||
if ((p == u) || (p == v) || (p == w))
|
||||
continue;
|
||||
Vector2 P = points[V[p]];
|
||||
if (InsideTriangle(A, B, C, P))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool InsideTriangle(Vector2 A, Vector2 B, Vector2 C, Vector2 P)
|
||||
{
|
||||
float ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy;
|
||||
float cCROSSap, bCROSScp, aCROSSbp;
|
||||
|
||||
ax = C.x - B.x; ay = C.y - B.y;
|
||||
bx = A.x - C.x; by = A.y - C.y;
|
||||
cx = B.x - A.x; cy = B.y - A.y;
|
||||
apx = P.x - A.x; apy = P.y - A.y;
|
||||
bpx = P.x - B.x; bpy = P.y - B.y;
|
||||
cpx = P.x - C.x; cpy = P.y - C.y;
|
||||
|
||||
aCROSSbp = ax * bpy - ay * bpx;
|
||||
cCROSSap = cx * apy - cy * apx;
|
||||
bCROSScp = bx * cpy - by * cpx;
|
||||
|
||||
return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
12
Assets/Dreamteck/Utilities/MeshUtility.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81cc5b669f819ca42a81d2c18c654e23
|
||||
timeCreated: 1450542790
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
78
Assets/Dreamteck/Utilities/ResourceUtility.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
|
||||
namespace Dreamteck
|
||||
{
|
||||
public static class ResourceUtility
|
||||
{
|
||||
//Attempts to find the input directory pattern inside a given directory and if it fails, proceeds with looking up all subfolders
|
||||
public static string FindFolder(string dir, string folderPattern)
|
||||
{
|
||||
if (folderPattern.StartsWith("/")) folderPattern = folderPattern.Substring(1);
|
||||
if (!dir.EndsWith("/")) dir += "/";
|
||||
if (folderPattern == "") return "";
|
||||
string[] folders = folderPattern.Split('/');
|
||||
if (folders.Length == 0) return "";
|
||||
string foundDir = "";
|
||||
try
|
||||
{
|
||||
foreach (string d in Directory.GetDirectories(dir))
|
||||
{
|
||||
DirectoryInfo dirInfo = new DirectoryInfo(d);
|
||||
if (dirInfo.Name == folders[0])
|
||||
{
|
||||
foundDir = d;
|
||||
string searchDir = FindFolder(d, string.Join("/", folders, 1, folders.Length - 1));
|
||||
if (searchDir != "")
|
||||
{
|
||||
foundDir = searchDir;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (foundDir == "")
|
||||
{
|
||||
foreach (string d in Directory.GetDirectories(dir))
|
||||
{
|
||||
foundDir = FindFolder(d, string.Join("/", folders));
|
||||
if (foundDir != "") break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (System.Exception excpt)
|
||||
{
|
||||
Debug.LogError(excpt.Message);
|
||||
return "";
|
||||
}
|
||||
return foundDir;
|
||||
}
|
||||
|
||||
public static Texture2D LoadTexture(string dreamteckPath, string textureFileName)
|
||||
{
|
||||
string path = Application.dataPath + "/Dreamteck/" + dreamteckPath;
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
path = FindFolder(Application.dataPath, "Dreamteck/" + dreamteckPath);
|
||||
if (!Directory.Exists(path)) return null;
|
||||
}
|
||||
if (!File.Exists(path + "/" + textureFileName)) return null;
|
||||
byte[] bytes = File.ReadAllBytes(path + "/" + textureFileName);
|
||||
Texture2D result = new Texture2D(1, 1);
|
||||
result.name = textureFileName;
|
||||
result.LoadImage(bytes);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Texture2D LoadTexture(string path)
|
||||
{
|
||||
if (!File.Exists(path)) return null;
|
||||
byte[] bytes = File.ReadAllBytes(path);
|
||||
Texture2D result = new Texture2D(1, 1);
|
||||
FileInfo finfo = new FileInfo(path);
|
||||
result.name = finfo.Name;
|
||||
result.LoadImage(bytes);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Dreamteck/Utilities/ResourceUtility.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e9dc735344bf0e43ba98718f54e0656
|
||||
timeCreated: 1458246009
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Assets/Dreamteck/Utilities/SceneUtility.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Dreamteck
|
||||
{
|
||||
public static class SceneUtility
|
||||
{
|
||||
public static void GetChildrenRecursively(Transform current, ref List<Transform> transformList)
|
||||
{
|
||||
transformList.Add(current);
|
||||
foreach (Transform child in current) GetChildrenRecursively(child, ref transformList);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Dreamteck/Utilities/SceneUtility.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5c6af18f0a94e34b8500b13d07331d6
|
||||
timeCreated: 1504129319
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
46
Assets/Dreamteck/Utilities/ScriptableObjectUtility.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
#if UNITY_EDITOR
|
||||
namespace Dreamteck {
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
|
||||
public static class ScriptableObjectUtility
|
||||
{
|
||||
public static ScriptableObject CreateAsset<T>(string name = "") where T : ScriptableObject
|
||||
{
|
||||
T asset = ScriptableObject.CreateInstance<T>();
|
||||
SaveAsset<T>(asset, name);
|
||||
return asset;
|
||||
}
|
||||
|
||||
public static ScriptableObject CreateAsset(string type, string name = "")
|
||||
{
|
||||
ScriptableObject asset = ScriptableObject.CreateInstance(type);
|
||||
SaveAsset<ScriptableObject>(asset, name);
|
||||
return asset;
|
||||
}
|
||||
|
||||
static void SaveAsset<T>(T asset, string name = "") where T : ScriptableObject
|
||||
{
|
||||
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
|
||||
if (path == "")
|
||||
{
|
||||
path = "Assets";
|
||||
}
|
||||
else if (Path.GetExtension(path) != "")
|
||||
{
|
||||
path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), "");
|
||||
}
|
||||
string assetName = "New " + typeof(T).ToString();
|
||||
if (name != "") assetName = name;
|
||||
string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/" + assetName + ".asset");
|
||||
AssetDatabase.CreateAsset(asset, assetPathAndName);
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
EditorUtility.FocusProjectWindow();
|
||||
Selection.activeObject = asset;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
12
Assets/Dreamteck/Utilities/ScriptableObjectUtility.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85e4f0317c6ed394cb416b5bf4fe4c59
|
||||
timeCreated: 1470333114
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
66
Assets/Dreamteck/Utilities/TS_Bounds.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace Dreamteck
|
||||
{
|
||||
[System.Serializable]
|
||||
public class TS_Bounds
|
||||
{
|
||||
public Vector3 center = Vector3.zero;
|
||||
public Vector3 extents = Vector3.zero;
|
||||
public Vector3 max = Vector3.zero;
|
||||
public Vector3 min = Vector3.zero;
|
||||
public Vector3 size = Vector3.zero;
|
||||
|
||||
public TS_Bounds()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public TS_Bounds(Bounds bounds)
|
||||
{
|
||||
center = bounds.center;
|
||||
extents = bounds.extents;
|
||||
max = bounds.max;
|
||||
min = bounds.min;
|
||||
size = bounds.size;
|
||||
}
|
||||
|
||||
public TS_Bounds(Vector3 c, Vector3 s)
|
||||
{
|
||||
center = c;
|
||||
size = s;
|
||||
extents = s / 2;
|
||||
max = center + extents;
|
||||
min = center - extents;
|
||||
}
|
||||
|
||||
public TS_Bounds(Vector3 min, Vector3 max, Vector3 center)
|
||||
{
|
||||
size = new Vector3(max.x - min.x, max.y - min.y, max.z - min.z);
|
||||
extents = size / 2f;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.center = center;
|
||||
}
|
||||
|
||||
public void CreateFromMinMax(Vector3 min, Vector3 max)
|
||||
{
|
||||
size.x = max.x - min.x;
|
||||
size.y = max.y - min.y;
|
||||
size.z = max.z - min.z;
|
||||
extents = size / 2f;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
center = (Vector3.Lerp(min, max, 0.5f));
|
||||
}
|
||||
|
||||
public bool Contains(Vector3 point)
|
||||
{
|
||||
if (point.x < min.x || point.x > max.x) return false;
|
||||
if (point.y < min.y || point.y > max.y) return false;
|
||||
if (point.z < min.z || point.z > max.z) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Dreamteck/Utilities/TS_Bounds.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c28a6bb56e8cee4fb7dd9a493afbf83
|
||||
timeCreated: 1463695116
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
371
Assets/Dreamteck/Utilities/TS_Mesh.cs
Normal file
@@ -0,0 +1,371 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Dreamteck
|
||||
{
|
||||
//Thread-safe mesh & bounds classes for working with threads.
|
||||
public class TS_Mesh
|
||||
{
|
||||
public int vertexCount
|
||||
{
|
||||
get { return vertices.Length; }
|
||||
set { }
|
||||
}
|
||||
public Vector3[] vertices = new Vector3[0];
|
||||
public Vector3[] normals = new Vector3[0];
|
||||
public Vector4[] tangents = new Vector4[0];
|
||||
public Color[] colors = new Color[0];
|
||||
public Vector2[] uv = new Vector2[0];
|
||||
public Vector2[] uv2 = new Vector2[0];
|
||||
public Vector2[] uv3 = new Vector2[0];
|
||||
public Vector2[] uv4 = new Vector2[0];
|
||||
public int[] triangles = new int[0];
|
||||
public List<int[]> subMeshes = new List<int[]>();
|
||||
public TS_Bounds bounds = new TS_Bounds(Vector3.zero, Vector3.zero);
|
||||
|
||||
public volatile bool hasUpdate = false;
|
||||
|
||||
public TS_Mesh()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public TS_Mesh(Mesh mesh)
|
||||
{
|
||||
CreateFromMesh(mesh);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
vertices = new Vector3[0];
|
||||
normals = new Vector3[0];
|
||||
tangents = new Vector4[0];
|
||||
colors = new Color[0];
|
||||
uv = new Vector2[0];
|
||||
uv2 = new Vector2[0];
|
||||
uv3 = new Vector2[0];
|
||||
uv4 = new Vector2[0];
|
||||
triangles = new int[0];
|
||||
subMeshes = new List<int[]>();
|
||||
bounds = new TS_Bounds(Vector3.zero, Vector3.zero);
|
||||
}
|
||||
|
||||
public void CreateFromMesh(Mesh mesh)
|
||||
{
|
||||
vertices = mesh.vertices;
|
||||
normals = mesh.normals;
|
||||
tangents = mesh.tangents;
|
||||
colors = mesh.colors;
|
||||
uv = mesh.uv;
|
||||
uv2 = mesh.uv2;
|
||||
uv3 = mesh.uv3;
|
||||
uv4 = mesh.uv4;
|
||||
triangles = mesh.triangles;
|
||||
bounds = new TS_Bounds(mesh.bounds);
|
||||
for (int i = 0; i < mesh.subMeshCount; i++)
|
||||
{
|
||||
subMeshes.Add(mesh.GetTriangles(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void Combine(List<TS_Mesh> newMeshes, bool overwrite = false)
|
||||
{
|
||||
int newVerts = 0;
|
||||
int newTris = 0;
|
||||
int submeshCount = 0;
|
||||
for(int i = 0; i < newMeshes.Count; i++)
|
||||
{
|
||||
newVerts += newMeshes[i].vertexCount;
|
||||
newTris += newMeshes[i].triangles.Length;
|
||||
if (newMeshes[i].subMeshes.Count > submeshCount) submeshCount = newMeshes[i].subMeshes.Count;
|
||||
}
|
||||
int[] submeshTrisCount = new int[submeshCount];
|
||||
int[] submeshOffsets = new int[submeshCount];
|
||||
for (int i = 0; i < newMeshes.Count; i++)
|
||||
{
|
||||
for (int j = 0; j < newMeshes[i].subMeshes.Count; j++) submeshTrisCount[j] += newMeshes[i].subMeshes[j].Length;
|
||||
}
|
||||
|
||||
if (overwrite)
|
||||
{
|
||||
int vertexOffset = 0;
|
||||
int trisOffset = 0;
|
||||
if (vertices.Length != newVerts) vertices = new Vector3[newVerts];
|
||||
if (normals.Length != newVerts) normals = new Vector3[newVerts];
|
||||
if (uv.Length != newVerts) uv = new Vector2[newVerts];
|
||||
if (uv2.Length != newVerts) uv2 = new Vector2[newVerts];
|
||||
if (uv3.Length != newVerts) uv3 = new Vector2[newVerts];
|
||||
if (uv4.Length != newVerts) uv4 = new Vector2[newVerts];
|
||||
if (colors.Length != newVerts) colors = new Color[newVerts];
|
||||
if (tangents.Length != newVerts) tangents = new Vector4[newVerts];
|
||||
if (triangles.Length != newTris) triangles = new int[newTris];
|
||||
if (subMeshes.Count != submeshCount) subMeshes.Clear();
|
||||
|
||||
|
||||
for (int i = 0; i < newMeshes.Count; i++)
|
||||
{
|
||||
newMeshes[i].vertices.CopyTo(vertices, vertexOffset);
|
||||
newMeshes[i].normals.CopyTo(normals, vertexOffset);
|
||||
newMeshes[i].uv.CopyTo(uv, vertexOffset);
|
||||
newMeshes[i].uv2.CopyTo(uv2, vertexOffset);
|
||||
newMeshes[i].uv3.CopyTo(uv3, vertexOffset);
|
||||
newMeshes[i].uv4.CopyTo(uv4, vertexOffset);
|
||||
newMeshes[i].colors.CopyTo(colors, vertexOffset);
|
||||
newMeshes[i].tangents.CopyTo(tangents, vertexOffset);
|
||||
|
||||
for (int j = trisOffset; j < trisOffset + newMeshes[i].triangles.Length; j++) triangles[j] = newMeshes[i].triangles[j - newTris] + vertexOffset;
|
||||
trisOffset += newMeshes[i].triangles.Length;
|
||||
|
||||
for (int j = 0; j < newMeshes[i].subMeshes.Count; j++)
|
||||
{
|
||||
if (j >= subMeshes.Count) subMeshes.Add(new int[submeshTrisCount[j]]);
|
||||
else if (subMeshes[j].Length != submeshTrisCount[j]) subMeshes[j] = new int[submeshTrisCount[j]];
|
||||
|
||||
for (int x = submeshOffsets[j]; x < submeshOffsets[j] + newMeshes[i].subMeshes[j].Length; x++)
|
||||
{
|
||||
subMeshes[j][x] = newMeshes[i].subMeshes[j][x - submeshOffsets[j]] + vertexOffset;
|
||||
}
|
||||
submeshOffsets[j] += newMeshes[i].subMeshes[j].Length;
|
||||
}
|
||||
vertexOffset += newMeshes[i].vertexCount;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector3[] newVertices = new Vector3[vertices.Length + newVerts];
|
||||
Vector3[] newNormals = new Vector3[vertices.Length + newVerts];
|
||||
Vector2[] newUvs = new Vector2[vertices.Length + newVerts];
|
||||
Vector2[] newUvs2 = new Vector2[vertices.Length + newVerts];
|
||||
Vector2[] newUvs3 = new Vector2[vertices.Length + newVerts];
|
||||
Vector2[] newUvs4 = new Vector2[vertices.Length + newVerts];
|
||||
Color[] newColors = new Color[vertices.Length + newVerts];
|
||||
Vector4[] newTangents = new Vector4[tangents.Length + newVerts];
|
||||
int[] newTriangles = new int[triangles.Length + newTris];
|
||||
List<int[]> newSubmeshes = new List<int[]>();
|
||||
for (int i = 0; i < submeshTrisCount.Length; i++)
|
||||
{
|
||||
newSubmeshes.Add(new int[submeshTrisCount[i]]);
|
||||
if (i < subMeshes.Count) submeshTrisCount[i] = subMeshes[i].Length;
|
||||
else submeshTrisCount[i] = 0;
|
||||
}
|
||||
newVerts = vertexCount;
|
||||
newTris = triangles.Length;
|
||||
vertices.CopyTo(newVertices, 0);
|
||||
normals.CopyTo(newNormals, 0);
|
||||
uv.CopyTo(newUvs, 0);
|
||||
uv2.CopyTo(newUvs2, 0);
|
||||
uv3.CopyTo(newUvs3, 0);
|
||||
uv4.CopyTo(newUvs4, 0);
|
||||
colors.CopyTo(newColors, 0);
|
||||
tangents.CopyTo(newTangents, 0);
|
||||
triangles.CopyTo(newTriangles, 0);
|
||||
|
||||
for (int i = 0; i < newMeshes.Count; i++)
|
||||
{
|
||||
newMeshes[i].vertices.CopyTo(newVertices, newVerts);
|
||||
newMeshes[i].normals.CopyTo(newNormals, newVerts);
|
||||
newMeshes[i].uv.CopyTo(newUvs, newVerts);
|
||||
newMeshes[i].uv2.CopyTo(newUvs2, newVerts);
|
||||
newMeshes[i].uv3.CopyTo(newUvs3, newVerts);
|
||||
newMeshes[i].uv4.CopyTo(newUvs4, newVerts);
|
||||
newMeshes[i].colors.CopyTo(newColors, newVerts);
|
||||
newMeshes[i].tangents.CopyTo(newTangents, newVerts);
|
||||
|
||||
for (int n = newTris; n < newTris + newMeshes[i].triangles.Length; n++)
|
||||
{
|
||||
newTriangles[n] = newMeshes[i].triangles[n - newTris] + newVerts;
|
||||
}
|
||||
|
||||
|
||||
for (int n = 0; n < newMeshes[i].subMeshes.Count; n++)
|
||||
{
|
||||
for (int x = submeshTrisCount[n]; x < submeshTrisCount[n] + newMeshes[i].subMeshes[n].Length; x++)
|
||||
{
|
||||
newSubmeshes[n][x] = newMeshes[i].subMeshes[n][x - submeshTrisCount[n]] + newVerts;
|
||||
}
|
||||
submeshTrisCount[n] += newMeshes[i].subMeshes[n].Length;
|
||||
}
|
||||
newTris += newMeshes[i].triangles.Length;
|
||||
newVerts += newMeshes[i].vertexCount;
|
||||
}
|
||||
|
||||
vertices = newVertices;
|
||||
normals = newNormals;
|
||||
uv = newUvs;
|
||||
uv2 = newUvs2;
|
||||
uv3 = newUvs3;
|
||||
uv4 = newUvs4;
|
||||
colors = newColors;
|
||||
tangents = newTangents;
|
||||
triangles = newTriangles;
|
||||
subMeshes = newSubmeshes;
|
||||
}
|
||||
}
|
||||
|
||||
public void Combine(TS_Mesh newMesh)
|
||||
{
|
||||
Vector3[] newVertices = new Vector3[vertices.Length + newMesh.vertices.Length];
|
||||
Vector3[] newNormals = new Vector3[normals.Length + newMesh.normals.Length];
|
||||
Vector2[] newUvs = new Vector2[uv.Length + newMesh.uv.Length];
|
||||
Vector2[] newUvs2 = new Vector2[uv.Length + newMesh.uv2.Length];
|
||||
Vector2[] newUvs3 = new Vector2[uv.Length + newMesh.uv3.Length];
|
||||
Vector2[] newUvs4 = new Vector2[uv.Length + newMesh.uv4.Length];
|
||||
Color[] newColors = new Color[colors.Length + newMesh.colors.Length];
|
||||
Vector4[] newTangents = new Vector4[tangents.Length + newMesh.tangents.Length];
|
||||
int[] newTriangles = new int[triangles.Length + newMesh.triangles.Length];
|
||||
|
||||
vertices.CopyTo(newVertices, 0);
|
||||
newMesh.vertices.CopyTo(newVertices, vertices.Length);
|
||||
|
||||
normals.CopyTo(newNormals, 0);
|
||||
newMesh.normals.CopyTo(newNormals, normals.Length);
|
||||
|
||||
uv.CopyTo(newUvs, 0);
|
||||
newMesh.uv.CopyTo(newUvs, uv.Length);
|
||||
|
||||
uv2.CopyTo(newUvs2, 0);
|
||||
newMesh.uv2.CopyTo(newUvs2, uv2.Length);
|
||||
|
||||
uv3.CopyTo(newUvs3, 0);
|
||||
newMesh.uv3.CopyTo(newUvs3, uv3.Length);
|
||||
|
||||
uv4.CopyTo(newUvs4, 0);
|
||||
newMesh.uv4.CopyTo(newUvs4, uv4.Length);
|
||||
|
||||
colors.CopyTo(newColors, 0);
|
||||
newMesh.colors.CopyTo(newColors, colors.Length);
|
||||
|
||||
tangents.CopyTo(newTangents, 0);
|
||||
newMesh.tangents.CopyTo(newTangents, tangents.Length);
|
||||
|
||||
for(int i = 0; i < newTriangles.Length; i++)
|
||||
{
|
||||
if (i < triangles.Length) newTriangles[i] = triangles[i];
|
||||
else newTriangles[i] = (newMesh.triangles[i - triangles.Length] + vertices.Length);
|
||||
}
|
||||
|
||||
for(int i = 0; i < newMesh.subMeshes.Count; i++)
|
||||
{
|
||||
if(i >= subMeshes.Count) subMeshes.Add(newMesh.subMeshes[i]);
|
||||
else
|
||||
{
|
||||
int[] newTris = new int[subMeshes[i].Length + newMesh.subMeshes[i].Length];
|
||||
subMeshes[i].CopyTo(newTris, 0);
|
||||
for(int n = 0; n < newMesh.subMeshes[i].Length; n++)
|
||||
{
|
||||
newTris[subMeshes[i].Length + n] = newMesh.subMeshes[i][n] + vertices.Length;
|
||||
}
|
||||
subMeshes[i] = newTris;
|
||||
}
|
||||
}
|
||||
vertices = newVertices;
|
||||
normals = newNormals;
|
||||
uv = newUvs;
|
||||
uv2 = newUvs2;
|
||||
uv3 = newUvs3;
|
||||
uv4 = newUvs4;
|
||||
colors = newColors;
|
||||
tangents = newTangents;
|
||||
triangles = newTriangles;
|
||||
}
|
||||
|
||||
public static TS_Mesh Copy(TS_Mesh input)
|
||||
{
|
||||
TS_Mesh result = new TS_Mesh();
|
||||
result.vertices = new Vector3[input.vertices.Length];
|
||||
input.vertices.CopyTo(result.vertices, 0);
|
||||
result.normals = new Vector3[input.normals.Length];
|
||||
input.normals.CopyTo(result.normals, 0);
|
||||
result.uv = new Vector2[input.uv.Length];
|
||||
input.uv.CopyTo(result.uv, 0);
|
||||
result.uv2 = new Vector2[input.uv2.Length];
|
||||
input.uv2.CopyTo(result.uv2, 0);
|
||||
result.uv3 = new Vector2[input.uv3.Length];
|
||||
input.uv3.CopyTo(result.uv3, 0);
|
||||
result.uv4 = new Vector2[input.uv4.Length];
|
||||
input.uv4.CopyTo(result.uv4, 0);
|
||||
result.colors = new Color[input.colors.Length];
|
||||
input.colors.CopyTo(result.colors, 0);
|
||||
result.tangents = new Vector4[input.tangents.Length];
|
||||
input.tangents.CopyTo(result.tangents, 0);
|
||||
result.triangles = new int[input.triangles.Length];
|
||||
input.triangles.CopyTo(result.triangles, 0);
|
||||
result.subMeshes = new List<int[]>();
|
||||
for(int i = 0; i < input.subMeshes.Count; i++)
|
||||
{
|
||||
result.subMeshes.Add(new int[input.subMeshes[i].Length]);
|
||||
input.subMeshes[i].CopyTo(result.subMeshes[i], 0);
|
||||
}
|
||||
result.bounds = new TS_Bounds(input.bounds.center, input.bounds.size);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Absorb(TS_Mesh input)
|
||||
{
|
||||
if (vertices.Length != input.vertexCount) vertices = new Vector3[input.vertexCount];
|
||||
if (normals.Length != input.normals.Length) normals = new Vector3[input.normals.Length];
|
||||
if (colors.Length != input.colors.Length) colors = new Color[input.colors.Length];
|
||||
if (uv.Length != input.uv.Length) uv = new Vector2[input.uv.Length];
|
||||
if (uv2.Length != input.uv2.Length) uv2 = new Vector2[input.uv2.Length];
|
||||
if (uv3.Length != input.uv3.Length) uv3 = new Vector2[input.uv3.Length];
|
||||
if (uv4.Length != input.uv4.Length) uv4 = new Vector2[input.uv4.Length];
|
||||
if (tangents.Length != input.tangents.Length) tangents = new Vector4[input.tangents.Length];
|
||||
if (triangles.Length != input.triangles.Length) triangles = new int[input.triangles.Length];
|
||||
|
||||
input.vertices.CopyTo(vertices, 0);
|
||||
input.normals.CopyTo(normals, 0);
|
||||
input.colors.CopyTo(colors, 0);
|
||||
input.uv.CopyTo(uv, 0);
|
||||
input.uv2.CopyTo(uv2, 0);
|
||||
input.uv3.CopyTo(uv3, 0);
|
||||
input.uv4.CopyTo(uv4, 0);
|
||||
input.tangents.CopyTo(tangents, 0);
|
||||
input.triangles.CopyTo(triangles, 0);
|
||||
|
||||
if (subMeshes.Count == input.subMeshes.Count)
|
||||
{
|
||||
for (int i = 0; i < subMeshes.Count; i++)
|
||||
{
|
||||
if (input.subMeshes[i].Length != subMeshes[i].Length) subMeshes[i] = new int[input.subMeshes[i].Length];
|
||||
input.subMeshes[i].CopyTo(subMeshes[i], 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
subMeshes = new List<int[]>();
|
||||
for (int i = 0; i < input.subMeshes.Count; i++)
|
||||
{
|
||||
subMeshes.Add(new int[input.subMeshes[i].Length]);
|
||||
input.subMeshes[i].CopyTo(subMeshes[i], 0);
|
||||
}
|
||||
}
|
||||
bounds = new TS_Bounds(input.bounds.center, input.bounds.size);
|
||||
}
|
||||
|
||||
public void WriteMesh(ref Mesh input)
|
||||
{
|
||||
if (input == null) input = new Mesh();
|
||||
if (vertices == null || vertices.Length <= 65000)
|
||||
{
|
||||
input.Clear();
|
||||
input.vertices = vertices;
|
||||
input.normals = normals;
|
||||
if (tangents.Length == vertices.Length) input.tangents = tangents;
|
||||
if (colors.Length == vertices.Length) input.colors = colors;
|
||||
if(uv.Length == vertices.Length) input.uv = uv;
|
||||
if (uv2.Length == vertices.Length) input.uv2 = uv2;
|
||||
if (uv3.Length == vertices.Length) input.uv3 = uv3;
|
||||
if (uv4.Length == vertices.Length) input.uv4 = uv4;
|
||||
input.triangles = triangles;
|
||||
if (subMeshes.Count > 0)
|
||||
{
|
||||
input.subMeshCount = subMeshes.Count;
|
||||
for (int i = 0; i < subMeshes.Count; i++) input.SetTriangles(subMeshes[i], i);
|
||||
}
|
||||
input.RecalculateBounds();
|
||||
hasUpdate = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Dreamteck/Utilities/TS_Mesh.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ca64fd6869620449bcb61d4f66c798e
|
||||
timeCreated: 1447354835
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
317
Assets/Dreamteck/Utilities/TS_Transform.cs
Normal file
@@ -0,0 +1,317 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace Dreamteck
|
||||
{
|
||||
[System.Serializable]
|
||||
public class TS_Transform
|
||||
{
|
||||
public Vector3 position
|
||||
{
|
||||
get { return new Vector3(posX, posY, posZ); }
|
||||
set
|
||||
{
|
||||
setPosition = true;
|
||||
setLocalPosition = false;
|
||||
posX = value.x;
|
||||
posY = value.y;
|
||||
posZ = value.z;
|
||||
}
|
||||
}
|
||||
public Quaternion rotation
|
||||
{
|
||||
get { return new Quaternion(rotX, rotY, rotZ, rotW); }
|
||||
set
|
||||
{
|
||||
setRotation = true;
|
||||
setLocalRotation = false;
|
||||
rotX = value.x;
|
||||
rotY = value.y;
|
||||
rotZ = value.z;
|
||||
rotW = value.w;
|
||||
}
|
||||
}
|
||||
public Vector3 scale
|
||||
{
|
||||
get { return new Vector3(scaleX, scaleY, scaleZ); }
|
||||
set
|
||||
{
|
||||
setScale = true;
|
||||
scaleX = value.x;
|
||||
scaleY = value.y;
|
||||
scaleZ = value.z;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 lossyScale
|
||||
{
|
||||
get { return new Vector3(lossyScaleX, lossyScaleY, lossyScaleZ); }
|
||||
set
|
||||
{
|
||||
setScale = true;
|
||||
lossyScaleX = value.x;
|
||||
lossyScaleY = value.y;
|
||||
lossyScaleZ = value.z;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 localPosition
|
||||
{
|
||||
get { return new Vector3(lposX, lposY, lposZ); }
|
||||
set
|
||||
{
|
||||
setLocalPosition = true;
|
||||
setPosition = false;
|
||||
lposX = value.x;
|
||||
lposY = value.y;
|
||||
lposZ = value.z;
|
||||
}
|
||||
}
|
||||
public Quaternion localRotation
|
||||
{
|
||||
get { return new Quaternion(lrotX, lrotY, lrotZ, lrotW); }
|
||||
set
|
||||
{
|
||||
setLocalRotation = true;
|
||||
setRotation = false;
|
||||
lrotX = value.x;
|
||||
lrotY = value.y;
|
||||
lrotZ = value.z;
|
||||
lrotW = value.w;
|
||||
}
|
||||
}
|
||||
|
||||
private bool setPosition = false;
|
||||
private bool setRotation = false;
|
||||
private bool setScale = false;
|
||||
private bool setLocalPosition = false;
|
||||
private bool setLocalRotation = false;
|
||||
|
||||
public Transform transform
|
||||
{
|
||||
get
|
||||
{
|
||||
return _transform;
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private Transform _transform;
|
||||
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private volatile float posX = 0f;
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private volatile float posY = 0f;
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private volatile float posZ = 0f;
|
||||
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private volatile float scaleX = 1f;
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private volatile float scaleY = 1f;
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private volatile float scaleZ = 1f;
|
||||
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private volatile float lossyScaleX = 1f;
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private volatile float lossyScaleY = 1f;
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private volatile float lossyScaleZ = 1f;
|
||||
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private volatile float rotX = 0f;
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private volatile float rotY = 0f;
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private volatile float rotZ = 0f;
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private volatile float rotW = 0f;
|
||||
|
||||
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private volatile float lposX = 0f;
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private volatile float lposY = 0f;
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private volatile float lposZ = 0f;
|
||||
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private volatile float lrotX = 0f;
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private volatile float lrotY = 0f;
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private volatile float lrotZ = 0f;
|
||||
[SerializeField]
|
||||
[HideInInspector]
|
||||
private volatile float lrotW = 0f;
|
||||
#if UNITY_EDITOR
|
||||
private volatile bool isPlaying = false;
|
||||
#endif
|
||||
|
||||
public TS_Transform(Transform input)
|
||||
{
|
||||
SetTransform(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the TS_Transform. Call this regularly on every frame you need it to update. Should ALWAYS be called from the main thread
|
||||
/// </summary>
|
||||
public void Update()
|
||||
{
|
||||
if (transform == null) return;
|
||||
#if UNITY_EDITOR
|
||||
isPlaying = Application.isPlaying;
|
||||
#endif
|
||||
if (setPosition) _transform.position = position;
|
||||
else if (setLocalPosition) _transform.localPosition = localPosition;
|
||||
else
|
||||
{
|
||||
position = _transform.position;
|
||||
localPosition = _transform.localPosition;
|
||||
}
|
||||
|
||||
if (setScale) _transform.localScale = scale;
|
||||
else scale = _transform.localScale;
|
||||
lossyScale = _transform.lossyScale;
|
||||
|
||||
|
||||
if (setRotation) _transform.rotation = rotation;
|
||||
else if (setLocalRotation) _transform.localRotation = localRotation;
|
||||
else
|
||||
{
|
||||
rotation = _transform.rotation;
|
||||
localRotation = _transform.localRotation;
|
||||
}
|
||||
setPosition = setLocalPosition = setRotation = setLocalRotation = setScale = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the transform reference. Should ALWAYS be called from the main thread
|
||||
/// </summary>
|
||||
/// <param name="input">Transform reference</param>
|
||||
public void SetTransform(Transform input)
|
||||
{
|
||||
_transform = input;
|
||||
setPosition = setLocalPosition = setRotation = setLocalRotation = setScale = false;
|
||||
Update();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if there's any change in the transform. Should ALWAYS be called from the main thread
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool HasChange()
|
||||
{
|
||||
return HasPositionChange() || HasRotationChange() || HasScaleChange();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if there's a change in the position. Should ALWAYS be called from the main thread
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool HasPositionChange()
|
||||
{
|
||||
return posX != _transform.position.x || posY != _transform.position.y || posZ != _transform.position.z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if there is a change in the rotation. Should ALWAYS be called from the main thread
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool HasRotationChange()
|
||||
{
|
||||
return rotX != _transform.rotation.x || rotY != _transform.rotation.y || rotZ != _transform.rotation.z || rotW != _transform.rotation.w;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if there is a change in the scale. Should ALWAYS be called from the main thread
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool HasScaleChange()
|
||||
{
|
||||
return lossyScaleX != _transform.lossyScale.x || lossyScaleY != _transform.lossyScale.y || lossyScaleZ != _transform.lossyScale.z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Thread-safe TransformPoint
|
||||
/// </summary>
|
||||
/// <param name="point"></param>
|
||||
/// <returns></returns>
|
||||
public Vector3 TransformPoint(Vector3 point)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!isPlaying) return transform.TransformPoint(point);
|
||||
#endif
|
||||
Vector3 scaled = new Vector3(point.x * lossyScaleX, point.y * lossyScaleY, point.z * lossyScaleZ);
|
||||
Vector3 rotated = rotation * scaled;
|
||||
return position + rotated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Thread-safe TransformDirection
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
public Vector3 TransformDirection(Vector3 direction)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!isPlaying) return transform.TransformDirection(direction);
|
||||
#endif
|
||||
return TransformPoint(direction) - position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Thread-safe InverseTransformPoint
|
||||
/// </summary>
|
||||
/// <param name="point"></param>
|
||||
/// <returns></returns>
|
||||
public Vector3 InverseTransformPoint(Vector3 point)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!isPlaying) return transform.InverseTransformPoint(point);
|
||||
#endif
|
||||
return InverseTransformDirection(point - position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Thread-safe InverseTransformDirection
|
||||
/// </summary>
|
||||
/// <param name="direction"></param>
|
||||
/// <returns></returns>
|
||||
public Vector3 InverseTransformDirection(Vector3 direction)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!isPlaying) return transform.InverseTransformDirection(direction);
|
||||
#endif
|
||||
Vector3 rotated = Quaternion.Inverse(rotation) * direction;
|
||||
return new Vector3(rotated.x / lossyScaleX, rotated.y / lossyScaleY, rotated.z / lossyScaleZ);
|
||||
}
|
||||
|
||||
public T GetComponent<T>()
|
||||
{
|
||||
return _transform.GetComponent<T>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
12
Assets/Dreamteck/Utilities/TS_Transform.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c22a5076c8dce1b40a2a12e5bc7abc69
|
||||
timeCreated: 1463604029
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
49
Assets/Dreamteck/Utilities/TransformUtility.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Dreamteck
|
||||
{
|
||||
public static class TransformUtility
|
||||
{
|
||||
public static Vector3 GetPosition(ref Matrix4x4 m)
|
||||
{
|
||||
return m.GetColumn(3);
|
||||
}
|
||||
|
||||
public static Quaternion GetRotation(ref Matrix4x4 m)
|
||||
{
|
||||
return Quaternion.LookRotation(m.GetColumn(2), m.GetColumn(1));
|
||||
}
|
||||
|
||||
public static Vector3 GetScale(ref Matrix4x4 m)
|
||||
{
|
||||
return new Vector3(m.GetColumn(0).magnitude, m.GetColumn(1).magnitude, m.GetColumn(2).magnitude);
|
||||
}
|
||||
|
||||
public static void SetPosition(ref Matrix4x4 m, ref Vector3 p)
|
||||
{
|
||||
m.SetColumn(3, new Vector4(p.x, p.y, p.z, 1f));
|
||||
}
|
||||
|
||||
public static void GetChildCount(Transform parent, ref int count)
|
||||
{
|
||||
foreach (Transform child in parent)
|
||||
{
|
||||
count++;
|
||||
GetChildCount(child, ref count);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsParent(Transform child, Transform parent)
|
||||
{
|
||||
Transform current = child;
|
||||
while(current.parent != null)
|
||||
{
|
||||
current = current.parent;
|
||||
if (current == parent) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Dreamteck/Utilities/TransformUtility.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 157259bef35b27e4ebcccdd7e3eee86b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||