public void PreviewBox(BoxJSON box) { if (go != null) { GameObject.Destroy(go); } go = new GameObject(); float shelf_size = box == null ? 1 : box.width; //if (shelf_size < 1) { shelf_size = 1; } ShelfJSON shelf_json = new ShelfJSON(); //shelf_json.front_index = new int[] { 3, 0, 1, 2, 3 }; shelf_json.front_index = new int[] { 3, 0 }; shelf_json.x_points = new float[] { -shelf_size, -shelf_size, shelf_size, shelf_size }; shelf_json.y_points = new float[] { -shelf_size, shelf_size, shelf_size, -shelf_size }; shelf_json.boxes = box == null ? new BoxJSON[0] : new BoxJSON[] { box }; shelf_json.thickness = shelf_size / 5.0f; ShelfJSON[] shj_array = new ShelfJSON[] { shelf_json }; StandJSON sj = new StandJSON(); sj.shelves = shj_array; sj.y_start = -1.0f; sj.wall_x = new float[0]; sj.wall_y = new float[0]; StandJSON[] sj_array = new StandJSON[] { sj }; SceneData sd = new SceneData(sj_array); SG = go.AddComponent <SceneGenerator>() as SceneGenerator; SG.transform.parent = this.transform; SG.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f); SG.GenerateScene(sd); shelf_json.boxes[0].cpr = 0.25f; shelf_json.boxes[0].cir = 0; //shelf_json.boxes[0].cil = 0; ShelfGenerator shg = SG.stands[0].shelves[0]; shg.cubes[0].SetStartingPosition(0, 0.25f); /* Camera needs to focus the new object, the position of the new object is not defined till the next * update cycle. Do the camera position update in the next lateupdate */ camera_pos_needs_update = true; }
public void Initialize(ShelfJSON s) { onItemAttachedCallBacks = new List <OnItemAttachedCallback>(); onItemDeattachedCallBacks = new List <OnItemDeattachedCallback>(); onShelfClickedCallBacks = new List <OnShelfClickedCallback>(); onChildProductClickedCallBacks = new List <OnChildProductClickedCallback>(); childs_selected = new List <bool>(); name = s.name; this_shelf = s; transform.localPosition = new Vector3(0, s.absolute_height, 0); transform.localRotation = Quaternion.identity; // Generate new mesh game object shelf_mesh = new GameObject("mesh"); // Calculate the mesh from the raw data MeshGenerator meshGen = new MeshGenerator(s.x_points, s.y_points); Mesh msh = meshGen.get3DMeshFrom2D(-s.thickness); // Render the mesh shelf_mesh.AddComponent(typeof(MeshRenderer)); MeshFilter meshRenderer = shelf_mesh.AddComponent(typeof(MeshFilter)) as MeshFilter; meshRenderer.mesh = msh; shelf_mesh.GetComponent <MeshRenderer>().material = Resources.Load("Materials/StandardTransparent", typeof(Material)) as Material; shelf_mesh.GetComponent <MeshRenderer>().material.color = Color.white; shelf_mesh.GetComponent <Transform>().localScale = new Vector3(1, 1, 1); shelf_mesh.GetComponent <Transform>().SetParent(transform); shelf_mesh.GetComponent <Transform>().localPosition = new Vector3(0, 0, 0); shelf_mesh.GetComponent <Transform>().localRotation = Quaternion.identity; // Enables to pass the on click event to this object shelf_mesh.AddComponent <OnClickPassUp>(); MeshCollider mc = shelf_mesh.AddComponent <MeshCollider>(); mc.sharedMesh = msh; mc.convex = true; mc.isTrigger = true; // Calculate the the points that belong to the front face of the shelf // If none ar given, they are all front face by default if (s.front_index == null) { s.front_index = new int[s.x_points.Length]; for (int p = 0; p < s.front_index.Length; p++) { s.front_index[p] = p; } } Vector3[] vertices = new Vector3[s.front_index.Length]; for (int a = 0; a < vertices.Length; a++) { vertices[a] = new Vector3(s.x_points[s.front_index[a]], 0, s.y_points[s.front_index[a]]); } dragLines = new DragLines(vertices, 0.2f, false); cubes = new List <Drag3D>(); cubesJSON = new List <BoxJSON>(); id2cube = new Dictionary <int, GameObject>(); if (this_shelf.boxes != null) { for (int p = 0; p < this_shelf.boxes.Length; p++) { GameObject new_cube = GenerateProduct(this_shelf.boxes[p]); AttachProduct(this_shelf.boxes[p], new_cube); } } sharedCollisionMap = new CollisionMap2(cubes.ToArray(), dragLines, this); initialized = true; }