Esempio n. 1
0
        void AddSpawnedAsset(ResourceActivationContext context, AssetSpawner resource, UnityAsset asset, GameObject obj)
        {
            GameObject rootObject = new GameObject(asset.AssetName);

            rootObject.transform.position   = Vector3.zero;
            rootObject.transform.localScale = Vector3.one;
            rootObject.transform.rotation   = Quaternion.Euler(Vector3.zero);

            var worldObj = AddWorldObject(context, obj, rootObject);

            worldObj.Asset = asset;

            obj.transform.position   = Vector3.zero;
            obj.transform.localScale = Vector3.one;
            obj.transform.rotation   = Quaternion.Euler(Vector3.zero);

            obj.transform.SetParent(rootObject.transform);

            if (resource.SpawnPosition is FixedWorldPosition)
            {
                var fixedPos = resource.SpawnPosition as FixedWorldPosition;

                if (fixedPos.Position != null)
                {
                    rootObject.transform.position = LayoutHelper.ToVector3(fixedPos.Position);
                }

                if (resource.AssetInstance.Layout != null)
                {
                    LayoutHelper.Apply(obj.transform, resource.AssetInstance.Layout);
                }
            }

            m_worldObjects.Add(resource.AssetInstance.Id, worldObj);
        }
Esempio n. 2
0
        public void MultiSetDictionary()
        {
            var set = new SetDictionary <int, int>(new Dictionary <int, int>
            {
                { 5, 0 },
                { 6, 1 },
                { 7, 2 },
                { 8, 3 },
                { 9, 4 },
                { 1, 5 },
                { 2, 6 },
                { 3, 7 },
                { 4, 8 },
            }, true);

            set.Add(5, 9);
            set.Add(1, 10);
            set.Add(2, 11);
            set.Add(3, 12);
            set.ToArray().Should().Equal(new KeyValuePair <int, int>[]
            {
                KeyValuePair.Create(1, 5),
                KeyValuePair.Create(1, 10),
                KeyValuePair.Create(2, 6),
                KeyValuePair.Create(2, 11),
                KeyValuePair.Create(3, 7),
                KeyValuePair.Create(3, 12),
                KeyValuePair.Create(4, 8),
                KeyValuePair.Create(5, 0),
                KeyValuePair.Create(5, 9),
                KeyValuePair.Create(6, 1),
                KeyValuePair.Create(7, 2),
                KeyValuePair.Create(8, 3),
                KeyValuePair.Create(9, 4),
            });
            set.Remove(5);
            set.ToArray().Should().Equal(new KeyValuePair <int, int>[]
            {
                KeyValuePair.Create(1, 5),
                KeyValuePair.Create(1, 10),
                KeyValuePair.Create(2, 6),
                KeyValuePair.Create(2, 11),
                KeyValuePair.Create(3, 7),
                KeyValuePair.Create(3, 12),
                KeyValuePair.Create(4, 8),
                KeyValuePair.Create(5, 9),
                KeyValuePair.Create(6, 1),
                KeyValuePair.Create(7, 2),
                KeyValuePair.Create(8, 3),
                KeyValuePair.Create(9, 4),
            });
            set.FindNodeLowerBound(4).Pair.Should().Be(KeyValuePair.Create(4, 8));
            set.FindNodeUpperBound(4).Pair.Should().Be(KeyValuePair.Create(5, 9));
            set.FindNodeLowerBound(5).Pair.Should().Be(KeyValuePair.Create(5, 9));
            set.FindNodeUpperBound(5).Pair.Should().Be(KeyValuePair.Create(6, 1));

            set.FindNodeLowerBound(10).Should().BeNull();
            set.FindNodeUpperBound(10).Should().BeNull();
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
0
        /** Not currently used
         * public static void InstantiateAssetInstance<T>(AssetInstance assetInstance, Action<T> onLoad, bool applyLayout = true)
         *  where T : UnityEngine.Object
         * {
         *  ThreadHelper.Instance.CallOnMainThread(() =>
         *      {
         *          var unityAsset = assetInstance.Asset as UnityAsset;
         *
         *          if (unityAsset != null)
         *          {
         *              LoadAsset<T>(unityAsset, (T assetObj) =>
         *              {
         *                  onLoad(assetObj);
         *              });
         *          }
         *      });
         * }
         *
         * public static void InstantiateAssetInstance(AssetInstance assetInstance, Action<GameObject> onLoad, bool applyLayout = true)
         * {
         *  InstantiateAssetInstance<GameObject>(assetInstance, onLoad, applyLayout);
         * }*/

        static void LoadAssetBundle(Motive.Unity.Models.AssetBundle motiveBundle, Action <UnityEngine.AssetBundle> onReady, bool loadAllAssets = false)
        {
            if (motiveBundle.Url == null)
            {
                return;
            }

            UnityEngine.AssetBundle unityBundle;

            if (!m_loadedBundles.TryGetValue(motiveBundle.Url, out unityBundle))
            {
                if (m_loadOperations.ContainsKey(motiveBundle.Url))
                {
                    m_loadOperations.Add(motiveBundle.Url, onReady);
                }
                else
                {
                    m_loadOperations.Add(motiveBundle.Url, onReady);

                    var local = WebServices.Instance.MediaDownloadManager.GetPathForItem(motiveBundle.Url);
                    //var localUri = (new Uri(local)).AbsoluteUri;

                    var bundleLoad = UnityEngine.AssetBundle.LoadFromFileAsync(local);

                    bundleLoad.completed += (asyncObj) =>
                    {
                        unityBundle = bundleLoad.assetBundle;

                        if (unityBundle == null)
                        {
                            return;
                        }

                        if (loadAllAssets)
                        {
                            unityBundle.LoadAllAssetsAsync();
                        }

                        m_loadedBundles[motiveBundle.Url] = unityBundle;

                        foreach (var call in m_loadOperations[motiveBundle.Url])
                        {
                            call(unityBundle);
                        }

                        m_loadOperations.RemoveAll(motiveBundle.Url);
                    };
                }
            }
            else
            {
                onReady(unityBundle);
            }
        }
Esempio n. 5
0
        internal void AddMapOverlay(ResourceActivationContext context, MapOverlay overlay)
        {
            if (overlay.CenterLocation != null)
            {
                var ann = new Overlay(overlay);

                m_overlays.Add(context.InstanceId, ann);

                MapView.AddOverlay(ann);
            }
        }
Esempio n. 6
0
        public void ReverseComparer()
        {
            var set = new SetDictionary <int, int, ReverseComparerStruct <int> >(new Dictionary <int, int>
            {
                { 5, 0 },
                { 6, 1 },
                { 7, 2 },
                { 8, 3 },
                { 9, 4 },
                { 1, 5 },
                { 2, 6 },
                { 3, 7 },
                { 4, 8 },
            });

            set.Add(5, 9);
            set.Add(1, 10);
            set.Add(2, 11);
            set.Add(3, 12);
            set.ToArray().Should().Equal(new Dictionary <int, int>
            {
                { 9, 4 },
                { 8, 3 },
                { 7, 2 },
                { 6, 1 },
                { 5, 0 },
                { 4, 8 },
                { 3, 7 },
                { 2, 6 },
                { 1, 5 },
            });
            set.Remove(5);
            set.ToArray().Should().Equal(new Dictionary <int, int>
            {
                { 9, 4 },
                { 8, 3 },
                { 7, 2 },
                { 6, 1 },
                { 4, 8 },
                { 3, 7 },
                { 2, 6 },
                { 1, 5 },
            });
            set.FindNodeLowerBound(6).Pair.Should().Be(KeyValuePair.Create(6, 1));
            set.FindNodeUpperBound(6).Pair.Should().Be(KeyValuePair.Create(4, 8));
            set.FindNodeLowerBound(5).Pair.Should().Be(KeyValuePair.Create(4, 8));
            set.FindNodeUpperBound(5).Pair.Should().Be(KeyValuePair.Create(4, 8));

            set.FindNodeLowerBound(0).Should().BeNull();
            set.FindNodeUpperBound(0).Should().BeNull();
        }
        public void ApplyEffects(ResourceActivationContext context, WorldObjectEffectPlayer resource)
        {
            if (resource.WorldObjectReferences != null &&
                resource.Effects != null)
            {
                foreach (var wo in resource.WorldObjectReferences)
                {
                    var instId = context.GetInstanceId(wo.ObjectId);

                    var worldObjs = m_worldObjects[instId];

                    if (worldObjs != null)
                    {
                        foreach (var worldObj in worldObjs)
                        {
                            ApplyEffects(worldObj, context, resource);
                        }
                    }
                    else
                    {
                        m_pendingEffects.Add(instId, new ActiveResourceContainer <WorldObjectEffectPlayer>(context, resource));
                    }
                }
            }
        }
    internal void AddLocationMarker(string instanceId, LocationMarker marker)
    {
        if (marker.Locations != null)
        {
            foreach (var l in marker.Locations)
            {
                var ann = new MapAnnotation <LocationMarker>(l, marker);

                ann.Marker = marker.Marker;

                m_markerAnnotations.Add(instanceId, ann);

                AddAnnotation(ann);
            }
        }
    }
        void ApplyEffects(WorldObjectBehaviour worldObj, ResourceActivationContext effectContext, WorldObjectEffectPlayer resource)
        {
            if (resource.Effects != null)
            {
                foreach (var eref in resource.Effects)
                {
                    switch (eref.Type)
                    {
                    case "motive.unity.animation":

                        var anim = eref as UnityAnimation;

                        if (anim != null)
                        {
                            var asset = anim.Asset;

                            if (asset != null)
                            {
                                var animTgt = worldObj.GetAnimationTarget();

                                if (animTgt)
                                {
                                    // Target may have been destroyed somewhere
                                    var objAnim = worldObj.GetAnimationTarget().AddComponent <WorldObjectAnimation>();
                                    objAnim.AnimationAsset = asset;

                                    m_effects.Add(effectContext.InstanceId, objAnim);
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }
Esempio n. 10
0
        internal void StartTracking(ARMarkerObject markerObj)
        {
            var markerIdent = markerObj.MarkerIdentifier;

            m_logger.Debug("start tracking {0}", markerIdent);

            m_trackingMarkerObjects.Add(markerIdent, markerObj);

            // Find all media items for the given marker
            var media = m_activeResourceMedia[markerIdent];

            m_logger.Debug("found {0} media items for {1}", media == null ? 0 : media.Count(), markerIdent);

            if (media != null)
            {
                foreach (var c in media)
                {
                    // Attach each media item to the marker
                    AttachMediaObject(c, markerObj);
                }
            }

            var assets = m_activeResourceAssets[markerIdent];

            if (assets != null)
            {
                foreach (var a in assets)
                {
                    AttachAssetObject(a, markerObj);
                }
            }

            TrackingConditionMonitor.TrackingMarkersUpdated();
        }
Esempio n. 11
0
        public void Populate(Catalog <LocationTreasureChest> catalog)
        {
            foreach (var tc in catalog)
            {
                if (tc.TreasureChests != null)
                {
                    if (tc.StoryTags != null)
                    {
                        foreach (var t in tc.StoryTags)
                        {
                            foreach (var chest in tc.TreasureChests)
                            {
                                m_storyTagChests.Add(t, chest);
                            }
                        }
                    }

                    if (tc.LocationTypes != null)
                    {
                        foreach (var t in tc.LocationTypes)
                        {
                            foreach (var chest in tc.TreasureChests)
                            {
                                m_locationTypeChests.Add(t, chest);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 12
0
        void ApplyEffects(WorldObjectBehaviour worldObj, ResourceActivationContext effectContext, WorldObjectEffectPlayer resource)
        {
            if (resource.Effects != null)
            {
                foreach (var eref in resource.Effects)
                {
                    IWorldObjectEffectHandler handler;

                    if (m_effectHandlers.TryGetValue(eref.Type, out handler))
                    {
                        var appliedEffect = new AppliedEffect(handler, worldObj, effectContext, resource, eref);

                        handler.ApplyEffect(appliedEffect);

                        m_appliedEffects.Add(effectContext.InstanceId, appliedEffect);
                    }
                    else
                    {
                        var errStr = string.Format("Could not find handler for effect type {0}", eref.Type);

                        SystemErrorHandler.Instance.ReportError(errStr);

                        m_logger.Warning(errStr);
                    }
                }
            }
        }
    protected virtual void OnItemsSpawned(string instanceId, LocationSpawnItemResults <T> result)
    {
        m_itemLocations.Add(instanceId, result.SourceLocation);

        if (ItemsSpawned != null)
        {
            ItemsSpawned(this, new LocationSpawnItemDriverEventArgs <T>(result));
        }
    }
Esempio n. 14
0
        protected override void AddItem(Recipe item)
        {
            if (item.Output != null && item.Output.CollectibleCounts != null)
            {
                foreach (var cc in item.Output.CollectibleCounts)
                {
                    m_recipesByCollectible.Add(cc.CollectibleId, item);
                }
            }

            base.AddItem(item);
        }
Esempio n. 15
0
        public void AddAnnotation(MapAnnotation annotation)
        {
            lock (m_toRemove)
            {
                m_toRemove.Remove(annotation);
            }

            m_locationAnnotations.Add(annotation.Location.Id, annotation);

            lock (m_toAdd)
            {
                m_toAdd.Add(annotation);
            }
        }
Esempio n. 16
0
 void CheckAdd(Pledge row)
 {
     if (isSaving)
     {
         return;
     }
     if (currentDates.Contains(row.Date) && pledgeTypes.Contains(row.Type))
     {
         if (row.Person != CurrentPerson)
         {
             thirdPartyPledges.Add(new PledgeKey(row), row);
             gridView.RefreshData();
             OnSummaryChanged();
         }
         else
         {
             AuctionPledge ap;
             if (auctionPledges.TryGetValue(new PledgeKey(row), out ap))
             {
                 ap.UpdateFromPledge(row);
             }
         }
     }
 }
Esempio n. 17
0
        void AddScriptFolder(string folderPath)
        {
            var parts = folderPath.Split('/');
            var path  = "";

            foreach (var part in parts)
            {
                if (!string.IsNullOrEmpty(part))
                {
                    m_scriptFolders.Add(string.IsNullOrEmpty(path) ? "/" : path, part);

                    path = path + "/" + part;
                }
            }
        }
Esempio n. 18
0
        VisualMarkerWorldObject CreateWorldObject(ARMarkerObject markerObj, VisualMarkerObject spawnedItem, GameObject animationTarget, ResourceActivationContext context = null)
        {
            var worldObj = new VisualMarkerWorldObject
            {
                GameObject = spawnedItem.gameObject
            };

            spawnedItem.WorldObject = worldObj;

            ARWorld.Instance.AddWorldObject(worldObj, context);
            WorldObjectManager.Instance.AddWorldObject(context, spawnedItem.gameObject, animationTarget, spawnedItem.LayoutObject);

            m_spawnedObjects.Add(markerObj, spawnedItem);

            return(worldObj);
        }
Esempio n. 19
0
        public void ObjectAction(string objectId, string action, bool oneShot)
        {
            if (action == m_currAction && objectId == m_currObjId)
            {
                return;
            }

            if (!oneShot)
            {
                m_objectActions.Add(objectId, action);
            }

            if (m_availableObjects.Contains(objectId))
            {
                ApplyObjectAction(objectId, action, oneShot);
            }
        }
Esempio n. 20
0
        void AddRecipe(Recipe recipe)
        {
            lock (m_recipesById)
            {
                m_recipesById[recipe.Id] = recipe;

                if (recipe.Output == null || recipe.Output.CollectibleCounts == null)
                {
                    return;
                }

                // each recipe can have multiple outputs, register each
                foreach (var cc in recipe.Output.CollectibleCounts)
                {
                    m_recipesByCollectible.Add(cc.CollectibleId, recipe);
                }
            }
        }
        /// <summary>
        /// Sort Items into SetDictionaries to query faster.
        /// </summary>
        /// <param name="item"></param>
        protected override void AddItem(Collectible item)
        {
            base.AddItem(item);

            if (item == null)
            {
                return;
            }

            // attributes
            if (item.Attributes != null && item.Attributes.Count() > 0)
            {
                foreach (var attr in item.Attributes)
                {
                    m_itemsByAttr.Add(attr, item);
                }
            }

            // emits actions
            if (item.EmittedActions != null && item.EmittedActions.Count() > 0)
            {
                foreach (var act in item.EmittedActions)
                {
                    if (!string.IsNullOrEmpty(act.Action))
                    {
                        m_itemsByEmitAction.Add(act.Action, item);
                    }
                }
            }

            // received
            if (item.ReceivedActions != null && item.ReceivedActions.Count() > 0)
            {
                foreach (var act in item.ReceivedActions)
                {
                    if (!string.IsNullOrEmpty(act.Action))
                    {
                        m_itemsByReceivedAction.Add(act.Action, item);
                    }
                }
            }
        }
Esempio n. 22
0
        void AddMarkerMedia(MarkerMedia markerMedia)
        {
            if (markerMedia.MediaUrl == null)
            {
                return;
            }

            m_activeResourceMedia.Add(markerMedia.Marker.Identifier, markerMedia);

            var objs = m_trackingVuMarkers[markerMedia.Marker.Identifier];

            if (markerMedia.Marker.Database != null)
            {
                LoadDataSet(markerMedia.Marker.Database);
            }

            if (objs != null)
            {
                foreach (var obj in objs)
                {
                    obj.ExtendedTracking = markerMedia.Marker.UseExtendedTracking;

                    AttachMediaObject(
                        markerMedia,
                        //markerMedia.Marker.Identifier,
                        obj.gameObject

                        /*,
                         * markerMedia.ObjectId,
                         * markerMedia.MediaUrl,
                         * markerMedia.MediaType,
                         * markerMedia.MediaLayout,
                         * markerMedia.OnOpen,
                         * markerMedia.OnSelect,
                         * markerMedia.OnClose*/);
                }
            }
        }
Esempio n. 23
0
        void AddMarkerMedia(MarkerMedia markerMedia)
        {
            if (markerMedia.MediaUrl == null)
            {
                return;
            }

            m_activeResourceMedia.Add(markerMedia.Marker.GetIdentifier(), markerMedia);

            var objs = m_trackingMarkerObjects[markerMedia.Marker.GetIdentifier()];

            Adapter.RegisterMarker(markerMedia.Marker);

            if (objs != null)
            {
                foreach (var obj in objs)
                {
                    AttachMediaObject(
                        markerMedia,
                        obj);
                }
            }
        }
Esempio n. 24
0
        void Add3DAsset(MarkerAsset markerAsset)
        {
            Adapter.RegisterMarker(markerAsset.Marker);

            var objs = m_trackingMarkerObjects[markerAsset.Marker.GetIdentifier()];

            m_activeResourceAssets.Add(markerAsset.Marker.GetIdentifier(), markerAsset);

            if (objs != null && objs.Count() > 0)
            {
                foreach (var obj in objs)
                {
                    //obj.ExtendedTracking = markerAsset.Marker.UseExtendedTracking;

                    AttachAssetObject(markerAsset, obj);
                }
            }
            else
            {
                // Cache the asset if supported
                AssetLoader.PreloadAsset(markerAsset.AssetInstance.Asset);
            }
        }
Esempio n. 25
0
        void Add3dAsset(MarkerAsset markerAsset)
        {
            if (markerAsset.Marker.Database != null)
            {
                LoadDataSet(markerAsset.Marker.Database);
            }

            var objs = m_trackingVuMarkers[markerAsset.Marker.Identifier];

            m_activeResourceAssets.Add(markerAsset.Marker.Identifier, markerAsset);

            if (objs != null && objs.Count() > 0)
            {
                foreach (var obj in objs)
                {
                    obj.ExtendedTracking = markerAsset.Marker.UseExtendedTracking;

                    AttachAssetObject(
                        markerAsset,
                        //markerAsset.Marker.Identifier,
                        obj.gameObject

                        /*,
                         * markerAsset.ObjectId,
                         * markerAsset.AssetInstance,
                         * markerAsset.MediaUrl,
                         * markerAsset.MediaLayout,
                         * markerAsset.OnOpen,
                         * markerAsset.OnSelect*/);
                }
            }
            else
            {
                // Preload the asset even if there's no marker yet
                UnityAssetLoader.LoadAsset <GameObject>((UnityAsset)markerAsset.AssetInstance.Asset, (obj) => { });
            }
        }
Esempio n. 26
0
        public WorldObjectBehaviour AddWorldObject(ResourceActivationContext context, GameObject obj, GameObject animationTarget, GameObject rootObj = null)
        {
            var worldObj = (rootObj ?? obj).AddComponent <WorldObjectBehaviour>();

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

            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);
        }
        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()));
                }
            }
        }
Esempio n. 28
0
        void ProcessValuables(IEnumerable <LocationValuablesCollectionItemContainer> locationValuables)
        {
            m_perf = new PerfCounters();

            m_perf.Start("v");

            // Group items by the sets of locations they reference.
            // The goal here is to reduce the number of locations we visit, ideally as close to 1
            // visit per location as possible.
            SetDictionary <IEnumerable <Location>, LocationValuablesCollectionItemContainer> fixedSets =
                new SetDictionary <IEnumerable <Location>, LocationValuablesCollectionItemContainer>();

            // Location sets per story tag
            Dictionary <string, IEnumerable <Location> > tagSets = new Dictionary <string, IEnumerable <Location> >();
            // Location sets per location type
            Dictionary <string, IEnumerable <Location> > typeSets = new Dictionary <string, IEnumerable <Location> >();

            SetDictionary <string, LocationValuablesCollectionItemContainer> tagLvcs =
                new SetDictionary <string, LocationValuablesCollectionItemContainer>();

            SetDictionary <string, LocationValuablesCollectionItemContainer> typeLvcs =
                new SetDictionary <string, LocationValuablesCollectionItemContainer>();

            foreach (var lvc in locationValuables)
            {
                if (lvc.SpawnItem.Locations != null)
                {
                    fixedSets.Add(lvc.SpawnItem.Locations, lvc);
                }

                if (lvc.SpawnItem.LocationTypes != null)
                {
                    foreach (var type in lvc.SpawnItem.LocationTypes)
                    {
                        if (!typeSets.ContainsKey(type))
                        {
                            typeSets[type] = LocationCache.Instance.GetLocationsWithType(type);
                        }

                        typeLvcs.Add(type, lvc);
                    }
                }

                if (lvc.SpawnItem.StoryTags != null)
                {
                    foreach (var tag in lvc.SpawnItem.StoryTags)
                    {
                        if (!tagSets.ContainsKey(tag))
                        {
                            tagSets[tag] = LocationCache.Instance.GetLocationsWithStoryTag(tag);
                        }

                        tagLvcs.Add(tag, lvc);
                    }
                }
            }

            Dictionary <string, Location> processedLocations = new Dictionary <string, Location>();

            // Processes the set of locations, optionally creating a union with an existing set
            Action <IEnumerable <Location>, IEnumerable <LocationValuablesCollectionItemContainer> > processLocations =
                (locs, lvcsIn) =>
            {
                m_perf.Start("l");

                m_perf.Start("u");

                HashSet <LocationValuablesCollectionItemContainer> lvcs = new HashSet <LocationValuablesCollectionItemContainer>();

                if (lvcsIn != null)
                {
                    lvcs.UnionWith(lvcsIn);
                }

                m_perf.Stop("u");

                m_perf.Start("locs");

                if (locs != null)
                {
                    foreach (var location in locs)
                    {
                        if (!processedLocations.ContainsKey(location.Id))
                        {
                            processedLocations.Add(location.Id, location);

                            if (location.LocationTypes != null)
                            {
                                foreach (var type in location.LocationTypes)
                                {
                                    var tl = typeLvcs[type];

                                    if (tl != null)
                                    {
                                        lvcs.UnionWith(tl);
                                    }
                                }
                            }

                            if (location.StoryTags != null)
                            {
                                foreach (var tag in location.StoryTags)
                                {
                                    var tl = tagLvcs[tag];

                                    if (tl != null)
                                    {
                                        lvcs.UnionWith(tl);
                                    }
                                }
                            }

                            m_perf.Start("c");

                            // Can be smarter here: if LVCs haven't changed, only locations, then
                            // any location that's been checked can be skipped
                            foreach (var lvc in lvcs)
                            {
                                // Have we processed this lvc/location combo recently??
                                // Note: this currently persists until the resource is deactivated.
                                LocationSpawnItemResults <LocationValuablesCollection> results = null;

                                lock (m_locationComputedItems)
                                {
                                    results = GetResults(lvc.ActivationContext.InstanceId, location);

                                    if (results != null)
                                    {
                                        continue;
                                    }

                                    results =
                                        new LocationSpawnItemResults <LocationValuablesCollection>(lvc.ActivationContext.InstanceId, location, lvc.SpawnItem);

                                    var prob = lvc.SpawnItem.Probability.GetValueOrDefault(1);
                                    var rnd  = Tools.RandomDouble(0, 1);

                                    if (rnd < prob)
                                    {
                                        // Tada!
                                        results.DidSpawn = true;
                                    }

                                    AddComputedResult(location, lvc.InstanceId, results);
                                }

                                if (results.DidSpawn)
                                {
                                    OnItemsSpawned(lvc.InstanceId, results);
                                }
                            }

                            m_perf.Stop("c");
                        }
                        else
                        {
                            // TODO: locations re-used
                        }
                    }
                }

                m_perf.Stop("locs");

                m_perf.Stop("l");
            };

            foreach (var set in fixedSets.Keys)
            {
                processLocations(set, fixedSets[set]);
            }

            foreach (var set in tagSets.Values)
            {
                processLocations(set, null);
            }

            foreach (var set in typeSets.Values)
            {
                processLocations(set, null);
            }

            /*
             * m_activationContexts.Add(e.ActivationContext.InstanceId, e.ActivationContext);
             */

            //if (IsRunning)
            {
                //AddSpawnItems(e.LocationValuables, null/*e.ActivationContext.GetStorageAgent()*/);
            }

            m_perf.Stop("v");

            m_logger.Debug("ProcessValuables perf={0}", m_perf.ToShortString());
        }
        public virtual void AddTaskAnnotation(D driver, MapAnnotation <D> annotation)
        {
            m_taskAnnotations.Add(driver.ActivationContext.InstanceId, annotation);

            AddAnnotation(annotation);
        }
Esempio n. 30
0
        internal void StartTracking(VuforiaTrackableEventHandler trackableBehaviour)
        {
            // hack for now: clear any objects attached to this one
            for (int i = 0; i < trackableBehaviour.gameObject.transform.childCount; i++)
            {
                var t = trackableBehaviour.gameObject.transform.GetChild(i);
                //Destroy(t.gameObject);
            }

            var instanceId = trackableBehaviour.Identifier;

            m_logger.Debug("start tracking " + instanceId);

            m_trackingVuMarkers.Add(trackableBehaviour.Identifier, trackableBehaviour);

            var media = m_activeResourceMedia[trackableBehaviour.Identifier];

            m_logger.Debug("found {0} media items for {1}", media == null ? 0 : media.Count(), instanceId);

            if (media != null)
            {
                foreach (var c in media)
                {
                    trackableBehaviour.ExtendedTracking = c.Marker.UseExtendedTracking;

                    AttachMediaObject(c, trackableBehaviour.gameObject);

                    /*
                     *  m_trackableBehaviour.Identifier,
                     *  m_trackableBehaviour.gameObject,
                     *  c.ObjectId,
                     *  c.MediaUrl,
                     *  c.MediaType,
                     *  c.MediaLayout,
                     *  c.OnOpen,
                     *  c.OnSelect,
                     *  c.OnClose);*/
                }
            }

            var assets = m_activeResourceAssets[trackableBehaviour.Identifier];

            if (assets != null)
            {
                foreach (var a in assets)
                {
                    trackableBehaviour.ExtendedTracking = a.Marker.UseExtendedTracking;

                    AttachAssetObject(
                        a,
                        trackableBehaviour.gameObject);

                    /*
                     *  m_trackableBehaviour.Identifier,
                     *  m_trackableBehaviour.gameObject,
                     *  a.ObjectId,
                     *  a.AssetInstance,
                     *  a.MediaUrl,
                     *  a.MediaLayout,
                     *  a.OnOpen,
                     *  a.OnSelect);*/
                }
            }
        }