Exemple #1
0
 public virtual void RemovePointsOfInterestSubLayer(PrefabItemOptions layer)
 {
     _layerProperty.locationPrefabList.Remove(layer);
     _layerProperty.OnSubLayerPropertyRemoved(new VectorLayerUpdateArgs {
         property = layer
     });
 }
Exemple #2
0
        /// <summary>
        /// Places a prefab at all locations specified by the LatLon array.
        /// </summary>
        /// <param name="prefab"> A Game Object Prefab.</param>
        /// <param name="LatLon">A Vector2d(Latitude Longitude) object</param>
        public virtual void SpawnPrefabAtGeoLocation(GameObject prefab,
                                                     Vector2d[] LatLon,
                                                     Action <List <GameObject> > callback = null,
                                                     bool scaleDownWithWorld = true,
                                                     string locationItemName = "New Location")
        {
            var coordinateArray = new string[LatLon.Length];

            for (int i = 0; i < LatLon.Length; i++)
            {
                coordinateArray[i] = LatLon[i].x + ", " + LatLon[i].y;
            }

            PrefabItemOptions item = new PrefabItemOptions()
            {
                findByType         = LocationPrefabFindBy.AddressOrLatLon,
                prefabItemName     = locationItemName,
                spawnPrefabOptions = new SpawnPrefabOptions()
                {
                    prefab             = prefab,
                    scaleDownWithWorld = scaleDownWithWorld
                },

                coordinates = coordinateArray
            };

            if (callback != null)
            {
                item.OnAllPrefabsInstantiated += callback;
            }

            CreatePrefabLayer(item);
        }
Exemple #3
0
        /// <summary>
        /// Places the prefab for supplied categories.
        /// </summary>
        /// <param name="prefab">GameObject Prefab</param>
        /// <param name="categories"><see cref="LocationPrefabCategories"/> For more than one category separate them by pipe
        /// (eg: LocationPrefabCategories.Food | LocationPrefabCategories.Nightlife)</param>
        /// <param name="density">Density controls the number of POIs on the map.(Integer value between 1 and 30)</param>
        /// <param name="locationItemName">Name of this location prefab item for future reference</param>
        /// <param name="scaleDownWithWorld">Should the prefab scale up/down along with the map game object?</param>
        public virtual void SpawnPrefabByCategory(GameObject prefab,
                                                  LocationPrefabCategories categories = LocationPrefabCategories.AnyCategory,
                                                  int density             = 30, Action <List <GameObject> > callback = null,
                                                  bool scaleDownWithWorld = true,
                                                  string locationItemName = "New Location")
        {
            PrefabItemOptions item = new PrefabItemOptions()
            {
                findByType         = LocationPrefabFindBy.MapboxCategory,
                categories         = categories,
                density            = density,
                prefabItemName     = locationItemName,
                spawnPrefabOptions = new SpawnPrefabOptions()
                {
                    prefab             = prefab,
                    scaleDownWithWorld = scaleDownWithWorld
                }
            };

            if (callback != null)
            {
                item.OnAllPrefabsInstantiated += callback;
            }

            CreatePrefabLayer(item);
        }
Exemple #4
0
        /// <summary>
        /// Creates the prefab layer.
        /// </summary>
        /// <param name="item"> the options of the prefab layer.</param>
        private void CreatePrefabLayer(PrefabItemOptions item)
        {
            if (_vectorData.LayerProperty.sourceType == VectorSourceType.None ||
                !_vectorData.LayerProperty.sourceOptions.Id.Contains(MapboxDefaultVector.GetParameters(VectorSourceType.MapboxStreets).Id))
            {
                Debug.LogError("In order to place location prefabs please add \"mapbox.mapbox-streets-v7\" to the list of vector data sources");
                return;
            }

            //ensure that there is a vector layer
            if (_vectorData == null)
            {
                _vectorData = new VectorLayer();
            }

            //ensure that there is a list of prefabitems
            if (_vectorData.LocationPrefabsLayerProperties.locationPrefabList == null)
            {
                _vectorData.LocationPrefabsLayerProperties.locationPrefabList = new List <PrefabItemOptions>();
            }

            //add the prefab item if it doesn't already exist
            if (!_vectorData.LayerProperty.vectorSubLayers.Contains(item))
            {
                _vectorData.LocationPrefabsLayerProperties.locationPrefabList.Add(item);
                _vectorData.AddVectorLayer(item);
            }
        }
