Example #1
0
 public static void HandleDetectKeyOnDisable(Object[] targets)
 {
     if (m_detectKeyData != null && targets.Contains(m_detectKeyData.Target))
     {
         m_detectKeyData = null;
     }
 }
Example #2
0
        public static bool HandleDetectKeyOnGUI(Object[] targets, Event current)
        {
            if (m_detectKeyData == null)
            {
                return(false);
            }

            if (targets.Contains(m_detectKeyData.Target) && (current.type == EventType.KeyDown || current.shift))
            {
                KeyCode keyCode = current.shift ? KeyCode.LeftShift : current.keyCode;
                if (keyCode != m_detectKeyData.KeyHandler[m_detectKeyData.KeyIndex] &&
                    EditorUtility.DisplayDialog("Key detected", "Change '" +
                                                m_detectKeyData.KeyHandler[m_detectKeyData.KeyIndex].ToString() +
                                                "' to '" +
                                                keyCode.ToString() +
                                                "'?", "Ok", "Cancel"))
                {
                    m_detectKeyData.KeyHandler[m_detectKeyData.KeyIndex] = keyCode;
                    m_detectKeyData = null;
                    current.Use();
                    return(true);
                }
                else
                {
                    m_detectKeyData = null;
                    foreach (var target in targets)
                    {
                        EditorUtility.SetDirty(target);
                    }
                }
            }

            return(false);
        }
Example #3
0
 public static void HandleDetectKeyOnDisable(object target)
 {
     if (m_detectKeyData != null && m_detectKeyData.Target == target)
     {
         m_detectKeyData = null;
     }
 }
Example #4
0
 /// <summary>
 /// Start/stop detect key given BaseEditor target, enable/disable flag and key index.
 /// </summary>
 /// <param name="target">Target object with BaseEditor custom editor.</param>
 /// <param name="flag">True to enable, false to disable.</param>
 /// <param name="keyIndex">Index of key to detect. </param>
 public void DetectKey(Object target, bool flag, int keyIndex)
 {
     if (flag && IsValidKeyIndex(keyIndex))
     {
         m_detectKeyData = new DetectKeyData()
         {
             Target = target, KeyHandler = this, KeyIndex = keyIndex
         }
     }
     ;
     else
     {
         m_detectKeyData = null;
     }
 }