private void Control_ValueChanging(object sender, System.EventArgs e)
        {
            SlideCtrl    s = sender as SlideCtrl;
            UIFloatParam p = s.Tag as UIFloatParam;

            p.Value = s.GetPos();
        }
        public static UIFloatParam FromString(string _inputs, string _value)
        {
            //ex. "Factor", 0.0, 10.0
            var inputs = _inputs.Split(',');

            if (inputs.Length != 3)
            {
                return(null);
            }

            string name = inputs[0].Replace("\"", "");

            float min, max;

            if (!float.TryParse(inputs[1], NumberStyles.Float, CultureInfo.InvariantCulture, out min))
            {
                return(null);
            }

            if (!float.TryParse(inputs[2], NumberStyles.Float, CultureInfo.InvariantCulture, out max))
            {
                return(null);
            }

            //ex. 0.0
            float value;

            if (!float.TryParse(_value, NumberStyles.Float, CultureInfo.InvariantCulture, out value))
            {
                return(null);
            }

            if (min < max)
            {
                var param = new UIFloatParam(min, max);
                param.Name  = name;
                param.Value = value;
                return(param);
            }

            return(null);
        }
Beispiel #3
0
        /// <summary>
        /// 更新参数列表UI
        /// </summary>
        /// <param name="strShaderSource"></param>
        private void CreateUIParameters(string strShaderSource)
        {
            Program.s_GameInstance.ShaderParameters.Clear();

            UIBaseParam.ENUM_UIBaseParamType paramType = UIBaseParam.ENUM_UIBaseParamType.eUnknow;
            int idxStart  = 0;
            int idxSource = 0;

            // 第一轮查找Float
            while (idxSource != -1)
            {
                paramType = UIBaseParam.ENUM_UIBaseParamType.eUnknow;

                //Get FloatParam
                idxStart = strShaderSource.IndexOf("FloatParam", idxSource);
                if (idxStart != -1)
                {
                    paramType = UIBaseParam.ENUM_UIBaseParamType.eFloat;
                }

                if (paramType == UIBaseParam.ENUM_UIBaseParamType.eUnknow)
                {
                    break;
                }

                // 找到行尾
                int idxEnd = strShaderSource.IndexOf("\n", idxStart);
                if (idxEnd == -1)
                {
                    break;
                }

                idxSource = idxEnd;

                // 获取本行
                var line = strShaderSource.Substring(idxStart, idxEnd - idxStart);

                //Inputs Part
                idxStart = line.IndexOf("(");
                if (idxStart == -1)
                {
                    break;
                }

                idxEnd = line.IndexOf(")");
                if (idxEnd == -1)
                {
                    break;
                }

                var inputs = line.Substring(idxStart + 1, idxEnd - idxStart - 1);
                inputs = inputs.Replace(" ", "");

                //Egal Part
                idxStart = line.IndexOf("=");
                if (idxStart == -1)
                {
                    break;
                }

                //Value Part
                var value = line.Substring(idxStart + 1);
                value = value.Replace(" ", "");

                //Add Param
                if (paramType == UIBaseParam.ENUM_UIBaseParamType.eFloat)
                {
                    UIFloatParam p = UIFloatParam.FromString(inputs, value);
                    if (p != null)
                    {
                        Program.s_GameInstance.ShaderParameters.Add(p);
                    }
                }
            }
            ;

            // 第二轮,找Texture2D
            paramType = UIBaseParam.ENUM_UIBaseParamType.eUnknow;
            idxStart  = 0;
            idxSource = 0;

            while (idxSource != -1)
            {
                paramType = UIBaseParam.ENUM_UIBaseParamType.eUnknow;

                idxStart = strShaderSource.IndexOf("Texture2DParam", idxSource);
                if (idxStart != -1)
                {
                    paramType = UIBaseParam.ENUM_UIBaseParamType.Texture2D;
                }

                if (paramType == UIBaseParam.ENUM_UIBaseParamType.eUnknow)
                {
                    break;
                }

                // 找到行尾
                int idxEnd = strShaderSource.IndexOf("\n", idxStart);
                if (idxEnd == -1)
                {
                    break;
                }

                //Update for next line
                idxSource = idxEnd;

                // 获取本行
                var line = strShaderSource.Substring(idxStart, idxEnd - idxStart);

                //Inputs Part
                idxStart = line.IndexOf("(");
                if (idxStart == -1)
                {
                    break;
                }

                idxEnd = line.IndexOf(")");
                if (idxEnd == -1)
                {
                    break;
                }

                var inputs = line.Substring(idxStart + 1, idxEnd - idxStart - 1);
                inputs = inputs.Replace(" ", "");

                //Egal Part
                idxStart = line.IndexOf("=");
                if (idxStart == -1)
                {
                    break;
                }

                //Value Part
                var value = line.Substring(idxStart + 1);
                value = value.Replace(" ", "");

                //Add Param
                if (paramType == UIBaseParam.ENUM_UIBaseParamType.Texture2D)
                {
                    UITexture2DParam p = UITexture2DParam.FromString(inputs, value);
                    if (p != null)
                    {
                        Program.s_GameInstance.ShaderParameters.Add(p);
                    }
                }
            }
            ;

            // 更新UI显示
            ShaderParametersUserControl.DisplayParameters(Program.s_GameInstance.ShaderParameters);
        }