public void SaveSelectedUnit() { currentProp.ClearContainer(); for (int i = 0; i < contents.Length; ++i) { for (int j = contents[i].transform.childCount - 1; j >= 0; j--) { MapResSelectedUnit unitRes = contents[i].transform.GetChild(j).gameObject.GetComponent <MapResSelectedUnit>(); if (unitRes.GetUnitStauts() != MapResSelectedUnit.ResUnitStatus.IsNone) { bool isOn = (unitRes.GetUnitStauts() == MapResSelectedUnit.ResUnitStatus.IsOn) ? true : false; MapResProperty.unitStauts TempunitRes = new MapResProperty.unitStauts(); TempunitRes.sID = unitRes.GetEid(); TempunitRes.sStatus = unitRes.GetUnitStauts(); currentProp.AddIdContainerList(unitRes.GetEid(), TempunitRes); } } } MapDesignTools.instance.HideUnitProp(); }
MapResSelectedUnit AddResToolItem(MapResProperty resProp, int idx) { GameObject go = (GameObject)Instantiate(kResUnitPrefab, Vector3.zero, Quaternion.identity); go.transform.SetParent(contents[idx].transform); go.transform.localScale = Vector3.one; go.SetActive(true); MapResSelectedUnit selUnit = go.GetComponent <MapResSelectedUnit>(); selUnit.Init(); int eid = resProp.GetEid(); if (currentProp.GetContainerFromID(eid) != null) { MapResProperty.unitStauts mUnit = currentProp.GetContainerFromID(eid); selUnit.SetUnitStauts(mUnit.sStatus); } selUnit.setNameAndID(resProp.GetName(), resProp.GetIDStr()); selUnit.SetEid(eid); return(selUnit); }
void OpenFile() { #if UNITY_EDITOR string path = EditorUtility.OpenFilePanel("Load test csv file", "", ""); if (string.IsNullOrEmpty(path)) { return; } MapDesignTools.instance.FilePath = path; WWW www = new WWW("file:///" + path); print(www.url); Debug.Log(www.text); CsvReader csvFile = new CsvReader(); csvFile.SetData(www.text); int row = csvFile.GetRow() - 1; for (int i = 2; i < row; i++) { string eID = csvFile.GetDataByRowAndCol(i, 0); string resType = csvFile.GetDataByRowAndCol(i, 1); string resName = csvFile.GetDataByRowAndCol(i, 2); string resID = csvFile.GetDataByRowAndCol(i, 3); string resScale = csvFile.GetDataByRowAndCol(i, 4); string posX = csvFile.GetDataByRowAndCol(i, 5); string posY = csvFile.GetDataByRowAndCol(i, 6); string posZ = csvFile.GetDataByRowAndCol(i, 7); string rotX = csvFile.GetDataByRowAndCol(i, 8); string rotY = csvFile.GetDataByRowAndCol(i, 9); string rotZ = csvFile.GetDataByRowAndCol(i, 10); string TrggerPara2 = csvFile.GetDataByRowAndCol(i, 11); string ContrainID = csvFile.GetDataByRowAndCol(i, 12); string respath = csvFile.GetDataByRowAndCol(i, 13); string[] TrggerPara2Salce = TrggerPara2.Split(new char[] { '|' }); string[] EventResponse = ContrainID.Split(new char[] { '|' }); float posy = float.Parse(posY); if (int.Parse(resType) == 18) { posy += 1; } Vector3 pos = new Vector3(float.Parse(posX), posy, float.Parse(posZ)); Quaternion rotation = Quaternion.Euler(float.Parse(rotX), float.Parse(rotY), float.Parse(rotZ)); string id = GetLastStr(eID, 4); MapResProperty mRes = InstantUnit(respath, pos, int.Parse(id), int.Parse(resType), resName, int.Parse(resID), rotation); if (TrggerPara2Salce.Length == 3) { mRes.transform.localScale = new Vector3(float.Parse(TrggerPara2Salce[0]), float.Parse(TrggerPara2Salce[1]), float.Parse(TrggerPara2Salce[2])); } for (int k = 0; k < EventResponse.Length; k++) { string conId = EventResponse[k]; if (string.IsNullOrEmpty(conId)) { break; } int sId = 0; MapResProperty.unitStauts status = new MapResProperty.unitStauts(); if (conId.Contains("!")) { conId = GetLastStr(conId, 4); sId = int.Parse(conId); status.sStatus = MapResSelectedUnit.ResUnitStatus.IsEx; } else { conId = GetLastStr(conId, 4); sId = int.Parse(conId); status.sStatus = MapResSelectedUnit.ResUnitStatus.IsOn; status.sID = sId; } mRes.AddIdContainerList(sId, status); } } #endif }