public void AddNewBar(float min, float max, float value, bool showValue)
        {
            if (BarChartComponentGameObject.GetComponent <Slider>() == null ||
                BarChartComponentGameObject.GetComponent <ScaledComponent>() == null ||
                BarChartComponentGameObject.GetComponent <BarChartComponent>() == null)
            {
                return;
            }

            if (min > max)
            {
                return;
            }

            if (value < min || value > max)
            {
                return;
            }

            GameObject        bcc       = Instantiate(BarChartComponentGameObject, transform);
            Slider            bccSlider = bcc.GetComponent <Slider>();
            BarChartComponent bccScript = bcc.GetComponent <BarChartComponent>();

            bccSlider.minValue      = min;
            bccSlider.maxValue      = max;
            bccSlider.value         = value;
            bccScript.ShowValueText = showValue;

            UpdateVisuals();
        }
        public void UpdateVisuals()
        {
            int barChildren = 0;

            for (int i = 0; i < transform.childCount; i++)
            {
                if (transform.GetChild(i).tag != "Bar")
                {
                    continue;
                }

                if (transform.GetChild(i).GetComponent <Slider>() == null ||
                    transform.GetChild(i).GetComponent <ScaledComponent>() == null ||
                    transform.GetChild(i).GetComponent <BarChartComponent>() == null)
                {
                    Debug.LogWarningFormat(
                        transform,
                        "Manager contains child not fit for purpose.",
                        transform.GetChild(i));
                    return;
                }

                // locals
                Slider            childSlider          = transform.GetChild(i).GetComponent <Slider>();
                ScaledComponent   childScaledComponent = transform.GetChild(i).GetComponent <ScaledComponent>();
                BarChartComponent childBcc             = transform.GetChild(i).GetComponent <BarChartComponent>();

                // Slider
                childSlider.direction    = barDirection;
                childSlider.wholeNumbers = WholeNumbers;

                // BCC
                childBcc.ValueText.text = childSlider.value.ToString(CultureInfo.CurrentCulture);

                // Scaled comp
                if (barChildren == 0)
                {
                    childScaledComponent.ComponentPosition.Left = leftPaddingPercentage;
                }
                else
                {
                    childScaledComponent.ComponentPosition.Left = (spacePercentage * barChildren) + leftPaddingPercentage;
                }

                childScaledComponent.Container             = GetComponent <RectTransform>();
                childScaledComponent.ComponentScale.Height = heightPercentage;
                childScaledComponent.ComponentScale.Width  = widthPercentage;

                // Colour
                childBcc.Colour = UpdateColour(barChildren, transform.childCount - 1);
                ++barChildren;
            }
        }
        public override void OnInspectorGUI()
        {
            BarChartManager bcmScript = (BarChartManager)target;

            EditorGUILayout.LabelField(
                "Bar Chart Manager",
                new GUIStyle {
                fontSize = 18, fontStyle = FontStyle.Bold, alignment = TextAnchor.MiddleCenter
            });
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            DrawDefaultInspector();

            if (GUILayout.Button("Update Styles"))
            {
                bcmScript.UpdateVisuals();
            }

            randomAmount = EditorGUILayout.IntField(randomAmount);
            if (GUILayout.Button("Random"))
            {
                bcmScript.RandomPopulate(randomAmount);
            }

            EditorGUILayout.Space();
            EditorGUILayout.Separator();
            EditorGUILayout.LabelField(
                "Bar Chart Editor",
                new GUIStyle {
                fontSize = 18, fontStyle = FontStyle.Bold, alignment = TextAnchor.MiddleCenter
            });
            EditorGUILayout.LabelField("New", new GUIStyle {
                fontSize = 12, fontStyle = FontStyle.Bold
            });

            value     = EditorGUILayout.IntField("Value", value);
            min       = EditorGUILayout.IntField("Min", min);
            max       = EditorGUILayout.IntField("Max", max);
            showValue = EditorGUILayout.Toggle("Show value text", showValue);

            if (GUILayout.Button("Create"))
            {
                bcmScript.AddNewBar(min, max, value, showValue);
            }

            EditorGUILayout.LabelField("Edit", new GUIStyle {
                fontSize = 12, fontStyle = FontStyle.Bold
            });
            if (GUILayout.Button("Purge"))
            {
                bcmScript.Purge();
            }
            edit = EditorGUILayout.Foldout(edit, "Show Children");
            if (edit)
            {
                for (int i = 0; i < bcmScript.transform.childCount; i++)
                {
                    Transform child = bcmScript.transform.GetChild(i);
                    if (child.tag != "Bar")
                    {
                        continue;
                    }

                    EditorGUILayout.LabelField(
                        string.Format("Bar {0}", i),
                        new GUIStyle {
                        fontSize = 10, fontStyle = FontStyle.Bold
                    });

                    Slider            childSlider = child.GetComponent <Slider>();
                    BarChartComponent childScript = child.GetComponent <BarChartComponent>();

                    childSlider.value = EditorGUILayout.Slider(
                        "Value",
                        childSlider.value,
                        childSlider.minValue,
                        childSlider.maxValue);
                    childScript.ShowValueText = EditorGUILayout.Toggle("Show value text", childScript.ShowValueText);
                    childScript.Colour        = EditorGUILayout.ColorField("Colour", childScript.Colour);

                    if (GUILayout.Button("Delete"))
                    {
                        DestroyImmediate(child.gameObject);
                    }

                    EditorGUILayout.Separator();
                    EditorGUILayout.Space();
                }
            }
        }