コード例 #1
0
ファイル: ImporterContext.cs プロジェクト: sh-akira/UniVRM
        protected virtual Schedulable <Unit> LoadAsync()
        {
            return
                (Schedulable.Create()
                 .AddTask(Scheduler.ThreadPool, () =>
            {
                if (m_textures.Count == 0)
                {
                    //
                    // runtime
                    //
                    CreateTextureItems();
                }
                else
                {
                    //
                    // already CreateTextures(by assetPostProcessor or editor menu)
                    //
                }
            })
                 .ContinueWithCoroutine(Scheduler.ThreadPool, TexturesProcessOnAnyThread)
                 .ContinueWithCoroutine(Scheduler.MainThread, TexturesProcessOnMainThread)
                 .ContinueWithCoroutine(Scheduler.MainThread, LoadMaterials)
                 .OnExecute(Scheduler.ThreadPool, parent =>
            {
                // UniGLTF does not support draco
                // https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_draco_mesh_compression/README.md#conformance
                if (GLTF.extensionsRequired.Contains("KHR_draco_mesh_compression"))
                {
                    throw new UniGLTFNotSupportedException("draco is not supported");
                }

                // meshes
                var meshImporter = new MeshImporter();
                for (int i = 0; i < GLTF.meshes.Count; ++i)
                {
                    var index = i;
                    parent.AddTask(Scheduler.ThreadPool,
                                   () =>
                    {
                        using (MeasureTime("ReadMesh"))
                        {
                            return meshImporter.ReadMesh(this, index);
                        }
                    })
                    .ContinueWith(Scheduler.MainThread, x =>
                    {
                        using (MeasureTime("BuildMesh"))
                        {
                            var meshWithMaterials = MeshImporter.BuildMesh(this, x);

                            var mesh = meshWithMaterials.Mesh;

                            // mesh name
                            if (string.IsNullOrEmpty(mesh.name))
                            {
                                mesh.name = string.Format("UniGLTF import#{0}", i);
                            }
                            var originalName = mesh.name;
                            for (int j = 1; Meshes.Any(y => y.Mesh.name == mesh.name); ++j)
                            {
                                mesh.name = string.Format("{0}({1})", originalName, j);
                            }

                            return meshWithMaterials;
                        }
                    })
                    .ContinueWith(Scheduler.ThreadPool, x => Meshes.Add(x))
                    ;
                }
            })
                 .ContinueWithCoroutine(Scheduler.MainThread, LoadNodes)
                 .ContinueWithCoroutine(Scheduler.MainThread, BuildHierarchy)
                 .ContinueWith(Scheduler.MainThread, _ =>
            {
                using (MeasureTime("AnimationImporter"))
                {
                    AnimationImporter.ImportAnimation(this);
                }
            })
                 .ContinueWithCoroutine(Scheduler.MainThread, OnLoadModel)
                 .ContinueWith(Scheduler.CurrentThread,
                               _ =>
            {
                if (m_showSpeedLog)
                {
                    Debug.Log(GetSpeedLog());
                }
                return Unit.Default;
            }));
        }
