Exemple #1
0
        /// <summary>
        /// Draws a Rule Matrix for the given Rule for a RuleTile.
        /// </summary>
        /// <param name="tile">Tile to draw rule for.</param>
        /// <param name="rect">GUI Rect to draw rule at.</param>
        /// <param name="bounds">Cell bounds of the Rule.</param>
        /// <param name="tilingRule">Rule to draw Rule Matrix for.</param>
        public virtual void RuleMatrixOnGUI(RuleTile tile, Rect rect, BoundsInt bounds, RuleTile.TilingRule tilingRule)
        {
            Handles.color = EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.2f) : new Color(0f, 0f, 0f, 0.2f);
            float w = rect.width / bounds.size.x;
            float h = rect.height / bounds.size.y;

            for (int y = 0; y <= bounds.size.y; y++)
            {
                float top = rect.yMin + y * h;
                Handles.DrawLine(new Vector3(rect.xMin, top), new Vector3(rect.xMax, top));
            }
            for (int x = 0; x <= bounds.size.x; x++)
            {
                float left = rect.xMin + x * w;
                Handles.DrawLine(new Vector3(left, rect.yMin), new Vector3(left, rect.yMax));
            }
            Handles.color = Color.white;

            var neighbors = tilingRule.GetNeighbors();

            for (int y = bounds.yMin; y < bounds.yMax; y++)
            {
                for (int x = bounds.xMin; x < bounds.xMax; x++)
                {
                    Vector3Int pos = new Vector3Int(x, y, 0);
                    Rect r = new Rect(rect.xMin + (x - bounds.xMin) * w, rect.yMin + (-y + bounds.yMax - 1) * h, w - 1, h - 1);
                    RuleMatrixIconOnGUI(tilingRule, neighbors, pos, r);
                }
            }
        }
    public override void OnInspectorGUI()
    {
        AutoTileLookup lookup = target as AutoTileLookup;



        showBaseInspector = EditorGUILayout.Foldout(showBaseInspector, "Show Base Inspector");
        if (showBaseInspector)
        {
            base.OnInspectorGUI();
        }

        overrideRulesFromTile = EditorGUILayout.Foldout(overrideRulesFromTile, "Override Rules List");
        if (overrideRulesFromTile)
        {
            EditorGUILayout.BeginVertical(GUI.skin.box);
            {
                EditorGUILayout.LabelField(
                    "This will set the target rules for this lookup to match.  " +
                    "You don't need to use this unless you are creating a new lookup.", GUI.skin.box);

                RuleTile load = (RuleTile)EditorGUILayout.ObjectField("Load Ruleset", null, typeof(RuleTile), false);
                if (load)
                {
                    lookup.m_maskValues = load.m_TilingRules;
                }
            }
            EditorGUILayout.EndVertical();
        }

        showSubTileMapping = EditorGUILayout.Foldout(showSubTileMapping, "Show Subtile Mapping");
        if (showSubTileMapping)
        {
            EditorGUILayout.BeginVertical(GUI.skin.box);
            {
                EditorGUILayout.LabelField(
                    "This shows each Rule (set with the override tile rules parameter.)  " +
                    "Alongside each rule is the lookup data for each quadrant of the tile.", GUI.skin.box);
            }
            EditorGUILayout.EndVertical();

            SubTileMappingGUI(lookup);
        }



        EditorGUILayout.BeginVertical(GUI.skin.box);
        {
            EditorGUILayout.LabelField(
                "This will take the texture and generate " +
                "the appropriate assets + RuleTile data.", GUI.skin.box);

            Texture2D texture = (Texture2D)EditorGUILayout.ObjectField(null, typeof(Texture2D), false);
            if (texture != null)
            {
                ImportAutotile.ImportSubtile(texture, lookup);
            }
        }
        EditorGUILayout.EndVertical();
    }
    private bool IsWalkable(Vector3Int node, float ArrowAvoidance)
    {
        if (!GameRule.get.GetBounds().Contains(node))
        {
            return(false);
        }

        RuleTile tile = TileMap.GetTile <RuleTile>(node);


        if (tile == null)
        {
            return(false);
        }


        if (TileMap.GetColliderType(node) != Tile.ColliderType.None)
        {
            return(false);
        }

        if (GameRule.get.HasStatue(TileMap.GetBoundsLocal(node)))
        {
            return(false);
        }

        if (GameRule.get.NearBoomerang(node, ArrowAvoidance))
        {
            return(false);
        }

        return(true);
    }
