forked from RE-SS3D/SS3D
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
108 additions
and
87 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
Assets/Scripts/SS3D/Systems/Tile/TileMapCreator/BuildGhost.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using SS3D.Data; | ||
using SS3D.Data.Enums; | ||
using SS3D.Systems.Tile; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace SS3D.Systems.Tile.TileMapCreator | ||
{ | ||
|
||
public enum BuildMatMode | ||
{ | ||
Valid, | ||
Invalid, | ||
Delete | ||
} | ||
|
||
public class BuildGhost | ||
{ | ||
public GameObject ghost; | ||
public Vector3 position; | ||
public Direction direction; | ||
|
||
public BuildGhost(GameObject ghostObject, Vector3 targetPosition, Direction dir) | ||
{ | ||
ghost = ghostObject; | ||
position = targetPosition; | ||
direction = dir; | ||
} | ||
|
||
/// <summary> | ||
/// 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) | ||
{ | ||
Material ghostMat = null; | ||
|
||
switch (mode) | ||
{ | ||
case BuildMatMode.Valid: | ||
ghostMat = Assets.Get<Material>((int)AssetDatabases.Materials, (int)MaterialsIds.ValidConstruction); | ||
break; | ||
|
||
case BuildMatMode.Invalid: | ||
ghostMat = Assets.Get<Material>((int)AssetDatabases.Materials, (int)MaterialsIds.InvalidConstruction); | ||
break; | ||
|
||
case BuildMatMode.Delete: | ||
ghostMat = Assets.Get<Material>((int)AssetDatabases.Materials, (int)MaterialsIds.DeleteConstruction); | ||
break; | ||
} | ||
|
||
|
||
foreach (MeshRenderer mr in ghost.GetComponentsInChildren<MeshRenderer>()) | ||
{ | ||
Material[] materials = mr.materials; | ||
for (int i = 0; i < materials.Length; i++) | ||
{ | ||
materials[i] = ghostMat; | ||
} | ||
|
||
mr.materials = materials; | ||
} | ||
} | ||
|
||
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); | ||
} | ||
|
||
public void SetNextRotation() | ||
{ | ||
if (ghost.TryGetComponent(out ICustomGhostRotation customRotationComponent)) | ||
{ | ||
direction = customRotationComponent.GetNextDirection(direction); | ||
} | ||
else | ||
{ | ||
direction = TileHelper.GetNextCardinalDir(direction); | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/Scripts/SS3D/Systems/Tile/TileMapCreator/BuildGhost.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters