Exemple #1
0
        public void LoadRole(LodNode data)
        {
            m_NumberOfLODs = data.levels.Length;
            m_LODs.Clear();

            var go = LodUtil.CreateRole(data, m_NumberOfLODs, true);

            for (int i = 0; i < m_NumberOfLODs; i++)
            {
                LODAsset oDAsset = new LODAsset();
                oDAsset.screenPercentage = data.levels[i];
                if (i == 0)
                {
                    m_selectLOD     = 0;
                    m_cameraPercent = data.levels[i] + (1 - data.levels[i]) * 0.5f;
                }
                string name = data.prefab + "_LOD" + i;
                var    tf   = go.transform.Find(name);
                if (tf)
                {
                    oDAsset.Drop(tf.gameObject);
                }
                m_LODs.Add(oDAsset);
            }
            LodUtil.CheckBoneValid(m_LODs, out bone_error);
        }
Exemple #2
0
 private void UpdateBehavic()
 {
     if (SelectedLOD >= 0)
     {
         GameObject go = m_LODs[SelectedLOD]?.go;
         LodUtil.UpdateCamera(m_cameraPercent, go, m_direct);
     }
 }
Exemple #3
0
 private void OpenLodWin(LodNode lod)
 {
     if (LodUtil.MakeLodEnv())
     {
         var win = LodWindow.LodShow();
         win.LoadRole(lod);
         win.UpdateInfo();
     }
 }
Exemple #4
0
 public static LodWindow LodShow()
 {
     if (LodUtil.MakeLodEnv())
     {
         var    win     = GetWindow <LodWindow>();
         string iconPat = "Assets/Editor/LOD/ico.png";
         var    icon    = AssetDatabase.LoadAssetAtPath <Texture2D>(iconPat);
         win.titleContent = new GUIContent(" role lod preview window", icon);
         win.Show();
         return(win);
     }
     return(null);
 }
Exemple #5
0
 private void GuiButtons()
 {
     GUILayout.Space(8);
     GUILayout.BeginHorizontal();
     if (GUILayout.Button("Add"))
     {
         LodUtil.Add <LodNode>(ref odData.nodes, new LodNode("role"));
     }
     if (GUILayout.Button("Save"))
     {
         odData.Save();
     }
     GUILayout.EndHorizontal();
 }
Exemple #6
0
        public override void OnInspectorGUI()
        {
            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Label(icon, LODGUI.Styles.LODRendererButton, GUILayout.MaxWidth(32), GUILayout.MaxHeight(32));
            GUILayout.Label("Lod Data", LODGUI.titleLableStyle);
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            LodNode action = null;

            search = GuiSearch(search);
            if (Data.nodes != null)
            {
                for (int i = 0; i < Data.nodes.Length; i++)
                {
                    var node = Data.nodes[i];
                    if (node.Match(search))
                    {
                        var op = node.GUI();
                        if (op == LodOP.DELETE)
                        {
                            Data.nodes = LodUtil.Remv <LodNode>(Data.nodes, i);
                            break;
                        }
                        else if (op == LodOP.DETAIL)
                        {
                            action = node;
                        }
                    }
                }
            }
            GuiButtons();
            GUILayout.EndVertical();
            if (action != null)
            {
                OpenLodWin(action);
            }
        }
Exemple #7
0
        public bool AddorUpdate(string prefab, float[] levels)
        {
            bool find = false;

            if (nodes != null)
            {
                for (int i = 0; i < nodes.Length; i++)
                {
                    if (nodes[i].prefab == prefab)
                    {
                        find            = true;
                        nodes[i].levels = levels;
                        break;
                    }
                }
            }
            if (!find)
            {
                LodUtil.Add <LodNode>(ref nodes, new LodNode(prefab, levels));
            }
            return(find);
        }
