博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数据生成XML导入Excel
阅读量:5269 次
发布时间:2019-06-14

本文共 6604 字,大约阅读时间需要 22 分钟。

using UnityEngine;

using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

public class EffectPointList : EditorWindow {

public GameObject object1;

public static EffectPointList listWindow;

private string searchFolder = "Assets/Art/Characters";
private string[] prefabPathList;
private List<GameObject> instantiatePrefab = new List<GameObject>();
Dictionary<string, PrefabDict> prefabDict = new Dictionary<string, PrefabDict>();

[MenuItem("Assets/ListEffectPoints")]

static void Start()

{
listWindow = (EffectPointList)EditorWindow.GetWindow(typeof(EffectPointList), true, "特效点列表");
listWindow.minSize = new Vector2(400, 200);
listWindow.Show();
}

void OnGUI()

{
EditorGUILayout.HelpBox("在Assets/Art/Characters/Editor下生成EffectPointsInfo.xml。", MessageType.Info);

if (GUILayout.Button("生成特效点信息", GUILayout.Height(40)))

{
instantiatePrefab.Clear();
GetAllPrefab();

Dictionary<string, PrefabDict> xmlDict = CheckAllPrefab();

GenerateXML(xmlDict);

}

}

void GetAllPrefab()

{
prefabPathList = AssetDatabase.FindAssets("t:Prefab", new string[] { searchFolder });

for (int i = 0; i < prefabPathList.Length; ++i)

{
string prefabPath = AssetDatabase.GUIDToAssetPath(prefabPathList[i]);
GameObject obj = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;

if (!prefabPath.Contains("Effects"))

{
GameObject clone = (GameObject)PrefabUtility.InstantiatePrefab(obj);
instantiatePrefab.Add(clone);
}
}
}

Dictionary<string, PrefabDict> CheckAllPrefab()

{
prefabDict.Clear();

foreach (var obj in instantiatePrefab)

{
if (obj == null)
continue;

PrefabDict pfb = new PrefabDict();

foreach (Transform child in obj.GetComponentsInChildren<Transform>() )

{
if( child.name.Contains("Head_C_EffectPoint") )
pfb.Head_C_EffectPoint = true;
if( child.name.Contains("Head_T_EffectPoint") )
pfb.Head_T_EffectPoint = true;
if( child.name.Contains("Hand_L_EffectPoint") )
pfb.Hand_L_EffectPoint = true;
if( child.name.Contains("Hand_R_EffectPoint") )
pfb.Hand_R_EffectPoint = true;

if( child.name.Contains("Foot_L_EffectPoint") )

pfb.Foot_L_EffectPoint = true;
if( child.name.Contains("Foot_R_EffectPoint") )
pfb.Foot_R_EffectPoint = true;
if( child.name.Contains("Chest_EffectPoint") )
pfb.Chest_EffectPoint = true;
if( child.name.Contains("Bottom_EffectPoint") )
pfb.Bottom_EffectPoint = true;

if( child.name.Contains("Weapon01_EffectPoint") )

pfb.Weapon01_EffectPoint = true;
if( child.name.Contains("Normal_HurtPoint") )
pfb.Normal_HurtPoint = true;
if( child.name.Contains("Special_HurtPoint") )
pfb.Special_HurtPoint = true;
if( child.name.Contains("Footsteps_EffectPoint") )
pfb.Footsteps_EffectPoint = true;

}

prefabDict.Add(obj.name, pfb);

DestroyImmediate(obj);

}

return prefabDict;

}

private class PrefabDict

{
public bool Head_C_EffectPoint = false;
public bool Head_T_EffectPoint = false;
public bool Hand_L_EffectPoint = false;
public bool Hand_R_EffectPoint = false;

public bool Foot_L_EffectPoint = false;

public bool Foot_R_EffectPoint = false;
public bool Chest_EffectPoint = false;
public bool Bottom_EffectPoint = false;

public bool Weapon01_EffectPoint = false;

public bool Normal_HurtPoint = false;
public bool Special_HurtPoint = false;
public bool Footsteps_EffectPoint = false;
}

void GenerateXML(Dictionary<string, PrefabDict> dict)

{
string xmlPath = Application.dataPath + "/Editor/EffectPointsInfo.xml";
if (File.Exists(xmlPath))
{
Debug.Log(xmlPath);
File.Delete(xmlPath);
}

XmlDocument xmlDoc = new XmlDocument();

XmlDeclaration xmldecl;
xmldecl = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
XmlElement root = xmlDoc.DocumentElement;
xmlDoc.InsertBefore(xmldecl, root);

XmlElement infoBase = xmlDoc.CreateElement("InfoBase"); //创建根节点,最上层节点 角色名

xmlDoc.AppendChild(infoBase);

foreach (var dic in dict)

{
XmlElement characterInfo = xmlDoc.CreateElement("effectPointsInfo");
infoBase.AppendChild(characterInfo);

XmlElement characterKey = xmlDoc.CreateElement("Character");

XmlElement Head_C_EffectPoint = xmlDoc.CreateElement("Head_C_EffectPoint");

XmlElement Head_T_EffectPoint = xmlDoc.CreateElement("Head_T_EffectPoint");
XmlElement Hand_L_EffectPoint = xmlDoc.CreateElement("Hand_L_EffectPoint");
XmlElement Hand_R_EffectPoint = xmlDoc.CreateElement("Hand_R_EffectPoint");

XmlElement Foot_L_EffectPoint = xmlDoc.CreateElement("Foot_L_EffectPoint");

XmlElement Foot_R_EffectPoint = xmlDoc.CreateElement("Foot_R_EffectPoint");
XmlElement Chest_EffectPoint = xmlDoc.CreateElement("Chest_EffectPoint");
XmlElement Bottom_EffectPoint = xmlDoc.CreateElement("Bottom_EffectPoint");

XmlElement Weapon01_EffectPoint = xmlDoc.CreateElement("Weapon01_EffectPoint");

XmlElement Normal_HurtPoint = xmlDoc.CreateElement("Normal_HurtPoint");
XmlElement Special_HurtPoint = xmlDoc.CreateElement("Special_HurtPoint");
XmlElement Footsteps_EffectPoint = xmlDoc.CreateElement("Footsteps_EffectPoint");

characterKey.InnerText = dic.Key.ToString();

Head_C_EffectPoint.InnerText = dic.Value.Head_C_EffectPoint.ToString();

Head_T_EffectPoint.InnerText = dic.Value.Head_T_EffectPoint.ToString();
Hand_L_EffectPoint.InnerText = dic.Value.Hand_L_EffectPoint.ToString();
Hand_R_EffectPoint.InnerText = dic.Value.Hand_R_EffectPoint.ToString();

Foot_L_EffectPoint.InnerText = dic.Value.Foot_L_EffectPoint.ToString();

Foot_R_EffectPoint.InnerText = dic.Value.Foot_R_EffectPoint.ToString();
Chest_EffectPoint.InnerText = dic.Value.Chest_EffectPoint.ToString();
Bottom_EffectPoint.InnerText = dic.Value.Bottom_EffectPoint.ToString();

Weapon01_EffectPoint.InnerText = dic.Value.Weapon01_EffectPoint.ToString();

Normal_HurtPoint.InnerText = dic.Value.Normal_HurtPoint.ToString();
Special_HurtPoint.InnerText = dic.Value.Special_HurtPoint.ToString();
Footsteps_EffectPoint.InnerText = dic.Value.Footsteps_EffectPoint.ToString();

characterInfo.AppendChild(characterKey);

characterInfo.AppendChild(Head_C_EffectPoint);
characterInfo.AppendChild(Head_T_EffectPoint);
characterInfo.AppendChild(Hand_L_EffectPoint);
characterInfo.AppendChild(Hand_R_EffectPoint);

characterInfo.AppendChild(Foot_L_EffectPoint);

characterInfo.AppendChild(Foot_R_EffectPoint);
characterInfo.AppendChild(Chest_EffectPoint);
characterInfo.AppendChild(Bottom_EffectPoint);

characterInfo.AppendChild(Weapon01_EffectPoint);

characterInfo.AppendChild(Normal_HurtPoint);
characterInfo.AppendChild(Special_HurtPoint);
characterInfo.AppendChild(Footsteps_EffectPoint);

}

xmlDoc.Save(xmlPath); //创建EffectPointsInfo.xml文件

AssetDatabase.Refresh();
this.ShowNotification( new GUIContent("数据生成!") );
}
}

转载于:https://www.cnblogs.com/JimmyCode/p/4665341.html

你可能感兴趣的文章
JQ中 trigger()和triggerHandler()区别
查看>>
SpringMvc和servlet简单对比介绍
查看>>
查看linux系统版本命令
查看>>
外连接的用法 -- 《SQL进阶教程》 jupyter note
查看>>
Mysql创建用户与授权
查看>>
实现MySQL数据库的实时备份
查看>>
http://palmap.com.cn
查看>>
【JAVA、C++】LeetCode 014 Longest Common Prefix
查看>>
1、自动化运维之SaltStack实践
查看>>
ubuntu安装和查看已安装
查看>>
20150916-html第一次课
查看>>
js 正则表达式符号含义
查看>>
思考不动的时候
查看>>
Resharper让我们的asp.net开发效率提高三分之一
查看>>
MonkeyDevice模块功能详解
查看>>
Python学习笔记(yield与装饰器)
查看>>
python 备份脚本
查看>>
ES6-块级作用域绑定-let和const
查看>>
jquery 简单弹出层
查看>>
Android应用程序支持不同屏幕(尺寸、密度)
查看>>