コード例 #2
0
ファイル: VRMImporter.cs プロジェクト: superowner/UniWinApi
        private static Schedulable <GameObject> LoadVrmAsyncInternal(VRMImporterContext ctx, bool show)
        {
            return(Schedulable.Create()
                   .AddTask(Scheduler.ThreadPool, () =>
            {
                using (ctx.MeasureTime("glTF_VRM_Material.Parse"))
                {
                    return glTF_VRM_Material.Parse(ctx.Json);
                }
            })
                   .ContinueWith(Scheduler.MainThread, gltfMaterials =>
            {
                using (ctx.MeasureTime("new VRMMaterialImporter"))
                {
                    ctx.MaterialImporter = new VRMMaterialImporter(ctx, gltfMaterials);
                }
            })
                   .OnExecute(Scheduler.ThreadPool, parent =>
            {
                // textures
                for (int i = 0; i < ctx.GLTF.textures.Count; ++i)
                {
                    var index = i;
                    parent.AddTask(Scheduler.MainThread,
                                   () =>
                    {
                        using (ctx.MeasureTime("texture.Process"))
                        {
                            var texture = new TextureItem(ctx.GLTF, index);
                            texture.Process(ctx.GLTF, ctx.Storage);
                            return texture;
                        }
                    })
                    .ContinueWith(Scheduler.ThreadPool, x => ctx.AddTexture(x));
                }
            })
                   .ContinueWithCoroutine(Scheduler.MainThread, () => LoadMaterials(ctx))
                   .OnExecute(Scheduler.ThreadPool, parent =>
            {
                // meshes
                var meshImporter = new MeshImporter();
                for (int i = 0; i < ctx.GLTF.meshes.Count; ++i)
                {
                    var index = i;
                    parent.AddTask(Scheduler.ThreadPool,
                                   () =>
                    {
                        using (ctx.MeasureTime("ReadMesh"))
                        {
                            return meshImporter.ReadMesh(ctx, index);
                        }
                    })
                    .ContinueWith(Scheduler.MainThread, x =>
                    {
                        using (ctx.MeasureTime("BuildMesh"))
                        {
                            return gltfImporter.BuildMesh(ctx, x);
                        }
                    })
                    .ContinueWith(Scheduler.ThreadPool, x => ctx.Meshes.Add(x))
                    ;
                }
            })
                   .ContinueWithCoroutine(Scheduler.MainThread, () =>
            {
                using (ctx.MeasureTime("LoadNodes"))
                {
                    return LoadNodes(ctx);
                }
            })
                   .ContinueWithCoroutine(Scheduler.MainThread, () =>
            {
                using (ctx.MeasureTime("BuildHierarchy"))
                {
                    return BuildHierarchy(ctx);
                }
            })
                   .ContinueWith(Scheduler.CurrentThread, _ =>
            {
                //using (ctx.MeasureTime("OnLoadModel"))
                {
                    return VRMImporter.OnLoadModel(ctx);
                }
            })
                   .ContinueWith(Scheduler.CurrentThread,
                                 _ =>
            {
                ctx.Root.name = "VRM";

                if (show)
                {
                    ctx.ShowMeshes();
                }

                Debug.Log(ctx.GetSpeedLog());
                return ctx.Root;
            }));
        }
コード例 #3
0
 public SystemTimerObservable(float delta, Schedulable schedulable)
     : base(false)
 {
     this.dueTime     = delta;
     this.schedulable = schedulable;
 }
コード例 #4
0
    private void PopulateElements(object data = null)
    {
        refreshHandle.ClearScheduler();
        refreshHandle = UIScheduler.Instance.Schedule("RefreshToDoList", 0.1f, PopulateElements, null, null);
        ListPool <Chore.Precondition.Context, BuildingChoresPanel> .PooledList pooledList = ListPool <Chore.Precondition.Context, BuildingChoresPanel> .Allocate();

        ChoreConsumer.PreconditionSnapshot lastPreconditionSnapshot = choreConsumer.GetLastPreconditionSnapshot();
        if (lastPreconditionSnapshot.doFailedContextsNeedSorting)
        {
            lastPreconditionSnapshot.failedContexts.Sort();
            lastPreconditionSnapshot.doFailedContextsNeedSorting = false;
        }
        pooledList.AddRange(lastPreconditionSnapshot.failedContexts);
        pooledList.AddRange(lastPreconditionSnapshot.succeededContexts);
        Chore.Precondition.Context choreB = default(Chore.Precondition.Context);
        MinionTodoChoreEntry       minionTodoChoreEntry = null;
        int         num       = 0;
        Schedulable component = DetailsScreen.Instance.target.GetComponent <Schedulable>();
        string      arg       = string.Empty;
        Schedule    schedule  = component.GetSchedule();

        if (schedule != null)
        {
            ScheduleBlock block = schedule.GetBlock(Schedule.GetBlockIdx());
            arg = block.name;
        }
        currentScheduleBlockLabel.SetText(string.Format(UI.UISIDESCREENS.MINIONTODOSIDESCREEN.CURRENT_SCHEDULE_BLOCK, arg));
        choreTargets.Clear();
        bool flag = false;

        activeChoreEntries = 0;
        for (int num2 = pooledList.Count - 1; num2 >= 0; num2--)
        {
            Chore.Precondition.Context context = pooledList[num2];
            if (context.chore != null)
            {
                Chore.Precondition.Context context2 = pooledList[num2];
                if (!context2.chore.target.isNull)
                {
                    Chore.Precondition.Context context3 = pooledList[num2];
                    if (!((UnityEngine.Object)context3.chore.target.gameObject == (UnityEngine.Object)null) && pooledList[num2].IsPotentialSuccess())
                    {
                        Chore.Precondition.Context context4 = pooledList[num2];
                        if ((UnityEngine.Object)context4.chore.driver == (UnityEngine.Object)choreConsumer.choreDriver)
                        {
                            currentTask.Apply(pooledList[num2]);
                            minionTodoChoreEntry = currentTask;
                            choreB = pooledList[num2];
                            num    = 0;
                            flag   = true;
                        }
                        else if (!flag && activeChoreEntries != 0 && GameUtil.AreChoresUIMergeable(pooledList[num2], choreB))
                        {
                            num++;
                            minionTodoChoreEntry.SetMoreAmount(num);
                        }
                        else
                        {
                            ChoreConsumer obj = choreConsumer;
                            Chore.Precondition.Context context5            = pooledList[num2];
                            HierarchyReferences        hierarchyReferences = PriorityGroupForPriority(obj, context5.chore);
                            MinionTodoChoreEntry       choreEntry          = GetChoreEntry(hierarchyReferences.GetReference <RectTransform>("EntriesContainer"));
                            choreEntry.Apply(pooledList[num2]);
                            minionTodoChoreEntry = choreEntry;
                            choreB = pooledList[num2];
                            num    = 0;
                            flag   = false;
                        }
                    }
                }
            }
        }
        pooledList.Recycle();
        for (int num3 = choreEntries.Count - 1; num3 >= activeChoreEntries; num3--)
        {
            choreEntries[num3].gameObject.SetActive(false);
        }
        foreach (Tuple <PriorityScreen.PriorityClass, int, HierarchyReferences> priorityGroup in priorityGroups)
        {
            RectTransform reference = priorityGroup.third.GetReference <RectTransform>("EntriesContainer");
            priorityGroup.third.gameObject.SetActive(reference.childCount > 0);
        }
    }
コード例 #5
0
        private static Schedulable <GameObject> LoadVrmAsyncInternal(VRMImporterContext ctx)
        {
            var schedulable = Schedulable.Create();

            return(schedulable
                   .AddTask(Scheduler.ThreadPool, () =>
            {
                ctx.GLTF.baseDir = Path.GetDirectoryName(ctx.Path);
                return Unit.Default;
            })
                   .ContinueWith(Scheduler.ThreadPool, _ =>
            {
                return glTF_VRM_Material.Parse(ctx.Json);
            })
                   .ContinueWith(Scheduler.MainThread, x =>
            {
                // material function
                ctx.CreateMaterial = VRMImporter.GetMaterialFunc(x);
            })
                   .OnExecute(Scheduler.ThreadPool, parent =>
            {
                // textures
                for (int i = 0; i < ctx.GLTF.textures.Count; ++i)
                {
                    var index = i;
                    parent.AddTask(Scheduler.MainThread,
                                   () => gltfImporter.ImportTexture(ctx.GLTF, index))
                    .ContinueWith(Scheduler.ThreadPool, x => ctx.Textures.Add(x));
                }
            })
                   .ContinueWithCoroutine(Scheduler.MainThread, () => LoadMaterials(ctx))
                   .OnExecute(Scheduler.ThreadPool, parent =>
            {
                // meshes
                for (int i = 0; i < ctx.GLTF.meshes.Count; ++i)
                {
                    var index = i;
                    parent.AddTask(Scheduler.ThreadPool,
                                   () => gltfImporter.ReadMesh(ctx, index))
                    .ContinueWith(Scheduler.MainThread, x => gltfImporter.BuildMesh(ctx, x))
                    .ContinueWith(Scheduler.ThreadPool, x => ctx.Meshes.Add(x))
                    ;
                }
            })
                   .ContinueWithCoroutine(Scheduler.MainThread, () => LoadNodes(ctx))
                   .ContinueWithCoroutine(Scheduler.MainThread, () => BuildHierarchy(ctx))
                   .ContinueWith(Scheduler.MainThread, _ => VRMImporter.OnLoadModel(ctx))
                   .ContinueWith(Scheduler.MainThread,
                                 _ =>
            {
                /*
                 * Debug.LogFormat("task end: {0}/{1}/{2}/{3}",
                 *  ctx.Textures.Count,
                 *  ctx.Materials.Count,
                 *  ctx.Meshes.Count,
                 *  ctx.Nodes.Count
                 *  );
                 */
                ctx.Root.name = Path.GetFileNameWithoutExtension(ctx.Path);

                // 非表示のメッシュを表示する
                ctx.ShowMeshes();

                return ctx.Root;
            }));
        }
コード例 #6
0
 public StatesInstance(FinishMingleChore master, GameObject mingler) : base(master)
 {
     schedule = master.GetComponent <Schedulable>();
     sm.mingler.Set(mingler, smi);
     mingleCellSensor = GetComponent <Sensors>().GetSensor <MingleCellSensor>();
 }
コード例 #7
0
        public bool IsRecTime()
        {
            Schedulable component = base.master.GetComponent <Schedulable>();

            return(component.IsAllowed(Db.Get().ScheduleBlockTypes.Recreation));
        }