コード例 #1
0
        /// <summary>
        ///     Draws the UI.
        /// </summary>
        /// <param name="rect">The rect.</param>
        /// <returns></returns>
        public BatcherState DrawUI(Rect rect)
        {
            if (CurrentDownload == null)
            {
                BatcherState = BatcherState.NoPendingDownloads;
                return(BatcherState);
            }

            GUI.BeginGroup(rect, GUI.skin.box);
            {
                const float height = 20f,
                            border = 2f;

                Color fillColor       = Color.white,
                      backgroundColor = Color.gray;

                bool  reportProgress = m_ProgressValue != null;
                float progressValue  = m_CurrentProgress * (1 - m_CallbackLoadPercentage) +
                                       m_ReportedProgress * m_CallbackLoadPercentage;
                float finalValue = !reportProgress ? m_CurrentProgress : progressValue;

                float fillPerc1 = finalValue,
                      fillPerc2 = finalValue / m_CurrentPendingItems;

                var _rect        = rect.ResetPosition();
                var labelRect    = GetRectFor(_rect, height * 2);
                var labelCaption = $"Download item {fillPerc1 * 100f:F2}%" + (m_CurrentPendingItems > 1
                                       ? $" of total {fillPerc2 * 100f:F2}%"
                                       : string.Empty) +
                                   Environment.NewLine +
                                   $"({m_CurrentPendingItems} pending items -- {GetCaption()})";

                GUI.Label(
                    labelRect,
                    labelCaption,
                    GlobalGUIStyle.WithCenteredRichText());

                var bar1Rect = GetRectFor(_rect, height).SumTop(height * 2 + 5);
                UIUtils.DrawBar(bar1Rect, fillPerc1, fillColor, backgroundColor, border);

                var bar2Rect = GetRectFor(_rect, height).SumTop(height * 3 + 10);
                UIUtils.DrawBar(bar2Rect, fillPerc2, fillColor, backgroundColor, border);
            }
            GUI.EndGroup();

            if (!m_PendingAsyncDownloadsFlag)
            {
                BatcherState = Update();
            }
            else
            {
                return(BatcherState.PendingAsyncDownloads);
            }

            return(BatcherState);
        }
