Skip to content

Commit

Permalink
remove unnecessary rootgenconfig parameter. refactor HexGridCamera.At…
Browse files Browse the repository at this point in the history
…tachCamera parameter to support lack of RootGenConfig
  • Loading branch information
jordanstudioroot committed Jul 1, 2020
1 parent 079db56 commit 467e2ea
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 30 deletions.
29 changes: 17 additions & 12 deletions Assets/rootgen-unitycsharp/Runtime/Camera/HexGridCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,15 @@ public bool SuspendInput {
// ~ Non-Static

// ~~ public
public static void AttachCamera(HexMap grid, float hexOuterRadius) {

public static void AttachCamera(HexMap map, float hexSize) {
HexGridCamera resultMono;
_hexOuterRadius = hexOuterRadius;
_hexOuterRadius = hexSize;

if (InstanceValidation.InstanceExists<HexGridCamera>()) {
resultMono = InstanceValidation.GetFirstInstance<HexGridCamera>();
resultMono.transform.SetParent(grid.transform, false);
resultMono.TargetGrid = grid;
resultMono.transform.SetParent(map.transform, false);
resultMono.TargetGrid = map;
resultMono.enabled = true;
if (InstanceValidation.SingleInstanceExists<HexGridCamera>()) {
RootLog.Log(
Expand All @@ -212,8 +213,8 @@ public static void AttachCamera(HexMap grid, float hexOuterRadius) {
else {
GameObject resultObj = new GameObject("HexGridCamera");
resultMono = resultObj.AddComponent<HexGridCamera>();
resultMono.transform.SetParent(grid.transform, false);
resultMono.TargetGrid = grid;
resultMono.transform.SetParent(map.transform, false);
resultMono.TargetGrid = map;
resultMono.enabled = true;

GameObject swivelObj = new GameObject("Swivel");
Expand Down Expand Up @@ -241,19 +242,23 @@ public static void AttachCamera(HexMap grid, float hexOuterRadius) {
cameraMono.farClipPlane = 1000f;
cameraMono.depth = -1f;

resultMono.transform.SetParent(grid.transform, false);
resultMono.transform.SetParent(map.transform, false);

if (grid.GridCenter) {
if (map.GridCenter) {
resultMono.SetPosition(
grid,
grid.GridCenter.transform.position.x,
grid.GridCenter.transform.position.z,
hexOuterRadius
map,
map.GridCenter.transform.position.x,
map.GridCenter.transform.position.z,
_hexOuterRadius
);
}
}
}

public static void AttachCamera(HexMap grid, RootGenConfig config) {
AttachCamera(grid, config.hexSize);
}

public void ValidatePosition(HexMap grid, float hexOuterRadius) {
AdjustPosition(grid, 0, 0, hexOuterRadius);
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/rootgen-unitycsharp/Runtime/Core/MapGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class MapGenerator {
/// </returns>
public HexMap GenerateMap(
RootGenConfig config,
bool editMode
bool editMode = true
) {
string diagnostics = "Generate Map Performance Diagnostics\n\n";

Expand Down
7 changes: 3 additions & 4 deletions Assets/rootgen-unitycsharp/Runtime/Core/RootGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,15 @@ public RootGen() {
/// </returns>
public HexMap GenerateMap(
RootGenConfig config,
bool editMode
bool editMode = true
) {
Destroy.DestroyAll<HexMap>();

HexMap result = _mapGenerator.GenerateMap(
config,
editMode
config
);

HexGridCamera.AttachCamera(result, config.hexSize);
HexGridCamera.AttachCamera(result, config);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void OnEnable() {
// Start is called before the first frame update
void Start() {
if (config) {
_hexMap = _rootGen.GenerateMap(config, true);
_hexMap = _rootGen.GenerateMap(config);
_hexMap.Draw(config.hexSize);
}
else {
Expand All @@ -34,7 +34,7 @@ void Update()
{
if (Input.GetKeyUp(KeyCode.R)) {
if (config) {
_hexMap = _rootGen.GenerateMap(config, true);
_hexMap = _rootGen.GenerateMap(config);
_hexMap.Draw(config.hexSize);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ public class RootGenConfig : ScriptableObject
[Range(0f, 1f)]
public float startingMoisture = 0.1f;

[Range(0, 20)]
public int riverPercentage = 10;

[Range(0f, 1f)]
public float extraLakeProbability = 0.25f;

Expand Down
8 changes: 0 additions & 8 deletions Assets/rootgen-unitycsharp/Tests.meta

This file was deleted.

0 comments on commit 467e2ea

Please sign in to comment.