public int Deserialize(List <string> data) { GetComponent <TypedObject>().TypeIndex = int.Parse(data[0]); TypedObject.Type type = GetComponent <TypedObject>().Types[GetComponent <TypedObject>().TypeIndex]; transform.localScale = new Vector3(type.Size.x, type.Size.y, transform.localScale.z); for (int i = 0; i < transform.childCount; i++) { transform.GetChild(i).position = transform.position + transform.GetChild(i).localPosition; } Mesh mesh = Instantiate(GameManager.singleton.OnePlane); mesh.SetUVs(0, new List <Vector2>() { new Vector2(type.MinUV.x, type.MinUV.y), new Vector2(type.MaxUV.x, type.MinUV.y), new Vector2(type.MaxUV.x, type.MaxUV.y), new Vector2(type.MinUV.x, type.MaxUV.y) }); mesh.RecalculateBounds(); mesh.RecalculateNormals(); mesh.RecalculateTangents(); GetComponent <MeshFilter>().mesh = mesh; return(1); }
public void Draw() { target = (GameObject)EditorGUILayout.ObjectField("Target", target, typeof(GameObject), true); size = EditorGUILayout.Vector2IntField("Texture size", new Vector2Int((int)size.x, (int)size.y)); if (GUILayout.Button("Start")) { Container container = JsonUtility.FromJson <Container>(Resources.Load <TextAsset>(target.name).text); TypedObject component = target.GetComponent <TypedObject>(); TypedObject.Type[] types = new TypedObject.Type[container.types.Length]; for (int i = 0; i < types.Length; i++) { Object type = container.types[i]; types[i] = new TypedObject.Type( new Vector2(type.width, type.height), new Vector2(type.offset.x / size.x, (size.y - type.offset.y - type.height) / size.y), new Vector2((type.offset.x + type.width) / size.x, (size.y - type.offset.y) / size.y) ); } component.Types = types; } }
public static GameObject SetupRoomObject(GameObject go, RoomObject obj) { go.name = obj.prefabName + "_" + obj.ID; go.transform.localPosition = new Vector3(obj.coords.x, obj.coords.y, go.transform.localPosition.z); SpawnedData spawnedData = go.GetComponent <SpawnedData>(); if (obj.data != null && obj.data.Length != 0) { if (spawnedData == null) { Debug.LogError("Spawned prefab not have SpawnedData script: " + go.name); return(null); } spawnedData.spawnedData = obj.data; } if (spawnedData != null) { spawnedData.roomObject = obj; } if (go.GetComponent <TypedObject>() != null) { TypedObject.Type type = go.GetComponent <TypedObject>().Types[obj.type]; go.GetComponent <TypedObject>().TypeIndex = obj.type; go.transform.localScale = new Vector3(type.Size.x, type.Size.y, go.transform.localScale.z); for (int i = 0; i < go.transform.childCount; i++) { go.transform.GetChild(i).position = go.transform.position + go.transform.GetChild(i).localPosition; } Mesh mesh = MonoBehaviour.Instantiate(GameManager.singleton.OnePlane); mesh.SetUVs(0, new List <Vector2>() { new Vector2(type.MinUV.x, type.MinUV.y), new Vector2(type.MaxUV.x, type.MinUV.y), new Vector2(type.MaxUV.x, type.MaxUV.y), new Vector2(type.MinUV.x, type.MaxUV.y) }); go.GetComponent <MeshFilter>().mesh = mesh; } MeshFilter filter = go.GetComponent <MeshFilter>(); if (filter != null && filter.mesh != null) { Mesh mesh = filter.mesh; mesh.RecalculateBounds(); mesh.RecalculateNormals(); mesh.RecalculateTangents(); } if (obj.mirrorX) { Vector3[] a = go.GetComponent <MeshFilter>().mesh.vertices; a = null; } go.transform.localScale = new Vector3(go.transform.localScale.x * (obj.mirrorX ? -1 : 1), go.transform.localScale.y * (obj.mirrorY ? -1 : 1), go.transform.localScale.z); if (filter != null && filter.mesh != null) { try { go.transform.position += new Vector3( obj.mirrorX ? (filter.mesh.vertices[1].x - filter.mesh.vertices[0].x) * -go.transform.localScale.x : 0, obj.mirrorY ? (filter.mesh.vertices[2].y - filter.mesh.vertices[0].y) * -go.transform.localScale.y : 0, 0); // mark } catch (IndexOutOfRangeException e) { Debug.Log("OutOfRange"); } } int childCount = go.transform.childCount; if (go.GetComponent <SimpleObject>().NotMirrorChildrensOnSpawn) { for (int i = 0; i < childCount; i++) { go.transform.GetChild(i).localScale = new Vector3(go.transform.GetChild(i).localScale.x *(obj.mirrorX ? -1 : 1), go.transform.GetChild(i).localScale.y *(obj.mirrorY ? -1 : 1), go.transform.GetChild(i).localScale.z); } } return(go); }