예제 #1
0
    private void Start()
    {
        publishedEntity = GetComponentInParent <PublishedEntity>();

        if (publishedEntity == null)
        {
            Destroy(this);
        }
    }
예제 #2
0
 public EntityPublisher CreateEntityPublisher(PublishedEntity Entity, string playerEntityType,
                                              bool publishLocation, bool publishHeading, bool publishPitch, bool publishRoll, bool publishVelocity)
 {
     localPublishedEntities.Add(Entity);
     return(new EntityPublisher(
                ExerciseConnectionPtr, NetSimAgent.Instance.CreateEntityPublisher(ExerciseConnectionPtr, playerEntityType),
                publishLocation, publishHeading, publishPitch, publishRoll, publishVelocity
                ));
 }
예제 #3
0
 /// <summary>
 /// This is called on PublishedEntity.OnDestroy(), to signal that this entity has been destroyed and to remove it from the list.
 /// </summary>
 /// <param name="RemovedEntity"></param>
 public void RemovePublishedEntity(PublishedEntity RemovedEntity)
 {
     localPublishedEntities.Remove(RemovedEntity);
 }
    private void EntityStateChanged(EntityState entityState)
    {
        if (!checkedEntityIds.Contains(entityState.entityId))
        {
            PublishedEntity e = ExerciseConnection.LocalPublishedEntities.Find(x => x.MyEntityId == entityState.entityId);

            //Reflected entities' marking text is capped at 11 characters. This is why StartsWith is used and not ==.
            //if same entity id but different marking texts, change
            if (null != e && !e.MarkingText.StartsWith(NetSimAgent.Instance.GetReflectedEntityMarkingText(entityState.reflectedEntityPtr)))
            {
                EventReports.EntityIdChange idChange = new EventReports.EntityIdChange();
                idChange.SenderId = e.MyEntityId;
                EntityId id = new EntityId(1, UnityEngine.Random.Range(0, 9999), (ushort)UnityEngine.Random.Range(0, 255));
                idChange.NewEntityId = id;
                EventReportsManager.Send(idChange);
                e.MyEntityId = id;
                e.entityPublisher.SetEntityId(id.ToString());
                if (entitiesIdsToIgnore.Remove(idChange.SenderId))
                {
                    entitiesIdsToIgnore.Add(id);
                }
            }
            else
            {
                checkedEntityIds.Add(entityState.entityId);
            }
        }

        if (entitiesIdsToIgnore.Contains(entityState.entityId))
        {
            return;
        }

        ReflectedEntityCache reflectedEntityCache;

        bool joined = false;

        if (!reflectedEntitiesCache.TryGetValue(entityState.entityId, out reflectedEntityCache))
        {
            reflectedEntityCache = CreateReflectedEntity(entityState);
            joined = true;
        }

        if (reflectedEntityCache == null)
        {
            return;
        }

        if (reflectedEntityCache.Rigidbody != null)
        {
            reflectedEntityCache.Rigidbody.MovePosition(new Vector3(doubleToFloat(entityState.posX), doubleToFloat(entityState.posY), doubleToFloat(entityState.posZ)));
            reflectedEntityCache.Rigidbody.velocity = new Vector3(doubleToFloat(entityState.velX), doubleToFloat(entityState.velZ), doubleToFloat(entityState.velY));
        }
        else
        {
            reflectedEntityCache.Transform.position = new Vector3(doubleToFloat(entityState.posX), doubleToFloat(entityState.posY), doubleToFloat(entityState.posZ));
        }
        reflectedEntityCache.Transform.eulerAngles = new Vector3(doubleToFloat(-entityState.rotY), doubleToFloat(entityState.rotX), doubleToFloat(-entityState.rotZ));

        // TODO: Use this for Pitch.
        //reflectedEntityCache.Transform.eulerAngles = new Vector3(doubleToFloat(entityState.rotX), doubleToFloat(entityState.rotY), doubleToFloat(entityState.rotZ));

        if (reflectedEntityCache.Animator != null)
        {
            SetAnimatorParams("Posture", entityState.lifeformState, ref reflectedEntityCache.PrevLifeformState, reflectedEntityCache);
            SetAnimatorParams("Damage", entityState.DamageState, ref reflectedEntityCache.PrevDamageStateName, reflectedEntityCache);
            if (reflectedEntityCache.AnimatorSpeedParameterHash != -1)
            {
                reflectedEntityCache.Animator.SetFloat(reflectedEntityCache.AnimatorSpeedParameterHash, new Vector3(doubleToFloat(entityState.velX), doubleToFloat(entityState.velZ), doubleToFloat(entityState.velY)).magnitude);
            }
        }


        reflectedEntityCache.ReflectedEntity.LifeformState      = entityState.lifeformState;
        reflectedEntityCache.ReflectedEntity.DamageState        = entityState.DamageState;
        reflectedEntityCache.ReflectedEntity.ForceType          = entityState.forceType;
        reflectedEntityCache.ReflectedEntity.PrimaryWeaponState = entityState.primaryWeaponState;
        if (null != reflectedEntityCache.SelectedDevice)
        {
            reflectedEntityCache.SelectedDevice.SetCurrentWeaponState(entityState.primaryWeaponState);
        }

        if (joined && ReflectedEntityJoined != null)
        {
            ReflectedEntityJoined(reflectedEntityCache.ReflectedEntity);
        }
    }