Skip to content
Open
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

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

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

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

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

103 changes: 103 additions & 0 deletions Assets/MenuUi/Scripts/SoulHome/FurnitureHandling.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using System.Collections;
using System.Collections.Generic;
using Altzone.Scripts.Model.Poco.Game;
using UnityEditor.Graphs;
using UnityEngine;
using UnityEngine.InputSystem.XR;
using UnityEngine.Rendering;
using Debug = Prg.Debug;

namespace MenuUI.Scripts.SoulHome
{


public class FurnitureHandling : MonoBehaviour
{
public enum Direction
Expand All @@ -16,6 +20,11 @@ public enum Direction
Right,
Back
}
public enum InteractionPattern
{
Surround, // All surrounding slots
FrontRow, // All slots along the "front" width
}

[SerializeField]
private string _name;
Expand All @@ -39,6 +48,7 @@ public enum Direction
[SerializeField]
private SortingGroup _sortingGroup;


private Furniture _furniture;
[SerializeField]
private GameObject _trayFurnitureObject;
Expand All @@ -50,6 +60,95 @@ public enum Direction
private FurnitureSlot _slot;
private FurnitureSlot _tempSlot;

[SerializeField]
private bool _hasInteractionSlot = false;
private Vector2Int _interactionOffset = new Vector2Int(0, 1);
public bool HasInteractionSlot => _hasInteractionSlot;

//[SerializeField] public InteractionPattern Pattern = InteractionPattern.FrontRow;
public List<FurnitureSlot> AssignedInteractionSlots { get; private set; } = new List<FurnitureSlot>();

[HideInInspector]
public List<Vector2Int> customInteractionOffsets = new List<Vector2Int>();

[Header("Dimensions (Edit Mode Configurations)")]
[SerializeField] private int _width = 1;
[SerializeField] private int _height = 1;

public int Width => _width;
public int Height => _height;

public void ClearInteractionSlots()
{
foreach (var slot in AssignedInteractionSlots)
{
slot.IsReserved = false;
slot.InteractionOwner = null;
slot.ClearValidity();
}
AssignedInteractionSlots.Clear();
}

public void AddInteractionSlot(FurnitureSlot slot)
{
if (!AssignedInteractionSlots.Contains(slot))
{
slot.IsReserved = true;
AssignedInteractionSlots.Add(slot);
}
}

//Get closest interaction slot for npc to path to
public FurnitureSlot GetClosestInteractionSlot(Vector3 npcPosition)
{
if (AssignedInteractionSlots == null || AssignedInteractionSlots.Count == 0)
return null;

FurnitureSlot closest = null;
float minDistance = float.MaxValue;

foreach (var slot in AssignedInteractionSlots)
{
float dist = Vector3.Distance(npcPosition, slot.transform.position);
if (dist < minDistance)
{
minDistance = dist;
closest = slot;
}
}
return closest;
}

public void StartInteract(SoulHomeAvatarController controller)
{
StartCoroutine(InteractRoutine(controller));
}

private IEnumerator InteractRoutine(SoulHomeAvatarController controller)
{
GameObject original = controller.gameObject;
original.SetActive(false);

GameObject dummy = Instantiate(original);
dummy.SetActive(true);

dummy.transform.SetParent(this.transform, true);
dummy.transform.localPosition = Vector3.zero;

Animator dummyAnim = dummy.GetComponentInChildren<Animator>();
//dummyAnim.Play("");

//yield return new WaitForEndOfFrame(); // Wait for animator to update
//float animLength = dummyAnim.GetCurrentAnimatorStateInfo(0).length;
//yield return new WaitForSeconds(animLength);

//Temporary
yield return new WaitForSeconds(10);

Destroy(dummy);
original.SetActive(true);
}

public Furniture Furniture { get => _furniture; set => _furniture = value; }
public Vector2 Position { get => _position; set => _position = value; }
public FurnitureSlot Slot { get => _slot;
Expand Down Expand Up @@ -126,6 +225,10 @@ void Start()

public Vector3Int GetFurnitureSize()
{
if (Furniture == null)
{
return new Vector3Int(_width, _height, 0);
}
if (Furniture.IsRotated) return Furniture.GetFurnitureSizeRotated();
return Furniture.GetFurnitureNormalSize();
}
Expand Down
83 changes: 83 additions & 0 deletions Assets/MenuUi/Scripts/SoulHome/FurnitureInteractionCustomEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using MenuUI.Scripts.SoulHome;
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(FurnitureHandling))]
public class FurnitureInteractionCustomEditor : Editor
{
private SerializedProperty widthProp;
private SerializedProperty heightProp;

private void OnEnable()
{
widthProp = serializedObject.FindProperty("_width");
heightProp = serializedObject.FindProperty("_height");
}
public override void OnInspectorGUI()
{
DrawDefaultInspector();
serializedObject.Update();

FurnitureHandling script = (FurnitureHandling)target;

if (widthProp.intValue < 1) widthProp.intValue = 1;
if (heightProp.intValue < 1) heightProp.intValue = 1;

GUILayout.Space(15);
EditorGUILayout.HelpBox("GREEN = Furniture Body (Size)\nYELLOW = Interaction Slots", MessageType.Info);
GUILayout.Label("Custom Interaction Pattern (Front View)", EditorStyles.boldLabel);

int width = widthProp.intValue;
int height = heightProp.intValue;

if (width <= 0 || height <= 0)
{
EditorGUILayout.HelpBox($"Size is 0 or negative.", MessageType.Warning);
return;
}

for (int y = 1; y >= -height; y--)
{
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();

for (int x = -1; x <= width; x++)
{
Vector2Int pos = new Vector2Int(x, y);

bool isInteraction = script.customInteractionOffsets.Contains(pos);
bool isFurnitureBody = (x >= 0 && x < width && y <= 0 && y > -height);

if (isFurnitureBody) GUI.backgroundColor = Color.green;
else if (isInteraction) GUI.backgroundColor = Color.yellow;
else GUI.backgroundColor = Color.white;

string buttonText = isFurnitureBody ? "F" : (isInteraction ? "I" : "");

if (GUILayout.Button(buttonText, GUILayout.Width(30), GUILayout.Height(30)))
{
if (!isFurnitureBody)
{
Undo.RecordObject(script, "Modify Custom Interaction Slot");
if (isInteraction) script.customInteractionOffsets.Remove(pos);
else script.customInteractionOffsets.Add(pos);

EditorUtility.SetDirty(script);
}
}
GUI.backgroundColor = Color.white;
}
GUILayout.FlexibleSpace();
EditorGUILayout.EndHorizontal();
}

if (GUILayout.Button("Clear Pattern"))
{
Undo.RecordObject(script, "Clear Interaction Pattern");
script.customInteractionOffsets.Clear();
EditorUtility.SetDirty(script);
}

serializedObject.ApplyModifiedProperties();
}
}

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

