public void OnAddButtonPressed() { BoxJSON b = new BoxJSON(myDB.contents[dbIndex]); b.x_repeats = stack_x; b.y_repeats = stack_y; b.z_repeats = stack_z; Drag3D product = _UItoSimulation.AddProduct(stand_dropdown_index, shelf_dropdown_index, b); if (product != null) { _SimualtionToUI.NotifyNewProductAdded(product); if (productIndexes != null && productIndexes.Length > 0) { bool[] new_index = new bool[productIndexes.Length + 1]; for (int i = 0; i < productIndexes.Length; i++) { new_index[i] = productIndexes[i]; } new_index[productIndexes.Length] = false; productIndexes = new_index; } } // Redraw UI //UpdateUIState(stand_dropdown_index, shelf_dropdown_index, productIndexes, false, true); }
// Attatching/de-attatching products to this shelf // public void AttachProduct(BoxJSON b, GameObject cube) { cube.GetComponent <Drag3D>().BindToParent(this); cubes.Add(cube.GetComponent <Drag3D>()); cubesJSON.Add(b); id2cube.Add(cube.GetInstanceID(), cube); childs_selected.Add(false); cube.GetComponent <Drag3D>().SG = this; cube.transform.parent = this.transform; if (initialized) { sharedCollisionMap.UpdateProducts(cubes.ToArray()); } // Only need to update the UI for the products added after Start() has been executed if (initialized == true) { ExecOnItemAttachedCallbacks(transform.parent.GetComponent <StandGenerator>(), this, cube.GetComponent <Drag3D>()); SetSelected(); sharedCollisionMap.UpdateProducts(cubes.ToArray()); } }
public Drag3D AddProduct(int stand_i, int shelf_i, BoxJSON b) { b.actual_width = b.width * b.x_repeats + ProductAesthetics.BOX_STACK_X_SPACING * b.x_repeats; b.actual_height = b.height * b.y_repeats + ProductAesthetics.BOX_STACK_Y_SPACING * b.y_repeats; b.actual_depth = b.depth * b.z_repeats + ProductAesthetics.BOX_STACK_Z_SPACING * b.z_repeats; if (b != null) { GameObject go = standList[stand_i].shelves[shelf_i].AttachNewProduct(b); if (go != null) { return(go.GetComponent <Drag3D>()); } else { Debug.Log("Could not add product"); return(null); } } else { Debug.LogError("Item not found in database!"); return(null); } }
private Vector3 CalculateCenterPosition(BoxJSON b) { Vector3 right_p = SG.dragLines.points[box.cir] + (SG.dragLines.points[box.cir + 1] - SG.dragLines.points[box.cir]) * box.cpr; Vector3 left_p = SG.dragLines.points[box.cil] + (SG.dragLines.points[box.cil + 1] - SG.dragLines.points[box.cil]) * box.cpl; Vector3 perp_dir = (left_p - right_p).to2DwoY().PerpClockWise().to3DwY(0).normalized; return(right_p + (perp_dir * -box.actual_depth / 2) + ((left_p - right_p) / 2) + new Vector3(0, box.actual_height / 2, 0)); }
private void UpdatePreview() { BoxJSON b = new BoxJSON(myDB.contents[dbIndex]); b.x_repeats = stack_x; b.y_repeats = stack_y; b.z_repeats = stack_z; previewController.PreviewBox(b); }
public Vector2 GetRightVertextPosition(BoxJSON b) { if (b.cir >= points.Length) { return(points[points.Length - 1]); } else { return(points[b.cir] + (points[b.cir + 1] - points[b.cir]) * b.cpr); } }
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 BoxJSON SearchItemByID(int ID) { dbconn = (IDbConnection) new SqliteConnection("URI=file:" + DB_PATH); // the connection requires that prefix dbconn.Open(); //Open connection to the database. IDbCommand dbcmd = dbconn.CreateCommand(); // Partial coincidence query string sqlQuery = SELECT_ALL + PRODUCT_TABLE + " WHERE ID = @param"; dbcmd.CommandText = sqlQuery; // Requires % around search word to look for it in any substring of the products' names dbcmd.Parameters.Add(new SqliteParameter("@param", ID)); List <String> return_items = new List <String>(); DBItem aux = new DBItem(); IDataReader reader = dbcmd.ExecuteReader(); while (reader.Read()) { // Get the variables form the entry of the reader int id = reader.GetInt32(0); string name = reader.GetString(1); float width = reader.GetFloat(2); float height = reader.GetFloat(3); float depth = reader.GetFloat(4); string img_path = reader.GetString(5); Debug.Log("found = " + name); aux.ID = id; aux.name = name; aux.width = width; aux.height = height; aux.depth = depth; aux.img_path = img_path; } BoxJSON found = new BoxJSON(aux); // DB Closing reader.Close(); reader = null; dbcmd.Dispose(); dbcmd = null; dbconn.Close(); dbconn = null; return(found); }
/* - - - - - NON-STATIC METHODS - - - - - */ public void Initialize(BoxJSON b) { box = b; onMyCollisionEnterCallbacks = new List <OnMyCollisionEnterCallback>(); onMyCollisionExitCallbacks = new List <OnMyCollisionExitCallback>(); onDragStartCallBacks = new List <OnDragStartCallback>(); onDragEndCallBacks = new List <OnDragEndCallback>(); PA = gameObject.GetComponent <ProductAesthetics>(); if (PA == null) { Debug.LogError("Product Aesthetics not present"); } }
public GameObject AttachNewProduct(BoxJSON b) { BoxJSON out_box; if (sharedCollisionMap.FindNextEmptySpace(b, out out_box)) { GameObject go = this.GenerateProduct(out_box); AttachProduct(out_box, go); go.GetComponent <Drag3D>().SetStartingPosition(); return(go); } else { return(null); } }
public void Initialize(BoxJSON box, Drag3D D3D) { this.box = box; this.D3D = D3D; if (D3D != null) { D3D.RegisterOnMyCollisionEnterCallback(OnMyCollisionEnter); D3D.RegisterOnMyCollisionExitCallback(OnMyCollisionExit); D3D.RegisterOnDragStartCallback(OnDragStart); D3D.RegisterOnDragEndCallback(OnDragEnd); } else { Debug.LogError("Null D3D in Product Aesthetics"); } }
// If in group controller mode all it will do is spread the "messages" from the UI to each individual cubes public void InitializeAsGroupController(BoxJSON box, Drag3D D3D) { this.box = box; this.D3D = D3D; IS_GROUP_CONTROLLER = true; paChilds = new List <ProductAesthetics>(); // Count all the childs foreach (Transform child in transform) { ProductAesthetics pa = child.GetComponent <ProductAesthetics>(); if (pa != null) { paChilds.Add(pa); } } }
public BoxJSON Copy() { BoxJSON copy = new BoxJSON(); copy.width = this.width; copy.height = this.height; copy.depth = this.depth; copy.name = this.name; copy.img_path = this.img_path; copy.actual_width = this.actual_width; copy.actual_height = this.actual_height; copy.actual_depth = this.actual_depth; copy.x_repeats = this.x_repeats; copy.y_repeats = this.y_repeats; copy.z_repeats = this.z_repeats; return(copy); }
public bool WouldBoxColide(BoxJSON cube) { /* Check if this new hypothetical box would colide */ /* This new box is not placed in the world yet, so we need to obtain the vertices positon in a new way */ Vector2[] vertices = new Vector2[4]; /* Vertices 0 and 3 we can know straigh away since they are on the dragline */ vertices[0] = (draglines.points[cube.cil] + (draglines.points[cube.cil + 1] - draglines.points[cube.cil]) * cube.cpl).to2DwoY(); vertices[3] = (draglines.points[cube.cir] + (draglines.points[cube.cir + 1] - draglines.points[cube.cir]) * cube.cpr).to2DwoY(); /* Calculate the remaning ones */ Vector2 normal = (vertices[0] - vertices[3]).PerpClockWise(); vertices[1] = vertices[0] + (-normal.normalized) * cube.actual_depth; vertices[2] = vertices[3] + (-normal.normalized) * cube.actual_depth; vertices[0] = SG.transform.TransformPoint(vertices[0].to3DwY(0)).to2DwoY(); vertices[1] = SG.transform.TransformPoint(vertices[1].to3DwY(0)).to2DwoY(); vertices[2] = SG.transform.TransformPoint(vertices[2].to3DwY(0)).to2DwoY(); vertices[3] = SG.transform.TransformPoint(vertices[3].to3DwY(0)).to2DwoY(); /* Use the shelf transform to get world coordinates */ for (int i = 0; i < cubes.Length; i++) { Vector2[] other_vertices; cubes[i].GetBottomVertices(out other_vertices); if (MiscFunc.BoxesColide2D(vertices, other_vertices)) { return(true); } } return(false); }
// Generation of products // public GameObject GenerateProduct(BoxJSON box) { GameObject gocube; if (box.x_repeats == 1 && box.y_repeats == 1 && box.z_repeats == 1) { gocube = GameObject.CreatePrimitive(PrimitiveType.Cube); gocube.transform.localScale = new Vector3(box.width, box.height, box.depth); Drag3D d3d = gocube.AddComponent(typeof(Drag3D)) as Drag3D; ProductAesthetics pa = gocube.AddComponent <ProductAesthetics>(); d3d.Initialize(box); // Make it so there is always at least a very small gap in betwwen cubes gocube.GetComponent <BoxCollider>().size *= 1.05f; gocube.GetComponent <BoxCollider>().isTrigger = true; pa.Initialize(box, d3d); gocube.name = box.name; Rigidbody rb = gocube.AddComponent <Rigidbody>(); rb.isKinematic = true; rb.useGravity = false; } else { gocube = new GameObject(); List <GameObject> gos = new List <GameObject>(); Vector3 final_size = new Vector3(box.actual_width, box.actual_height, box.actual_depth); Vector3 original_size = new Vector3(box.width, box.height, box.depth); for (int x = 0; x < box.x_repeats; x++) { for (int y = 0; y < box.y_repeats; y++) { for (int z = 0; z < box.z_repeats; z++) { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube); go.transform.localPosition = new Vector3(box.width * x + ProductAesthetics.BOX_STACK_X_SPACING * x, box.height * y + ProductAesthetics.BOX_STACK_Y_SPACING * y, box.depth * z + ProductAesthetics.BOX_STACK_Y_SPACING * z) - final_size / 2 + original_size / 2; go.transform.localScale = original_size; go.transform.SetParent(gocube.transform); go.GetComponent <BoxCollider>().enabled = false; gos.Add(go); } } } Drag3D d3d = gocube.AddComponent(typeof(Drag3D)) as Drag3D; ProductAesthetics pae = gocube.AddComponent <ProductAesthetics>(); d3d.Initialize(box); // Make it so there is always at least a very small gap in betwwen cubes //gocube.GetComponent<BoxCollider>().size *= 1.05f; foreach (GameObject go in gos) { ProductAesthetics pa = go.AddComponent <ProductAesthetics>(); pa.Initialize(box, d3d); } pae.InitializeAsGroupController(box, d3d); gocube.AddComponent <BoxCollider>(); gocube.GetComponent <BoxCollider>().center = Vector3.zero; gocube.GetComponent <BoxCollider>().size = final_size; gocube.GetComponent <BoxCollider>().isTrigger = true; gocube.transform.localScale = Vector3.one; gocube.name = box.name; Rigidbody rb = gocube.AddComponent <Rigidbody>(); rb.isKinematic = true; rb.useGravity = false; } return(gocube); }
public bool FindNextEmptySpace(BoxJSON sizes, out BoxJSON out_box) { /* Find the next empty space in the draglines */ out_box = null; if (cubes.Length == 0) { out_box = sizes.Copy(); out_box.cir = 0; out_box.cpr = 0.01f; draglines.CalculateMatchingPoint(out_box.cir, out_box.cpr, out_box.actual_width, true, ref out_box.cil, ref out_box.cpl); return(true); } else { /* Sort the cubes according to their positions right to left */ List <Drag3D> ordered = new List <Drag3D>(); for (int i = 0; i < cubes.Length; i++) { ordered.Add(cubes[i]); } ordered.Sort(Drag3D.CompareByPosition); /* Check if it ispossible to add it to the right of the first product */ for (int i = 0; i < ordered.Count; i++) { out_box = sizes.Copy(); out_box.cir = ordered[i].box.cil; out_box.cpr = ordered[i].box.cpl; draglines.CalculateMatchingPoint(out_box.cir, out_box.cpr, out_box.actual_width, true, ref out_box.cil, ref out_box.cpl); /* While we haven't reached the next box ... or the end of the draglines */ while ( i == ordered.Count - 1 ? /* last index in draglines and position is at the end */ !(out_box.cil == draglines.points.Length - 1 && out_box.cpl < 0.99f): /* stepped into the next product */ (out_box.cil < ordered[i + 1].box.cir || (out_box.cil == ordered[i + 1].box.cir && out_box.cpl < ordered[i + 1].box.cpr))) { // OPTION TO CONSIDER draglines.MoveInDragline(ref out_box.cil,ref out_box.cpl, draglines.points[out_box.cil], ref 5); /* If we can fit the rigth vertex of the product in this dragline */ if (out_box.cpl <= 0.99f) { out_box.cpl += 0.01f; } /* Use the next dragline if it is not the last one */ else if (out_box.cil != draglines.points.Length - 2) { out_box.cil += 1; out_box.cpl = 0; } /* No draglines left, can't fit the product */ else { break; } draglines.CalculateMatchingPoint(out_box.cil, out_box.cpl, out_box.actual_width, false, ref out_box.cir, ref out_box.cpr); /* Temporarily position it to the right of the product and check if it fits */ if (!WouldBoxColide(out_box)) { /* Found a position which does't colide */ return(true); } } } return(false); } }
public void AttachProduct2(BoxJSON b, GameObject cube) { }
public Vector2 GetLeftVertextPosition(BoxJSON b) { return(points[b.cil] + (points[b.cil + 1] - points[b.cil]) * b.cpl); }