Beispiel #1
0
        public void UnityEventCanBeInvokedDirectly()
        {
            var dummyGameObject = new GameObject();

            _unityEvent.AddListener(gameObject =>
                                    Assert.AreSame(dummyGameObject, gameObject, "GameObject is passed in as a parameter"));

            _gameObjectEventListener.OnEventBroadcast(dummyGameObject);
        }
        public void OnGameObjectEventBroadcast_CalledWithExpectedArgument()
        {
            // Arrange
            GameObject gameObjectArgument      = null;
            var        unityEvent              = new GameObjectEventUnityEvent();
            var        gameObjectEvent         = ScriptableObject.CreateInstance <GameObjectEvent>();
            var        gameObjectEventListener = new GameObject().AddComponent <GameObjectEventListener>();

            gameObjectEventListener.soEvent    = gameObjectEvent;
            gameObjectEventListener.unityEvent = unityEvent;
            gameObjectEventListener.OnEnable();
            var dummyGameObject = new GameObject();

            unityEvent.AddListener(gameObject => gameObjectArgument = gameObject);

            // Act
            gameObjectEvent.Broadcast(dummyGameObject);

            // Assert
            Assert.AreSame(dummyGameObject, gameObjectArgument, "GameObject is passed in as a parameter");
        }
        public void OnGameObjectEventBroadcast_GameEventListenerInvokesUnityEventOnGameEventBroadcast()
        {
            // Arrange
            GameObject gameObjectArgument      = null;
            var        eventListenerCalled     = false;
            var        unityEvent              = new GameObjectEventUnityEvent();
            var        gameObjectEvent         = ScriptableObject.CreateInstance <GameObjectEvent>();
            var        gameObjectEventListener = new GameObject().AddComponent <GameObjectEventListener>();

            gameObjectEventListener.soEvent    = gameObjectEvent;
            gameObjectEventListener.unityEvent = unityEvent;
            gameObjectEventListener.OnEnable();
            var dummyGameObject = new GameObject();

            unityEvent.AddListener(gameObject => eventListenerCalled = true);

            // Act
            gameObjectEvent.Broadcast(dummyGameObject);

            // Assert
            Assert.True(eventListenerCalled);
        }
        public void ScriptEventListenerHandleFunction_UnityEventCanBeInvokedDirectly()
        {
            // Arrange
            var eventListenerCalled     = false;
            var unityEvent              = new GameObjectEventUnityEvent();
            var gameObjectEvent         = ScriptableObject.CreateInstance <GameObjectEvent>();
            var gameObjectEventListener = new GameObject().AddComponent <GameObjectEventListener>();

            gameObjectEventListener.soEvent    = gameObjectEvent;
            gameObjectEventListener.unityEvent = unityEvent;
            gameObjectEventListener.OnEnable();

            var dummyGameObject = new GameObject();

            unityEvent.AddListener(gameObject => eventListenerCalled = true);

            // Act
            gameObjectEventListener.OnEventBroadcast(dummyGameObject);

            // Assert
            Assert.True(eventListenerCalled);
        }