Changing Unity Source Code

I’m trying to gain access to the getSelectedString function within the InputField.cs file in the UI source code. I’m following the instructions on the bitbucket page on how to put the new .dll file in the Unity editor file structure. All I have done is changed the “protected string GetSelectedString()” to “public string GetSelectedString()”
I did a build and cleared all errors. I put the resulted .dll files from the output folder to the unity editor folder per bitbucket’s instructions.
Now, when I try to call this function in code it will not recognize the function. For instance:

public void HighlightedText()
{
Debug.Log(inputfield.GetSelectedString());
}

it errors out not knowing what .GetSelectedString() is.

Any suggestions?

There are 2 versions of the UnityEngine.UI.dll extension. They are all located under

/UnityInstallFolder/Editor/Data/UnityExtensions/Unity/GUISystem/

The second version is inside the Standalone subfolder. I’m not sure what’s different in those two version (they have different filesize) and which one is used in the editor / in a build, but it’s possible that you didn’t replaced the correct one.

Apart from that you can easily access the selected string by using an extension method and implement a similar method that extracts the selected string.

using UnityEngine;
using UnityEngine.UI;

namespace UnityEngine.UI.Extensions
{
    public static class InputFieldExtension
    {
        public static string GetSelection(this InputField aField)
        {
            if (aField == null)
                return "";
            int start = aField.selectionAnchorPosition;
            int end = aField.selectionFocusPosition;
            int len = end - start;
            if (len == 0)
                return "";
            if (len < 0)
            {
                start = end;
                len = -len;
            }
            return aField.text.Substring(start, len);
        }
    }
}