public BuilderInspectorCanvas(BuilderInspector inspector) { m_Inspector = inspector; m_Document = inspector.document; m_CanvasInspector = m_Inspector.Q(ContainerName); var builderWindow = inspector.paneWindow as Builder; if (builderWindow == null) { return; } m_Canvas = builderWindow.canvas; m_CameraModeEnabled = false; // Size Fields m_CanvasWidth = root.Q <IntegerField>("canvas-width"); m_CanvasWidth.RegisterValueChangedCallback(OnWidthChange); m_CanvasHeight = root.Q <IntegerField>("canvas-height"); m_CanvasHeight.RegisterValueChangedCallback(OnHeightChange); m_Canvas.RegisterCallback <GeometryChangedEvent>(OnCanvasSizeChange); // This allows user to temporarily type values below the minimum canvas size SetDelayOnSizeFieldsEnabled(true); // To update the canvas size as user mouse drags the width or height labels DisableDelayOnActiveLabelMouseDraggers(); m_MatchGameViewToggle = root.Q <Toggle>("match-game-view"); m_MatchGameViewToggle.RegisterValueChangedCallback(OnMatchGameViewModeChanged); m_MatchGameViewHelpBox = root.Q <HelpBox>("match-game-view-hint"); // Background Opacity m_ColorOpacityField = root.Q <PercentSlider>("background-color-opacity-field"); m_ColorOpacityField.RegisterValueChangedCallback(e => { settings.ColorModeBackgroundOpacity = e.newValue; OnBackgroundOpacityChange(e.newValue); }); m_ImageOpacityField = root.Q <PercentSlider>("background-image-opacity-field"); m_ImageOpacityField.RegisterValueChangedCallback(e => { settings.ImageModeCanvasBackgroundOpacity = e.newValue; OnBackgroundOpacityChange(e.newValue); }); m_CameraOpacityField = root.Q <PercentSlider>("background-camera-opacity-field"); m_CameraOpacityField.RegisterValueChangedCallback(e => { settings.CameraModeCanvasBackgroundOpacity = e.newValue; OnBackgroundOpacityChange(e.newValue); }); // Setup Background State m_BackgroundOptionsFoldout = root.Q <FoldoutWithCheckbox>("canvas-background-foldout"); m_BackgroundOptionsFoldout.RegisterCheckboxValueChangedCallback(e => { settings.EnableCanvasBackground = e.newValue; PostSettingsChange(); ApplyBackgroundOptions(); }); // Setup Background Mode var backgroundModeType = typeof(BuilderCanvasBackgroundMode); var backgroundModeValues = Enum.GetValues(backgroundModeType) .OfType <BuilderCanvasBackgroundMode>().Select((v) => v.ToString()).ToList(); m_BackgroundMode = root.Q <ToggleButtonStrip>("background-mode-field"); m_BackgroundMode.enumType = backgroundModeType; m_BackgroundMode.choices = backgroundModeValues; m_BackgroundMode.RegisterValueChangedCallback(OnBackgroundModeChange); // Color field. m_ColorField = root.Q <ColorField>("background-color-field"); m_ColorField.RegisterValueChangedCallback(OnBackgroundColorChange); // Set Image field. m_ImageField = root.Q <ObjectField>("background-image-field"); m_ImageField.objectType = typeof(Texture2D); m_ImageField.RegisterValueChangedCallback(OnBackgroundImageChange); m_ImageScaleModeField = root.Q <ToggleButtonStrip>("background-image-scale-mode-field"); m_ImageScaleModeField.enumType = typeof(ScaleMode); var backgroundScaleModeValues = Enum.GetValues(typeof(ScaleMode)) .OfType <ScaleMode>().Select((v) => BuilderNameUtilities.ConvertCamelToDash(v.ToString())).ToList(); m_ImageScaleModeField.choices = backgroundScaleModeValues; m_ImageScaleModeField.RegisterValueChangedCallback(OnBackgroundImageScaleModeChange); m_FitCanvasToImageButton = root.Q <Button>("background-image-fit-canvas-button"); m_FitCanvasToImageButton.clickable.clicked += FitCanvasToImage; // Set Camera field. m_CameraField = root.Q <ObjectField>("background-camera-field"); m_CameraField.objectType = typeof(Camera); m_CameraField.RegisterValueChangedCallback(OnBackgroundCameraChange); #if !UNITY_2019_4 SetupEditorExtensionsModeToggle(); #else RemoveDocumentSettings(); #endif // Control Containers m_BackgroundColorModeControls = root.Q("canvas-background-color-mode-controls"); m_BackgroundImageModeControls = root.Q("canvas-background-image-mode-controls"); m_BackgroundCameraModeControls = root.Q("canvas-background-camera-mode-controls"); EditorApplication.playModeStateChanged += PlayModeStateChange; }
public BuilderInspectorCanvas(BuilderInspector inspector) { m_Inspector = inspector; m_Document = inspector.document; m_CanvasInspector = m_Inspector.Q("canvas-inspector"); var builderWindow = inspector.paneWindow as Builder; if (builderWindow == null) { return; } m_Canvas = builderWindow.canvas; m_CameraModeEnabled = false; // Size Fields m_CanvasWidth = root.Q <IntegerField>("canvas-width"); m_CanvasWidth.isDelayed = true; m_CanvasWidth.RegisterValueChangedCallback(OnWidthChange); m_CanvasHeight = root.Q <IntegerField>("canvas-height"); m_CanvasHeight.isDelayed = true; m_CanvasHeight.RegisterValueChangedCallback(OnHeightChange); m_Canvas.RegisterCallback <GeometryChangedEvent>(OnCanvasSizeChange); // Background Opacity m_OpacityField = root.Q <PercentSlider>("background-opacity-field"); m_OpacityField.RegisterValueChangedCallback(OnBackgroundOpacityChange); // Setup Background Mode var backgroundModeType = typeof(BuilderCanvasBackgroundMode); var backgroundModeValues = Enum.GetValues(backgroundModeType) .OfType <BuilderCanvasBackgroundMode>().Select((v) => v.ToString()).ToList(); var backgroundModeNames = Enum.GetNames(backgroundModeType); m_BackgroundMode = root.Q <ToggleButtonStrip>("background-mode-field"); m_BackgroundMode.enumType = backgroundModeType; m_BackgroundMode.labels = backgroundModeNames; m_BackgroundMode.choices = backgroundModeValues; m_BackgroundMode.RegisterValueChangedCallback(OnBackgroundModeChange); // Color field. m_ColorField = root.Q <ColorField>("background-color-field"); m_ColorField.RegisterValueChangedCallback(OnBackgroundColorChange); // Set Image field. m_ImageField = root.Q <ObjectField>("background-image-field"); m_ImageField.objectType = typeof(Texture2D); m_ImageField.RegisterValueChangedCallback(OnBackgroundImageChange); m_ImageScaleModeField = root.Q <ToggleButtonStrip>("background-image-scale-mode-field"); m_ImageScaleModeField.enumType = typeof(ScaleMode); var backgroundScaleModeValues = Enum.GetValues(typeof(ScaleMode)) .OfType <ScaleMode>().Select((v) => BuilderNameUtilities.ConvertCamelToDash(v.ToString())).ToList(); m_ImageScaleModeField.choices = backgroundScaleModeValues; m_ImageScaleModeField.RegisterValueChangedCallback(OnBackgroundImageScaleModeChange); m_FitCanvasToImageButton = root.Q <Button>("background-image-fit-canvas-button"); m_FitCanvasToImageButton.clickable.clicked += FitCanvasToImage; // Set Camera field. m_CameraField = root.Q <ObjectField>("background-camera-field"); m_CameraField.objectType = typeof(Camera); m_CameraField.RegisterValueChangedCallback(OnBackgroundCameraChange); // Control Containers m_BackgroundColorModeControls = root.Q("canvas-background-color-mode-controls"); m_BackgroundImageModeControls = root.Q("canvas-background-image-mode-controls"); m_BackgroundCameraModeControls = root.Q("canvas-background-camera-mode-controls"); EditorApplication.playModeStateChanged += PlayModeStateChange; }