public void InitializeData()
        {
            //if (Collection.transform.childCount > 0)
            //    return;

            // 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>()
            {
                { "alkali metal", MatAlkaliMetal },
                { "alkaline earth metal", MatAlkalineEarthMetal },
                { "transition metal", MatTransitionMetal },
                { "metalloid", MatMetalloid },
                { "diatomic nonmetal", MatDiatomicNonmetal },
                { "polyatomic nonmetal", MatPolyatomicNonmetal },
                { "post-transition metal", MatPostTransitionMetal },
                { "noble gas", MatNobleGas },
                { "actinide", MatActinide },
                { "lanthanide", MatLanthanide },
            };


            if (isFirstRun == true)
            {
                // Insantiate the element prefabs in their correct locations and with correct text
                foreach (ElementData element in elements)
                {
                    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)
                {
                    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);
            }
        }
Ejemplo n.º 2
0
        void OnEnable()
        {
            if (Collection.transform.childCount > 0)
            {
                return;
            }

            Debug.Log("Creating arrangement");

            Dictionary <string, Material> typeMaterials = new Dictionary <string, Material>()
            {
                { "alkali metal", MatAlkaliMetal },
                { "alkaline earth metal", MatAlkalineEarthMetal },
                { "transition metal", MatTransitionMetal },
                { "metalloid", MatMetalloid },
                { "diatomic nonmetal", MatDiatomicNonmetal },
                { "polyatomic nonmetal", MatPolyatomicNonmetal },
                { "post-transition metal", MatPostTransitionMetal },
                { "noble gas", MatNobleGas },
                { "actinide", MatActinide },
                { "lanthanide", MatLanthanide },
            };

            // Parse the elements out of the json file
            TextAsset          asset    = Resources.Load <TextAsset>("JSON/PeriodicTableJSON");
            List <ElementData> elements = ElementsData.FromJSON(asset.text).elements;

            // Insantiate the element prefabs in their correct locations and with correct text
            foreach (ElementData element in elements)
            {
                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, Collection.Radius);
                newElement.transform.localRotation = Quaternion.identity;
            }

            // Store this configuration in the dynamic collection so we can retrieve it later
            Collection.GetComponent <ObjectCollectionDynamic>().StoreArrangement();
        }