예제 #1
0
        public BaseDisposable SharedComponentUpdate(string id, string json)
        {
            SceneController.i.OnMessageDecodeStart?.Invoke("ComponentUpdated");
            sharedComponentUpdatedMessage.json = json;
            sharedComponentUpdatedMessage.id   = id;
            SceneController.i.OnMessageDecodeEnds?.Invoke("ComponentUpdated");

            BaseDisposable disposableComponent = null;

            if (disposableComponents.TryGetValue(sharedComponentUpdatedMessage.id, out disposableComponent))
            {
                disposableComponent.UpdateFromJSON(sharedComponentUpdatedMessage.json);
                return(disposableComponent);
            }
            else
            {
                if (gameObject == null)
                {
                    Debug.LogError($"Unknown disposableComponent {sharedComponentUpdatedMessage.id} -- scene has been destroyed?");
                }
                else
                {
                    Debug.LogError($"Unknown disposableComponent {sharedComponentUpdatedMessage.id}", gameObject);
                }
            }

            return(null);
        }
예제 #2
0
        public DecentralandEntity DuplicateEntity(DecentralandEntity entity)
        {
            if (!entities.ContainsKey(entity.entityId))
            {
                return(null);
            }

            DecentralandEntity newEntity = CreateEntity(System.Guid.NewGuid().ToString());

            if (entity.children.Count > 0)
            {
                using (var iterator = entity.children.GetEnumerator())
                {
                    while (iterator.MoveNext())
                    {
                        DecentralandEntity childDuplicate = DuplicateEntity(iterator.Current.Value);
                        childDuplicate.SetParent(newEntity);
                    }
                }
            }

            if (entity.parent != null)
            {
                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, BaseComponent> component in entity.components)
            {
                EntityComponentCreateOrUpdateFromUnity(newEntity.entityId, component.Key, DCLTransform.model);
            }

            foreach (KeyValuePair <System.Type, BaseDisposable> component in entity.GetSharedComponents())
            {
                BaseDisposable baseDisposable = SharedComponentCreate(System.Guid.NewGuid().ToString(), component.Value.GetClassId());
                string         jsonModel      = Newtonsoft.Json.JsonConvert.SerializeObject(component.Value.GetModel());
                baseDisposable.UpdateFromJSON(jsonModel);
                SharedComponentAttach(newEntity.entityId, baseDisposable.id);
            }

            //NOTE: (Adrian) Evaluate if all created components should be handle as equals instead of different
            foreach (KeyValuePair <string, UUIDComponent> component in entity.uuidComponents)
            {
                EntityComponentCreateOrUpdateFromUnity(newEntity.entityId, CLASS_ID_COMPONENT.UUID_CALLBACK, component.Value.model);
            }

            return(newEntity);
        }