Exemple #4
0
    void ConverteToSimpleTile(Tilemap map)
    {
        var size = map.size;

        for (int row = -size.y / 2; row < size.y; row++)
        {
            for (int col = -size.x / 2; col < size.x; col++)
            {
                var      pos     = new Vector3Int(col, row, 0);
                RuleTile oldTile = map.GetTile(pos) as RuleTile;
                if (oldTile != null)
                {
                    MockRuleTile newTile;
                    if (!old_new_Tiles.ContainsKey(oldTile))
                    {
                        newTile = new MockRuleTile(oldTile);
                        old_new_Tiles.Add(oldTile, newTile);
                    }
                    else
                    {
                        newTile = old_new_Tiles[oldTile];
                    }
                    map.SetTile(pos, newTile);
                }
            }
        }
    }
    public void OverrideRuleTile()
    {
        // Make a copy of the Rule Tile Template from a new asset.
        RuleTile _new = CreateInstance<RuleTile>();
        EditorUtility.CopySerialized(RuleTileTemplate, _new);

        // Get all the sprites in the Texture2D file (TileMap)
        string spriteSheet = AssetDatabase.GetAssetPath(TileMap);
        Sprite[] sprites = AssetDatabase.LoadAllAssetsAtPath(spriteSheet)
            .OfType<Sprite>().ToArray();

        if (sprites.Length != RuleTileTemplate.m_TilingRules.Count)
        {
            Debug.LogWarning("The Tilemap doesn't have the same number of sprites than the Rule Tile template has rules.");
        }

        // Set all the sprites of the TileMap.
        for (int i = 0; i < RuleTileTemplate.m_TilingRules.Count; i++)
        {
            _new.m_TilingRules[i].m_Sprites[0] = sprites[i];
            _new.m_DefaultSprite = sprites[24];
        }

        // Replace this Asset with the new one.
        AssetDatabase.CreateAsset(_new, AssetDatabase.GetAssetPath(this));
    }
        private static void AutogenerateTiles()
        {
            string[] actorSpriteGuids = AssetDatabase.FindAssets("t:sprite",
                                                                 new[] { "Assets/Sprites/Actor" });
            string[] itemSpriteGuids = AssetDatabase.FindAssets("t:sprite",
                                                                new[] { "Assets/Sprites/Item" });

            foreach (string guid in actorSpriteGuids)
            {
                string   path   = AssetDatabase.GUIDToAssetPath(guid);
                Sprite   sprite = AssetDatabase.LoadAssetAtPath <Sprite>(path);
                RuleTile tile   = ScriptableObject.CreateInstance <RuleTile>();
                tile.m_DefaultSprite = sprite;
                string name = sprite.name.Split('_')[1];
                AssetDatabase.CreateAsset(tile, $"Assets/Tiles/Actor/Tile_{name}.asset");
            }

            foreach (string guid in itemSpriteGuids)
            {
                string path   = AssetDatabase.GUIDToAssetPath(guid);
                Sprite sprite = AssetDatabase.LoadAssetAtPath <Sprite>(path);
                Tile   tile   = ScriptableObject.CreateInstance <Tile>();
                tile.sprite = sprite;
                string name = sprite.name.Split('_')[1];
                AssetDatabase.CreateAsset(tile, $"Assets/Tiles/Item/Tile_{name}.asset");
            }

            Debug.Log("Finished auto-generating tiles.");
        }