14 changes: 12 additions & 2 deletions Assets/MenuUi/Scripts/SoulHome/FurnitureSlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public class FurnitureSlot : MonoBehaviour

[SerializeField] private SpriteRenderer _slotValidityIndicator;

public bool IsReserved { get; set; }

public FurnitureHandling InteractionOwner;
public FurnitureHandling SlotOwner;

public Furniture Furniture { get => furniture;
set
{
Expand Down Expand Up @@ -82,9 +87,14 @@ public void InitializeSlot(int row, int column, int id, FurnitureGrid furnitureG
_slotValidityIndicator.sortingOrder = id*1000 + 901;
}

public void SetValidity(bool validity)
public void SetValidity(bool validity, bool isInteractSlot = false)
{
if (validity)
if (isInteractSlot)
{

_slotValidityIndicator.color = new Color(1, 1, 0, 0.3f); //Yellow
}
else if (validity)
{
_slotValidityIndicator.color = new Color(0,1,0, 0.3f);
}
Expand Down
10 changes: 10 additions & 0 deletions Assets/MenuUi/Scripts/SoulHome/RoomData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1193,5 +1193,15 @@ public void ResetPosition(GameObject furniture, bool temp)
}
furniture.GetComponent<FurnitureHandling>().SetScale();
}

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
public void AddToValidityList(FurnitureSlot slot)
{
if (slot != null && !_currentSlotValidity.Contains(slot))
{
_currentSlotValidity.Add(slot);
}
}
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
}
Loading