Exemple #8
0
        public LodUtil.Direct GUI(LodUtil.Direct direct)
        {
            if (meshes != null && go != null)
            {
                scroll = GUILayout.BeginScrollView(scroll);
                GUILayout.BeginVertical();
                GUILayout.BeginHorizontal();
                GUILayout.Label(go.name, LODGUI.totalStyle);
                direct = (LodUtil.Direct)EditorGUILayout.EnumPopup(direct, GUILayout.MaxWidth(80));
                if (GUILayout.Button("Visualize Bounds", GUILayout.MaxWidth(110)))
                {
                    LodUtil.AttachCollider(go);
                }
                GUILayout.EndHorizontal();
                GUILayout.Label("total verts: " + vertCnt + " tris: " + triCnt, LODGUI.totalStyle);

                GUILayout.BeginHorizontal();

                GUILayout.BeginVertical();
                int i = 0;
                foreach (var mesh in meshes)
                {
                    GUILayout.BeginHorizontal();
                    GUIMesh(mesh);
                    GUILayout.BeginVertical();
                    GUILayout.Space(24);
                    GUILayout.Label(mesh.name);
                    GUILayout.Label("verts: " + mesh.vertexCount);
                    GUILayout.Label("tris:  " + mesh.triangles.Length / 3);
                    GUILayout.Label("bounds: " + mesh.bounds);

                    GUILayout.BeginHorizontal();
                    var render = renders[i++];
                    var desc   = "render bones: " + render.bones.Length + " matrix:" + mesh.bindposes.Length + " weights:" + mesh.boneWeights.Length;
                    if (GUILayout.Button(desc, UnityEngine.GUI.skin.label) || string.IsNullOrEmpty(boneInfo))
                    {
                        BoneInfo(render);
                    }
                    GUILayout.EndHorizontal();

                    desc = "skin ";
                    if (has(mesh.uv))
                    {
                        desc += "uv ";
                    }
                    if (has(mesh.uv2))
                    {
                        desc += "uv2 ";
                    }
                    if (has(mesh.uv3))
                    {
                        desc += "uv3 ";
                    }
                    if (has(mesh.uv4))
                    {
                        desc += "uv4 ";
                    }
                    if (has(mesh.normals))
                    {
                        desc += "normal ";
                    }
                    if (has(mesh.tangents))
                    {
                        desc += "tangent ";
                    }
                    if (has(mesh.colors))
                    {
                        desc += "color ";
                    }
                    if (mesh.subMeshCount > 1)
                    {
                        desc += "submesh ";
                    }
                    GUILayout.Label(desc);
                    GUILayout.EndVertical();
                    GUILayout.EndHorizontal();
                }

                GUILayout.EndHorizontal();
                GUILayout.Space(10);
                GUILayout.Label(boneInfo);
                GUILayout.EndHorizontal();

                GUILayout.EndVertical();
                GUILayout.EndScrollView();
            }
            else
            {
                GUILayout.Label("no gameobject attached");
            }
            return(direct);
        }