Exemple #7
0
 protected void PutMissileToPool()
 {
     this.gameObject.SetActive(false);
     this.gameObject.transform.parent = missilePool.transform;
     missileContainer.PutToPool(this.gameObject);
     explosionTile = Resources.Load <RuleTile>("ExplosionTile");
 }
    void OnTriggerExit2D(Collider2D other)
    {
        if (other.gameObject.tag == "Passenger" || other.gameObject.tag == "Guard" || other.gameObject.tag == "Builder" || other.gameObject.tag == "Captain")
        {
            // Incase the installed furniture has changed
            if (tileOWW.GetInstalledFurniture()?.GetFurnitureType() == "Airlock Open")
            {
                // Enable collision
                gameObject.GetComponent <NavMeshObstacle>().enabled = true;

                // Close door texure
                RuleTile t = Resources.Load <RuleTile>("TileSets/Furniture/Airlock");
                FurnitureSpriteController.Instance.tilemap.SetTile(new Vector3Int((int)gameObject.transform.position.x, (int)gameObject.transform.position.y, 0), t);

                // Block oxygen flow
                tileOWW.GetInstalledFurniture().SetFurnitureType("Airlock");
            }
            else if (tileOWW.GetInstalledFurniture()?.GetFurnitureType() == "Airlock")
            {
                // Do nothing
            }
            else
            {
                Destroy(gameObject);
            }
        }
    }
 public MapSet(Tilemap a, RuleTile b, List <Vector3Int> c, string d)
 {
     map   = a;
     tile  = b;
     seeds = c;
     name  = d;
 }
Exemple #10
0
 public void Caminho()
 {
     tmUso      = controle;
     rTUso      = linha;
     tileETexto = 0;
     deletar    = false;
     delTexto   = false;
 }
Exemple #11
0
    public MockRuleTile(RuleTile baseTile)
    {
        this.m_DefaultSprite       = baseTile.m_DefaultSprite;
        this.m_DefaultColliderType = baseTile.m_DefaultColliderType;
        this.m_TilingRules         = baseTile.m_TilingRules;

        RealTile = baseTile;
    }
        public override void OnInspectorGUI()
        {
            tile.m_DefaultSprite       = EditorGUILayout.ObjectField("Default Sprite", tile.m_DefaultSprite, typeof(Sprite), false) as Sprite;
            tile.m_DefaultGameObject   = EditorGUILayout.ObjectField("Default Game Object", tile.m_DefaultGameObject, typeof(GameObject), false) as GameObject;
            tile.m_DefaultColliderType = (Tile.ColliderType)EditorGUILayout.EnumPopup("Default Collider", tile.m_DefaultColliderType);

            serializedObject.Update();
            EditorGUI.BeginChangeCheck();
            var baseFields = typeof(RuleTile).GetFields().Select(field => field.Name);
            var fields     = target.GetType().GetFields().Select(field => field.Name).Where(field => !baseFields.Contains(field));

            foreach (var field in fields)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty(field), true);
            }
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }

            EditorGUILayout.Space();

            if (m_ReorderableList != null && tile.m_TilingRules != null)
            {
                m_ReorderableList.DoLayoutList();
            }

            //Clones a ruleset and changes its base tiles.
            if (tile.m_TilingRules.Count > 0)
            {
                tile.SpriteMapTOClone = EditorGUILayout.ObjectField("Sprite to Clone", tile.SpriteMapTOClone, typeof(Sprite), false) as Sprite;

                if (GUILayout.Button("Clone Button") && tile.SpriteMapTOClone != null)
                {
                    String   path = AssetDatabase.GetAssetPath(tile.SpriteMapTOClone);
                    Object[] data = AssetDatabase.LoadAllAssetsAtPath(path);
                    Sprite[] spritelist;
                    spritelist = Array.ConvertAll(data, item => item as Sprite);
                    RuleTile ruletile = new RuleTile();
                    AssetDatabase.CreateAsset(ruletile, "Assets/" + tile.name + "_" + (++count) + ".asset");

                    for (int i = 0; i < tile.m_TilingRules.Count; i++)
                    {
                        RuleTile.TilingRule rule = new RuleTile.TilingRule();
                        rule.m_Output       = tile.m_TilingRules[i].m_Output;
                        rule.m_Sprites[0]   = spritelist[i + 1];
                        rule.m_GameObject   = tile.m_DefaultGameObject;
                        rule.m_ColliderType = tile.m_DefaultColliderType;
                        for (int j = 0; j < tile.m_TilingRules[i].m_Neighbors.Length; j++)
                        {
                            rule.m_Neighbors[j] = tile.m_TilingRules[i].m_Neighbors[j];
                        }

                        ruletile.m_TilingRules.Add(rule);
                    }
                }
            }
        }
