public static int ExcuteLogicOp(UnitMaterialEditor gui, MaterialProperty prop, MaterialProperty[] props, JSONObject args) { var _op = String.Empty; args.GetField(out _op, UnitMaterialEditor.Cfg.ArgsKey_OP, "=="); if (prop == null) { var ret = -1; String _id0, _id1; if (args.GetField(out _id0, UnitMaterialEditor.Cfg.ArgsKey_OP_Arg0, String.Empty)) { String ret0; var _0 = EvalLogicOpArg(gui, _id0, props, out ret0); var argIndex = 1; while (args.GetField(out _id1, UnitMaterialEditor.Cfg.ArgsKey_OP_ArgPrefix + argIndex.ToString(), String.Empty)) { String ret1; var _1 = EvalLogicOpArg(gui, _id1, props, out ret1); if (_0 != -1 && _1 != -1) { ret = Compare(_op, _0, _1) ? 1 : 0; } else { if (ret0 != null && ret1 != null) { ret = Compare(_op, ret0, ret1) ? 1 : 0; } } if (_op != "&&" && _op != "||") { break; } else { if (_op == "&&") { if (ret != 1) { break; } } else if (_op == "||") { if (ret == 1) { break; } } } ++argIndex; _0 = _1; ret0 = ret1; } } return(ret); } switch (prop.type) { case MaterialProperty.PropType.Texture: { var lh = prop.textureValue != null ? 1 : 0; int rh; if (!ShaderGUIHelper.ParseValue(gui, args, UnitMaterialEditor.Cfg.ArgsKey_OP_Ref, out rh)) { rh = 1; } return(ShaderGUIHelper.Compare(_op, lh, rh) ? 1 : 0); } case MaterialProperty.PropType.Vector: { Vector4 rh; int mask; if (ShaderGUIHelper.ParseValue(gui, args, UnitMaterialEditor.Cfg.ArgsKey_OP_Ref, out rh, out mask)) { return(ShaderGUIHelper.Compare(_op, prop.vectorValue, rh, mask) ? 1 : 0); } } break; case MaterialProperty.PropType.Color: { Vector4 rh; int mask; if (ShaderGUIHelper.ParseValue(gui, args, UnitMaterialEditor.Cfg.ArgsKey_OP_Ref, out rh, out mask)) { return(ShaderGUIHelper.Compare(_op, prop.colorValue, rh, mask) ? 1 : 0); } } break; case MaterialProperty.PropType.Range: case MaterialProperty.PropType.Float: { float rh = 0; ShaderGUIHelper.ParseValue(gui, args, UnitMaterialEditor.Cfg.ArgsKey_OP_Ref, out rh); return(ShaderGUIHelper.Compare(_op, prop.floatValue, rh) ? 1 : 0); } } return(-1); }
public static int EvalLogicOpArg(UnitMaterialEditor gui, String express, MaterialProperty[] props, out String returnValue) { returnValue = null; if (!String.IsNullOrEmpty(express)) { var m = UnitMaterialEditor.Reg_LogicRef.Match(express); if (m.Success && m.Groups.Count > 2) { var rev = m.Groups[1].ToString().Trim() == "!"; var id = m.Groups[2].ToString().Trim(); if (!String.IsNullOrEmpty(id)) { var ui = gui.FindPropEditor <UnitMaterialEditor>(id); if (ui != null) { var b = ui.GetLogicOpResult(out returnValue, props); if (rev) { b = !b; } return(b ? 1 : 0); } else { var result = false; var material = gui.materialEditor.target as Material; if (material != null && material.shader != null) { var shader = material.shader; for (int i = 0; i < ShaderUtil.GetPropertyCount(shader); ++i) { var name = ShaderUtil.GetPropertyName(shader, i); if (name == id) { switch (ShaderUtil.GetPropertyType(shader, i)) { case ShaderUtil.ShaderPropertyType.Color: result = ShaderGUIHelper.Compare(">", material.GetColor(name), new Color(0, 0, 0, 0)); break; case ShaderUtil.ShaderPropertyType.Float: case ShaderUtil.ShaderPropertyType.Range: result = material.GetFloat(name) > 0; break; case ShaderUtil.ShaderPropertyType.TexEnv: result = material.GetTexture(name) != null; break; case ShaderUtil.ShaderPropertyType.Vector: result = ShaderGUIHelper.Compare(">", material.GetVector(name), new Vector4(0, 0, 0, 0)); break; } if (rev) { result = !result; } return(result ? 1 : 0); } } } } return(0); } } else { returnValue = express; } } return(-1); }
public static int ExcuteLogicOp(UnitMaterialEditor gui, MaterialProperty prop, JSONObject args) { var _op = String.Empty; args.GetField(out _op, "op", "=="); if (prop == null) { String _id0, _id1; if (args.GetField(out _id0, "arg0", String.Empty) && args.GetField(out _id1, "arg1", String.Empty)) { String ret0; String ret1; var _0 = EvalLogicOpArg(gui, _id0, out ret0); var _1 = EvalLogicOpArg(gui, _id1, out ret1); if (_0 != -1 && _1 != -1) { return(Compare(_op, _0, _1) ? 1 : 0); } else { if (ret0 != null && ret1 != null) { return(Compare(_op, ret0, ret1) ? 1 : 0); } } } return(-1); } switch (prop.type) { case MaterialProperty.PropType.Texture: { var lh = prop.textureValue != null ? 1 : 0; int rh; if (!ShaderGUIHelper.ParseValue(gui, args, "ref", out rh)) { rh = 1; } return(ShaderGUIHelper.Compare(_op, lh, rh) ? 1 : 0); } case MaterialProperty.PropType.Vector: { Vector4 rh; int comp; if (ShaderGUIHelper.ParseValue(gui, args, "ref", out rh, out comp)) { return(ShaderGUIHelper.Compare(_op, prop.vectorValue, rh, comp) ? 1 : 0); } } break; case MaterialProperty.PropType.Color: { Vector4 rh; int comp; if (ShaderGUIHelper.ParseValue(gui, args, "ref", out rh, out comp)) { var c = prop.colorValue; return(ShaderGUIHelper.Compare(_op, new Vector4(c.r, c.g, c.b, c.r), rh, comp) ? 1 : 0); } } break; case MaterialProperty.PropType.Range: case MaterialProperty.PropType.Float: { float rh = 0; ShaderGUIHelper.ParseValue(gui, args, "ref", out rh); return(ShaderGUIHelper.Compare(_op, prop.floatValue, rh) ? 1 : 0); } } return(-1); }