Example #1
0
    public void OnBeginDrag(PointerEventData pointerDrag)
    {
        newObject = objectPool.GetObject();
        newObject.transform.position = this.transform.position + new Vector3(30, -30, 0);
        newObject.transform.SetParent(this.transform, true);

        // make sure orientation is correct
        int check = (int)Mathf.Round(newObject.transform.localScale.x);

        if (check == -1)
        {
            newObject.transform.Find("Image").localScale = new Vector3(1, 1, 1);
            newObject.transform.Find("Image").gameObject.GetComponent <Image>().color = new Color32(255, 255, 255, 255);
        }

        if (typeOfItems == Draggable.Slot.Value)
        {
            newObject.GetComponent <HasValue>().SetValue(1);
        }
        else if (typeOfItems == Draggable.Slot.Variable)
        {
            newObject.GetComponent <HasValue>().SetValue(gameController.GetEquation().variableValue);
        }

        if (newObject.transform.Find("Coefficient") != null)
        {
            Coefficient coef = newObject.transform.Find("Coefficient").gameObject.GetComponent <Coefficient>();
            coef.SetValue(1);
        }

        childScript = newObject.GetComponent <Draggable>();
        childScript.ShowOnPositiveSide();
        childScript.Start();
        childScript.typeOfItem     = typeOfItems;
        childScript.gameController = gameController;
        childScript.OnBeginDrag(pointerDrag);
        childScript.parentToReturnTo = this.gameObject.transform;
    }
Example #2
0
    // when a term has been dropped on it react accordingly
    public void TermDroppedOn(bool alreadyDropped = true)
    {
        string dragData = "Bracket Coefficient dragged onto Bracket Inside Term " + numDroppedOn.ToString();

        dataController.StoreDragData(dragData);


        if (alreadyDropped)
        {
            numDroppedOn++;

            if (numDroppedOn == numTerms)
            {
                // we have successfully expanded the bracket
                Debug.Log("Expanded");
                soundEffects.PlayExpanded();

                int i           = 0;
                int numChildren = this.gameObject.transform.Find("TermsInBracket").childCount;
                while (i < numChildren)
                {
                    Transform child = this.gameObject.transform.Find("TermsInBracket").GetChild(i);

                    // multiply out coefficients
                    Coefficient coef    = child.Find("Coefficient").gameObject.GetComponent <Coefficient>();
                    Fraction    newCoef = coef.GetFractionValue() * this.gameObject.transform.Find("Coefficient").gameObject.GetComponent <Coefficient>().GetFractionValue();
                    coef.SetValue(newCoef);

                    // reset as draggable
                    // child.gameObject.GetComponent<Draggable>().SetBracketStatus(false);
                    Destroy(child.gameObject.transform.Find("Coefficient").GetComponent <BracketInsideCoefficient>());

                    i++;
                }

                // update arrows
                Coefficient coeff = this.gameObject.transform.Find("Coefficient").gameObject.GetComponent <Coefficient>();

                arrow1.gameObject.SetActive(true);
                arrow1.sprite = solidArrow;
                arrow1Text.SetActive(true);
                arrow1Text.transform.Find("Text").gameObject.GetComponent <Text>().text = coeff.GetValue().ToString() + "x";

                arrow2.gameObject.SetActive(true);
                arrow2.gameObject.GetComponent <Image>().sprite = solidArrow;
                arrow2Text.SetActive(true);
                arrow2Text.transform.Find("Text").gameObject.GetComponent <Text>().text = coeff.GetValue().ToString() + "x";

                coeff.SetValue(1);
                expanded = true;
            }
            else // first drop
            {
                soundEffects.PlayOneDragged();

                // show the arrows
                double coef = this.transform.Find("Coefficient").gameObject.GetComponent <Coefficient>().GetValue();
                if (this.transform.Find("TermsInBracket").GetChild(0).Find("Coefficient").gameObject.GetComponent <BracketInsideCoefficient>().droppedOn)
                {
                    // first item in bracket was dropped on
                    arrow1.gameObject.SetActive(true);
                    arrow1.sprite = solidArrow;
                    arrow1Text.SetActive(true);
                    arrow1Text.transform.Find("Text").gameObject.GetComponent <Text>().text = coef.ToString() + "x";

                    arrow2.gameObject.SetActive(true);
                    arrow2.gameObject.GetComponent <Image>().sprite = dashedArrow;
                }
                else
                {
                    arrow2.gameObject.SetActive(true);
                    arrow2.sprite = solidArrow;
                    arrow2Text.SetActive(true);
                    arrow2Text.transform.Find("Text").gameObject.GetComponent <Text>().text = coef.ToString() + "x";

                    arrow1.gameObject.SetActive(true);
                    arrow1.gameObject.GetComponent <Image>().sprite = dashedArrow;
                }
            }
        }
    }