Exemple #13
0
 /// <summary>
 /// Updates all RuleOverrideTiles which override the given RUleTile
 /// </summary>
 /// <param name="target">RuleTile which has been updated</param>
 public static void UpdateAffectedOverrideTiles(RuleTile target)
 {
     List<RuleOverrideTile> overrideTiles = FindAffectedOverrideTiles(target);
     foreach (var overrideTile in overrideTiles)
     {
         overrideTile.Override();
         UpdateAffectedOverrideTiles(overrideTile.m_InstanceTile);
     }
 }
 private void Awake()
 {
     // Ff there is a default template, load it when the asset is created.
     RuleTileTemplate_Default = Resources.Load("AutoRuleTile_default") as RuleTile;
     if (RuleTileTemplate_Default != null)
     {
         RuleTileTemplate = RuleTileTemplate_Default;
     }
 }
Exemple #15
0
    public void Init()
    {
        string slug = "Sprites/RuleTiles/" + this.TileSlug;

        BiomeTile = Resources.Load <RuleTile>(slug);

        slug    = "Prefabs/Trees/" + this.TileSlug;
        Treefab = Resources.Load <GameObject>(slug);
    }
Exemple #16
0
 public void Direcao()
 {
     tmUso      = controle;
     tUso       = direcao0;
     rTUso      = null;
     tileETexto = 0;
     deletar    = false;
     delTexto   = false;
 }
Exemple #17
0
        private void DrawRuleMatrix(RuleTile tile, Rect rect, RuleTile.Rule rule)
        {
            var index = 0;
            var w     = rect.width / 3;
            var h     = rect.height / 3;
            var color = new Color(0, 0, 0, 0.2f);

            for (var y = 0; y <= 3; y++)
            {
                var top = rect.yMin + y * h;
                HandleHelper.DrawLine(new Vector2(rect.xMin, top), new Vector2(rect.xMax, top), color);
            }

            for (var x = 0; x <= 3; x++)
            {
                var left = rect.xMin + x * w;
                HandleHelper.DrawLine(new Vector3(left, rect.yMin), new Vector3(left, rect.yMax), color);
            }

            for (var y = 0; y <= 2; y++)
            {
                for (var x = 0; x <= 2; x++)
                {
                    var r = new Rect(rect.xMin + x * w, rect.yMin + y * h, w - 1, h - 1);

                    if (x != 1 || y != 1)
                    {
                        var currentRule = rule.Neighbors[index];

                        DrawRule(tile, r, new Vector2Int(x, y), currentRule);

                        index++;
                    }
                    else
                    {
                        if (!rule.UseReference)
                        {
                            if (rule.Tile.FlipHorizontal)
                            {
                                GUI.DrawTexture(r, RuleTileEditor.Textures[10]);
                            }

                            if (rule.Tile.FlipVertical)
                            {
                                GUI.DrawTexture(r, RuleTileEditor.Textures[11]);
                            }

                            if (rule.Tile.Rotation != 0)
                            {
                                GUI.DrawTexture(r, RuleTileEditor.Textures[5]);
                            }
                        }
                    }
                }
            }
        }
    static private void ImportWangTile()
    {
        if (Selection.objects.Length != 1)
        {
            return;
        }

        Object file = Selection.objects[0];
        string path = AssetDatabase.GetAssetPath(file);

        Object[]      spriteObjs = AssetDatabase.LoadAllAssetsAtPath(path);
        List <Sprite> sprites    = new List <Sprite>();

        for (int i = 0; i < spriteObjs.Length; i++)
        {
            try
            {
                Sprite sprite = (Sprite)spriteObjs[i];
                sprites.Add(sprite);
            }
            catch (System.Exception) { }
        }

        sprites.Sort((sprite1, sprite2) =>
        {
            int dashIndex1 = sprite1.name.LastIndexOf("_");
            int dashIndex2 = sprite2.name.LastIndexOf("_");
            int index1     = int.Parse(sprite1.name.Substring(dashIndex1 + 1));
            int index2     = int.Parse(sprite2.name.Substring(dashIndex2 + 1));

            // // return 0;
            return(index1.CompareTo(index2));
        });


        RuleTile ruleTile = ScriptableObject.CreateInstance <RuleTile>();

        ruleTile.m_DefaultSprite = sprites[0];

        for (int i = 0; i < sprites.Count; i++)
        {
            RuleTile.TilingRule rule = FindWangTileRule(i);
            if (rule != null)
            {
                rule.m_Sprites = new Sprite[] { sprites[i] };
                ruleTile.m_TilingRules.Add(rule);
            }
        }

        RuleTile.TilingRule first = ruleTile.m_TilingRules[0];
        ruleTile.m_TilingRules.RemoveAt(0);
        ruleTile.m_TilingRules.Add(first);

        AssetDatabase.CreateAsset(ruleTile, "Assets/NewWangTile.asset");
        AssetDatabase.SaveAssets();
    }
