-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameCoreUtils.cs
More file actions
116 lines (91 loc) · 2.92 KB
/
Copy pathGameCoreUtils.cs
File metadata and controls
116 lines (91 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Text;
namespace GameCoreUtils
{
public class NormalizeMeshSize : EditorWindow {
public GameObject gm;
public void OnGUI()
{
}
[MenuItem("Assets/normalize mesh", validate = true)]
public static bool CanNormalizeMeshScale()
{
if (Selection.activeObject != null)
{
if (Selection.activeObject is GameObject)
{
return true;
}
}
return false;
}
[MenuItem("Assets/normalize mesh")]
public static void NormalizeMeshScale()
{
GameObject gm = (GameObject)Selection.activeObject;
Mesh m = gm.GetComponent<MeshFilter>().sharedMesh;
Vector3[] tris = m.vertices;
Vector3 v;
Vector3 s = gm.transform.localScale;
gm.transform.localScale = Vector3.one;
for (int i = 0; i < tris.Length; i++)
{
v = tris[i];
v.x = v.x * s.x;
v.y = v.y * s.y;
v.z = v.z * s.z;
tris[i] = v;
}
m.vertices = tris;
m.RecalculateBounds();
}
}
public static class GCoreUtil
{
public static T[] CopyAndAdd<T>(T[] tocopy, params T[] add)
{
T[] ret = new T[tocopy.Length + add.Length];
for (int i = 0; i < tocopy.Length; i++)
ret[i] = tocopy[i];
int newpos = tocopy.Length;
for (int i = 0; i < add.Length; i++)
{
ret[newpos] = add[i];
newpos++;
}
return ret;
}
public static T[] AddElement<T>(T[] target, params T[] items)
{
if (target == null)
{
target = new T[] { };
}
if (items == null)
{
items = new T[] { };
}
T[] result = new T[target.Length + items.Length];
target.CopyTo(result, 0);
items.CopyTo(result, target.Length);
return result;
}
public static void CreateFolder( string path)
{
string[] elements = path.Split('/');
StringBuilder sb = new StringBuilder(elements[0]);
string last;
for (int i = 1; i < elements.Length; i++)
{
last = sb.ToString();
sb.Append('/').Append(elements[i]);
if (AssetDatabase.IsValidFolder(sb.ToString()) == false ) {
AssetDatabase.CreateFolder(last, elements[i]);
}
}
}
}
}