Ejemplo n.º 1
0
        /// <inheritdoc />
        public void DispatchTriggerEnter(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 (PhysicsEnterCallbackMap.ContainsKey(physicsType))
            {
                Action <object, PhysicsTriggerEventArgs> callback = null;
                lock (SyncObj)
                {
                    if (PhysicsEnterCallbackMap.ContainsKey(physicsType))
                    {
                        callback = PhysicsEnterCallbackMap[physicsType];
                    }
                }

                callback?.Invoke(this, new PhysicsTriggerEventArgs(objectTrigerRanOn, colliderThatTriggered));
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public void RegisterTriggerEnterEventSubscription(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 (PhysicsEnterCallbackMap.ContainsKey(physicsType))
                {
                    PhysicsEnterCallbackMap[physicsType] += physicsCallback;
                }
                else
                {
                    PhysicsEnterCallbackMap.Add(physicsType, physicsCallback);
                }
            }
        }