Skip to main content
added 1 character in body
Source Link
Hellium
  • 2.9k
  • 1
  • 12
  • 27

This question is quite opinion-based, but personally, I would clearly choose the Inheritance based solution (or I would use an Interface if you don't need any class variables in the Interactible class).

If you put all your logic in a single class, you clearly violate one of the SOLID principle : Single responsibility principle.

The code used to move a platform should not "know" orhow to start a cutscene. This does not make sense.

The unfortunate downside to this is that I can't just use one prefab for all my events and change them based on the custom editor that I define.

I don't think using a single prefab would be a good idea anyway. Where do you attach the script? Using a specific script according to the event would allow you to attach it to the asset (or an empty parent), making more sense in my opinion.

I would have to create a custom editor for each possible child of the Interactible class, and instead of selecting which type of event I want it to be from a simple drop down, I will have to swap out different scripts for different functionality.

Why would you need to create a custom editor for each child class? The CustomEditor tag has an additionnal parameter so that the custom editor can edit child classes:

public CustomEditor(Type inspectedType, bool editorForChildClasses);

This question is quite opinion-based, but personally, I would clearly choose the Inheritance based solution (or I would use an Interface if you don't need any class variables in the Interactible class).

If you put all your logic in a single class, you clearly violate one of the SOLID principle : Single responsibility principle.

The code used to move a platform should not "know" or to start a cutscene. This does not make sense.

The unfortunate downside to this is that I can't just use one prefab for all my events and change them based on the custom editor that I define.

I don't think using a single prefab would be a good idea anyway. Where do you attach the script? Using a specific script according to the event would allow you to attach it to the asset (or an empty parent), making more sense in my opinion.

I would have to create a custom editor for each possible child of the Interactible class, and instead of selecting which type of event I want it to be from a simple drop down, I will have to swap out different scripts for different functionality.

Why would you need to create a custom editor for each child class? The CustomEditor tag has an additionnal parameter so that the custom editor can edit child classes:

public CustomEditor(Type inspectedType, bool editorForChildClasses);

This question is quite opinion-based, but personally, I would clearly choose the Inheritance based solution (or I would use an Interface if you don't need any class variables in the Interactible class).

If you put all your logic in a single class, you clearly violate one of the SOLID principle : Single responsibility principle.

The code used to move a platform should not "know" how to start a cutscene. This does not make sense.

The unfortunate downside to this is that I can't just use one prefab for all my events and change them based on the custom editor that I define.

I don't think using a single prefab would be a good idea anyway. Where do you attach the script? Using a specific script according to the event would allow you to attach it to the asset (or an empty parent), making more sense in my opinion.

I would have to create a custom editor for each possible child of the Interactible class, and instead of selecting which type of event I want it to be from a simple drop down, I will have to swap out different scripts for different functionality.

Why would you need to create a custom editor for each child class? The CustomEditor tag has an additionnal parameter so that the custom editor can edit child classes:

public CustomEditor(Type inspectedType, bool editorForChildClasses);
Source Link
Hellium
  • 2.9k
  • 1
  • 12
  • 27

This question is quite opinion-based, but personally, I would clearly choose the Inheritance based solution (or I would use an Interface if you don't need any class variables in the Interactible class).

If you put all your logic in a single class, you clearly violate one of the SOLID principle : Single responsibility principle.

The code used to move a platform should not "know" or to start a cutscene. This does not make sense.

The unfortunate downside to this is that I can't just use one prefab for all my events and change them based on the custom editor that I define.

I don't think using a single prefab would be a good idea anyway. Where do you attach the script? Using a specific script according to the event would allow you to attach it to the asset (or an empty parent), making more sense in my opinion.

I would have to create a custom editor for each possible child of the Interactible class, and instead of selecting which type of event I want it to be from a simple drop down, I will have to swap out different scripts for different functionality.

Why would you need to create a custom editor for each child class? The CustomEditor tag has an additionnal parameter so that the custom editor can edit child classes:

public CustomEditor(Type inspectedType, bool editorForChildClasses);