Exemplo n.º 1
0
        /// <summary>
        /// Creates a new curve drawing GUI element.
        /// </summary>
        /// <param name="layout">Layout into which to add the GUI element.</param>
        /// <param name="width">Width of the element in pixels.</param>
        /// <param name="height">Height of the element in pixels.</param>
        /// <param name="curveInfos">Initial set of curves to display. </param>
        public GUICurveDrawing(GUILayout layout, int width, int height, CurveDrawInfo[] curveInfos)
            : base(layout, width, height)
        {
            tickHandler = new GUIGraphTicks(GUITickStepType.Time);
            this.curveInfos = curveInfos;

            ClearSelectedKeyframes(); // Makes sure the array is initialized
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a set of objects in which each object represents a GUI for a material parameter.
        /// </summary>
        /// <param name="mat">Material for whose parameters to create GUI for.</param>
        /// <param name="layout">Layout to add the parameter GUI elements to.</param>
        /// <returns>A material parameter GUI object for each supported material parameter.</returns>
        internal static MaterialParamGUI[] CreateMaterialGUI(Material mat, GUILayout layout)
        {
            Shader shader = mat.Shader;
            if (shader == null)
                return new MaterialParamGUI[0];

            List<MaterialParamGUI> guiParams = new List<MaterialParamGUI>();
            ShaderParameter[] shaderParams = shader.Parameters;

            foreach (var param in shaderParams)
            {
                if (param.Internal)
                    continue;

                switch (param.Type)
                {
                    case ShaderParameterType.Float:
                        layout.AddSpace(5);
                        guiParams.Add(new MaterialParamFloatGUI(param, mat, layout));
                        break;
                    case ShaderParameterType.Vector2:
                        layout.AddSpace(5);
                        guiParams.Add(new MaterialParamVec2GUI(param, mat, layout));
                        break;
                    case ShaderParameterType.Vector3:
                        layout.AddSpace(5);
                        guiParams.Add(new MaterialParamVec3GUI(param, mat, layout));
                        break;
                    case ShaderParameterType.Vector4:
                        layout.AddSpace(5);
                        guiParams.Add(new MaterialParamVec4GUI(param, mat, layout));
                        break;
                    case ShaderParameterType.Matrix3:
                        layout.AddSpace(5);
                        guiParams.Add(new MaterialParamMat3GUI(param, mat, layout));
                        break;
                    case ShaderParameterType.Matrix4:
                        layout.AddSpace(5);
                        guiParams.Add(new MaterialParamMat4GUI(param, mat, layout));
                        break;
                    case ShaderParameterType.Color:
                        layout.AddSpace(5);
                        guiParams.Add(new MaterialParamColorGUI(param, mat, layout));
                        break;
                    case ShaderParameterType.Texture2D:
                    case ShaderParameterType.Texture3D:
                    case ShaderParameterType.TextureCube:
                        layout.AddSpace(5);
                        guiParams.Add(new MaterialParamTextureGUI(param, mat, layout));
                        break;
                }
            }

            return guiParams.ToArray();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructs a new set of GUI elements for inspecting the limit object.
        /// </summary>
        /// <param name="limit">Initial values to assign to the GUI elements.</param>
        /// <param name="layout">Layout to append the GUI elements to.</param>
        /// <param name="properties">A set of properties that are persisted by the parent inspector. Used for saving state.
        ///                          </param>
        public LimitAngularRangeGUI(LimitAngularRange limit, GUILayout layout, SerializableProperties properties)
        {
            this.limitData = limit.Data;

            limitLowerField.OnChanged += x => { limitData.lower = new Degree(x); MarkAsModified(); };
            limitLowerField.OnFocusLost += ConfirmModify;

            limitUpperField.OnChanged += x => { limitData.upper = new Degree(x); MarkAsModified(); };
            limitUpperField.OnFocusLost += ConfirmModify;

            layout.AddElement(limitLowerField);
            layout.AddElement(limitUpperField);
            limitCommonGUI = new LimitCommonGUI("angularRange", limit.CommonData, layout, properties);
            limitCommonGUI.OnChanged += x => MarkAsModified();
            limitCommonGUI.OnConfirmed += ConfirmModify;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a new GUIFieldSelector and registers its GUI elements in the provided layout.
        /// </summary>
        /// <param name="layout">Layout into which to add the selector GUI hierarchy.</param>
        /// <param name="so">Scene object to inspect the fields for.</param>
        /// <param name="width">Width of the selector area, in pixels.</param>
        /// <param name="height">Height of the selector area, in pixels.</param>
        public GUIFieldSelector(GUILayout layout, SceneObject so, int width, int height)
        {
            rootSO = so;

            scrollArea = new GUIScrollArea();
            scrollArea.SetWidth(width);
            scrollArea.SetHeight(height);

            layout.AddElement(scrollArea);

            GUISkin skin = EditorBuiltin.GUISkin;
            GUIElementStyle style = skin.GetStyle(EditorStyles.Expand);
            foldoutWidth = style.Width;

            Rebuild();
        }
        /// <summary>
        /// Constructs a new set of GUI elements for inspecting the auto exposure settings object.
        /// </summary>
        /// <param name="settings">Initial values to assign to the GUI elements.</param>
        /// <param name="layout">Layout to append the GUI elements to.</param>
        public AutoExposureSettingsGUI(AutoExposureSettings settings, GUILayout layout)
        {
            this.settings = settings;

            histogramLog2MinField.OnChanged += x => { this.settings.HistogramLog2Min = x; MarkAsModified(); ConfirmModify(); };
            histogramLog2MaxField.OnChanged += x => { this.settings.HistogramLog2Max = x; MarkAsModified(); ConfirmModify(); };
            histogramPctLowField.OnChanged += x => { this.settings.HistogramPctLow = x; MarkAsModified(); ConfirmModify(); };
            histogramPctHighField.OnChanged += x => { this.settings.HistogramPctHigh = x; MarkAsModified(); ConfirmModify(); };
            minEyeAdaptationField.OnChanged += x => { this.settings.MinEyeAdaptation = x; MarkAsModified(); ConfirmModify(); };
            maxEyeAdaptationField.OnChanged += x => { this.settings.MaxEyeAdaptation = x; MarkAsModified(); ConfirmModify(); };
            eyeAdaptationSpeedUpField.OnChanged += x => { this.settings.EyeAdaptationSpeedUp = x; MarkAsModified(); ConfirmModify(); };
            eyeAdaptationSpeedDownField.OnChanged += x => { this.settings.EyeAdaptationSpeedDown = x; MarkAsModified(); ConfirmModify(); };

            layout.AddElement(histogramLog2MinField);
            layout.AddElement(histogramLog2MaxField);
            layout.AddElement(histogramPctLowField);
            layout.AddElement(histogramPctHighField);
            layout.AddElement(minEyeAdaptationField);
            layout.AddElement(maxEyeAdaptationField);
            layout.AddElement(eyeAdaptationSpeedUpField);
            layout.AddElement(eyeAdaptationSpeedDownField);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Constructs a new set of GUI elements for inspecting the drive object.
        /// </summary>
        /// <param name="drive">Initial values to assign to the GUI elements.</param>
        /// <param name="layout">Layout to append the GUI elements to.</param>
        public D6JointDriveGUI(D6JointDrive drive, GUILayout layout)
        {
            driveData = drive.Data;

            stiffnessField.OnChanged += x => { driveData.stiffness = x; MarkAsModified(); };
            stiffnessField.OnFocusLost += ConfirmModify;
            stiffnessField.OnConfirmed += ConfirmModify;

            dampingField.OnChanged += x => { driveData.damping = x; MarkAsModified(); };
            dampingField.OnFocusLost += ConfirmModify;
            dampingField.OnConfirmed += ConfirmModify;

            forceLimitField.OnChanged += x => { driveData.forceLimit = x; MarkAsModified(); };
            forceLimitField.OnFocusLost += ConfirmModify;
            forceLimitField.OnConfirmed += ConfirmModify;

            accelerationField.OnChanged += x => { driveData.acceleration = x; MarkAsModified(); ConfirmModify(); };

            layout.AddElement(stiffnessField);
            layout.AddElement(dampingField);
            layout.AddElement(forceLimitField);
            layout.AddElement(accelerationField);
        }
Exemplo n.º 7
0
                /// <summary>
                /// Creates a new rectangle offset GUI.
                /// </summary>
                /// <param name="title">Text to display on the title bar.</param>
                /// <param name="layout">Layout to append the GUI elements to.</param>
                public RectOffsetGUI(LocString title, GUILayout layout)
                {
                    GUILayoutX rectLayout = layout.AddLayoutX();
                    rectLayout.AddElement(new GUILabel(title, GUIOption.FixedWidth(100)));
                    GUILayoutY rectContentLayout = rectLayout.AddLayoutY();

                    GUILayoutX rectTopRow = rectContentLayout.AddLayoutX();
                    GUILayoutX rectBotRow = rectContentLayout.AddLayoutX();

                    offsetLeftField = new GUIIntField(new LocEdString("Left"), 40);
                    offsetRightField = new GUIIntField(new LocEdString("Right"), 40);
                    offsetTopField = new GUIIntField(new LocEdString("Top"), 40);
                    offsetBottomField = new GUIIntField(new LocEdString("Bottom"), 40);

                    rectTopRow.AddElement(offsetLeftField);
                    rectTopRow.AddElement(offsetRightField);
                    rectBotRow.AddElement(offsetTopField);
                    rectBotRow.AddElement(offsetBottomField);

                    offsetLeftField.OnChanged += x =>
                    {
                        offset.left = x;

                        if(OnChanged != null)
                            OnChanged(offset);
                    };

                    offsetRightField.OnChanged += x =>
                    {
                        offset.right = x;

                        if (OnChanged != null)
                            OnChanged(offset);
                    };

                    offsetTopField.OnChanged += x =>
                    {
                        offset.top = x;

                        if (OnChanged != null)
                            OnChanged(offset);
                    };

                    offsetBottomField.OnChanged += x =>
                    {
                        offset.bottom = x;

                        if (OnChanged != null)
                            OnChanged(offset);
                    };

                    Action DoOnConfirmed = () =>
                    {
                        if (OnConfirmed != null)
                            OnConfirmed();
                    };

                    offsetLeftField.OnConfirmed += DoOnConfirmed;
                    offsetLeftField.OnFocusLost += DoOnConfirmed;
                    offsetRightField.OnConfirmed += DoOnConfirmed;
                    offsetRightField.OnFocusLost += DoOnConfirmed;
                    offsetTopField.OnConfirmed += DoOnConfirmed;
                    offsetTopField.OnFocusLost += DoOnConfirmed;
                    offsetBottomField.OnConfirmed += DoOnConfirmed;
                    offsetBottomField.OnFocusLost += DoOnConfirmed;
                }
Exemplo n.º 8
0
                /// <summary>
                /// Builds the GUI for the specified state style.
                /// </summary>
                /// <param name="title">Text to display on the title bar.</param>
                /// <param name="layout">Layout to append the GUI elements to.</param>
                public void BuildGUI(LocString title, GUILayout layout)
                {
                    foldout = new GUIToggle(title, EditorStyles.Foldout);
                    textureField = new GUIResourceField(typeof(SpriteTexture), new LocEdString("Texture"));
                    textColorField = new GUIColorField(new LocEdString("Text color"));

                    foldout.OnToggled += x =>
                    {
                        textureField.Active = x;
                        textColorField.Active = x;
                        isExpanded = x;
                    };

                    textureField.OnChanged += x =>
                    {
                        SpriteTexture texture = Resources.Load<SpriteTexture>(x);
                        state.Texture = texture;

                        if (OnChanged != null)
                            OnChanged(state);
                    };

                    textColorField.OnChanged += x =>
                    {
                        state.TextColor = x;

                        if (OnChanged != null)
                            OnChanged(state);
                    };

                    layout.AddElement(foldout);
                    layout.AddElement(textureField);
                    layout.AddElement(textColorField);

                    foldout.Value = isExpanded;
                    textureField.Active = isExpanded;
                    textColorField.Active = isExpanded;
                }
Exemplo n.º 9
0
            /// <summary>
            /// Builds GUI for the specified GUI element style.
            /// </summary>
            /// <param name="layout">Layout to append the GUI elements to.</param>
            /// <param name="depth">Determines the depth at which the element is rendered.</param>
            public void BuildGUI(GUILayout layout, int depth)
            {
                short backgroundDepth = (short)(Inspector.START_BACKGROUND_DEPTH - depth - 1);
                string bgPanelStyle = depth % 2 == 0
                    ? EditorStyles.InspectorContentBgAlternate
                    : EditorStyles.InspectorContentBg;

                GUIToggle foldout = new GUIToggle(new LocEdString("Style"), EditorStyles.Foldout);
                GUITexture inspectorContentBg = new GUITexture(null, bgPanelStyle);

                layout.AddElement(foldout);
                GUIPanel panel = layout.AddPanel();
                GUIPanel backgroundPanel = panel.AddPanel(backgroundDepth);

                backgroundPanel.AddElement(inspectorContentBg);

                GUILayoutX guiIndentLayoutX = panel.AddLayoutX();
                guiIndentLayoutX.AddSpace(IndentAmount);
                GUILayoutY guiIndentLayoutY = guiIndentLayoutX.AddLayoutY();
                guiIndentLayoutY.AddSpace(IndentAmount);
                GUILayoutY contentLayout = guiIndentLayoutY.AddLayoutY();
                guiIndentLayoutY.AddSpace(IndentAmount);
                guiIndentLayoutX.AddSpace(IndentAmount);

                fontField = new GUIResourceField(typeof (Font), new LocEdString("Font"));
                fontSizeField = new GUIIntField(new LocEdString("Font size"));
                horzAlignField = new GUIEnumField(typeof (TextHorzAlign), new LocEdString("Horizontal alignment"));
                vertAlignField = new GUIEnumField(typeof(TextVertAlign), new LocEdString("Vertical alignment"));
                imagePositionField = new GUIEnumField(typeof(GUIImagePosition), new LocEdString("Image position"));
                wordWrapField = new GUIToggleField(new LocEdString("Word wrap"));

                contentLayout.AddElement(fontField);
                contentLayout.AddElement(fontSizeField);
                contentLayout.AddElement(horzAlignField);
                contentLayout.AddElement(vertAlignField);
                contentLayout.AddElement(imagePositionField);
                contentLayout.AddElement(wordWrapField);

                normalGUI.BuildGUI(new LocEdString("Normal"), contentLayout);
                hoverGUI.BuildGUI(new LocEdString("Hover"), contentLayout);
                activeGUI.BuildGUI(new LocEdString("Active"), contentLayout);
                focusedGUI.BuildGUI(new LocEdString("Focused"), contentLayout);
                normalOnGUI.BuildGUI(new LocEdString("NormalOn"), contentLayout);
                hoverOnGUI.BuildGUI(new LocEdString("HoverOn"), contentLayout);
                activeOnGUI.BuildGUI(new LocEdString("ActiveOn"), contentLayout);
                focusedOnGUI.BuildGUI(new LocEdString("FocusedOn"), contentLayout);

                borderGUI = new RectOffsetGUI(new LocEdString("Border"), contentLayout);
                marginsGUI = new RectOffsetGUI(new LocEdString("Margins"), contentLayout);
                contentOffsetGUI = new RectOffsetGUI(new LocEdString("Content offset"), contentLayout);

                fixedWidthField = new GUIToggleField(new LocEdString("Fixed width"));
                widthField = new GUIIntField(new LocEdString("Width"));
                minWidthField = new GUIIntField(new LocEdString("Min. width"));
                maxWidthField = new GUIIntField(new LocEdString("Max. width"));

                fixedHeightField = new GUIToggleField(new LocEdString("Fixed height"));
                heightField = new GUIIntField(new LocEdString("Height"));
                minHeightField = new GUIIntField(new LocEdString("Min. height"));
                maxHeightField = new GUIIntField(new LocEdString("Max. height"));

                contentLayout.AddElement(fixedWidthField);
                contentLayout.AddElement(widthField);
                contentLayout.AddElement(minWidthField);
                contentLayout.AddElement(maxWidthField);

                contentLayout.AddElement(fixedHeightField);
                contentLayout.AddElement(heightField);
                contentLayout.AddElement(minHeightField);
                contentLayout.AddElement(maxHeightField);

                foldout.OnToggled += x =>
                {
                    panel.Active = x;
                    isExpanded = x;
                };

                fontField.OnChanged += x =>
                {
                    Font font = Resources.Load<Font>(x);

                    GetStyle().Font = font;
                    MarkAsModified();
                    ConfirmModify();
                };
                fontSizeField.OnChanged += x => { GetStyle().FontSize = x; MarkAsModified(); };
                fontSizeField.OnFocusLost += ConfirmModify;
                fontSizeField.OnConfirmed += ConfirmModify;
                horzAlignField.OnSelectionChanged += x =>
                {
                    GetStyle().TextHorzAlign = (TextHorzAlign)x;
                    MarkAsModified();
                    ConfirmModify();
                };
                vertAlignField.OnSelectionChanged += x =>
                {
                    GetStyle().TextVertAlign = (TextVertAlign)x;
                    MarkAsModified();
                    ConfirmModify();
                };
                imagePositionField.OnSelectionChanged += x =>
                {
                    GetStyle().ImagePosition = (GUIImagePosition)x;
                    MarkAsModified();
                    ConfirmModify();
                };
                wordWrapField.OnChanged += x => { GetStyle().WordWrap = x; MarkAsModified(); ConfirmModify(); };

                normalGUI.OnChanged += x => { GetStyle().Normal = x; MarkAsModified(); ConfirmModify(); };
                hoverGUI.OnChanged += x => { GetStyle().Hover = x; MarkAsModified(); ConfirmModify(); };
                activeGUI.OnChanged += x => { GetStyle().Active = x; MarkAsModified(); ConfirmModify(); };
                focusedGUI.OnChanged += x => { GetStyle().Focused = x; MarkAsModified(); ConfirmModify(); };
                normalOnGUI.OnChanged += x => { GetStyle().NormalOn = x; MarkAsModified(); ConfirmModify(); };
                hoverOnGUI.OnChanged += x => { GetStyle().HoverOn = x; MarkAsModified(); ConfirmModify(); };
                activeOnGUI.OnChanged += x => { GetStyle().ActiveOn = x; MarkAsModified(); ConfirmModify(); };
                focusedOnGUI.OnChanged += x => { GetStyle().FocusedOn = x; MarkAsModified(); ConfirmModify(); };

                borderGUI.OnChanged += x => { GetStyle().Border = x; MarkAsModified(); };
                marginsGUI.OnChanged += x => { GetStyle().Margins = x; MarkAsModified(); };
                contentOffsetGUI.OnChanged += x => { GetStyle().ContentOffset = x; MarkAsModified(); };

                borderGUI.OnConfirmed += ConfirmModify;
                marginsGUI.OnConfirmed += ConfirmModify;
                contentOffsetGUI.OnConfirmed += ConfirmModify;

                fixedWidthField.OnChanged += x => { GetStyle().FixedWidth = x; MarkAsModified(); ConfirmModify(); };
                widthField.OnChanged += x => GetStyle().Width = x;
                widthField.OnFocusLost += ConfirmModify;
                widthField.OnConfirmed += ConfirmModify;
                minWidthField.OnChanged += x => GetStyle().MinWidth = x;
                minWidthField.OnFocusLost += ConfirmModify;
                minWidthField.OnConfirmed += ConfirmModify;
                maxWidthField.OnChanged += x => GetStyle().MaxWidth = x;
                maxWidthField.OnFocusLost += ConfirmModify;
                maxWidthField.OnConfirmed += ConfirmModify;

                fixedHeightField.OnChanged += x => { GetStyle().FixedHeight = x; MarkAsModified(); ConfirmModify(); };
                heightField.OnChanged += x => GetStyle().Height = x;
                heightField.OnFocusLost += ConfirmModify;
                heightField.OnConfirmed += ConfirmModify;
                minHeightField.OnChanged += x => GetStyle().MinHeight = x;
                minHeightField.OnFocusLost += ConfirmModify;
                minHeightField.OnConfirmed += ConfirmModify;
                maxHeightField.OnChanged += x => GetStyle().MaxHeight = x;
                maxHeightField.OnFocusLost += ConfirmModify;
                maxHeightField.OnConfirmed += ConfirmModify;

                foldout.Value = isExpanded;
                panel.Active = isExpanded;
            }
Exemplo n.º 10
0
 /// <summary>
 /// Constructs a new events timeline and adds it to the specified layout.
 /// </summary>
 /// <param name="layout">Layout to add the events GUI to.</param>
 /// <param name="width">Width of the GUI element in pixels.</param>
 /// <param name="height">Height of the GUI element in pixels.</param>
 public GUIAnimEvents(GUILayout layout, int width, int height)
     : base(layout, width, height)
 {
 }
Exemplo n.º 11
0
            /// <summary>
            /// Constructs a new empty inspectable list GUI.
            /// </summary>
            /// <param name="parent">Parent Inspector this field belongs to.</param>
            /// <param name="title">Label to display on the list GUI title.</param>
            /// <param name="path">Full path to this property (includes name of this property and all parent properties).
            /// </param>
            /// <param name="property">Serializable property referencing a list.</param>
            /// <param name="layout">Layout to which to append the list GUI elements to.</param>
            /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple
            ///                     nested containers whose backgrounds are overlaping. Also determines background style,
            ///                     depths divisible by two will use an alternate style.</param>
            public InspectableListGUI(Inspector parent, LocString title, string path, SerializableProperty property, 
                GUILayout layout, int depth)
                : base(title, layout, depth)
            {
                this.property = property;
                this.parent = parent;
                this.path = path;

                list = property.GetValue<IList>();
                if (list != null)
                    numElements = list.Count;
            }
        /// <summary>
        /// Constructs a new set of GUI elements for inspecting the white balance settings object.
        /// </summary>
        /// <param name="settings">Initial values to assign to the GUI elements.</param>
        /// <param name="layout">Layout to append the GUI elements to.</param>
        public WhiteBalanceSettingsGUI(WhiteBalanceSettings settings, GUILayout layout)
        {
            this.settings = settings;

            temperatureField.OnChanged += x => { this.settings.Temperature = x; MarkAsModified(); ConfirmModify(); };
            tintField.OnChanged += x => { this.settings.Tint = x; MarkAsModified(); ConfirmModify(); };

            layout.AddElement(temperatureField);
            layout.AddElement(tintField);
        }
        /// <summary>
        /// Constructs a new set of GUI elements for inspecting the tone mapping settings object.
        /// </summary>
        /// <param name="settings">Initial values to assign to the GUI elements.</param>
        /// <param name="layout">Layout to append the GUI elements to.</param>
        public TonemappingSettingsGUI(TonemappingSettings settings, GUILayout layout)
        {
            this.settings = settings;

            shoulderStrengthField.OnChanged += x => { this.settings.FilmicCurveShoulderStrength = x; MarkAsModified(); };
            shoulderStrengthField.OnFocusLost += ConfirmModify;
            shoulderStrengthField.OnConfirmed += ConfirmModify;

            linearStrengthField.OnChanged += x => { this.settings.FilmicCurveLinearStrength = x; MarkAsModified(); };
            linearStrengthField.OnFocusLost += ConfirmModify;
            linearStrengthField.OnConfirmed += ConfirmModify;

            linearAngleField.OnChanged += x => { this.settings.FilmicCurveLinearAngle = x; MarkAsModified(); };
            linearAngleField.OnFocusLost += ConfirmModify;
            linearAngleField.OnConfirmed += ConfirmModify;

            toeStrengthField.OnChanged += x => { this.settings.FilmicCurveToeStrength = x; MarkAsModified(); };
            toeStrengthField.OnFocusLost += ConfirmModify;
            toeStrengthField.OnConfirmed += ConfirmModify;

            toeNumeratorField.OnChanged += x => { this.settings.FilmicCurveToeNumerator = x; MarkAsModified(); };
            toeNumeratorField.OnFocusLost += ConfirmModify;
            toeNumeratorField.OnConfirmed += ConfirmModify;

            toeDenominatorField.OnChanged += x => { this.settings.FilmicCurveToeDenominator = x; MarkAsModified(); };
            toeDenominatorField.OnFocusLost += ConfirmModify;
            toeDenominatorField.OnConfirmed += ConfirmModify;

            whitePointField.OnChanged += x => { this.settings.FilmicCurveLinearWhitePoint = x; MarkAsModified(); };
            whitePointField.OnFocusLost += ConfirmModify;
            whitePointField.OnConfirmed += ConfirmModify;

            layout.AddElement(shoulderStrengthField);
            layout.AddElement(linearStrengthField);
            layout.AddElement(linearAngleField);
            layout.AddElement(toeStrengthField);
            layout.AddElement(toeNumeratorField);
            layout.AddElement(toeDenominatorField);
            layout.AddElement(whitePointField);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Recreates all the GUI elements used by this inspector.
        /// </summary>
        private void BuildGUI()
        {
            if (InspectedObject != null)
            {
                Camera camera = (Camera)InspectedObject;

                projectionTypeField.OnSelectionChanged += x =>
                {
                    camera.ProjectionType = (ProjectionType)x;
                    MarkAsModified();
                    ConfirmModify();
                    ToggleTypeSpecificFields((ProjectionType)x);
                };

                fieldOfView.OnChanged += x => { camera.FieldOfView = (Degree)x; MarkAsModified(); };
                fieldOfView.OnFocusLost += ConfirmModify;

                orthoHeight.OnChanged += x => { camera.OrthoHeight = x; MarkAsModified(); };
                orthoHeight.OnConfirmed += ConfirmModify;
                orthoHeight.OnFocusLost += ConfirmModify;

                aspectField.OnChanged += x => { camera.AspectRatio = x; MarkAsModified(); };
                aspectField.OnConfirmed += ConfirmModify;
                aspectField.OnFocusLost += ConfirmModify;

                nearPlaneField.OnChanged += x => { camera.NearClipPlane = x; MarkAsModified(); };
                nearPlaneField.OnConfirmed += ConfirmModify;
                nearPlaneField.OnFocusLost += ConfirmModify;

                farPlaneField.OnChanged += x => { camera.FarClipPlane = x; MarkAsModified(); };
                farPlaneField.OnConfirmed += ConfirmModify;
                farPlaneField.OnFocusLost += ConfirmModify;

                viewportXField.OnChanged += x =>
                {
                    Rect2 rect = camera.ViewportRect;
                    rect.x = x;
                    camera.ViewportRect = rect;

                    MarkAsModified();
                };
                viewportXField.OnConfirmed += ConfirmModify;
                viewportXField.OnFocusLost += ConfirmModify;

                viewportYField.OnChanged += x =>
                {
                    Rect2 rect = camera.ViewportRect;
                    rect.y = x;
                    camera.ViewportRect = rect;

                    MarkAsModified();
                };
                viewportYField.OnConfirmed += ConfirmModify;
                viewportYField.OnFocusLost += ConfirmModify;

                viewportWidthField.OnChanged += x =>
                {
                    Rect2 rect = camera.ViewportRect;
                    rect.width = x;
                    camera.ViewportRect = rect;

                    MarkAsModified();
                };
                viewportWidthField.OnConfirmed += ConfirmModify;
                viewportWidthField.OnFocusLost += ConfirmModify;

                viewportHeightField.OnChanged += x =>
                {
                    Rect2 rect = camera.ViewportRect;
                    rect.height = x;
                    camera.ViewportRect = rect;

                    MarkAsModified();
                };
                viewportHeightField.OnConfirmed += ConfirmModify;
                viewportHeightField.OnFocusLost += ConfirmModify;

                clearFlagsFields.OnSelectionChanged += x =>
                {
                    camera.ClearFlags = (ClearFlags) x;
                    MarkAsModified();
                    ConfirmModify();
                };

                clearStencilField.OnChanged += x => { camera.ClearStencil = (ushort) x; };
                clearStencilField.OnConfirmed += ConfirmModify;
                clearStencilField.OnFocusLost += ConfirmModify;

                clearDepthField.OnChanged += x => { camera.ClearDepth = x; };
                clearDepthField.OnConfirmed += ConfirmModify;
                clearDepthField.OnFocusLost += ConfirmModify;

                clearColorField.OnChanged += x =>
                {
                    camera.ClearColor = x;
                    MarkAsModified();
                    ConfirmModify();
                };

                priorityField.OnChanged += x => { camera.Priority = x; MarkAsModified(); };
                priorityField.OnConfirmed += ConfirmModify;
                priorityField.OnFocusLost += ConfirmModify;

                layersField.OnSelectionChanged += x =>
                {
                    ulong layers = 0;
                    bool[] states = layersField.States;
                    for (int i = 0; i < states.Length; i++)
                        layers |= states[i] ? Layers.Values[i] : 0;

                    layersValue = layers;
                    camera.Layers = layers;

                    MarkAsModified();
                    ConfirmModify();
                };

                mainField.OnChanged += x =>
                {
                    camera.Main = x;
                    MarkAsModified();
                    ConfirmModify();
                };

                hdrField.OnChanged += x =>
                {
                    camera.HDR = x;
                    MarkAsModified();
                    ConfirmModify();
                };

                skyboxField.OnChanged += x =>
                {
                    Texture skyboxTex = Resources.Load<Texture>(x);

                    camera.Skybox = skyboxTex as TextureCube;
                    MarkAsModified();
                    ConfirmModify();
                };

                Layout.AddElement(projectionTypeField);
                Layout.AddElement(fieldOfView);
                Layout.AddElement(orthoHeight);
                Layout.AddElement(aspectField);
                Layout.AddElement(nearPlaneField);
                Layout.AddElement(farPlaneField);
                GUILayoutX viewportTopLayout = Layout.AddLayoutX();
                viewportTopLayout.AddElement(new GUILabel(new LocEdString("Viewport"), GUIOption.FixedWidth(100)));
                GUILayoutY viewportContentLayout = viewportTopLayout.AddLayoutY();

                GUILayoutX viewportTopRow = viewportContentLayout.AddLayoutX();
                viewportTopRow.AddElement(viewportXField);
                viewportTopRow.AddElement(viewportWidthField);

                GUILayoutX viewportBotRow = viewportContentLayout.AddLayoutX();
                viewportBotRow.AddElement(viewportYField);
                viewportBotRow.AddElement(viewportHeightField);

                Layout.AddElement(clearFlagsFields);
                Layout.AddElement(clearColorField);
                Layout.AddElement(clearDepthField);
                Layout.AddElement(clearStencilField);
                Layout.AddElement(priorityField);
                Layout.AddElement(layersField);
                Layout.AddElement(mainField);
                Layout.AddElement(hdrField);
                Layout.AddElement(skyboxField);

                postProcessFoldout.OnToggled += x =>
                {
                    Persistent.SetBool("postProcess_Expanded", x);
                    postProcessLayout.Active = x;
                };
                Layout.AddElement(postProcessFoldout);

                postProcessLayout = Layout.AddLayoutX();
                {
                    postProcessLayout.AddSpace(10);

                    GUILayoutY contentsLayout = postProcessLayout.AddLayoutY();
                    postProcessGUI = new PostProcessSettingsGUI(camera.PostProcess, contentsLayout, Persistent);
                    postProcessGUI.OnChanged += x => { camera.PostProcess = x; MarkAsModified(); };
                    postProcessGUI.OnConfirmed += ConfirmModify;
                }

                ToggleTypeSpecificFields(camera.ProjectionType);
                postProcessLayout.Active = Persistent.GetBool("postProcess_Expanded");
            }
        }
Exemplo n.º 15
0
 /// <summary>
 /// Creates a new scroll area.
 /// </summary>
 /// <param name="options">Options that allow you to control how is the element positioned and sized. This will 
 ///                       override any similar options set by style.</param>
 public GUIScrollArea(params GUIOption[] options)
 {
     Internal_CreateInstance(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, "", "", options);
     _mainLayout = new GUILayoutY(this);
 }
Exemplo n.º 16
0
        /// <summary>
        /// Updates GUI for the directory bar. Should be called whenever the active folder changes.
        /// </summary>
        private void RefreshDirectoryBar()
        {
            if (folderListLayout != null)
            {
                folderListLayout.Destroy();
                folderListLayout = null;
            }

            folderListLayout = folderBarLayout.AddLayoutX();

            string[] folders = null;
            string[] fullPaths = null;

            if (IsSearchActive)
            {
                folders = new[] {searchQuery};
                fullPaths = new[] { searchQuery };
            }
            else
            {
                string currentDir = Path.Combine("Resources", CurrentFolder);

                folders = currentDir.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar },
                    StringSplitOptions.RemoveEmptyEntries);

                fullPaths = new string[folders.Length];
                for (int i = 0; i < folders.Length; i++)
                {
                    if (i == 0)
                        fullPaths[i] = "";
                    else
                        fullPaths[i] = Path.Combine(fullPaths[i - 1], folders[i]);
                }
            }

            int availableWidth = folderBarLayout.Bounds.width - FOLDER_BUTTON_WIDTH * 2;
            int numFolders = 0;
            for (int i = folders.Length - 1; i >= 0; i--)
            {
                GUIButton folderButton = new GUIButton(folders[i]);

                if (!IsSearchActive)
                {
                    string fullPath = fullPaths[i];
                    folderButton.OnClick += () => OnFolderButtonClicked(fullPath);
                }

                GUIButton separator = new GUIButton("/", GUIOption.FixedWidth(FOLDER_SEPARATOR_WIDTH));

                folderListLayout.InsertElement(0, separator);
                folderListLayout.InsertElement(0, folderButton);
                numFolders++;

                Rect2I folderListBounds = folderListLayout.Bounds;
                if (folderListBounds.width > availableWidth)
                {
                    if (numFolders > 2)
                    {
                        separator.Destroy();
                        folderButton.Destroy();
                        break;
                    }
                }
            }
        }
Exemplo n.º 17
0
        private void OnInitialize()
        {
            ProjectLibrary.OnEntryAdded += OnEntryChanged;
            ProjectLibrary.OnEntryImported += OnEntryChanged;
            ProjectLibrary.OnEntryRemoved += OnEntryChanged;

            GUILayoutY contentLayout = GUI.AddLayoutY();

            searchBarLayout = contentLayout.AddLayoutX();
            searchField = new GUITextField();
            searchField.OnChanged += OnSearchChanged;
            searchField.OnFocusGained += StopRename;

            GUIContent clearIcon = new GUIContent(EditorBuiltin.GetLibraryWindowIcon(LibraryWindowIcon.Clear),
                new LocEdString("Clear"));
            GUIButton clearSearchBtn = new GUIButton(clearIcon);
            clearSearchBtn.OnClick += OnClearClicked;
            clearSearchBtn.SetWidth(40);

            GUIContent optionsIcon = new GUIContent(EditorBuiltin.GetLibraryWindowIcon(LibraryWindowIcon.Options),
                new LocEdString("Options"));
            optionsButton = new GUIButton(optionsIcon);
            optionsButton.OnClick += OnOptionsClicked;
            optionsButton.SetWidth(40);
            searchBarLayout.AddElement(searchField);
            searchBarLayout.AddElement(clearSearchBtn);
            searchBarLayout.AddElement(optionsButton);

            folderBarLayout = contentLayout.AddLayoutX();

            GUIContent homeIcon = new GUIContent(EditorBuiltin.GetLibraryWindowIcon(LibraryWindowIcon.Home),
                new LocEdString("Home"));
            GUIButton homeButton = new GUIButton(homeIcon, GUIOption.FixedWidth(FOLDER_BUTTON_WIDTH));
            homeButton.OnClick += OnHomeClicked;

            GUIContent upIcon = new GUIContent(EditorBuiltin.GetLibraryWindowIcon(LibraryWindowIcon.Up),
                new LocEdString("Up"));
            GUIButton upButton = new GUIButton(upIcon, GUIOption.FixedWidth(FOLDER_BUTTON_WIDTH));
            upButton.OnClick += OnUpClicked;

            folderBarLayout.AddElement(homeButton);
            folderBarLayout.AddElement(upButton);
            folderBarLayout.AddSpace(10);

            contentScrollArea = new GUIScrollArea(GUIOption.FlexibleWidth(), GUIOption.FlexibleHeight());
            contentLayout.AddElement(contentScrollArea);
            contentLayout.AddFlexibleSpace();

            entryContextMenu = LibraryMenu.CreateContextMenu(this);
            content = new LibraryGUIContent(this, contentScrollArea);

            Refresh();

            dropTarget = new LibraryDropTarget(this);
            dropTarget.Bounds = GetScrollAreaBounds();
            dropTarget.OnStart += OnDragStart;
            dropTarget.OnDrag += OnDragMove;
            dropTarget.OnLeave += OnDragLeave;
            dropTarget.OnDropResource += OnResourceDragDropped;
            dropTarget.OnDropSceneObject += OnSceneObjectDragDropped;
            dropTarget.OnEnd += OnDragEnd;

            Selection.OnSelectionChanged += OnSelectionChanged;
            Selection.OnResourcePing += OnPing;
        }
Exemplo n.º 18
0
            /// <summary>
            /// Creates a new inspectable list GUI object that displays the contents of the provided serializable property.
            /// </summary>
            /// <param name="parent">Parent Inspector this field belongs to.</param>
            /// <param name="title">Label to display on the list GUI title.</param>
            /// <param name="path">Full path to this property (includes name of this property and all parent properties).
            /// </param>
            /// <param name="property">Serializable property referencing a list.</param>
            /// <param name="layout">Layout to which to append the list GUI elements to.</param>
            /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple
            ///                     nested containers whose backgrounds are overlaping. Also determines background style,
            ///                     depths divisible by two will use an alternate style.</param>
            public static InspectableListGUI Create(Inspector parent, LocString title, string path, 
                SerializableProperty property, GUILayout layout, int depth)
            {
                InspectableListGUI listGUI = new InspectableListGUI(parent, title, path, property, layout, depth);
                listGUI.BuildGUI();

                return listGUI;
            }
        /// <summary>
        /// Constructs a new set of GUI elements for inspecting the color grading settings object.
        /// </summary>
        /// <param name="settings">Initial values to assign to the GUI elements.</param>
        /// <param name="layout">Layout to append the GUI elements to.</param>
        public ColorGradingSettingsGUI(ColorGradingSettings settings, GUILayout layout)
        {
            this.settings = settings;

            saturationField.OnChanged += x => { this.settings.Saturation = x; MarkAsModified(); };
            saturationField.OnFocusLost += ConfirmModify;
            saturationField.OnConfirmed += ConfirmModify;

            contrastField.OnChanged += x => { this.settings.Contrast = x; MarkAsModified(); };
            contrastField.OnFocusLost += ConfirmModify;
            contrastField.OnConfirmed += ConfirmModify;

            gainField.OnChanged += x => { this.settings.Gain = x; MarkAsModified(); };
            gainField.OnFocusLost += ConfirmModify;
            gainField.OnConfirmed += ConfirmModify;

            offsetField.OnChanged += x => { this.settings.Offset = x; MarkAsModified(); };
            offsetField.OnFocusLost += ConfirmModify;
            offsetField.OnConfirmed += ConfirmModify;

            layout.AddElement(saturationField);
            layout.AddElement(contrastField);
            layout.AddElement(gainField);
            layout.AddElement(offsetField);
        }
Exemplo n.º 20
0
            /// <summary>
            /// Builds the inspectable dictionary GUI elements. Must be called at least once in order for the contents to 
            /// be populated.
            /// </summary>
            /// <param name="parent">Parent Inspector this field belongs to.</param>
            /// <param name="title">Label to display on the list GUI title.</param>
            /// <param name="path">Full path to this property (includes name of this property and all parent properties).
            /// </param>
            /// <param name="property">Serializable property referencing a dictionary</param>
            /// <param name="layout">Layout to which to append the list GUI elements to.</param>
            /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple
            ///                     nested containers whose backgrounds are overlaping. Also determines background style,
            ///                     depths divisible by two will use an alternate style.</param>
            public static InspectableDictionaryGUI Create(Inspector parent, LocString title, string path, 
                SerializableProperty property, GUILayout layout, int depth = 0)
            {
                InspectableDictionaryGUI guiDictionary = new InspectableDictionaryGUI(parent, title, path, property,
                    layout, depth);
                guiDictionary.BuildGUI();

                return guiDictionary;
            }
        /// <summary>
        /// Constructs a new set of GUI elements for inspecting the post process settings object.
        /// </summary>
        /// <param name="settings">Initial values to assign to the GUI elements.</param>
        /// <param name="layout">Layout to append the GUI elements to.</param>
        /// <param name="properties">A set of properties that are persisted by the parent inspector. Used for saving state.
        ///                          </param>
        public PostProcessSettingsGUI(PostProcessSettings settings, GUILayout layout, SerializableProperties properties)
        {
            this.settings = settings;
            this.properties = properties;

            // Auto exposure
            enableAutoExposureField.OnChanged += x => { this.settings.EnableAutoExposure = x; MarkAsModified(); ConfirmModify(); };
            layout.AddElement(enableAutoExposureField);

            autoExposureFoldout.OnToggled += x =>
            {
                properties.SetBool("autoExposure_Expanded", x);
                ToggleFoldoutFields();
            };
            layout.AddElement(autoExposureFoldout);

            autoExposureLayout = layout.AddLayoutX();
            {
                autoExposureLayout.AddSpace(10);

                GUILayoutY contentsLayout = autoExposureLayout.AddLayoutY();
                autoExposureGUI = new AutoExposureSettingsGUI(settings.AutoExposure, contentsLayout);
                autoExposureGUI.OnChanged += x => { this.settings.AutoExposure = x; MarkAsModified(); };
                autoExposureGUI.OnConfirmed += ConfirmModify;
            }

            // Tonemapping
            enableToneMappingField.OnChanged += x => { this.settings.EnableTonemapping = x; MarkAsModified(); ConfirmModify(); };
            layout.AddElement(enableToneMappingField);

            //// Tonemapping settings
            toneMappingFoldout.OnToggled += x =>
            {
                properties.SetBool("toneMapping_Expanded", x);
                ToggleFoldoutFields();
            };
            layout.AddElement(toneMappingFoldout);

            toneMappingLayout = layout.AddLayoutX();
            {
                toneMappingLayout.AddSpace(10);

                GUILayoutY contentsLayout = toneMappingLayout.AddLayoutY();
                toneMappingGUI = new TonemappingSettingsGUI(settings.Tonemapping, contentsLayout);
                toneMappingGUI.OnChanged += x => { this.settings.Tonemapping = x; MarkAsModified(); };
                toneMappingGUI.OnConfirmed += ConfirmModify;
            }

            //// White balance settings
            whiteBalanceFoldout.OnToggled += x =>
            {
                properties.SetBool("whiteBalance_Expanded", x);
                ToggleFoldoutFields();
            };
            layout.AddElement(whiteBalanceFoldout);

            whiteBalanceLayout = layout.AddLayoutX();
            {
                whiteBalanceLayout.AddSpace(10);

                GUILayoutY contentsLayout = whiteBalanceLayout.AddLayoutY();
                whiteBalanceGUI = new WhiteBalanceSettingsGUI(settings.WhiteBalance, contentsLayout);
                whiteBalanceGUI.OnChanged += x => { this.settings.WhiteBalance = x; MarkAsModified(); };
                whiteBalanceGUI.OnConfirmed += ConfirmModify;
            }

            //// Color grading settings
            colorGradingFoldout.OnToggled += x =>
            {
                properties.SetBool("colorGrading_Expanded", x);
                ToggleFoldoutFields();
            };
            layout.AddElement(colorGradingFoldout);

            colorGradingLayout = layout.AddLayoutX();
            {
                colorGradingLayout.AddSpace(10);

                GUILayoutY contentsLayout = colorGradingLayout.AddLayoutY();
                colorGradingGUI = new ColorGradingSettingsGUI(settings.ColorGrading, contentsLayout);
                colorGradingGUI.OnChanged += x => { this.settings.ColorGrading = x; MarkAsModified(); };
                colorGradingGUI.OnConfirmed += ConfirmModify;
            }

            // Gamma
            gammaField.OnChanged += x => { this.settings.Gamma = x; MarkAsModified(); ConfirmModify(); };
            layout.AddElement(gammaField);

            // Exposure scale
            exposureScaleField.OnChanged += x => { this.settings.ExposureScale = x; MarkAsModified(); ConfirmModify(); };
            layout.AddElement(exposureScaleField);

            ToggleFoldoutFields();
        }
Exemplo n.º 22
0
 protected static extern void Internal_CreateInstanceY(GUILayout instance, GUIOption[] options);
Exemplo n.º 23
0
 /// <summary>
 /// Creates a new scroll area.
 /// </summary>
 /// <param name="scrollBarStyle">Optional style that controls the look of the scroll bars. Style will be retrieved 
 ///                              from the active GUISkin. If not specified default element style is used.</param> 
 /// <param name="scrollAreaStyle">Optional style that controls the look of the scroll area. Style will be retrieved 
 ///                              from the active GUISkin. If not specified default element style is used.</param>      
 /// <param name="options">Options that allow you to control how is the element positioned and sized. This will 
 ///                       override any similar options set by style.</param>
 public GUIScrollArea(string scrollBarStyle, string scrollAreaStyle, params GUIOption[] options)
 {
     Internal_CreateInstance(this, ScrollBarType.ShowIfDoesntFit, ScrollBarType.ShowIfDoesntFit, scrollBarStyle, scrollAreaStyle, options);
     _mainLayout = new GUILayoutY(this);
 }
Exemplo n.º 24
0
            public Element(SceneObject so, Component comp, string path)
            {
                this.so = so;
                this.comp = comp;
                this.path = path;

                toggle = null;
                childLayout = null;
                indentLayout = null;

                children = null;
            }
Exemplo n.º 25
0
            /// <summary>
            /// Constructs a new dictionary GUI.
            /// </summary>
            /// <param name="parent">Parent Inspector this field belongs to.</param>
            /// <param name="title">Label to display on the list GUI title.</param>
            /// <param name="path">Full path to this property (includes name of this property and all parent properties).
            /// </param>
            /// <param name="property">Serializable property referencing a dictionary</param>
            /// <param name="layout">Layout to which to append the list GUI elements to.</param>
            /// <param name="depth">Determines at which depth to render the background. Useful when you have multiple
            ///                     nested containers whose backgrounds are overlaping. Also determines background style,
            ///                     depths divisible by two will use an alternate style.</param>
            protected InspectableDictionaryGUI(Inspector parent, LocString title, string path, SerializableProperty property, 
                GUILayout layout, int depth = 0)
                : base(title, layout, depth)
            {
                this.property = property;
                this.parent = parent;
                this.path = path;

                dictionary = property.GetValue<IDictionary>();
                if (dictionary != null)
                    numElements = dictionary.Count;

                UpdateKeys();
            }
Exemplo n.º 26
0
 /// <summary>
 /// Creates a new scroll area.
 /// </summary>
 /// <param name="vertBarType">Type of the vertical scroll bar.</param>
 /// <param name="horzBarType">Type of the horizontal scroll bar.</param>
 /// <param name="options">Options that allow you to control how is the element positioned and sized. This will 
 ///                       override any similar options set by style.</param>
 public GUIScrollArea(ScrollBarType vertBarType, ScrollBarType horzBarType, params GUIOption[] options)
 {
     Internal_CreateInstance(this, vertBarType, horzBarType, "", "", options);
     _mainLayout = new GUILayoutY(this);
 }
Exemplo n.º 27
0
 protected static extern void Internal_CreateInstancePanel(GUILayout instance, Int16 depth, ushort depthRangeMin, 
     ushort depthRangeMax, GUIOption[] options);
Exemplo n.º 28
0
        /// <summary>
        /// Recreates the entire curve editor GUI depending on the currently selected scene object.
        /// </summary>
        private void RebuildGUI()
        {
            GUI.Clear();
            guiCurveEditor = null;
            guiFieldDisplay = null;

            if (selectedSO == null)
            {
                GUILabel warningLbl = new GUILabel(new LocEdString("Select an object to animate in the Hierarchy or Scene windows."));

                GUILayoutY vertLayout = GUI.AddLayoutY();
                vertLayout.AddFlexibleSpace();
                GUILayoutX horzLayout = vertLayout.AddLayoutX();
                vertLayout.AddFlexibleSpace();

                horzLayout.AddFlexibleSpace();
                horzLayout.AddElement(warningLbl);
                horzLayout.AddFlexibleSpace();

                return;
            }

            // Top button row
            GUIContent playIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.Play),
                new LocEdString("Play"));
            GUIContent recordIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.Record),
                new LocEdString("Record"));

            GUIContent prevFrameIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.FrameBack),
                new LocEdString("Previous frame"));
            GUIContent nextFrameIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.FrameForward),
                new LocEdString("Next frame"));

            GUIContent addKeyframeIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.AddKeyframe),
                new LocEdString("Add keyframe"));
            GUIContent addEventIcon = new GUIContent(EditorBuiltin.GetAnimationWindowIcon(AnimationWindowIcon.AddEvent),
                new LocEdString("Add event"));

            GUIContent optionsIcon = new GUIContent(EditorBuiltin.GetLibraryWindowIcon(LibraryWindowIcon.Options),
                new LocEdString("Options"));

            playButton = new GUIToggle(playIcon, EditorStyles.Button);
            recordButton = new GUIToggle(recordIcon, EditorStyles.Button);

            prevFrameButton = new GUIButton(prevFrameIcon);
            frameInputField = new GUIIntField();
            nextFrameButton = new GUIButton(nextFrameIcon);

            addKeyframeButton = new GUIButton(addKeyframeIcon);
            addEventButton = new GUIButton(addEventIcon);

            optionsButton = new GUIButton(optionsIcon);

            playButton.OnToggled += x =>
            {
                if(x)
                    SwitchState(State.Playback);
                else
                    SwitchState(State.Normal);
            };

            recordButton.OnToggled += x =>
            {
                if (x)
                    SwitchState(State.Recording);
                else
                    SwitchState(State.Normal);
            };

            prevFrameButton.OnClick += () =>
            {
                SetCurrentFrame(currentFrameIdx - 1);

                switch (state)
                {
                    case State.Recording:
                    case State.Normal:
                        PreviewFrame(currentFrameIdx);
                        break;
                    default:
                        SwitchState(State.Normal);
                        break;
                }
            };

            frameInputField.OnChanged += x =>
            {
                SetCurrentFrame(x);

                switch (state)
                {
                    case State.Recording:
                    case State.Normal:
                        PreviewFrame(currentFrameIdx);
                        break;
                    default:
                        SwitchState(State.Normal);
                        break;
                }
            };

            nextFrameButton.OnClick += () =>
            {
                SetCurrentFrame(currentFrameIdx + 1);

                switch (state)
                {
                    case State.Recording:
                    case State.Normal:
                        PreviewFrame(currentFrameIdx);
                        break;
                    default:
                        SwitchState(State.Normal);
                        break;
                }
            };

            addKeyframeButton.OnClick += () =>
            {
                SwitchState(State.Normal);
                guiCurveEditor.AddKeyFrameAtMarker();
            };

            addEventButton.OnClick += () =>
            {
                SwitchState(State.Normal);
                guiCurveEditor.AddEventAtMarker();
            };

            optionsButton.OnClick += () =>
            {
                Vector2I openPosition = ScreenToWindowPos(Input.PointerPosition);
                AnimationOptions dropDown = DropDownWindow.Open<AnimationOptions>(this, openPosition);
                dropDown.Initialize(this);
            };

            // Property buttons
            addPropertyBtn = new GUIButton(new LocEdString("Add property"));
            delPropertyBtn = new GUIButton(new LocEdString("Delete selected"));

            addPropertyBtn.OnClick += () =>
            {
                Action openPropertyWindow = () =>
                {
                    Vector2I windowPos = ScreenToWindowPos(Input.PointerPosition);
                    FieldSelectionWindow fieldSelection = DropDownWindow.Open<FieldSelectionWindow>(this, windowPos);
                    fieldSelection.OnFieldSelected += OnFieldAdded;
                };

                if (clipInfo.clip == null)
                {
                    LocEdString title = new LocEdString("Warning");
                    LocEdString message =
                        new LocEdString("Selected object doesn't have an animation clip assigned. Would you like to create" +
                                        " a new animation clip?");

                    DialogBox.Open(title, message, DialogBox.Type.YesNoCancel, type =>
                    {
                        if (type == DialogBox.ResultType.Yes)
                        {
                            string clipSavePath;
                            if (BrowseDialog.SaveFile(ProjectLibrary.ResourceFolder, "*.asset", out clipSavePath))
                            {
                                SwitchState(State.Empty);
                                clipSavePath = Path.ChangeExtension(clipSavePath, ".asset");

                                AnimationClip newClip = new AnimationClip();

                                ProjectLibrary.Create(newClip, clipSavePath);
                                LoadAnimClip(newClip);

                                Animation animation = selectedSO.GetComponent<Animation>();
                                if (animation == null)
                                    animation = selectedSO.AddComponent<Animation>();

                                animation.DefaultClip = newClip;
                                EditorApplication.SetSceneDirty();

                                SwitchState(State.Normal);
                                openPropertyWindow();
                            }
                        }
                    });
                }
                else
                {
                    if (clipInfo.isImported)
                    {
                        LocEdString title = new LocEdString("Warning");
                        LocEdString message =
                            new LocEdString("You cannot add/edit/remove curves from animation clips that" +
                                            " are imported from an external file.");

                        DialogBox.Open(title, message, DialogBox.Type.OK);
                    }
                    else
                    {
                        SwitchState(State.Normal);
                        openPropertyWindow();
                    }
                }
            };

            delPropertyBtn.OnClick += () =>
            {
                if (clipInfo.clip == null)
                    return;

                SwitchState(State.Normal);

                if (clipInfo.isImported)
                {
                    LocEdString title = new LocEdString("Warning");
                    LocEdString message =
                        new LocEdString("You cannot add/edit/remove curves from animation clips that" +
                                        " are imported from an external file.");

                    DialogBox.Open(title, message, DialogBox.Type.OK);
                }
                else
                {
                    LocEdString title = new LocEdString("Warning");
                    LocEdString message = new LocEdString("Are you sure you want to remove all selected fields?");

                    DialogBox.Open(title, message, DialogBox.Type.YesNo, x =>
                    {
                        if (x == DialogBox.ResultType.Yes)
                        {
                            RemoveSelectedFields();
                            ApplyClipChanges();
                        }
                    });
                }
            };

            GUIPanel mainPanel = GUI.AddPanel();
            GUIPanel backgroundPanel = GUI.AddPanel(1);

            GUILayout mainLayout = mainPanel.AddLayoutY();

            buttonLayout = mainLayout.AddLayoutX();
            buttonLayout.AddSpace(5);
            buttonLayout.AddElement(playButton);
            buttonLayout.AddElement(recordButton);
            buttonLayout.AddSpace(5);
            buttonLayout.AddElement(prevFrameButton);
            buttonLayout.AddElement(frameInputField);
            buttonLayout.AddElement(nextFrameButton);
            buttonLayout.AddSpace(5);
            buttonLayout.AddElement(addKeyframeButton);
            buttonLayout.AddElement(addEventButton);
            buttonLayout.AddSpace(5);
            buttonLayout.AddElement(optionsButton);
            buttonLayout.AddFlexibleSpace();

            buttonLayoutHeight = playButton.Bounds.height;

            GUITexture buttonBackground = new GUITexture(null, EditorStyles.HeaderBackground);
            buttonBackground.Bounds = new Rect2I(0, 0, Width, buttonLayoutHeight);
            backgroundPanel.AddElement(buttonBackground);

            GUILayout contentLayout = mainLayout.AddLayoutX();
            GUILayout fieldDisplayLayout = contentLayout.AddLayoutY(GUIOption.FixedWidth(FIELD_DISPLAY_WIDTH));

            guiFieldDisplay = new GUIAnimFieldDisplay(fieldDisplayLayout, FIELD_DISPLAY_WIDTH,
                Height - buttonLayoutHeight * 2, selectedSO);
            guiFieldDisplay.OnEntrySelected += OnFieldSelected;

            GUILayout bottomButtonLayout = fieldDisplayLayout.AddLayoutX();
            bottomButtonLayout.AddElement(addPropertyBtn);
            bottomButtonLayout.AddElement(delPropertyBtn);

            horzScrollBar = new GUIResizeableScrollBarH();
            horzScrollBar.OnScrollOrResize += OnHorzScrollOrResize;

            vertScrollBar = new GUIResizeableScrollBarV();
            vertScrollBar.OnScrollOrResize += OnVertScrollOrResize;

            GUITexture separator = new GUITexture(null, EditorStyles.Separator, GUIOption.FixedWidth(3));
            contentLayout.AddElement(separator);

            GUILayout curveLayout = contentLayout.AddLayoutY();
            GUILayout curveLayoutHorz = curveLayout.AddLayoutX();
            GUILayout horzScrollBarLayout = curveLayout.AddLayoutX();
            horzScrollBarLayout.AddElement(horzScrollBar);
            horzScrollBarLayout.AddFlexibleSpace();

            editorPanel = curveLayoutHorz.AddPanel();
            curveLayoutHorz.AddElement(vertScrollBar);
            curveLayoutHorz.AddFlexibleSpace();

            scrollBarHeight = horzScrollBar.Bounds.height;
            scrollBarWidth = vertScrollBar.Bounds.width;

            Vector2I curveEditorSize = GetCurveEditorSize();
            guiCurveEditor = new GUICurveEditor(this, editorPanel, curveEditorSize.x, curveEditorSize.y);
            guiCurveEditor.OnFrameSelected += OnFrameSelected;
            guiCurveEditor.OnEventAdded += OnEventsChanged;
            guiCurveEditor.OnEventModified += EditorApplication.SetProjectDirty;
            guiCurveEditor.OnEventDeleted += OnEventsChanged;
            guiCurveEditor.OnCurveModified += () =>
            {
                SwitchState(State.Normal);

                ApplyClipChanges();
                PreviewFrame(currentFrameIdx);

                EditorApplication.SetProjectDirty();
            };
            guiCurveEditor.OnClicked += () =>
            {
                if(state != State.Recording)
                    SwitchState(State.Normal);
            };
            guiCurveEditor.Redraw();

            horzScrollBar.SetWidth(curveEditorSize.x);
            vertScrollBar.SetHeight(curveEditorSize.y);

            UpdateScrollBarSize();
        }
