Skip to content

Commit

Permalink
Change: ComponentData RegisterComponent methods now return boolean if…
Browse files Browse the repository at this point in the history
… successful or not
  • Loading branch information
WooshiiDev committed Sep 6, 2023
1 parent d8b20b2 commit e0c8de2
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions HierarchyDecorator/Scripts/Editor/Data/ComponentData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,12 @@ public void DeleteCustomGroup(int index)
/// Register a custom component to <see cref="AllCustomComponents"/>.
/// </summary>
/// <param name="component">The component to register.</param>
public void RegisterCustomComponent(Component component)
public bool RegisterCustomComponent(Component component)
{
if (component == null)
{
Debug.LogError("Cannot register null component.");
return;
return false;
}

MonoScript script = MonoScript.FromMonoBehaviour(component as MonoBehaviour);
Expand All @@ -306,7 +306,7 @@ public void RegisterCustomComponent(Component component)

if (script == null)
{
return;
return false;
}

ComponentType type = new ComponentType(component.GetType(), false);
Expand All @@ -316,35 +316,36 @@ public void RegisterCustomComponent(Component component)

if (!type.IsValid())
{
return;
return false;
}

RegisterCustomComponent(type);
return RegisterCustomComponent(type);
}

/// <summary>
/// Register a custom component to <see cref="AllCustomComponents"/>.
/// </summary>
/// <param name="component">The component to register.</param>
public void RegisterCustomComponent(ComponentType component)
public bool RegisterCustomComponent(ComponentType component)
{
// Cannot register null components

if (component == null)
{
Debug.LogError($"Attempted to register null component.");
return;
return false;
}

// Do not register the component if it already exists

if (allCustomComponents.Contains(component))
{
Debug.LogError($"Attempted to register a component that already exists. ({component})");
return;
return false;
}

allCustomComponents.Add(component);
return true;
}

public void MoveCustomGroup(int index, int newIndex)
Expand Down

0 comments on commit e0c8de2

Please sign in to comment.