public bool TryGetSharedComponent(CLASS_ID componentId, out BaseDisposable component) { foreach (KeyValuePair <Type, BaseDisposable> keyValuePairBaseDisposable in GetSharedComponents()) { if (keyValuePairBaseDisposable.Value.GetClassId() == (int)componentId) { component = keyValuePairBaseDisposable.Value; return(true); } } component = null; return(false); }
public static string CreateAndSetShape(ParcelScene scene, string entityId, CLASS_ID classId, string model) { string componentId = GetComponentUniqueId(scene, "shape", (int)classId, entityId); scene.SharedComponentCreate( componentId, (int)classId ); scene.SharedComponentUpdate( componentId, model); scene.SharedComponentAttach( entityId, componentId ); return(componentId); }
public static T SharedComponentCreate <T, K>(ParcelScene scene, CLASS_ID id, K model = null) where T : BaseDisposable where K : class, new() { if (model == null) { model = new K(); } disposableIdCounter++; string uniqueId = GetComponentUniqueId(scene, "material", (int)id, "-shared-" + disposableIdCounter); T result = scene.SharedComponentCreate(uniqueId, (int)id) as T; Assert.IsNotNull(result, "class-id mismatch!"); scene.SharedComponentUpdate(uniqueId, JsonUtility.ToJson(model)); return(result); }
public static IEnumerator TestUIElementAddedCorrectlyOnInvisibleParent <TComponent, TComponentModel>(ParcelScene scene, CLASS_ID classId) where TComponent : UIShape where TComponentModel : UIShape.Model, new() { UIScreenSpace parentElement = TestHelpers.SharedComponentCreate <UIScreenSpace, UIScreenSpace.Model>(scene, CLASS_ID.UI_SCREEN_SPACE_SHAPE); yield return(parentElement.routine); // make canvas invisible yield return(SharedComponentUpdate(parentElement, new UIScreenSpace.Model { visible = false })); TComponent targetUIElement = SharedComponentCreate <TComponent, TComponentModel>(scene, classId, new TComponentModel { parentComponent = parentElement.id, width = new UIValue(100f), height = new UIValue(100f) }); yield return(targetUIElement.routine); RectTransform uiCanvasRectTransform = parentElement.childHookRectTransform.GetComponentInParent <RectTransform>(); Assert.AreEqual(uiCanvasRectTransform.rect.width / 2, targetUIElement.referencesContainer.layoutElementRT.anchoredPosition.x); Assert.AreEqual(-uiCanvasRectTransform.rect.height / 2, targetUIElement.referencesContainer.layoutElementRT.anchoredPosition.y); Assert.AreEqual(100f, targetUIElement.referencesContainer.layoutElementRT.rect.width); Assert.AreEqual(100f, targetUIElement.referencesContainer.layoutElementRT.rect.height); }
public static IEnumerator TestSharedComponentDefaultsOnUpdate <TModel, TComponent>(ParcelScene scene, CLASS_ID id) where TComponent : BaseDisposable where TModel : class, new() { TComponent component = TestHelpers.SharedComponentCreate <TComponent, TModel>(scene, id); if (component.routine != null) { yield return(component.routine); } TModel generatedModel = new TModel(); foreach (FieldInfo f in typeof(TModel).GetFields()) { System.Type t = f.FieldType; object valueToSet = GetRandomValueForType(t); f.SetValue(generatedModel, valueToSet); } yield return(SharedComponentUpdate(component, generatedModel)); yield return(TestHelpers.SharedComponentUpdate(component, new TModel())); yield return(component.routine); CompareWithDefaultedInstance <TModel, TComponent>(component); component.Dispose(); }
public static IEnumerator TestAttachedSharedComponentOfSameTypeIsReplaced <TModel, TComponent>(ParcelScene scene, CLASS_ID classId) where TComponent : BaseDisposable where TModel : class, new() { // Create scene entity and 1st component DecentralandEntity entity = CreateSceneEntity(scene); var component = SharedComponentCreate <TComponent, TModel>(scene, classId); if (component.routine != null) { yield return(component.routine); } System.Type componentType = typeof(TComponent); if (component is BaseShape) { componentType = typeof(BaseShape); } // Attach 1st component to entity TestHelpers.SharedComponentAttach(component, entity); Assert.IsTrue(entity.GetSharedComponent(componentType) != null); Assert.AreEqual(component, entity.GetSharedComponent(componentType)); // Assign 2nd component to same entity var component2 = SharedComponentCreate <TComponent, TModel>(scene, classId); if (component2.routine != null) { yield return(component2.routine); } TestHelpers.SharedComponentAttach(component2, entity); Assert.IsTrue(entity.GetSharedComponent(componentType) != null); Assert.AreEqual(component2, entity.GetSharedComponent(componentType)); Assert.IsFalse(component.attachedEntities.Contains(entity)); }
private static T CreateEntityWithPrimitive <T, K>(ParcelScene scene, Vector3 position, CLASS_ID classId, K model = null) where T : ParametrizedShape <K> where K : BaseShape.Model, new() { if (model == null) { model = new K(); } DecentralandEntity entity = CreateSceneEntity(scene); T shape = SharedComponentCreate <T, K>(scene, classId, model); SharedComponentAttach(shape, entity); SetEntityTransform(scene, entity, position, Quaternion.identity, Vector3.one); return(shape); }
protected IEnumerator CreateUIComponent <SharedComponentType, SharedComponentModel>(CLASS_ID classId, SharedComponentModel model, string componentId) where SharedComponentType : BaseDisposable where SharedComponentModel : class, new() { if (model == null) { model = new SharedComponentModel(); } // Creation var component = scene.SharedComponentCreate( componentId, "material", (int)classId ) as SharedComponentType; yield return(component.routine); // "fake" update (triggers 1st ApplyChanges() call) scene.SharedComponentUpdate(componentId, JsonUtility.ToJson(new SharedComponentModel())); yield return(component.routine); // "real" update scene.SharedComponentUpdate(componentId, JsonUtility.ToJson(model)); yield return(component.routine); }