private void SaveIngreadiantsPoints() { ingredientsPoints = new List <Vector3>(); ingredientsCenters = new List <Vector3>(); ingredientsCorners = new List <Vector3>(); float[] mainXPoints; float[] mainZPoints; for (int i = 0; i < ingredients.Length; i++) { Transform ingredient = ingredients[i]; Renderer ingredRend = ingredient.GetComponent <Renderer>(); Vector3 center = ingredRend.bounds.center; ingredientsCenters.Add(center); Vector3 point1 = IngredientsScripts.FindPoint(ingredRend, 90); Vector3 point2 = IngredientsScripts.FindPoint(ingredRend, -90); Vector3 point3 = IngredientsScripts.FindPoint(ingredRend, 180); Vector3 point4 = IngredientsScripts.FindPoint(ingredRend, 0); point1.x = (int)point1.x + 1; point1.z = (int)point1.z; point2.x = (int)point2.x + 1; point2.z = (int)point2.z + 1; point3.x = (int)point3.x; point3.z = (int)point3.z; point4.x = (int)point4.x + 1; point4.z = (int)point4.z; ingredientsCorners.Add(point1); ingredientsCorners.Add(point2); ingredientsCorners.Add(point3); ingredientsCorners.Add(point4); mainZPoints = new float[] { point1.z, point3.z, point2.z, point4.z }; mainXPoints = new float[] { point1.x, point3.x, point2.x, point4.x }; int leastZ = (int)Mathf.Min(mainZPoints); int mostZ = (int)Mathf.Max(mainZPoints); int leastX = (int)Mathf.Min(mainXPoints); int mostX = (int)Mathf.Max(mainXPoints); int lenX = (mostX - leastX + 1); int lenZ = (mostZ - leastZ + 1); int len = lenX * lenZ; for (int z = leastZ; z <= mostZ; z++) { for (int x = leastX; x <= mostX; x++) { //TODO: try to exclude exteram oints ex: 3,3 & 7,3 & 3,7 & 7,7 ingredientsPoints.Add(new Vector3(x, center.y, z)); } } } }
public override void OnInspectorGUI() { IngredientsScripts myScript = (IngredientsScripts)target; /* * if(DrawDefaultInspector()) * { * if(myScript.autoUpdate) * myScript.findIngredient(); * } */ if (GUILayout.Button("Find Ingredient")) { //myScript.FindIngredients(); } }