Exemplo n.º 1
0
        public static void ProcessAutoFillChildrenAttribute(FieldInfo fieldInfo, Component ownerComponent)
        {
            var isEnumerable = IsTypeEnumerable(fieldInfo.FieldType);

            if (isEnumerable)
            {
                ProcessEnumerableFieldInfoForComponent(fieldInfo, ownerComponent,
                                                       type => ownerComponent.GetComponentsInChildren(type).Where(component => component.gameObject != ownerComponent.gameObject).ToArray());
                return;
            }

            var values = ownerComponent.GetComponentsInChildren(fieldInfo.FieldType);

            if (values.Length > 1)
            {
                CustomAttributeSystem.LogValidationError($"Found more than one {fieldInfo.FieldType} at {ownerComponent}.");
            }
            var value = values.FirstOrDefault(component => component.gameObject != ownerComponent.gameObject);

            fieldInfo.SetValue(ownerComponent, value);
        }
Exemplo n.º 2
0
        public static void ProcessAutoFillSceneAttribute(FieldInfo fieldInfo, Component ownerComponent)
        {
            var isEnumerable = IsTypeEnumerable(fieldInfo.FieldType);

            if (isEnumerable)
            {
                ProcessEnumerableFieldInfoForComponent(
                    fieldInfo,
                    ownerComponent,
                    type => UnityEngine.Object.FindObjectsOfType(type, true) as Component[]);
                return;
            }

            var values = UnityEngine.Object.FindObjectsOfType(fieldInfo.FieldType, true);

            if (values.Length > 1)
            {
                CustomAttributeSystem.LogValidationError($"Found more than one {fieldInfo.FieldType} at {ownerComponent}.");
            }
            var value = values.FirstOrDefault();

            fieldInfo.SetValue(ownerComponent, value);
        }
 public override void Action() => CustomAttributeSystem.ProcessScene();