示例#1
0
        /// <summary>
        /// 简单测试:通过设置数据实体的值来更新界面显示
        /// </summary>
        public override void Update()
        {
            base.Update();
            if (Input.GetKeyDown(KeyCode.P))
            {
                ConfigEntity _entity = (ConfigEntity)this.DataEntity;
                _entity.BackgroundVolume = 0.2f;
                _entity.ForegroundVolume = 0.4f;
                _entity.BackgroundVolume = 0.6f;
                _entity.ForegroundVolume = 0.8f;
            }

            if (Input.GetKeyDown(KeyCode.Q))
            {
                ConfigEntity _entity = (ConfigEntity)this.DataEntity;
                Debug.Log(_entity.BackgroundVolume);
                Debug.Log(_entity.ForegroundVolume);
            }
        }
示例#2
0
        /// <summary>
        /// 显示属性变化事件,测试属性绑定是否正确
        /// </summary>
        /// <param name="evt"></param>
        public override void ProcessLogic(PropertyMessage evt)
        {
            //处理背景音乐调整
            if (evt.PropertyName.Equals("BackgroundVolume"))
            {
                float newValue = (float)evt.NewValue;
                newValue = newValue * 100;
                string strNewValue = String.Format("{0:F}", newValue);

                ConfigViewModel viewModel = GetComponent <ConfigViewModel>();
                if (viewModel != null)
                {
                    ConfigEntity entity = utilsEntity.GetEntity <ConfigEntity>(gameObject);
                    entity.BackgroundText = "当前音量:[" + strNewValue + "%]";
                }
                return;
            }

            //处理前景音乐调整
            if (evt.PropertyName.Equals("ForegroundVolume"))
            {
                float newValue = (float)evt.NewValue;
                newValue = newValue * 100;
                string strNewValue = String.Format("{0:F}", newValue);

                ConfigViewModel viewModel = GetComponent <ConfigViewModel>();
                if (viewModel != null)
                {
                    ConfigEntity entity = (ConfigEntity)viewModel.DataEntity;
                    entity.ForegroundText = "当前音量:[" + strNewValue + "%]";
                }
                return;
            }

            //处理确定操作
            if (evt.PropertyName.Equals("OkClicked"))
            {
                //忽略初始化事件
                if (evt.NewValue == evt.OldValue)
                {
                    return;
                }

                int clicked = (int)evt.NewValue;
                if (clicked == -1)
                {
                    return;
                }

                ConfigViewModel viewModel = GetComponent <ConfigViewModel>();
                if (viewModel != null)
                {
                    ConfigEntity entity = (ConfigEntity)viewModel.DataEntity;
                    entity.OpenClose = false;
                }
                return;
            }

            //处理对话框打开或关闭操作
            if (evt.PropertyName.Equals("OpenClose"))
            {
                bool openClose = (bool)evt.NewValue;
                if (!openClose)
                {
                    gameObject.transform.localScale = Vector3.zero;
                }
                else
                {
                    gameObject.transform.localScale = Vector3.one;
                }
                return;
            }

            //处理开启前景音乐
            if (evt.PropertyName.Equals("EnableFgMusic"))
            {
                bool   enable = (bool)evt.NewValue;
                Slider slier  = GameObject.Find("Canvas/ImageConfigPanel/SliderFgVolume").GetComponent <Slider>();
                slier.interactable = enable;
                return;
            }

            //处理开启背景音乐
            if (evt.PropertyName.Equals("EnableBgMusic"))
            {
                bool   enable = (bool)evt.NewValue;
                Slider slier  = GameObject.Find("Canvas/ImageConfigPanel/SliderBgVolume").GetComponent <Slider>();
                slier.interactable = enable;
                return;
            }
        }