// 編集前と後でオブジェクトを分ける場合用(未使用)
        public ACCMaterial(ACCMaterial src) {
            this.original = src;
            this.renderer = src.renderer;
            this.material = src.material;
            this.name = src.name;
            //this.shader = src.shader;
            //this.type1 = src.type1;
            this.type = src.type;

            this.renderQueue = src.renderQueue;
            
            // TODO 配列の中身はディープコピーとする 
            this.editColors = src.editColors;
            this.editVals = src.editVals;
            
        }
        private bool drawValueSlider(string label, EditValue edit, float sliderMin, float sliderMax)
        {
            bool changed     = false;
            bool fontChanged = false;

            GUILayout.BeginHorizontal(optItemHeight);
            try {
                drawLabel(ref label);

                if (!edit.isSync)
                {
                    SetTextColor(uiParams.textStyleSC, ref txtColorRed);
                    fontChanged = true;
                }

                var editedVal = GUILayout.TextField(edit.editVal, uiParams.textStyleSC, optInputWidth);
                if (edit.editVal != editedVal)   // 直接書き換えられたケース
                {
                    edit.Set(editedVal);
                    changed |= edit.isSync; // テキスト値書き換え、かつ値が同期⇒変更とみなす
                }

                float sliderVal = edit.val;
                if (drawSlider(ref sliderVal, sliderMin, sliderMax))
                {
                    edit.Set(sliderVal);
                    changed = true;
                }
                GUILayout.Space(buttonMargin);
            } finally {
                GUILayout.EndHorizontal();
                if (fontChanged)
                {
                    SetTextColor(uiParams.textStyleSC, ref txtColor);
                }
            }
            return(changed);
        }
        private bool drawValueSlider(string label, EditValue edit, float sliderMin, float sliderMax) {
            bool changed = false;
            bool fontChanged = false;
            GUILayout.BeginHorizontal(optItemHeight);
            try {
                drawLabel(ref label);

                if (!edit.isSync) {
                    SetTextColor(uiParams.textStyleSC, ref txtColorRed);
                    fontChanged = true;
                }

                var editedVal = GUILayout.TextField(edit.editVal, uiParams.textStyleSC, optInputWidth);
                if (edit.editVal != editedVal) { // 直接書き換えられたケース
                    edit.Set(editedVal);
                    changed |= edit.isSync; // テキスト値書き換え、かつ値が同期⇒変更とみなす
                }

                float sliderVal = edit.val;
                if (drawSlider(ref sliderVal, sliderMin, sliderMax)) {
                    edit.Set(sliderVal);
                    changed = true;
                }
                GUILayout.Space(buttonMargin);

            } finally {
                GUILayout.EndHorizontal();
                if (fontChanged) {
                    SetTextColor(uiParams.textStyleSC, ref txtColor);
                }
            }
            return changed;
        }
        private void SetupFloatSlider(string label, EditValue edit, float sliderMin, float sliderMax,
                                      Action<float> func, bool[] mulVals, params float[] vals) {
            GUILayout.BeginHorizontal();
            GUILayout.Label(label, uiParams.lStyle, optItemHeight);
            GUILayout.Space(uiParams.marginL);

            bool changed = false;
            for (int i=0; i< vals.Length; i++) {
                string blabel = vals[i].ToString();
                GUILayoutOption opt;
                if (blabel.Length <= 1) opt = bWidthOpt;
                else if (blabel.Length <= 3) opt = bWidthWOpt;
                else opt = GUILayout.Width(baseWidth*0.5f*(blabel.Length+1));
                if (GUILayout.Button(blabel, bStyleSS, opt)) {
                    edit.Set( vals[i] );
                    changed = true;
                }
            }
            if (mulVals != null && mulVals.Length >= 3) {
                if (mulVals[0]) {
                    if (GUILayout.Button("<", bStyleSS, bWidthOpt)) {
                        edit.SetWithCheck(edit.val * 0.9f);
                        changed = true;
                    }
                }
                if (mulVals[1]) {
                    if (GUILayout.Button(">", bStyleSS, bWidthOpt)) {
                        edit.SetWithCheck(edit.val * 1.1f);
                        changed = true;
                    }
                }
                if (mulVals[2]) {
                    if (GUILayout.Button("x-1", bStyleSS, bWidthWOpt)) {
                        edit.Set(edit.val * -1f);
                        changed = true;
                    }
                }
            }
            GUILayout.EndHorizontal();

            if (changed || drawValueSlider(null, edit, sliderMin, sliderMax)) {
                func(edit.val);
            }
        }
 private void SetupFloatSlider(string label, EditValue edit, float sliderMin, float sliderMax,
                               Action<float> func, params float[] vals) {
     SetupFloatSlider(label, edit, sliderMin, sliderMax, func, null, vals);
 }
        private void InitType() {
            // Color生成
            var colProps = type.colProps;
            this.editColors = new EditColor[colProps.Length];
            for (int i=0; i<colProps.Length; i++) {
                var colProp = colProps[i];
                var ec = new EditColor(null, colProp.colorType);
                if (material != null) {
                    ec.Set( material.GetColor(colProps[i].propId) );
                } else {
                    ec.Set( colProps[i].defaultVal );
                }
                editColors[i] = ec;
            }

            // float生成
            var props = type.fProps;
            this.editVals = new EditValue[props.Length];
            for (int i=0; i<props.Length; i++) {
                float val = props[i].defaultVal;
                if (material != null) {
                    val = material.GetFloat(props[i].propId);
                }
                editVals[i] = new EditValue(val, props[i].range);
            }
        }
        public void Update(ShaderType sdrType) {
            if (this.type == sdrType) return;
            // TODO 変更前のマテリアルから設定値をロード


            // 同一長の場合でも更新(Alphaの有無が異なるケースがある)            
            var colProps = sdrType.colProps;
            var createdColors = new EditColor[colProps.Length];
            for (int i=0; i<colProps.Length; i++) {
                var colProp = colProps[i];
                if (i < this.editColors.Length && editColors[i].val.HasValue) {
                    // カラータイプが異なる場合は、インスタンスを作り直して色をコピー
                    if (editColors[i].type == colProp.colorType) {
                        createdColors[i] = editColors[i];
                    } else {
                        createdColors[i] = new EditColor(editColors[i].val, colProp.colorType); 
                    }
                } else {
                    var ec = new EditColor(null, colProp.colorType);
                    if (material != null) {
                        ec.Set( material.GetColor(colProps[i].propId) );
                    } else {
                        ec.Set( (original != null)? original.GetColor(i): colProps[i].defaultVal );
                    }
                    createdColors[i] = ec;
                }
            }
            editColors = createdColors;
            
            
            var props = sdrType.fProps;
            var createdVals = new EditValue[props.Length];
            for (int i=0; i<props.Length; i++) {
                float val;
                if (material != null) {
                    val = material.GetFloat(props[i].propId);
                } else {
                    val = props[i].defaultVal;//(original != null)? original.GetColor(i): Color.white;
                }
                createdVals[i] = new EditValue(val, props[i].range);
            }
            this.editVals = createdVals;

            // テクスチャ情報の初期化
            foreach (var texProp in sdrType.texProps) {
                // セットしてないテクスチャは空テクスチャをセット
                if (!material.HasProperty(texProp.keyName)) {
                    material.SetTexture(texProp.propId, new Texture());
                }
            }

            type = sdrType;
        }
        private void SetupFloatSlider(string label, EditValue edit, float sliderMin, float sliderMax,
                                      Action <float> func, PresetOperation[] presetOprs, float[] vals1, float[] vals2)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(label, uiParams.lStyle, optItemHeight);
            GUILayout.Space(uiParams.marginL);

            bool           changed = false;
            Action <float> preset  = (val) => {
                string          blabel = val.ToString();
                GUILayoutOption opt;
                if (blabel.Length <= 1)
                {
                    opt = bWidthOpt;
                }
                else if (blabel.Length <= 3)
                {
                    opt = bWidthWOpt;
                }
                else
                {
                    opt = GUILayout.Width(baseWidth * 0.5f * (blabel.Length + 1));
                }
                if (GUILayout.Button(blabel, bStyleSS, opt))
                {
                    edit.Set(val);
                    changed = true;
                }
            };

            if (vals1 != null)
            {
                foreach (float val in vals1)
                {
                    preset(val);
                }
            }
            if (vals2 != null)
            {
                foreach (float val in vals2)
                {
                    preset(val);
                }
            }

            if (presetOprs != null)
            {
                foreach (var pset in presetOprs)
                {
                    var widthOpt = (pset.label.Length == 1) ? bWidthOpt : bWidthWOpt;
                    if (GUILayout.Button(pset.label, bStyleSS, widthOpt))
                    {
                        edit.SetWithCheck(pset.func(edit.val));
                        changed = true;
                    }
                }
            }
            GUILayout.EndHorizontal();

            if (changed || drawValueSlider(null, edit, sliderMin, sliderMax))
            {
                func(edit.val);
            }
        }
 private void SetupFloatSlider(string label, EditValue edit, float sliderMin, float sliderMax,
                               Action <float> func, float[] vals1, float[] vals2)
 {
     SetupFloatSlider(label, edit, sliderMin, sliderMax, func, null, vals1, vals2);
 }