예제 #1
0
        /// <summary>
        ///    Unregisters engagement dependency.
        /// </summary>
        public void UnregisterDependency(IEquipmentEngagementDependency dependency)
        {
            dependency.EngagementAllowed    -= OnDependencyAllowedEngagement;
            dependency.EngagementProhibited -= OnDependencyProhibitedEngagement;

            _dependencies.Remove(dependency);
        }
예제 #2
0
        /// <summary>
        ///    Registers object that determines whether that equipment is allowed to be powered on
        ///    by some subsystem or another external or internal dependency.
        /// </summary>
        public void RegisterDependency(IEquipmentEngagementDependency dependency)
        {
            Assert.IsTrue(dependency.Equipment == this, "Attempted to register foreign dependency.");

            _dependencies.Add(dependency);

            dependency.EngagementAllowed    += OnDependencyAllowedEngagement;
            dependency.EngagementProhibited += OnDependencyProhibitedEngagement;
        }
예제 #3
0
        private void OnDependencyProhibitedEngagement(IEquipmentEngagementDependency sender)
        {
            Assert.IsTrue(_dependencies.Contains(sender), "Reacted to dependency that wasn't in dependencies list.");

            if (Enabled)
            {
                Disengage();
            }
        }
예제 #4
0
        private void OnDependencyAllowedEngagement(IEquipmentEngagementDependency sender)
        {
            if (!IsInstalled)
            {
                return;
            }
            //We don't need to (un)subscribe from/to dependencies since there should be
            //no external references to them preventing equipment to be garbage-collected (if it no longer needed).
            //Although Equipment.Destroy is coming anyway, so it would be good to unregister all dependencies in it.

            Assert.IsTrue(_dependencies.Contains(sender), "Reacted to dependency that wasn't in dependencies list.");

            TryToEngage();
        }