diff --git a/Assets/SWPPT3/Scripts/Main/PlayerLogic/PlayerMover.cs b/Assets/SWPPT3/Scripts/Main/PlayerLogic/PlayerMover.cs index 95fc2407..1f3c2c84 100644 --- a/Assets/SWPPT3/Scripts/Main/PlayerLogic/PlayerMover.cs +++ b/Assets/SWPPT3/Scripts/Main/PlayerLogic/PlayerMover.cs @@ -16,8 +16,6 @@ public class PlayerMover : MonoBehaviour private SoftbodyGenerator _softbody; private Player _player; - private SoftbodyGenerator _softbody; - private float _moveSpeed; private float _jumpForce; private float _rotationSpeed; diff --git a/Assets/SWPPT3/Scripts/SoftbodyPhysics/RubberJump.cs b/Assets/SWPPT3/Scripts/SoftbodyPhysics/Particle.cs similarity index 97% rename from Assets/SWPPT3/Scripts/SoftbodyPhysics/RubberJump.cs rename to Assets/SWPPT3/Scripts/SoftbodyPhysics/Particle.cs index b860f3e1..b0df6673 100644 --- a/Assets/SWPPT3/Scripts/SoftbodyPhysics/RubberJump.cs +++ b/Assets/SWPPT3/Scripts/SoftbodyPhysics/Particle.cs @@ -3,7 +3,7 @@ namespace SWPPT3.SoftbodyPhysics { - public class RubberJump : MonoBehaviour + public class Particle : MonoBehaviour { private Rigidbody _rb; diff --git a/Assets/SWPPT3/Scripts/SoftbodyPhysics/RubberJump.cs.meta b/Assets/SWPPT3/Scripts/SoftbodyPhysics/Particle.cs.meta similarity index 100% rename from Assets/SWPPT3/Scripts/SoftbodyPhysics/RubberJump.cs.meta rename to Assets/SWPPT3/Scripts/SoftbodyPhysics/Particle.cs.meta diff --git a/Assets/SWPPT3/Scripts/SoftbodyPhysics/SoftbodyGenerator.cs b/Assets/SWPPT3/Scripts/SoftbodyPhysics/SoftbodyGenerator.cs index 8881855f..2b2b4038 100644 --- a/Assets/SWPPT3/Scripts/SoftbodyPhysics/SoftbodyGenerator.cs +++ b/Assets/SWPPT3/Scripts/SoftbodyPhysics/SoftbodyGenerator.cs @@ -60,15 +60,15 @@ public bool IsRubberJump private NativeArray _optToOriDic; // opt -> ori 를 위한 dictionary private NativeArray _oriPositions; - private List _oriJointAnchorsList; - private Vector3[] _oriJointAnchorArray; - private NativeArray _bufferJointAnchors; + // private List _oriJointAnchorsList; + // private Vector3[] _oriJointAnchorArray; + // private NativeArray _bufferJointAnchors; private List _configurableJointList; private ConfigurableJoint[] _configurableJointsArray; - private List<(int, int)> _jointsDict; - private NativeArray<(int,int)> _jointsDictNa; + // private List<(int, int)> _jointsDict; + // private NativeArray<(int,int)> _jointsDictNa; // NativeArray for Job system @@ -270,8 +270,6 @@ public void TriggerExit(Collider other) private GameObject centerOfMasObj = null; private Rigidbody _rbOfCenter = null; - private PhysicMaterial _physicsMaterial = null; - private bool _isJumpKey; public bool IsJumpKey @@ -288,21 +286,10 @@ private void Awake() Damp = _script.Damp; RubberJump = _script.RubberJump; - // CollissionSurfaceOffset = _script.CollissionSurfaceOffset; - - _oriJointAnchorsList = new List(); _configurableJointList = new List(); - _jointsDict = new List<(int, int)>(); _isJumpKey = false; - _physicsMaterial = new PhysicMaterial(); - _physicsMaterial.bounciness = 0f; - _physicsMaterial.dynamicFriction = 0f; - _physicsMaterial.staticFriction = 0f; - - _physicsMaterial.bounceCombine = PhysicMaterialCombine.Maximum; - WritableVertices = new List(); WritableNormals = new List(); _phyisicedVertexes = new List(); @@ -370,7 +357,6 @@ private void Awake() // add collider to each of vertex ( sphere collider ) var sphereColider = _tempObj.AddComponent() as SphereCollider; sphereColider.radius = CollissionSurfaceOffset; - sphereColider.material = _physicsMaterial; // add current collider to Collider list ; _sphereColliderList.Add(sphereColider); @@ -382,10 +368,11 @@ private void Awake() _tempRigidBody.drag = PhysicsRoughness; _tempRigidBody.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative; - var rubberJump = _tempObj.AddComponent(); + var rubberJump = _tempObj.AddComponent(); OnRubberJump += rubberJump.SetActive; rubberJump._softbody = this; + rubberJump.jumpForce = _script.RubberJump; _rigidbodyList.Add(_tempRigidBody); @@ -409,10 +396,6 @@ private void Awake() rootRB.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative; _rigidbodyList.Add(rootRB); - // var rootSC = gameObject.AddComponent(); - // rootSC.radius = CollissionSurfaceOffset; - // _sphereColliderList.Add(rootSC); - _sphereColliderArray = _sphereColliderList.ToArray(); _rigidbodyArray = _rigidbodyList.ToArray(); @@ -489,10 +472,6 @@ private void Awake() var destinationBody = _phyisicedVertexes[jointIndex.y].GetComponent(); float distanceBetween = Vector3.Distance(thisGameObject.transform.position, destinationBody.transform.position); - _jointsDict.Add((jointIndex.x, jointIndex.y)); - - - // configure current spring joint thisBodyJoint.connectedBody = destinationBody; @@ -507,7 +486,6 @@ private void Awake() thisBodyJoint.linearLimitSpring = Springlimit; - _oriJointAnchorsList.Add(thisBodyJoint.connectedAnchor); _configurableJointList.Add(thisBodyJoint); } @@ -530,17 +508,10 @@ private void Awake() destinationBodyJoint.massScale = 0.001f; - _jointsDict.Add((i,_rigidbodyList.Count - 1)); - _oriJointAnchorsList.Add(jointIndex.transform.localPosition - _rbOfCenter.transform.localPosition); _configurableJointList.Add(destinationBodyJoint); } - _oriJointAnchorArray = _oriJointAnchorsList.ToArray(); - _bufferJointAnchors = new NativeArray(_oriJointAnchorArray.Length, Allocator.Persistent); - _configurableJointsArray = _configurableJointList.ToArray(); - - _jointsDictNa = new NativeArray<(int, int)>(_jointsDict.ToArray(), Allocator.Persistent); } public void FixJoint() @@ -686,23 +657,7 @@ public void Update() public void FixedUpdate() { - if (IsSlime) - { - var getVertexLocalPositionJob = new GetVertexLocalPositionJob - { - Buffer = _optVerticesBuffer, - }; - var getVertexLocalPositionHandle = getVertexLocalPositionJob.Schedule(_optVerticesTransform); - var getConnectedAnchorJob = new GetConnectedAnchorJob - { - AnchorBuffer = _bufferJointAnchors, - JointDict = _jointsDictNa, - LocalPositions = _optVerticesBuffer - }; - var getConnectedAnchorHandle = getConnectedAnchorJob.Schedule(_jointsDictNa.Length,16, getVertexLocalPositionHandle); - getConnectedAnchorHandle.Complete(); - } } public void OnDestroy() @@ -711,42 +666,10 @@ public void OnDestroy() if(_optVerticesTransform.isCreated) _optVerticesTransform.Dispose(); if(_optToOriDic.IsCreated) _optToOriDic.Dispose(); if(_oriPositions.IsCreated) _oriPositions.Dispose(); - if(_jointsDictNa.IsCreated) _jointsDictNa.Dispose(); - if(_bufferJointAnchors.IsCreated) _bufferJointAnchors.Dispose(); - } - } - - /// - /// - /// LocalPosition buffer에 transformacess에 있는 local position을 대입 - /// - [BurstCompile] - public struct GetVertexLocalPositionJob : IJobParallelForTransform - { - public NativeArray Buffer; - - public void Execute(int index, TransformAccess transform) - { - Buffer[index] = transform.localPosition; } } - [BurstCompile] - public struct GetConnectedAnchorJob : IJobParallelFor - { - [ReadOnly] public NativeArray LocalPositions; - [ReadOnly] public NativeArray<(int, int)> JointDict; - public NativeArray AnchorBuffer; - public void Execute(int index) - { - var du = JointDict[index]; - var idx1 = du.Item1; - var idx2 = du.Item2; - - AnchorBuffer[index] = LocalPositions[idx1] - LocalPositions[idx2]; - } - } /// /// vertex를 optimize하면서 optimize된 vertex를 Original vertex에 대응하기 위한 job @@ -770,14 +693,4 @@ public class DebugColorGameObject : MonoBehaviour public Color Color { get; set; } } - // [CustomEditor(typeof(SoftbodyGenerator))] - // public class LookAtPointEditor : Editor - // { - // public override void OnInspectorGUI() - // { - // SoftbodyGenerator softbody = target as SoftbodyGenerator; - - // softbody.DebugMode = EditorGUILayout.Toggle("#Debug mod", softbody.DebugMode); - // } - // } }