using UnityEngine; using System.Collections; using UnityEngine.UI; public class UI_Control : MonoBehaviour { public Slider Col1_Sld; public Slider Col2_Sld; public RectTransform pan1; public RectTransform pan2; public RectTransform pan2Child; public RectTransform pan3; public Text val_1_Txt; public Text val_2_Txt; public Text val_3_Txt; public void onColSld() { float valSld1 = Col1_Sld.value; float valSld2 = Col2_Sld.value; val_1_Txt.text = valSld1.ToString("F2"); float remainder = (1 - valSld1); float val2 = remainder * valSld2; val_2_Txt.text = val2.ToString("F2"); float val3 = remainder * (1 - valSld2); val_3_Txt.text = val3.ToString("F2"); RectTransform Sld2rct = Col2_Sld.GetComponent<RectTransform>(); float width = baseSld2_rct.sizeDelta.x; float dx = valSld1 * width; Sld2rct.sizeDelta = new Vector2(baseSld2_rct.sizeDelta.x - dx, baseSld2_rct.sizeDelta.y); width = basePan1_rct.sizeDelta.x; dx = valSld1 * width; pan1.sizeDelta = new Vector2(dx, basePan1_rct.sizeDelta.y); width = basePan3_rct.sizeDelta.x; float width2 = Sld2rct.sizeDelta.x; float dx1 = valSld1 * width + valSld2 * width2; pan3.sizeDelta = new Vector2(basePan3_rct.sizeDelta.x - dx1, basePan3_rct.sizeDelta.y); dx = valSld1; pan2.pivot = new Vector2(basePan2Pivot.x - dx, basePan2Pivot.y); width = basePan2Child_rct.sizeDelta.x; dx = (valSld1) * width + (1-valSld2) * width2; pan2Child.sizeDelta = new Vector2(basePan2Child_rct.sizeDelta.x - dx, basePan2Child_rct.sizeDelta.y); //pan2.sizeDelta = new Vector2(basePan2_rct.sizeDelta.x - dx1, basePan2_rct.sizeDelta.y); } RectTransform baseSld1_rct; RectTransform baseSld2_rct; RectTransform basePan1_rct; RectTransform basePan2_rct; RectTransform basePan3_rct; RectTransform basePan2Child_rct; Vector2 basePan2Pivot; void Start () { baseSld1_rct = Col1_Sld.GetComponent<RectTransform>(); //does not change; baseSld2_rct = Instantiate(Col2_Sld.GetComponent<RectTransform>()); basePan1_rct = Instantiate(pan1); basePan2_rct = Instantiate(pan2); basePan3_rct = Instantiate(pan3); basePan2Pivot = pan2.pivot; basePan2Child_rct = Instantiate(pan2Child); } }