public void randomRecipe() { // Parse the elements out of the json file TextAsset asset = Resources.Load <TextAsset>("JSON/PeriodicTableJSON"); List <ElementData> elements = ElementsData.FromJSON(asset.text).elements; Dictionary <string, Material> typeMaterials = new Dictionary <string, Material>() { { "sweet", MatTransitionMetal }, { "savory", MatMetalloid }, { "spicy", MatDiatomicNonmetal }, { "salty", MatNobleGas }, { "sour", MatActinide }, { "bitter", MatLanthanide }, }; int index = UnityEngine.Random.Range(0, elements.Count); ElementData element = elements[index]; GameObject newElement = Instantiate <GameObject>(ElementPrefab, Parent); newElement.GetComponentInChildren <Element>().SetFromElementData(element, typeMaterials); newElement.transform.localPosition = new Vector3(element.xpos * ElementSeperationDistance - ElementSeperationDistance * 18 / 2, ElementSeperationDistance * 9 - element.ypos * ElementSeperationDistance, 2.0f); newElement.transform.localRotation = Quaternion.identity; }
public void searchWithDishName(List <string> searchstrs) { // Parse the elements out of the json file TextAsset asset = Resources.Load <TextAsset>("JSON/PeriodicTableJSON"); List <ElementData> elements = ElementsData.FromJSON(asset.text).elements; Dictionary <string, Material> typeMaterials = new Dictionary <string, Material>() { { "sweet", MatTransitionMetal }, { "savory", MatMetalloid }, { "spicy", MatDiatomicNonmetal }, { "salty", MatNobleGas }, { "sour", MatActinide }, { "bitter", MatLanthanide }, }; if (isFirstRun == true) { // Insantiate the element prefabs in their correct locations and with correct text foreach (ElementData element in elements) { if (searchSubStrings(element.name, searchstrs)) { GameObject newElement = Instantiate <GameObject>(ElementPrefab, Parent); newElement.GetComponentInChildren <Element>().SetFromElementData(element, typeMaterials); newElement.transform.localPosition = new Vector3(element.xpos * ElementSeperationDistance - ElementSeperationDistance * 18 / 2, ElementSeperationDistance * 9 - element.ypos * ElementSeperationDistance, 2.0f); newElement.transform.localRotation = Quaternion.identity; } } isFirstRun = false; } else { int i = 0; // Update position and data of existing element objects foreach (Transform existingElementObject in Parent) { if (searchSubStrings(existingElementObject.name, searchstrs)) { existingElementObject.parent.GetComponentInChildren <Element>().SetFromElementData(elements[i], typeMaterials); existingElementObject.localPosition = new Vector3(elements[i].xpos * ElementSeperationDistance - ElementSeperationDistance * 18 / 2, ElementSeperationDistance * 9 - elements[i].ypos * ElementSeperationDistance, 2.0f); existingElementObject.localRotation = Quaternion.identity; i++; } } Parent.localPosition = new Vector3(0.0f, -0.7f, 0.7f); LegendTransform.localPosition = new Vector3(0.0f, 0.15f, 1.8f); } }