Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by kez1304 · May 03, 2019 at 11:27 AM · eventinheritanceinterfacedelegate

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 ScriptableObjects.

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?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kez1304 · May 03, 2019 at 11:41 AM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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 :

  1. One inheriting from ScriptableObject with the CreateAssetMenu attribute, and all the data you need

  2. Another 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 ) ;
 }
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kez1304 · May 03, 2019 at 11:38 AM 0
Share

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.

avatar image Hellium kez1304 · May 03, 2019 at 12:27 PM 0
Share

I wasn't very clear sorry. I've edited my answer with more details.

avatar image kez1304 Hellium · May 03, 2019 at 12:51 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

109 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Interaction script 2 Answers

Instantiating an object from its interface 3 Answers

How to make Delegates/Events survive assembly reload? 3 Answers

C# event setup, no result 0 Answers

An OS design issue: File types associated with their appropriate programs 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges