예제 #1
0
    private void CreateGauge()
    {
        Vector2 gaugeSize = Vector2.zero;

        if (gaugeModel != null)
        {
            gaugeObject    = Instantiate(gaugeModel, Vector3.zero, Quaternion.identity);
            gaugeComponent = gaugeObject.GetComponent <WorldSpaceGauge>();
            if (gaugeComponent == null)
            {
                Destroy(gaugeObject);
                gaugeObject = null;
            }
            else
            {
                gaugeComponent.Build(maxValue, 0f);
                gaugeComponent.SetCurrentValue(currentValue);
                gaugeSize        = gaugeComponent.backgroundSize;
                gaugeArea.width  = gaugeSize.x;
                gaugeArea.height = gaugeSize.y;
                gaugeSize        = gaugeComponent.foregroundSize;
                gaugeArea.width  = (gaugeArea.width > gaugeSize.x) ? gaugeArea.width : gaugeSize.x;
                gaugeArea.height = (gaugeArea.height > gaugeSize.y) ? gaugeArea.height : gaugeSize.y;
                gaugeObject.transform.SetParent(transform, false);
            }
        }
    }