Esempio n. 1
0
 protected virtual void Init(string aname)
 {
     if (ability == null)
     {
         ability = new BaseDriven();
     }
     ability.Name = aname;
 }
Esempio n. 2
0
 /// <summary>
 /// 解析驱动内容
 /// </summary>
 /// <param name="content">内容</param>
 public void ParseContent(string content)
 {
     ability = DataDrivenFactory.ParseConfig(content);
     if (ability == null)
     {
         this.ShowNotification(new GUIContent("解析驱动失败!!!"));
         return;
     }
     _status = EditorStatus.Editor;
 }
        public string GenerateContent(BaseDriven ability)
        {
            BuildDriven   buildAbility = ability as BuildDriven;
            StringBuilder sb           = new StringBuilder("// This File is auto generated! Don't modify!!!\n");

            sb.AppendFormat("\"{0}\"\n", buildAbility.Name);
            sb.AppendLine("{");
            sb.AppendLine("\t\"Driven\"\t\"abilitydriven\"");

            sb.Append("}");
            return(sb.ToString());
        }
        /// <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);
        }
        /// <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("取消转换"));
                }
            }
        }
Esempio n. 6
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();
        }
        public static BaseDriven Trans(BaseDriven ability, string className)
        {
            //UnityEngine.Debug.Log(className);
            Assembly asm = Assembly.GetExecutingAssembly();

            if (asm == null)
            {
                return(null);
            }
            //2 UnityEditor 内部类
            Type cacheServerType = asm.GetType(className);

            //3 创建实例
            BaseDriven cacheServerPreferencesObj = (BaseDriven)Activator.CreateInstance(cacheServerType);

            //UnityEngine.Debug.Log(cacheServerPreferencesObj.GetType().ToString());
            cacheServerPreferencesObj.CopyFrom(ability);
            return(cacheServerPreferencesObj);
        }
 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();
 }
Esempio n. 9
0
 public virtual void CopyFrom(BaseDriven ability)
 {
     Name = ability.Name;
 }
Esempio n. 10
0
 /// <summary>
 /// 切换驱动类型
 /// </summary>
 /// <param name="iType">目标类型</param>
 public void ChangeDrivenTypeTo(DDConfig.DrivenType iType)
 {
     ability = DataDrivenFactory.Trans(ability, "DataDriven." + System.Enum.GetName(typeof(DDConfig.DrivenType), iType));
 }