protected virtual void PlayNotification(ResourceActivationContext context, PlayableContent playable, Notification notification, ResourcePanelData <Notification> data, Action onClose)
        {
            if (Platform.Instance.IsInBackground)
            {
                context.Open();

                if (!BackgroundNotifier.Instance.HasNotification(context.InstanceId))
                {
                    var localNotification = new Motive.Core.Notifications.LocalNotification();

                    localNotification.Title = notification.Title;
                    localNotification.Text  = notification.Message;

                    Platform.Instance.LocalNotificationManager.PostNotification(playable.Id, localNotification);
                }

                BackgroundNotifier.Instance.RemoveNotification(context.InstanceId);

                /*
                 * if (notification.SoundUrl != null)
                 * {
                 *  var path = WebServices.Instance.MediaDownloadManager.GetPathForItem(notification.SoundUrl);
                 *  m_channel.Play(new Uri(path));
                 * }*/

                if (onClose != null)
                {
                    onClose();
                }
            }
            else
            {
                if (notification.Title != null ||
                    notification.Message != null)
                {
                    Push(context, PanelStack, NotificationPanel, data, onClose);
                }
                else
                {
                    context.Open();

                    if (notification.Vibrate)
                    {
                        Platform.Instance.LocalNotificationManager.Vibrate();
                    }

                    if (notification.Sound != null)
                    {
                        Platform.Instance.PlaySound(notification.Sound.Url);
                    }

                    if (onClose != null)
                    {
                        onClose();
                    }
                }
            }
        }
        public void SpawnAsset(ResourceActivationContext context, AssetSpawner resource)
        {
            if (resource.AssetInstance == null ||
                resource.AssetInstance.Asset == null)
            {
                return;
            }

            var asset = resource.AssetInstance.Asset as UnityAsset;

            if (asset != null)
            {
                if (asset.AssetBundle != null)
                {
                    AssetLoader.LoadAsset <GameObject>(asset, obj =>
                    {
                        if (obj)
                        {
                            AddSpawnedAsset(context, resource, asset, obj);
                        }
                    });
                }
                else
                {
                    var obj = Resources.Load <GameObject>(asset.AssetName);

                    if (obj)
                    {
                        AddSpawnedAsset(context, resource, asset, GameObject.Instantiate(obj));
                    }
                }
            }

            context.Open();
        }
        public void ProcessInterfaceDirector(ResourceActivationContext context, InterfaceDirector director)
        {
            if (context.IsClosed)
            {
                return;
            }

            context.Open();

            if (director.Commands == null ||
                director.Commands.Length == 0)
            {
                context.Close();

                return;
            }

            BatchProcessor iter = new BatchProcessor(director.Commands.Length, context.Close);

            foreach (var command in director.Commands)
            {
                IInterfaceCommandHandler handler = null;

                if (m_handlers.TryGetValue(command.Type, out handler))
                {
                    handler.ProcessInterfaceCommand(context, command, () => iter++);
                }
                else
                {
                    throw new NotSupportedException("Unsupported interface command type " + command.Type);
                }
            }
        }
Esempio n. 4
0
        public WorldObjectBehaviour AddWorldObject(ResourceActivationContext context, GameObject obj, GameObject animationTarget, GameObject rootObj = null)
        {
            context.Open();

            var worldObj = (rootObj ?? obj).AddComponent <WorldObjectBehaviour>();

            worldObj.AnimationTarget    = animationTarget;
            worldObj.InteractibleObject = obj;
            worldObj.WorldObject        = obj;
            worldObj.ActivationContext  = context;

            m_worldObjects.Add(context.InstanceId, worldObj);

            var effects = m_pendingEffects[context.InstanceId];

            m_pendingEffects.RemoveAll(context.InstanceId);

            if (effects != null)
            {
                foreach (var container in effects)
                {
                    ApplyEffects(worldObj, container.ActivationContext, container.Resource);
                }
            }

            return(worldObj);
        }
        protected void Push(ResourceActivationContext context, string stackName, Panel panel, object data, Action onClose)
        {
            ThreadHelper.Instance.CallOnMainThread(() =>
            {
                context.Open();

                PanelManager.Instance.Push(stackName, panel, data, onClose);
            });
        }
