示例#1
0
        public override void OnInspectorGUI()
        {
            Init();

            serializedObject.Update();

            GUILayout.Space(6f);
            ActionDelegateEditor.SetLabelWidth(80f);

            GUILayout.BeginHorizontal();

            SerializedProperty sp = ActionDelegateEditor.DrawProperty("Key", serializedObject, "key");

            string currentKey = sp.stringValue;
            bool   isPresent  = keys != null && Array.Exists(keys, item => item == currentKey);

            GUI.color = isPresent ? Color.green : Color.red;
            GUILayout.BeginVertical(GUILayout.Width(22f));
            GUILayout.Space(2f);
            GUILayout.Label(isPresent ? "\u2714" : "\u2718", GUILayout.Height(20f));
            GUILayout.EndVertical();
            GUI.color = Color.white;
            GUILayout.EndHorizontal();

            if (isPresent)
            {
                if (ActionDelegateEditor.DrawHeader("Preview"))
                {
                    ActionDelegateEditor.BeginContents();

                    foreach (KeyValuePair <string, Dictionary <string, string> > pair in Localization.LocalizationData)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label(pair.Key, GUILayout.Width(66f));

                        if (GUILayout.Button(pair.Value[currentKey], "TextArea", GUILayout.MinWidth(80f),
                                             GUILayout.MaxWidth(Screen.width - 110f)))
                        {
                            (target as BaseLocalize).Localize(pair.Value[currentKey]);
                            GUIUtility.hotControl      = 0;
                            GUIUtility.keyboardControl = 0;
                        }

                        GUILayout.EndHorizontal();
                    }

                    ActionDelegateEditor.EndContents();
                }
            }
            else if (keys != null && !string.IsNullOrEmpty(currentKey))
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(80f);
                GUILayout.BeginVertical();
                GUI.backgroundColor = new Color(1f, 1f, 1f, 0.35f);

                int matches = 0;

                for (int i = 0, imax = keys.Length; i < imax; ++i)
                {
                    if (keys[i].StartsWith(currentKey, StringComparison.OrdinalIgnoreCase) ||
                        keys[i].Contains(currentKey))
                    {
                        if (GUILayout.Button(keys[i] + " \u25B2", "CN CountBadge"))
                        {
                            sp.stringValue             = keys[i];
                            GUIUtility.hotControl      = 0;
                            GUIUtility.keyboardControl = 0;
                        }

                        if (++matches == 8)
                        {
                            GUILayout.Label("...and more");
                            break;
                        }
                    }
                }

                GUI.backgroundColor = Color.white;
                GUILayout.EndVertical();
                GUILayout.Space(22f);
                GUILayout.EndHorizontal();
            }

            serializedObject.ApplyModifiedProperties();
        }
示例#2
0
        public override void OnInspectorGUI()
        {
            PropertySync pb = target as PropertySync;

            ActionDelegateEditor.SetLabelWidth(80f);

            serializedObject.Update();

            if (pb.direction == PropertySync.Direction.TargetUpdatesSource && pb.target != null)
            {
                PropertyBindingReferenceDrawer.filter = pb.target.GetPropertyType();
            }

            GUILayout.Space(3f);
            PropertySync.Direction dir = (target as PropertySync).direction;

            PropertyBindingReferenceDrawer.mustRead = dir == PropertySync.Direction.SourceUpdatesTarget ||
                                                      dir == PropertySync.Direction.BiDirectional;
            PropertyBindingReferenceDrawer.mustWrite = dir == PropertySync.Direction.TargetUpdatesSource ||
                                                       dir == PropertySync.Direction.BiDirectional;

            ActionDelegateEditor.DrawProperty(serializedObject, "source");

            if (pb.direction == PropertySync.Direction.SourceUpdatesTarget && pb.source != null)
            {
                PropertyBindingReferenceDrawer.filter = pb.source.GetPropertyType();
            }

            if (pb.source.target != null)
            {
                GUILayout.Space(-18f);

                if (pb.direction == PropertySync.Direction.TargetUpdatesSource)
                {
                    GUILayout.Label("   \u25B2"); // Up
                }
                else if (pb.direction == PropertySync.Direction.SourceUpdatesTarget)
                {
                    GUILayout.Label("   \u25BC"); // Down
                }
                else
                {
                    GUILayout.Label("  \u25B2\u25BC");
                }
            }

            GUILayout.Space(1f);

            PropertyBindingReferenceDrawer.mustRead = dir == PropertySync.Direction.TargetUpdatesSource ||
                                                      dir == PropertySync.Direction.BiDirectional;
            PropertyBindingReferenceDrawer.mustWrite = dir == PropertySync.Direction.SourceUpdatesTarget ||
                                                       dir == PropertySync.Direction.BiDirectional;

            ActionDelegateEditor.DrawProperty(serializedObject, "target");

            PropertyBindingReferenceDrawer.mustRead  = false;
            PropertyBindingReferenceDrawer.mustWrite = false;
            PropertyBindingReferenceDrawer.filter    = typeof(void);

            GUILayout.Space(1f);
            ActionDelegateEditor.DrawPaddedProperty(serializedObject, "direction");
            ActionDelegateEditor.DrawPaddedProperty(serializedObject, "update");
            GUILayout.BeginHorizontal();
            ActionDelegateEditor.DrawProperty(" ", serializedObject, "editMode", GUILayout.Width(100f));
            GUILayout.Label("Update in Edit Mode");

            if (pb.source.GetPropertyType() == typeof(bool) && pb.target.GetPropertyType() == typeof(bool))
            {
                ActionDelegateEditor.DrawProperty(" ", serializedObject, "invertBool", GUILayout.Width(100f));
                GUILayout.Label("Invert Bool");
            }

            GUILayout.EndHorizontal();

            if (!serializedObject.isEditingMultipleObjects)
            {
                if (pb.source != null && pb.target != null &&
                    pb.source.GetPropertyType() != pb.target.GetPropertyType())
                {
                    if (pb.direction == PropertySync.Direction.BiDirectional)
                    {
                        EditorGUILayout.HelpBox(
                            "Bi-Directional updates require both Source and Target to reference values of the same type.",
                            MessageType.Error);
                    }
                    else if (pb.direction == PropertySync.Direction.SourceUpdatesTarget)
                    {
                        if (!PropertyBindingReference.Convert(pb.source.Get(), pb.target.GetPropertyType()))
                        {
                            EditorGUILayout.HelpBox(
                                "Unable to convert " + pb.source.GetPropertyType() + " to " +
                                pb.target.GetPropertyType(), MessageType.Error);
                        }
                    }
                    else if (!PropertyBindingReference.Convert(pb.target.Get(), pb.source.GetPropertyType()))
                    {
                        EditorGUILayout.HelpBox(
                            "Unable to convert " + pb.target.GetPropertyType() + " to " + pb.source.GetPropertyType(),
                            MessageType.Error);
                    }
                }
            }

            serializedObject.ApplyModifiedProperties();
        }