Exemple #19
0
    public void LeftClick(Vector3 position)
    {
        Vector3Int positionInt = new Vector3Int((int)position.x, (int)position.y, (int)position.z);
        RuleTile   tile        = (RuleTile)m_map.m_foregroundTilemap.GetTile(positionInt);

        if (tile != null)
        {
            Debug.Log(string.Format("Tile is: {0}", tile.GetType()));
        }
    }
        public RuleTileEditor GetSubTileEditor(int index, RuleTile tile)
        {
            if (m_SubTileEditors[index] == null)
            {
                m_SubTileEditors[index] = UnityEditor.Editor.CreateEditor(tile) as RuleTileEditor;
                m_SubTileEditors[index].m_ReorderableList.onChangedCallback += list => OnSubListUpdate(index);
            }

            return(m_SubTileEditors[index]);
        }
Exemple #21
0
 /// <summary>
 /// 加载资源
 /// </summary>
 public void InitRes()
 {
     tile0 = Resources.Load(ResModule.Instance.GetPath(ResType.Tile, IdContract.TILE_BULE).assetPath) as RuleTile;
     tile1 = Resources.Load(ResModule.Instance.GetPath(ResType.Tile, IdContract.TILE_CERULEAN).assetPath) as RuleTile;
     tile2 = Resources.Load(ResModule.Instance.GetPath(ResType.Tile, IdContract.TILE_GREEN).assetPath) as RuleTile;
     tile3 = Resources.Load(ResModule.Instance.GetPath(ResType.Tile, IdContract.TILE_ORANGE).assetPath) as RuleTile;
     tile4 = Resources.Load(ResModule.Instance.GetPath(ResType.Tile, IdContract.TILE_PURPLE).assetPath) as RuleTile;
     tile5 = Resources.Load(ResModule.Instance.GetPath(ResType.Tile, IdContract.TILE_RED).assetPath) as RuleTile;
     tile6 = Resources.Load(ResModule.Instance.GetPath(ResType.Tile, IdContract.TILE_YELLOW).assetPath) as RuleTile;
 }
Exemple #22
0
        protected override Sprite GetSprite(Vector3Int position, ITilemap tilemap)
        {
            int index = 0;

            if (sprites.Length > 1)
            {
                index = Mathf.Clamp(Mathf.FloorToInt(RuleTile.GetPerlinValue(position, perlinScale, perlinOffset) * sprites.Length), 0, sprites.Length - 1);
            }
            return(sprites[index]);
        }
