コード例 #1
0
    private void CreateItem(Vector2 position)
    {
        //if (!mapLayoutDictionary.ContainsKey(position.ToString()))
        bool cursorPlaceable = cursor.GetComponent <CursorCollisionCheck>().Placeable;

        if (cursorPlaceable)
        {
            // Instantiate gameobject
            Vector3 positionVector3 = new Vector3();
            positionVector3.x = position.x;
            positionVector3.y = 0f;
            positionVector3.z = position.y;
            GameObject item = Instantiate(Resources.Load(editorPrefabString), cursor.transform.position, cursor.transform.rotation) as GameObject;

            // Create maplayoutelement
            MapLayoutElement newElement = new MapLayoutElement();
            newElement.prefabPath       = itemPrefabString;
            newElement.prefabPathEditor = editorPrefabString;
            newElement.position.x       = (int)position.x;
            newElement.position.y       = (int)position.y;

            // Create gridspace list for new maplayoutelement
            SerializableVector2Int gridSpace = new SerializableVector2Int();
            gridSpace.x = (int)position.x;
            gridSpace.y = (int)position.y;
            newElement.gridSpaces.Add(gridSpace);

            // Add the new element to the current save & maplayoutdictionary
            currentSave.mapLayout.Add(position.ToString(), newElement);
            mapLayoutDictionary.Add(position.ToString(), item);
        }
    }
コード例 #2
0
 private void  DetermineNextCell(MapLayoutElement mle, int topRow, ref int row, ref int col)
 {
     if (columnsFirstCheckBox.Checked)
     {
         row--;
         if (row < mle.MinRow)
         {
             row = topRow;
             col++;
         }
     }
     else
     {
         col++;
         if (col > mle.MaxColumn)
         {
             col = mle.MinColumn;
             row--;
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// Combines the background elements in the mapList with the elements to be mappend
        /// in the elementList using the mappings in the mappingList.
        /// </summary>
        /// <param name="mapList"></param>
        /// <param name="elementList"></param>
        /// <param name="mappingList"></param>
        /// <param name="mapLayout"></param>
        private void PopulateMapLayout(List <GenericElement> mapList,
                                       List <GenericElement> elementList,
                                       List <Mapping> mappingList,
                                       Dictionary <String, MapLayoutElement> mapLayout)
        {
            // create a dictionary between element names and their position in the element list
            var elementIndex = new Dictionary <String, int>();
            int elementPos   = 0;

            foreach (GenericElement element in elementList)
            {
                if (!elementIndex.ContainsKey(element.Name))
                {
                    elementIndex.Add(element.Name, elementPos);
                    elementPos++;
                }
                else
                {
                    String error = "### Duplicate Name " + element.Name;
                    Trace.WriteLine(error);
                    errorListBox.Items.Add(error);
                }
            }


            int mapPos = 0;

            foreach (GenericElement mapElement in mapList)
            {
                var mapLayoutElement = new MapLayoutElement(mapElement.Name, mapPos);

                foreach (Mapping mapping in mappingList)
                {
                    if (mapping.MapName == mapElement.Name)
                    {
                        if (elementIndex.ContainsKey(mapping.ElementName))
                        {
                            mapLayoutElement.AddMappedElement(mapping.ElementName);
                        }
                        else
                        {
                            String error = "### Invalid mapping of element " + mapping.ElementName + " (not existing) to " + mapping.MapName;
                            Trace.WriteLine(error);
                            errorListBox.Items.Add(error);
                        }
                    }
                }

                if (!mapLayout.ContainsKey(mapElement.Name))
                {
                    mapLayout.Add(mapElement.Name, mapLayoutElement);
                }
                else
                {
                    String error = "### Duplicate mapping " + mapElement.Name + " to " + mapLayoutElement.Name;
                    Trace.WriteLine(error);
                    errorListBox.Items.Add(error);
                }
                mapPos++;
            }

            foreach (MapLayoutElement me in mapLayout.Values)
            {
                Trace.WriteLine("MapLayoutElement " + me.Name + " to be used for " + me.NumMappedElements());
            }
        }