private void DoImportWmo(TileItem tileItem, GameObject parent) { var instance = DoImportAsset(tileItem, parent); if (instance == null) { return; } var itemName = Path.GetFileNameWithoutExtension(tileItem.ModelFile); var wmoFile = _basePath + "/" + itemName + "_ModelPlacementInformation.csv"; if (!File.Exists(wmoFile)) { Debug.LogFormat("Error: Could not find model placement file for WMO '{0}'", wmoFile); } using (var stream = new MemoryStream(AssetDatabase.LoadAssetAtPath <TextAsset>(wmoFile).bytes)) using (var reader = new StreamReader(stream)) { reader.ReadLine(); string line; while ((line = reader.ReadLine()) != null) { var wmoItem = WmoItem.FromCsv(line); DoImportWmoAsset(wmoItem, instance); } } PrefabUtility.ApplyPrefabInstance(instance, InteractionMode.AutomatedAction); instance.transform.Rotate(0.0f, 90.0f, 0.0f); }
public static WmoItem FromCsv(string line) { string[] values = line.Split(';'); if (values.Length != ValueCount) { throw new ArgumentException("CSV line '" + line + "' does not contain exactly " + ValueCount + " values!"); } WmoItem wmoItem = new WmoItem(); wmoItem.ModelFile = values[0]; wmoItem.PositionX = Convert.ToSingle(values[1], FORMAT); wmoItem.PositionY = Convert.ToSingle(values[2], FORMAT); wmoItem.PositionZ = Convert.ToSingle(values[3], FORMAT); wmoItem.RotationW = Convert.ToSingle(values[4], FORMAT); wmoItem.RotationX = Convert.ToSingle(values[5], FORMAT); wmoItem.RotationY = Convert.ToSingle(values[6], FORMAT); wmoItem.RotationZ = Convert.ToSingle(values[7], FORMAT); wmoItem.ScaleFactor = Convert.ToSingle(values[8], FORMAT); wmoItem.DoodadSet = values[9]; return(wmoItem); }
private void DoImportWmoAsset(WmoItem wmoItem, GameObject parent) { var instance = PrepareAsset(wmoItem.ModelFile, parent); if (instance == null) { Debug.LogFormat("Failed to load asset '{0}'", wmoItem.ModelFile); return; } instance.transform.parent = parent.transform; instance.transform.localPosition = new Vector3(wmoItem.PositionX, wmoItem.PositionZ, wmoItem.PositionY); var rotation = new Quaternion(wmoItem.RotationX, wmoItem.RotationY, wmoItem.RotationZ, wmoItem.RotationW).eulerAngles; instance.transform.localRotation = Quaternion.Euler(rotation.x, rotation.z, rotation.y); instance.transform.localScale = new Vector3(wmoItem.ScaleFactor, wmoItem.ScaleFactor, wmoItem.ScaleFactor); }