Example #1
0
        /// <summary>
        /// Meant to convert our Avatar data to follow our POSITION struct to be sent each update
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="position"></param>
        /// <param name="rotation"></param>
        public void SendUpdatesToNetwork(Entity_Type entityType, Vector3 position, Quaternion rotation)
        {
            Position coords = GeneratePosition(this, entityType, position, rotation);

            //send data over to those funcions attached to our UnityEvent
            coordExport.Invoke(coords);
        }
Example #2
0
        public float ComputeScaleFactor(Entity_Type entityType)
        {
            float scaleFactor = 0.123456789f;

            //setup animation parameter to update
            switch (entityType)
            {
            case Entity_Type.users_head:
                scaleFactor = headEntityTransform.parent.lossyScale.x;
                break;

            case Entity_Type.users_Lhand:
                scaleFactor = leftHandAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime;
                break;

            case Entity_Type.users_Rhand:
                scaleFactor = rightHandAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime;
                break;

            default:
                throw new System.Exception("Invalid entity type encountered.");
            }

            return(scaleFactor);
        }
Example #3
0
    public virtual void Init(int index_ = -1)
    {
        type  = Entity_Type.NONE;
        trans = gameObject.transform;

        isActive = false;
        index    = index_;
    }
Example #4
0
        public void SendStrokeNetworkUpdate(int sID, Entity_Type entityType, float lineWidth = 1, Vector3 curPos = default, Vector4 color = default)
        {
            var drawUpdate = new Draw((int)NetworkUpdateHandler.Instance.client_id, sID
                                      , (int)entityType, lineWidth, curPos,
                                      color);

            var drawSer = JsonUtility.ToJson(drawUpdate);

            KomodoMessage komodoMessage = new KomodoMessage("draw", drawSer);

            komodoMessage.Send();
        }
Example #5
0
 public Position GeneratePosition(MainClientUpdater who, Entity_Type entityType, Vector3 position, Quaternion rotation)
 {
     return(new Position
     {
         clientId = ComputeClientID(who),
         entityId = ComputeEntityID(clientID, entityType),
         entityType = ComputeEntityType(entityType),
         scaleFactor = ComputeScaleFactor(entityType),
         rot = rotation,
         pos = position,
     });
 }
Example #6
0
    public void SendUpdatesToNetwork(Entity_Type entityType, Vector3 position, Quaternion rotation)
    {
        Coords coords = new Coords
        {
            clientId   = this.clientID,
            entityId   = (this.clientID * 10) + (int)entityType,
            entityType = (int)entityType,
            rot        = rotation,
            pos        = position,
        };

        coordExport.Invoke(coords);
    }
Example #7
0
        public static string GetEntityType()
        {
            List <Entity_Type> ets = new List <Entity_Type>();
            DataTable          dt  = Mydb.ExecuteReadertoDataTable("select * from ENTITY_TYPE", new SqlParameter[] { }, CommandType.Text);

            foreach (DataRow item in dt.Rows)
            {
                Entity_Type et = new Entity_Type();
                et.ENTITY_TYPE_ID   = Convert.ToInt32(item["ENTITY_TYPE_ID"]);
                et.ENTITY_TYPE_NAME = item["ENTITY_TYPE_NAME"].ToString();
                ets.Add(et);
            }
            JavaScriptSerializer js = new JavaScriptSerializer();

            return(js.Serialize(ets));
        }
        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");
            }
        }
        private Position GeneratePosition(Entity_Type entityType, Vector3 position, Quaternion rotation)
        {
            int clientID = _GetTopIncrementalClientId();

            Position result = new Position
            {
                clientId    = clientID,
                entityId    = MainClientUpdater.Instance.ComputeEntityID(clientID, entityType),
                entityType  = MainClientUpdater.Instance.ComputeEntityType(entityType),
                scaleFactor = MainClientUpdater.Instance.ComputeScaleFactor(entityType),
                rot         = rotation,
                pos         = position,
            };

            //Debug.Log($"new Position({result.clientId}, {result.entityId}, {result.entityType}, {result.scaleFactor}, {result.rot}, {result.pos})");

            return(result);
        }
        //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);
        }
Example #11
0
        public void SendSyncPosition(Entity_Type entityType, Vector3 position, Quaternion rotation)
        {
            Position coords = GeneratePosition(this, entityType, position, rotation);

            netUpdateHandler.SendSyncPoseMessage(coords);
        }
Example #12
0
 public int ComputeEntityType(Entity_Type entityType)
 {
     return((int)entityType);
 }
Example #13
0
 public int ComputeEntityID(int clientID, Entity_Type entityType)
 {
     return((clientID * 10) + (int)entityType);
 }