Exemple #9
0
        public LodOP GUI()
        {
            LodOP lodOP = LodOP.NONE;

            EditorGUILayout.BeginHorizontal();
            folder = EditorGUILayout.Foldout(folder, desc);
            if (GUILayout.Button("X", GUILayout.MaxWidth(36)))
            {
                lodOP = LodOP.DELETE;
            }
            EditorGUILayout.EndHorizontal();
            if (folder)
            {
                obj = EditorGUILayout.ObjectField("fbx", obj, typeof(GameObject), false);
                if (obj == null)
                {
                    var path = dir + "/" + prefab + "_LOD0.fbx";
                    obj = AssetDatabase.LoadAssetAtPath <GameObject>(path);
                }
                else
                {
                    var path = AssetDatabase.GetAssetPath(obj);
                    int idx  = path.LastIndexOf("/");
                    dir = path.Substring(0, idx);
                    int idx2 = path.LastIndexOf("_LOD");
                    if (idx2 > 0)
                    {
                        prefab = path.Substring(idx + 1, idx2 - idx - 1);
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("fbx's name is not match lod rule", MessageType.Error);
                    }
                }
                EditorGUILayout.BeginHorizontal();

                EditorGUILayout.LabelField(prefab);
                if (GUILayout.Button("Add", GUILayout.MaxWidth(80)))
                {
                    LodUtil.Add <float>(ref levels, levels[levels.Length - 1] / 2.0f);
                    LodUtil.Add <ExMesh>(ref format, ExMesh.UV1);
                }
                if (GUILayout.Button("Detail", GUILayout.MaxWidth(80)))
                {
                    lodOP = LodOP.DETAIL;
                }
                EditorGUILayout.EndHorizontal();
                comment = EditorGUILayout.TextField("备注: ", comment);
                bool sort = true;
                for (int i = 0; i < levels.Length; i++)
                {
                    bool del = false;
                    EditorGUILayout.BeginHorizontal();
                    levels[i] = EditorGUILayout.FloatField(" - lod" + i, levels[i]);
                    if (format == null || format.Length <= i)
                    {
                        format = defaultFmt;
                    }
                    format[i] = (ExMesh)EditorGUILayout.EnumFlagsField(format[i], GUILayout.MaxWidth(80));
                    if (GUILayout.Button("X", GUILayout.MaxWidth(36)))
                    {
                        del = true;
                    }
                    EditorGUILayout.EndHorizontal();
                    if (levels[i] <= 0 || levels[i] >= 1)
                    {
                        EditorGUILayout.HelpBox("lod range [0-1]", MessageType.Error);
                    }
                    if (del)
                    {
                        levels = LodUtil.Remv <float>(levels, i);
                        format = LodUtil.Remv <ExMesh>(format, i);
                        break;
                    }
                    if (i > 0 && levels[i] >= levels[i - 1])
                    {
                        sort = false;
                    }
                }
                if (!sort)
                {
                    EditorGUILayout.HelpBox("lod sort invalid", MessageType.Error);
                }
            }
            return(lodOP);
        }
Exemple #10
0
        private void OnGUI()
        {
            var initiallyEnabled = GUI.enabled;

            if (SelectedLOD >= m_NumberOfLODs)
            {
                SelectedLOD = m_NumberOfLODs - 1;
            }
            GUILayout.BeginVertical();
            GUILayout.Space(10);

            GUILayout.BeginHorizontal();
            GUILayout.Label("Select Role: ");

            role_pop = EditorGUILayout.Popup(role_pop, roles);
            GUILayout.Space(8);
            if (GUILayout.Button("load"))
            {
                LoadRole(lodNode);
                UpdateInfo();
            }
            if (GUILayout.Button("save"))
            {
                float[] levels = m_LODs.Where(x => x.screenPercentage > 0 && x.screenPercentage < 1).Select(x => x.screenPercentage).ToArray();
                string  prefab = lodNode.prefab;
                config.AddorUpdate(prefab, levels);
                config.Save();
                LodExport.Export(m_LODs.ToArray(), lodNode);

                LodUtil.ReLoad(m_LODs, lodNode);
                return;
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(18);

            var sliderBarPosition = GUILayoutUtility.GetRect(0, LODGUI.kSliderBarHeight, GUILayout.ExpandWidth(true));
            var lods = LODGUI.CreateLODInfos(m_NumberOfLODs, sliderBarPosition,
                                             i => string.Format("LOD {0}", i),
                                             i => m_LODs[i].screenPercentage);

            DrawLODLevelSlider(sliderBarPosition, lods);
            GUILayout.Space(LODGUI.kSliderBarBottomMargin);

            if (QualitySettings.lodBias != 1.0f)
            {
                EditorGUILayout.HelpBox(string.Format("Active LOD bias is {0:0.0#}. Distances are adjusted accordingly.", QualitySettings.lodBias), MessageType.Warning);
            }

            GUILayout.Space(8);
            GUILayout.Label(SelectedLOD < 0 ? "Culled" : "LOD " + SelectedLOD, LODGUI.selectStyle);
            GUILayout.Space(8);
            if (SelectedLOD >= 0)
            {
                var direct = m_LODs[SelectedLOD].GUI(m_direct);
                if (m_direct != direct)
                {
                    m_direct = direct;
                    UpdateBehavic();
                }
            }
            GUILayout.EndVertical();
        }