Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by caglarenes · Nov 04, 2016 at 09:44 AM · c#events

C# Events System

Hello, I'm using "Windows Store Native" plug-in and it has some 'events' list.

 WSANativeInterstitialAd.AdReady
 WSANativeInterstitialAd.Cancelled
 WSANativeInterstitialAd.Completed
 WSANativeInterstitialAd.ErrorOcurred

In past, I used to this code line to work with events in Unity:

 WSANativeInterstitialAd.ErrorOcurred += () =>
         {
             Debug.Log("InterstitialError");
         };

But now WSANativeInterstitialAd() have to take an argument;

WSAInterstitialAdType.Vungle or WSAInterstitialAdType.Microsoft

So, my code don't work and it says:

 error CS1593: Delegate `System.Action<CI.WSANative.Advertising.WSAInterstitialAdType>' does not take `0' arguments
 
 error CS0019: Operator `+=' cannot be applied to operands of type `System.Action<CI.WSANative.Advertising.WSAInterstitialAdType>' and `anonymous method'

I don't have information about events, It's too complicated me and I don't know what "+=" or "=>" are mean in C#. How can I work my code again and can you explain events in easy way?

Comment
Add comment · Show 5
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 Zodiarc · Nov 04, 2016 at 10:04 AM 1
Share

"+=" is pretty much the same in any language.

Basically:

 int a = 1;
 
 a = a + 1; // is the same as
 a += 1;


"=>" on the other hand is a lamdba delegate

avatar image Landern Zodiarc · Nov 04, 2016 at 01:05 PM 0
Share

@Zodiarc, that isn't actually true, when subscribing to an event the += actually calls add whereas the -= calls remove of the event, i mean the below literally.

Further reading, Jon Skeets Chapter 2 on events

Example of what it looks like through implementation:

 //... snip
 
 public event EventHandler SomeEvent
 {
     add
     {
         // When subscribing(+=) this is what is called using that operator
     }
     remove
     {
         // When unsubscribing(-=) this is what is called using that operator
     }
 }

@caglarenes, i would suggest hitting up the documentation on the assets site (http://www.claytoninds.com/#wsanative). The current documentation shows a different implementation for the current version then what you're using.

avatar image Zodiarc Landern · Nov 04, 2016 at 01:13 PM 0
Share

Ok my bad. Thanks for the clarification.

Show more comments

2 Replies

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

Answer by caglarenes · Nov 04, 2016 at 04:44 PM

I solve my problem. I should declare the Interstitial type to event but I didn't know how can I.

 WSANativeInterstitialAd.AdReady += ( WSAInterstitialAdType testad ) =>
         {

                     if  ( testad == WSAInterstitialAdType.Vungle)
             Debug.Log("VungleInterstitialReady");
                     .etc
         };

Thanks for all. I study more with your informations.

Comment
Add comment · 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
0

Answer by IndieFist · Mar 12, 2017 at 08:20 PM

Are you finally solved that? Should i put this OnEnable?

Comment
Add comment · 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

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

254 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 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 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

Help! I'm apparently way too used to C# with winforms... 0 Answers

Analytics CustomEvent sent without internet connection 0 Answers

Pre-populated UnityEvent style list from GetComponents on GameObject 0 Answers

UnityEngine.GameObject' does not contain a definition for `SetSelectedGameObject' 0 Answers

When should i be using events 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