Example #1
0
    //rempli le champ imput avec le symbole selectionné
    public void CompleteIField()
    {
        iField = focusHandler.getCurrentFormule();
        if (iField == null)
        {
            iField = backupField;
        }
        caret = (CaretPos)iField.GetComponent(typeof(CaretPos));

        ClavierEnum clavierEnum = (ClavierEnum)Enum.Parse(typeof(ClavierEnum), symb, true);
        String      realSymb    = GetEnumDescription(clavierEnum);

        caretPos = caret.getCaretPos();
        try
        {
            iField.text = iField.text.Substring(0, caretPos) + realSymb + iField.text.Substring(caretPos);
            caretPos   += realSymb.Length;
            caret.setCaretPos(caretPos);    /* On a ajouter un caractère */
        }
        catch (ArgumentOutOfRangeException) /* Utile si l'utilisateur fait une selection et la supprime */
        {
            iField.text += realSymb;
            caretPos     = iField.text.Length;
            caret.setCaretPos(caretPos);
        }
        iField.Select();
        iField.ActivateInputField();
        StartCoroutine(MoveTextEnd());
    }
Example #2
0
    public void VerifFormule()
    {
        iField = focusHandler.getCurrentFormule();
        output = focusHandler.getCurrentVerif();

        if (string.IsNullOrEmpty(iField.text))
        {
            return;
        }
        try
        {
            Formule     formule = FormuleFactory.parse(iField.text);
            Jardin      jardin  = terrainHandler.getJardin();
            Communicate comm    = new Communicate(SCRIPT_PYTHON, jardin);
            foreach (Element el in jardin.GetElements())
            {
                Debug.Log(el);
            }


            //lance le script
            comm.GetSource().Execute(comm.GetScope());
            object pythonForm = comm.HandleForm(formule);
            Func <Jardin, object> unity_my_interp_formul = comm.GetScope().GetVariable <Func <Jardin, object> >("unity_my_interp_formul");
            object pythonJardin = unity_my_interp_formul(jardin);
            Func <object, object, object> unity_eval_one_form = comm.GetScope().GetVariable <Func <object, object, object> >("unity_eval_one_form");
            var res = unity_eval_one_form(pythonJardin, pythonForm);
            Debug.Log("res=" + res);

            //Affiche résultat
            if ((bool)res == true)
            {
                output.color = Color.green;
                output.text  = "Vrai";
            }
            else
            {
                output.color = Color.red;
                output.text  = "Faux";
            }
        }
        catch (ParserLogException)
        {
            output.color = Color.red;
            output.text  = "Erreur";
            Debug.Log("Erreur formule");
        }
        catch (ValueErrorException)
        {
            output.color = new Color32(255, 128, 0, 255);
            output.text  = "Var libre";
        }
        catch (Exception)
        {
            output.color = Color.red;
            output.text  = "Erreur imprévue";
        }
    }