“Exemple d'action d'unité” Réponses codées

Exemple d'action d'unité

public static event Action<string> OnGameOver;
public void TakeDamage(float damage)
{
    health -= damage;
    if(health < 0)
    {
        OnGameOver?.Invoke("The game is over");
    }
}

// can have multiple paramethers, always return null (if you want that it 
// retur something you have to create your own event

public static event Action<string> OnGameOver;
public static event Action<float, bool> OnPlayerHurt;
Jesús Angarita

actions d'unité

//An Action is basically an interface for any method which has no return 
//and no input parameters, that's it.

//So you can assign to your Action variable an anonymous method:

class ExampleClass
{
    public static event Action<string> loginSucceededEvent;
}

ExampleClass.loginSucceededEvent = delegate (string str)
{
  //
  // Add your code here;
  //
};

//or you can use this common method:
Action someAction += someMethod1;
Action someAction += someMethod2:
 
someAction(); // <-- calls someMethod1 and someMethod2

// then this happens:
 
void someMethod1()
{
     //something happens here
}
 
void someMethod2()
{
     //something else happens here
}
Jesús Angarita

Réponses similaires à “Exemple d'action d'unité”

Questions similaires à “Exemple d'action d'unité”

Plus de réponses similaires à “Exemple d'action d'unité” dans C#

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code