Esempio n. 6
0
        public virtual void ActivatePlayerTaskDriver(ResourceActivationContext context, IPlayerTaskDriver driver)
        {
            if (!context.IsClosed)
            {
                context.Open();

                if (driver.Task.Outcomes != null)
                {
                    foreach (var oc in driver.Task.Outcomes)
                    {
                        m_outcomeDrivers.Add(oc.Id, driver);
                    }
                }

                m_drivers[context.InstanceId] = driver;

                // todo auto accept every task based on config option
                if (TaskManager.Instance.AutoAcceptTask)
                {
                    driver.Accept(); // calls start
                }

                //else if (driver.IsAccepted)
                //{
                //    driver.Start();
                //}

                if (context.IsFirstActivation)
                {
                    if (TaskNotifier.Instance)
                    {
                        TaskNotifier.Instance.AddNewTask(driver);
                    }
                }
            }
            else
            {
                // Track closed drivers, but don't do anything else with them.
                // This enables task views that store a "completed" task state.
                if (driver.Task.Outcomes != null)
                {
                    foreach (var oc in driver.Task.Outcomes)
                    {
                        m_outcomeDrivers.Add(oc.Id, driver);
                    }
                }

                m_drivers[context.InstanceId] = driver;
            }

            if (Updated != null)
            {
                Updated(this, EventArgs.Empty);
            }
        }
        public virtual void PlayAudioContent(ResourceActivationContext activationContext, PlayableContent playable, Action onClose)
        {
            activationContext.Open();

            AudioContentPlayer.Instance.PlayAudioContent(activationContext.InstanceId, playable.Content as LocalizedAudioContent, GetRouteForAudioContent(playable), (whenDone) =>
            {
                BeforePlayAudio(activationContext, playable, whenDone);
            },
                                                         () =>
            {
                AfterPlayAudio(activationContext, playable, onClose);
            });
        }
        public override void ActivateResource(ResourceActivationContext context, LocativeAudioContent resource)
        {
            if (LocativeAudioAnnotationHandler.Instance && resource.ShowOnMap)
            {
                LocativeAudioAnnotationHandler.Instance.AddLocativeAudio(context.InstanceId, resource);
            }

            LocativeAudioDriver.Instance.Activate(context.InstanceId, resource,
                                                  () =>
            {
                context.Open();
            },
                                                  (success) =>
            {
                context.Close();
            });
        }
Esempio n. 9
0
        internal void Add3DAsset(ResourceActivationContext context, VisualMarker3DAsset resource)
        {
            if (!CheckAdapter())
            {
                return;
            }

            if (resource.AssetInstance == null ||
                resource.Markers == null)
            {
                return;
            }

            foreach (var marker in resource.Markers)
            {
                var vumark = marker as IVisualMarker;

                if (vumark != null)
                {
                    var asset = new MarkerAsset
                    {
                        ActivationContext = context,
                        AssetInstance     = resource.AssetInstance,
                        Marker            = vumark,
                        MediaLayout       = resource.FallbackImage == null ? null : resource.FallbackImage.Layout,
                        MediaUrl          = resource.FallbackImage == null ? null : resource.FallbackImage.MediaUrl,
                        ObjectId          = context.InstanceId,
                        OnOpen            = () =>
                        {
                            context.Open();
                        },
                        OnSelect = () =>
                        {
                            context.FireEvent("select");
                        },
                        OnClose = () =>
                        {
                            context.Close();
                        }
                    };

                    Add3DAsset(asset);
                }
            }
        }
Esempio n. 10
0
        public void AddMarkerMedia(ResourceActivationContext context, VisualMarkerMedia resource)
        {
            if (!CheckAdapter())
            {
                return;
            }

            if (resource.MediaElement == null ||
                resource.MediaElement.MediaUrl == null ||
                resource.Markers == null)
            {
                return;
            }

            foreach (var marker in resource.Markers.OfType <IVisualMarker>())
            {
                if (marker != null)
                {
                    var media = new MarkerMedia
                    {
                        ActivationContext = context,
                        Marker            = marker,
                        MediaLayout       = resource.MediaElement.Layout,
                        MediaType         = resource.MediaElement.MediaItem.MediaType,
                        MediaUrl          = resource.MediaElement.MediaUrl,
                        Color             = resource.MediaElement.Color,
                        ObjectId          = context.InstanceId,
                        OnOpen            = () =>
                        {
                            context.Open();
                        },
                        OnSelect = () =>
                        {
                            context.FireEvent("select");
                        },
                        OnClose = () =>
                        {
                            context.Close();
                        }
                    };

                    AddMarkerMedia(media);
                }
            }
        }
        public void AddLocationValuablesCollection(ResourceActivationContext context, LocationValuablesCollection lvc)
        {
            if (context.IsClosed)
            {
                return;
            }

            context.Open();

            m_contexts.Add(context.InstanceId, context);

            List <Location> addedLocations = null;

            lock (m_valuablesByLocation)
            {
                var typeTagContainer = new LocationValuablesInstance
                {
                    ActivationContext   = context,
                    ValuablesCollection = lvc
                };

                if (lvc.LocationTypes != null)
                {
                    foreach (var t in lvc.LocationTypes)
                    {
                        m_valuablesByType.Add(t, typeTagContainer);
                    }
                }

                if (lvc.StoryTags != null)
                {
                    foreach (var t in lvc.StoryTags)
                    {
                        m_valuablesByTag.Add(t, typeTagContainer);
                    }
                }
            }

            bool isUpdating;

            var container = new LocationValuablesCollectionItemContainer(context, lvc);

            m_allValuables.Add(context.InstanceId, container);

            lock (this)
            {
                isUpdating = m_updating;

                if (isUpdating)
                {
                    m_addedValuables.Add(context.InstanceId, container);
                    m_removedValuables.Remove(context.InstanceId);
                }
            }

            if (!isUpdating)
            {
                if (ValuablesAdded != null)
                {
                    ValuablesAdded(this, new LocationValuablesCollectionManagerEventArgs(context, lvc));
                }

                if (addedLocations != null && LocationsAdded != null)
                {
                    LocationsAdded(this, new LocationValuablesCollectionManagerEventArgs(addedLocations.ToArray()));
                }
            }
        }