Exemple #23
0
        public override void RuleMatrixOnGUI(RuleTile ruleTile, Rect rect, BoundsInt bounds,
                                             RuleTile.TilingRule tilingRule)
        {
            Handles.color = EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.2f) : new Color(0f, 0f, 0f, 0.2f);
            float w = rect.width / bounds.size.x;
            float h = rect.height / bounds.size.y;

            // Grid
            float d = rect.width / (bounds.size.x + bounds.size.y);

            for (int y = 0; y <= bounds.size.y; y++)
            {
                float left   = rect.xMin + d * y;
                float top    = rect.yMin + d * y;
                float right  = rect.xMax - d * (bounds.size.y - y);
                float bottom = rect.yMax - d * (bounds.size.y - y);
                Handles.DrawLine(new Vector3(left, bottom), new Vector3(right, top));
            }

            for (int x = 0; x <= bounds.size.x; x++)
            {
                float left   = rect.xMin + d * x;
                float top    = rect.yMax - d * x;
                float right  = rect.xMax - d * (bounds.size.x - x);
                float bottom = rect.yMin + d * (bounds.size.x - x);
                Handles.DrawLine(new Vector3(left, bottom), new Vector3(right, top));
            }

            Handles.color = Color.white;

            var neighbors = tilingRule.GetNeighbors();

            // Icons
            float iconSize  = (rect.width - d) / (bounds.size.x + bounds.size.y - 1);
            float iconScale = Mathf.Pow(2, 0.5f);

            for (int y = bounds.yMin; y < bounds.yMax; y++)
            {
                for (int x = bounds.xMin; x < bounds.xMax; x++)
                {
                    Vector3Int pos    = new Vector3Int(x, y, 0);
                    Vector3Int offset = new Vector3Int(pos.x - bounds.xMin, pos.y - bounds.yMin, 0);
                    Rect       r      = new Rect(
                        rect.xMin + rect.size.x - iconSize * (offset.y - offset.x + 0.5f + bounds.size.x),
                        rect.yMin + rect.size.y - iconSize * (offset.y + offset.x + 1.5f),
                        iconSize, iconSize
                        );
                    Vector2 center = r.center;
                    r.size  *= iconScale;
                    r.center = center;

                    RuleMatrixIconOnGUI(tilingRule, neighbors, pos, r);
                }
            }
        }
Exemple #24
0
        private void DrawRule(RuleTile tile, Rect rect, Vector2Int pos, RuleTile.NeighborType neighbor)
        {
            switch (neighbor)
            {
            case RuleTile.NeighborType.Any: break;

            case RuleTile.NeighborType.This: GUI.DrawTexture(rect, RuleTileEditor.Textures[pos.y * 3 + pos.x]); break;

            case RuleTile.NeighborType.NotThis: GUI.DrawTexture(rect, RuleTileEditor.Textures[9]); break;
            }
        }
    static void ProcessFullsizeTexture(Texture2D selectedTexture, AutoTileLookup lookup)
    {
        string assetName = selectedTexture.name;

        if (!AssetDatabase.IsValidFolder("Assets/Autotiles"))
        {
            string rootGuid = AssetDatabase.CreateFolder("Assets", "Autotiles");
        }

        string folderGuid = AssetDatabase.CreateFolder("Assets/Autotiles", assetName);

        string folderName = AssetDatabase.GUIDToAssetPath(folderGuid);

        Vector2Int TileResolution = new Vector2Int(
            selectedTexture.width / 4,
            selectedTexture.height / 6);



        AssetDatabase.Refresh();



        RuleTile m_tile = ScriptableObject.CreateInstance <RuleTile>();

        m_tile.m_TilingRules = new List <RuleTile.TilingRule>();


        int count = 0;

        for (int i = 255; i >= 0; i--)
        {
            RuleTile.TilingRule rule = GetRule(i);
            if (rule != null)
            {
                m_tile.m_TilingRules.Add(rule);
                GenerateSprites(count, TileResolution.x, selectedTexture, lookup, folderName);
                count++;
            }
        }
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();

        for (int i = 0; i < m_tile.m_TilingRules.Count; i++)
        {
            m_tile.m_TilingRules[i].m_Sprites    = new Sprite[1];
            m_tile.m_TilingRules[i].m_Sprites[0] = AssetDatabase.LoadAssetAtPath <Sprite>(folderName + "/" + selectedTexture.name + i + ".png");
        }

        AssetDatabase.CreateAsset(m_tile, folderName + "/" + assetName + "tile.asset");

        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }
