using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class CREATE : MonoBehaviour { public static void Point(GameObject Base, string N, float x, float y, float z) { GameObject point = GameObject.CreatePrimitive(PrimitiveType.Cube); if (point.GetComponent()) point.GetComponent().enabled = false; if (point.GetComponent()) point.GetComponent().enabled = false; point.name = N; point.transform.position = new Vector3(x, y, z); if(N.IndexOf("P")!=-1)point.transform.localScale = new Vector3(0f,0f, 0f); else point.transform.localScale = new Vector3(0,0, 0); point.transform.parent = Base.transform; } public static void EmptyPoint(GameObject Base, string N, float x, float y, float z) { GameObject point = new(N) { name = N }; point.transform.position = new Vector3(x, y, z); point.transform.parent = Base.transform; point.transform.localScale = new Vector3(0.00f, 0.00f, 0.00f); } public static void EmptyPoint(GameObject Base, string N, Vector3 Position) { GameObject point = new(N) { name = N }; point.transform.position = Position; point.transform.parent = Base.transform; point.transform.localScale = new Vector3(0.00f, 0.00f, 0.00f); } public static Mesh Mesh4V(Vector3 P1, Vector3 P2, Vector3 P3, Vector3 P4) { Mesh m = new Mesh { vertices = new Vector3[] { P1, P2, P3, P4 }, uv = new Vector2[] { new(0, 1), new(1, 1), new(1, 0), new(0, 0), }, triangles = new int[] { 0, 1, 2, 0, 2, 3 } }; m.RecalculateNormals(); return m; } public static Mesh Mesh3V(Vector3 P1, Vector3 P2, Vector3 P3) { Mesh m = new Mesh(); m.vertices = new Vector3[] { P1, P2, P3 }; m.uv = new Vector2[] { new (0, 1), new (1, 1), new (0, 0), }; m.triangles = new int[] { 0, 1, 2 }; m.RecalculateNormals(); return m; } //IMAGE public static Sprite SPRITE(string path, string rotation, float width, float height, string color) { Texture2D T2Door = Resources.Load(path); if (path.IndexOf("COUNT") == -1) { T2Door = ChangeColors(T2Door, DOIT.CSc(color, 255), Color.white); } if (rotation == "90") T2Door = DOIT.Rotate(T2Door); Vector4 borders = new Vector4(0.1f, 0.1f, 0.1f, 0.1f); width = width * 10; height = height * 10; if (width > 256) width = 256; if (height > 256) height = 256; Sprite TS = Sprite.Create(T2Door, new Rect(0f, 0f, width, height), Vector2.one * 0.5f, 256, 0, SpriteMeshType.FullRect, borders); return TS; } public static Sprite SPRITETEXTURE(string CODE, string Rs, float W, float H) { //string models = Get.CabTextureValue(CODE, 9); string models = Get.LibraryValue(CODE, CsvHeaders.Texture, DataTypes.CabTexture); //string Cs = Get.CabTextureValue(CODE, 13); string Cs = Get.LibraryValue(CODE, CsvHeaders.Normal_Strength, DataTypes.CabTexture); string sCs = Get.LibraryValue(CODE, CsvHeaders.Texture, DataTypes.CabTexture); Texture2D T2Door = Instantiate(Resources.Load("CABTEXTURE/" + models)); if (sCs != Cs) T2Door = ChangeColors(T2Door, DOIT.CSc(Cs, 255), Color.white); if (Rs == "90") T2Door = DOIT.Rotate(T2Door); Vector4 borders = new Vector4(0.1f, 0.1f, 0.1f, 0.1f); W = W * 10; H = H * 10; if (W > 256) W = 256; if (H > 256) H = 256; Sprite TS = Sprite.Create(T2Door, new Rect(0f, 0f, W, H), Vector2.one * 0.5f, 256, 0, SpriteMeshType.FullRect, borders); return TS; } public static Texture2D ChangeColors(Texture2D tex, Color newColor1, Color newColor2) { Texture2D newtexture = Instantiate(tex); var colors1 = newtexture.GetPixels(); for (var i = 0; i < colors1.Length; ++i) { float pixelValue = colors1[i].grayscale; colors1[i] = Color.Lerp(newColor1, newColor2, pixelValue); } newtexture.SetPixels(colors1); newtexture.Apply(); return newtexture; } //MATERIAL public static Material GetCounterMat(string name,string SCENE_PNL) { print("nmae===="+name); string[] Name = name.Split('?'); string Tex = Get.LibraryValue(Name[0], CsvHeaders.Texture, DataTypes.Counter); string Size = Get.LibraryValue(Name[0], CsvHeaders.Tile, DataTypes.Counter); string CT = Get.LibraryValue(Name[0], CsvHeaders.Contrast, DataTypes.Counter); string C1 = Get.LibraryValue(Name[0], CsvHeaders.Color_1, DataTypes.Counter); string C2 = Get.LibraryValue(Name[0], CsvHeaders.Color_2, DataTypes.Counter); string G = Get.LibraryValue(Name[0], CsvHeaders.Normal_Strength, DataTypes.Counter); string Rot = "0"; if (name.IndexOf('?') != -1) Rot = Name[1];//Get.CounterValue(Texture_name, CsvHeaders.Rotation).Replace("r", ""); string S = Get.LibraryValue(Name[0], CsvHeaders.Finish, DataTypes.Counter); if (S.IndexOf("G") != -1) { S = "0.95"; } if (S.IndexOf("S") != -1) { S = "0.8"; } if (S.IndexOf("M") != -1) { S = "0.5"; } //print("S==="+S); float Shine = DOIT.ConvertStringToNumber(S); string path = Tex.Split(".")[0]; //Material M = Instantiate(_G.MATTEXTURES); Material M; if(SCENE_PNL=="SCENE")M= Instantiate(_G.TEXTURE); else M = Instantiate(_G.MATTEXTURES_PNL); Texture2D T = Instantiate(Resources.Load("TEXTURES/" + path + "/" + Tex)); M.SetTexture("_MainTex", T);//texture M.SetFloat("_tile", DOIT.ConvertStringToNumber(Size));//size1 M.SetFloat("_contrast", DOIT.ConvertStringToNumber(CT));//Contrast M.SetColor("_c1", DOIT.CSc(C1, 255));//Color M.SetColor("_c2", DOIT.CSc(C2, 255));//Color Grout M.SetFloat("_normal", DOIT.ConvertStringToNumber(G));//Bump M.SetFloat("_rotation", DOIT.ConvertStringToNumber(Rot));//Rotation M.SetFloat("_smoothness", Shine);//_G.FLC[7] shine return M; } public static Material GetCounterMatFromCode(string code,string SCENE_PNL) { print("name===========================" + code); string[] c = code.Split(","); string Tex = c[0]; string size = c[1]; string Contrast = c[2]; string Cat = c[0].Substring(0, 4); Texture2D T = Resources.Load("TEXTURES/" + Cat + "/" + Tex); float Size = DOIT.ConvertStringToNumber(c[1]);//size float CT = DOIT.ConvertStringToNumber(c[2]);//size Color C1 = DOIT.CSc(c[3], 255);//color 1 Color C2 = DOIT.CSc(c[4], 255);//color 2 //Grout float G = 0; if (c[5] == "NA") { c[5] = "0.5"; } G = DOIT.ConvertStringToNumber(c[5]); //Rotation float R = DOIT.ConvertStringToNumber(c[6].Replace("r", "")); //Shine if (c[7].IndexOf("G") != -1) { c[7] = "0.95"; } if (c[7].IndexOf("S") != -1) { c[7] = "0.8"; } if (c[7].IndexOf("M") != -1) { c[7] = "0.5"; } float S = DOIT.ConvertStringToNumber(c[7]); float GI = DOIT.ConvertStringToNumber(c[9]); Material M; if(SCENE_PNL=="SCENE")M= Instantiate(_G.TEXTURE); else M = Instantiate(_G.MATTEXTURES_PNL); M.SetTexture("_MainTex", T);//texture M.SetFloat("_tile", DOIT.ConvertStringToNumber(size));//size1 M.SetFloat("_contrast", DOIT.ConvertStringToNumber(Contrast));//Contrast M.SetColor("_c1", C1);//Color M.SetColor("_c2", C2);//Color Grout M.SetFloat("_normal", G);//Bump M.SetFloat("_rotation", R);//Rotation M.SetFloat("_smoothness", S);//_G.FLC[7] shine M.SetFloat("_normaltoggle", 1); return M; } public static Material GetMatfromRawCode(string code,string SCENE_PNL) { Material M; if(SCENE_PNL=="SCENE")M= Instantiate(_G.TEXTURE); else M = Instantiate(_G.MATTEXTURES_PNL); string[] c = code.Split(","); string Tex = c[0]; string size = c[1]; string Contrast = c[2]; string Cat = c[0].Substring(0, 4); Texture2D T = Resources.Load("TEXTURES/" + Cat + "/" + Tex); float Size = DOIT.ConvertStringToNumber(c[1]);//size float CT = DOIT.ConvertStringToNumber(c[2]);//size Color C1 = DOIT.CSc(c[3], 255);//color 1 Color C2 = DOIT.CSc(c[4], 255);//color 2 //Grout float G = 0; if (c[5] == "NA") { c[5] = "0.5"; } G = DOIT.ConvertStringToNumber(c[5]); //Rotation float R = DOIT.ConvertStringToNumber(c[6].Replace("r", "")); //Shine if (c[7].IndexOf("G") != -1) { c[7] = "0.95"; } if (c[7].IndexOf("S") != -1) { c[7] = "0.8"; } if (c[7].IndexOf("M") != -1) { c[7] = "0.5"; } float S = DOIT.ConvertStringToNumber(c[7]); //float GI = DOIT.ConvertStringToNumber(c[9]); M.SetTexture("_MainTex", T);//_G.FLC[0] texture M.SetFloat("_tile", Size);//_G.FLC[1] size1 X M.SetFloat("_contrast", CT);//_G.FLC[2] Contrast M.SetColor("_c1", C1);//_G.FLC[3] M.SetColor("_c2", C2);//_G.FLC[4] M.SetFloat("_normal", G);//_G.FLC[5] Grouth bump value M.SetFloat("_rotation", R);//_G.FLC[6] rotation M.SetFloat("_smoothness", S);//_G.FLC[7] shine //MAT.SetFloat("_intensity", GI);//_G.FLC[7] Intensity return M; } public static string Hexiset(string H) { if (H == null) return H; H = H.Replace(".", "").Replace("+", ""); if (H.Length == 5) H = "0" + H; if (H == "0") H = "000000"; return H; } public static void ResetMaterialFromName(Material M, string id, string cat) { string[] Name = id.Split('?'); string G = "1"; string Rot = "0"; string path = "CABTEXTURE/"; string Tex; string Size; string CT; string C1; string C2; string S; Tex = UIT.Value("CabTexture",id,"Texture"); Size = "1"; CT = UIT.Value("CabTexture",id,"Contrast"); C1 = UIT.Value("CabTexture",id,"C1"); C2 = UIT.Value("CabTexture",id,"C2"); S = "S"; string C3 = ""; string color3= ""; if(!_G.UIT) { color3 = Get.LibraryValue(Name[0], CsvHeaders.Color_3, cat); if (!string.IsNullOrEmpty(color3)) { C3 = Hexiset(Get.LibraryValue(Name[0], CsvHeaders.Color_3, cat)); } } else C3 = UIT.Value("CabTexture",id,"C3"); if (cat == "Counter") { path = "TEXTURES/COUN/"; } if (S.IndexOf("G") != -1) { S = "0.95"; } if (S.IndexOf("S") != -1) { S = "0.8"; } if (S.IndexOf("M") != -1) { S = "0.5"; } float Shine = DOIT.ConvertStringToNumber(S); Texture2D T = Instantiate(Resources.Load(path + Tex)); M.SetTexture("_MainTex", T);//texture M.SetFloat("_tile", DOIT.ConvertStringToNumber(Size));//size1 M.SetFloat("_contrast", DOIT.ConvertStringToNumber(CT));//Contrast M.SetColor("_c1", DOIT.CSc(C1, 255));//Color M.SetColor("_c2", DOIT.CSc(C2, 255));//Color Grout if (!string.IsNullOrEmpty(color3)) { M.SetColor("_c3", DOIT.CSc(C3, 255));//Color Grout } M.SetFloat("_normal", DOIT.ConvertStringToNumber(G));//Bump M.SetFloat("_rotation", DOIT.ConvertStringToNumber(Rot));//Rotation M.SetFloat("_smoothness", Shine);//_G.FLC[7] shine } public static void ResetMaterialFromCode(Material M, string code, string cat) { print("code from ResetMaterialFromCode===="+code);//code from ResetMaterialFromCode====none,FFFFFFFF,FFFFFFFF,FFFFFFFF,0.25,0.25,0.25,0.5,0.25 // none, Texture index 0 // FFFFFFFF, Color 1 index 1 // FFFFFFFF, Color 2 index 2 // FFFFFFFF, Color 3 index 3 // 0.25, Tile Horizontal index 4 // 0.25, Tile Vertical index 5 // 0.25, Smootness index 6 // 0.5, Metallic index 7 // 0.25 Contrast index 8 //Adding to code // 1 index 9 //0.05 index 10 //0.25 index 11 //0 index 12 code =code.Replace("?",","); //if (code.Split(',').Length < 10) { code += ",1,0.05,0.25,0"; } string[] c = code.Split(","); string Tex = c[0]; Color C1 = DOIT.CSc(c[1], 255);//color 1 Color C2 = DOIT.CSc(c[2], 255);//color 2 // Color C3 = DOIT.CSc(c[2], 255);//color 3 // float Size = DOIT.ConvertStringToNumber(c[4]);//size // float CT = DOIT.ConvertStringToNumber(c[2]);//size // float R = DOIT.ConvertStringToNumber(c[6].Replace("r", ""));//Rotation //Shine // if (c[7].IndexOf("G") != -1) { c[7] = "0.95"; } // if (c[7].IndexOf("S") != -1) { c[7] = "0.8"; } // if (c[7].IndexOf("M") != -1) { c[7] = "0.5"; } // float S = DOIT.ConvertStringToNumber(c[7]); // //Grout // float G = 0; // if (c[5] == "NA") { c[5] = "0.5"; } // G = DOIT.ConvertStringToNumber(c[5]); // float GI = 1; // if (c.Length == 9) { GI = DOIT.ConvertStringToNumber(c[9]); } string Cat = ""; Texture2D T = null; if (Tex != "null") { Cat = c[0][..4]; if (Tex.IndexOf("Plywood") != -1) Tex = "WOOD.21"; if (Tex.IndexOf("Gypse") != -1) { Tex = "GypseHorizontal"; Cat = "ROOM"; } string path = "TEXTURES/" + Cat; if (cat == "CabTexture") { path = "TEXTURES"; } T = Resources.Load(path + "/" + Tex); } /*if (cat == "CabTexture" ||cat == "wall" ) { } /*else { Cat = c[0][..4]; if (Tex.IndexOf("Gypse") != -1) { Tex = "GypseHorizontal"; Cat = "ROOM"; } T = Resources.Load("TEXTURES/" + Cat + "/" + Tex); } if (cat == "Variable"){ T = Resources.Load("CABTEXTURE/" + Tex); } if (cat == "Wall"){ T = Resources.Load("CABTEXTURE/" + Tex); }*/ //New M.SetTexture("_MainTex", T);//_G.FLC[0] texture //M.SetFloat("_tile", Size);//_G.FLC[1] size1 X //M.SetFloat("_contrast", CT);//_G.FLC[2] Contrast M.SetColor("_c1", C1);//_G.FLC[3] M.SetColor("_c2", C2);//_G.FLC[4] //M.SetFloat("_normal", G);//_G.FLC[5] Grouth bump value //M.SetFloat("_rotation", R);//_G.FLC[6] rotation //M.SetFloat("_Smoothness", S);//_G.FLC[7] shine M.SetFloat("_Metallic", 0.05f);// //M.SetFloat("_intensity", GI); // if(_G.FLC.Length>10){ // M.SetFloat("_intensity", DOIT.ConvertStringToNumber(c[10])); // M.SetFloat("_SmoothnessTexture", DOIT.ConvertStringToNumber(c[11])); // M.SetFloat("_Tile_Offset_X", DOIT.ConvertStringToNumber(c[12])); // M.SetFloat("_Tile_Offset_Y", DOIT.ConvertStringToNumber(c[13])); // } } }