Last active
August 29, 2015 14:03
-
-
Save TAK-EMI/35ce7620544d1eaf486b to your computer and use it in GitHub Desktop.
多面体を作り出すスクリプト。生成する形状は直角三角柱(Cubeを斜めに半分にした形状)、多角柱、多角錐、トーラス(ドーナツ型)の4種類。MeshColliderを組み込んであるので生成直後にデフォルトのプリミティブ形状と同じように使えるはずです。UVも貼ってありますけど結構適当です。おまけでEditorから呼び出せるスクリプトも置いておきます。なんかあれば https://twitter.com/TAK_EMI まで。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
#if UNITY_EDITOR | |
using UnityEditor; | |
#endif | |
using System.Collections; | |
using System.IO; | |
namespace TAKL | |
{ | |
public class OtherPrimitive : MonoBehaviour | |
{ | |
public static Material createMaterial() | |
{ | |
GameObject primitive = GameObject.CreatePrimitive(PrimitiveType.Plane); | |
primitive.SetActive(false); | |
Material mat = primitive.GetComponent<MeshRenderer>().sharedMaterial; | |
DestroyImmediate(primitive); | |
return mat; | |
} | |
static Mesh makeMesh(string name, Vector3[] vert, Vector2[] uv, int[] ifs) | |
{ | |
Mesh mesh = new Mesh(); | |
mesh.name = name; | |
mesh.vertices = vert; | |
mesh.uv = uv; | |
mesh.triangles = ifs; | |
mesh.RecalculateBounds(); | |
mesh.RecalculateNormals(); | |
return mesh; | |
} | |
public static GameObject createHalfCube() | |
{ | |
string name = "HalfCube"; | |
GameObject hCube = new GameObject(name); | |
MeshFilter mf = hCube.AddComponent<MeshFilter>(); | |
#if UNITY_EDITOR | |
string path = "/Meshes/" + name + ".asset"; | |
if (!File.Exists(Application.dataPath + path)) | |
{ | |
#endif | |
int vertSize = 8 * 3; | |
Vector3[] vert = new Vector3[vertSize]; | |
vert[0] = new Vector3(-0.5f, 0.5f, -0.5f); | |
vert[1] = new Vector3(-0.5f, 0.5f, 0.5f); | |
vert[2] = new Vector3(0.5f, 0.5f, -0.5f); | |
vert[3] = new Vector3(-0.5f, 0.5f, 0.5f); | |
vert[4] = new Vector3(-0.5f, 0.5f, -0.5f); | |
vert[5] = new Vector3(-0.5f, -0.5f, -0.5f); | |
vert[6] = new Vector3(-0.5f, 0.5f, 0.5f); | |
vert[7] = new Vector3(-0.5f, -0.5f, -0.5f); | |
vert[8] = new Vector3(-0.5f, -0.5f, 0.5f); | |
vert[9] = new Vector3(-0.5f, 0.5f, -0.5f); | |
vert[10] = new Vector3(0.5f, 0.5f, -0.5f); | |
vert[11] = new Vector3(-0.5f, -0.5f, -0.5f); | |
vert[12] = new Vector3(0.5f, 0.5f, -0.5f); | |
vert[13] = new Vector3(0.5f, -0.5f, -0.5f); | |
vert[14] = new Vector3(-0.5f, -0.5f, -0.5f); | |
vert[15] = new Vector3(0.5f, 0.5f, -0.5f); | |
vert[16] = new Vector3(-0.5f, 0.5f, 0.5f); | |
vert[17] = new Vector3(0.5f, -0.5f, -0.5f); | |
vert[18] = new Vector3(-0.5f, 0.5f, 0.5f); | |
vert[19] = new Vector3(-0.5f, -0.5f, 0.5f); | |
vert[20] = new Vector3(0.5f, -0.5f, -0.5f); | |
vert[21] = new Vector3(-0.5f, -0.5f, -0.5f); | |
vert[22] = new Vector3(0.5f, -0.5f, -0.5f); | |
vert[23] = new Vector3(-0.5f, -0.5f, 0.5f); | |
Vector2[] uv = new Vector2[vertSize]; | |
uv[0] = new Vector2(0.0f, 0.0f); | |
uv[1] = new Vector2(0.0f, 1.0f); | |
uv[2] = new Vector2(1.0f, 0.0f); | |
uv[3] = new Vector2(0.0f, 1.0f); | |
uv[4] = new Vector2(1.0f, 1.0f); | |
uv[5] = new Vector2(1.0f, 0.0f); | |
uv[6] = new Vector2(0.0f, 1.0f); | |
uv[7] = new Vector2(1.0f, 0.0f); | |
uv[8] = new Vector2(0.0f, 0.0f); | |
uv[9] = new Vector2(0.0f, 1.0f); | |
uv[10] = new Vector2(1.0f, 1.0f); | |
uv[11] = new Vector2(0.0f, 0.0f); | |
uv[12] = new Vector2(1.0f, 1.0f); | |
uv[13] = new Vector2(1.0f, 0.0f); | |
uv[14] = new Vector2(0.0f, 0.0f); | |
uv[15] = new Vector2(0.0f, 1.0f); | |
uv[16] = new Vector2(1.0f, 1.0f); | |
uv[17] = new Vector2(0.0f, 0.0f); | |
uv[18] = new Vector2(1.0f, 1.0f); | |
uv[19] = new Vector2(1.0f, 0.0f); | |
uv[20] = new Vector2(0.0f, 0.0f); | |
uv[21] = new Vector2(1.0f, 0.0f); | |
uv[22] = new Vector2(0.0f, 0.0f); | |
uv[23] = new Vector2(1.0f, 1.0f); | |
int[] ifs = new int[vertSize]; | |
for (int i = 0; i < vertSize; ++i) | |
ifs[i] = i; | |
mf.sharedMesh = makeMesh(name, vert, uv, ifs); | |
#if UNITY_EDITOR | |
} | |
else | |
{ | |
mf.sharedMesh = AssetDatabase.LoadAssetAtPath("Assets" + path, typeof(Mesh)) as Mesh; | |
if (mf.sharedMesh == null) | |
throw new System.Exception(); | |
} | |
#endif | |
MeshCollider mc = hCube.AddComponent<MeshCollider>(); | |
mc.convex = true; | |
MeshRenderer mr = hCube.AddComponent<MeshRenderer>(); | |
mr.renderer.sharedMaterial = OtherPrimitive.createMaterial(); | |
return hCube; | |
} | |
public static GameObject createPrism(int polyNum, float r, float top, float bottom) | |
{ | |
string name = "Prism" + polyNum.ToString(); | |
GameObject prism = new GameObject(name); | |
MeshFilter mf = prism.AddComponent<MeshFilter>(); | |
#if UNITY_EDITOR | |
string path = "/Meshes/" + name + ".asset"; | |
if (!File.Exists(Application.dataPath + path)) | |
{ | |
#endif | |
int vNum = polyNum * 3 * 2 * 2; | |
Vector3[] vert = new Vector3[vNum]; | |
Vector2[] uv = new Vector2[vNum]; | |
int[] ifs = new int[vNum]; | |
float tCos0, tCos1, tSin0, tSin1; | |
int offset1, offset2; | |
offset1 = polyNum * 3; | |
offset2 = (polyNum * 3) * 2; | |
Vector3 v1, v2, v3, v4, cT, cB; | |
v1 = Vector3.zero; | |
v2 = Vector3.zero; | |
v3 = Vector3.zero; | |
cT = new Vector3(0.0f, top, 0.0f); | |
cB = new Vector3(0.0f, bottom, 0.0f); | |
Vector2 uvCenter = new Vector2(0.5f, 0.5f); | |
float step = 360.0f / (float)(polyNum); | |
float uvOffset = 1.0f / (float)(polyNum); | |
float tUvOffset; | |
int idx1, idx2; | |
float Deg2Rad = Mathf.Deg2Rad; | |
for (int i = 0; i < polyNum; ++i) | |
{ | |
tCos0 = Mathf.Cos((step * i) * Deg2Rad); | |
tCos1 = Mathf.Cos((step * (i + 1)) * Deg2Rad); | |
tSin0 = Mathf.Sin((step * i) * Deg2Rad); | |
tSin1 = Mathf.Sin((step * (i + 1)) * Deg2Rad); | |
v1.x = tCos1 * r; | |
v1.y = v2.y = top; | |
v1.z = tSin1 * r; | |
v2.x = tCos0 * r; | |
v2.z = tSin0 * r; | |
v3.x = tCos0 * r; | |
v3.y = v4.y = bottom; | |
v3.z = tSin0 * r; | |
v4.x = tCos1 * r; | |
v4.z = tSin1 * r; | |
idx1 = i * 3; | |
vert[idx1 + 0] = cT; | |
vert[idx1 + 1] = v1; | |
vert[idx1 + 2] = v2; | |
uv[idx1 + 0] = uvCenter; | |
uv[idx1 + 1] = new Vector2(tCos1 * 0.5f + 0.5f, tSin1 * 0.5f + 0.5f); | |
uv[idx1 + 2] = new Vector2(tCos0 * 0.5f + 0.5f, tSin0 * 0.5f + 0.5f); | |
idx2 = idx1 + offset1; | |
for (int j = 0; j < 3; ++j) | |
{ | |
ifs[idx1 + j] = idx1 + j; | |
ifs[idx2 + j] = idx2 + j; | |
} | |
vert[idx2 + 0] = cB; | |
vert[idx2 + 1] = v3; | |
vert[idx2 + 2] = v4; | |
uv[idx2 + 0] = uvCenter; | |
uv[idx2 + 1] = new Vector2(1.0f - (tCos0 * 0.5f + 0.5f), tSin0 * 0.5f + 0.5f); | |
uv[idx2 + 2] = new Vector2(1.0f - (tCos1 * 0.5f + 0.5f), tSin1 * 0.5f + 0.5f); | |
idx2 = i * 6; | |
idx2 = idx2 + offset2; | |
vert[idx2 + 0] = v2; | |
vert[idx2 + 1] = v1; | |
vert[idx2 + 2] = v4; | |
vert[idx2 + 3] = v2; | |
vert[idx2 + 4] = v4; | |
vert[idx2 + 5] = v3; | |
tUvOffset = i * uvOffset; | |
uv[idx2 + 0] = new Vector2(0.0f + tUvOffset, 1.0f); | |
uv[idx2 + 1] = new Vector2(uvOffset + tUvOffset, 1.0f); | |
uv[idx2 + 2] = new Vector2(uvOffset + tUvOffset, 0.0f); | |
uv[idx2 + 3] = new Vector2(0.0f + tUvOffset, 1.0f); | |
uv[idx2 + 4] = new Vector2(uvOffset + tUvOffset, 0.0f); | |
uv[idx2 + 5] = new Vector2(0.0f + tUvOffset, 0.0f); | |
for (int j = 0; j < 6; ++j) | |
ifs[idx2 + j] = idx2 + j; | |
} | |
mf.sharedMesh = makeMesh(name, vert, uv, ifs); | |
#if UNITY_EDITOR | |
} | |
else | |
{ | |
mf.sharedMesh = AssetDatabase.LoadAssetAtPath("Assets" + path, typeof(Mesh)) as Mesh; | |
if (mf.sharedMesh == null) | |
throw new System.Exception(); | |
} | |
#endif | |
MeshCollider mc = prism.AddComponent<MeshCollider>(); | |
mc.convex = true; | |
MeshRenderer mr = prism.AddComponent<MeshRenderer>(); | |
mr.renderer.sharedMaterial = OtherPrimitive.createMaterial(); | |
return prism; | |
} | |
public static GameObject createPyramid(int polyNum, float r, float top, float bottom) | |
{ | |
string name = "Pyramid" + polyNum.ToString(); | |
GameObject pyramid = new GameObject(name); | |
MeshFilter mf = pyramid.AddComponent<MeshFilter>(); | |
#if UNITY_EDITOR | |
string path = "/Meshes/" + name + ".asset"; | |
if (!File.Exists(Application.dataPath + path)) | |
{ | |
#endif | |
int vNum = polyNum * 3 * 2; | |
Vector3[] vert = new Vector3[vNum]; | |
Vector2[] uv = new Vector2[vNum]; | |
int[] ifs = new int[vNum]; | |
float cos0, cos1, sin0, sin1; | |
Vector3 v1, v2, cT, cB; | |
cT = new Vector3(0.0f, top, 0.0f); | |
cB = new Vector3(0.0f, bottom, 0.0f); | |
Vector2 uvCenter = new Vector2(0.5f, 0.5f); | |
float step = 360.0f / (float)(polyNum); | |
int offset = polyNum * 3; | |
int idx, tIdx; | |
for (int i = 0; i < polyNum; ++i) | |
{ | |
cos0 = Mathf.Cos((step * i) * Mathf.Deg2Rad); | |
cos1 = Mathf.Cos((step * (i + 1)) * Mathf.Deg2Rad); | |
sin0 = Mathf.Sin((step * i) * Mathf.Deg2Rad); | |
sin1 = Mathf.Sin((step * (i + 1)) * Mathf.Deg2Rad); | |
v1.x = cos0 * r; | |
v1.y = v2.y = bottom; | |
v1.z = sin0 * r; | |
v2.x = cos1 * r; | |
v2.z = sin1 * r; | |
idx = i * 3; | |
vert[idx + 0] = cB; | |
vert[idx + 1] = v1; | |
vert[idx + 2] = v2; | |
uv[idx + 0] = uvCenter; | |
uv[idx + 1] = new Vector2(1.0f - (cos0 * 0.5f + 0.5f), sin0 * 0.5f + 0.5f); | |
uv[idx + 2] = new Vector2(1.0f - (cos1 * 0.5f + 0.5f), sin1 * 0.5f + 0.5f); | |
tIdx = idx + offset; | |
for (int j = 0; j < 3; ++j) | |
{ | |
ifs[idx + j] = idx + j; | |
ifs[tIdx + j] = tIdx + j; | |
} | |
vert[tIdx + 0] = cT; | |
vert[tIdx + 1] = v2; | |
vert[tIdx + 2] = v1; | |
uv[tIdx + 0] = uvCenter; | |
uv[tIdx + 1] = new Vector2((cos1 * 0.5f + 0.5f), sin1 * 0.5f + 0.5f); | |
uv[tIdx + 2] = new Vector2((cos0 * 0.5f + 0.5f), sin0 * 0.5f + 0.5f); | |
} | |
mf.sharedMesh = makeMesh(name, vert, uv, ifs); | |
#if UNITY_EDITOR | |
} | |
else | |
{ | |
mf.sharedMesh = AssetDatabase.LoadAssetAtPath("Assets" + path, typeof(Mesh)) as Mesh; | |
if (mf.sharedMesh == null) | |
throw new System.Exception(); | |
} | |
#endif | |
MeshCollider mc = pyramid.AddComponent<MeshCollider>(); | |
mc.convex = true; | |
MeshRenderer mr = pyramid.AddComponent<MeshRenderer>(); | |
mr.renderer.sharedMaterial = OtherPrimitive.createMaterial(); | |
return pyramid; | |
} | |
public static GameObject createTorus(int DIV, float R, int div, float r) | |
{ | |
string name = "Torus" + DIV.ToString() + "_" + div.ToString(); | |
GameObject torus = new GameObject(name); | |
MeshFilter mf = torus.AddComponent<MeshFilter>(); | |
#if UNITY_EDITOR | |
string path = "/Meshes/" + name + ".asset"; | |
if (!File.Exists(Application.dataPath + path)) | |
{ | |
#endif | |
int vNum = div * 3 * 2 * DIV; | |
Vector3[] vert = new Vector3[vNum]; | |
Vector2[] uv = new Vector2[vNum]; | |
int[] ifs = new int[vNum]; | |
Vector3 axisX1, axisX2, axisY; | |
axisX1 = Vector3.right; | |
axisX2 = Vector3.right; | |
axisY = Vector3.up; | |
MeshCollider mc; | |
Vector3[] mcVert = new Vector3[div * 3 * 2]; | |
Vector2[] mcTexCoord = new Vector2[div * 3 * 2]; | |
int[] mcIFS = new int[div * 3 * 2]; | |
Vector3 v1, v2, v3, v4; | |
float cos0, cos1, sin0, sin1; | |
float STEP = 360.0f / (float)(DIV); | |
float step = 360.0f / (float)(div); | |
float uvOffset = 1.0f / (float)(div); | |
float tUvOffset; | |
int idx, mcIdx; | |
for (int I = 0; I < DIV; ++I) | |
{ | |
axisX1.x = Mathf.Cos((STEP * I) * Mathf.Deg2Rad); | |
axisX1.y = axisX2.y = 0.0f; | |
axisX1.z = Mathf.Sin((STEP * I) * Mathf.Deg2Rad); | |
axisX2.x = Mathf.Cos((STEP * (I + 1)) * Mathf.Deg2Rad); | |
axisX2.z = Mathf.Sin((STEP * (I + 1)) * Mathf.Deg2Rad); | |
mc = torus.AddComponent<MeshCollider>(); | |
mc.convex = true; | |
for (int i = 0; i < div; ++i) | |
{ | |
cos0 = Mathf.Cos((step * i) * Mathf.Deg2Rad); | |
cos1 = Mathf.Cos((step * (i + 1)) * Mathf.Deg2Rad); | |
sin0 = Mathf.Sin((step * i) * Mathf.Deg2Rad); | |
sin1 = Mathf.Sin((step * (i + 1)) * Mathf.Deg2Rad); | |
v1 = (axisX1 * R) + (axisX1 * (cos1 * r)) + (axisY * (sin1 * r)); | |
v2 = (axisX1 * R) + (axisX1 * (cos0 * r)) + (axisY * (sin0 * r)); | |
v3 = (axisX2 * R) + (axisX2 * (cos0 * r)) + (axisY * (sin0 * r)); | |
v4 = (axisX2 * R) + (axisX2 * (cos1 * r)) + (axisY * (sin1 * r)); | |
mcIdx = i * 6; | |
idx = I * (div * 6) + mcIdx; | |
vert[idx + 0] = mcVert[mcIdx + 0] = v2; | |
vert[idx + 1] = mcVert[mcIdx + 1] = v1; | |
vert[idx + 2] = mcVert[mcIdx + 2] = v4; | |
vert[idx + 3] = mcVert[mcIdx + 3] = v2; | |
vert[idx + 4] = mcVert[mcIdx + 4] = v4; | |
vert[idx + 5] = mcVert[mcIdx + 5] = v3; | |
tUvOffset = i * uvOffset; | |
uv[idx + 0] = mcTexCoord[mcIdx + 0] = new Vector2(0.0f + tUvOffset, 1.0f); | |
uv[idx + 1] = mcTexCoord[mcIdx + 0] = new Vector2(uvOffset + tUvOffset, 1.0f); | |
uv[idx + 2] = mcTexCoord[mcIdx + 0] = new Vector2(uvOffset + tUvOffset, 0.0f); | |
uv[idx + 3] = mcTexCoord[mcIdx + 0] = new Vector2(0.0f + tUvOffset, 1.0f); | |
uv[idx + 4] = mcTexCoord[mcIdx + 0] = new Vector2(uvOffset + tUvOffset, 0.0f); | |
uv[idx + 5] = mcTexCoord[mcIdx + 0] = new Vector2(0.0f + tUvOffset, 0.0f); | |
for (int j = 0; j < 6; ++j) | |
{ | |
ifs[idx + j] = idx + j; | |
mcIFS[mcIdx + j] = mcIdx + j; | |
} | |
} | |
mc.sharedMesh = OtherPrimitive.makeMesh("dummyMesh" + DIV.ToString() + "_" + div.ToString() + "_" + I.ToString(), mcVert, mcTexCoord, mcIFS); | |
} | |
mf.sharedMesh = makeMesh(name, vert, uv, ifs); | |
#if UNITY_EDITOR | |
} | |
else | |
{ | |
mf.sharedMesh = AssetDatabase.LoadAssetAtPath("Assets" + path, typeof(Mesh)) as Mesh; | |
if (mf.sharedMesh == null) | |
throw new System.Exception(); | |
MeshCollider mc; | |
for (int I = 0; I < DIV; ++I) | |
{ | |
mc = torus.AddComponent<MeshCollider>(); | |
mc.convex = true; | |
mc.sharedMesh = AssetDatabase.LoadAssetAtPath("Assets" + "/Meshes/" + "dummyMesh" + DIV.ToString() + "_" + div.ToString() + "_" + I.ToString() + ".asset", typeof(Mesh)) as Mesh; | |
if (mc.sharedMesh == null) | |
throw new System.Exception(); | |
} | |
} | |
#endif | |
MeshRenderer mr = torus.AddComponent<MeshRenderer>(); | |
mr.renderer.sharedMaterial = OtherPrimitive.createMaterial(); | |
return torus; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System.Collections; | |
using System.IO; | |
using TAKL; | |
public class OtherPrimitiveEditor : EditorWindow | |
{ | |
enum MakePrimitive | |
{ | |
None = 0, | |
Prism, | |
Pyramid, | |
Torus, | |
} | |
static MakePrimitive state = MakePrimitive.None; | |
int _polyNum = 0; | |
bool _detail = false; | |
float _radius = 0.5f; | |
float _top = 0.5f; | |
float _bottom = -0.5f; | |
int largeDiv = 0; | |
float largeR = 0.5f; | |
static void CreateAssets(GameObject obj) | |
{ | |
Mesh mesh = obj.GetComponent<MeshFilter>().sharedMesh; | |
string dirName = "Meshes"; | |
string meshPath = Application.dataPath + "/" + dirName + "/"; | |
if (!Directory.Exists(meshPath)) | |
AssetDatabase.CreateFolder("Assets", "Meshes").ToString(); | |
if (!File.Exists(meshPath + mesh.name + ".asset")) | |
AssetDatabase.CreateAsset(mesh, "Assets/" + dirName + "/" + mesh.name + ".asset"); | |
Mesh mcMesh; | |
MeshCollider[] mc = obj.GetComponents<MeshCollider>(); | |
int size = mc.Length; | |
for (int i = 0; i < size; ++i) | |
{ | |
mcMesh = mc[i].sharedMesh; | |
if (mcMesh != mesh) | |
{ | |
if(!File.Exists(meshPath + mcMesh.name + ".asset")) | |
AssetDatabase.CreateAsset(mcMesh, "Assets/" + dirName + "/" + mcMesh.name + ".asset"); | |
} | |
} | |
AssetDatabase.SaveAssets(); | |
return; | |
} | |
[MenuItem("GameObject/Create Other/Other Primitives/Half Cube")] | |
public static void CreateHalfCube() | |
{ | |
state = MakePrimitive.None; | |
GameObject obj = OtherPrimitive.createHalfCube(); | |
OtherPrimitiveEditor.CreateAssets(obj); | |
return; | |
} | |
[MenuItem("GameObject/Create Other/Other Primitives/Prism...")] | |
public static void CreatePrism() | |
{ | |
state = MakePrimitive.Prism; | |
OtherPrimitiveEditor.GetWindow(typeof(OtherPrimitiveEditor), false, "Prism"); | |
return; | |
} | |
[MenuItem("GameObject/Create Other/Other Primitives/Pyramid...")] | |
public static void CreateHalfSphere() | |
{ | |
state = MakePrimitive.Pyramid; | |
OtherPrimitiveEditor.GetWindow(typeof(OtherPrimitiveEditor), false, "Pyramid"); | |
return; | |
} | |
[MenuItem("GameObject/Create Other/Other Primitives/Torus...")] | |
public static void CreateTorus() | |
{ | |
state = MakePrimitive.Torus; | |
OtherPrimitiveEditor.GetWindow(typeof(OtherPrimitiveEditor), false, "Torus"); | |
return; | |
} | |
void OnGUI() | |
{ | |
Event e = Event.current; | |
bool keyPress = false; | |
switch (e.type) | |
{ | |
case EventType.keyDown: | |
switch (e.keyCode) | |
{ | |
case KeyCode.Return: | |
keyPress = true; | |
break; | |
} | |
break; | |
} | |
switch(state) | |
{ | |
case MakePrimitive.Prism: | |
this.createPrismGUI(keyPress); | |
break; | |
case MakePrimitive.Pyramid: | |
this.createPyramidGUI(keyPress); | |
break; | |
case MakePrimitive.Torus: | |
this.createTorusGUI(keyPress); | |
break; | |
} | |
return; | |
} | |
void createPrismGUI(bool pressEnter) | |
{ | |
int pNum = this._polyNum; | |
bool detail = this._detail; | |
float r = this._radius; | |
float t, b; | |
t = this._top; | |
b = this._bottom; | |
this._polyNum = pNum = EditorGUILayout.IntField("角数", pNum); | |
if (this._detail = detail = EditorGUILayout.Toggle("詳細設定", detail)) | |
{ | |
this._radius = r = EditorGUILayout.FloatField("半径", r); | |
this._top = t = EditorGUILayout.FloatField("上面", t); | |
this._bottom = b = EditorGUILayout.FloatField("底面", b); | |
} | |
else | |
{ | |
this._radius = r = 0.5f; | |
this._top = t = 0.5f; | |
this._bottom = b = -0.5f; | |
} | |
if (pNum <= 2) | |
{ | |
this._polyNum = 0; | |
return; | |
} | |
EditorGUILayout.BeginHorizontal(); | |
{ | |
EditorGUILayout.Space(); | |
if (GUILayout.Button("生成") || pressEnter) | |
{ | |
GameObject obj = OtherPrimitive.createPrism(pNum, r, t, b); | |
Selection.activeGameObject = obj; | |
OtherPrimitiveEditor.CreateAssets(obj); | |
this.Close(); | |
} | |
} EditorGUILayout.EndHorizontal(); | |
return; | |
} | |
void createPyramidGUI(bool pressEnter) | |
{ | |
int pNum = this._polyNum; | |
bool detail = this._detail; | |
float r = this._radius; | |
float t, b; | |
t = this._top; | |
b = this._bottom; | |
this._polyNum = pNum = EditorGUILayout.IntField("角数", pNum); | |
if (this._detail = detail = EditorGUILayout.Toggle("詳細設定", detail)) | |
{ | |
this._radius = r = EditorGUILayout.FloatField("半径", r); | |
this._top = t = EditorGUILayout.FloatField("頭頂点", t); | |
this._bottom = b = EditorGUILayout.FloatField("底面", b); | |
} | |
else | |
{ | |
this._radius = r = 0.5f; | |
this._top = t = 0.5f; | |
this._bottom = b = -0.5f; | |
} | |
if (pNum <= 2) | |
{ | |
this._polyNum = 0; | |
return; | |
} | |
EditorGUILayout.BeginHorizontal(); | |
{ | |
EditorGUILayout.Space(); | |
if (GUILayout.Button("生成") || pressEnter) | |
{ | |
GameObject obj = OtherPrimitive.createPyramid(pNum, r, t, b); | |
Selection.activeGameObject = obj; | |
OtherPrimitiveEditor.CreateAssets(obj); | |
this.Close(); | |
} | |
} EditorGUILayout.EndHorizontal(); | |
return; | |
} | |
void createTorusGUI(bool pressEnter) | |
{ | |
int div = this._polyNum; | |
float r = this._radius; | |
int DIV = this.largeDiv; | |
float R = this.largeR; | |
bool detail = this._detail; | |
this.largeDiv = DIV = EditorGUILayout.IntField("大角数", DIV); | |
this._polyNum = div = EditorGUILayout.IntField("小角数", div); | |
if (this._detail = detail = EditorGUILayout.Toggle("詳細設定", detail)) | |
{ | |
this.largeR = R = EditorGUILayout.FloatField("大半径", R); | |
this._radius = r = EditorGUILayout.FloatField("小半径", r); | |
} | |
else | |
{ | |
this._radius = r = 0.1f; | |
this.largeR = R = 0.5f; | |
} | |
if (div <= 2 || DIV <= 2) | |
{ | |
this._polyNum = 0; | |
return; | |
} | |
EditorGUILayout.BeginHorizontal(); | |
{ | |
EditorGUILayout.Space(); | |
if (GUILayout.Button("生成") || pressEnter) | |
{ | |
GameObject obj = OtherPrimitive.createTorus(DIV, R, div, r); | |
Selection.activeGameObject = obj; | |
OtherPrimitiveEditor.CreateAssets(obj); | |
this.Close(); | |
} | |
} EditorGUILayout.EndHorizontal(); | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment