示例#1
0
        private void ProcessPendingUpdates()
        {
            // We must be called in edit lock

            var timer = System.Diagnostics.Stopwatch.StartNew();      // Measure time precise in update

            #region Dynamic Loading/Add/Remove native handles ---------------------------------------------------------------

            Performance.Enter("PendNative");

            foreach (NodeLoadInfo nodeLoadInfo in pendingLoaders)
            {
                if (nodeLoadInfo.state == DynamicLoadingState.LOADED)   // We got a callback from dyn loader that we were loaded or unloaded
                {
                    unTransform transform = NodeUtils.FindFirstGameObjectTransform(nodeLoadInfo.loader.GetNativeReference());

                    if (transform == null)              // We have been unloaded or not registered
                    {
                        continue;
                    }

                    if (transform.childCount != 0)       // We have already a child and our sub graph was loaded
                    {
                        continue;
                    }

                    GameObject go = Traverse(nodeLoadInfo.node, null);          // Build sub graph

                    if (go != null)
                    {
                        go.transform.SetParent(transform, false);               // Connect to our parent
                    }
                }
                else if (nodeLoadInfo.state == DynamicLoadingState.UNLOADED)
                {
                    List <GameObject> list;

                    if (NodeUtils.FindGameObjects(nodeLoadInfo.loader.GetNativeReference(), out list))
                    {
                        foreach (GameObject go in list)
                        {
                            foreach (unTransform child in go.transform)         //We need to unload all limked go in hierarchy
                            {
                                RemoveGameObjectHandles(child.gameObject);
                                GameObject.Destroy(child.gameObject);
                            }
                        }
                    }
                }
            }

            pendingLoaders.Clear();

            Performance.Leave();

            #endregion

            #region Activate/Deactivate GameObjects based on scenegraph -----------------------------------------------------

            Performance.Enter("PendActGO");

            foreach (ActivationInfo activationInfo in pendingActivations)
            {
                List <GameObject> list;  // We need to activate the correct nodes

                if (NodeUtils.FindGameObjects(activationInfo.node.GetNativeReference(), out list))
                {
                    foreach (GameObject obj in list)
                    {
                        if (activationInfo.state == NodeActionEvent.IS_TRAVERSABLE)
                        {
                            obj.SetActive(true);
                        }
                        else
                        {
                            obj.SetActive(false);
                        }
                    }
                }
            }

            pendingActivations.Clear();

            Performance.Leave();

            #endregion

            #region Update slow loading assets ------------------------------------------------------------------------------

            Performance.Enter("PendSlow");

            while (pendingBuilds.Count > 0 && timer.Elapsed.TotalSeconds < Settings.MaxBuildTime)
            {
                NodeHandle handle = pendingBuilds.Dequeue();
                handle.BuildGameObject();
            }

            Performance.Leave();

            #endregion

            // Right now we use this as a dirty fix to handle unused shared materials

            _unusedCounter = (_unusedCounter + 1) % Settings.FrameCleanupInterval;
            if (_unusedCounter == 0)
            {
                Performance.Enter("PendCleanup");
                Resources.UnloadUnusedAssets();
                Performance.Leave();
            }
        }