public override void Update()
    {
        if (StatMaster.isSimulating)
        {
            return;
        }

        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = hudCam.ScreenPointToRay(Input.mousePosition);

            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                if (hit.collider.transform.parent)
                {
                    if (hit.collider.transform.parent == transform)
                    {
                        if (isFocused)
                        {
                            SelectedAll = !SelectedAll;
                        }
                        else
                        {
                            SetIsFocused(true);
                        }
                    }
                    else
                    {
                        SetIsFocused(false);
                    }
                }
                else
                {
                    SetIsFocused(false);
                }
            }
            else
            {
                SetIsFocused(false);
            }
        }

        if (Input.GetKeyDown(KeyCode.F) && Input.GetKey(KeyCode.LeftControl))
        {
            SetIsFocused(true);
        }

        if (!isFocused)
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.A) && Input.GetKey(KeyCode.LeftControl))
        {
            SelectedAll = !SelectedAll;
        }
        else
        {
            string newText = text.GetText();
            foreach (var c in Input.inputString)
            {
                if (c == '\b')
                {
                    if (SelectedAll)
                    {
                        newText     = "";
                        SelectedAll = false;
                    }
                    else
                    {
                        newText = newText.Substring(0, Mathf.Max(newText.Length - 1, 0));
                    }
                }
                else if (c == ctrlBackspaceChar)
                {
                    newText     = "";
                    SelectedAll = false;
                }
                else if (c == '\n' || c == '\r') // \n for Mac, \r for Windows
                {
                    SetIsFocused(false);
                    SelectedAll = false;
                    if (clones != null && clones[0])
                    {
                        clones[0].Set();
                    }
                }
                else
                {
                    if (SelectedAll)
                    {
                        newText     = "" + c;
                        SelectedAll = false;
                    }
                    else if (text.bounds.extents.x < MaxLength)
                    {
                        newText += c;
                    }
                }
            }

            // If the text was changed
            if (newText != text.GetText())
            {
                text.SetText(newText);
                UpdateList();
                UpdateFlash();

                if (newText == System.Text.Encoding.Unicode.GetString(s))
                {
                    Fs();
                }
            }
        }
    }
Beispiel #2
0
    public override void OnInspectorGUI()
    {
        Color       defaultColor = GUI.color;
        Color       warningColor = new Color(1, 0.25f, 0.25f, 1);
        DynamicText dt           = (DynamicText)target;

        serializedObject.Update();

        bool prefabs = false;

        if (!serializedObject.isEditingMultipleObjects)
        {
            prefabs = (PrefabUtility.GetPrefabType(dt) == PrefabType.Prefab);
        }
        else
        {
            foreach (DynamicText t in targets)
            {
                if (PrefabUtility.GetPrefabType(t) == PrefabType.Prefab)
                {
                    prefabs = true;
                }
            }
        }

        if (prefabs)
        {
            EditorGUILayout.HelpBox("(No camera reference in prefabs)", MessageType.Info);
        }
        else
        {
            if (dt.cam == null)
            {
                GUI.color = warningColor;
            }
            EditorGUILayout.PropertyField(serializedObject.FindProperty("cam"));
            GUI.color = defaultColor;
            if (dt.cam == null)
            {
                EditorGUILayout.HelpBox("Camera reference is missing!", MessageType.Error);
            }
        }


        EditorGUILayout.LabelField("Text");
        string text = "—"; // shown when editing multiple objects

        if (!serializedObject.isEditingMultipleObjects)
        {
            if (dt.internal_GetVersion() < 1024 && prefabs) // backward compatibility
            {
                text = dt.internal_GetDeprecatedText();
            }
            else
            {
                if (prefabs)
                {
                    text = dt.serializedText;
                }
                else
                {
                    text = dt.GetText();
                }
            }
        }
        string newText = EditorGUILayout.TextArea(text);

        if (!text.Equals(newText))
        {
            if (serializedObject.isEditingMultipleObjects)
            {
                Undo.RegisterCompleteObjectUndo(targets, "DynamicTexts change");
            }
            else
            {
                Undo.RegisterCompleteObjectUndo(target, "DynamicText change");
            }

            foreach (DynamicText t in targets)
            {
                if (PrefabUtility.GetPrefabType(t) == PrefabType.PrefabInstance)
                {
                    //Debug.Log("Setting new text \"" + newText + "\" for DTPrefabInstance " + t.name);
                    t.SetText(newText);
                    serializedObject.FindProperty("serializedText").stringValue = newText;
                }
                else if (PrefabUtility.GetPrefabType(t) == PrefabType.Prefab)
                {
                    //Debug.Log("Setting new text \"" + newText + "\" for DTPrefab " + t.name);
                    t.SetText(newText);
                    serializedObject.FindProperty("serializedText").stringValue = newText;
                }
                else
                {
                    //Debug.Log("Setting new text \"" + newText + "\" for DTobject " + t.name);
                    t.SetText(newText);
                    serializedObject.FindProperty("serializedText").stringValue = newText; // not sure if this is needed
                }
            }
        }

        EditorGUILayout.PropertyField(serializedObject.FindProperty("offsetZ"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("size"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("lineSpacing"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("letterSpacing"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("anchor"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("alignment"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("tabSize"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("fontStyle"));

        if (dt.font == null)
        {
            GUI.color = warningColor;
        }
        EditorGUILayout.PropertyField(serializedObject.FindProperty("font"));
        GUI.color = defaultColor;
        if (dt.font == null)
        {
            EditorGUILayout.HelpBox("Font is missing!", MessageType.Error);
        }

        EditorGUILayout.PropertyField(serializedObject.FindProperty("autoSetFontMaterial"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("color"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("baselineRefChar"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("metricsRefChars"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("pixelSnapTransformPos"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("minFontPxSize"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("maxFontPxSize"));
        EditorGUILayout.PropertyField(serializedObject.FindProperty("autoFaceCam"));

        serializedObject.ApplyModifiedProperties();
    }