Exemplo n.º 29
0
 protected static extern void Internal_CreateInstanceYFromScrollArea(GUILayout instance, GUIScrollArea parentArea);
Exemplo n.º 30
0
        /// <summary>
        /// Refreshes the contents of the content area. Must be called at least once after construction.
        /// </summary>
        /// <param name="viewType">Determines how to display the resource tiles.</param>
        /// <param name="entriesToDisplay">Project library entries to display.</param>
        /// <param name="bounds">Bounds within which to lay out the content entries.</param>
        public void Refresh(ProjectViewType viewType, LibraryEntry[] entriesToDisplay, Rect2I bounds)
        {
            if (mainPanel != null)
                mainPanel.Destroy();

            entries.Clear();
            entryLookup.Clear();

            mainPanel = parent.Layout.AddPanel();

            GUIPanel contentPanel = mainPanel.AddPanel(1);
            overlay = mainPanel.AddPanel(0);
            underlay = mainPanel.AddPanel(2);
            deepUnderlay = mainPanel.AddPanel(3);
            renameOverlay = mainPanel.AddPanel(-1);

            main = contentPanel.AddLayoutY();

            List<ResourceToDisplay> resourcesToDisplay = new List<ResourceToDisplay>();
            foreach (var entry in entriesToDisplay)
            {
                if (entry.Type == LibraryEntryType.Directory)
                    resourcesToDisplay.Add(new ResourceToDisplay(entry.Path, LibraryGUIEntryType.Single));
                else
                {
                    FileEntry fileEntry = (FileEntry)entry;
                    ResourceMeta[] metas = fileEntry.ResourceMetas;

                    if (metas.Length > 0)
                    {
                        if (metas.Length == 1)
                            resourcesToDisplay.Add(new ResourceToDisplay(entry.Path, LibraryGUIEntryType.Single));
                        else
                        {
                            resourcesToDisplay.Add(new ResourceToDisplay(entry.Path, LibraryGUIEntryType.MultiFirst));

                            for (int i = 1; i < metas.Length - 1; i++)
                            {
                                string path = Path.Combine(entry.Path, metas[i].SubresourceName);
                                resourcesToDisplay.Add(new ResourceToDisplay(path, LibraryGUIEntryType.MultiElement));
                            }

                            string lastPath = Path.Combine(entry.Path, metas[metas.Length - 1].SubresourceName);
                            resourcesToDisplay.Add(new ResourceToDisplay(lastPath, LibraryGUIEntryType.MultiLast));
                        }
                    }
                }
            }

            if (viewType == ProjectViewType.List16)
            {
                tileSize = 16;
                gridLayout = false;
                elementsPerRow = 1;
                horzElementSpacing = 0;
                int elemWidth = bounds.width;
                int elemHeight = tileSize;

                main.AddSpace(TOP_MARGIN);

                for (int i = 0; i < resourcesToDisplay.Count; i++)
                {
                    ResourceToDisplay entry = resourcesToDisplay[i];

                    LibraryGUIEntry guiEntry = new LibraryGUIEntry(this, main, entry.path, i, elemWidth, elemHeight,
                        entry.type);
                    entries.Add(guiEntry);
                    entryLookup[guiEntry.path] = guiEntry;

                    if (i != resourcesToDisplay.Count - 1)
                        main.AddSpace(LIST_ENTRY_SPACING);
                }

                main.AddFlexibleSpace();
            }
            else
            {
                int elemWidth = 0;
                int elemHeight = 0;
                int vertElemSpacing = 0;

                switch (viewType)
                {
                    case ProjectViewType.Grid64:
                        tileSize = 64;
                        elemWidth = tileSize;
                        elemHeight = tileSize + 36;
                        horzElementSpacing = 10;
                        vertElemSpacing = 12;
                        break;
                    case ProjectViewType.Grid48:
                        tileSize = 48;
                        elemWidth = tileSize;
                        elemHeight = tileSize + 36;
                        horzElementSpacing = 8;
                        vertElemSpacing = 10;
                        break;
                    case ProjectViewType.Grid32:
                        tileSize = 32;
                        elemWidth = tileSize + 16;
                        elemHeight = tileSize + 48;
                        horzElementSpacing = 6;
                        vertElemSpacing = 10;
                        break;
                }

                gridLayout = true;

                int availableWidth = bounds.width;

                elementsPerRow = MathEx.FloorToInt((availableWidth - horzElementSpacing) / (float)(elemWidth + horzElementSpacing));
                elementsPerRow = Math.Max(elementsPerRow, 1);

                int numRows = MathEx.CeilToInt(resourcesToDisplay.Count / (float)elementsPerRow);
                int neededHeight = numRows * elemHeight + TOP_MARGIN;
                if (numRows > 0)
                    neededHeight += (numRows - 1)* vertElemSpacing;

                bool requiresScrollbar = neededHeight > bounds.height;
                if (requiresScrollbar)
                {
                    availableWidth -= parent.ScrollBarWidth;
                    elementsPerRow = MathEx.FloorToInt((availableWidth - horzElementSpacing) / (float)(elemWidth + horzElementSpacing));
                    elementsPerRow = Math.Max(elementsPerRow, 1);
                }

                int extraRowSpace = availableWidth - (elementsPerRow * (elemWidth + horzElementSpacing) + horzElementSpacing);

                main.AddSpace(TOP_MARGIN);
                GUILayoutX rowLayout = main.AddLayoutX();
                rowLayout.AddSpace(horzElementSpacing);

                int elemsInRow = 0;
                for (int i = 0; i < resourcesToDisplay.Count; i++)
                {
                    if (elemsInRow == elementsPerRow && elemsInRow > 0)
                    {
                        main.AddSpace(vertElemSpacing);
                        rowLayout.AddSpace(extraRowSpace);
                        rowLayout = main.AddLayoutX();
                        rowLayout.AddSpace(horzElementSpacing);

                        elemsInRow = 0;
                    }

                    ResourceToDisplay entry = resourcesToDisplay[i];

                    LibraryGUIEntry guiEntry = new LibraryGUIEntry(this, rowLayout, entry.path, i, elemWidth, elemHeight,
                        entry.type);
                    entries.Add(guiEntry);
                    entryLookup[guiEntry.path] = guiEntry;

                    rowLayout.AddSpace(horzElementSpacing);

                    elemsInRow++;
                }

                int extraElements = elementsPerRow - elemsInRow;
                rowLayout.AddSpace((elemWidth + horzElementSpacing) * extraElements + extraRowSpace);

                main.AddFlexibleSpace();
            }

            for (int i = 0; i < entries.Count; i++)
            {
                LibraryGUIEntry guiEntry = entries[i];
                guiEntry.Initialize();
            }
        }