using UnityEngine; using UnityEngine.ResourceManagement.AsyncOperations; using UnityEngine.AddressableAssets; using System.Collections; public class CounterMCX : MonoBehaviour { private Texture2D Tex; static string TAG; static Material Mat; string Ctex; public static GameObject MCX4V(string Category, float t, Vector3 P1, Vector3 P2, Vector3 P3, Vector3 P4, string ctex) { //print("counetr texture============================================"+ctex); SetTexture(ctex); GameObject S = new("S"); Vector3 P1y = new(P1.x, P1.y - t, P1.z); Vector3 P2y = new(P2.x, P2.y - t, P2.z); Vector3 P3y = new(P3.x, P3.y - t, P3.z); Vector3 P4y = new(P4.x, P4.y - t, P4.z); SideV(S, "top", P1, P2, P3, P4, 90, 90, 0, 0, 0);//top SideV(S, "f", P1y, P1, P4, P4y, 90, 90, 0, 0, 0);//front SideV(S, "b", P3y, P3, P2, P2y, 90, 90, 0, 0, 0);//Back SideV(S, "l", P2y, P2, P1, P1y, 90, 90, 0, 0, 0);//left SideV(S, "r", P4y, P4, P3, P3y, 90, 90, 0, 0, 0);//Right if(Category=="CounterTop"){StaticCoroutine.Start(GORETURN(S));} return S; } public static IEnumerator GORETURN(GameObject GO) { // print("Mat.name====" + Mat.name); Addressables.LoadAssetAsync(Mat.name).Completed += handle => { if (handle.Status == AsyncOperationStatus.Succeeded) { Texture2D tex = Instantiate(handle.Result); foreach (Transform Side in GO.transform) { if (Side.childCount == 0) { Side.GetComponent().material.SetTexture("_Texture", tex); } else { foreach (Transform mcx in Side.transform) { mcx.GetComponent().material.SetTexture("_Texture", tex); } } } } else { Debug.LogError("Failed to load texture: " + Mat.name); } }; yield return null; //new WaitForSeconds(2); } public static GameObject MCX5VL(string Category,float t, float dd, float w, Vector3 P1, Vector3 P2, Vector3 P3, Vector3 P4, Vector3 P5, string ctex) { SetTexture(ctex); GameObject S = new("S"); GameObject top = new(); top.AddComponent(typeof(MeshFilter)); top.AddComponent(typeof(MeshRenderer)); top.GetComponent().mesh = CreateMeshShape5VL(t, dd, w, P1, P2, P3, P4, P5); top.GetComponent().material = Mat; top.GetComponent().probeAnchor = GameObject.Find("Reflection Probe").transform; DOIT.SetSizeTex(top, 2 * 12, 2 * 12, 0, 0, 0, 0, 90, 90); top.transform.parent = S.transform; top.name = "top"; top.tag = TAG; Vector3 P1y = new(P1.x, P1.y - t, P1.z); Vector3 P2y = new(P2.x, P2.y - t, P2.z); Vector3 P3y = new(P3.x, P3.y - t, P3.z); Vector3 P4y = new(P4.x, P4.y - t, P4.z); Vector3 P5y = new(P5.x, P5.y - t, P5.z); float h = Mathf.Abs(P1.y - P1y.y); w = Mathf.Abs(P1.x - P5.x); SideV(S, "f", P1y, P1, P5, P5y, 0, 0, 0, 0, 0);//front w = Mathf.Abs(P2.z - P1.z); SideV(S, "s", P2y, P2, P1, P1y, 0, 0, 0, 0, 0);//S1 w = Mathf.Abs(P3.x - P2.x); SideV(S, "s", P3y, P3, P2, P2y, 0, 0, 0, 0, 0);//S2 w = Mathf.Abs(P4.z - P3.z); SideV(S, "s", P4y, P4, P3, P3y, 0, 0, 0, 0, 0);//S3 w = Mathf.Abs(P4.x - P5.x); SideV(S, "s", P5y, P5, P4, P4y, 0, 0, 0, 0, 0);//S4 //w = Mathf.Abs(P5.z - P6.z); //SideV(S, "s", P6y, P6, P5, P5y, "zy");//S5 if(Category=="CounterTop"){StaticCoroutine.Start(GORETURN(S));} return S; } public static GameObject MCX5VR(string Category,float t, float dd, float w, Vector3 P1, Vector3 P2, Vector3 P3, Vector3 P4, Vector3 P5, string ctex) { SetTexture(ctex); GameObject S = new("S"); GameObject top = new(); top.AddComponent(typeof(MeshFilter)); top.AddComponent(typeof(MeshRenderer)); top.GetComponent().mesh = CreateMeshShape5VR(t, dd, w, P1, P2, P3, P4, P5); top.GetComponent().material = Mat; top.GetComponent().probeAnchor = GameObject.Find("Reflection Probe").transform; DOIT.SetSizeTex(top, 2 * 12, 2 * 12, 0, 0, 0, 0, 90, 90); top.transform.parent = S.transform; top.name = "top"; top.tag = TAG; Vector3 P1y = new(P1.x, P1.y - t, P1.z); Vector3 P2y = new(P2.x, P2.y - t, P2.z); Vector3 P3y = new(P3.x, P3.y - t, P3.z); Vector3 P4y = new(P4.x, P4.y - t, P4.z); Vector3 P5y = new(P5.x, P5.y - t, P5.z); w = Mathf.Abs(P1.x - P5.x); float h = Mathf.Abs(P1.y - P1y.y); SideV(S, "f", P1y, P1, P5, P5y, 0, 0, 0, 0, 0);//front w = Mathf.Abs(P2.z - P1.z); SideV(S, "s1", P2y, P2, P1, P1y, 0, 0, 0, 0, 0);//S1 w = Mathf.Abs(P3.x - P2.x); SideV(S, "s2", P3y, P3, P2, P2y, 0, 0, 0, 0, 0);//S2 w = Mathf.Abs(P4.z - P3.z); SideV(S, "s3", P4y, P4, P3, P3y, 0, 0, 0, 0, 0);//S3 w = Mathf.Abs(P4.x - P5.x); SideV(S, "s4", P5y, P5, P4, P4y, 0, 0, 0, 0, 0);//S4 if(Category=="CounterTop"){StaticCoroutine.Start(GORETURN(S));} return S; } public static GameObject MCX6VL(string Category,float t, float dd, float w, Vector3 P1, Vector3 P2, Vector3 P3, Vector3 P4, Vector3 P5, Vector3 P6, string ctex) { SetTexture(ctex); GameObject S = new("S"); GameObject top = new(); top.AddComponent(typeof(MeshFilter)); top.AddComponent(typeof(MeshRenderer)); top.GetComponent().mesh = CreateMeshShape6VL(t, dd, w, P1, P2, P3, P4, P5, P6); top.GetComponent().material = Mat; top.GetComponent().probeAnchor = GameObject.Find("Reflection Probe").transform; top.transform.parent = S.transform; top.name = "top"; top.tag = TAG; DOIT.SetSizeTex(top, 2 * 12, 2 * 12, 0, 0, 0, 0, 90, 90); Vector3 P1y = new(P1.x, P1.y - t, P1.z); Vector3 P2y = new(P2.x, P2.y - t, P2.z); Vector3 P3y = new(P3.x, P3.y - t, P3.z); Vector3 P4y = new(P4.x, P4.y - t, P4.z); Vector3 P5y = new(P5.x, P5.y - t, P5.z); Vector3 P6y = new(P6.x, P6.y - t, P6.z); float h = Mathf.Abs(P1.y - P1y.y); w = Mathf.Abs(P1.x - P6.x); SideV(S, "f", P1y, P1, P6, P6y, 0, 0, 0, 0, 0);//front w = Mathf.Abs(P2.z - P1.z); SideV(S, "s", P2y, P2, P1, P1y, 0, 0, 0, 0, 0);//S1 w = Mathf.Abs(P3.x - P2.x); SideV(S, "s", P3y, P3, P2, P2y, 0, 0, 0, 0, 0);//S2 w = Mathf.Abs(P4.z - P3.z); SideV(S, "s", P4y, P4, P3, P3y, 0, 0, 0, 0, 0);//S3 w = Mathf.Abs(P4.x - P5.x); SideV(S, "s", P5y, P5, P4, P4y, 0, 0, 0, 0, 0);//S4 w = Mathf.Abs(P5.z - P6.z); SideV(S, "s", P6y, P6, P5, P5y, 0, 0, 0, 0, 0);//S5 if(Category=="CounterTop"){StaticCoroutine.Start(GORETURN(S));} return S; } public static GameObject MCX6VR(string Category,float t, float dd, float w, Vector3 P1, Vector3 P2, Vector3 P3, Vector3 P4, Vector3 P5, Vector3 P6, string ctex) { //print("ctex======" + ctex); SetTexture(ctex); GameObject S = new("S"); GameObject top = new(); top.AddComponent(typeof(MeshFilter)); top.AddComponent(typeof(MeshRenderer)); top.GetComponent().mesh = CreateMeshShape6VR(t, dd, w, P1, P2, P3, P4, P5, P6); top.GetComponent().material = Mat; top.GetComponent().probeAnchor = GameObject.Find("Reflection Probe").transform; DOIT.SetSizeTex(top, 2 * 12, 2 * 12, 0, 0, 0, 0, 90, 90); /* top.GetComponent().material = Instantiate(_G.ST);//Resources.Load("MATERIALS/ST") as Material; top.GetComponent().material.mainTexture = Tex; DOIT.SetSizeTex(top, Size * 12, Size * 12, 0, 0, 0, 0, 90, 90); top.GetComponent().material.color = Col; top.GetComponent().material.SetFloat("_Smoothness", Shine); top.GetComponent().probeAnchor = GameObject.Find("Reflection Probe").transform;*/ top.transform.parent = S.transform; top.name = "top"; top.tag = TAG; Vector3 P1y = new(P1.x, P1.y - t, P1.z); Vector3 P2y = new(P2.x, P2.y - t, P2.z); Vector3 P3y = new(P3.x, P3.y - t, P3.z); Vector3 P4y = new(P4.x, P4.y - t, P4.z); Vector3 P5y = new(P5.x, P5.y - t, P5.z); Vector3 P6y = new(P6.x, P6.y - t, P6.z); w = Mathf.Abs(P1.x - P6.x); float h = Mathf.Abs(P1.y - P1y.y); SideV(S, "s", P1y, P1, P6, P6y, 0, 0, 0, 0, 0);//front w = Mathf.Abs(P2.z - P1.z); SideV(S, "s", P2y, P2, P1, P1y, 0, 0, 0, 0, 0);//S1 w = Mathf.Abs(P3.x - P2.x); SideV(S, "s", P3y, P3, P2, P2y, 0, 0, 0, 0, 0);//S2 w = Mathf.Abs(P4.z - P3.z); SideV(S, "s", P4y, P4, P3, P3y, 0, 0, 0, 0, 0);//S3 w = Mathf.Abs(P4.x - P5.x); SideV(S, "s", P5y, P5, P4, P4y, 0, 0, 0, 0, 0);//S4 w = Mathf.Abs(P5.z - P6.z); SideV(S, "s", P6y, P6, P5, P5y, 0, 0, 0, 0, 0);//S4 if(Category=="CounterTop"){StaticCoroutine.Start(GORETURN(S));} return S; } public static GameObject SideR(float t, float h, Vector3 P2, Vector3 P1) { GameObject SR = new("SR"); Vector3 P3 = new(P2.x + t, P1.y, P2.z); Vector3 P4 = new(P1.x + t, P1.y, P1.z); Vector3 P1y = new(P1.x, P1.y - h, P1.z); Vector3 P2y = new(P2.x, P2.y - h, P2.z); Vector3 P3y = new(P3.x, P3.y - h, P3.z); Vector3 P4y = new(P4.x, P4.y - h, P4.z); SideV(SR, "top", P1, P2, P3, P4, 0, 0, 0, 0, 0);//top SideV(SR, "f", P1y, P1, P4, P4y, 0, 0, 0, 0, 0);//front SideV(SR, "b", P3y, P3, P2, P2y, 0, 0, 0, 0, 0);//Back SideV(SR, "l", P2y, P2, P1, P1y, 0, 0, 0, 0, 0);//left SideV(SR, "r", P4y, P4, P3, P3y, 0, 0, 0, 0, 0);//Right StaticCoroutine.Start(GORETURN(SR)); return SR; } public static GameObject SideL(float t, float h, Vector3 P4, Vector3 P3) { GameObject SL = new("SL"); Vector3 P1 = new(P4.x - t, P4.y, P4.z); Vector3 P2 = new(P3.x - t, P1.y, P3.z); Vector3 P1y = new(P1.x, P1.y - h, P1.z); Vector3 P2y = new(P2.x, P2.y - h, P2.z); Vector3 P3y = new(P3.x, P3.y - h, P3.z); Vector3 P4y = new(P4.x, P4.y - h, P4.z); SideV(SL, "top", P1, P2, P3, P4, 0, 0, 0, 0, 0);//top SideV(SL, "f", P1y, P1, P4, P4y, 0, 0, 0, 0, 0);//front SideV(SL, "b", P3y, P3, P2, P2y, 0, 0, 0, 0, 0);//Back SideV(SL, "l", P2y, P2, P1, P1y, 0, 0, 0, 0, 0);//left SideV(SL, "r", P4y, P4, P3, P3y, 0, 0, 0, 0, 0);//Right StaticCoroutine.Start(GORETURN(SL)); return SL; } public static GameObject SideB(float t, float h, Vector3 P1, Vector3 P4) { GameObject SB = new("SR"); Vector3 P2 = new(P1.x, P1.y, P1.z + t); Vector3 P3 = new(P4.x, P1.y, P4.z + t); Vector3 P1y = new(P1.x, P1.y - h, P1.z); Vector3 P2y = new(P2.x, P2.y - h, P2.z); Vector3 P3y = new(P3.x, P3.y - h, P3.z); Vector3 P4y = new(P4.x, P4.y - h, P4.z); SideV(SB, "top", P1, P2, P3, P4, 0, 0, 0, 0, 0);//top SideV(SB, "f", P1y, P1, P4, P4y, 0, 0, 0, 0, 0);//front SideV(SB, "b", P3y, P3, P2, P2y, 0, 0, 0, 0, 0);//Back SideV(SB, "l", P2y, P2, P1, P1y, 0, 0, 0, 0, 0);//left SideV(SB, "r", P4y, P4, P3, P3y, 0, 0, 0, 0, 0);//Right StaticCoroutine.Start(GORETURN(SB)); return SB; } public static Mesh CreateMeshShape4V(Vector3 P1, Vector3 P2, Vector3 P3, Vector3 P4) { Mesh m = new(); m.vertices = new[] { P1, P2, P3, P4 }; m.uv = new Vector2[] { new (0, 0), new (0, 1), new (1, 1), new (1, 0), }; m.triangles = new int[] { 0, 1, 2, 0, 2, 3 }; m.RecalculateNormals(); m.RecalculateTangents(); return m; } public static Mesh CreateMeshShape6VL(float T, float dd, float w, Vector3 P1, Vector3 P2, Vector3 P3, Vector3 P4, Vector3 P5, Vector3 P6) { Mesh m = new Mesh(); float a = dd / w; m.vertices = new[] { P1, P2, P3, P4, P5, P6 }; m.uv = new Vector2[] { new(0, 0), new(0, 1), new(1, 1), new(1, 1-a), new(a, 1-a), new(a, 0) }; m.triangles = new int[] { 1, 2, 3, 1, 3, 4, 1, 4, 5, 1, 5, 0 }; m.RecalculateNormals(); m.RecalculateTangents(); return m; } public static Mesh CreateMeshShape6VR(float T, float dd, float w, Vector3 P1, Vector3 P2, Vector3 P3, Vector3 P4, Vector3 P5, Vector3 P6) { Mesh m = new Mesh(); float a = dd / w; m.vertices = new[] { P1, P2, P3, P4, P5, P6 }; m.uv = new Vector2[] { new (0, 1-a), new (0, 1), new (1, 1), new (1, 0), new (1-a, 0), new (1-a, 1-a) }; m.triangles = new int[] { 2, 3, 4, 2, 4, 5, 2, 5, 0, 2, 0, 1 }; m.RecalculateNormals(); m.RecalculateTangents(); return m; } public static Mesh CreateMeshShape5VL(float T, float dd, float w, Vector3 P1, Vector3 P2, Vector3 P3, Vector3 P4, Vector3 P5) { Mesh m = new Mesh(); float a = dd / w; m.vertices = new[] { P1, P2, P3, P4, P5 }; m.uv = new Vector2[] { new (0, 0), new (0, 1), new (1, 1), new (1, 1-a), new (a, 0) }; m.triangles = new int[] { 0, 1, 2, 0, 2, 3, 0, 3, 4 }; m.RecalculateNormals(); m.RecalculateTangents(); return m; } public static Mesh CreateMeshShape5VR(float T, float dd, float w, Vector3 P1, Vector3 P2, Vector3 P3, Vector3 P4, Vector3 P5) { Mesh m = new Mesh(); float a = dd / w; m.vertices = new[] { P1, P2, P3, P4, P5 }; m.uv = new Vector2[] { new (0, 1-a), new (0, 1), new (1, 1), new (1, 0), new (1-a, 0) }; m.triangles = new int[] { 1, 2, 3, 1, 3, 4, 1, 4, 0, }; m.RecalculateNormals(); m.RecalculateTangents(); return m; } public static GameObject SideV(GameObject S, string N, Vector3 P1, Vector3 P2, Vector3 P3, Vector3 P4, float RB, float RF, float RL, float RR, float RT) { GameObject s = new(N); s.AddComponent(typeof(MeshFilter)); s.AddComponent(typeof(MeshRenderer)); s.AddComponent(typeof(BoxCollider)); s.GetComponent().enabled = false; s.GetComponent().mesh = CreateMeshShape4V(P1, P2, P3, P4); s.GetComponent().material = Mat;//CREATE.getCounterMat(Code,24,24,"0"); s.GetComponent().probeAnchor = GameObject.Find("Reflection Probe").transform; s.transform.parent = S.transform; s.tag = TAG; DOIT.SetSizeTex(s, 2 * 12, 2 * 12, RB, RF, RL, RR, RT, 0);//back,front,l,r,top,under return s; } public static void SetTexture(string ctex) { //print("From CounterMCXctex===="+ctex);//COUN.1,1,1,FFFFFF,FFFFFF,1,90,S,ffffff,1,none Mat = UIT_MATERIAL.GetMaterial(ctex); TAG = "counter"; ctex.Replace(",", "?"); Mat.name = ctex.Split("?")[0]; } }