Exemple #26
0
        public static void CopyAllRules(MenuCommand item)
        {
            RuleTile tile = item.context as RuleTile;
            if (tile == null)
                return;

            RuleTileRuleWrapper rulesWrapper = new RuleTileRuleWrapper();
            rulesWrapper.rules = tile.m_TilingRules;
            var rulesJson = EditorJsonUtility.ToJson(rulesWrapper);
            EditorGUIUtility.systemCopyBuffer = rulesJson;
        }
Exemple #27
0
        internal virtual void RuleMatrixOnGUI(RuleTile tile, Rect rect, Rect sibRect, RuleTile.TilingRule tilingRule)
        {
            Handles.color = EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.2f) : new Color(0f, 0f, 0f, 0.2f);
            int   index = 0;
            float w     = rect.width / 3f;
            float h     = rect.height / 3f;

            for (int y = 0; y <= 3; y++)
            {
                float top = rect.yMin + y * h;
                Handles.DrawLine(new Vector3(rect.xMin, top), new Vector3(rect.xMax, top));

                if (tilingRule.m_CheckSiblings)
                {
                    float top2 = sibRect.yMin + y * h;
                    Handles.DrawLine(new Vector3(sibRect.xMin, top2), new Vector3(sibRect.xMax, top2));
                }
            }
            for (int x = 0; x <= 3; x++)
            {
                float left = rect.xMin + x * w;
                Handles.DrawLine(new Vector3(left, rect.yMin), new Vector3(left, rect.yMax));
                if (tilingRule.m_CheckSiblings)
                {
                    float left2 = sibRect.xMin + x * w;
                    Handles.DrawLine(new Vector3(left2, sibRect.yMin), new Vector3(left2, sibRect.yMax));
                }
            }
            Handles.color = Color.white;

            for (int y = 0; y <= 2; y++)
            {
                for (int x = 0; x <= 2; x++)
                {
                    Rect r  = new Rect(rect.xMin + x * w, rect.yMin + y * h, w - 1, h - 1);
                    Rect r2 = new Rect(sibRect.xMin + x * w, sibRect.yMin + y * h, w - 1, h - 1);
                    if (x != 1 || y != 1)
                    {
                        RuleOnGUI(r, y * 3 + x, tilingRule.m_Neighbors[index]);
                        RuleOnGUI(r2, y * 3 + x, tilingRule.m_SiblingNeighbors[index]);
                        RuleNeighborUpdate(r, r2, tilingRule, index);

                        index++;
                    }
                    else
                    {
                        RuleTransformOnGUI(r, tilingRule.m_RuleTransform);
                        RuleTransformOnGUI(r2, tilingRule.m_RuleTransform);
                        RuleTransformUpdate(r, r2, tilingRule);
                    }
                }
            }
        }
    void CreateRooms()
    {
        roomsNumber = dungeon.roomsNumber;
        roomSize    = dungeon.roomSize;
        bridgeTile  = dungeon.bridgeTile;
        groundTile  = dungeon.groundTile;
        barrelTile  = dungeon.barrelTile;
        chestTile   = dungeon.chestTile;
        barrelRate  = dungeon.barrelsRate;
        chestRate   = dungeon.chestRate;

        // svuota la tilemap
        ClearTilemaps();
        roomsCreated = 0;

        Vector3Int roomPosition = Vector3Int.zero;

        for (int i = 0; i < roomsNumber; i++)
        {
            counter = 0;
            CreateRoom(roomPosition);
            roomsPositions.Add(roomPosition);

            int direction;

            // non deve creare il passaggio nell'ultima stanza
            if (i != roomsNumber - 1)
            {
                bool isEmpty;
                do
                {
                    direction = Random.Range(0, 4);
                    isEmpty   = EmptySpot(roomPosition, direction);
                    counter++;
                }while ((isEmpty == false) && (counter <= 20));

                Debug.Log("Direction: " + direction + " , Empty: " + isEmpty);
                if (counter == 20)
                {
                    i = roomsNumber;
                    Debug.Log("Dead End");
                }
                else
                {
                    CreatePassage(roomPosition, direction);
                    roomPosition = GetNewPosition(roomPosition, direction);
                }
            }
            roomsCreated++;
        }
        Debug.Log("Rooms Created: " + roomsCreated);
    }
