예제 #1
0
        void DeactivateAttractionItem(ResourceActivationContext context, LocationAttractionItemProperties item)
        {
            IAttractionItemHandler handler = null;

            if (m_itemHandlers.TryGetValue(context.InstanceId, out handler))
            {
                if (item.AttractionReferences != null)
                {
                    foreach (var a in item.AttractionReferences)
                    {
                        m_attractionItemHandlers.Remove(a.ObjectId, handler);

                        ActivatedAttractionContext actxt;

                        if (m_atrractionActivators.TryGetValue(a.ObjectId, out actxt))
                        {
                            DetachHandlerFromAttraction(actxt, handler);
                        }
                    }
                }

                // Clean up any leftovers
                handler.DeactivateAll();
            }
        }
예제 #2
0
        void DetachHandlerFromAttraction(ActivatedAttractionContext actxt, IAttractionItemHandler handler)
        {
            handler.Deactivate(actxt.Attraction);

            actxt.RemoveItemHandler(handler);

            StopMontitoringAttractionItem(handler.ActivationContext);
        }
예제 #3
0
        void ActivateItemHandler(IAttractionItemHandler handler)
        {
            m_itemHandlers[handler.ActivationContext.InstanceId] = handler;

            if (handler.ItemProperties.AttractionReferences != null)
            {
                foreach (var a in handler.ItemProperties.AttractionReferences)
                {
                    ActivatedAttractionContext actxt = null;

                    if (m_atrractionActivators.TryGetValue(a.ObjectId, out actxt))
                    {
                        AttachHandlerToAttraction(actxt, handler);
                    }
                }
            }
        }
예제 #4
0
        public void ActivateInteractible(ResourceActivationContext ctxt, LocationAttractionInteractible interactible)
        {
            IAttractionItemHandler handler = null;

            if (interactible.InteractibleItem != null)
            {
                if (interactible.InteractibleItem is LocationAugmented3DAsset)
                {
                    handler = new AR3DAssetAttractionItemHandler(ctxt, interactible, (LocationAugmented3DAsset)interactible.InteractibleItem);
                }
                else if (interactible.InteractibleItem is LocationAugmentedImage)
                {
                    handler = new ARImageAttractionItemHandler(ctxt, interactible, (LocationAugmentedImage)interactible.InteractibleItem);
                }
            }

            if (handler != null)
            {
                ActivateItemHandler(handler);
            }

            OnUpdate();
        }
예제 #5
0
        void AttachHandlerToAttraction(ActivatedAttractionContext actxt, IAttractionItemHandler handler)
        {
            actxt.AddItemHandler(handler);

            MonitorAttractionItem(handler.ActivationContext, actxt, handler.ItemProperties, handler);
        }
예제 #6
0
        /// <summary>
        /// Starts monitoring an attraction item by setting up a location fence and following
        /// the activation/range rules. Will call back "activate" and "deactivate" based
        /// on these rules.
        /// </summary>
        /// <param name="ctxt"></param>
        /// <param name="actxt"></param>
        /// <param name="item"></param>
        /// <param name="activateItems"></param>
        /// <param name="deactivateItems"></param>
        private void MonitorAttractionItem(
            ResourceActivationContext ctxt,
            ActivatedAttractionContext actxt,
            LocationAttractionItemProperties item,
            IAttractionItemHandler handler)
        {
            bool activated  = false;
            var  wasInRange = ctxt.CheckEvent("in_range");

            Func <bool> checkAutoplay = () =>
            {
                var didPlay = ctxt.CheckEvent("open");

                return(item.AutoplayBehavior == AttractionRangeAutoplayBehavior.Always ||
                       item.AutoplayBehavior == AttractionRangeAutoplayBehavior.Once && !didPlay);
            };

            var autoplay = checkAutoplay();

            if (item.RangeAvailability == AttractionRangeAvailability.Always)
            {
                // Always activate
                activated = true;
                handler.Activate(actxt.Attraction, autoplay);
            }
            else
            {
                if (wasInRange && item.RangeAvailability == AttractionRangeAvailability.InRangeAndAfter)
                {
                    handler.Activate(actxt.Attraction, autoplay);
                }
            }

            var range = item.Range ?? actxt.Range;

            if (range != null && actxt.Attraction.Locations != null)
            {
                m_fencePool.WatchLocations(ctxt.InstanceId, actxt.Attraction.Locations, range,
                                           (locations) =>
                {
                    ctxt.FireEvent("in_range");
                    ctxt.SetState("in_range");

                    // In Range
                    if (!activated || item.RangeAvailability == AttractionRangeAvailability.OnlyInRange)
                    {
                        activated = true;
                        handler.Activate(actxt.Attraction, checkAutoplay());
                    }
                },
                                           () =>
                {
                    ctxt.ClearState("in_range");

                    // Out of range
                    if (item.RangeAvailability == AttractionRangeAvailability.OnlyInRange)
                    {
                        handler.Deactivate(actxt.Attraction);
                    }
                });
            }
            else
            {
                // Items haven't been activated, but there's no range or locations.
                // In this case treat the items as "in range" and activate them.
                if (!activated)
                {
                    ctxt.FireEvent("in_range");
                    ctxt.SetState("in_range");

                    activated = true;
                    handler.Activate(actxt.Attraction, autoplay);
                }
            }
        }
예제 #7
0
 public void RemoveItemHandler(IAttractionItemHandler handler)
 {
     m_itemHandlers.Remove(handler.ActivationContext.InstanceId);
 }
예제 #8
0
 public void AddItemHandler(IAttractionItemHandler handler)
 {
     m_itemHandlers[handler.ActivationContext.InstanceId] = handler;
 }