Exemplo n.º 1
0
        public static void EnterableTextField(SF_Node n, Rect r, ref string str, GUIStyle style, bool update = true)
        {
            if (style == null)
            {
                style = EditorStyles.textField;
            }
            string field_name = n.GetType().ToString() + "_txt_" + n.id;


            GUI.SetNextControlName(field_name);
            EditorGUI.BeginChangeCheck();
            str = EditorGUI.TextField(r, str, style);

            bool pressedEnter = Event.current.keyCode == KeyCode.Return;

            if (update)
            {
                if (pressedEnter)
                {
                    if (GUI.GetNameOfFocusedControl() == field_name)
                    {
                        n.OnUpdateNode(NodeUpdateType.Hard);
                    }
                    EditorGUI.EndChangeCheck();
                }
                else if (EditorGUI.EndChangeCheck())
                {
                    n.OnUpdateNode(NodeUpdateType.Soft);
                }
            }
            else if (EditorGUI.EndChangeCheck())
            {
                n.editor.ShaderOutdated = UpToDateState.OutdatedSoft;
            }
        }
Exemplo n.º 2
0
        public static void EnterableFloatField(SF_Node n, Rect r, ref float val, GUIStyle style)
        {
            if (style == null)
            {
                style = EditorStyles.textField;
            }
            string field_name = n.GetType().ToString() + "_" + n.id;


            GUI.SetNextControlName(field_name);
            EditorGUI.BeginChangeCheck();
            val = EditorGUI.FloatField(r, val, style);


            bool pressedEnter = Event.current.keyCode == KeyCode.Return && Event.current.type == EventType.KeyDown;

            if (pressedEnter)
            {
                EditorGUI.EndChangeCheck();
                //Debug.Log("Pressed enter with focus on " + GUI.GetNameOfFocusedControl() + ", should have been " + field_name);
                if (GUI.GetNameOfFocusedControl() == field_name)
                {
                    //Debug.Log("Pressed enter!");
                    n.OnUpdateNode(NodeUpdateType.Hard);
                }
            }
            else if (EditorGUI.EndChangeCheck())
            {
                n.OnUpdateNode(NodeUpdateType.Soft);
            }
        }