IEnumerator CreateWorldObject(GameObject xy, MapObject mapObject) { if (mapObject.isSpecial) yield break; //временно не добавляем спецобъекты Util.Map.Location map = global.map; string dir = Util.File.ObjectsStorageDir(map); string file = dir + "Object"+mapObject.id.ToString(); string contr = dir + "Controller"+mapObject.id.ToString(); GameObject obj = Util.Storage.LoadPrefab(file); GameObject muObject = null; if (obj!=null) { muObject = (GameObject)Instantiate(obj,Vector3.zero, Quaternion.identity); muObject.name = "Obj"+mapObject.id.ToString(); Transform SMD = muObject.transform.FindChild("SMDImport"); if (SMD!=null) { SkinnedMeshRenderer mesh = SMD.gameObject.GetComponent<SkinnedMeshRenderer>(); if (mesh!=null) { mesh.castShadows = mesh.receiveShadows = false; } } if (global.settings.AnimatedWorldObjects) Util.GO.SetAnimator ( muObject, contr ); Util.GO.SetParent (muObject.transform, xy.transform); Util.GO.SetLayer (muObject, Util.GO.Layer.WorldObjects); muObject.transform.position = mapObject.position; muObject.transform.localScale = new Vector3(mapObject.scale*Config.ScaleObject.x, mapObject.scale*Config.ScaleObject.y, mapObject.scale*Config.ScaleObject.z); muObject.transform.localRotation = Quaternion.Euler(mapObject.rotate); //добавляем AI на объект (если есть) System.Type type = WorldConfig.GetAIObjects(map, mapObject.id); if (type!=null) { muObject.AddComponent(type); } muObject.isStatic = true; } else { if (Config.ErrorWorldObjectNotFound) Debug.Log(Lang.str("ErrorCreateObject", file)); } yield break; }
void Parse(byte[] bytes) { //int count = (bytes.Length-3)/30; uint j = 0; for (int i = 3; i < bytes.Length; i+=30) { MapObject obj = new MapObject(); int id = BitConverter.ToUInt16(bytes, i)+1; Vector3 position = new Vector3( BitConverter.ToSingle(bytes, i+2), BitConverter.ToSingle(bytes, i+10)+Config.TileHeight*Config.HoleHeight+Config.FixHeightObject, BitConverter.ToSingle(bytes, i+6) ); Vector3 rotate = new Vector3( BitConverter.ToSingle(bytes, i+14), 180f-BitConverter.ToSingle(bytes, i+22), BitConverter.ToSingle(bytes, i+18) ); float scale = BitConverter.ToSingle(bytes, i+26); MuCoord coord = Util.Map.Vector3ToCoords(position); //если объект выходит за пределами карты пропускаем его if (coord.x<0 || coord.x>=Config.MapLength || coord.y<0 || coord.y>=Config.MapLength) continue; obj.id = id; obj.position = position; obj.rotate = rotate; obj.scale = scale; obj.isSpecial = isSpecial(obj.id); obj.num = j; j++; if (data[coord.x,coord.y]==null) { data[coord.x,coord.y] = new ArrayList(); } data[coord.x,coord.y].Add(obj); } }