using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Globalization; public class SetMolding : MonoBehaviour { static float t = 0.625f; //static float mUol = t * 1.5f; // static float mUor = t * 1.5f; //static float dis = 0; //static float discenter = 0; static Vector3 PC; static Vector3 PCO; static float W; //static float WS; static float H; static float D; static Texture tex; static float Uh = 3; static float UY; static Vector3 heading; //static float distance; static Vector3 direction; static GameObject TAR; static GameObject SEL; public static void Under() { for (int i = 0; i < _G.OBJnum; i++) { if (_G.OBJs[i] != null && _G.OBJs[i][4] == "W1" || _G.OBJs[i] != null && _G.OBJs[i][4] == "W4" || _G.OBJs[i] != null && _G.OBJs[i][4] == "W5") { _G.OBJs[i][71]= "0,0,0,0"; TAR = GameObject.Find(_G.OBJs[i][0]).gameObject; Vector3 Tp1 = TAR.transform.Find("P1").position; Vector3 Tp4 = TAR.transform.Find("P4").position; for (int k = 0; k < _G.OBJnum; k++) { if (_G.OBJs[k] != null && _G.OBJs[k][0] != _G.OBJs[i][0] && _G.OBJs[k][4] == "W1" || _G.OBJs[k] != null && _G.OBJs[k][0] != _G.OBJs[i][0] && _G.OBJs[k][4] == "W4" || _G.OBJs[k] != null && _G.OBJs[k][0] != _G.OBJs[i][0] && _G.OBJs[k][4] == "W5") { string[] UC = _G.OBJs[i][71].Split(","[0]); SEL = GameObject.Find(_G.OBJs[k][0]).gameObject; Vector3 Sp1 = SEL.transform.Find("P1").position; Vector3 Sp4 = SEL.transform.Find("P4").position; print("Tp4==" + Tp4 + " TARt=="+ i); print("Sp1==" + Sp1 + " SEL==" + i); if (Tp1 == Sp4) { UC[0] = "Um1"; } if (Tp4 == Sp1) { UC[2] = "Um3"; } _G.OBJs[i][71] = UC[0]+","+ UC[1] + "," + UC[2] + "," + UC[3] ; } } } } createUnderMolding(); } public static void createUnderMolding() { for (int i = 0; i < _G.OBJnum; i++) { if (_G.OBJs[i] != null && _G.OBJs[i][4] == "W1" || _G.OBJs[i] != null && _G.OBJs[i][4] == "W4" || _G.OBJs[i] != null && _G.OBJs[i][4] == "W5") { string[] UC = _G.OBJs[i][71].Split(","[0]); print("UC==== " +i.ToString(CultureInfo.InvariantCulture)+"===="+ _G.OBJs[i][71]); float t = 0.625f; SEL= GameObject.Find(_G.OBJs[i][0]).gameObject; SEL.transform.localRotation = Quaternion.Euler(0, 0, 0); W = DOIT.ConvertStringToNumber(_G.OBJs[i][6]); H = DOIT.ConvertStringToNumber(_G.OBJs[i][7]); D = DOIT.ConvertStringToNumber(_G.OBJs[i][8]); UY = -H / 2 - Uh / 2; float mUol = t * 1.0f; float mUor = t * 1.0f; if (UC[0] != "0") mUol = 0; if (UC[2] != "0") mUor = 0; //Delete List list = new List(); foreach(Transform child in SEL.transform){if (child.name.Substring(0,2) =="Um") list.Add(child.gameObject);} foreach (GameObject child in list){ Destroy(child);} if (_G.OBJs[i][4] == "W1") { if (mUol != 0) { GameObject Um1 = CreateUnder(SEL, "Um1", D - t * 2, Uh, t, -W / 2 + t+t/2, UY, t, 0, -90, 0, tex); } //GameObject Um2 = CreateUnder(OBJ, "Um2", W - 4 * t, Uh, t, 0, UY, D / 2 - t / 2 - t / 2, 0, 0, 0, tex); if (mUor != 0) { GameObject Um3 = CreateUnder(SEL, "Um3", D - t * 2, Uh, t, W / 2 - t-t/2, UY, t, 0, 90, 0, tex); } GameObject Um4 = CreateUnder(SEL, "Um4", W - mUol - mUor, Uh, t, mUol / 2 - mUor / 2, UY, -D / 2 + t + t / 2, 0, 0, 0, tex); } if (_G.OBJs[i][4] == "W4") { float dd = 13.4375f; float ddf = W - dd; float p1 = ddf / 0.707f; if (mUol != 0) { GameObject Um1 = CreateUnder(SEL, "Um1", dd - t * 2, Uh, t, -dd / 2 + t + t / 2, UY, -D/2+ t + t / 2, 0, 0, 0, tex); } if (mUor != 0) { GameObject Um3 = CreateUnder(SEL, "Um3", dd - t * 2, Uh, t, W / 2 - t - t / 2, UY, D/2-dd/2+t+t/2, 0, 90, 0, tex); } GameObject Um4 = CreateUnder(SEL, "Um4", p1+t*3 - mUol - mUor, Uh, t, W/2- ddf /2- +t / 0.707f, UY, -D / 2 + ddf/2+t/0.707f, 0, -45, 0, tex); } SEL.transform.localRotation = Quaternion.Euler(DOIT.ConvertStringToNumber(_G.OBJs[i][18]), DOIT.ConvertStringToNumber(_G.OBJs[i][19]), DOIT.ConvertStringToNumber(_G.OBJs[i][20])); } } } private static GameObject CreateUnder( GameObject OBJ,string Name, float sx, float sy, float sz, float px, float py, float pz, float rx, float ry, float rz, Texture tex) { GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube); obj.GetComponent().enabled = false; obj.transform.localScale = new Vector3(sx, sy, sz); obj.transform.position = OBJ.transform.position + OBJ.transform.TransformDirection(new Vector3(px, py, pz)); obj.transform.localRotation = Quaternion.Euler(rx, ry, rz); obj.GetComponent().material = new Material(Shader.Find("Universal Render Pipeline/Lit")); obj.GetComponent().material.mainTexture = tex; obj.GetComponent().material.mainTextureScale = new Vector2(sx / 12f, sy / 12f); //obj.GetComponent().probeAnchor = GameObject.Find("Reflection Probe").transform; obj.name = Name; //obj.tag = "cabbox"; obj.transform.SetParent(OBJ.transform); return obj; } }