Exemple #5
0
        /// <summary>
        /// Creates the prefab layer.
        /// </summary>
        /// <param name="item"> the options of the prefab layer.</param>
        private void CreatePrefabLayer(PrefabItemOptions item)
        {
            if (LayerProperty.sourceType == VectorSourceType.None ||
                !LayerProperty.sourceOptions.Id.Contains(MapboxDefaultVector.GetParameters(VectorSourceType.MapboxStreets).Id))
            {
                Debug.LogError("In order to place location prefabs please add \"mapbox.mapbox-streets-v7\" to the list of vector data sources");
                return;
            }

            AddPointsOfInterestSubLayer(item);
        }
Exemple #6
0
        // POI LAYER OPERATIONS

        public virtual void AddPointsOfInterestSubLayer(PrefabItemOptions poiLayerProperties)
        {
            if (_layerProperty.locationPrefabList == null)
            {
                _layerProperty.locationPrefabList = new List <PrefabItemOptions>();
            }

            _layerProperty.locationPrefabList.Add(poiLayerProperties);
            _layerProperty.OnSubLayerPropertyAdded(new VectorLayerUpdateArgs {
                property = _layerProperty.locationPrefabList.Last()
            });
        }
Exemple #7
0
        public void AddLocationPrefabItem(PrefabItemOptions prefabItem)
        {
            //ensure that there is a list of prefabitems
            if (PointsOfInterestSublayerList == null)
            {
                PointsOfInterestSublayerList = new List <PrefabItemOptions>();
            }

            //add the prefab item if it doesn't already exist
            if (!PointsOfInterestSublayerList.Contains(prefabItem))
            {
                PointsOfInterestSublayerList.Add(prefabItem);
            }
        }
Exemple #8
0
        /// <summary>
        /// Creates the prefab layer.
        /// </summary>
        /// <param name="item"> the options of the prefab layer.</param>
        private void CreatePrefabLayer(PrefabItemOptions item)
        {
            if (_vectorData.LayerProperty.sourceType == VectorSourceType.None ||
                !_vectorData.LayerProperty.sourceOptions.Id.Contains(MapboxDefaultVector.GetParameters(VectorSourceType.MapboxStreets).Id))
            {
                Debug.LogError("In order to place location prefabs please add \"mapbox.mapbox-streets-v7\" to the list of vector data sources");
                return;
            }

            //ensure that there is a vector layer
            if (_vectorData == null)
            {
                _vectorData = new VectorLayer();
            }

            _vectorData.AddLocationPrefabItem(item);
        }
