Ejemplo n.º 1
0
        public override VisualElement CreatePropertyGUI(SerializedProperty property)
        {
            Foldout foldout = new Foldout();

            foldout.BindProperty(property);
            foldout.text = property.displayName;

            foldout.contentContainer.Add(new PropertyField(property.FindPropertyRelative("enableFOVKick")));
            foldout.contentContainer.Add(new PropertyField(property.FindPropertyRelative("unscaledTime")));
            foldout.contentContainer.Add(new PropertyField(property.FindPropertyRelative("kickWhen")));
            foldout.contentContainer.Add(new PropertyField(property.FindPropertyRelative("kickAmount")));
            foldout.contentContainer.Add(new PropertyField(property.FindPropertyRelative("lerpTimeTo")));
            foldout.contentContainer.Add(new PropertyField(property.FindPropertyRelative("lerpTimeFrom")));

            foldout.contentContainer.Add(GoldPlayerUIHelper.GetSpace());

            PropertyField targetCamera = new PropertyField(property.FindPropertyRelative("targetCamera"));

#if GOLD_PLAYER_CINEMACHINE
            PropertyField cineToggle = new PropertyField(property.FindPropertyRelative("useCinemachine"));
            PropertyField cineCamera = new PropertyField(property.FindPropertyRelative("targetVirtualCamera"));

            // Put the register value changed in GeometryChangedEvent because then the property will have been rebuilt.
            cineToggle.RegisterCallback <GeometryChangedEvent>(evt =>
            {
                cineToggle.Q <Toggle>().RegisterValueChangedCallback(x =>
                {
                    targetCamera.style.display = x.newValue ? DisplayStyle.None : DisplayStyle.Flex;
                    cineCamera.style.display   = x.newValue ? DisplayStyle.Flex : DisplayStyle.None;
                });
            });

            bool useCinemachine = property.FindPropertyRelative("useCinemachine").boolValue;
            targetCamera.style.display = useCinemachine ? DisplayStyle.None : DisplayStyle.Flex;
            cineCamera.style.display   = useCinemachine ? DisplayStyle.Flex : DisplayStyle.None;

            foldout.contentContainer.Add(cineToggle);
            foldout.contentContainer.Add(cineCamera);
#endif
            foldout.contentContainer.Add(targetCamera);


            return(foldout);
        }
        /// <summary>
        /// UI Toolkit version
        /// </summary>
        /// <param name="property"></param>
        /// <returns></returns>
        public override VisualElement CreatePropertyGUI(SerializedProperty property)
        {
            var code = property.FindPropertyRelative("m_Code");

            var foldout = new Foldout {
                text = "Identifier"
            };

            foldout.BindProperty(property);

            var localeField = new ObjectField {
                objectType = typeof(Locale), value = LocalizationEditorSettings.GetLocale(code.stringValue)
            };

            localeField.AddToClassList("unity-base-field__input");
            localeField.RegisterCallback <MouseDownEvent>(evt => evt.StopPropagation());
            localeField.RegisterCallback <MouseUpEvent>(evt => evt.StopPropagation());
            localeField.RegisterValueChangedCallback(evt =>
            {
                var locale       = evt.newValue as Locale;
                code.stringValue = locale != null ? locale.Identifier.Code : string.Empty;
                code.serializedObject.ApplyModifiedProperties();
            });
            foldout.hierarchy[0].Add(localeField);
            foldout.hierarchy[0].hierarchy[0].RemoveFromClassList("unity-base-field__input");
            foldout.hierarchy[0].hierarchy[0].AddToClassList("unity-base-field__label");

            var codeField = new TextField {
                label = "Code"
            };

            codeField.RegisterValueChangedCallback(evt =>
            {
                localeField.SetValueWithoutNotify(LocalizationEditorSettings.GetLocale(evt.newValue));
            });
            codeField.BindProperty(code);
            foldout.Add(codeField);

            return(foldout);
        }