- Home /
Need to inherit from EventArgs AND ScriptableObject
I'm in a situation where I need to inherit from both EventArgs
and ScriptableObject
.
I can't see a way of achieving this, as I can't alter System.EventArgs
implementation to use an interface, nor ScriptableObject
s.
Am I going about this all wrong?
I want to be able to use the [CreateAssetMenu()]
(from ScriptableObject
) to create a new EventArgs
subclass... But it still needs to inherit from EventArgs
to match my delegate
method signature...
Any ideas?
Using an interface for EventArgs
would be the solution, but I'm unable to get the EventArgs
class to use that interface if I made it, as it's a System compiled class.
Answer by Hellium · May 03, 2019 at 11:29 AM
This is not possible.
Can't you simply create another class inheriting from EventArgs
with a simple getter&setter to access the instance of the Scriptable Object?
Create two classes :
One inheriting from ScriptableObject with the
CreateAssetMenu
attribute, and all the data you needAnother one, inheriting from
EventArgs
containing a simple reference to an instance of the class declared above
[CreateAssetMenu()]
public class MySO : ScriptableObject
{
// ... your data
}
public class MySOEventArgs : EventArgs
{
public MySO SO { get ; private set ;}
public MySOEventArgs( MySO so ) { SO = so ; }
}
// .. Somewhere in your code:
public event EventHandler<MySOEventArgs> SomethingHappened;
public void RaiseEvent( MySO mySOInstance )
{
MySOEventArgs args = new MySOEventArgs( mySOInstance );
if( SomethingHappened != null )
SomethingHappened( this, args ) ;
}
I want the ScriptableObject to access the Unity specific methods it allows (like the [CreateAsset$$anonymous$$enu()] mentioned). I'm not referencing some actual instance of a ScriptableObject. I want to be able to use the functionality it provides, whilst still being able to polymorph my proposed class in to an EventArgs type.
I wasn't very clear sorry. I've edited my answer with more details.
Lol. No need to be sorry, thanks a lot for expanding. I'm going to have to take an hour or so to wrap my head around all of this... I've only been using Unity and C# for a week or so.
Your answer
Follow this Question
Related Questions
Interaction script 2 Answers
Generic Triggers and Actions 0 Answers
Navmesh event on navigation end 0 Answers
Interface is lost with inheritance. How to solve? 2 Answers
OO Design | Specific example 2 Answers