private void InitializeNetworkedPhysicsObjectIfNeeded()
        {
            Entity_Type netObjectType = entityManager.GetComponentData <NetworkEntityIdentificationComponentData>(currentGrabbedNetObject.Entity).current_Entity_Type;

            if (netObjectType != Entity_Type.physicsObject)
            {
                return;
            }

            currentGrabbedObjectRigidBody = currentGrabbedNetObject.GetComponent <Rigidbody>();

            if (currentGrabbedObjectRigidBody == null)
            {
                Debug.LogWarning("No Rigid body on physics object Entity Type");
            }
        }
Exemple #2
0
        /// <summary>
        /// Meant to convert our Physics GameObject data send  data to follow our POSITION struct to be sent each update
        /// </summary>
        /// <param name="Net_Register_GameObject container of data"></param>
        public void SendPhysicsGameObjectUpdatesToNetwork(NetworkedGameObject eContainer)
        {
            int entityID = default;
            NetworkEntityIdentificationComponentData entityIDContainer = default;

            entityIDContainer = entityManager.GetComponentData <NetworkEntityIdentificationComponentData>(eContainer.Entity);
            entityID          = entityIDContainer.entityID;

            //make sure that we setup the reference to our rigidBody of our physics object that we are using to send data from
            if (!ClientSpawnManager.Instance.rigidbodyFromEntityId.ContainsKey(entityID))
            {
                ClientSpawnManager.Instance.rigidbodyFromEntityId.Add(entityID, eContainer.GetComponent <Rigidbody>());
            }
            var rb = ClientSpawnManager.Instance.rigidbodyFromEntityId[entityID];

            if (!rb)
            {
                Debug.LogError("There is no rigidbody in netobject entity id DICTIONARY: " + entityID);
                return;
            }

            Position coords = default;

            if (!rb.isKinematic && rb.IsSleeping() || entityManager.HasComponent <TransformLockTag>(eContainer.Entity))
            {
                physicsnRGOToRemove.Add(eContainer);

                //Send a last update for our network objects to be remove their physics funcionality to sync with others.
                StopPhysicsUpdates(eContainer);
            }

            coords = new Position
            {
                clientId    = entityIDContainer.clientID,
                entityId    = entityIDContainer.entityID,
                entityType  = (int)entityIDContainer.current_Entity_Type,
                rot         = eContainer.transform.rotation,
                pos         = eContainer.transform.position,
                scaleFactor = eContainer.transform.lossyScale.x,
            };

            coordExport.Invoke(coords);
        }
        //pick up our closest collider and obtain its references
        private Transform GetNearestRigidBody(Collider[] colliders)
        {
            float            minDistance       = float.MaxValue;
            float            distance          = 0.0f;
            List <Transform> transformToRemove = new List <Transform>();
            Collider         nearestTransform  = null;

            foreach (Collider col in colliders)
            {
                if (!col.CompareTag(TagList.interactable))
                {
                    continue;
                }

                if (!col.gameObject.activeInHierarchy)
                {
                    continue;
                }

                distance = (col.ClosestPoint(thisTransform.position) - thisTransform.position).sqrMagnitude; // (contactBody.position - thisTransform.position).sqrMagnitude;

                if (distance > 0.01f)
                {
                    continue;
                }

                //   Debug.Log("pick up is called");
                if (distance < minDistance)
                {
                    minDistance      = distance;
                    nearestTransform = col;
                }
            }
            // didnt find nearest collider return null
            if (nearestTransform == null)
            {
                return(null);
            }

            currentRB = null;
            //   currentParent = null;
            currentNetRegisteredGameObject = null;

            Transform nearPar = null;

            //set shared parent to reference when changing hands - set this ref when someone is picking up first object and//
            //whenever someone has on object on left hand then grabs that same object with the right hand, releases right hand to grab new object
            //with the left hand grab this new object - however, the shared parent is still the left

            //set last object to be picked up as the shared parent

            nearPar = nearestTransform.transform.parent;

            if (nearPar)
            {
                if (nearPar != firstControllerInteraction.thisTransform && nearPar != secondControllerInteraction.thisTransform && nearPar != StretchManager.Instance.midpoint && nearPar != StretchManager.Instance.endpoint1 && StretchManager.Instance.stretchParent != nearPar)
                {
                    var parent = nearestTransform.transform.parent;

                    if (firstControllerInteraction == this)
                    {
                        StretchManager.Instance.originalParentOfFirstHandTransform = parent;
                    }

                    if (secondControllerInteraction == this)
                    {
                        StretchManager.Instance.originalParentOfSecondHandTransform = parent;
                    }
                }
            }

            //var netObj = nearestTransform.GetComponent<NetworkAssociatedGameObject>();
            if (nearestTransform.TryGetComponent(out NetworkedGameObject netObj))
            {
                if (entityManager.HasComponent <TransformLockTag>(netObj.Entity))
                {
                    return(null);
                }

                currentNetRegisteredGameObject = netObj;

                Entity_Type netObjectType = default;
                netObjectType = entityManager.GetComponentData <NetworkEntityIdentificationComponentData>(currentNetRegisteredGameObject.Entity).current_Entity_Type;

                if (netObjectType == Entity_Type.physicsObject)
                {
                    currentRB = currentNetRegisteredGameObject.GetComponent <Rigidbody>();

                    if (currentRB == null)
                    {
                        Debug.LogWarning("No Rigid body on physics object Entity Type");
                    }
                }
            }
            return(nearestTransform.transform);
        }