public PackageController SpawnRandomPackage() { PackageController package = Instantiate(packagePrefab, transform.position, transform.rotation); int shapeEnumValue = Random.Range(0, System.Enum.GetNames(typeof(PackageShape)).Length); PackageShape shape = (PackageShape)shapeEnumValue; package.SetShape(shape); int colorEnumValue = Random.Range(0, System.Enum.GetNames(typeof(PackageColor)).Length); PackageColor color = (PackageColor)colorEnumValue; package.SetColor(color); int layoutEnumValue = Random.Range(0, System.Enum.GetNames(typeof(PackageLayout)).Length); PackageLayout layout = (PackageLayout)layoutEnumValue; package.SetLayout(layout); Rigidbody rb = package.GetComponent <Rigidbody>(); float randomAngle = Random.Range(0.0f, 360.0f); float randomStrength = Random.Range(0.0f, randomImpulseStrength); Vector3 force = transform.rotation * Quaternion.AngleAxis(randomAngle, Vector3.up) * (Vector3.forward * randomStrength); Vector3 randomOffset = new Vector3(Mathf.Sin(Random.Range(0.0f, Mathf.PI * 2.0f)), Mathf.Sin(Random.Range(0.0f, Mathf.PI * 2.0f)), Mathf.Sin(Random.Range(0.0f, Mathf.PI * 2.0f))) * 0.5f; rb.AddForceAtPosition(force, package.transform.position + randomOffset); if (OnPackageSpawned != null) { OnPackageSpawned(this, package); } return(package); }
public void SetLayout(PackageLayout _layout) { packageLayout = _layout; Texture2D t = null; switch (GetShape()) { case PackageShape.Box: { switch (packageLayout) { case PackageLayout.Layout1: t = boxLayout1Texture; break; case PackageLayout.Layout2: t = boxLayout2Texture; break; case PackageLayout.Layout3: t = boxLayout3Texture; break; } } break; case PackageShape.Pyramid: { switch (packageLayout) { case PackageLayout.Layout1: t = pyramidLayout1Texture; break; case PackageLayout.Layout2: t = pyramidLayout2Texture; break; case PackageLayout.Layout3: t = pyramidLayout3Texture; break; } } break; case PackageShape.Flat: { switch (packageLayout) { case PackageLayout.Layout1: t = flatLayout1Texture; break; case PackageLayout.Layout2: t = flatLayout2Texture; break; case PackageLayout.Layout3: t = flatLayout3Texture; break; } } break; case PackageShape.Cylinder: { switch (packageLayout) { case PackageLayout.Layout1: t = cylinderLayout1Texture; break; case PackageLayout.Layout2: t = cylinderLayout2Texture; break; case PackageLayout.Layout3: t = cylinderLayout3Texture; break; } } break; case PackageShape.Rectangle: { switch (packageLayout) { case PackageLayout.Layout1: t = rectangleLayout1Texture; break; case PackageLayout.Layout2: t = rectangleLayout2Texture; break; case PackageLayout.Layout3: t = rectangleLayout3Texture; break; } } break; case PackageShape.Sphere: { switch (packageLayout) { case PackageLayout.Layout1: t = sphereLayout1Texture; break; case PackageLayout.Layout2: t = sphereLayout2Texture; break; case PackageLayout.Layout3: t = sphereLayout3Texture; break; } } break; } layoutObject.material.mainTexture = t; }