Exemple #29
0
    private void Populate_World(int birth_amount, RuleTile place_tile)
    {
        List <Vector3Int> birth_list = new List <Vector3Int>();

        // Birth or death the cells depending on neighbours
        for (int i = 0; i < world_size.x * 10; i++)
        {
            for (int j = 0; j < world_size.y * 10; j++)
            {
                if ((i != 0) && (j != 0) && (i + 1 != world_size.x * 10) && (j + 1 != world_size.y * 10))
                {
                    Vector3Int target_pos = new Vector3Int(i, j, 0);

                    List <Vector3Int> neighbours = new List <Vector3Int>();

                    neighbours.Add(target_pos + new Vector3Int(1, 0, 0));
                    neighbours.Add(target_pos + new Vector3Int(-1, 0, 0));
                    neighbours.Add(target_pos + new Vector3Int(0, 1, 0));
                    neighbours.Add(target_pos + new Vector3Int(0, -1, 0));
                    neighbours.Add(target_pos + new Vector3Int(1, 1, 0));
                    neighbours.Add(target_pos + new Vector3Int(-1, 1, 0));
                    neighbours.Add(target_pos + new Vector3Int(1, -1, 0));
                    neighbours.Add(target_pos + new Vector3Int(-1, -1, 0));

                    int neighbour_count = 0;

                    foreach (var neighbour_check in neighbours)
                    {
                        if (Get_Tile(neighbour_check) != null)
                        {
                            neighbour_count++;
                        }
                    }



                    if ((neighbour_count >= birth_amount) && (Get_Tile(target_pos) != null))
                    {
                        birth_list.Add(target_pos);
                    }
                }
            }
        }


        foreach (var birth_pos in birth_list)
        {
            Add_Tile(birth_pos, place_tile);
            //dungeon_walls.SetTile(birth_pos, place_tile);
            //yield return null;
        }
    }
        internal override void RuleMatrixOnGUI(RuleTile ruleTile, Rect rect, RuleTile.TilingRule tilingRule)
        {
            var isoTile = (IsometricRuleTile)ruleTile;

            Handles.color = EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.2f) : new Color(0f, 0f, 0f, 0.2f);
            int   index = 0;
            float w     = rect.width / 3f;
            float h     = rect.height / 3f;

            // Grid
            for (int y = 0; y <= 3; y++)
            {
                float left   = rect.xMin + (y * rect.width) / 6;
                float right  = left + rect.width / 2;
                float bottom = rect.yMin + (y * rect.height) / 6;
                float top    = bottom + rect.height / 2;
                Handles.DrawLine(new Vector3(left, top), new Vector3(right, bottom));
            }
            for (int x = 0; x <= 3; x++)
            {
                float left   = rect.xMin + (x * rect.width) / 6;
                float right  = left + rect.width / 2;
                float top    = rect.yMax - (x * rect.height) / 6;
                float bottom = top - rect.height / 2;
                Handles.DrawLine(new Vector3(left, bottom), new Vector3(right, top));
            }
            Handles.color = Color.white;

            // Icons
            for (int y = 0; y <= 2; y++)
            {
                for (int x = 0; x <= 2; x++)
                {
                    Rect r = new Rect(
                        rect.xMin + ((x + y) * rect.width) / 6,
                        rect.yMin + ((2 - x + y) * rect.height) / 6,
                        w - 1, h - 1);
                    if (x != 1 || y != 1)
                    {
                        RuleOnGUI(r, s_Arrows[y, x], tilingRule.m_Neighbors[index]);
                        RuleNeighborUpdate(r, tilingRule, index);

                        index++;
                    }
                    else
                    {
                        RuleTransformOnGUI(r, tilingRule.m_RuleTransform);
                        RuleTransformUpdate(r, tilingRule);
                    }
                }
            }
        }