public void exportXml(string xmlname) { XmlDocument xmlDoc = new XmlDocument(); //创建根节点 XmlElement capfish = xmlDoc.CreateElement("CapFish"); xmlDoc.AppendChild(capfish); XmlElement server = xmlDoc.CreateElement("Server"); capfish.AppendChild(server); XmlElement fishseason = xmlDoc.CreateElement("FishSeasonConfig"); server.AppendChild(fishseason); XmlElement oneseason = xmlDoc.CreateElement("OneSeason"); fishseason.AppendChild(oneseason); int childcnt = transform.childCount; for (int i = 0; i < childcnt; i++) { FishSeasonInfoComponent seasoninfoCom = transform.GetChild(i).GetComponent <FishSeasonInfoComponent>(); XmlElement seasoninfo = seasoninfoCom.getElement(xmlDoc, oneseason); oneseason.AppendChild(seasoninfo); } xmlDoc.Save(Application.dataPath + "/" + xmlname); }
public override void OnInspectorGUI() { FishSeasonInfoComponent seasonInfoProperty = (FishSeasonInfoComponent)target; seasonInfoProperty.centerPoint = EditorGUILayout.Vector2Field("CenterPoint", seasonInfoProperty.centerPoint); seasonInfoProperty.speed = EditorGUILayout.FloatField("Speed", seasonInfoProperty.speed); seasonInfoProperty.aiId = EditorGUILayout.IntField("AiId", seasonInfoProperty.aiId); seasonInfoProperty.angle = EditorGUILayout.FloatField("Angle(Degree)", seasonInfoProperty.angle); seasonInfoProperty.transform.localPosition = new Vector3(seasonInfoProperty.centerPoint.x, -(seasonInfoProperty.centerPoint.y), 0); //seasonInfoProperty.transform.eulerAngles = new Vector3(0,0,-seasonInfoProperty.angle); }
public void onModifyOneSeason(int seasonIndex) { GameObject seasonRoot = GameObject.FindWithTag("SeasonRoot"); Transform objRoot = seasonRoot.transform; int childCnt = objRoot.childCount; for (int i = 0; i < childCnt;) { Transform child = objRoot.GetChild(i); GameObject.DestroyImmediate(child.gameObject); childCnt = objRoot.childCount; } OneFishSeason season = FishConfigManager.getInstance().getOneSeason(seasonIndex); TableFish fishtable = (TableFish)GameTableManager.getInstance().GetTable("table_fish"); GameObject oneSeasonObj = new GameObject(); oneSeasonObj.transform.parent = objRoot; oneSeasonObj.AddComponent <OneSeasonComponent>(); oneSeasonObj.name = "OneSeason"; oneSeasonObj.transform.localScale = Vector3.one; oneSeasonObj.transform.localPosition = Vector3.zero; foreach (FishSeasonInfo seasoninfo in season.seasonInfoList) { GameObject seasonInfoObj = new GameObject(); seasonInfoObj.transform.parent = oneSeasonObj.transform; seasonInfoObj.name = "OneSeasonInfo"; seasonInfoObj.transform.localScale = Vector3.one; FishSeasonInfoComponent seasonInfoCom = seasonInfoObj.AddComponent <FishSeasonInfoComponent>(); seasonInfoCom.centerPoint.Set(seasoninfo.mCenterPoint.x, seasoninfo.mCenterPoint.y); seasonInfoCom.speed = seasoninfo.mSpeed; seasonInfoCom.aiId = seasoninfo.mAiId; seasonInfoCom.angle = seasoninfo.mAngle; seasonInfoCom.transform.localPosition = new Vector3(seasoninfo.mCenterPoint.x, -(seasoninfo.mCenterPoint.y), 0); foreach (SingleFishOfSeason singlefish in seasoninfo.fishList) { TableFish.FishRecord record = fishtable.getRecordByFishKindId(singlefish.mFishKindId); if (record == null) { continue; } float fFishLength = record.width; GameObject fishObj = (GameObject)GameObject.Instantiate(Resources.Load("FishPrefabs/Prefab_Fish_" + record.name)); fishObj.name = "Prefab_Fish_" + record.name; fishObj.transform.parent = seasonInfoObj.transform; fishObj.transform.localScale = Vector3.one * record.scaleFactor; fishObj.transform.localPosition = new Vector3(singlefish.mFishPos.x, singlefish.mFishPos.y, 0); if (seasoninfo.mCenterPoint.x <= 0) { fishObj.transform.localPosition = new Vector3(-singlefish.mFishPos.x, singlefish.mFishPos.y, 0); } else if (seasoninfo.mCenterPoint.x >= 1280) { fishObj.transform.localPosition = new Vector3(singlefish.mFishPos.x, singlefish.mFishPos.y, 0); } else if (seasoninfo.mCenterPoint.y <= 0) { fishObj.transform.localPosition = new Vector3(singlefish.mFishPos.x, -singlefish.mFishPos.y, 0); } else if (seasoninfo.mCenterPoint.y >= 720) { fishObj.transform.localPosition = new Vector3(singlefish.mFishPos.x, singlefish.mFishPos.y, 0); } } UnityEditor.EditorApplication.MarkSceneDirty(); } }