Exemplo n.º 1
0
        public void ProcessArrayFieldWithProcessor(ExposedPropertyConfiguration propertyConfiguration, Component affectedComponent, FieldInfo field, Type fieldType)
        {
            string operationType = propertyConfiguration.OperationType;

            if (_processors.ContainsKey(operationType))
            {
                IPropertyProcessor propertyProcessor = _processors[operationType];

                Object[] values = {};

                if (fieldType == typeof(GameObject))
                {
                    values = propertyProcessor.ProcessArrayGameObjectField(
                        affectedComponent, fieldType, propertyConfiguration);
                }
                else if (fieldType.IsSubclassOf(typeof(Component)))
                {
                    values = propertyProcessor.ProcessArrayComponentField(
                        affectedComponent, fieldType, propertyConfiguration);
                }

                if (values != null)
                {
                    if (_arrayTypeUtils.IsArray(field.FieldType))
                    {
                        Array referencedObjectsArray = Array.CreateInstance(fieldType, values.Length);
                        for (int i = 0; i < referencedObjectsArray.Length; i++)
                        {
                            referencedObjectsArray.SetValue(values[i], i);
                        }

                        field.SetValue(affectedComponent, referencedObjectsArray);
                    }
                    //else it should be list
                    else
                    {
                        var list = (IList)Activator.CreateInstance(field.FieldType);

                        foreach (var value in values)
                        {
                            list.Add(value);
                        }
                        field.SetValue(affectedComponent, list);
                    }
                }
                else
                {
                    field.SetValue(affectedComponent, null);
                }
            }
        }
Exemplo n.º 2
0
        private void RenderFieldReferencesInformation(FieldInfo field, Component affectedComponent)
        {
            var value = field.GetValue(affectedComponent);
            int count = 0;

            //value.ToString() -> sometimes AudioSource or Animator wasn't null but "null", but inspector showed always None
            if (value != null && value.ToString() != "null")
            {
                //if there is a value and the field is array, it has to be nonempty
                if (_arrayTypeUtils.IsArray(field.FieldType))
                {
                    Array array = (Array)value;
                    count = _arrayTypeUtils.GetRealItemsCount(array);
                }
                //else if it's list
                else if (_arrayTypeUtils.IsList(field.FieldType))
                {
                    IList list = (IList)value;
                    count = _arrayTypeUtils.GetRealItemsCount(list);
                }
                //if it's field or object structure, the reference is ok
                else
                {
                    count = 1;
                }
            }

            GUIStyle guiStyle = new GUIStyle(EditorStyles.boldLabel);

            if (count == 0)
            {
                guiStyle.normal.textColor = Color.red;
            }

            EditorGUILayout.LabelField(count + "x", guiStyle, GUILayout.Width(25));
        }