Skip to content

Commit

Permalink
Merge branch 'main' into feature/renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
jihu0331 authored Dec 18, 2024
2 parents 10d9f77 + 6835909 commit ed2f23b
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 40 deletions.
39 changes: 38 additions & 1 deletion Assets/SWPPT3/Scripts/Main/ConductorLogic/PlayerConductor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using SWPPT3.Main.PlayerLogic;
using SWPPT3.Main.PlayerLogic.State;
using SWPPT3.SoftbodyPhysics;
Expand All @@ -11,8 +12,29 @@ public class PlayerConductor : Conductor
private Player _player;
private SoftbodyGenerator _softbodygenerator;

private SoftbodyGenerator _softbody;

private PlayerStates _previousState;

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

public void OnDisable()
{
if (_softbody != null)
{
_softbody.HandleCollisionEnterEvent -= HandleCollisionEnter;
_softbody.HandleCollisionExitEvent -= HandleCollisionExit;
}
}

private void Awake()
{
_softbodygenerator = gameObject.GetComponent<SoftbodyGenerator>();
Expand All @@ -33,8 +55,23 @@ public override bool IsConductive()
return _player.CurrentState == PlayerStates.Metal;
}

public void OncollisionEnter(Collision collision)

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

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

private void HandleCollisionExit(Collision other)
{
var conductor = other.gameObject.GetComponent<Conductor>();
if (conductor == null) return;
Connections.Remove(conductor.gameObject);
ConductorManager.IsDirty = true;
}
}
}
14 changes: 9 additions & 5 deletions Assets/SWPPT3/Scripts/Main/PlayerLogic/PlayerMover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using SWPPT3.Main.Manager;
using SWPPT3.Main.PlayerLogic.State;
using SWPPT3.Main.Prop;
using SWPPT3.SoftbodyPhysics;
using Unity.Collections;
using SWPPT3.SoftbodyPhysics;
using UnityEngine;
Expand All @@ -12,9 +13,8 @@ namespace SWPPT3.Main.PlayerLogic
public class PlayerMover : MonoBehaviour
{
[SerializeField] private PlayerScript _playerScript;
private Player _player;

private SoftbodyGenerator _softbody;
private Player _player;

private float _moveSpeed;
private float _jumpForce;
Expand All @@ -34,9 +34,6 @@ public class PlayerMover : MonoBehaviour

private void Start()
{
_player = GetComponent<Player>();
_softbody = GetComponent<SoftbodyGenerator>();

_rigidBodyId = GetComponent<Rigidbody>().GetInstanceID();
_moveSpeed = _playerScript.MoveSpeed;
_rotationSpeed = _playerScript.RotationSpeed;
Expand Down Expand Up @@ -70,6 +67,8 @@ private void Update()

public void OnEnable()
{
_player = GetComponent<Player>();
_softbody = GetComponent<SoftbodyGenerator>();
Physics.ContactModifyEvent += ModificationEvent;
if(_softbody != null)
{
Expand All @@ -79,6 +78,10 @@ public void OnEnable()
_softbody.HandleTriggerEnterEvent += HandleTriggerEnter;
_softbody.HandleTriggerExitEvent += HandleTriggerExit;
}
else
{
Debug.Log("null");
}
}

public void OnDisable()
Expand Down Expand Up @@ -150,6 +153,7 @@ private void HandleJump()
if (_groundedObjects.Count > 0 && GameManager.Instance.GameState == GameState.Playing)
{
_softbody.SoftbodyJump(_jumpForce);
_softbody.ResetDirty();
}
_softbody.IsJumpKey = true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using System;
using PlasticGui.WorkspaceWindow.Configuration;
using UnityEngine;

namespace SWPPT3.SoftbodyPhysics
{
public class RubberJump : MonoBehaviour
public class Particle : MonoBehaviour
{
private Rigidbody _rb;

public SoftbodyGenerator _softbody;

public float jumpForce;
public float rubberForce;

private void Awake()
{
Expand All @@ -32,9 +33,7 @@ private void OnCollisionEnter(Collision collision)
{
if (contact.normal.y >= 0.7f)
{
Vector3 force = Vector3.up * (_rb.mass * jumpForce);
_rb.AddForce(force, ForceMode.Impulse);

_softbody.SetDirty = true;
break; // 하나라도 조건 만족하면 탈출
}
}
Expand All @@ -57,9 +56,9 @@ private void OnTriggerEnter(Collider other)
_softbody.TriggerEnter(other);
}

private void OnTriggerStay(Collider other)
private void OnTriggerExit(Collider other)
{
_softbody.TriggerStay(other);
_softbody.TriggerExit(other);
}
}
}
50 changes: 24 additions & 26 deletions Assets/SWPPT3/Scripts/SoftbodyPhysics/SoftbodyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public void TriggerEnter(Collider other)
HandleTriggerEnterEvent?.Invoke(other);
}

public void TriggerStay(Collider other)
public void TriggerExit(Collider other)
{
HandleTriggerExitEvent?.Invoke(other);
}
Expand All @@ -270,7 +270,7 @@ public void TriggerStay(Collider other)
private GameObject centerOfMasObj = null;
private Rigidbody _rbOfCenter = null;

private PhysicMaterial _physicsMaterial = null;
public bool SetDirty;

private bool _isJumpKey;

Expand All @@ -282,6 +282,7 @@ public bool IsJumpKey

private void Awake()
{
SetDirty = false;
Softness = _script.Softness;
Mass = _script.Mass;
PhysicsRoughness = _script.PhysicsRoughness;
Expand All @@ -296,13 +297,6 @@ private void Awake()

_isJumpKey = false;

_physicsMaterial = new PhysicMaterial();
_physicsMaterial.bounciness = 0f;
_physicsMaterial.dynamicFriction = 0f;
_physicsMaterial.staticFriction = 0f;

_physicsMaterial.bounceCombine = PhysicMaterialCombine.Maximum;

WritableVertices = new List<Vector3>();
WritableNormals = new List<Vector3>();
_phyisicedVertexes = new List<GameObject>();
Expand Down Expand Up @@ -370,7 +364,6 @@ private void Awake()
// add collider to each of vertex ( sphere collider )
var sphereColider = _tempObj.AddComponent<SphereCollider>() as SphereCollider;
sphereColider.radius = CollissionSurfaceOffset;
sphereColider.material = _physicsMaterial;

// add current collider to Collider list ;
_sphereColliderList.Add(sphereColider);
Expand All @@ -382,10 +375,11 @@ private void Awake()
_tempRigidBody.drag = PhysicsRoughness;
_tempRigidBody.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;

var rubberJump = _tempObj.AddComponent<RubberJump>();
var rubberJump = _tempObj.AddComponent<Particle>();

OnRubberJump += rubberJump.SetActive;
rubberJump._softbody = this;
rubberJump.rubberForce = _script.RubberJump;

_rigidbodyList.Add(_tempRigidBody);

Expand All @@ -409,10 +403,6 @@ private void Awake()
rootRB.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;
_rigidbodyList.Add(rootRB);

// var rootSC = gameObject.AddComponent<SphereCollider>();
// rootSC.radius = CollissionSurfaceOffset;
// _sphereColliderList.Add(rootSC);

_sphereColliderArray = _sphereColliderList.ToArray();
_rigidbodyArray = _rigidbodyList.ToArray();

Expand Down Expand Up @@ -551,7 +541,6 @@ public void FixJoint()
joint.xMotion = ConfigurableJointMotion.Locked;
joint.yMotion = ConfigurableJointMotion.Locked;
joint.zMotion = ConfigurableJointMotion.Locked;
// joint.connectedAnchor = _bufferJointAnchors[i];
}
}

