Ejemplo n.º 1
0
        /// <inheritdoc />
        public void DispatchTriggerExit(PhysicsTriggerEventType physicsType, [JetBrains.Annotations.NotNull] GameObject objectTrigerRanOn, [JetBrains.Annotations.NotNull] Collider colliderThatTriggered)
        {
            if (objectTrigerRanOn == null)
            {
                throw new ArgumentNullException(nameof(objectTrigerRanOn));
            }
            if (colliderThatTriggered == null)
            {
                throw new ArgumentNullException(nameof(colliderThatTriggered));
            }

            if (PhysicsExitCallbackMap.ContainsKey(physicsType))
            {
                Action <object, PhysicsTriggerEventArgs> callback = null;
                lock (SyncObj)
                {
                    if (PhysicsExitCallbackMap.ContainsKey(physicsType))
                    {
                        callback = PhysicsExitCallbackMap[physicsType];
                    }
                }

                callback?.Invoke(this, new PhysicsTriggerEventArgs(objectTrigerRanOn, colliderThatTriggered));
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public void RegisterTriggerExitEventSubscription(PhysicsTriggerEventType physicsType, [JetBrains.Annotations.NotNull] Action <object, PhysicsTriggerEventArgs> physicsCallback)
        {
            if (physicsCallback == null)
            {
                throw new ArgumentNullException(nameof(physicsCallback));
            }
            if (!Enum.IsDefined(typeof(PhysicsTriggerEventType), physicsType))
            {
                throw new InvalidEnumArgumentException(nameof(physicsType), (int)physicsType, typeof(PhysicsTriggerEventType));
            }

            lock (SyncObj)
            {
                if (PhysicsExitCallbackMap.ContainsKey(physicsType))
                {
                    PhysicsExitCallbackMap[physicsType] += physicsCallback;
                }
                else
                {
                    PhysicsExitCallbackMap.Add(physicsType, physicsCallback);
                }
            }
        }