Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ MonoBehaviour:
_syncedConnections: 0
wallCapPrefab: {fileID: 3591147544166670882, guid: 9682b163cae64f74a93b6e84ce84ae5b, type: 3}
doorType: 0
airlockFloorPrefab: {fileID: 6767447678079105841, guid: 778e6f90a9ad89d4b856955961745b56, type: 3}
transparentFloorMaterial: {fileID: 2100000, guid: 11367021fd2c47deaef924f68d3e7d29, type: 2}
--- !u!95 &6205019768642409540
Animator:
serializedVersion: 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ MonoBehaviour:
_syncedConnections: 0
wallCapPrefab: {fileID: 3591147544166670882, guid: 9682b163cae64f74a93b6e84ce84ae5b, type: 3}
doorType: 0
airlockFloorPrefab: {fileID: 6767447678079105841, guid: 778e6f90a9ad89d4b856955961745b56, type: 3}
transparentFloorMaterial: {fileID: 2100000, guid: 11367021fd2c47deaef924f68d3e7d29, type: 2}
--- !u!114 &-2593019434011219120
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: AirlockTransparentFloor
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ValidKeywords:
- _ALPHABLEND_ON
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
disabledShaderPasses: []
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BumpMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailAlbedoMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailMask:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DetailNormalMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _EmissionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _OcclusionMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _ParallaxMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _BumpScale: 1
- _Cutoff: 0.5
- _DetailNormalMapScale: 1
- _DstBlend: 10
- _GlossMapScale: 1
- _Glossiness: 0.1
- _GlossyReflections: 1
- _Metallic: 0
- _Mode: 3
- _OcclusionStrength: 1
- _Parallax: 0.02
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 5
- _UVSec: 0
- _ZWrite: 0
m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 0}

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
Expand Up @@ -6,6 +6,7 @@
using SS3D.Logging;
using SS3D.Systems.Furniture;
using SS3D.Systems.Inventory.Containers;
using System;
using UnityEngine;