Expand All @@ -563,7 +552,6 @@ public void FreeJoint()
joint.xMotion = ConfigurableJointMotion.Limited;
joint.yMotion = ConfigurableJointMotion.Limited;
joint.zMotion = ConfigurableJointMotion.Limited;
// joint.connectedAnchor = _oriJointAnchorArray[i];
}
}

Expand Down Expand Up @@ -662,15 +650,6 @@ public void Update()
}
}

if (PlayerStates == SoftStates.Rubber && _isJumpKey == true)
{
IsRubberJump = true;
}
else
{
IsRubberJump = false;
}

var setVertexUpdateJob = new SetVertexUpdateJob
{
LocalPositions = _optVerticesBuffer,
Expand Down Expand Up @@ -703,6 +682,25 @@ public void FixedUpdate()
var getConnectedAnchorHandle = getConnectedAnchorJob.Schedule(_jointsDictNa.Length,16, getVertexLocalPositionHandle);
getConnectedAnchorHandle.Complete();
}
if (PlayerStates == SoftStates.Rubber && _isJumpKey == true)
{
IsRubberJump = true;
}
else
{
IsRubberJump = false;
}

if (IsRubberJump && SetDirty)
{
SoftbodyJump(_script.RubberJump);
Invoke("ResetDirty", _script.ResetSec);
}
}

public void ResetDirty()
{
SetDirty = false;
}

public void OnDestroy()
Expand Down
4 changes: 3 additions & 1 deletion Assets/SWPPT3/Scripts/SoftbodyPhysics/SoftbodyScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ public class SoftbodyScript : ScriptableObject
[SerializeField] private float damp;

[SerializeField] private float rubberJump;

[SerializeField] private float resetSec;
// [SerializeField] private float collissionSurfaceOffset;

public float Mass {get => mass; set => mass = value; }
public float PhysicsRoughness => physicsRoughness;
public float Softness => softness;
public float Damp => damp;
public float RubberJump => rubberJump;
// public float CollissionSurfaceOffset => collissionSurfaceOffset;
public float ResetSec => resetSec;


}
Expand Down

0 comments on commit ed2f23b

Please sign in to comment.