Beispiel #1
0
        private static void AllowOnlyOneAttributes(GameObject gameObject, Component component, bool isLinkingAllowed, Type componentType)
        {
            AllowOnlyOne allowOnlyOne = componentType.GetCustomAttribute <AllowOnlyOne>();

            if (allowOnlyOne != null)
            {
                Component OldItem = gameObject.GetComponent(componentType);
                if (OldItem != null && OldItem != component)
                {
                    if (EditorDialogs.ReplaceComponentDialog())
                    {
                        gameObject.AddComponent <DeleteComponent>().componentReference = OldItem;
                        if (isLinkingAllowed && allowOnlyOne.HasLinks)
                        {
                            List <MonoBehaviour> components = new List <MonoBehaviour>(gameObject.GetComponents <MonoBehaviour>());
                            for (int i = 0; i < components.Count; i++)
                            {
                                if (components[i] == component && (i + 1) < components.Count)
                                {
                                    Debug.Log("AllowOnlyOne -> Links");
                                    //gameObject.AddComponent<LinkComponents>().Init(components[i]);
                                    return;
                                }
                            }
                        }
                    }
                    else
                    {
                        gameObject.AddComponent <DeleteComponent>().componentReference = component;
                    }
                }
            }
        }
Beispiel #2
0
 private static bool LinkingCheckAttribute(Type componentType)
 {
     if (componentType.GetCustomAttribute <WithLinkingCheckDialog>() != null)
     {
         return(EditorDialogs.AllowLinkingDialog());
     }
     return(true);
 }
Beispiel #3
0
        private static void WarningMessageAttribute(Type componentType)
        {
            WithWarningDialog withWarningDialog = componentType.GetCustomAttribute <WithWarningDialog>();

            if (withWarningDialog != null)
            {
                EditorDialogs.WarningDialog(withWarningDialog.WarningMessage);
            }
        }
Beispiel #4
0
 private static void RequiresComponentsAttribute(GameObject gameObject, FieldInfo[] fieldInfos, List <Component> components, Component component, Type componentType)
 {
     if (componentType.GetCustomAttribute <RequiresComponents>() != null)
     {
         foreach (FieldInfo fieldInfo in fieldInfos)
         {
             if (fieldInfo.GetCustomAttribute <FieldRequiresComponent>() != null)
             {
                 Component matchingComponent = FindComponentOfType(components, fieldInfo.FieldType);
                 if (matchingComponent != null)
                 {
                     fieldInfo.SetValue(component, matchingComponent);
                 }
                 else
                 {
                     if (EditorDialogs.RequiresComponentDialog(fieldInfo.FieldType.Name))
                     {
                         fieldInfo.SetValue(component, gameObject.AddComponent(fieldInfo.FieldType));
                     }
                     else
                     {
                         gameObject.AddComponent <DeleteComponent>().componentReference = component;
                         return;
                     }
                 }
             }
             else
             {
                 FieldListRequiresComponent attribute = fieldInfo.GetCustomAttribute <FieldListRequiresComponent>();
                 if (attribute != null)
                 {
                     Type fieldType  = fieldInfo.FieldType.GetGenericArguments()[0];
                     var  listOfType = CreateListOfType(fieldType);
                     ForEachTypeComponent(components, fieldType, (Component eachComponent) => listOfType.Add(eachComponent));
                     if (attribute.RequireAtLeast > listOfType.Count)
                     {
                         if (EditorDialogs.RequiresMultipleComponentsDialog(fieldInfo.FieldType.Name,
                                                                            attribute.RequireAtLeast - listOfType.Count, attribute.RequireAtLeast))
                         {
                             for (int i = 0; i < attribute.RequireAtLeast; i++)
                             {
                                 listOfType.Add(gameObject.AddComponent(fieldInfo.FieldType));
                             }
                         }
                         else
                         {
                             gameObject.AddComponent <DeleteComponent>().componentReference = component;
                             return;
                         }
                     }
                     fieldInfo.SetValue(component, listOfType);
                 }
             }
         }
     }
 }
Beispiel #5
0
        private static bool CancelAddingDialogAttribute(GameObject gameObject, Component component, Type componentType)
        {
            WithCancelAddingDialog withWarningDialog = componentType.GetCustomAttribute <WithCancelAddingDialog>();

            if (withWarningDialog != null)
            {
                if (EditorDialogs.WarningDialogWithCancel(withWarningDialog.WarningMessage))
                {
                    return(false);
                }
                gameObject.AddComponent <DeleteComponent>().componentReference = component;
                return(true);
            }
            return(false);
        }
Beispiel #6
0
        private static void ComponentRequiresComponentAttribute(GameObject gameObject, Component component, List <Component> components, Type componentType)
        {
            List <ComponentRequiresComponent> attributes = new List <ComponentRequiresComponent>();

            attributes.AddRange(componentType.GetCustomAttributes <ComponentRequiresComponent>());
            foreach (ComponentRequiresComponent attribute in attributes)
            {
                var       requiredComponentType = attribute.requiredComponentType;
                Component matchingComponent     = FindComponentOfType(components, requiredComponentType);
                if (matchingComponent == null)
                {
                    if (EditorDialogs.RequiresComponentDialog(requiredComponentType.Name))
                    {
                        gameObject.AddComponent(requiredComponentType);
                    }
                    else
                    {
                        gameObject.AddComponent <DeleteComponent>().componentReference = component;
                        return;
                    }
                }
            }
        }