コード例 #1
0
        public static IEnumerator LoadAudioClip(ParcelScene scene, string audioClipId, string url, bool loop, bool loading,
                                                float volume, bool waitForLoading = true)
        {
            DCLAudioClip.Model model = new DCLAudioClip.Model
            {
                url             = url,
                loop            = loop,
                shouldTryToLoad = loading,
                volume          = volume
            };

            DCLAudioClip audioClip = scene.SharedComponentCreate(
                audioClipId,
                (int)CLASS_ID.AUDIO_CLIP
                ) as DCLAudioClip;

            scene.SharedComponentUpdate(audioClipId, JsonUtility.ToJson(model));

            yield return(audioClip.routine);

            Assert.IsTrue(scene.disposableComponents.ContainsKey(audioClipId), "Shared component was not created correctly!");

            if (waitForLoading)
            {
                yield return(new WaitUntil(
                                 () =>
                {
                    return audioClip.loadingState != DCLAudioClip.LoadState.LOADING_IN_PROGRESS &&
                    audioClip.loadingState != DCLAudioClip.LoadState.IDLE;
                }));
            }
        }
コード例 #2
0
ファイル: TestHelpers.cs プロジェクト: JacobLee325/explorer
        public static Coroutine SharedComponentUpdate <T>(T component, BaseModel model)
            where T : BaseDisposable
        {
            ParcelScene scene = component.scene as ParcelScene;

            scene.SharedComponentUpdate(component.id, model);

            return(component.routine);
        }
コード例 #3
0
ファイル: TestHelpers.cs プロジェクト: JacobLee325/explorer
        public static Coroutine SharedComponentUpdate <T, K>(T component, K model = null)
            where T : BaseDisposable
            where K : class, new()
        {
            if (model == null)
            {
                model = new K();
            }

            ParcelScene scene = component.scene as ParcelScene;

            scene.SharedComponentUpdate(component.id, JsonUtility.ToJson(model));

            return(component.routine);
        }
コード例 #4
0
        public static void InstantiateEntityWithMaterial(ParcelScene scene, string entityId, Vector3 position,
                                                         PBRMaterial.Model pbrMaterial, string materialComponentID = "a-material")
        {
            InstantiateEntityWithShape(scene, entityId, DCL.Models.CLASS_ID.BOX_SHAPE, position);

            scene.SharedComponentCreate(
                materialComponentID,
                (int)CLASS_ID.PBR_MATERIAL
                );

            scene.SharedComponentUpdate(
                materialComponentID,
                JsonUtility.ToJson(pbrMaterial));

            scene.SharedComponentAttach(
                entityId,
                materialComponentID
                );
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
 public static void UpdateShape(ParcelScene scene, string componentId, string model)
 {
     scene.SharedComponentUpdate(componentId, model);
 }
コード例 #8
0
        private void ProcessMessage(ParcelScene scene, string method, object msgPayload,
                                    out CustomYieldInstruction yieldInstruction)
        {
            yieldInstruction = null;
            IDelayedComponent delayedComponent = null;

            try
            {
                switch (method)
                {
                case MessagingTypes.ENTITY_CREATE:
                {
                    if (msgPayload is Protocol.CreateEntity payload)
                    {
                        scene.CreateEntity(payload.entityId);
                    }

                    break;
                }

                case MessagingTypes.ENTITY_REPARENT:
                {
                    if (msgPayload is Protocol.SetEntityParent payload)
                    {
                        scene.SetEntityParent(payload.entityId, payload.parentId);
                    }

                    break;
                }

                case MessagingTypes.ENTITY_COMPONENT_CREATE_OR_UPDATE:
                {
                    if (msgPayload is Protocol.EntityComponentCreateOrUpdate payload)
                    {
                        delayedComponent = scene.EntityComponentCreateOrUpdate(payload.entityId,
                                                                               (CLASS_ID_COMPONENT)payload.classId, payload.json) as IDelayedComponent;
                    }

                    break;
                }

                case MessagingTypes.ENTITY_COMPONENT_DESTROY:
                {
                    if (msgPayload is Protocol.EntityComponentDestroy payload)
                    {
                        scene.EntityComponentRemove(payload.entityId, payload.name);
                    }

                    break;
                }

                case MessagingTypes.SHARED_COMPONENT_ATTACH:
                {
                    if (msgPayload is Protocol.SharedComponentAttach payload)
                    {
                        scene.SharedComponentAttach(payload.entityId, payload.id);
                    }

                    break;
                }

                case MessagingTypes.SHARED_COMPONENT_CREATE:
                {
                    if (msgPayload is Protocol.SharedComponentCreate payload)
                    {
                        scene.SharedComponentCreate(payload.id, payload.classId);
                    }

                    break;
                }

                case MessagingTypes.SHARED_COMPONENT_DISPOSE:
                {
                    if (msgPayload is Protocol.SharedComponentDispose payload)
                    {
                        scene.SharedComponentDispose(payload.id);
                    }
                    break;
                }

                case MessagingTypes.SHARED_COMPONENT_UPDATE:
                {
                    if (msgPayload is Protocol.SharedComponentUpdate payload)
                    {
                        delayedComponent = scene.SharedComponentUpdate(payload.componentId, payload.json) as IDelayedComponent;
                    }

                    break;
                }

                case MessagingTypes.ENTITY_DESTROY:
                {
                    if (msgPayload is Protocol.RemoveEntity payload)
                    {
                        scene.RemoveEntity(payload.entityId);
                    }
                    break;
                }

                case MessagingTypes.INIT_DONE:
                {
                    scene.sceneLifecycleHandler.SetInitMessagesDone();
                    break;
                }

                case MessagingTypes.QUERY:
                {
                    if (msgPayload is QueryMessage queryMessage)
                    {
                        ParseQuery(queryMessage.payload, scene.sceneData.id);
                    }
                    break;
                }

                case MessagingTypes.OPEN_EXTERNAL_URL:
                {
                    if (msgPayload is Protocol.OpenExternalUrl payload)
                    {
                        OnOpenExternalUrlRequest?.Invoke(scene, payload.url);
                    }
                    break;
                }

                case MessagingTypes.OPEN_NFT_DIALOG:
                {
                    if (msgPayload is Protocol.OpenNftDialog payload)
                    {
                        DataStore.i.onOpenNFTPrompt.Set(new NFTPromptModel(payload.contactAddress, payload.tokenId,
                                                                           payload.comment), true);
                    }
                    break;
                }

                default:
                    Debug.LogError($"Unknown method {method}");
                    break;
                }
            }
            catch (Exception e)
            {
                throw new Exception(
                          $"Scene message error. scene: {scene.sceneData.id} method: {method} payload: {JsonUtility.ToJson(msgPayload)} {e}");
            }

            if (delayedComponent != null)
            {
                if (delayedComponent.isRoutineRunning)
                {
                    yieldInstruction = delayedComponent.yieldInstruction;
                }
            }
        }