Beispiel #1
0
        /// <summary>Logically links the source and the target, and starts the renderer.</summary>
        /// <remarks>It's always called <i>before</i> the physical link updates.</remarks>
        /// <param name="target">The target to link with.</param>
        protected virtual void LogicalLink(ILinkTarget target)
        {
            HostedDebugLog.Info(this, "Linking to target: {0}, actor={1}", target, linkActor);
            var linkInfo = new KasLinkEventImpl(this, target, linkActor);

            otherPeer             = target;
            linkTarget.linkSource = this;
            linkState             = LinkState.Linked;
            linkRenderer.StartRenderer(nodeTransform, linkTarget.nodeTransform);
            KASAPI.KasEvents.OnLinkCreated.Fire(linkInfo);
            part.Modules.OfType <ILinkStateEventListener>().ToList()
            .ForEach(x => x.OnKASLinkedState(linkInfo, isLinked: true));
        }
Beispiel #2
0
        /// <summary>
        /// Logically un-links the source and the current target, and stops the renderer.
        /// </summary>
        /// <remarks>It's always called <i>after</i> the physical link updates.</remarks>
        /// <param name="actorType">The actor which has initiated the un-linking.</param>
        protected virtual void LogicalUnlink(LinkActorType actorType)
        {
            HostedDebugLog.Info(this, "Un-linking from target: {0}, actor={1}", linkTarget, actorType);
            linkActor = actorType;
            var linkInfo = new KasLinkEventImpl(this, linkTarget, actorType);

            linkRenderer.StopRenderer();
            SetLinkState(LinkState.Available);
            if (linkTarget != null)
            {
                linkTarget.linkSource = null;
                SetOtherPeer(null);
            }
            linkActor = LinkActorType.None;
            KASAPI.KasEvents.OnLinkBroken.Fire(linkInfo);
            part.Modules.OfType <ILinkStateEventListener>().ToList()
            .ForEach(x => x.OnKASLinkedState(linkInfo, isLinked: false));
        }
Beispiel #3
0
        /// <inheritdoc/>
        protected override void OnPeerChange(ILinkPeer oldPeer)
        {
            base.OnPeerChange(oldPeer);
            linkState = linkSource != null ? LinkState.Linked : LinkState.Available;

            // Trigger events on the part.
            var oldSource = oldPeer as ILinkSource;

            if (linkStateMachine.currentState != null && oldSource != linkSource)
            {
                var linkInfo = new KasLinkEventImpl(linkSource ?? oldSource, this);
                if (linkSource != null)
                {
                    part.Modules.OfType <ILinkStateEventListener>().ToList()
                    .ForEach(x => x.OnKASLinkedState(linkInfo, isLinked: true));
                }
                else
                {
                    part.Modules.OfType <ILinkStateEventListener>().ToList()
                    .ForEach(x => x.OnKASLinkedState(linkInfo, isLinked: false));
                }
            }
        }