public IEnumerator BuiltInFontHandleErrorProperly() { DecentralandEntity entity = TestHelpers.CreateSceneEntity(scene); TextShape textShape = TestHelpers.EntityComponentCreate <TextShape, TextShape.Model>(scene, entity, new TextShape.Model()); yield return(textShape.routine); TMP_FontAsset defaultFont = textShape.GetComponentInChildren <TextMeshPro>().font; DCLFont font = TestHelpers.SharedComponentCreate <DCLFont, DCLFont.Model>(scene, CLASS_ID.FONT, new DCLFont.Model() { src = "no-valid-font" }); yield return(font.routine); scene.EntityComponentUpdate(entity, CLASS_ID_COMPONENT.TEXT_SHAPE, JsonUtility.ToJson(new TextShape.Model { font = font.id })); yield return(textShape.routine); Assert.IsTrue(font.error, "Built-in font error has not araise properly"); Assert.IsTrue(textShape.GetComponentInChildren <TextMeshPro>().font == defaultFont, "Built-in font didn't apply correctly"); }
public static IEnumerator TestEntityComponentDefaultsOnUpdate <TModel, TComponent>(ParcelScene scene) where TComponent : BaseComponent where TModel : class, new() { TModel generatedModel = new TModel(); foreach (FieldInfo f in typeof(TModel).GetFields()) { System.Type t = f.FieldType; object valueToSet = GetRandomValueForType(t); f.SetValue(generatedModel, valueToSet); } DecentralandEntity e = CreateSceneEntity(scene); TComponent component = EntityComponentCreate <TComponent, TModel>(scene, e, generatedModel); if (component.routine != null) { yield return(component.routine); } int id = (int)scene.ownerController.componentFactory.GetIdForType <TComponent>(); scene.EntityComponentUpdate(e, (CLASS_ID_COMPONENT)id, "{}"); if (component.routine != null) { yield return(component.routine); } CompareWithDefaultedInstance <TModel, TComponent>(component); TestHelpers.RemoveSceneEntity(scene, e.entityId); }
public static Coroutine EntityComponentUpdate <T, K>(T component, K model = null) where T : BaseComponent where K : class, new() { if (model == null) { model = new K(); } CLASS_ID_COMPONENT classId = Environment.i.world.sceneController.componentFactory.GetIdForType <T>(); ParcelScene scene = component.scene as ParcelScene; scene.EntityComponentUpdate(component.entity, classId, JsonUtility.ToJson(model)); return(component.routine); }