Skip to content

Commit

Permalink
clean up, doc and renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
stilnat committed Nov 24, 2023
1 parent 0a07099 commit bd321f5
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 104 deletions.
13 changes: 13 additions & 0 deletions Assets/Scripts/SS3D/Systems/Tile/TileMapCreator/BuildMatMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace SS3D.Systems.Tile.TileMapCreator
{
public enum BuildMatMode
{
Valid,
Invalid,
Delete
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
using Coimbra;
using SS3D.Data;
using SS3D.Data.Enums;
using SS3D.Systems.Tile;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace SS3D.Systems.Tile.TileMapCreator
{

public enum BuildMatMode
/// <summary>
/// Represent a hologram tile object used for construction, through the tilemap menu.
/// </summary>
public class ConstructionHologram
{
Valid,
Invalid,
Delete
}

public class BuildGhost
{
private GameObject _ghost;
private GameObject _hologram;
private Vector3 _position;
private Direction _direction;

public Direction Direction => _direction;

public bool ActiveSelf => _ghost.activeSelf;
public bool ActiveSelf => _hologram.activeSelf;

public bool SetActive { set => _ghost.SetActive(value); }
public bool SetActive { set => _hologram.SetActive(value); }

public Vector3 Position { get => _position; set => _position = value; }


public BuildGhost(GameObject ghostObject, Vector3 targetPosition, Direction dir)
/// <summary>
/// Build a new hologram
/// </summary>
/// <param name="ghostObject"> the game object we want to make a hologram from.</param>
/// <param name="targetPosition"> the initial position of the hologram in space.</param>
/// <param name="dir"> the expected original direction. Note that not all directions are compatible with
/// all tile objects. If it's not, it will choose another available direction.</param>
public ConstructionHologram(GameObject ghostObject, Vector3 targetPosition, Direction dir)
{
_ghost = ghostObject;
_hologram = ghostObject;
_position = targetPosition;
_direction = dir;

Expand All @@ -60,7 +60,7 @@ public BuildGhost(GameObject ghostObject, Vector3 targetPosition, Direction dir)
/// Chooses which material to set on the ghost based on which mode we are building.
/// </summary>
/// <param name="mode"></param>
public void ChangeGhostColor(BuildMatMode mode)
public void ChangeHologramColor(BuildMatMode mode)
{
Material ghostMat = null;

Expand All @@ -80,7 +80,7 @@ public void ChangeGhostColor(BuildMatMode mode)
}


foreach (MeshRenderer mr in _ghost.GetComponentsInChildren<MeshRenderer>())
foreach (MeshRenderer mr in _hologram.GetComponentsInChildren<MeshRenderer>())
{
Material[] materials = mr.materials;
for (int i = 0; i < materials.Length; i++)
Expand All @@ -92,16 +92,22 @@ public void ChangeGhostColor(BuildMatMode mode)
}
}

/// <summary>
/// Smoothly change rotation and position for better visual effects.
/// </summary>
public void UpdateRotationAndPosition()
{
// Small offset is added so that meshes don't overlap with already placed objects.
_ghost.transform.position = Vector3.Lerp(_ghost.transform.position, _position + new Vector3(0, 0.1f, 0), Time.deltaTime * 15f);
_ghost.transform.rotation = Quaternion.Lerp(_ghost.transform.rotation, Quaternion.Euler(0, TileHelper.GetRotationAngle(_direction), 0), Time.deltaTime * 15f);
_hologram.transform.position = Vector3.Lerp(_hologram.transform.position, _position + new Vector3(0, 0.1f, 0), Time.deltaTime * 15f);
_hologram.transform.rotation = Quaternion.Lerp(_hologram.transform.rotation, Quaternion.Euler(0, TileHelper.GetRotationAngle(_direction), 0), Time.deltaTime * 15f);
}

/// <summary>
/// Set the next allowed rotation, depends on the tile object.
/// </summary>
public void SetNextRotation()
{
if (_ghost.TryGetComponent(out ICustomGhostRotation customRotationComponent))
if (_hologram.TryGetComponent(out ICustomGhostRotation customRotationComponent))
{
_direction = customRotationComponent.GetNextDirection(_direction);
}
Expand All @@ -113,7 +119,7 @@ public void SetNextRotation()

public void Destroy()
{
_ghost.Dispose(true);
_hologram.Dispose(true);
}
}
}
Loading

0 comments on commit bd321f5

Please sign in to comment.