public static T EntityComponentCreate <T, K>(ParcelScene scene, DecentralandEntity entity, K model, CLASS_ID_COMPONENT classId = CLASS_ID_COMPONENT.NONE) where T : BaseComponent where K : new() { int componentClassId = classId == CLASS_ID_COMPONENT.NONE ? (int)scene.ownerController.componentFactory.GetIdForType <T>() : (int)classId; string componentInstanceId = GetComponentUniqueId(scene, typeof(T).Name, componentClassId, entity.entityId); string data; if (classId == CLASS_ID_COMPONENT.TRANSFORM) { PB_Transform transf = GetPBTransformFromModelJson(JsonUtility.ToJson(model)); data = System.Convert.ToBase64String(transf.ToByteArray()); } else { data = JsonUtility.ToJson(model); } return(scene.EntityComponentCreateOrUpdate( entity.entityId, (CLASS_ID_COMPONENT)componentClassId, data , out _) as T); }
public static PB_Transform GetPBTransformFromModelJson(string json) { DCLTransform.Model transfModel = JsonUtility.FromJson <DCLTransform.Model>(json); PB_Transform pbTranf = GetPBTransform(transfModel.position, transfModel.rotation, transfModel.scale); return(pbTranf); }
public static void SetEntityTransform(ParcelScene scene, DecentralandEntity entity, Vector3 position, Quaternion rotation, Vector3 scale) { PB_Transform pB_Transform = GetPBTransform(position, rotation, scale); scene.EntityComponentCreateOrUpdate( entity.entityId, CLASS_ID_COMPONENT.TRANSFORM, System.Convert.ToBase64String(pB_Transform.ToByteArray()) , out CleanableYieldInstruction routine); }
void UpdateEntityTransform(ParcelScene scene, string entityId, Vector3 position, Quaternion rotation, Vector3 scale) { PB_Transform pB_Transform = GetPBTransform(position, rotation, scale); scene.EntityComponentCreateOrUpdate( entityId, CLASS_ID_COMPONENT.TRANSFORM, System.Convert.ToBase64String(pB_Transform.ToByteArray()) ); }
public static PB_Transform GetPBTransform(Vector3 position, Quaternion rotation, Vector3 scale) { PB_Transform pbTranf = new PB_Transform(); pbTranf.Position = new PB_Vector3(); pbTranf.Position.X = position.x; pbTranf.Position.Y = position.y; pbTranf.Position.Z = position.z; pbTranf.Rotation = new PB_Quaternion(); pbTranf.Rotation.X = rotation.x; pbTranf.Rotation.Y = rotation.y; pbTranf.Rotation.Z = rotation.z; pbTranf.Rotation.W = rotation.w; pbTranf.Scale = new PB_Vector3(); pbTranf.Scale.X = scale.x; pbTranf.Scale.Y = scale.y; pbTranf.Scale.Z = scale.z; return(pbTranf); }