Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System; // musimy użyć to
- public class TestingEventSubscriber : MonoBehaviour
- {
- // Start is called before the first frame update
- void Start()
- {
- // STRUKTURA PODPIĘCIA FUNKCJI POD EVENT
- //
- // potrzebujemy referencji do naszego innego skryptu
- TestingEvents testingEvents = GetComponent<TestingEvents>();
- // z tą referencją mamy dostęp do naszego eventu:
- testingEvents .OnSpacePressed += TestingEvents_OnSpacePressed; // tutaj mówimy, że funkcja TestingEvents_OnSpacePressed
- // wykonuje się na event .OnSpacePressed
- // do powiedzenia tego musimy mieć obiekt klasy w której jest event
- //
- // nie wiem, dlaczego "GetComponent<TestingEvents>();"
- // sprawdzić, czy to musi być obiekt w którym jest event?
- // testujemy inny event
- testingEvents .OnIntEvent += TestingEvents_WithDelegate;
- // testujemy delegat Action bez parametrów
- testingEvents .OnActionEvent += TestingEvents_Action;
- // testujemy delegat Action a parametrami
- testingEvents .OnActionEventWithParameters += TestingEvents_ActionParameters;
- }
- private void TestingEvents_OnSpacePressed(object sender, EventArgs e)
- {
- Debug.Log("SPACE - Testing Event Subscriber");
- }
- private void TestingEvents_WithDelegate(int i)
- {
- Debug.Log("SPACE - DELEGATE " + i);
- }
- private void TestingEvents_Action()
- {
- Debug.Log("ACTION :3");
- }
- private void TestingEvents_ActionParameters(bool _bool, int _int)
- {
- Debug.Log(_bool + " " + _int);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement