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?
"+=" 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
@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.
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.
Answer by IndieFist · Mar 12, 2017 at 08:20 PM
Are you finally solved that? Should i put this OnEnable?
Your answer
![](https://koobas.hobune.stream/wayback/20220612100022im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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