Exemple #1
0
 /// <summary>
 /// Deactivate shift mode on a button
 /// </summary>
 public void DeactivateShiftModeOnKey(KeyboardButton key)
 {
     foreach (var button in m_Buttons)
     {
         if (button == key)
         {
             button.SetShiftModeActive(false);
         }
     }
 }
        /// <summary>
        /// Check for colliders that are keyboard keys.
        /// </summary>
        public void CheckForKeyCollision()
        {
            if (!m_Open)
            {
                return;
            }

            if (m_CurrentButton != null)
            {
                m_CurrentButton.OnTriggerStay(m_BulbCollider);
            }

            var            shortestDistance = Mathf.Infinity;
            KeyboardButton hitKey           = null;

            Collider[] hitColliders = Physics.OverlapSphere(m_Bulb.position, m_BulbRadius);
            foreach (var col in hitColliders)
            {
                var key = col.GetComponentInParent <KeyboardButton>();
                if (key != null)
                {
                    var newDist = Vector3.Distance(m_Bulb.position, key.transform.position);
                    if (newDist < shortestDistance)
                    {
                        hitKey = key;
                    }
                }
            }

            if (m_CurrentButton != hitKey)
            {
                if (m_CurrentButton != null)
                {
                    m_CurrentButton.OnTriggerExit(m_BulbCollider);
                }

                m_CurrentButton = hitKey;

                if (m_CurrentButton != null)
                {
                    m_CurrentButton.OnTriggerEnter(m_BulbCollider);
                }
            }
        }
        public override void OnInspectorGUI()
        {
            m_KeyboardButton = (KeyboardButton)target;

            serializedObject.Update();

            EditorGUILayout.PropertyField(m_SelectionFlagsProperty);

            var updateObjectName = false;

            EditorGUI.BeginChangeCheck();
            CharacterField("Primary Character", m_CharacterProperty, true);
            if (EditorGUI.EndChangeCheck())
            {
                updateObjectName = true;
            }

            EditorGUILayout.PropertyField(m_ButtonTextProperty);

            // Set text component to character
            if (m_KeyboardButton.textComponent != null)
            {
                EditorGUI.BeginChangeCheck();
                if (EditorGUI.EndChangeCheck())
                {
                    UpdateButtonTextAndObjectName(m_CharacterProperty.intValue, updateObjectName);
                }
            }

            // Handle shift character
            m_UseShiftCharacterProperty.boolValue = EditorGUILayout.Toggle("Use Shift Character", m_UseShiftCharacterProperty.boolValue);
            if (m_UseShiftCharacterProperty.boolValue)
            {
                var ch = (char)m_CharacterProperty.intValue;
                if (ch >= k_LowercaseStart && ch <= k_LowercaseEnd)
                {
                    var upperCase = ((char)m_CharacterProperty.intValue).ToString().ToUpper();
                    m_ShiftCharIsUppercase = upperCase.Equals(((char)m_ShiftCharacterProperty.intValue).ToString());
                    EditorGUI.BeginChangeCheck();
                    m_ShiftCharIsUppercase = EditorGUILayout.Toggle("Shift Character is Uppercase", m_ShiftCharIsUppercase);
                    if (EditorGUI.EndChangeCheck())
                    {
                        m_ShiftCharacterProperty.intValue = m_ShiftCharIsUppercase ? upperCase[0] : 0;
                    }
                }
                else
                {
                    m_ShiftCharIsUppercase = false;
                }

                if (!m_ShiftCharIsUppercase)
                {
                    CharacterField("Shift Character", m_ShiftCharacterProperty, false);
                }
            }
            else
            {
                m_ShiftCharIsUppercase = false;
            }

            EditorGUILayout.PropertyField(m_ButtonMeshProperty);
            EditorGUILayout.PropertyField(m_RepeatOnHoldProperty);
            EditorGUILayout.PropertyField(m_WorkspaceButtonProperty);

            if (GUILayout.Button("Create layout transfrom"))
            {
                // Get position in hierarchy
                var siblingIndex = 0;
                foreach (Transform child in m_KeyboardButton.transform.parent)
                {
                    if (child == m_KeyboardButton.transform)
                    {
                        break;
                    }
                    siblingIndex++;
                }

                var t = new GameObject(m_KeyboardButton.name + "_LayoutPosition").transform;
                t.SetParent(m_KeyboardButton.transform);
                t.localPosition = Vector3.zero;
                t.localRotation = Quaternion.identity;
                t.localScale    = Vector3.one;
                t.SetParent(m_KeyboardButton.transform.parent);
                t.transform.SetSiblingIndex(siblingIndex);
            }

            serializedObject.ApplyModifiedProperties();
        }