using System;
using System.Collections.Generic;
using UnityEngine;
namespace DunGen
{
///
/// A description of the layout of a dungeon
///
[Serializable]
[CreateAssetMenu(fileName = "New Archetype", menuName = "DunGen/Dungeon Archetype", order = 700)]
public sealed class DungeonArchetype : ScriptableObject, ISerializationCallbackReceiver
{
#region Legacy Properties
[Obsolete("StraightenChance is deprecated. Use StraighteningSettings instead")]
public float StraightenChance = 0.0f;
#endregion
public static int CurrentFileVersion = 1;
///
/// A collection of tile sets from which rooms will be selected to fill the dungeon
///
public List TileSets = new List();
///
/// A collection of tile sets that can be used at the start of branch paths
///
public List BranchStartTileSets = new List();
///
/// Defines how the TileSets and BranchStartTileSets are used when placing rooms at the beginning of a branch
///
public BranchCapType BranchStartType = BranchCapType.InsteadOf;
///
/// A collection of tile sets that can be used at the end of branch paths
///
public List BranchCapTileSets = new List();
///
/// Defines how the TileSets and BranchEndTileSets are used when placing rooms at the end of a branch
///
public BranchCapType BranchCapType = BranchCapType.AsWellAs;
///
/// The maximum depth (in tiles) that any branch in the dungeon can be
///
public IntRange BranchingDepth = new IntRange(2, 4);
///
/// The maximum number of branches each room can have
///
public IntRange BranchCount = new IntRange(0, 2);
///
/// The chance that this archetype will produce a straight section for the main path
///
public PathStraighteningSettings StraighteningSettings = new PathStraighteningSettings();
///
/// Should DunGen attempt to prevent this archetype from appearing more than once throughout the dungeon layout?
///
public bool Unique = false;
[SerializeField]
private int fileVersion = 0;
public bool GetHasValidBranchStartTiles()
{
if (BranchStartTileSets.Count == 0)
return false;
foreach (var tileSet in BranchStartTileSets)
if (tileSet.TileWeights.Weights.Count > 0)
return true;
return false;
}
public bool GetHasValidBranchCapTiles()
{
if (BranchCapTileSets.Count == 0)
return false;
foreach (var tileSet in BranchCapTileSets)
if (tileSet.TileWeights.Weights.Count > 0)
return true;
return false;
}
#region ISerializationCallbackReceiver Implementation
public void OnBeforeSerialize()
{
}
public void OnAfterDeserialize()
{
if (this == null)
return;
bool isDirty = false;
// Upgrade to StraighteningSettings
if (fileVersion < 1)
{
if (StraighteningSettings == null)
StraighteningSettings = new PathStraighteningSettings();
#pragma warning disable 0618
if (StraightenChance > 0.0f)
{
StraighteningSettings.StraightenChance = Mathf.Clamp01(StraightenChance);
StraighteningSettings.OverrideStraightenChance = true;
}
#pragma warning restore 0618
fileVersion = 1;
isDirty = true;
}
#if UNITY_EDITOR
// Schedule to mark dirty & save
if (isDirty)
{
UnityEditor.EditorApplication.delayCall += () =>
{
UnityEditor.EditorUtility.SetDirty(this);
UnityEditor.AssetDatabase.SaveAssetIfDirty(this);
};
}
#endif
}
#endregion
}
public enum BranchCapType : byte
{
InsteadOf,
AsWellAs,
}
}