Example #1
0
 public virtual void OnEnable()
 {
     m_State      = Loadm_State.Unloaded;
     m_ReadyState = Loadm_State.None;
     m_Root       = null;
     m_Data       = null;
     m_Coroutine  = null;
 }
Example #2
0
 //开始加载
 public override void Load(UnityLODGroupFast data, ChildTreeRoot root)
 {
     if (m_State == Loadm_State.Unloaded)
     {
         m_Data = data;
         m_Root = root;
         Addressables.InstantiateAsync(m_Data._assetPath).Completed += OnAssetInstantiated;
         m_State = Loadm_State.Loading;
     }
     else if (m_State == Loadm_State.UnLoading)
     {
         m_State = Loadm_State.Loading;
     }
 }
Example #3
0
 /*开始加载*/
 public virtual void Load(UnityLODGroupFast data, ChildTreeRoot root)
 {
     //子类实现
 }
Example #4
0
 public virtual void Set(UnityLODGroupFast data, ChildTreeRoot root)
 {
     m_Data = data;
     m_Root = root;
 }
Example #5
0
        /*更新BVH,对生成的BVH做后处理,广度遍历*/
        public IEnumerator UpdateRootVolume(Action <List <LODVolume> > action)
        {
            Queue <LODVolume> queue = new Queue <LODVolume>();

            //给每个子树添加ChildTreeRoot
            queue.Enqueue(this);
            while (queue.Count > 0)
            {
                LODVolume lodVolume = queue.Dequeue();
                if (lodVolume.combined != null)
                {
                    ChildTreeRoot treeRoot = lodVolume.gameObject.AddComponent <ChildTreeRoot>();
                    continue;
                }
                foreach (LODVolume lv in lodVolume.childVolumes)
                {
                    queue.Enqueue(lv);
                }
                EditorUtility.DisplayProgressBar("添加ChildTreeRoot", lodVolume.name, 0.3f);
            }

            //叶子节点,给每个UnityLODGroup做引用,同时所有子树的节点引用ChildTreeRoot
            queue.Enqueue(this);
            while (queue.Count > 0)
            {
                LODVolume lodVolume = queue.Dequeue();
                foreach (LODVolume lv in lodVolume.childVolumes)
                {
                    queue.Enqueue(lv);
                }
                if (lodVolume.childVolumes.Count < 1)
                {
                    foreach (var fast in lodVolume.lodGroups)
                    {
                        fast._lodVolume = lodVolume;
                    }
                }
                lodVolume.childTreeRoot = lodVolume.GetComponentInParent <ChildTreeRoot>();
                EditorUtility.DisplayProgressBar("引用ChildTreeRoot", lodVolume.name, 0.6f);
            }

            //设置节点深度
            int curLevelNum = 0; //当前层的节点数
            int curLevel    = 1; //层数

            queue.Enqueue(this);
            while (queue.Count > 0)
            {
                curLevelNum = queue.Count;
                while (curLevelNum-- > 0)
                {
                    LODVolume lodVolume = queue.Dequeue();
                    lodVolume.deep = curLevel;

                    foreach (LODVolume lv in lodVolume.childVolumes)
                    {
                        queue.Enqueue(lv);
                    }
                    EditorUtility.DisplayProgressBar("深度设置", lodVolume.name, 0.8f);
                }
                curLevel++;
            }

            //构造后续遍历列表
            List <LODVolume>  backSort = new List <LODVolume>();
            Stack <LODVolume> stack    = new Stack <LODVolume>();

            stack.Push(this);
            while (stack.Count > 0)
            {
                LODVolume lodVolume = stack.Pop();
                backSort.Add(lodVolume);
                foreach (LODVolume lv in lodVolume.childVolumes)
                {
                    stack.Push(lv);
                }
                EditorUtility.DisplayProgressBar("构造后续遍历列表", lodVolume.name, 0.9f);
            }
            backSort.Reverse();

            if (action != null)
            {
                action.Invoke(backSort);
            }

            yield return(null);
        }