/* - - - - - 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"); } }
// 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); } } }
// 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); }