Exemple #9
0
        /// <summary>
        /// Places the prefab at POI locations if its name contains the supplied string
        /// <param name="prefab">GameObject Prefab</param>
        /// <param name="nameString">This is the string that will be checked against the POI name to see if is contained in it, and ony those POIs will be spawned</param>
        /// <param name="density">Density (Integer value between 1 and 30)</param>
        /// <param name="locationItemName">Name of this location prefab item for future reference</param>
        /// <param name="scaleDownWithWorld">Should the prefab scale up/down along with the map game object?</param>
        /// </summary>
        public virtual void SpawnPrefabByName(GameObject prefab,
                                              string nameString,
                                              int density = 30,
                                              Action <List <GameObject> > callback = null,
                                              bool scaleDownWithWorld = true,
                                              string locationItemName = "New Location")
        {
            PrefabItemOptions item = new PrefabItemOptions()
            {
                findByType         = LocationPrefabFindBy.POIName,
                nameString         = nameString,
                density            = density,
                prefabItemName     = locationItemName,
                spawnPrefabOptions = new SpawnPrefabOptions()
                {
                    prefab             = prefab,
                    scaleDownWithWorld = scaleDownWithWorld
                }
            };

            CreatePrefabLayer(item);
        }
        public void DrawUI(SerializedProperty property)
        {
            objectId = property.serializedObject.targetObject.GetInstanceID().ToString();
            var prefabItemArray = property.FindPropertyRelative("locationPrefabList");
            var layersRect      = EditorGUILayout.GetControlRect(GUILayout.MinHeight(Mathf.Max(prefabItemArray.arraySize + 1, 1) * _lineHeight + MultiColumnHeader.DefaultGUI.defaultHeight),
                                                                 GUILayout.MaxHeight((prefabItemArray.arraySize + 1) * _lineHeight + MultiColumnHeader.DefaultGUI.defaultHeight));

            if (!m_Initialized)
            {
                bool firstInit   = m_MultiColumnHeaderState == null;
                var  headerState = FeatureSubLayerTreeView.CreateDefaultMultiColumnHeaderState();
                if (MultiColumnHeaderState.CanOverwriteSerializedFields(m_MultiColumnHeaderState, headerState))
                {
                    MultiColumnHeaderState.OverwriteSerializedFields(m_MultiColumnHeaderState, headerState);
                }
                m_MultiColumnHeaderState = headerState;

                var multiColumnHeader = new FeatureSectionMultiColumnHeader(headerState);

                if (firstInit)
                {
                    multiColumnHeader.ResizeToFit();
                }

                treeModel = new TreeModel <FeatureTreeElement>(GetData(prefabItemArray));
                if (m_TreeViewState == null)
                {
                    m_TreeViewState = new TreeViewState();
                }

                if (layerTreeView == null)
                {
                    layerTreeView = new FeatureSubLayerTreeView(m_TreeViewState, multiColumnHeader, treeModel, FeatureSubLayerTreeView.uniqueIdPoI);
                }
                layerTreeView.multiColumnHeader = multiColumnHeader;
                m_Initialized = true;
            }


            layerTreeView.Layers = prefabItemArray;
            layerTreeView.Reload();
            layerTreeView.OnGUI(layersRect);

            if (layerTreeView.hasChanged)
            {
                EditorHelper.CheckForModifiedProperty(property);
                layerTreeView.hasChanged = false;
            }

            selectedLayers = layerTreeView.GetSelection();
            //if there are selected elements, set the selection index at the first element.
            //if not, use the Selection index to persist the selection at the right index.
            if (selectedLayers.Count > 0)
            {
                //ensure that selectedLayers[0] isn't out of bounds
                if (selectedLayers[0] - FeatureSubLayerTreeView.uniqueIdPoI > prefabItemArray.arraySize - 1)
                {
                    selectedLayers[0] = prefabItemArray.arraySize - 1 + FeatureSubLayerTreeView.uniqueIdPoI;
                }

                SelectionIndex = selectedLayers[0];
            }
            else
            {
                selectedLayers = new int[1] {
                    SelectionIndex
                };
                if (SelectionIndex > 0 && (SelectionIndex - FeatureSubLayerTreeView.uniqueIdPoI <= prefabItemArray.arraySize - 1))
                {
                    layerTreeView.SetSelection(selectedLayers);
                }
            }


            GUILayout.Space(EditorGUIUtility.singleLineHeight);
            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button(new GUIContent("Add Layer"), (GUIStyle)"minibuttonleft"))
            {
                //GUILayout.Space(EditorGUIUtility.singleLineHeight);
                prefabItemArray.arraySize++;

                var prefabItem     = prefabItemArray.GetArrayElementAtIndex(prefabItemArray.arraySize - 1);
                var prefabItemName = prefabItem.FindPropertyRelative("coreOptions.sublayerName");

                prefabItemName.stringValue = "New Location";

                // Set defaults here because SerializedProperty copies the previous element.
                prefabItem.FindPropertyRelative("coreOptions.isActive").boolValue      = true;
                prefabItem.FindPropertyRelative("coreOptions.snapToTerrain").boolValue = true;
                prefabItem.FindPropertyRelative("presetFeatureType").enumValueIndex    = (int)PresetFeatureType.Points;
                var categories = prefabItem.FindPropertyRelative("categories");
                categories.intValue = (int)(LocationPrefabCategories.AnyCategory);                //To select any category option

                var density = prefabItem.FindPropertyRelative("density");
                density.intValue = 15;                //To select all locations option

                //Refreshing the tree
                layerTreeView.Layers = prefabItemArray;
                layerTreeView.AddElementToTree(prefabItem);
                layerTreeView.Reload();

                selectedLayers = new int[1] {
                    prefabItemArray.arraySize - 1
                };
                layerTreeView.SetSelection(selectedLayers);

                if (EditorHelper.DidModifyProperty(property))
                {
                    PrefabItemOptions prefabItemOptionToAdd = (PrefabItemOptions)EditorHelper.GetTargetObjectOfProperty(prefabItem) as PrefabItemOptions;
                    ((VectorLayerProperties)EditorHelper.GetTargetObjectOfProperty(property)).OnSubLayerPropertyAdded(new VectorLayerUpdateArgs {
                        property = prefabItemOptionToAdd
                    });
                }
            }

            if (GUILayout.Button(new GUIContent("Remove Selected"), (GUIStyle)"minibuttonright"))
            {
                foreach (var index in selectedLayers.OrderByDescending(i => i))
                {
                    if (layerTreeView != null)
                    {
                        var poiSubLayer = prefabItemArray.GetArrayElementAtIndex(index - FeatureSubLayerTreeView.uniqueIdPoI);

                        VectorLayerProperties vectorLayerProperties = (VectorLayerProperties)EditorHelper.GetTargetObjectOfProperty(property);
                        PrefabItemOptions     poiSubLayerProperties = (PrefabItemOptions)EditorHelper.GetTargetObjectOfProperty(poiSubLayer);

                        vectorLayerProperties.OnSubLayerPropertyRemoved(new VectorLayerUpdateArgs {
                            property = poiSubLayerProperties
                        });

                        layerTreeView.RemoveItemFromTree(index);
                        prefabItemArray.DeleteArrayElementAtIndex(index - FeatureSubLayerTreeView.uniqueIdPoI);
                        layerTreeView.treeModel.SetData(GetData(prefabItemArray));
                    }
                }
                selectedLayers = new int[0];
                layerTreeView.SetSelection(selectedLayers);
            }

            EditorGUILayout.EndHorizontal();

            if (selectedLayers.Count == 1 && prefabItemArray.arraySize != 0 && selectedLayers[0] - FeatureSubLayerTreeView.uniqueIdPoI >= 0)
            {
                //ensure that selectedLayers[0] isn't out of bounds
                if (selectedLayers[0] - FeatureSubLayerTreeView.uniqueIdPoI > prefabItemArray.arraySize - 1)
                {
                    selectedLayers[0] = prefabItemArray.arraySize - 1 + FeatureSubLayerTreeView.uniqueIdPoI;
                }
                SelectionIndex = selectedLayers[0];

                var layerProperty = prefabItemArray.GetArrayElementAtIndex(SelectionIndex - FeatureSubLayerTreeView.uniqueIdPoI);

                layerProperty.isExpanded = true;
                var  subLayerCoreOptions = layerProperty.FindPropertyRelative("coreOptions");
                bool isLayerActive       = subLayerCoreOptions.FindPropertyRelative("isActive").boolValue;
                if (!isLayerActive)
                {
                    GUI.enabled = false;
                }
                DrawLayerLocationPrefabProperties(layerProperty, property);
                if (!isLayerActive)
                {
                    GUI.enabled = true;
                }
            }
            else
            {
                GUILayout.Space(15);
                GUILayout.Label("Select a visualizer to see properties");
            }
        }