using UnityEngine; using UnityEngine.UI; using TMPro; public class ColorPicker : MonoBehaviour { public bool isDraggable = false; public TMP_InputField ImputHEX; public GameObject pickerObj; [Range(0, 255)] public int alphaTolerancy = 0; public Image PickerBG; public Slider Transparency; public Button btnColor; public TMP_InputField _Hexidecimal; void Start(){ //Get.o2("Panel_SCENE/PNL/PAINTpnl").set // Color actColor = GetComponent().sprite.texture.GetPixel ( // Mathf.RoundToInt ((pickerObj.transform.position.x - transform.position.x) // *(1/GetComponent().localScale.x)*(1/GetComponentInParent().scaleFactor)), // Mathf.RoundToInt ((pickerObj.transform.position.y - transform.position.y) // *(1/GetComponent().localScale.y) // *(1/GetComponentInParent().scaleFactor)) + GetComponent ().sprite.texture.height); // if (actColor.a >= ((255 - alphaTolerancy) / 255f)) { // _G.pickedColor = actColor; // } } public void OnEnter(){ isDraggable = true; _G.NAVIGATE = false; } public void OnExit(){ isDraggable = false; _G.NAVIGATE = true; } public void OnClick() { int pickerPosX=Mathf.RoundToInt ((Input.mousePosition.x - transform.position.x) * (1 / GetComponent ().localScale.x) * (1 / GetComponentInParent ().scaleFactor)); int pickerPosY=Mathf.RoundToInt ((Input.mousePosition.y - transform.position.y) * (1 / GetComponent ().localScale.y) * (1 / GetComponentInParent ().scaleFactor)) + GetComponent ().sprite.texture.height; if (isDraggable && pickerPosX<512*1 && pickerPosX>0 && pickerPosY<512*1f && pickerPosY>0)// { _G.NAVIGATE = false; Color actColor = GetComponent ().sprite.texture.GetPixel (pickerPosX,pickerPosY); if (actColor.a >= ((255 - alphaTolerancy) / 255f)) { _G.pickedColor = actColor; pickerObj.transform.position = Input.mousePosition; //string cols=ColorUtility.ToHtmlStringRGB(actColor); Transform colcat = Get.o1(transform.parent.parent.name).transform.GetChild(0); Transform img = colcat.Find("Image"); if (img != null) { img.GetComponent().color = actColor; } if (_Hexidecimal != null) { _Hexidecimal.text = ColorUtility.ToHtmlStringRGB(actColor); } if (PickerBG != null) { PickerBG.GetComponent().color=actColor; } string ColerPicker1 =transform.parent.name; string ColerPicker2 = transform.parent.parent.name; if(_G.PON=="TEXTUREPNL"){ SetOnTextureShow(actColor,ColerPicker2); } if(_G.PON=="UNIVERSALpnl" || _G.PON=="MOLDINGpnl" || _G.PON=="PANELpnl"){ SetOnCabTexture(actColor,ColerPicker2,"_c"+ColerPicker2.Split('_')[1]); } if(_G.PON=="CABDOORpnl"){ SetOnDoorShow(actColor,ColerPicker2,"_c"+ColerPicker2.Split('_')[1]); } if(ColerPicker1=="ColorPickerSoft"){SetOnSoft();} if(ColerPicker1.IndexOf("ColorPickerDIYTexture")!=-1){ Material M= Get.o1("DIY_CABTEXTURE/IMAGE/Image").GetComponent().material; M.SetColor("_c"+this.transform.parent.parent.name.Replace("ColorPickerDIYTexture",""), DOIT.CSc(ColorUtility.ToHtmlStringRGB(actColor), 255)); } if(_G.PON=="CREATORpnl") { Material M= Get.o2("3D Object Show/Texture","Center").GetComponent().material; string Name=transform.parent.transform.parent.name; M.SetColor(Name, DOIT.CSc(ColorUtility.ToHtmlStringRGB(actColor), 255)); StaticCoroutine.Start( LibraryCreator.RTImageCaroutine( Get.o2("CREATORpnl/SHOWSELECTION/IMAGE","RawImage") )); //Get.o2("CREATORpnl/SHOWSELECTION/IMAGE","RawImage").GetComponent().texture=LibraryCreator.RTImage(); } } } } public void SetOnSoft(){ string clos=ImputHEX.text; int value=Mathf.RoundToInt(Transparency.value); string TON=Get.ToggleOnInChild("SOFTCOLOR/Selections"); byte alpha=System.Convert.ToByte(value); if(TON=="BAR")_G.colorBar= DOIT.CSc(clos,alpha); if(TON=="BTN")_G.colorButton= DOIT.CSc(clos,alpha); if(TON=="ICON")_G.colorIcon= DOIT.CSc(clos,alpha); if(TON=="TEXT")_G.colorText = DOIT.CSc(clos,alpha); if(TON=="BACK")_G.colorBG= DOIT.CSc(clos,alpha); } public void SetOnTextureShow(Color actColor,string cat){ //print("---add color to texture pnl-----"); if(cat=="ColorPickerTexture"){_G.SC[3]=ColorUtility.ToHtmlStringRGB(actColor); } if(cat=="ColorPickerGrouth"){_G.SC[4]=ColorUtility.ToHtmlStringRGB(actColor); } SliderColor.SetOntarget(); } public void SetOnDoorShow(Color actColor,string cat, string c){ print("G.PON==="+_G.PON); //Color col=DOIT.CSc(ColorUtility.ToHtmlStringRGB(actColor),255); Material Mat=Get.o2(_G.PON+"/SHOWSELECTION/DOOR/","Imagedoor").GetComponent().GetMaterial(); Mat.SetColor(c,actColor); } public void SetOnCabTexture(Color actColor,string cat, string c){ Color col=DOIT.CSc(ColorUtility.ToHtmlStringRGB(actColor),255); Get.o2(_G.PON+"/SHOWSELECTION/IMAGE/","Image").GetComponent().material.SetColor(c,col); } }