コード例 #2
0
        /// <summary>
        /// Called when [GUI].
        /// </summary>
        /// <param name="position">The position.</param>
        /// <param name="property">The property.</param>
        /// <param name="label">The label.</param>
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            const float helpBoxSize             = 25f,
                        lateralInspectorPadding = 15f;

            float finalWidth = EditorGUIUtility.currentViewWidth - lateralInspectorPadding;

            var declaringType = fieldInfo.DeclaringType;

            if (!declaringType.BaseType.FullName.Contains("MonoSingleton"))
            {
                EditorGUI.HelpBox(position, "Declaring type of this field is not a MonoSingleton.", MessageType.Error);
                noContentHeight = helpBoxSize;
                return;
            }

            if (!declaringType.IsExecutingInEditMode())
            {
                EditorGUI.HelpBox(position,
                                  "Declared MonoBehaviour needs to have [ExecuteInEditMode] attribute declared in order to view the Gif.",
                                  MessageType.Warning);
            }

            if (hasException)
            {
                var content = new GUIContent(exception.ToString());

                float helpBoxHeight = EditorStyles.helpBox.CalcHeight(content, finalWidth);

                EditorGUI.HelpBox(position, content.text, MessageType.Error);
                position.y += helpBoxHeight;

                noContentHeight = helpBoxHeight;

                // TODO: Add button to reload assemblies

                // Exit UI
                return;
            }

            try
            {
                if (!m_drawOnce)
                {
                    m_boxBackground = new Color32(33, 33, 33, 128).ToTexture();
                    m_drawOnce      = true;
                }

                if (m_finalHeight.HasValue)
                {
                    GUI.Box(
                        new Rect(position.position, new Vector2(finalWidth - 10, m_finalHeight.Value)),
                        string.Empty,
                        new GUIStyle("box")
                    {
                        normal = new GUIStyleState()
                        {
                            background = m_boxBackground
                        }
                    });
                }

                EditorGUI.BeginProperty(position, label, property);
                {
                    if (Application.isPlaying)
                    {
                        EditorGUI.HelpBox(position, "Inspector isn't showed while playing!", MessageType.Warning);
                        position.y += helpBoxSize;

                        noContentHeight = helpBoxSize;

                        // Exit UI
                        return;
                    }

                    var gif = fieldInfo.GetValue(property.serializedObject.targetObject) as UniGif.GifFile;

                    EditorUtility.SetDirty(property.serializedObject.targetObject);

                    const float defHeight = 16f;

                    r = new RectHelper(position);

                    var monoProp = property.FindPropertyRelative("mono");

                    if (monoProp.objectReferenceValue == null)
                    {
                        monoProp.objectReferenceValue = (Object)declaringType.GetInstanceFromSingleton();
                    }

                    var    pathProp = property.FindPropertyRelative("path");
                    string path     = pathProp.stringValue;

                    // Sloppy patch
                    r.VerticalSpace(-15f);

                    const float texSize = 64f;

                    var buttonRect = r.NextHeight(texSize);
                    var _labelRect = buttonRect.RestLeft(20);
                    var _boxRect   = _labelRect.RestLeft(20);

                    var   labelContent = new GUIContent($"<b>GIF:</b> {fieldInfo.Name}");
                    float labelWidth   = GUI.skin.label.CalcSize(labelContent).x;

                    GUI.Label(_labelRect.ForceWidth(labelWidth).RestTop(defHeight + 5), labelContent, GlobalGUIStyle.WithCenteredRichText());
                    GUI.Box(_boxRect.ForceWidth(texSize).SumLeft(labelWidth + 5).RestTop(texSize - (defHeight + 5)), m_firstFrame);

                    if (GUI.Button(_boxRect.ForceBoth(defHeight * 2, defHeight).SumLeft(labelWidth + texSize + 10).SumTop(5), "..."))
                    {
                        string gifPath;
                        do
                        {
                            gifPath = EditorUtility.OpenFilePanel("Search for gif", string.IsNullOrEmpty(path) ? Application.dataPath : path, "gif");
                            pathProp.stringValue = gifPath;

                            validPath = CheckValidGif(path);

                            if (string.IsNullOrEmpty(path))
                            {
                                break;
                            }
                        }while (!validPath);

                        if (validPath && path != gifPath)
                        {
                            // Do something when the property changes
                            gif.UpdateFromPath(gifPath, this);

                            SetFirstFrame(gif);
                        }
                    }

                    r.VerticalSpace(5);

                    var foldoutRect = r.GetNextHeight(defHeight).SumLeft(15f);
                    if (Event.current.type == EventType.MouseUp && foldoutRect.Contains(Event.current.mousePosition))
                    {
                        isFoldout   = !isFoldout;
                        GUI.changed = true;
                        Event.current.Use();
                    }

                    if (validPath)
                    {
                        isFoldout           = EditorGUI.Foldout(foldoutRect, isFoldout, "Display GIF");
                        property.isExpanded = isFoldout;

                        if (property.isExpanded)
                        {
                            const float vertSpace = 40f,
                                        vertFix   = -15f;

                            r.VerticalSpace(vertSpace);
                            gif.Draw(r);

                            var withCenteredRichText = GlobalGUIStyle.WithCenteredRichText();

                            // Fixed: Uneccesary height appears after the gif
                            Rect labelRect   = r.NextHeight(defHeight),
                                 marqueeRect = r.NextHeight(defHeight);

                            // Sloppy patch
                            labelRect.y   += vertFix;
                            marqueeRect.y += vertFix;

                            GUI.Label(labelRect, "<b>Current Loaded Gif Path</b>", withCenteredRichText);
                            MarqueeEffect.MarqueeLabelOnHover(marqueeRect, $"{path.Replace(Application.dataPath + "/", "")}");

                            r.VerticalSpace(vertFix);
                        }
                        else
                        {
                            r.VerticalSpace(15);
                        }

                        SetFirstFrame(gif);
                    }

                    OnceUILoaded(property, path, gif);
                }
                EditorGUI.EndProperty();

                m_finalHeight = r.CurrentHeight;
            }
            catch (Exception ex)
            {
                exception = ex;
                Debug.LogException(ex);
            }
        }
