static void FixTextures() { foreach (Transform t in GLDTools.GetSelection()) { GLDTools.FixTiling(t); } }
void OnGUI() { minSize = new Vector2((float)pWidth, (float)pHeight); EditorGUILayout.BeginHorizontal(); GUILayout.Space(hSpan); if (GUILayout.Button("Create", GUILayout.Width(eSize))) { Transform[] tt = GLDTools.GetSelection(); foreach (Transform t in tt) { if (t.tag == "Floor") { GameObject go = GLDTools.NoCloneName((GameObject)Instantiate(Resources.Load("Environment/Ceiling"), t.position, t.rotation)); Align(go.transform); GLDTools.FixTiling(go.transform); Selection.activeGameObject = go; } } } GUILayout.Space(hSpan); if (GUILayout.Button("Align", GUILayout.Width(eSize))) { Transform[] tt = GLDTools.GetSelection(); foreach (Transform t in tt) { if (t.tag == "Ceiling") { Align(t); } } } GUILayout.Space(hSpan); EditorGUILayout.EndHorizontal(); GUILayout.Space(vSpan); EditorGUILayout.BeginHorizontal(); GUILayout.Space(hSpan); if (GUILayout.Button("Set", GUILayout.Width(eSize))) { Transform[] tt = GLDTools.GetSelection(); foreach (Transform t in tt) { if (t.tag == "Ceiling") { RaycastHit h; if (Physics.Raycast(t.position, t.up, out h) && h.transform.root.tag == "Floor") { t.position = h.point + h.transform.root.up * height; } } } } GUILayout.Space(hSpan); EditorGUIUtility.labelWidth = eSize / 2f; height = EditorGUILayout.FloatField("Height", height, GUILayout.Width(eSize)); GUILayout.Space(hSpan); EditorGUILayout.EndHorizontal(); }
static void DebugShow() { Transform[] tt = GLDTools.GetSelection(); foreach (Transform t in tt) { HideInfo[] hii = t.GetComponentsInChildren <HideInfo> (true); foreach (HideInfo hi in hii) { hi.transform.gameObject.SetActive(true); } } }
private GameObject Build(Transform t1, Transform t2) { Vector3[] se = ClosestPairs(SamplePoints(t1.transform), SamplePoints(t2.transform)); Vector3 mp = (se [0] + se [1]) / 2f; GameObject br = GLDTools.NoCloneName((GameObject)Instantiate(Resources.Load("Environment/Bridge"), mp, Quaternion.identity)); float l = (se [0] - se [1]).magnitude; br.transform.localScale = new Vector3(width, 0.02f, l); br.transform.rotation = Quaternion.FromToRotation(Vector3.forward, se [1] - se [0]); Vector3 r = br.transform.rotation.eulerAngles; r.z = 0f; br.transform.rotation = Quaternion.Euler(r); GLDTools.FixTiling(br.transform); return(br); }
void OnGUI() { minSize = new Vector2((float)pWidth, (float)pHeight); EditorGUILayout.BeginHorizontal(); GUILayout.Space(hSpan); EditorGUIUtility.labelWidth = eSize; EditorGUILayout.PrefixLabel("Texels size"); EditorGUIUtility.labelWidth = eSize * 0.2f; sx = EditorGUILayout.FloatField("X", sx, GUILayout.Width((int)(eSize * 0.5f))); sz = EditorGUILayout.FloatField("Z", sz, GUILayout.Width((int)(eSize * 0.5f))); GUILayout.Space(hSpan); EditorGUILayout.EndHorizontal(); GUILayout.Space(vSpan); EditorGUILayout.BeginHorizontal(); GUILayout.Space(hSpan); EditorGUIUtility.labelWidth = eSize; EditorGUILayout.PrefixLabel("N. of texels"); EditorGUIUtility.labelWidth = eSize * 0.2f; tx = EditorGUILayout.IntField("X", tx, GUILayout.Width((int)(eSize * 0.5f))); tz = EditorGUILayout.IntField("Z", tz, GUILayout.Width((int)(eSize * 0.5f))); GUILayout.Space(hSpan); EditorGUILayout.EndHorizontal(); GUILayout.Space(vSpan); curve = EditorGUILayout.BeginToggleGroup("Curve", curve); EditorGUIUtility.labelWidth = eSize / 2f; EditorGUILayout.BeginHorizontal(); GUILayout.Space(hSpan); updown = (CurveType)EditorGUILayout.EnumPopup("Direction", updown, GUILayout.Width(eSize)); GUILayout.Space(hSpan); EditorGUIUtility.labelWidth = eSize / 2.5f; h = EditorGUILayout.FloatField("height", h, GUILayout.Width((int)(eSize * 0.8))); GUILayout.Space(hSpan); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndToggleGroup(); GUILayout.Space(vSpan); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Build", GUILayout.Width(eSize))) { Transform[] tt = GLDTools.GetSelection(); Vector3 origin = tt.Length == 1 ? tt[0].position : Vector3.zero; Vector3 nc = origin - new Vector3((((float)tx) / 2f) * sx, 0f, (((float)tz) / 2f) * sz); Vector3 sc = new Vector3(sx, 0.02f, sz); GameObject root = new GameObject(); root.name = "Texels"; root.transform.position = origin; root.transform.rotation = Quaternion.identity; for (int i = 0; i < tx; i += 1) { for (int j = 0; j < tz; j += 1) { GameObject go = GLDTools.NoCloneName((GameObject)Instantiate(Resources.Load("Environment/Floor"), nc + new Vector3((float)i * sx, 0f, (float)j * sz), Quaternion.identity)); go.transform.localScale = sc; go.transform.parent = root.transform; if (curve) { float d; Vector3 s = go.transform.localScale; if (updown == CurveType.Down) { float di = (Mathf.Sin(((float)i * Mathf.PI) / (float)(tx - 1)) - 1f) * Mathf.Abs(h); float dj = (Mathf.Sin(((float)j * Mathf.PI) / (float)(tz - 1)) - 1f) * Mathf.Abs(h); d = Mathf.Min(di, dj); s.y = Mathf.Max(h + d, 0.02f); go.transform.Translate(new Vector3(0f, ((d - h) / 2f), 0f)); } else { float di = h - Mathf.Sin(((float)i * Mathf.PI) / (float)(tx - 1)) * Mathf.Abs(h); float dj = h - Mathf.Sin(((float)j * Mathf.PI) / (float)(tz - 1)) * Mathf.Abs(h); d = Mathf.Max(di, dj); s.y = Mathf.Max(d, 0.02f); go.transform.Translate(new Vector3(0f, d / 2f, 0f)); } go.transform.localScale = s; } } } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); }
void OnGUI() { minSize = new Vector2((float)pWidth, (float)pHeight); EditorGUILayout.BeginHorizontal(); GUILayout.Space(hSpan); if (GUILayout.Button("Create", GUILayout.Width(eSize))) { Transform[] tt = GLDTools.GetSelection(); Vector3 origin = tt.Length == 1 ? tt[0].position : Vector3.zero; GameObject go = GLDTools.NoCloneName((GameObject)Instantiate(Resources.Load("Environment/Floor"), origin, Quaternion.identity)); go.transform.localScale = new Vector3(fx, 0.02f, fz); go.transform.position = origin; GLDTools.FixTiling(go.transform); } GUILayout.Space(hSpan); EditorGUIUtility.labelWidth = eSize * 0.2f; fx = EditorGUILayout.FloatField("X", fx, GUILayout.Width((int)(eSize * 0.5f))); fz = EditorGUILayout.FloatField("Z", fz, GUILayout.Width((int)(eSize * 0.5f))); GUILayout.Space(hSpan); EditorGUILayout.EndHorizontal(); GUILayout.Space(vSpan); EditorGUILayout.BeginHorizontal(); GUILayout.Space(hSpan); if (GUILayout.Button("Terrain", GUILayout.Width(eSize))) { Transform[] tt = GLDTools.GetSelection(); Vector3 origin = tt.Length == 1 ? tt[0].position : Vector3.zero; TerrainData terrainData = new TerrainData(); terrainData.size = new Vector3(tx, Mathf.Max(tx, tz), tz); GameObject go = Terrain.CreateTerrainGameObject(terrainData); go.transform.position = new Vector3(-tx / 2f, 0f, -tz / 2f) + origin; } GUILayout.Space(hSpan); EditorGUIUtility.labelWidth = eSize * 0.2f; tx = EditorGUILayout.FloatField("X", tx, GUILayout.Width((int)(eSize * 0.5f))); tz = EditorGUILayout.FloatField("Z", tz, GUILayout.Width((int)(eSize * 0.5f))); GUILayout.Space(hSpan); EditorGUILayout.EndHorizontal(); GUILayout.Space(vSpan); EditorGUILayout.BeginHorizontal(); GUILayout.Space(hSpan); if (GUILayout.Button("Railings", GUILayout.Width(eSize))) { Transform[] tt = GLDTools.GetSelection(); foreach (Transform t in tt) { if (t.tag == "Floor") { Quaternion q = t.rotation; t.rotation = Quaternion.identity; Vector3 sz = t.localScale; GameObject n = GLDTools.NoCloneName((GameObject)GameObject.Instantiate(Resources.Load("Environment/Railing"), t.position + new Vector3(0f, rHeight / 2f, sz.z / 2f), Quaternion.identity)); GameObject s = GLDTools.NoCloneName((GameObject)GameObject.Instantiate(Resources.Load("Environment/Railing"), t.position + new Vector3(0f, rHeight / 2f, -sz.z / 2f), Quaternion.identity)); GameObject e = GLDTools.NoCloneName((GameObject)GameObject.Instantiate(Resources.Load("Environment/Railing"), t.position + new Vector3(sz.x / 2f, rHeight / 2f, 0f), Quaternion.identity)); GameObject w = GLDTools.NoCloneName((GameObject)GameObject.Instantiate(Resources.Load("Environment/Railing"), t.position + new Vector3(-sz.x / 2f, rHeight / 2f, 0f), Quaternion.identity)); n.transform.localScale = new Vector3(sz.x, rHeight, 0.02f); s.transform.localScale = new Vector3(sz.x, rHeight, 0.02f); e.transform.localScale = new Vector3(0.02f, rHeight, sz.z); w.transform.localScale = new Vector3(0.02f, rHeight, sz.z); n.transform.parent = t; s.transform.parent = t; e.transform.parent = t; w.transform.parent = t; t.rotation = q; } } } GUILayout.Space(hSpan); EditorGUIUtility.labelWidth = eSize / 2f; rHeight = EditorGUILayout.FloatField("Height", rHeight, GUILayout.Width(eSize)); GUILayout.Space(hSpan); EditorGUILayout.EndHorizontal(); }
void OnGUI() { minSize = new Vector2((float)pWidth, (float)pHeight); EditorGUILayout.BeginHorizontal(); GUILayout.Space(hSpan); if (GUILayout.Button("Create", GUILayout.Width(eSize))) { Transform[] tt = GLDTools.GetSelection(); Vector3 origin = tt.Length == 1 ? tt[0].position : Vector3.zero; GameObject go = GLDTools.NoCloneName((GameObject)Instantiate(Resources.Load("Environment/Wall"), origin, Quaternion.identity)); go.transform.position += go.transform.up * (go.transform.localScale.y / 2f); } GUILayout.Space(hSpan); if (GUILayout.Button("Put Down", GUILayout.Width(eSize))) { Transform[] tt = GLDTools.GetSelection(); foreach (Transform t in tt) { if (t.tag == "Wall") { RaycastHit h; if (Physics.Raycast(t.position, -t.up, out h)) { t.localRotation = h.transform.root.localRotation; t.position = h.point + t.localRotation * (Vector3.up * t.localScale.y / 2f); } else if (Physics.Raycast(t.position, t.up, out h) && h.transform.root.tag == "Floor") { t.localRotation = h.transform.root.localRotation; t.position = h.point + t.localRotation * (Vector3.up * ((t.localScale.y / 2f) + h.transform.root.localScale.y)); } } } } GUILayout.Space(hSpan); EditorGUILayout.EndHorizontal(); GUILayout.Space(vSpan); EditorGUILayout.BeginHorizontal(); GUILayout.Space(hSpan); if (GUILayout.Button("Span Vertical", GUILayout.Width(eSize))) { Transform[] tt = GLDTools.GetSelection(); foreach (Transform t in tt) { if (t.tag == "Wall") { RaycastHit h; Quaternion backupRot = t.localRotation; Vector3 backupPos = t.position; Vector3 v; if (Physics.Raycast(t.position, -t.up, out h) && h.transform.root.tag == "Floor") { t.localRotation = h.transform.root.localRotation; t.position = h.point + t.localRotation * (Vector3.up * t.localScale.y / 2f); v = h.point; if (Physics.Raycast(t.position, t.up, out h) && h.transform.root.tag == "Ceiling") { t.position = (v + h.point) / 2f; Vector3 tmp = t.transform.root.localScale; tmp.y = (v - h.point).magnitude; t.localScale = tmp; } else { t.localRotation = backupRot; t.position = backupPos; } } } } } GUILayout.Space(hSpan); if (GUILayout.Button("Span Horizontal", GUILayout.Width(eSize))) { Transform[] tt = GLDTools.GetSelection(); foreach (Transform t in tt) { if (t.tag == "Wall") { RaycastHit h; Vector3 lft, rgt; if (Physics.Raycast(t.position, -t.right, out h)) { lft = h.point; if (Physics.Raycast(t.position, t.right, out h)) { rgt = h.point; t.position = (lft + rgt) / 2f; Vector3 tmp = t.localScale; tmp.x = (rgt - lft).magnitude; t.localScale = tmp; } } } } } GUILayout.Space(hSpan); EditorGUILayout.EndHorizontal(); GUILayout.Space(vSpan); EditorGUILayout.BeginHorizontal(); GUILayout.Space(hSpan); if (GUILayout.Button("Set", GUILayout.Width(eSize))) { Transform[] tt = GLDTools.GetSelection(); foreach (Transform t in tt) { if (t.tag == "Wall") { Vector3 s = t.localScale; t.position = t.position + t.up * (height - s.y) / 2f; s.y = height; t.localScale = s; } } } GUILayout.Space(hSpan); EditorGUIUtility.labelWidth = eSize / 2f; height = EditorGUILayout.FloatField("Height", height, GUILayout.Width(eSize)); GUILayout.Space(hSpan); EditorGUILayout.EndHorizontal(); }
void OnGUI() { minSize = new Vector2((float)pWidth, (float)pHeight); EditorGUILayout.LabelField("Select 2 objects"); GUILayout.Space(vSpan); EditorGUILayout.BeginHorizontal(); GUILayout.Space(hSpan); if (GUILayout.Button("Build", GUILayout.Width(eSize))) { Transform[] tt = GLDTools.GetSelection(); if (tt.Length != 2) { return; } Build(tt[0], tt[1]); } GUILayout.Space(hSpan); EditorGUIUtility.labelWidth = eSize / 2f; width = EditorGUILayout.FloatField("Width", width, GUILayout.Width(eSize)); GUILayout.Space(hSpan); EditorGUILayout.EndHorizontal(); GUILayout.Space(vSpan); EditorGUILayout.BeginHorizontal(); GUILayout.Space(hSpan); if (GUILayout.Button("Railings", GUILayout.Width(eSize))) { Transform[] tt = GLDTools.GetSelection(); foreach (Transform t in tt) { Debug.Log(t.tag); if (t.tag == "Bridge") { Debug.Log("A"); Quaternion q = t.rotation; t.rotation = Quaternion.identity; Vector3 sz = t.localScale; //GameObject n = GLDTools.NoCloneName ((GameObject) GameObject.Instantiate (Resources.Load ("Environment/Railing"), t.position + new Vector3(0f, rHeight / 2f, sz.z / 2f), Quaternion.identity)); //GameObject s = GLDTools.NoCloneName ((GameObject) GameObject.Instantiate (Resources.Load ("Environment/Railing"), t.position + new Vector3(0f, rHeight / 2f, -sz.z / 2f), Quaternion.identity)); GameObject e = GLDTools.NoCloneName((GameObject)GameObject.Instantiate(Resources.Load("Environment/Railing"), t.position + new Vector3(sz.x / 2f, rHeight / 2f, 0f), Quaternion.identity)); GameObject w = GLDTools.NoCloneName((GameObject)GameObject.Instantiate(Resources.Load("Environment/Railing"), t.position + new Vector3(-sz.x / 2f, rHeight / 2f, 0f), Quaternion.identity)); //n.transform.localScale = new Vector3 (sz.x, rHeight, 0.02f); //s.transform.localScale = new Vector3 (sz.x, rHeight, 0.02f); e.transform.localScale = new Vector3(0.02f, rHeight, sz.z); w.transform.localScale = new Vector3(0.02f, rHeight, sz.z); //n.transform.parent = t; //s.transform.parent = t; e.transform.parent = t; w.transform.parent = t; t.rotation = q; } } } GUILayout.Space(hSpan); EditorGUIUtility.labelWidth = eSize / 2f; rHeight = EditorGUILayout.FloatField("Height", rHeight, GUILayout.Width(eSize)); GUILayout.Space(hSpan); EditorGUILayout.EndHorizontal(); }