// Create the Save object, and put data to store into it.
    private Save CreateSaveGameObject()
    {
        Save save = new Save();

        save.SaveAttributes(GetAttributesGridValues());

        List <EventFunctionScript> eventFuncs = new List <EventFunctionScript>();
        int numChild = eventFunctionsGrid.transform.childCount;

        for (int i = 0; i < numChild; i++)
        {
            GameObject          eventFuncWhole    = eventFunctionsGrid.transform.GetChild(i).gameObject;
            EventFunctionScript currEventFunction = new EventFunctionScript(eventFuncWhole);
            eventFuncs.Add(currEventFunction);
        }

        save.SaveEventFunctions(eventFuncs.ToArray());

        return(save);
    }
    private void BuildTheEventFunctionGrid(EventFunctionScript[] eventfuncs)
    {
        for (int i = 0; i < eventfuncs.Length; i++)
        {
            GameObject          eventfuncwhole = Instantiate(eventFunctionWhole, eventFunctionsGrid.transform);
            EventFunctionScript currEventFunc  = eventfuncs[i];
            string eventName = currEventFunc.GetEventName();

            // populate event names.
            Transform eventFuncRep = eventfuncwhole.transform.Find("EventFunctionRep");
            eventFuncRep.Find("EventFunctionButton").
            GetComponentInChildren <Text>().text = eventName;
            Transform eventFuncInput = eventfuncwhole.transform.Find("EventFunctionInput");
            eventFuncInput.GetComponent <InputField>().text = eventName;

            // populate the message display.
            Transform msgDisplay = eventFuncInput.Find("MessageDisplay");
            msgDisplay.GetComponent <InputField>().text = currEventFunc.GetMessageDisplay();

            // populate conditional statements.
            Transform conditionGrid = eventFuncInput.Find("Scroll View(Condition)").Find("Viewport").Find("ConditionGrid");
            Destroy(conditionGrid.GetChild(0).gameObject); // remove all child (it has only 1 child by default)
            EventFunctionScript.ConditionScript[] conds = currEventFunc.GetAllConditions();
            for (int j = 0; j < conds.Length; j++)
            {
                // retrieve all saved values for population.
                EventFunctionScript.ConditionScript cond = conds[j];
                int dropdownVal   = cond.dropdownValue;
                int secDropVal    = cond.secondDropdownValue;
                int attributeType = cond.attrType;

                // start populating to real world.
                GameObject conditionalDropdown = Instantiate(condDropdown, conditionGrid);
                conditionalDropdown.GetComponent <Dropdown>().value = dropdownVal;
                Transform condAttachment = conditionalDropdown.transform.Find("ConditionalAttachment");

                if (dropdownVal == 1)  // attribute
                {
                    Transform attrInputCond = condAttachment.GetChild(0);
                    Transform dropdown      = attrInputCond.Find("Dropdown");

                    dropdown.GetComponent <Dropdown>().value = secDropVal;
                    dropdown.GetComponent <DropdownAttributeCondition>().type = attributeType;
                    dropdown.GetComponent <DropdownAttributeCondition>().attributeIndexSelected = secDropVal;
                    if (attributeType == AttributeScript.ATTRIBUTE_TYPE_CONTINUOUS)
                    {
                        int       x1Value        = cond.x1Val;
                        float     y1Percent      = cond.y1Percent;
                        int       x2Value        = cond.x2Val;
                        float     y2Percent      = cond.y2Percent;
                        Transform continuousCase = attrInputCond.Find("ContinuousCase");
                        continuousCase.Find("X(Value)1").GetComponent <InputField>().text   = x1Value.ToString();
                        continuousCase.Find("X(Value)2").GetComponent <InputField>().text   = x2Value.ToString();
                        continuousCase.Find("Y(Percent)1").GetComponent <InputField>().text = y1Percent.ToString();
                        continuousCase.Find("Y(Percent)2").GetComponent <InputField>().text = y2Percent.ToString();
                    }
                    else if (attributeType == AttributeScript.ATTRIBUTE_TYPE_DISCRETE)
                    {
                        float[] percentages = cond.discretePercents;
                        // only update when data is populated.
                        dropdown.GetComponent <DropdownAttributeCondition>().percentagesFeed = percentages;
                    }
                }
            }

            // populate action statements.
            Transform actionGrid = eventFuncInput.Find("Scroll View(Action)").Find("Viewport").Find("ActionGrid");
            Destroy(actionGrid.GetChild(0).gameObject); // remove all child (it has only 1 child by default)
            EventFunctionScript.ActionScript[] actns = currEventFunc.GetAllActions();
            for (int j = 0; j < actns.Length; j++)
            {
                // retrieve all saved values for population.
                EventFunctionScript.ActionScript actn = actns[j];
                int dropdownVal = actn.dropdownValue;
                int secDropVal  = actn.secondDropdownValue;
                int thirdVal    = actn.thirdValue;
                int type        = actn.attrType;

                // start populating to real world.
                GameObject actionDropdown = Instantiate(actnDropdown, actionGrid);
                actionDropdown.GetComponent <Dropdown>().value = dropdownVal;

                Transform actnAttachment = actionDropdown.transform.Find("ActionAttachment");

                if (dropdownVal == 1) // attribute
                {
                    Transform attrInputAction = actnAttachment.GetChild(0);
                    Transform dropdown        = attrInputAction.Find("Dropdown");
                    dropdown.GetComponent <Dropdown>().value = secDropVal;
                    dropdown.GetComponent <DropdownAttributeAction>().type = type;
                    dropdown.GetComponent <DropdownAttributeAction>().attributeIndexSelected = secDropVal;
                    dropdown.GetComponent <DropdownAttributeAction>().thirdValue             = thirdVal;

                    if (type == AttributeScript.ATTRIBUTE_TYPE_CONTINUOUS)
                    {
                        Transform continuousCase = attrInputAction.Find("ContinuousCase");
                        continuousCase.Find("ChangeField").GetComponent <InputField>().text = thirdVal.ToString();
                    }
                    else if (type == AttributeScript.ATTRIBUTE_TYPE_DISCRETE)
                    {
                        Transform discreteCase = attrInputAction.Find("DiscreteCase");
                        discreteCase.Find("Dropdown").GetComponent <Dropdown>().value = thirdVal;
                    }
                }
            }

            // Hide and unhide the necessary so that rep view is shown.
            eventFuncRep.gameObject.SetActive(true);
            eventFuncInput.gameObject.SetActive(false);
        }
    }