Ejemplo n.º 1
0
        public virtual void DrawExpressionName(BatchExpression be)
        {
            if (m_ExpressionNames != null && m_ExpressionNames.Length > 0)
            {
                int index = EditorGUILayout.Popup(be.index, m_ExpressionNames);

                if (index == m_ExpressionNames.Length - 1)
                {
                    be.index = index;
                    //last one is custom define
                    string name = EditorGUILayout.TextField(be.name);
                    if (be.name != name)
                    {
                        ChangeExpression(be, index, name);
                    }
                }
                else if (be.index != index)
                {
                    ChangeExpression(be, index, "");
                }
            }
            else
            {
                string name = EditorGUILayout.TextField(be.name);
                if (be.name != name)
                {
                    ChangeExpression(be, 1, name);
                }
            }
        }
Ejemplo n.º 2
0
        protected void AddExpressionToGroup(BatchExpressionGroup group)
        {
            BatchExpression expr = new BatchExpression();

            ChangeExpression(expr, group.expressions.Count, "");
            expr.parent = group;
            group.expressions.Add(expr);
        }
Ejemplo n.º 3
0
        public void RemoveExpression(BatchExpression be)
        {
            if (be.parent != null)
            {
                be.parent.expressions.Remove(be);
            }

            m_ValueFields.Remove(be);
        }
Ejemplo n.º 4
0
 protected void DrawExpressionValue(BatchExpression be)
 {
     if (m_ValueFields.ContainsKey(be))
     {
         BaseField baseField = m_ValueFields[be];
         baseField.Draw();
         if (baseField.value != be.value)
         {
             be.value = baseField.value;
         }
     }
 }
Ejemplo n.º 5
0
        int ModifyComponents(List <FindResult> results, ClassInfo classInfo, List <BatchExpression> expressions)
        {
            int n = 0;

            if (results != null && results.Count > 0 && expressions != null && expressions.Count > 0)
            {
                for (int i = 0; i < results.Count; ++i)
                {
                    FindResult result = results[i];

                    for (int j = 0; j < expressions.Count; ++j)
                    {
                        BatchExpression expression = expressions[j];

                        if (expression.value != null)
                        {
                            MemberInfo member = ReflectionUtils.GetMember(classInfo.type, expression.name);

                            if (member != null)
                            {
                                object expressionValue = expression.value;
                                object memberValue     = ReflectionUtils.GetValue(member, result.obj);
                                Type   memberType      = ReflectionUtils.GetFieldOrPropertyType(member);

                                if (expressionValue.GetType() != memberType)
                                {
                                    expressionValue = Convert.ChangeType(expressionValue, memberType);
                                }

                                if (m_ExpressionOperators.ContainsKey(expression.op))
                                {
                                    expressionValue = m_ExpressionOperators[expression.op].Execute(memberValue, expressionValue);
                                }

                                ReflectionUtils.SetValue(member, result.obj, expressionValue);
                                ++n;
                            }
                        }
                    }
                }
            }

            if (n > 0)
            {
                AssetDatabase.SaveAssets();
            }

            return(n);
        }
Ejemplo n.º 6
0
        public virtual void DrawExpression(BatchExpression be)
        {
            GUILayout.BeginHorizontal();

            DrawExpressionName(be);

            DrawExpresstionOp(be);

            DrawExpressionValue(be);

            if (GUILayout.Button("-"))
            {
                RemoveExpression(be);
            }

            GUILayout.EndHorizontal();
        }
Ejemplo n.º 7
0
        bool CheckConditions(ClassInfo classInfo, object obj, List <BatchExpression> conditions, bool isAny)
        {
            bool pass = true;

            if (conditions != null && conditions.Count > 0)
            {
                pass = !isAny;

                for (int k = 0; k < conditions.Count; ++k)
                {
                    BatchExpression condition = conditions[k];

                    MemberInfo member = ReflectionUtils.GetMember(classInfo.type, condition.name);

                    if (member != null)
                    {
                        object fieldValue     = ReflectionUtils.GetValue(member, obj);
                        object conditionValue = condition.value;

                        if (m_ConditionOperators.ContainsKey(condition.op))
                        {
                            if (m_ConditionOperators[condition.op].Execute(fieldValue, conditionValue))
                            {
                                if (isAny)
                                {
                                    pass = true;
                                    break;
                                }
                            }
                            else
                            {
                                if (!isAny)
                                {
                                    pass = false;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            return(pass);
        }
Ejemplo n.º 8
0
        void FixExpressionsValue(ClassInfo classInfo, List <BatchExpression> expressions)
        {
            for (int j = 0; j < expressions.Count; ++j)
            {
                BatchExpression expression = expressions[j];

                if (expression.value != null)
                {
                    MemberInfo member = ReflectionUtils.GetMember(classInfo.type, expression.name);

                    if (member != null)
                    {
                        Type memberType = ReflectionUtils.GetFieldOrPropertyType(member);

                        if (expression.value.GetType() != memberType)
                        {
                            expression.value = Convert.ChangeType(expression.value, memberType);
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        protected void ChangeExpression(BatchExpression be, int index, string name = null)
        {
            if (m_ExpressionNames != null)
            {
                if (index < m_ExpressionNames.Length - 1)
                {
                    be.index = index;
                    be.name  = m_ExpressionNames[be.index];
                }
                else
                {
                    be.index = m_ExpressionNames.Length - 1;
                    be.name  = name;
                }
            }
            else
            {
                be.index = 0;
                be.name  = name;
            }

            Type newType = m_ClassInfo.GetMemberType(be.name);

            if (newType != be.type)
            {
                be.type  = newType;
                be.value = null;

                m_ValueFields[be] = BaseField.Create(be.value, be.type, "");
            }

            if (!m_ValueFields.ContainsKey(be) && be.type != null)
            {
                m_ValueFields.Add(be, BaseField.Create(be.value, be.type, ""));
            }
        }
Ejemplo n.º 10
0
 public override void DrawExpresstionOp(BatchExpression be)
 {
     be.op = (int)((ModifyOperation)EditorGUILayout.EnumPopup((ModifyOperation)be.op));
 }
Ejemplo n.º 11
0
 public virtual void DrawExpresstionOp(BatchExpression be)
 {
     //
 }