using System.Collections.Generic; using UnityEngine; public class Addknob : MonoBehaviour { //public static GameObject knob; public static void Knob(GameObject DS,float w, float h, string p, float px, float py, int nO, string cat, float depth, string modelDoor) { if (!IsModelAllowingKnobs(modelDoor)) { _G.OBJs[nO][85] = "NONE"; _G.OBJs[nO][86] = "NONE"; //return null; } else if(_G.OBJs[nO][60] != "UNIQUE") // check if cab is link with a global or is unique, if is global, assign back the current knob for the global of that cab { if (int.TryParse(_G.OBJs[nO][60].Substring(_G.OBJs[nO][60].Length - 1, 1), out int global)) { if (_G.OBJs[nO][85] == "NONE") { //_G.OBJs[nO][85] = _G.GLOBAL[global][7]; } if (_G.OBJs[nO][86] == "NONE") { //_G.OBJs[nO][86] = _G.GLOBAL[global][10]; } } } int nk = 85; if (cat == "d") {nk = 86;}//if drawer if(_G.OBJs[nO][nk].Split("?").Length<3){_G.OBJs[nO][nk]+="?#000000FF_Mat_none?6.57?0.39?1.10";} string[] CODE=_G.OBJs[nO][nk].Split('?'); string kcode = CODE[0]; print("_G.OBJs[nO][nk]======" + _G.OBJs[nO][nk]); //G.OBJs[nO][nk]======K_6?V?#737373_Matt_none?6.57?0.39?12 //_G.OBJs[nO][nk]======K_54?V?666666_Gloss?6.5625?1?1 if (kcode != "NONE" && kcode != "K_NONE") { string VH = CODE[1]; GameObject Knob = new(); //string Oname = UIT_KNOB.GetIconName(kcode); if (!string.IsNullOrEmpty(kcode) && kcode != "NONE") { //LOAD Knob = Instantiate(Resources.Load("OBJECTS/KNOBS/" + kcode, typeof(GameObject))) as GameObject; //MATERIALS Material mat2 = UIT_MATERIAL.GetMaterial("ff00ff_Metal"); Material mat = UIT_MATERIAL.GetMaterial(CODE[2]); //if (CODE[2].IndexOf("&") != -1){ mat2 = UIT_MATERIAL.GetMaterial(CODE[2].Split("&")[1]); } GameObject C1 = null; GameObject C2 = null; //COLORS for (int i = 0; i < Knob.transform.childCount; i++) { if (Knob.transform.GetChild(i).name.IndexOf("C1") != -1) { C1 = Knob.transform.GetChild(i).gameObject; } if (Knob.transform.GetChild(i).name.IndexOf("C2") != -1) { C1 = Knob.transform.GetChild(i).gameObject; } } if (C1 != null) { if (new List { "K_54", "K_3", "K_6", "K_7" }.Contains(CODE[0])) C1.transform.localRotation = Quaternion.Euler(0, -90, 90); C1.GetComponent().material = mat; } if (C2 != null) { C2.transform.localRotation = Quaternion.Euler(0, -90, 90); C2.GetComponent().material = mat2; } //POSITION Knob.name = "knob" + CODE[0]; float KW = DOIT.ConvertStringToNumber(CODE[3]); float KH = DOIT.ConvertStringToNumber(CODE[4]); float KD = DOIT.ConvertStringToNumber(CODE[5]); float ws=float.Parse(_OL.GetValue(CODE[0],"w")); float hs=float.Parse(_OL.GetValue(CODE[0],"h")); float ds=float.Parse(_OL.GetValue(CODE[0],"d")); Knob.transform.localScale=new(KH/hs,KW/ws,KD/ds); if (VH == "H") { if (p == "1" || p == "3") p = "2"; if (p == "7" || p == "9") p = "8"; } float pz = -depth * 0.5f; float ofy123 = 0f; float ofy456 = 0f; float ofy789 = 0f; float dx = w * 0.5f - 1.25f; float dy = h / 2 - 1.25f; float ofKW = KW * 0.5f; if (p == "1") { Knob.transform.localRotation = Quaternion.Euler(0, 0, 0); } if (p == "2") { Knob.transform.localRotation = Quaternion.Euler(0, 0, -90); } if (p == "3") { Knob.transform.localRotation = Quaternion.Euler(0, 0, 180); } if (p == "4") { Knob.transform.localRotation = Quaternion.Euler(0, 0, 0); } if (p == "5") { Knob.transform.localRotation = Quaternion.Euler(0, 0, 90); } if (p == "6") { Knob.transform.localRotation = Quaternion.Euler(0, 0, 180); } if (p == "7") { Knob.transform.localRotation = Quaternion.Euler(0, 0, 0); } if (p == "8") { Knob.transform.localRotation = Quaternion.Euler(0, 0, -90); } if (p == "9") { Knob.transform.localRotation = Quaternion.Euler(0, 0, 180); } if (cat != "dd") { knobset.Reposition(p, Knob, px, py, pz, dx, dy, ofy123, ofy456, ofy789, ofKW); } if (cat == "dd") { ofy123 = 0; ofy456 = h * 0.25f; ofy789 = h * 0.5f; knobset.Reposition(p, Knob, px, py, pz, dx, dy, ofy123, ofy456, ofy789, ofKW); GameObject Knob2 = Instantiate(Knob); ofy123 -= h * 0.5f; ofy456 = -h * 0.25f; ofy789 = -0; Knob2.transform.parent = DS.transform; knobset.Reposition(p, Knob2, px, py, pz, dx, dy, ofy123, ofy456, ofy789, ofKW); } string installation = GetInstallation(kcode); if (installation == "special") { //pz=-0.25f; pz = -0.25f; if (VH == "H") { dx = w / 2 + KW * 0.5f; dy = h / 2 - KH * 0.5f; ; knobset.Reposition(p, Knob, px, py, pz, dx, dy, ofy123, ofy456, ofy789, ofKW); } if (VH == "V") { dx = w / 2 + KH / 2; dy = h / 2 - KW * 0.5f - 0.5f; knobset.Reposition(p, Knob, px, py, pz, dx, dy, ofy123, ofy456, ofy789, ofKW); } } Knob.tag = "knob"; } Knob.transform.parent = DS.transform; } } private static bool IsModelAllowingKnobs(string modelDoor) { string[] modelException = new string[]{ "15", "16", "18", "19"}; foreach(string exception in modelException) { if(modelDoor == exception) { return false; } } return true; } public static string GetInstallation(string K){ return _OL.GetValue(K,"Installation"); } }//end