public ISharedComponent SharedComponentCreate(string id, int classId) { if (disposableComponents.TryGetValue(id, out ISharedComponent component)) { return(component); } if (classId == (int)CLASS_ID.UI_SCREEN_SPACE_SHAPE || classId == (int)CLASS_ID.UI_FULLSCREEN_SHAPE) { if (GetSharedComponent <UIScreenSpace>() != null) { return(null); } } var factory = Environment.i.world.componentFactory; ISharedComponent newComponent = factory.CreateComponent(classId) as ISharedComponent; if (newComponent == null) { return(null); } disposableComponents.Add(id, newComponent); OnAddSharedComponent?.Invoke(id, newComponent); newComponent.Initialize(this, id); return(newComponent); }
private void OnAddSharedComponent(string id, ISharedComponent component) { if (state != State.READY) { disposableNotReady.Add(id); } }
public void SetSharedComponent <T0>(T0 component) where T0 : ISharedComponent { if (!arch.HasSharedType(TypeCache.GetTypeCache(typeof(T0), false))) { throw new Exception("Shared component not found in chunk."); } int indexNull = -1; for (int i = 0; i < sharedComponents.Length; i++) { ISharedComponent sharedComp = sharedComponents[i]; if (sharedComp == null && indexNull == -1) { indexNull = i; } else if (sharedComp is T0 comp) { sharedComponents[i] = component; return; } } if (indexNull != -1) { sharedComponents[indexNull] = component; } else { throw new Exception("Shared component not found in chunk."); } }
public bool HasSharedComponents(params ISharedComponent[] components) { for (int i = 0; i < components.Length; i++) { bool found = false; ISharedComponent comp = components[i]; if (comp == null) { continue; } for (int t = 0; t < sharedComponents.Length; t++) { var sharedComp = sharedComponents[t]; if (sharedComp == null) { continue; } if (sharedComp.Equals(comp)) { found = true; break; } } if (!found) { return(false); } } return(true); }
public void AddSharedComponent(System.Type componentType, ISharedComponent component) { if (component == null) { return; } RemoveSharedComponent(componentType); sharedComponents.Add(componentType, component); }
public bool IsSharedComponentEmpty <T0>() where T0 : ISharedComponent { for (int i = 0; i < sharedComponents.Length; i++) { ISharedComponent sharedComp = sharedComponents[i]; if (sharedComp != null && sharedComp is T0) { return(false); } } return(true); }
public bool TryGetSharedComponent(CLASS_ID componentId, out ISharedComponent component) { foreach (KeyValuePair <Type, ISharedComponent> keyValuePairBaseDisposable in sharedComponents) { if (keyValuePairBaseDisposable.Value.GetClassId() == (int)componentId) { component = keyValuePairBaseDisposable.Value; return(true); } } component = null; return(false); }
public bool TryGetSharedComponent <T0>(out T0 comp) where T0 : ISharedComponent { for (int i = 0; i < sharedComponents.Length; i++) { ISharedComponent sComp = sharedComponents[i]; if (sComp is T0 temp) { comp = temp; return(true); } } comp = default; return(false); }
public static IDCLEntity DuplicateEntity(ParcelScene scene, IDCLEntity entity) { if (!scene.entities.ContainsKey(entity.entityId)) { return(null); } IDCLEntity newEntity = scene.CreateEntity(System.Guid.NewGuid().ToString()); if (entity.children.Count > 0) { using (var iterator = entity.children.GetEnumerator()) { while (iterator.MoveNext()) { IDCLEntity childDuplicate = DuplicateEntity(scene, iterator.Current.Value); childDuplicate.SetParent(newEntity); } } } if (entity.parent != null) { scene.SetEntityParent(newEntity.entityId, entity.parent.entityId); } DCLTransform.model.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position); DCLTransform.model.rotation = entity.gameObject.transform.rotation; DCLTransform.model.scale = entity.gameObject.transform.lossyScale; foreach (KeyValuePair <CLASS_ID_COMPONENT, IEntityComponent> component in entity.components) { scene.EntityComponentCreateOrUpdateWithModel(newEntity.entityId, component.Key, component.Value.GetModel()); } foreach (KeyValuePair <System.Type, ISharedComponent> component in entity.sharedComponents) { ISharedComponent sharedComponent = scene.SharedComponentCreate(System.Guid.NewGuid().ToString(), component.Value.GetClassId()); sharedComponent.UpdateFromModel(component.Value.GetModel()); scene.SharedComponentAttach(newEntity.entityId, sharedComponent.id); } return(newEntity); }
public void SetSharedComponents(params ISharedComponent[] shareds) { for (int i = 0; i < shareds.Length; i++) { ISharedComponent currShared = shareds[i]; if (currShared == null) { continue; } if (!arch.HasSharedType(TypeCache.GetTypeCache(currShared.GetType(), false))) { throw new Exception("Shared component not found in chunk."); } int indexNull = -1; for (int s = 0; s < sharedComponents.Length; s++) { ISharedComponent sharedComp = sharedComponents[s]; if (sharedComp == null && indexNull == -1) { indexNull = s; } else if (sharedComp.GetType() == currShared.GetType()) { sharedComponents[s] = currShared; return; } } if (indexNull != -1) { sharedComponents[indexNull] = currShared; } else { throw new Exception("Shared component not found in chunk."); } } }
private void OnDisposableReady(ISharedComponent component) { if (owner.isReleased) { return; } disposableNotReady.Remove(component.id); if (VERBOSE) { Debug.Log($"{owner.sceneData.basePosition} Disposable objects left... {disposableNotReady.Count}"); } if (disposableNotReady.Count == 0) { SetSceneReady(); } OnStateRefreshed?.Invoke(owner); owner.RefreshLoadingState(); }
public void ShapeLoadFinish(ISharedComponent component) { OnShapeFinishLoading?.Invoke(this); }