Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/tweaks #108

Merged
merged 5 commits into from
Dec 18, 2024
Merged
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
15 changes: 8 additions & 7 deletions Assets/SWPPT3/Prefabs/TestPlayer2.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ GameObject:
- component: {fileID: 5865617930821872789}
- component: {fileID: 5865617930821872788}
- component: {fileID: 5865617930821872779}
- component: {fileID: 5865617930821872786}
- component: {fileID: -3614967427876102556}
- component: {fileID: 5481324099820973624}
m_Layer: 0
m_Name: TestPlayer2
m_TagString: Untagged
Expand Down Expand Up @@ -136,7 +136,7 @@ MonoBehaviour:
_slimeMaterial: {fileID: 2100000, guid: 7ea5cfe07ca064031985a22bef0fec2b, type: 2}
_rubberMaterial: {fileID: 2100000, guid: 21165d66baa9949edbc4302d0636e546, type: 2}
_metalMaterial: {fileID: 2100000, guid: 264f74bf3bd1b48c199dabcbaf507a00, type: 2}
--- !u!114 &5865617930821872786
--- !u!114 &-3614967427876102556
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -145,10 +145,12 @@ MonoBehaviour:
m_GameObject: {fileID: 5865617930821872778}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0c09447a90b2486dbaf0f9f60b29ab64, type: 3}
m_Script: {fileID: 11500000, guid: 0a2e5935e3c8414d84013fe0a3407d69, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &-3614967427876102556
_script: {fileID: 11400000, guid: 9a8ab858636d14f22a69db749d270fec, type: 2}
SetDirty: 0
--- !u!114 &5481324099820973624
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
Expand All @@ -157,8 +159,7 @@ MonoBehaviour:
m_GameObject: {fileID: 5865617930821872778}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0a2e5935e3c8414d84013fe0a3407d69, type: 3}
m_Script: {fileID: 11500000, guid: 05e8fb54764743469044103f9b46c089, type: 3}
m_Name:
m_EditorClassIdentifier:
_script: {fileID: 11400000, guid: 9a8ab858636d14f22a69db749d270fec, type: 2}
SetDirty: 0
_player: {fileID: 5865617930821872779}
73 changes: 0 additions & 73 deletions Assets/SWPPT3/Scripts/Main/AudioLogic/BgmObject.cs

This file was deleted.

3 changes: 0 additions & 3 deletions Assets/SWPPT3/Scripts/Main/AudioLogic/BgmObject.cs.meta

This file was deleted.

8 changes: 5 additions & 3 deletions Assets/SWPPT3/Scripts/Main/ConductorLogic/Conductor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#region

using System.Collections.Generic;
using System.Linq;
using UnityEngine;

