Exemplo n.º 1
0
 // Update is called once per frame
 void Update()
 {
     // If we have a selected object, update the field
     if (selectedObject != null)
     {
         UpdatePotentialFields updateFields = selectedObject.GetComponent <UpdatePotentialFields>();
         for (int y = 0; y < 30; y++)
         {
             for (int x = 0; x < 30; x++)
             {
                 updateFields.customField[y * 30 + x] = gridArray[y * 30 + x].GetComponent <ChangePixelColor>().charge;
             }
         }
     }
 }
Exemplo n.º 2
0
    public void SetActive(GameObject obj)
    {
        selectedObject = obj;

        bool shouldHide = !selectedObject.GetComponent <UpdatePotentialFields>().IsUsingCustomShape();

        if (shouldHide)
        {
            // Set all inactive, except for the convert to new shape box if shouldn't be active
            bool foundText = false;
            foreach (Transform child in transform)
            {
                if (child.GetComponent <Text>() == null || foundText)
                {
                    child.gameObject.SetActive(false);
                }
                else
                {
                    foundText = true;
                }
            }

            button.SetActive(true);
        }
        else
        {
            // Set all inactive, except for the convert to new shape box if shouldn't be active
            foreach (Transform child in transform)
            {
                child.gameObject.SetActive(true);
            }

            UpdatePotentialFields updateFields = selectedObject.GetComponent <UpdatePotentialFields>();
            // Update canvas
            for (int y = 0; y < 30; y++)
            {
                for (int x = 0; x < 30; x++)
                {
                    gridArray[y * 30 + x].GetComponent <ChangePixelColor>().charge = updateFields.customField[y * 30 + x];

                    // change color based on charge
                    if (gridArray[y * 30 + x].GetComponent <ChangePixelColor>().charge > 0)
                    {
                        float colorFactor = gridArray[y * 30 + x].GetComponent <ChangePixelColor>().charge / 40.0f;
                        Image img         = gridArray[y * 30 + x].GetComponent <Image>();
                        img.color = new Color(0.5f + colorFactor, 0.5f - colorFactor, 0.5f - colorFactor, 1);
                    }
                    else if (gridArray[y * 30 + x].GetComponent <ChangePixelColor>().charge < 0)
                    {
                        float colorFactor = gridArray[y * 30 + x].GetComponent <ChangePixelColor>().charge / 40.0f;
                        Image img         = gridArray[y * 30 + x].GetComponent <Image>();
                        img.color = new Color(0.5f + colorFactor, 0.5f - colorFactor, 0.5f + colorFactor, 1);
                    }
                    else
                    {
                        Image img = gridArray[y * 30 + x].GetComponent <Image>();
                        img.color = new Color(255, 255, 255);
                    }
                }
            }

            button.SetActive(false);
        }
    }