Пример #1
0
        private void SpawnPart(int row, int column, MazePartDefinition def)
        {
            if (def == null || def.prefabName == "unset")
            {
                return;
            }
            try
            {
                Transform  maze   = GameObject.Find("Maze").transform;
                GameObject prefab = (GameObject)Resources.Load($"MazeParts/{def.prefabName}");
                if (prefab == null)
                {
                    prefab = (GameObject)Resources.Load($"MazeParts/Specials/{def.prefabName}");
                }
                GameObject part = (GameObject)Instantiate(prefab);


                part.GetComponent <DebugPattern>().partDef = def;
                part.transform.SetParent(maze);
                part.transform.rotation = Quaternion.Euler(0.0f, 90.0f * def.rotation, 0.0f);
                part.name = $"{def.prefabName.Replace("pf", "")} ROW:{def.row} COLUMN:{def.column}";
                // If area A change material
                int cDataIndex = _connections.FindIndex(p => p.row == def.row && p.column == def.column);
                _connections[cDataIndex].inGameObject = part;
                part.GetComponent <MazePiece>().AssignArea(_connections[cDataIndex]);

                part.transform.position = new Vector3(column * 7, 0, row * -7);
            }
            catch (System.Exception)
            {
                Debug.Log($"Failed to spawn prefab {def.prefabName}.");
                throw;
            }
        }
Пример #2
0
        public void InsertMapData(int row, int column, MazePartDefinition data, bool skipRotation = false)
        {
            map[row][column] = new MazePartDefinition(data, row, column);
            if (!skipRotation)
            {
                switch (data.rotation)
                {
                case 1:
                    map[row][column].validNorth = data.validWest;
                    map[row][column].validEast  = data.validNorth;
                    map[row][column].validSouth = data.validEast;
                    map[row][column].validWest  = data.validSouth;
                    break;

                case 2:
                    map[row][column].validNorth = data.validSouth;
                    map[row][column].validEast  = data.validWest;
                    map[row][column].validSouth = data.validNorth;
                    map[row][column].validWest  = data.validEast;
                    break;

                case 3:
                    map[row][column].validNorth = data.validEast;
                    map[row][column].validEast  = data.validSouth;
                    map[row][column].validSouth = data.validWest;
                    map[row][column].validWest  = data.validNorth;
                    break;
                }
            }
        }
Пример #3
0
 public void AddItem(MazePartDefinition entry)
 {
     if (!_dropTable.Exists(p => p.prefabName == entry.prefabName))
     {
         _dropTable.Add(entry);
         _dropTable.Sort((x, y) => x.generationWeight.CompareTo(y.generationWeight));
     }
 }
Пример #4
0
 public MazePartDefinition(MazePartDefinition data, int r, int c)
 {
     prefabName       = data.prefabName;
     generationWeight = data.generationWeight;
     willGenerate     = data.willGenerate;
     validNorth       = data.validNorth;
     validEast        = data.validEast;
     validSouth       = data.validSouth;
     validWest        = data.validWest;
     pattern          = data.pattern;
     rotation         = data.rotation;
     row    = r;
     column = c;
 }
Пример #5
0
        public void ClearMap()
        {
            // check min size
            if (height < 5)
            {
                height = 5;
            }
            if (width < 5)
            {
                width = 5;
            }

            map = new Dictionary <int, Dictionary <int, MazePartDefinition> >();
            for (int row = 0; row < height; row++)
            {
                map[row] = new Dictionary <int, MazePartDefinition>();
                for (int column = 0; column < width; column++)
                {
                    map[row][column] = new MazePartDefinition();
                }
            }
        }
Пример #6
0
 internal void RemoveEntry(MazePartDefinition piece)
 {
     _dropTable.RemoveAll(p => p.prefabName == piece.prefabName);
 }