예제 #1
0
        /// <summary>
        /// 保存驱动
        /// </summary>
        /// <param name="ability">驱动</param>
        private static void SaveAbility(DataDrivenEditor dataDrivenEditor, BaseDriven ability)
        {
            string content = string.Empty;

            if (_editor != null)
            {
                content = _editor.GenerateContent(ability);
            }
            if (File.Exists(dataDrivenEditor.FilePath))
            {
                File.Delete(dataDrivenEditor.FilePath);
            }
            FileUtil.CreateTextFile(dataDrivenEditor.FilePath, content);
        }
예제 #2
0
        /// <summary>
        /// 展示驱动数据
        /// </summary>
        /// <param name="dataDrivenEditor">编辑器</param>
        /// <param name="ability">驱动</param>
        public static void OnGUI(DataDrivenEditor dataDrivenEditor, BaseDriven ability)
        {
            string _type = ability.GetType().ToString();

            _type = _type.Replace("DataDriven.", "");
            dtype = (DDConfig.DrivenType)System.Enum.Parse(typeof(DDConfig.DrivenType), _type);

            _editor = SwitchDrawDrivenEditor();

            EditorGUILayout.BeginVertical();
            if (EditorGUILayout.DropdownButton(new UnityEngine.GUIContent("保存"), UnityEngine.FocusType.Keyboard))
            {
                SaveAbility(dataDrivenEditor, ability);
            }
            // 文件名
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("文件名:");
            EditorGUILayout.LabelField(ability.Name);
            EditorGUILayout.EndHorizontal();
            // 驱动类型
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("驱动类型:");
            int iType = EditorGUILayout.Popup((int)dtype, DDConfig.DrivenTypeName);

            EditorGUILayout.EndHorizontal();
            if (_editor != null)
            {
                _editor.OnGUI(ability, dataDrivenEditor);
            }

            EditorGUILayout.EndVertical();

            if (iType != (int)dtype)
            {
                // 转换类型,可能会丢失数据
                if (EditorUtility.DisplayDialog("转换类型", "转换类型可能会引起数据丢失!!确定需要转换?", "确定", "取消"))
                {
                    // 关闭展示
                    if (_editor != null)
                    {
                        _editor.CloseDrawDriven();
                    }
                    dataDrivenEditor.ChangeDrivenTypeTo((DDConfig.DrivenType)iType);
                }
                else
                {
                    dataDrivenEditor.ShowNotification(new UnityEngine.GUIContent("取消转换"));
                }
            }
        }
예제 #3
0
 static void CreateDataDrivenWindow()
 {
     if (_Instance == null)
     {
         _Instance = GetWindow <DataDrivenEditor>();
         _Instance.titleContent = new GUIContent(WINDOW_TITLE);
         _Instance.Init();
         _Instance.minSize = new Vector2(1000, 600);
     }
     // 展示窗口
     _Instance.Show();
     // 聚焦展示
     _Instance.Focus();
 }
예제 #4
0
        /// <summary>
        /// 画驱动属性面板
        /// </summary>
        /// <param name="ability">驱动</param>
        public void OnGUI(BaseDriven ability, DataDrivenEditor dataDrivenEditor)
        {
            float WindowHeiht = dataDrivenEditor.position.height;
            float WindowWidth = dataDrivenEditor.position.width;

            if (buildAbility != ability)
            {
                buildAbility = ability as BuildDriven;
                GameObject obj = AssetDatabase.LoadAssetAtPath <GameObject>(ResPrePath + buildAbility.Model);
                gameObjectEditor = Editor.CreateEditor(obj);
            }
            EditorGUILayout.BeginVertical();
            EditorGUILayout.BeginHorizontal();

            float h = EditorGUIUtility.singleLineHeight * 3;

            GUILayout.BeginArea(new Rect(0, h, 500, 500));
            if (gameObjectEditor != null)
            {
                gameObjectEditor.OnPreviewGUI(GUILayoutUtility.GetRect(500, 500), EditorStyles.whiteLabel);
            }
            else
            {
                EditorGUILayout.LabelField("模型加载失败");
            }
            GUILayout.EndArea();
            GUILayout.BeginArea(new Rect(500, h, WindowWidth - 500, WindowHeiht - h));

            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
            EditorGUILayout.BeginVertical();
            // 展示所有的属性
            string newModel = EditorGUILayout.TextField("模型名称:", buildAbility.Model);

            if (newModel != buildAbility.Model)
            {
                GameObject obj = AssetDatabase.LoadAssetAtPath <GameObject>(ResPrePath + newModel);
                buildAbility.Model = newModel;
                gameObjectEditor   = Editor.CreateEditor(obj);
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndScrollView();

            GUILayout.EndArea();
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();
        }
예제 #5
0
        /// <summary>
        /// 渲染窗口
        /// </summary>
        public static void OnGUI(DataDrivenEditor _editor)
        {
            Vector2 size    = _editor.position.size;
            float   h       = size.y * 0.5f;
            float   w       = size.x * 0.5f;
            bool    isPress = GUI.Button(new Rect(new Vector2(w - 50, h - 70), new Vector2(100, 60)), new GUIContent("打开"));

            if (isPress)
            {
                string path = EditorUtility.OpenFilePanel("选择您要打开的文件", _editor.ConfigPath, Fliter);
                if (path != null && path.Length > 0)
                {
                    _editor.FilePath = path;
                    string content = File.ReadAllText(path);
                    _editor.ParseContent(content);
                }
                else
                {
                    _editor.ShowNotification(new GUIContent("用户取消操作"));
                }
            }
            isPress = GUI.Button(new Rect(new Vector2(w - 50, h + 10), new Vector2(100, 60)), new GUIContent("创建"));
            if (isPress)
            {
                string defaultName = System.DateTime.Now.Ticks.ToString();
                string path        = EditorUtility.SaveFilePanelInProject("您要保存的文件", defaultName, Fliter, "message");
                if (path != null && path.Length > 0)
                {
                    string _p = Application.dataPath.Replace("Assets", "") + path;
                    _editor.FilePath = _p;
                    string _name    = FileUtil.GetFileName(_p);
                    string _content = GenerateDefaultContent(_name);
                    FileUtil.CreateTextFile(_p, _content);
                    _editor.ParseContent(_content);
                }
                else
                {
                    _editor.ShowNotification(new GUIContent("用户取消操作"));
                }
            }
        }
 public void OnGUI(BaseDriven ability, DataDrivenEditor dataDrivenEditor)
 {
     EditorGUILayout.BeginVertical();
     EditorGUILayout.BeginHorizontal();
     if (GUILayout.Button(EditorGUIUtility.IconContent(PropertiesIcon), GUILayout.Width(20), GUILayout.Height(15)))
     {
         extendProperties = !extendProperties;
         if (extendProperties)
         {
             PropertiesIcon = "Toolbar Minus";
         }
         else
         {
             PropertiesIcon = "Toolbar Plus";
         }
     }
     EditorGUILayout.LabelField(PropertiesName);
     EditorGUILayout.EndHorizontal();
     if (extendProperties)
     {
     }
     EditorGUILayout.EndVertical();
 }