Example #1
0
        // Returns true iff the entity type matched and
        public bool TryToApplyPosition(Position positionData)
        {
            if (positionData.entityType != (int)Entity_Type.objects)
            {
                return(false);
            }

            int entityId = positionData.entityId;

            if (!networkedObjectFromEntityId.ContainsKey(entityId))
            {
                Debug.LogWarning("Entity ID : " + positionData.entityId + "not found in Dictionary dropping object movement packet");

                return(false);
            }

            Transform netObjTransform = networkedObjectFromEntityId[entityId].transform;

            if (!netObjTransform)
            {
                Debug.LogError($"TryToApplyPosition: NetObj with entityID {entityId} had no Transform component");

                return(false);
            }

            netObjTransform.position = positionData.pos;

            netObjTransform.rotation = positionData.rot;

            UnityExtensionMethods.SetGlobalScale(netObjTransform, Vector3.one * positionData.scaleFactor);

            return(true);
        }
        public void ApplyPositionToStart(Position positionData)
        {
            //alternate kinematic to allow for sending non physics transform updates;
            if (NetworkedObjectsManager.Instance.networkedObjectFromEntityId.ContainsKey(positionData.entityId))
            {
                if (!rigidbodyFromEntityId.ContainsKey(positionData.entityId))
                {
                    rigidbodyFromEntityId.Add(positionData.entityId, NetworkedObjectsManager.Instance.networkedObjectFromEntityId[positionData.entityId].GetComponent <Rigidbody>());
                }

                var rb = rigidbodyFromEntityId[positionData.entityId];

                if (!rb)
                {
                    Debug.LogError("There is no rigidbody in netobject entity id: " + positionData.entityId);

                    return;
                }

                rb.isKinematic = true;

                NetworkedObjectsManager.Instance.networkedObjectFromEntityId[positionData.entityId].transform.position = positionData.pos;

                NetworkedObjectsManager.Instance.networkedObjectFromEntityId[positionData.entityId].transform.rotation = positionData.rot;

                UnityExtensionMethods.SetGlobalScale(NetworkedObjectsManager.Instance.networkedObjectFromEntityId[positionData.entityId].transform, Vector3.one * positionData.scaleFactor);
            }
            else
            {
                Debug.LogWarning("Entity ID : " + positionData.entityId + "not found in Dictionary dropping physics object movement packet");
            }
        }