예제 #1
0
    private void OnTargetParamChanged(string paramName)
    {
        if (_atomJSON.val == "")
        {
            return;
        }
        if (_storableJSON.val == "")
        {
            return;
        }
        if (paramName == "")
        {
            return;
        }

        var atom = SuperController.singleton.GetAtomByUid(_atomJSON.val);

        if (atom == null)
        {
            throw new NullReferenceException($"Atom {_atomJSON.val} does not exist");
        }
        var storable = atom.GetStorableByID(_storableJSON.val);

        if (storable == null)
        {
            throw new NullReferenceException($"Storable {_storableJSON.val} of atom {_atomJSON.val} does not exist");
        }
        _targetParam = storable.GetFloatJSONParam(paramName);
        if (_targetParam == null)
        {
            throw new NullReferenceException($"Float JSON param {paramName} of storable {_storableJSON.val} of atom {_atomJSON.val} does not exist");
        }

        _valueJSON.constrained = false;
        _valueJSON.defaultVal  = _targetParam.defaultVal;
        _valueJSON.val         = _targetParam.val;
        _valueJSON.min         = _targetParam.min;
        _valueJSON.max         = _targetParam.max;
        _valueJSON.constrained = _targetParam.constrained;
        _ui.Configure(_labelJSON.val, _valueJSON.min, _valueJSON.max, _valueJSON.defaultVal, _valueJSON.constrained, "F2", true, !_valueJSON.constrained);
    }
예제 #2
0
    public void OnEnable()
    {
        if (_uiTransform != null || _atom == null)
        {
            return;
        }

        try
        {
            var canvas = _atom.GetComponentInChildren <Canvas>();
            if (canvas == null)
            {
                throw new NullReferenceException("Could not find a canvas to attach to");
            }

            _uiTransform = Instantiate(manager.configurableSliderPrefab.transform);
            if (_uiTransform == null)
            {
                throw new NullReferenceException("Could not instantiate configurableSliderPrefab");
            }
            _uiTransform.SetParent(canvas.transform, false);
            _uiTransform.gameObject.SetActive(true);

            _ui = _uiTransform.GetComponent <UIDynamicSlider>();
            if (_ui == null)
            {
                throw new NullReferenceException("Could not find a UIDynamicSlider component");
            }
            _ui.Configure(_labelJSON.val, _valueJSON.min, _valueJSON.max, _valueJSON.val, _valueJSON.constrained, "F2", true, !_valueJSON.constrained);
            _valueJSON.slider = _ui.slider;

            _uiTransform.Translate(Vector3.down * 0.3f, Space.Self);
            _uiTransform.Translate(Vector3.right * 0.35f, Space.Self);
        }
        catch (Exception exc)
        {
            SuperController.LogError($"{nameof(UISlider)}.{nameof(OnEnable)}: " + exc);
        }
    }