namespace SS3D.Systems.Inventory.Interactions
Expand Down Expand Up @@ -81,4 +82,4 @@ public bool Start(InteractionEvent interactionEvent, InteractionReference refere
return true;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@

using System.Collections.Generic;
using UnityEngine;
using SS3D.Systems.Tile.Connections.AdjacencyTypes;
using Coimbra;
using FishNet.Object;
using SS3D.Core;

namespace SS3D.Systems.Tile.Connections
{
/// <summary>
/// Connector for doors, handling adding wall caps, creating custom floor tile under the door.
/// TODO : add the custom floor.
/// </summary>
public class DoorAdjacencyConnector : AbstractHorizontalConnector, IAdjacencyConnector
{
Expand All @@ -32,21 +33,98 @@ private enum DoorType
[SerializeField]
private DoorType doorType;

[SerializeField]
private GameObject airlockFloorPrefab = null;

[SerializeField]
private Material transparentFloorMaterial = null;

// WallCap gameobjects, North, East, South, West. Null if not present.
private GameObject[] wallCaps = new GameObject[4];

private GameObject _airlockFloor;

public override void OnStartClient()
{
base.OnStartClient();
RefreshAirlockFloorTiles();
}

private void Start()
{
RefreshAirlockFloorTiles();
}

public override bool UpdateSingleConnection(Direction dir, PlacedTileObject placedObject, bool updateNeighbours)
{
bool update = base.UpdateSingleConnection(dir, placedObject, updateNeighbours);
if (update)
UpdateWallCaps();

RefreshAirlockFloorTiles();

return update;
}

public override void UpdateAllConnections()
{
base.UpdateAllConnections();
UpdateWallCaps();
RefreshAirlockFloorTiles();
}

public void RefreshAirlockFloorTiles()
{
if (_placedObject == null)
{
return;
}

if (!TryGetAirlockFloorNeighbours(out List<PlacedTileObject> neighbours))
{
return;
}

GameObject floorTile = GetOrCreateAirlockFloor();
if (floorTile == null)
{
return;
}

MeshRenderer activeFloorRenderer = GetActiveAirlockFloorRenderer(floorTile);
if (activeFloorRenderer == null)
{
return;
}

_placedObject.HasNeighbourFrontBack(neighbours, out PlacedTileObject frontTile, true);
_placedObject.HasNeighbourFrontBack(neighbours, out PlacedTileObject backTile, false);

SetRendererMaterial(activeFloorRenderer, 0, GetFloorMaterialOrDefault(frontTile, transparentFloorMaterial));
SetRendererMaterial(activeFloorRenderer, 1, GetFloorMaterialOrDefault(backTile, transparentFloorMaterial));
}

private bool TryGetAirlockFloorNeighbours(out List<PlacedTileObject> floorNeighbours)
{
floorNeighbours = new List<PlacedTileObject>();
if (!SubSystems.TryGet(out TileSubSystem tileSystem) || tileSystem.CurrentMap == null)
{
return false;
}

PlacedTileObject[] neighbours = tileSystem.CurrentMap.GetNeighbourPlacedObjects(
TileLayer.Turf,
_placedObject.gameObject.transform.position);

foreach (PlacedTileObject neighbour in neighbours)
{
if (neighbour != null)
{
floorNeighbours.Add(neighbour);
}
}

return true;
}

/// <summary>
Expand Down Expand Up @@ -106,6 +184,99 @@ public override bool IsConnected(PlacedTileObject neighbourObject)
neighbourObject.GenericType == TileObjectGenericType.Wall);
}

private GameObject GetOrCreateAirlockFloor()
{
if (_airlockFloor != null)
{
return _airlockFloor;
}

if (airlockFloorPrefab == null)
{
return null;
}

_airlockFloor = Instantiate(airlockFloorPrefab, transform);
_airlockFloor.name = "AirlockFloorTile";
_airlockFloor.transform.localPosition = Vector3.zero;
_airlockFloor.transform.localRotation = Quaternion.identity;
_airlockFloor.transform.localScale = Vector3.one;
RemoveTileRuntimeComponents(_airlockFloor);

return _airlockFloor;
}

private void RemoveTileRuntimeComponents(GameObject floorTile)
{
foreach (Collider collider in floorTile.GetComponents<Collider>())
{
Destroy(collider);
}

foreach (MonoBehaviour component in floorTile.GetComponents<MonoBehaviour>())
{
Destroy(component);
}
}

private MeshRenderer GetActiveAirlockFloorRenderer(GameObject floorTile)
{
bool doorRunsNorthSouth = IsNorthSouth(_placedObject.Direction);
Transform northSouthTile = floorTile.transform.Find("AirlockTileNS");
Transform eastWestTile = floorTile.transform.Find("AirlockTileEW");

if (northSouthTile != null)
{
northSouthTile.gameObject.SetActive(doorRunsNorthSouth);
}

if (eastWestTile != null)
{
eastWestTile.gameObject.SetActive(!doorRunsNorthSouth);
}

Transform activeTile = doorRunsNorthSouth ? northSouthTile : eastWestTile;
return activeTile != null ? activeTile.GetComponent<MeshRenderer>() : null;
}

public static bool IsNorthSouth(Direction direction)
{
return direction == Direction.North || direction == Direction.South;
}

public static Material GetFloorMaterialOrDefault(PlacedTileObject tileObject, Material defaultMaterial)
{
if (tileObject == null || tileObject.GenericType != TileObjectGenericType.Floor)
{
return defaultMaterial;
}

MeshRenderer floorRenderer = tileObject.GetComponentInChildren<MeshRenderer>();
if (floorRenderer == null || floorRenderer.sharedMaterials.Length == 0)
{
return defaultMaterial;
}

return floorRenderer.sharedMaterials[0] ?? defaultMaterial;
}

public static void SetRendererMaterial(MeshRenderer renderer, int materialIndex, Material material)
{
if (renderer == null || material == null)
{
return;
}

Material[] materials = renderer.sharedMaterials;
if (materialIndex < 0 || materialIndex >= materials.Length)
{
return;
}

materials[materialIndex] = material;
renderer.sharedMaterials = materials;
}

/// <summary>
/// Get the index of a wallcap in the wallcap Array.
/// </summary>
Expand Down
Loading
Loading