Exemplo n.º 1
0
        public void Initialize()
        {
            // 所有资源
            m_resObjects.Clear();
            string[] files = Directory.GetFiles(SettingManager.Inst.Setting.artPath, "*.prefab", SearchOption.AllDirectories);
            for (int i = 0; i < files.Length; i++)
            {
                var id        = Utils.MDToStr(Utils.ReplaceSeparator(files[i]));
                var resObject = new ResObject(id, files[i]);
                m_resObjects.Add(id, resObject);
            }

            // 资源分组
            m_groups.Clear();

            string[] dirs = Directory.GetDirectories(SettingManager.Inst.Setting.artPath, "*", SearchOption.TopDirectoryOnly);
            for (int i = 0; i < dirs.Length; i++)
            {
                var id    = Utils.MDToStr(Utils.ReplaceSeparator(dirs[i]));
                var group = new ResGroup(id, dirs[i]);
                m_groups.Add(id, group);
            }
        }
Exemplo n.º 2
0
        private void Initialize()
        {
            if (Inst == null)
            {
                OpenCubeWorldEditorWindow();
            }

            // 层初始化
            var layer = typeof(TemplateGrid).Name;

            if (!TagOperation.IsHasLayer(layer))
            {
                TagOperation.AddLayer(layer);
            }

            // 关卡
            Environment.Inst.Initialize();

            // 资源
            ResManager.Inst.Initialize();

            // 场景界面
            m_sceneWindow = new SceneWindow();
            m_sceneWindow.Initialize();
            // 切换工具事件
            m_sceneWindow.switchToolsEventHandler += OnSwitchToolsEventHandler;

            // TODO
            m_templateGridSize = new Vector2Int(40, 40);

            // 资源预览
            classRecords       = new Dictionary <string, bool>();
            m_secondaryGroupId = "";
            m_resGroup         = null;
            m_resObject        = null;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 画资源库物体预览展示
        /// </summary>
        private void DrawModelView()
        {
            if (m_resGroup == null)
            {
                return;
            }

            // 二级分组
            if (m_resGroup.haveGroup)
            {
                EditorGUILayout.BeginHorizontal();
                List <ResGroup> groups = m_resGroup.GetGroups();
                for (int i = 0; i < groups.Count; i++)
                {
                    if (GUILayout.Toggle(m_secondaryGroupId == groups[i].id, m_content = new GUIContent(groups[i].GetGroupName()), "Button", GUILayout.Height(20)))
                    {
                        m_secondaryGroupId = groups[i].id;
                        m_resGroup         = groups[i];
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
            else
            {
                m_secondaryGroupId = "";
            }

            // view 列表
            m_modelViewScrollPosition = EditorGUILayout.BeginScrollView(m_modelViewScrollPosition);

            m_modelViewHorizontalCounter = 0;

            m_modelViewColumn = (int)(Inst.position.width / 200);
            if (m_modelViewColumn <= 1)
            {
                m_modelViewColumn = 1;
            }

            EditorGUILayout.BeginVertical();

            List <ResClass> classs = m_resGroup.GetClasss();

            for (int i = 0; i < classs.Count; i++)
            {
                var _class = classs[i];

                EditorGUILayout.BeginVertical();
                if (!classRecords.ContainsKey(_class.id))
                {
                    classRecords[_class.id] = true;
                }

                classRecords[_class.id] = GUILayout.Toggle(classRecords[_class.id], m_content = new GUIContent(_class.GetClassName()), GUI.skin.button, GUILayout.Width(Inst.position.width - 20), GUILayout.Height(20));

                if (classRecords[_class.id])
                {
                    EditorGUILayout.BeginHorizontal();

                    List <ResObject> resObjects = _class.GetResObjects();
                    for (int k = 0; k < resObjects.Count; k++)
                    {
                        var resObject = resObjects[k];

                        EditorGUILayout.BeginVertical();

                        // 模型预览
                        Texture2D previewImage = AssetPreview.GetAssetPreview(resObject.prefab);
                        m_content = new GUIContent(previewImage);
                        // 选中状态
                        bool selected = false;
                        if (m_resObject != null)
                        {
                            if (m_resObject.id == resObject.id)
                            {
                                selected = true;
                            }
                        }

                        bool isSelected = GUILayout.Toggle(selected, m_content, GUI.skin.button);
                        if (isSelected && editorEnabled)
                        {
                            if ((m_resObject != null && m_resObject.id != resObject.id) || m_resObject == null)
                            {
                                // 切换到笔刷工具
                                sceneWindow.SwitchTools(SceneToolsType.Brush);
                                sceneWindow.brushTools.Bind(resObject);
                                sceneWindow.brushWindow.Initialize();
                            }
                            m_resObject = resObject;
                        }

                        EditorGUILayout.BeginHorizontal("Box");
                        EditorGUILayout.LabelField(resObject.GetFileNameWithoutExtension());
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.EndVertical();

                        m_modelViewHorizontalCounter++;
                        if (m_modelViewHorizontalCounter == m_modelViewColumn)
                        {
                            m_modelViewHorizontalCounter = 0;
                            EditorGUILayout.EndHorizontal();
                            EditorGUILayout.BeginHorizontal();
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndVertical();
            }

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
        }
Exemplo n.º 4
0
        void OnGUI()
        {
            if (Inst == null)
            {
                return;
            }
            if (Application.isPlaying)
            {
                return;
            }

            // 缺少必要组件展示创建界面
            if (!CheckSceneRuleLegal())
            {
                editorEnabled = false;
                DrawCreate();
                return;
            }

            EditorGUILayout.BeginVertical("box");

            // 编辑模式开关按钮
            editorEnabled = GUILayout.Toggle(editorEnabled, "Enable Editor", "Button", GUILayout.Height(30));

            // 场景主界面
            if (editorEnabled)
            {
                sceneWindow.ShowWindow();
            }
            else
            {
                sceneWindow.CloseWindow();
            }

            // 保存场景按钮
            EditorGUILayout.BeginHorizontal("box");

            // 跳转到创建新场景
            if (GUILayout.Button("Create Scene", GUILayout.Height(30)))
            {
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();
                GoToCreateScene();
                return;
            }

            // 保存场景
            if (GUILayout.Button("Save Scene", GUILayout.Height(30)))
            {
                SaveScene();
            }

            // 生成场景配置按钮
            if (GUILayout.Button("Export Xml", GUILayout.Height(30)))
            {
                ExportXml();
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();

            // 网格规模尺寸设置
            EditorGUILayout.BeginVertical("box");
            EditorGUILayout.LabelField("Template Grid Setting");
            GUILayout.Space(3);
            EditorGUILayout.BeginVertical("box");
            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("Size ", GUILayout.Width(50));
                m_templateGridSize = EditorGUILayout.Vector2IntField("", m_templateGridSize);
            }

            // 校正网格模版尺寸
            CorrectSize(m_templateGridSize);
            // 设置网格模版尺寸
            sceneWindow.templateGrid.width  = m_templateGridSize.x;
            sceneWindow.templateGrid.lenght = m_templateGridSize.y;

            // 网格高度设置
            GUILayout.Space(3);
            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("Height ", GUILayout.Width(50));
                GUILayout.Label(sceneWindow.templateGrid.height.ToString());
            }

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndVertical();


            // 区域
            EditorGUILayout.BeginVertical("box");
            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("Area Setting");
                if (GUILayout.Button("Add Area", GUILayout.Width(80)))
                {
                    Environment.Inst.AddArea();
                    ShowNotification(new GUIContent("add area succeed."));
                }
            }
            EditorGUILayout.BeginVertical("box");
            using (new GUILayout.HorizontalScope())
            {
                for (int i = 0; i < Environment.Inst.GetMaxAreaIndex(); i++)
                {
                    var key = i + 1;
                    if (GUILayout.Toggle(area == key, key.ToString(), GUI.skin.button))
                    {
                        area = key;
                    }
                }
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndVertical();

            // 材料分组按钮
            GUILayout.Space(3);
            EditorGUILayout.BeginHorizontal();
            FieldInfo[] fields = typeof(MaterialType).GetFields();
            for (int i = 0; i < fields.Length; i++)
            {
                var fieldName = fields[i].Name;
                if (!fieldName.Equals("value__"))
                {
                    var mt = (MaterialType)fields[i].GetValue(fields[i]);
                    if (GUILayout.Toggle(materialType == mt, m_content = new GUIContent(mt.ToString()), "Button", GUILayout.Height(30)))
                    {
                        m_materialType = mt;
                        m_resGroup     = ResManager.Inst.GetResGroupByName(mt.ToString());
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            // 资源库预览界面
            DrawModelView();

            // 场景重绘
            SceneView.RepaintAll();
        }