#endregion
Expand All @@ -9,8 +10,9 @@ namespace SWPPT3.Main.ConductorLogic
{
public class Conductor : MonoBehaviour
{
public virtual IEnumerable<GameObject> GetConnections => Connections.AsEnumerable();

public List<GameObject> Connections { get ; set; }
public List<GameObject> Connections { get ; set; } = new ();


public virtual bool IsConductive()
Expand All @@ -25,7 +27,7 @@ private void Awake()

private void OnCollisionEnter(Collision other)
{
var conductor = other.gameObject.GetComponent<Conductor>();
var conductor = other.gameObject.GetComponentInParent<Conductor>();
if (conductor == null) return;

Connections.Add(conductor.gameObject);
Expand All @@ -35,7 +37,7 @@ private void OnCollisionEnter(Collision other)

private void OnCollisionExit(Collision other)
{
var conductor = other.gameObject.GetComponent<Conductor>();
var conductor = other.gameObject.GetComponentInParent<Conductor>();
if (conductor == null) return;
Connections.Remove(conductor.gameObject);
ConductorManager.IsDirty = true;
Expand Down
4 changes: 2 additions & 2 deletions Assets/SWPPT3/Scripts/Main/ConductorLogic/ConductorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ConductorManager : MonoBehaviour

public static bool IsDirty = false;

private void Update()
private void LateUpdate()
{
if (IsDirty)
{
Expand All @@ -45,7 +45,7 @@ private void CheckConnection()
{
var current = queue.Dequeue();

foreach (var connectionObj in current.Connections)
foreach (var connectionObj in current.GetConnections)
{
//Debug.Log(current.ToString()+ connectionObj.ToString());
var conductor = connectionObj.GetComponent<Conductor>();
Expand Down
62 changes: 57 additions & 5 deletions Assets/SWPPT3/Scripts/Main/ConductorLogic/PlayerConductor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#region

using System.Collections.Generic;
using System.Linq;
using SWPPT3.Main.PlayerLogic;
using SWPPT3.Main.PlayerLogic.State;
using SWPPT3.SoftbodyPhysics;
Expand All @@ -19,13 +21,20 @@ public class PlayerConductor : Conductor

private PlayerStates _previousState;

public override IEnumerable<GameObject> GetConnections => _connectedObjects.AsEnumerable();

private readonly HashSet<GameObject> _connectedObjects = new();
private readonly Dictionary<int, bool> _stayMap = new();
private readonly HashSet<int> _removeSet = new();

public void OnEnable()
{
_softbody = GetComponent<SoftbodyGenerator>();
if (_softbody != null)
{
_softbody.HandleCollisionEnterEvent += HandleCollisionEnter;
_softbody.HandleCollisionExitEvent += HandleCollisionExit;
_softbody.HandleCollisionStayEvent += HandleCollisionStay;
}
}

Expand All @@ -35,6 +44,7 @@ public void OnDisable()
{
_softbody.HandleCollisionEnterEvent -= HandleCollisionEnter;
_softbody.HandleCollisionExitEvent -= HandleCollisionExit;
_softbody.HandleCollisionStayEvent -= HandleCollisionStay;
}
}

Expand All @@ -51,30 +61,72 @@ private void Update()
_previousState = _player.CurrentState;
ConductorManager.IsDirty = true;
}

_removeSet.Clear();

foreach (var kvp in _stayMap)
{
if (!kvp.Value)
{
_removeSet.Add(kvp.Key);
}
}

_connectedObjects.RemoveWhere(go => _removeSet.Contains(go.GetInstanceID()));

foreach (var k in _removeSet)
{
_stayMap.Remove(k);
}

Debug.Log(_connectedObjects.Count);

if (_removeSet.Count != 0)
{
ConductorManager.IsDirty = true;
}

foreach (var connectedObject in _connectedObjects)
{
_stayMap[connectedObject.GetInstanceID()] = false;
}
}

public override bool IsConductive()
{
return _player.CurrentState == PlayerStates.Metal;
}


private void HandleCollisionEnter(Collision other)
{
var conductor = other.gameObject.GetComponent<Conductor>();
if (conductor == null) return;

Connections.Add(conductor.gameObject);
_connectedObjects.Add(conductor.gameObject);
_stayMap[conductor.gameObject.GetInstanceID()] = true;
ConductorManager.IsDirty = true;
//Debug.Log("Oncollisionenter"+ gameObject.name);
}

private void HandleCollisionExit(Collision other)
private void HandleCollisionStay(Collision other)
{
var conductor = other.gameObject.GetComponent<Conductor>();
if (conductor == null) return;
Connections.Remove(conductor.gameObject);
ConductorManager.IsDirty = true;

_stayMap[conductor.gameObject.GetInstanceID()] = true;
}

private void HandleCollisionExit(Collision other)
{
// var conductor = other.gameObject.GetComponent<Conductor>();
// if (conductor == null) return;
//
//
// conductor.gameObject.id
// if (Connections.Contains(conductor.gameObject))
// Connections.Remove(conductor.gameObject);
//
// ConductorManager.IsDirty = true;
}
}
}
2 changes: 2 additions & 0 deletions Assets/SWPPT3/Scripts/Main/PlayerLogic/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ public void TryChangeState(PlayerStates newState)
if (newState == PlayerStates.Slime || Item[newState] > 0)
{
if (newState != PlayerStates.Slime) Item[newState]--;

OnItemChanged?.Invoke();
_currentState = newState;

if (newState == PlayerStates.Rubber)
{
_meshRenderer.material = _rubberMaterial;
Expand Down
7 changes: 5 additions & 2 deletions Assets/SWPPT3/Scripts/Main/PlayerLogic/PlayerMover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ private void Start()
}
}

private void Update()
private void FixedUpdate()
{
Vector3 moveDirection = GetMoveDirection();
Vector3 force = moveDirection * _moveSpeed;
_softbody.move(force);
_softbody.Move(force);
}

private void Update()
{
if (isRightButton && _lookInput != Vector2.zero)
{
RotatePlayer();
Expand Down
20 changes: 5 additions & 15 deletions Assets/SWPPT3/Scripts/Main/PlayerLogic/State/PlayerState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,27 @@ public enum PlayerStates

public abstract class PlayerState
{
private bool isDirty= false;
private bool isDirty = false;

public virtual void InteractWithProp(Player player, PropBase obstacle)
{
isDirty = true;

if (isDirty)
{
isDirty = false;
if (obstacle is ItemBox itemBox)
{
itemBox.InteractWithPlayer();

player.SetItemCounts(0,
itemBox.ItemState == PlayerStates.Metal ? player.Item[PlayerStates.Metal] + 1 : player.Item[PlayerStates.Metal],
itemBox.ItemState == PlayerStates.Rubber ? player.Item[PlayerStates.Rubber] + 1 : player.Item[PlayerStates.Rubber]
);
}
else if (obstacle is PoisonPool)
{
//Debug.Log("collide with Poison pool");
GameManager.Instance.GameState = GameState.GameOver;
}
else if (obstacle is Gas)
{
foreach (PlayerStates playerState in Enum.GetValues(typeof(PlayerStates)))
{
player.SetItemCounts(0, 0, 0);
}
}
else if (obstacle is PoisonPool)
{
//Debug.Log("collide with Poison pool");
// Debug.Log("collide with Poison pool");
GameManager.Instance.GameState = GameState.GameOver;
}
else if (obstacle is Gas)
Expand Down Expand Up @@ -77,5 +68,4 @@ public virtual void StopInteractWithProp(Player player, PropBase obstacle)

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 7cbae8c0fef54416928371022a21f4fa, type: 3}
m_Name: PlayerScript
m_EditorClassIdentifier:
_moveSpeed: 0.05
_moveSpeed: 0.1
_jumpForce: 300
_rotationSpeed: 5
_rotationSpeed: 5.07
_normalcriteria: 0.7
Loading