コード例 #3
0
        public static GUISkinOverride Push(GlobalGUIStyle guiStyle, GUIStyle style)
        {
            GUIStyle oldStyle = null;

            switch (guiStyle)
            {
            case GlobalGUIStyle.ScrollView:
                oldStyle            = GUI.skin.scrollView;
                GUI.skin.scrollView = style;
                break;

            case GlobalGUIStyle.VerticalScrollbarDownButton:
                oldStyle = GUI.skin.verticalScrollbarDownButton;
                GUI.skin.verticalScrollbarDownButton = style;
                break;

            case GlobalGUIStyle.VerticalScrollbarThumb:
                oldStyle = GUI.skin.verticalScrollbarThumb;
                GUI.skin.verticalScrollbarThumb = style;
                break;

            case GlobalGUIStyle.VerticalScrollbar:
                oldStyle = GUI.skin.verticalScrollbar;
                GUI.skin.verticalScrollbar = style;
                break;

            case GlobalGUIStyle.HorizontalScrollbarRightButton:
                oldStyle = GUI.skin.horizontalScrollbarRightButton;
                GUI.skin.horizontalScrollbarRightButton = style;
                break;

            case GlobalGUIStyle.HorizontalScrollbarLeftButton:
                oldStyle = GUI.skin.horizontalScrollbarLeftButton;
                GUI.skin.horizontalScrollbarLeftButton = style;
                break;

            case GlobalGUIStyle.HorizontalScrollbarThumb:
                oldStyle = GUI.skin.horizontalScrollbarThumb;
                GUI.skin.horizontalScrollbarThumb = style;
                break;

            case GlobalGUIStyle.HorizontalScrollbar:
                oldStyle = GUI.skin.horizontalScrollbar;
                GUI.skin.horizontalScrollbar = style;
                break;

            case GlobalGUIStyle.VerticalSliderThumb:
                oldStyle = GUI.skin.verticalSliderThumb;
                GUI.skin.verticalSliderThumb = style;
                break;

            case GlobalGUIStyle.VerticalSlider:
                oldStyle = GUI.skin.verticalSlider;
                GUI.skin.verticalSlider = style;
                break;

            case GlobalGUIStyle.HorizontalSliderThumb:
                oldStyle = GUI.skin.horizontalSliderThumb;
                GUI.skin.horizontalSliderThumb = style;
                break;

            case GlobalGUIStyle.Window:
                oldStyle        = GUI.skin.window;
                GUI.skin.window = style;
                break;

            case GlobalGUIStyle.Toggle:
                oldStyle        = GUI.skin.toggle;
                GUI.skin.toggle = style;
                break;

            case GlobalGUIStyle.Button:
                oldStyle        = GUI.skin.button;
                GUI.skin.button = style;
                break;

            case GlobalGUIStyle.TextArea:
                oldStyle          = GUI.skin.textArea;
                GUI.skin.textArea = style;
                break;

            case GlobalGUIStyle.TextField:
                oldStyle           = GUI.skin.textField;
                GUI.skin.textField = style;
                break;

            case GlobalGUIStyle.Label:
                oldStyle       = GUI.skin.label;
                GUI.skin.label = style;
                break;

            case GlobalGUIStyle.Box:
                oldStyle     = GUI.skin.box;
                GUI.skin.box = style;
                break;
            }

            return(new GUISkinOverride()
            {
                _oldStyle = oldStyle,
                _style = guiStyle
            });
        }