Utility for fetching asset previews by instance ID of assets, See AssetPreview.GetAssetPreview. Since previews are loaded asynchronously methods are provided for requesting if all previews have been fully loaded, see AssetPreview.IsLoadingAssetPreviews. Loaded previews are stored in a cache, the size of the cache can be controlled by calling [AssetPreview.SetPreviewTextureCacheSize].

示例#1
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (s_DefaultIcon == null)
            {
                Init();
            }
            AudioClip target  = this.target as AudioClip;
            Event     current = Event.current;

            if (((current.type == EventType.Repaint) || (current.type == EventType.Layout)) || (current.type == EventType.Used))
            {
                if (Event.current.type == EventType.Repaint)
                {
                    background.Draw(r, false, false, false, false);
                }
                int channelCount = AudioUtil.GetChannelCount(target);
                m_wantedRect = new Rect(r.x, r.y, r.width, r.height);
                float num3 = m_wantedRect.width / target.length;
                if (!AudioUtil.HasPreview(target) && (AudioUtil.IsTrackerFile(target) || AudioUtil.IsMovieAudio(target)))
                {
                    float y = (r.height <= 150f) ? ((r.y + (r.height / 2f)) - 25f) : ((r.y + (r.height / 2f)) - 10f);
                    if (r.width > 64f)
                    {
                        if (AudioUtil.IsTrackerFile(target))
                        {
                            EditorGUI.DropShadowLabel(new Rect(r.x, y, r.width, 20f), string.Format("Module file with " + AudioUtil.GetMusicChannelCount(target) + " channels.", new object[0]));
                        }
                        else if (AudioUtil.IsMovieAudio(target))
                        {
                            if (r.width > 450f)
                            {
                                EditorGUI.DropShadowLabel(new Rect(r.x, y, r.width, 20f), "Audio is attached to a movie. To audition the sound, play the movie.");
                            }
                            else
                            {
                                EditorGUI.DropShadowLabel(new Rect(r.x, y, r.width, 20f), "Audio is attached to a movie.");
                                EditorGUI.DropShadowLabel(new Rect(r.x, y + 10f, r.width, 20f), "To audition the sound, play the movie.");
                            }
                        }
                        else
                        {
                            EditorGUI.DropShadowLabel(new Rect(r.x, y, r.width, 20f), "Can not show PCM data for this file");
                        }
                    }
                    if (this.m_PlayingClip == target)
                    {
                        float    clipPosition = AudioUtil.GetClipPosition(target);
                        TimeSpan span         = new TimeSpan(0, 0, 0, 0, (int)(clipPosition * 1000f));
                        EditorGUI.DropShadowLabel(new Rect(m_wantedRect.x, m_wantedRect.y, m_wantedRect.width, 20f), string.Format("Playing - {0:00}:{1:00}.{2:000}", span.Minutes, span.Seconds, span.Milliseconds));
                    }
                }
                else
                {
                    PreviewGUI.BeginScrollView(m_wantedRect, this.m_Position, m_wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");
                    Texture2D image = null;
                    if (r.width < 100f)
                    {
                        image = AssetPreview.GetAssetPreview(target);
                    }
                    else
                    {
                        image = AudioUtil.GetWaveFormFast(target, 1, 0, target.samples, r.width, r.height);
                    }
                    if (image == null)
                    {
                        Rect position = new Rect {
                            x      = ((m_wantedRect.width - s_DefaultIcon.width) / 2f) + m_wantedRect.x,
                            y      = ((m_wantedRect.height - s_DefaultIcon.height) / 2f) + m_wantedRect.y,
                            width  = s_DefaultIcon.width,
                            height = s_DefaultIcon.height
                        };
                        GUI.DrawTexture(position, s_DefaultIcon);
                        base.Repaint();
                    }
                    else
                    {
                        GUI.DrawTexture(new Rect(m_wantedRect.x, m_wantedRect.y, m_wantedRect.width, m_wantedRect.height), image);
                    }
                    for (int i = 0; i < channelCount; i++)
                    {
                        if ((channelCount > 1) && (r.width > 64f))
                        {
                            Rect rect2 = new Rect(m_wantedRect.x + 5f, m_wantedRect.y + ((m_wantedRect.height / ((float)channelCount)) * i), 30f, 20f);
                            EditorGUI.DropShadowLabel(rect2, "ch " + ((i + 1)).ToString());
                        }
                    }
                    if (this.m_PlayingClip == target)
                    {
                        float    num7  = AudioUtil.GetClipPosition(target);
                        TimeSpan span2 = new TimeSpan(0, 0, 0, 0, (int)(num7 * 1000f));
                        GUI.DrawTexture(new Rect(m_wantedRect.x + ((int)(num3 * num7)), m_wantedRect.y, 2f, m_wantedRect.height), EditorGUIUtility.whiteTexture);
                        if (r.width > 64f)
                        {
                            EditorGUI.DropShadowLabel(new Rect(m_wantedRect.x, m_wantedRect.y, m_wantedRect.width, 20f), string.Format("{0:00}:{1:00}.{2:000}", span2.Minutes, span2.Seconds, span2.Milliseconds));
                        }
                        else
                        {
                            EditorGUI.DropShadowLabel(new Rect(m_wantedRect.x, m_wantedRect.y, m_wantedRect.width, 20f), string.Format("{0:00}:{1:00}", span2.Minutes, span2.Seconds));
                        }
                        if (!AudioUtil.IsClipPlaying(target))
                        {
                            this.m_PlayingClip = null;
                        }
                    }
                    PreviewGUI.EndScrollView();
                }
                if (m_bPlayFirst)
                {
                    AudioUtil.PlayClip(target, 0, m_bLoop);
                    this.m_PlayingClip = target;
                    m_bPlayFirst       = false;
                }
                if (this.playing)
                {
                    GUIView.current.Repaint();
                }
            }
            else
            {
                int num = AudioUtil.GetSampleCount(target) / ((int)r.width);
                switch (current.type)
                {
                case EventType.MouseDown:
                case EventType.MouseDrag:
                    if (r.Contains(current.mousePosition) && !AudioUtil.IsMovieAudio(target))
                    {
                        if (this.m_PlayingClip != target)
                        {
                            AudioUtil.StopAllClips();
                            AudioUtil.PlayClip(target, 0, m_bLoop);
                            this.m_PlayingClip = target;
                        }
                        AudioUtil.SetClipSamplePosition(target, num * ((int)current.mousePosition.x));
                        current.Use();
                    }
                    break;
                }
            }
        }
示例#2
0
 private void DrawListElement(Rect rect, bool even, AInfo ainfo)
 {
     if (ainfo == null)
     {
         Debug.LogError("DrawListElement: AInfo not valid!");
     }
     else
     {
         float num     = 17f;
         float a       = 0.3f;
         bool  changed = GUI.changed;
         bool  enabled = GUI.enabled;
         Color color   = GUI.color;
         GUI.changed = false;
         GUI.enabled = true;
         GUIStyle style = (!even) ? AnnotationWindow.m_Styles.listOddBg : AnnotationWindow.m_Styles.listEvenBg;
         GUI.Label(rect, GUIContent.Temp(""), style);
         Rect position = rect;
         position.width = rect.width - 64f - 22f;
         GUI.Label(position, ainfo.m_DisplayText, AnnotationWindow.m_Styles.listTextStyle);
         float   num2    = 16f;
         Rect    rect2   = new Rect(rect.width - 64f, rect.y + (rect.height - num2) * 0.5f, num2, num2);
         Texture texture = null;
         if (ainfo.m_ScriptClass != "")
         {
             texture = EditorGUIUtility.GetIconForObject(EditorGUIUtility.GetScript(ainfo.m_ScriptClass));
             Rect position2 = rect2;
             position2.x     += 18f;
             position2.y     += 1f;
             position2.width  = 1f;
             position2.height = 12f;
             if (!EditorGUIUtility.isProSkin)
             {
                 GUI.color = new Color(0f, 0f, 0f, 0.33f);
             }
             else
             {
                 GUI.color = new Color(1f, 1f, 1f, 0.13f);
             }
             GUI.DrawTexture(position2, EditorGUIUtility.whiteTexture, ScaleMode.StretchToFill);
             GUI.color = Color.white;
             Rect rect3 = rect2;
             rect3.x    += 18f;
             rect3.y     = rect3.y;
             rect3.width = 9f;
             if (GUI.Button(rect3, this.iconSelectContent, AnnotationWindow.m_Styles.iconDropDown))
             {
                 UnityEngine.Object script = EditorGUIUtility.GetScript(ainfo.m_ScriptClass);
                 if (script != null)
                 {
                     this.m_LastScriptThatHasShownTheIconSelector = ainfo.m_ScriptClass;
                     if (IconSelector.ShowAtPosition(script, rect3, true))
                     {
                         IconSelector.SetMonoScriptIconChangedCallback(new IconSelector.MonoScriptIconChangedCallback(this.MonoScriptIconChanged));
                         GUIUtility.ExitGUI();
                     }
                 }
             }
         }
         else if (ainfo.HasIcon())
         {
             texture = AssetPreview.GetMiniTypeThumbnailFromClassID(ainfo.m_ClassID);
         }
         if (texture != null)
         {
             if (!ainfo.m_IconEnabled)
             {
                 GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, a);
             }
             this.iconToggleContent.image = texture;
             if (GUI.Button(rect2, this.iconToggleContent, GUIStyle.none))
             {
                 ainfo.m_IconEnabled = !ainfo.m_IconEnabled;
                 this.SetIconState(ainfo);
             }
             GUI.color = color;
         }
         if (GUI.changed)
         {
             this.SetIconState(ainfo);
             GUI.changed = false;
         }
         GUI.enabled = true;
         GUI.color   = color;
         if (ainfo.HasGizmo())
         {
             string tooltip   = "Show/Hide Gizmo";
             Rect   position3 = new Rect(rect.width - 23f, rect.y + (rect.height - num) * 0.5f, num, num);
             ainfo.m_GizmoEnabled = GUI.Toggle(position3, ainfo.m_GizmoEnabled, new GUIContent("", tooltip), AnnotationWindow.m_Styles.toggle);
             if (GUI.changed)
             {
                 this.SetGizmoState(ainfo);
             }
         }
         GUI.enabled = enabled;
         GUI.changed = changed;
         GUI.color   = color;
     }
 }
示例#3
0
 // Create a standard Object-derived asset.
 public static void CreateAsset(Object asset, string pathName)
 {
     StartNameEditingIfProjectWindowExists(asset.GetInstanceID(), ScriptableObject.CreateInstance <DoCreateNewAsset>(), pathName, AssetPreview.GetMiniThumbnail(asset), null);
 }
示例#4
0
        private void OnGUI()
        {
            HandleContextMenu();

            EditorGUILayout.BeginVertical();
            GUILayout.Space(10f);
            EditorGUILayout.BeginHorizontal();
            float leftMargin = (Screen.width / EditorGUIUtility.pixelsPerPoint - Styles.toolbarWidth) * 0.5f;

            GUILayout.Space(leftMargin);
            EditMode.DoInspectorToolbar(k_SceneViewEditModes, Styles.toolContents, GridPaintingState.instance);
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(leftMargin);
            DoActiveTargetsGUI();
            EditorGUILayout.EndHorizontal();
            GUILayout.Space(6f);
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical();
            Rect clipboardToolbarRect = EditorGUILayout.BeginHorizontal(GUIContent.none, "Toolbar");

            DoClipboardHeader();
            EditorGUILayout.EndHorizontal();
            Rect  dragRect           = new Rect(k_DropdownWidth + k_ResizerDragRectPadding, 0, position.width - k_DropdownWidth - k_ResizerDragRectPadding, k_ToolbarHeight);
            float brushInspectorSize = m_PreviewResizer.ResizeHandle(position, k_MinBrushInspectorHeight, k_MinClipboardHeight, k_ToolbarHeight, dragRect);
            float clipboardHeight    = position.height - brushInspectorSize - k_TopAreaHeight;
            Rect  clipboardRect      = new Rect(0f, clipboardToolbarRect.yMax, position.width, clipboardHeight);

            OnClipboardGUI(clipboardRect);
            EditorGUILayout.EndVertical();

            GUILayout.Space(clipboardRect.height);

            EditorGUILayout.BeginVertical();
            EditorGUILayout.BeginHorizontal(GUIContent.none, "Toolbar");
            DoBrushesDropdown();
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            m_BrushScroll = GUILayout.BeginScrollView(m_BrushScroll, false, false);
            GUILayout.Space(5f);
            OnBrushInspectorGUI();
            GUILayout.EndScrollView();
            EditorGUILayout.EndVertical();

            Color oldColor = Handles.color;

            Handles.color = Color.black;
            Handles.DrawLine(new Vector3(0, clipboardRect.yMax + 0.5f, 0), new Vector3(Screen.width, clipboardRect.yMax + 0.5f, 0));
            Handles.color = Color.black.AlphaMultiplied(0.33f);
            Handles.DrawLine(new Vector3(0, GUILayoutUtility.GetLastRect().yMax + 0.5f, 0), new Vector3(Screen.width, GUILayoutUtility.GetLastRect().yMax + 0.5f, 0));
            Handles.color = oldColor;

            EditorGUILayout.BeginVertical();

            GUILayout.Space(2f);

            EditorGUILayout.EndVertical();

            // Keep repainting until all previews are loaded
            if (AssetPreview.IsLoadingAssetPreviews(GetInstanceID()))
            {
                Repaint();
            }

            // Release keyboard focus on click to empty space
            if (Event.current.type == EventType.MouseDown)
            {
                GUIUtility.keyboardControl = 0;
            }
        }
示例#5
0
        private static void DrawObjectFieldLargeThumb(Rect position, int id, Object obj, GUIContent content)
        {
            GUIStyle thumbStyle = EditorStyles.objectFieldThumb;

            thumbStyle.Draw(position, GUIContent.none, id, DragAndDrop.activeControlID == id, position.Contains(Event.current.mousePosition));

            if (obj != null && !showMixedValue)
            {
                bool isCubemap = obj is Cubemap;
                bool isSprite  = obj is Sprite;
                Rect thumbRect = thumbStyle.padding.Remove(position);

                if (isCubemap || isSprite)
                {
                    Texture2D t2d = AssetPreview.GetAssetPreview(obj);
                    if (t2d != null)
                    {
                        if (isSprite || t2d.alphaIsTransparency)
                        {
                            DrawTextureTransparent(thumbRect, t2d);
                        }
                        else
                        {
                            DrawPreviewTexture(thumbRect, t2d);
                        }
                    }
                    else
                    {
                        // Preview not loaded -> Draw icon
                        thumbRect.x += (thumbRect.width - content.image.width) / 2f;
                        thumbRect.y += (thumbRect.height - content.image.width) / 2f;
                        GUIStyle.none.Draw(thumbRect, content.image, false, false, false, false);

                        // Keep repaint until the object field has a proper preview
                        HandleUtility.Repaint();
                    }
                }
                else
                {
                    // Draw texture
                    Texture2D t2d = content.image as Texture2D;
                    if (t2d != null && t2d.alphaIsTransparency)
                    {
                        DrawTextureTransparent(thumbRect, t2d);
                    }
                    else
                    {
                        DrawPreviewTexture(thumbRect, content.image);
                    }
                }
            }
            else
            {
                GUIStyle s2 = thumbStyle.name + "Overlay";
                BeginHandleMixedValueContentColor();

                s2.Draw(position, content, id);
                EndHandleMixedValueContentColor();
            }
            GUIStyle s3 = thumbStyle.name + "Overlay2";

            s3.Draw(position, s_Select, id);
        }
示例#6
0
        internal static Rect DrawHeaderGUI(Editor editor, string header, float leftMargin)
        {
            if (Editor.s_Styles == null)
            {
                Editor.s_Styles = new Editor.Styles();
            }
            GUILayout.BeginHorizontal(Editor.s_Styles.inspectorBig, new GUILayoutOption[0]);
            GUILayout.Space(38f);
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            GUILayout.Space(19f);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            if (leftMargin > 0f)
            {
                GUILayout.Space(leftMargin);
            }
            if (editor)
            {
                editor.OnHeaderControlsGUI();
            }
            else
            {
                EditorGUILayout.GetControlRect(new GUILayoutOption[0]);
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            Rect lastRect = GUILayoutUtility.GetLastRect();
            Rect r        = new Rect(lastRect.x + leftMargin, lastRect.y, lastRect.width - leftMargin, lastRect.height);
            Rect rect     = new Rect(r.x + 6f, r.y + 6f, 32f, 32f);

            if (editor)
            {
                editor.OnHeaderIconGUI(rect);
            }
            else
            {
                GUI.Label(rect, AssetPreview.GetMiniTypeThumbnail(typeof(UnityEngine.Object)), Editor.s_Styles.centerStyle);
            }
            Rect rect2 = new Rect(r.x + 44f, r.y + 6f, r.width - 44f - 38f - 4f, 16f);

            if (editor)
            {
                editor.OnHeaderTitleGUI(rect2, header);
            }
            else
            {
                GUI.Label(rect2, header, EditorStyles.largeLabel);
            }
            if (editor)
            {
                editor.DrawHeaderHelpAndSettingsGUI(r);
            }
            Event current = Event.current;

            if (editor != null && current.type == EventType.MouseDown && current.button == 1 && r.Contains(current.mousePosition))
            {
                EditorUtility.DisplayObjectContextMenu(new Rect(current.mousePosition.x, current.mousePosition.y, 0f, 0f), editor.targets, 0);
                current.Use();
            }
            return(lastRect);
        }
        public void OnGUI(float width, bool fixedWidth)
        {
            bool   flag = Event.current.type == EventType.Repaint;
            string text = null;

            if (this.m_ParticleSystems.Length > 1)
            {
                text = "Multiple Particle Systems";
            }
            else if (this.m_ParticleSystems.Length > 0)
            {
                text = this.m_ParticleSystems[0].gameObject.name;
            }
            if (fixedWidth)
            {
                EditorGUIUtility.labelWidth = width * 0.4f;
                EditorGUILayout.BeginVertical(new GUILayoutOption[]
                {
                    GUILayout.Width(width)
                });
            }
            else
            {
                EditorGUIUtility.labelWidth  = 0f;
                EditorGUIUtility.labelWidth -= 4f;
                EditorGUILayout.BeginVertical(new GUILayoutOption[0]);
            }
            InitialModuleUI initial = (InitialModuleUI)this.m_Modules[0];

            for (int i = 0; i < this.m_Modules.Length; i++)
            {
                ModuleUI moduleUI = this.m_Modules[i];
                if (moduleUI != null)
                {
                    bool flag2 = moduleUI == this.m_Modules[0];
                    if (moduleUI.visibleUI || flag2)
                    {
                        GUIContent gUIContent = new GUIContent();
                        Rect       rect;
                        GUIStyle   style;
                        if (flag2)
                        {
                            rect  = GUILayoutUtility.GetRect(width, 25f);
                            style = ParticleSystemStyles.Get().emitterHeaderStyle;
                        }
                        else
                        {
                            rect  = GUILayoutUtility.GetRect(width, 15f);
                            style = ParticleSystemStyles.Get().moduleHeaderStyle;
                        }
                        if (moduleUI.foldout)
                        {
                            using (new EditorGUI.DisabledScope(!moduleUI.enabled))
                            {
                                Rect position = EditorGUILayout.BeginVertical(ParticleSystemStyles.Get().modulePadding, new GUILayoutOption[0]);
                                position.y      -= 4f;
                                position.height += 4f;
                                GUI.Label(position, GUIContent.none, ParticleSystemStyles.Get().moduleBgStyle);
                                moduleUI.OnInspectorGUI(initial);
                                EditorGUILayout.EndVertical();
                            }
                        }
                        if (flag2)
                        {
                            ParticleSystemRenderer component = this.m_ParticleSystems[0].GetComponent <ParticleSystemRenderer>();
                            float num       = 21f;
                            Rect  position2 = new Rect(rect.x + 4f, rect.y + 2f, num, num);
                            if (flag && component != null)
                            {
                                bool flag3 = false;
                                int  num2  = 0;
                                if (!this.multiEdit)
                                {
                                    if (component.renderMode == ParticleSystemRenderMode.Mesh)
                                    {
                                        if (component.mesh != null)
                                        {
                                            num2 = component.mesh.GetInstanceID();
                                        }
                                    }
                                    else if (component.sharedMaterial != null)
                                    {
                                        num2 = component.sharedMaterial.GetInstanceID();
                                    }
                                    if (EditorUtility.IsDirty(num2))
                                    {
                                        AssetPreview.ClearTemporaryAssetPreviews();
                                    }
                                    if (num2 != 0)
                                    {
                                        Texture2D assetPreview = AssetPreview.GetAssetPreview(num2);
                                        if (assetPreview != null)
                                        {
                                            GUI.DrawTexture(position2, assetPreview, ScaleMode.StretchToFill, true);
                                            flag3 = true;
                                        }
                                    }
                                }
                                if (!flag3)
                                {
                                    GUI.Label(position2, GUIContent.none, ParticleSystemStyles.Get().moduleBgStyle);
                                }
                            }
                            if (!this.multiEdit && EditorGUI.DropdownButton(position2, GUIContent.none, FocusType.Passive, GUIStyle.none))
                            {
                                if (EditorGUI.actionKey)
                                {
                                    List <int> list       = new List <int>();
                                    int        instanceID = this.m_ParticleSystems[0].gameObject.GetInstanceID();
                                    list.AddRange(Selection.instanceIDs);
                                    if (!list.Contains(instanceID) || list.Count != 1)
                                    {
                                        if (list.Contains(instanceID))
                                        {
                                            list.Remove(instanceID);
                                        }
                                        else
                                        {
                                            list.Add(instanceID);
                                        }
                                    }
                                    Selection.instanceIDs = list.ToArray();
                                }
                                else
                                {
                                    Selection.instanceIDs      = new int[0];
                                    Selection.activeInstanceID = this.m_ParticleSystems[0].gameObject.GetInstanceID();
                                }
                            }
                        }
                        Rect position3 = new Rect(rect.x + 2f, rect.y + 1f, 13f, 13f);
                        if (!flag2 && GUI.Button(position3, GUIContent.none, GUIStyle.none))
                        {
                            moduleUI.enabled = !moduleUI.enabled;
                        }
                        Rect position4 = new Rect(rect.x + rect.width - 10f, rect.y + rect.height - 10f, 10f, 10f);
                        Rect position5 = new Rect(position4.x - 4f, position4.y - 4f, position4.width + 4f, position4.height + 4f);
                        Rect position6 = new Rect(position4.x - 23f, position4.y - 8f, 20f, 20f);
                        if (flag2 && EditorGUI.DropdownButton(position5, ParticleSystemUI.s_Texts.addModules, FocusType.Passive, GUIStyle.none))
                        {
                            this.ShowAddModuleMenu();
                        }
                        if (!string.IsNullOrEmpty(text))
                        {
                            gUIContent.text = ((!flag2) ? moduleUI.displayName : text);
                        }
                        else
                        {
                            gUIContent.text = moduleUI.displayName;
                        }
                        gUIContent.tooltip = moduleUI.toolTip;
                        bool flag4 = GUI.Toggle(rect, moduleUI.foldout, gUIContent, style);
                        if (flag4 != moduleUI.foldout)
                        {
                            int button = Event.current.button;
                            if (button != 0)
                            {
                                if (button == 1)
                                {
                                    if (flag2)
                                    {
                                        this.ShowEmitterMenu();
                                    }
                                    else
                                    {
                                        this.ShowModuleMenu(i);
                                    }
                                }
                            }
                            else
                            {
                                bool foldout = !moduleUI.foldout;
                                if (Event.current.control)
                                {
                                    ModuleUI[] modules = this.m_Modules;
                                    for (int j = 0; j < modules.Length; j++)
                                    {
                                        ModuleUI moduleUI2 = modules[j];
                                        if (moduleUI2 != null && moduleUI2.visibleUI)
                                        {
                                            moduleUI2.foldout = foldout;
                                        }
                                    }
                                }
                                else
                                {
                                    moduleUI.foldout = foldout;
                                }
                            }
                        }
                        if (!flag2)
                        {
                            EditorGUI.showMixedValue = moduleUI.enabledHasMultipleDifferentValues;
                            GUIStyle style2 = (!EditorGUI.showMixedValue) ? ParticleSystemStyles.Get().checkmark : ParticleSystemStyles.Get().checkmarkMixed;
                            GUI.Toggle(position3, moduleUI.enabled, GUIContent.none, style2);
                            EditorGUI.showMixedValue = false;
                        }
                        if (flag)
                        {
                            if (flag2)
                            {
                                GUI.Label(position4, GUIContent.none, ParticleSystemStyles.Get().plus);
                            }
                        }
                        if (flag2 && !string.IsNullOrEmpty(this.m_SupportsCullingTextLabel))
                        {
                            GUIContent content = new GUIContent("", ParticleSystemStyles.Get().warningIcon, this.m_SupportsCullingTextLabel);
                            GUI.Label(position6, content);
                        }
                        GUILayout.Space(1f);
                    }
                }
            }
            GUILayout.Space(-1f);
            EditorGUILayout.EndVertical();
            this.ApplyProperties();
        }
        internal static void ShowAssetsPopupMenu <T>(Rect buttonRect, string typeName, SerializedProperty serializedProperty, string fileExtension, string defaultFieldName) where T : Object, new()
        {
            GenericMenu gm = new GenericMenu();

            int selectedInstanceID = serializedProperty.objectReferenceValue != null?serializedProperty.objectReferenceValue.GetInstanceID() : 0;


            bool foundDefaultAsset = false;
            var  type    = UnityEditor.UnityType.FindTypeByName(typeName);
            int  classID = type != null ? type.persistentTypeID : 0;

            BuiltinResource[] resourceList = null;

            // Check the assets for one that matches the default name.
            if (classID > 0)
            {
                resourceList = EditorGUIUtility.GetBuiltinResourceList(classID);
                foreach (var resource in resourceList)
                {
                    if (resource.m_Name == defaultFieldName)
                    {
                        gm.AddItem(new GUIContent(resource.m_Name), resource.m_InstanceID == selectedInstanceID, AssetPopupMenuCallback, new object[] { resource.m_InstanceID, serializedProperty });
                        resourceList      = resourceList.Where(x => x != resource).ToArray();
                        foundDefaultAsset = true;
                        break;
                    }
                }
            }

            // If no defalut asset was found, add defualt null value.
            if (!foundDefaultAsset)
            {
                gm.AddItem(new GUIContent(defaultFieldName), selectedInstanceID == 0, AssetPopupMenuCallback, new object[] { 0, serializedProperty });
            }

            // Add items from asset database
            foreach (var property in AssetDatabase.FindAllAssets(new SearchFilter()
            {
                classNames = new[] { typeName }
            }))
            {
                gm.AddItem(new GUIContent(property.name), property.instanceID == selectedInstanceID, AssetPopupMenuCallback, new object[] { property.instanceID, serializedProperty });
            }

            // Add builtin items, except for the already added default item.
            if (classID > 0 && resourceList != null)
            {
                foreach (var resource in resourceList)
                {
                    gm.AddItem(new GUIContent(resource.m_Name), resource.m_InstanceID == selectedInstanceID, AssetPopupMenuCallback, new object[] { resource.m_InstanceID, serializedProperty });
                }
            }

            var  target   = serializedProperty.serializedObject.targetObject;
            bool isPreset = Preset.IsEditorTargetAPreset(target);

            // the preset object is destroyed with the inspector, and nothing new can be created that needs this link. Fix for case 1208437
            if (!isPreset)
            {
                // Create item
                gm.AddSeparator("");
                gm.AddItem(EditorGUIUtility.TrTextContent("Create New..."), false, delegate
                {
                    var newAsset = Activator.CreateInstance <T>();
                    var doCreate = ScriptableObject.CreateInstance <DoCreateNewAsset>();
                    doCreate.SetProperty(serializedProperty);
                    ProjectWindowUtil.StartNameEditingIfProjectWindowExists(newAsset.GetInstanceID(), doCreate, "New " + typeName + "." + fileExtension, AssetPreview.GetMiniThumbnail(newAsset), null);
                });
            }

            gm.DropDown(buttonRect);
        }
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (AudioClipInspector.s_DefaultIcon == null)
            {
                AudioClipInspector.Init();
            }
            AudioClip audioClip = this.target as AudioClip;
            Event     current   = Event.current;

            if (current.type != EventType.Repaint && current.type != EventType.Layout && current.type != EventType.Used)
            {
                int num = AudioUtil.GetSampleCount(audioClip) / (int)r.width;
                switch (current.type)
                {
                case EventType.MouseDown:
                case EventType.MouseDrag:
                    if (r.Contains(current.mousePosition) && !AudioUtil.IsMovieAudio(audioClip))
                    {
                        if (this.m_PlayingClip != audioClip)
                        {
                            AudioUtil.StopAllClips();
                            AudioUtil.PlayClip(audioClip, 0, AudioClipInspector.m_bLoop);
                            this.m_PlayingClip = audioClip;
                        }
                        AudioUtil.SetClipSamplePosition(audioClip, num * (int)current.mousePosition.x);
                        current.Use();
                    }
                    break;
                }
                return;
            }
            if (Event.current.type == EventType.Repaint)
            {
                background.Draw(r, false, false, false, false);
            }
            int channelCount = AudioUtil.GetChannelCount(audioClip);

            AudioClipInspector.m_wantedRect = new Rect(r.x, r.y, r.width, r.height);
            float num2 = AudioClipInspector.m_wantedRect.width / audioClip.length;

            if (!AudioUtil.HasPreview(audioClip) && (AudioUtil.IsTrackerFile(audioClip) || AudioUtil.IsMovieAudio(audioClip)))
            {
                float num3 = (r.height <= 150f) ? (r.y + r.height / 2f - 25f) : (r.y + r.height / 2f - 10f);
                if (r.width > 64f)
                {
                    if (AudioUtil.IsTrackerFile(audioClip))
                    {
                        EditorGUI.DropShadowLabel(new Rect(r.x, num3, r.width, 20f), string.Format("Module file with " + AudioUtil.GetMusicChannelCount(audioClip) + " channels.", new object[0]));
                    }
                    else
                    {
                        if (AudioUtil.IsMovieAudio(audioClip))
                        {
                            if (r.width > 450f)
                            {
                                EditorGUI.DropShadowLabel(new Rect(r.x, num3, r.width, 20f), "Audio is attached to a movie. To audition the sound, play the movie.");
                            }
                            else
                            {
                                EditorGUI.DropShadowLabel(new Rect(r.x, num3, r.width, 20f), "Audio is attached to a movie.");
                                EditorGUI.DropShadowLabel(new Rect(r.x, num3 + 10f, r.width, 20f), "To audition the sound, play the movie.");
                            }
                        }
                        else
                        {
                            EditorGUI.DropShadowLabel(new Rect(r.x, num3, r.width, 20f), "Can not show PCM data for this file");
                        }
                    }
                }
                if (this.m_PlayingClip == audioClip)
                {
                    float    clipPosition = AudioUtil.GetClipPosition(audioClip);
                    TimeSpan timeSpan     = new TimeSpan(0, 0, 0, 0, (int)(clipPosition * 1000f));
                    EditorGUI.DropShadowLabel(new Rect(AudioClipInspector.m_wantedRect.x, AudioClipInspector.m_wantedRect.y, AudioClipInspector.m_wantedRect.width, 20f), string.Format("Playing - {0:00}:{1:00}.{2:000}", timeSpan.Minutes, timeSpan.Seconds, timeSpan.Milliseconds));
                }
            }
            else
            {
                PreviewGUI.BeginScrollView(AudioClipInspector.m_wantedRect, this.m_Position, AudioClipInspector.m_wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");
                Texture2D texture2D;
                if (r.width < 100f)
                {
                    texture2D = AssetPreview.GetAssetPreview(audioClip);
                }
                else
                {
                    texture2D = AudioUtil.GetWaveFormFast(audioClip, 1, 0, audioClip.samples, r.width, r.height);
                }
                if (texture2D == null)
                {
                    GUI.DrawTexture(new Rect
                    {
                        x      = (AudioClipInspector.m_wantedRect.width - (float)AudioClipInspector.s_DefaultIcon.width) / 2f + AudioClipInspector.m_wantedRect.x,
                        y      = (AudioClipInspector.m_wantedRect.height - (float)AudioClipInspector.s_DefaultIcon.height) / 2f + AudioClipInspector.m_wantedRect.y,
                        width  = (float)AudioClipInspector.s_DefaultIcon.width,
                        height = (float)AudioClipInspector.s_DefaultIcon.height
                    }, AudioClipInspector.s_DefaultIcon);
                    base.Repaint();
                }
                else
                {
                    GUI.DrawTexture(new Rect(AudioClipInspector.m_wantedRect.x, AudioClipInspector.m_wantedRect.y, AudioClipInspector.m_wantedRect.width, AudioClipInspector.m_wantedRect.height), texture2D);
                }
                for (int i = 0; i < channelCount; i++)
                {
                    if (channelCount > 1 && r.width > 64f)
                    {
                        Rect position = new Rect(AudioClipInspector.m_wantedRect.x + 5f, AudioClipInspector.m_wantedRect.y + AudioClipInspector.m_wantedRect.height / (float)channelCount * (float)i, 30f, 20f);
                        EditorGUI.DropShadowLabel(position, "ch " + (i + 1).ToString());
                    }
                }
                if (this.m_PlayingClip == audioClip)
                {
                    float    clipPosition2 = AudioUtil.GetClipPosition(audioClip);
                    TimeSpan timeSpan2     = new TimeSpan(0, 0, 0, 0, (int)(clipPosition2 * 1000f));
                    GUI.DrawTexture(new Rect(AudioClipInspector.m_wantedRect.x + (float)((int)(num2 * clipPosition2)), AudioClipInspector.m_wantedRect.y, 2f, AudioClipInspector.m_wantedRect.height), EditorGUIUtility.whiteTexture);
                    if (r.width > 64f)
                    {
                        EditorGUI.DropShadowLabel(new Rect(AudioClipInspector.m_wantedRect.x, AudioClipInspector.m_wantedRect.y, AudioClipInspector.m_wantedRect.width, 20f), string.Format("{0:00}:{1:00}.{2:000}", timeSpan2.Minutes, timeSpan2.Seconds, timeSpan2.Milliseconds));
                    }
                    else
                    {
                        EditorGUI.DropShadowLabel(new Rect(AudioClipInspector.m_wantedRect.x, AudioClipInspector.m_wantedRect.y, AudioClipInspector.m_wantedRect.width, 20f), string.Format("{0:00}:{1:00}", timeSpan2.Minutes, timeSpan2.Seconds));
                    }
                    if (!AudioUtil.IsClipPlaying(audioClip))
                    {
                        this.m_PlayingClip = null;
                    }
                }
                PreviewGUI.EndScrollView();
            }
            if (AudioClipInspector.m_bPlayFirst)
            {
                AudioUtil.PlayClip(audioClip, 0, AudioClipInspector.m_bLoop);
                this.m_PlayingClip = audioClip;
                AudioClipInspector.m_bPlayFirst = false;
            }
            if (this.playing)
            {
                GUIView.current.Repaint();
            }
        }
示例#10
0
        public static int ShowTerrainLayersSelectionHelper(Terrain terrain, int activeTerrainLayer)
        {
            GUILayout.Label(s_Styles.terrainLayers, EditorStyles.boldLabel);
            GUI.changed = false;
            int selectedTerrainLayer = activeTerrainLayer;

            if (terrain.terrainData.terrainLayers.Length > 0)
            {
                TerrainLayer[] layers           = terrain.terrainData.terrainLayers;
                var            layerGUIContents = new GUIContent[layers.Length];
                for (int i = 0; i < layers.Length; ++i)
                {
                    layerGUIContents[i] = new GUIContent
                    {
                        image   = (layers[i] == null || layers[i].diffuseTexture == null) ? EditorGUIUtility.whiteTexture : AssetPreview.GetAssetPreview(layers[i].diffuseTexture) ?? layers[i].diffuseTexture,
                        text    = layers[i] == null ? "Missing" : layers[i].name,
                        tooltip = layers[i] == null ? "Missing" : layers[i].name
                    };
                }
                selectedTerrainLayer = TerrainInspector.AspectSelectionGridImageAndText(activeTerrainLayer, layerGUIContents, 64, s_Styles.errNoLayersFound, out _);
            }
            else
            {
                selectedTerrainLayer = -1;
            }

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            // menu button
            Rect r = GUILayoutUtility.GetRect(s_Styles.btnEditTerrainLayers, new GUIStyle("Button"));

            if (GUI.Button(r, s_Styles.btnEditTerrainLayers, new GUIStyle("Button")))
            {
                MenuCommand context = new MenuCommand(terrain, selectedTerrainLayer);
                EditorUtility.DisplayPopupMenu(new Rect(r.x, r.y, 0, 0), "CONTEXT /TerrainLayers", context);
            }
            GUILayout.EndHorizontal();

            return(selectedTerrainLayer);
        }
 private void DrawListElement(Rect rect, bool even, AInfo ainfo)
 {
     if (ainfo == null)
     {
         Debug.LogError((object)"DrawListElement: AInfo not valid!");
     }
     else
     {
         float num1    = 17f;
         float a       = 0.3f;
         bool  changed = GUI.changed;
         bool  enabled = GUI.enabled;
         Color color   = GUI.color;
         GUI.changed = false;
         GUI.enabled = true;
         GUIStyle style = !even ? AnnotationWindow.m_Styles.listOddBg : AnnotationWindow.m_Styles.listEvenBg;
         GUI.Label(rect, GUIContent.Temp(string.Empty), style);
         Rect position1 = rect;
         position1.width = (float)((double)rect.width - 64.0 - 22.0);
         GUI.Label(position1, ainfo.m_DisplayText, AnnotationWindow.m_Styles.listTextStyle);
         float   num2      = 16f;
         Rect    position2 = new Rect(rect.width - 64f, rect.y + (float)(((double)rect.height - (double)num2) * 0.5), num2, num2);
         Texture texture   = (Texture)null;
         if (ainfo.m_ScriptClass != string.Empty)
         {
             texture = (Texture)EditorGUIUtility.GetIconForObject(EditorGUIUtility.GetScript(ainfo.m_ScriptClass));
             Rect position3 = position2;
             position3.x += 18f;
             ++position3.y;
             position3.width  = 1f;
             position3.height = 12f;
             GUI.color        = EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.13f) : new Color(0.0f, 0.0f, 0.0f, 0.33f);
             GUI.DrawTexture(position3, (Texture)EditorGUIUtility.whiteTexture, ScaleMode.StretchToFill);
             GUI.color = Color.white;
             Rect rect1 = position2;
             rect1.x += 18f;
             // ISSUE: explicit reference operation
             // ISSUE: variable of a reference type
             Rect& local = @rect1;
             // ISSUE: explicit reference operation
             double y = (double)(^ local).y;
             // ISSUE: explicit reference operation
             (^ local).y = (float)y;
             rect1.width = 9f;
             if (GUI.Button(rect1, this.iconSelectContent, AnnotationWindow.m_Styles.iconDropDown))
             {
                 UnityEngine.Object script = EditorGUIUtility.GetScript(ainfo.m_ScriptClass);
                 if (script != (UnityEngine.Object)null)
                 {
                     this.m_LastScriptThatHasShownTheIconSelector = ainfo.m_ScriptClass;
                     if (IconSelector.ShowAtPosition(script, rect1, true))
                     {
                         IconSelector.SetMonoScriptIconChangedCallback(new IconSelector.MonoScriptIconChangedCallback(this.MonoScriptIconChanged));
                         GUIUtility.ExitGUI();
                     }
                 }
             }
         }
         else if (ainfo.HasIcon())
         {
             texture = (Texture)AssetPreview.GetMiniTypeThumbnailFromClassID(ainfo.m_ClassID);
         }
         if ((UnityEngine.Object)texture != (UnityEngine.Object)null)
         {
             if (!ainfo.m_IconEnabled)
             {
                 GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, a);
                 string empty = string.Empty;
             }
             this.iconToggleContent.image = texture;
             if (GUI.Button(position2, this.iconToggleContent, GUIStyle.none))
             {
                 ainfo.m_IconEnabled = !ainfo.m_IconEnabled;
                 this.SetIconState(ainfo);
             }
             GUI.color = color;
         }
         if (GUI.changed)
         {
             this.SetIconState(ainfo);
             GUI.changed = false;
         }
         GUI.enabled = true;
         GUI.color   = color;
         if (ainfo.HasGizmo())
         {
             string tooltip   = "Show/Hide Gizmo";
             Rect   position3 = new Rect(rect.width - 23f, rect.y + (float)(((double)rect.height - (double)num1) * 0.5), num1, num1);
             ainfo.m_GizmoEnabled = GUI.Toggle(position3, ainfo.m_GizmoEnabled, new GUIContent(string.Empty, tooltip), AnnotationWindow.m_Styles.toggle);
             if (GUI.changed)
             {
                 this.SetGizmoState(ainfo);
             }
         }
         GUI.enabled = enabled;
         GUI.changed = changed;
         GUI.color   = color;
     }
 }
        public void OnGUI(ParticleSystem root, float width, bool fixedWidth)
        {
            if (ParticleSystemUI.s_Texts == null)
            {
                ParticleSystemUI.s_Texts = new ParticleSystemUI.Texts();
            }
            bool   flag1 = Event.current.type == EventType.Repaint;
            string str   = !(bool)((Object)this.m_ParticleSystem) ? (string)null : this.m_ParticleSystem.gameObject.name;

            if (fixedWidth)
            {
                EditorGUIUtility.labelWidth = width * 0.55f;
                EditorGUILayout.BeginVertical(GUILayout.Width(width));
            }
            else
            {
                EditorGUIUtility.labelWidth  = 0.0f;
                EditorGUIUtility.labelWidth -= 4f;
                EditorGUILayout.BeginVertical();
            }
            for (int moduleIndex = 0; moduleIndex < this.m_Modules.Length; ++moduleIndex)
            {
                ModuleUI module1 = this.m_Modules[moduleIndex];
                if (module1 != null)
                {
                    bool flag2 = module1 == this.m_Modules[0];
                    if (module1.visibleUI || flag2)
                    {
                        GUIContent content = new GUIContent();
                        Rect       rect;
                        GUIStyle   style;
                        if (flag2)
                        {
                            rect  = GUILayoutUtility.GetRect(width, 25f);
                            style = ParticleSystemStyles.Get().emitterHeaderStyle;
                        }
                        else
                        {
                            rect  = GUILayoutUtility.GetRect(width, 15f);
                            style = ParticleSystemStyles.Get().moduleHeaderStyle;
                        }
                        if (module1.foldout)
                        {
                            EditorGUI.BeginDisabledGroup(!module1.enabled);
                            Rect position = EditorGUILayout.BeginVertical(ParticleSystemStyles.Get().modulePadding, new GUILayoutOption[0]);
                            position.y      -= 4f;
                            position.height += 4f;
                            GUI.Label(position, GUIContent.none, ParticleSystemStyles.Get().moduleBgStyle);
                            module1.OnInspectorGUI(this.m_ParticleSystem);
                            EditorGUILayout.EndVertical();
                            EditorGUI.EndDisabledGroup();
                        }
                        if (flag2)
                        {
                            ParticleSystemRenderer particleSystemRenderer = this.GetParticleSystemRenderer();
                            float num      = 21f;
                            Rect  position = new Rect(rect.x + 4f, rect.y + 2f, num, num);
                            if (flag1 && (Object)particleSystemRenderer != (Object)null)
                            {
                                bool             flag3      = false;
                                int              instanceID = 0;
                                RendererModuleUI module2    = this.m_Modules[this.m_Modules.Length - 1] as RendererModuleUI;
                                if (module2 != null)
                                {
                                    if (module2.IsMeshEmitter())
                                    {
                                        if ((Object)particleSystemRenderer.mesh != (Object)null)
                                        {
                                            instanceID = particleSystemRenderer.mesh.GetInstanceID();
                                        }
                                    }
                                    else if ((Object)particleSystemRenderer.sharedMaterial != (Object)null)
                                    {
                                        instanceID = particleSystemRenderer.sharedMaterial.GetInstanceID();
                                    }
                                    if (EditorUtility.IsDirty(instanceID))
                                    {
                                        AssetPreview.ClearTemporaryAssetPreviews();
                                    }
                                }
                                if (instanceID != 0)
                                {
                                    Texture2D assetPreview = AssetPreview.GetAssetPreview(instanceID);
                                    if ((Object)assetPreview != (Object)null)
                                    {
                                        GUI.DrawTexture(position, (Texture)assetPreview, ScaleMode.StretchToFill, true);
                                        flag3 = true;
                                    }
                                }
                                if (!flag3)
                                {
                                    GUI.Label(position, GUIContent.none, ParticleSystemStyles.Get().moduleBgStyle);
                                }
                            }
                            if (EditorGUI.ButtonMouseDown(position, GUIContent.none, FocusType.Passive, GUIStyle.none))
                            {
                                if (EditorGUI.actionKey)
                                {
                                    List <int> intList    = new List <int>();
                                    int        instanceId = this.m_ParticleSystem.gameObject.GetInstanceID();
                                    intList.AddRange((IEnumerable <int>)Selection.instanceIDs);
                                    if (!intList.Contains(instanceId) || intList.Count != 1)
                                    {
                                        if (intList.Contains(instanceId))
                                        {
                                            intList.Remove(instanceId);
                                        }
                                        else
                                        {
                                            intList.Add(instanceId);
                                        }
                                    }
                                    Selection.instanceIDs = intList.ToArray();
                                }
                                else
                                {
                                    Selection.instanceIDs      = new int[0];
                                    Selection.activeInstanceID = this.m_ParticleSystem.gameObject.GetInstanceID();
                                }
                            }
                        }
                        Rect position1 = new Rect(rect.x + 2f, rect.y + 1f, 13f, 13f);
                        if (!flag2 && GUI.Button(position1, GUIContent.none, GUIStyle.none))
                        {
                            module1.enabled = !module1.enabled;
                        }
                        Rect position2 = new Rect((float)((double)rect.x + (double)rect.width - 10.0), (float)((double)rect.y + (double)rect.height - 10.0), 10f, 10f);
                        Rect position3 = new Rect(position2.x - 4f, position2.y - 4f, position2.width + 4f, position2.height + 4f);
                        Rect position4 = new Rect(position2.x - 23f, position2.y - 3f, 16f, 16f);
                        if (flag2 && EditorGUI.ButtonMouseDown(position3, ParticleSystemUI.s_Texts.addModules, FocusType.Passive, GUIStyle.none))
                        {
                            this.ShowAddModuleMenu();
                        }
                        content.text    = string.IsNullOrEmpty(str) ? module1.displayName : (!flag2 ? module1.displayName : str);
                        content.tooltip = module1.toolTip;
                        if (GUI.Toggle(rect, module1.foldout, content, style) != module1.foldout)
                        {
                            switch (Event.current.button)
                            {
                            case 0:
                                bool flag4 = !module1.foldout;
                                if (Event.current.control)
                                {
                                    foreach (ModuleUI module2 in this.m_Modules)
                                    {
                                        if (module2 != null && module2.visibleUI)
                                        {
                                            module2.foldout = flag4;
                                        }
                                    }
                                    break;
                                }
                                module1.foldout = flag4;
                                break;

                            case 1:
                                if (flag2)
                                {
                                    this.ShowEmitterMenu();
                                    break;
                                }
                                this.ShowModuleMenu(moduleIndex);
                                break;
                            }
                        }
                        if (!flag2)
                        {
                            GUI.Toggle(position1, module1.enabled, GUIContent.none, ParticleSystemStyles.Get().checkmark);
                        }
                        if (flag1 && flag2)
                        {
                            GUI.Label(position2, GUIContent.none, ParticleSystemStyles.Get().plus);
                        }
                        ParticleSystemUI.s_Texts.supportsCullingText.tooltip = ParticleSystemUI.m_SupportsCullingText;
                        if (flag2 && ParticleSystemUI.s_Texts.supportsCullingText.tooltip != null)
                        {
                            GUI.Label(position4, ParticleSystemUI.s_Texts.supportsCullingText);
                        }
                        GUILayout.Space(1f);
                    }
                }
            }
            GUILayout.Space(-1f);
            EditorGUILayout.EndVertical();
            this.ApplyProperties();
        }
示例#13
0
        public void OnGUI(ParticleSystem root, float width, bool fixedWidth)
        {
            if (ParticleSystemUI.s_Texts == null)
            {
                ParticleSystemUI.s_Texts = new ParticleSystemUI.Texts();
            }
            bool   flag = Event.current.type == EventType.Repaint;
            string text = (!this.m_ParticleSystem) ? null : this.m_ParticleSystem.gameObject.name;

            if (fixedWidth)
            {
                EditorGUIUtility.labelWidth = width * 0.55f;
                EditorGUILayout.BeginVertical(new GUILayoutOption[]
                {
                    GUILayout.Width(width)
                });
            }
            else
            {
                EditorGUIUtility.labelWidth  = 0f;
                EditorGUIUtility.labelWidth -= 4f;
                EditorGUILayout.BeginVertical(new GUILayoutOption[0]);
            }
            for (int i = 0; i < this.m_Modules.Length; i++)
            {
                ModuleUI moduleUI = this.m_Modules[i];
                if (moduleUI != null)
                {
                    bool flag2 = moduleUI == this.m_Modules[0];
                    if (moduleUI.visibleUI || flag2)
                    {
                        GUIContent gUIContent = new GUIContent();
                        Rect       rect;
                        GUIStyle   style;
                        if (flag2)
                        {
                            rect  = GUILayoutUtility.GetRect(width, 25f);
                            style = ParticleSystemStyles.Get().emitterHeaderStyle;
                        }
                        else
                        {
                            rect  = GUILayoutUtility.GetRect(width, 15f);
                            style = ParticleSystemStyles.Get().moduleHeaderStyle;
                        }
                        if (moduleUI.foldout)
                        {
                            EditorGUI.BeginDisabledGroup(!moduleUI.enabled);
                            Rect position = EditorGUILayout.BeginVertical(ParticleSystemStyles.Get().modulePadding, new GUILayoutOption[0]);
                            position.y      -= 4f;
                            position.height += 4f;
                            GUI.Label(position, GUIContent.none, ParticleSystemStyles.Get().moduleBgStyle);
                            moduleUI.OnInspectorGUI(this.m_ParticleSystem);
                            EditorGUILayout.EndVertical();
                            EditorGUI.EndDisabledGroup();
                        }
                        if (flag2)
                        {
                            ParticleSystemRenderer particleSystemRenderer = this.GetParticleSystemRenderer();
                            float num       = 21f;
                            Rect  position2 = new Rect(rect.x + 4f, rect.y + 2f, num, num);
                            if (flag && particleSystemRenderer != null)
                            {
                                bool             flag3            = false;
                                int              num2             = 0;
                                RendererModuleUI rendererModuleUI = this.m_Modules[this.m_Modules.Length - 1] as RendererModuleUI;
                                if (rendererModuleUI != null)
                                {
                                    if (rendererModuleUI.IsMeshEmitter())
                                    {
                                        if (particleSystemRenderer.mesh != null)
                                        {
                                            num2 = particleSystemRenderer.mesh.GetInstanceID();
                                        }
                                    }
                                    else
                                    {
                                        if (particleSystemRenderer.sharedMaterial != null)
                                        {
                                            num2 = particleSystemRenderer.sharedMaterial.GetInstanceID();
                                        }
                                    }
                                    if (EditorUtility.IsDirty(num2))
                                    {
                                        AssetPreview.ClearTemporaryAssetPreviews();
                                    }
                                }
                                if (num2 != 0)
                                {
                                    Texture2D assetPreview = AssetPreview.GetAssetPreview(num2);
                                    if (assetPreview != null)
                                    {
                                        GUI.DrawTexture(position2, assetPreview, ScaleMode.StretchToFill, true);
                                        flag3 = true;
                                    }
                                }
                                if (!flag3)
                                {
                                    GUI.Label(position2, GUIContent.none, ParticleSystemStyles.Get().moduleBgStyle);
                                }
                            }
                            if (EditorGUI.ButtonMouseDown(position2, GUIContent.none, FocusType.Passive, GUIStyle.none))
                            {
                                if (EditorGUI.actionKey)
                                {
                                    List <int> list       = new List <int>();
                                    int        instanceID = this.m_ParticleSystem.gameObject.GetInstanceID();
                                    list.AddRange(Selection.instanceIDs);
                                    if (!list.Contains(instanceID) || list.Count != 1)
                                    {
                                        if (list.Contains(instanceID))
                                        {
                                            list.Remove(instanceID);
                                        }
                                        else
                                        {
                                            list.Add(instanceID);
                                        }
                                    }
                                    Selection.instanceIDs = list.ToArray();
                                }
                                else
                                {
                                    Selection.instanceIDs      = new int[0];
                                    Selection.activeInstanceID = this.m_ParticleSystem.gameObject.GetInstanceID();
                                }
                            }
                        }
                        Rect position3 = new Rect(rect.x + 2f, rect.y + 1f, 13f, 13f);
                        if (!flag2 && GUI.Button(position3, GUIContent.none, GUIStyle.none))
                        {
                            moduleUI.enabled = !moduleUI.enabled;
                        }
                        Rect position4 = new Rect(rect.x + rect.width - 10f, rect.y + rect.height - 10f, 10f, 10f);
                        Rect position5 = new Rect(position4.x - 4f, position4.y - 4f, position4.width + 4f, position4.height + 4f);
                        Rect position6 = new Rect(position4.x - 23f, position4.y - 3f, 16f, 16f);
                        if (flag2 && EditorGUI.ButtonMouseDown(position5, ParticleSystemUI.s_Texts.addModules, FocusType.Passive, GUIStyle.none))
                        {
                            this.ShowAddModuleMenu();
                        }
                        if (!string.IsNullOrEmpty(text))
                        {
                            gUIContent.text = ((!flag2) ? moduleUI.displayName : text);
                        }
                        else
                        {
                            gUIContent.text = moduleUI.displayName;
                        }
                        gUIContent.tooltip = moduleUI.toolTip;
                        bool flag4 = GUI.Toggle(rect, moduleUI.foldout, gUIContent, style);
                        if (flag4 != moduleUI.foldout)
                        {
                            int button = Event.current.button;
                            if (button != 0)
                            {
                                if (button == 1)
                                {
                                    if (flag2)
                                    {
                                        this.ShowEmitterMenu();
                                    }
                                    else
                                    {
                                        this.ShowModuleMenu(i);
                                    }
                                }
                            }
                            else
                            {
                                bool foldout = !moduleUI.foldout;
                                if (Event.current.control)
                                {
                                    ModuleUI[] modules = this.m_Modules;
                                    for (int j = 0; j < modules.Length; j++)
                                    {
                                        ModuleUI moduleUI2 = modules[j];
                                        if (moduleUI2 != null && moduleUI2.visibleUI)
                                        {
                                            moduleUI2.foldout = foldout;
                                        }
                                    }
                                }
                                else
                                {
                                    moduleUI.foldout = foldout;
                                }
                            }
                        }
                        if (!flag2)
                        {
                            GUI.Toggle(position3, moduleUI.enabled, GUIContent.none, ParticleSystemStyles.Get().checkmark);
                        }
                        if (flag && flag2)
                        {
                            GUI.Label(position4, GUIContent.none, ParticleSystemStyles.Get().plus);
                        }
                        ParticleSystemUI.s_Texts.supportsCullingText.tooltip = ParticleSystemUI.m_SupportsCullingText;
                        if (flag2 && ParticleSystemUI.s_Texts.supportsCullingText.tooltip != null)
                        {
                            GUI.Label(position6, ParticleSystemUI.s_Texts.supportsCullingText);
                        }
                        GUILayout.Space(1f);
                    }
                }
            }
            GUILayout.Space(-1f);
            EditorGUILayout.EndVertical();
            this.ApplyProperties();
        }
 public static void CreateAsset(UnityEngine.Object asset, string pathName)
 {
     ProjectWindowUtil.StartNameEditingIfProjectWindowExists(asset.GetInstanceID(), (EndNameEditAction)ScriptableObject.CreateInstance <DoCreateNewAsset>(), pathName, AssetPreview.GetMiniThumbnail(asset), (string)null);
 }
示例#15
0
 public static System.Type SearchBar(params System.Type[] types)
 {
     if (SceneModeUtility.s_NoneButtonContent == null)
     {
         SceneModeUtility.s_NoneButtonContent      = EditorGUIUtility.IconContent("sv_icon_none");
         SceneModeUtility.s_NoneButtonContent.text = "None";
     }
     if (SceneModeUtility.s_FocusType != null && ((UnityEngine.Object)SceneModeUtility.s_HierarchyWindow == (UnityEngine.Object)null || SceneModeUtility.s_HierarchyWindow.m_SearchFilter != "t:" + SceneModeUtility.s_FocusType.Name))
     {
         SceneModeUtility.s_FocusType = (System.Type)null;
     }
     GUILayout.Label("Scene Filter:");
     EditorGUILayout.BeginHorizontal();
     if (SceneModeUtility.TypeButton(EditorGUIUtility.TempContent("All", (Texture)AssetPreview.GetMiniTypeThumbnail(typeof(GameObject))), SceneModeUtility.s_FocusType == null, SceneModeUtility.styles.typeButton))
     {
         SceneModeUtility.SearchForType((System.Type)null);
     }
     for (int index = 0; index < types.Length; ++index)
     {
         System.Type type      = types[index];
         Texture2D   texture2D = type != typeof(Renderer) ? (type != typeof(Terrain) ? AssetPreview.GetMiniTypeThumbnail(type) : EditorGUIUtility.IconContent("Terrain Icon").image as Texture2D) : EditorGUIUtility.IconContent("MeshRenderer Icon").image as Texture2D;
         if (SceneModeUtility.TypeButton(EditorGUIUtility.TempContent(ObjectNames.NicifyVariableName(type.Name) + "s", (Texture)texture2D), type == SceneModeUtility.s_FocusType, SceneModeUtility.styles.typeButton))
         {
             SceneModeUtility.SearchForType(type);
         }
     }
     GUILayout.FlexibleSpace();
     EditorGUILayout.EndHorizontal();
     return(SceneModeUtility.s_FocusType);
 }
示例#16
0
 /// <summary>
 ///   <para>Returns the thumbnail for the type.</para>
 /// </summary>
 /// <param name="type"></param>
 public static Texture2D GetMiniTypeThumbnail(System.Type type)
 {
     return(!typeof(MonoBehaviour).IsAssignableFrom(type) ? AssetPreview.INTERNAL_GetMiniTypeThumbnailFromType(type) : EditorGUIUtility.LoadIcon(type.FullName.Replace('.', '/') + " Icon"));
 }
示例#17
0
 private void DrawListElement(Rect rect, bool even, AInfo ainfo)
 {
     if (ainfo == null)
     {
         Debug.LogError("DrawListElement: AInfo not valid!");
     }
     else
     {
         string str;
         float  width   = 17f;
         float  a       = 0.3f;
         bool   changed = GUI.changed;
         bool   enabled = GUI.enabled;
         Color  color   = GUI.color;
         GUI.changed = false;
         GUI.enabled = true;
         GUIStyle style = !even ? m_Styles.listOddBg : m_Styles.listEvenBg;
         GUI.Label(rect, GUIContent.Temp(string.Empty), style);
         Rect position = rect;
         position.width = (rect.width - 64f) - 22f;
         GUI.Label(position, ainfo.m_DisplayText, m_Styles.listTextStyle);
         float   num3          = 16f;
         Rect    rect3         = new Rect(rect.width - 64f, rect.y + ((rect.height - num3) * 0.5f), num3, num3);
         Texture iconForObject = null;
         if (ainfo.m_ScriptClass != string.Empty)
         {
             iconForObject = EditorGUIUtility.GetIconForObject(EditorGUIUtility.GetScript(ainfo.m_ScriptClass));
             Rect rect4 = rect3;
             rect4.x += 18f;
             rect4.y++;
             rect4.width  = 1f;
             rect4.height = 12f;
             if (!EditorGUIUtility.isProSkin)
             {
                 GUI.color = new Color(0f, 0f, 0f, 0.33f);
             }
             else
             {
                 GUI.color = new Color(1f, 1f, 1f, 0.13f);
             }
             GUI.DrawTexture(rect4, EditorGUIUtility.whiteTexture, ScaleMode.StretchToFill);
             GUI.color = Color.white;
             Rect rect5 = rect3;
             rect5.x    += 18f;
             rect5.y     = rect5.y;
             rect5.width = 9f;
             if (GUI.Button(rect5, this.iconSelectContent, m_Styles.iconDropDown))
             {
                 Object script = EditorGUIUtility.GetScript(ainfo.m_ScriptClass);
                 if (script != null)
                 {
                     this.m_LastScriptThatHasShownTheIconSelector = ainfo.m_ScriptClass;
                     if (IconSelector.ShowAtPosition(script, rect5, true))
                     {
                         IconSelector.SetMonoScriptIconChangedCallback(new IconSelector.MonoScriptIconChangedCallback(this.MonoScriptIconChanged));
                         GUIUtility.ExitGUI();
                     }
                 }
             }
         }
         else if (ainfo.HasIcon())
         {
             iconForObject = AssetPreview.GetMiniTypeThumbnailFromClassID(ainfo.m_ClassID);
         }
         if (iconForObject != null)
         {
             if (!ainfo.m_IconEnabled)
             {
                 GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, a);
                 str       = string.Empty;
             }
             this.iconToggleContent.image = iconForObject;
             if (GUI.Button(rect3, this.iconToggleContent, GUIStyle.none))
             {
                 ainfo.m_IconEnabled = !ainfo.m_IconEnabled;
                 this.SetIconState(ainfo);
             }
             GUI.color = color;
         }
         if (GUI.changed)
         {
             this.SetIconState(ainfo);
             GUI.changed = false;
         }
         GUI.enabled = true;
         GUI.color   = color;
         if (ainfo.HasGizmo())
         {
             str = "Show/Hide Gizmo";
             Rect rect6 = new Rect(rect.width - 23f, rect.y + ((rect.height - width) * 0.5f), width, width);
             ainfo.m_GizmoEnabled = GUI.Toggle(rect6, ainfo.m_GizmoEnabled, new GUIContent(string.Empty, str), m_Styles.toggle);
             if (GUI.changed)
             {
                 this.SetGizmoState(ainfo);
             }
         }
         GUI.enabled = enabled;
         GUI.changed = changed;
         GUI.color   = color;
     }
 }
示例#18
0
 internal static Texture2D GetMiniTypeThumbnail(UnityEngine.Object obj)
 {
     return(AssetPreview.INTERNAL_GetMiniTypeThumbnailFromObject(obj));
 }
示例#19
0
        internal static Rect DrawHeaderGUI(Editor editor, string header, float leftMargin)
        {
            GUILayout.BeginHorizontal(BaseStyles.inspectorBig);
            GUILayout.Space(kImageSectionWidth - 6);
            GUILayout.BeginVertical();
            GUILayout.Space(k_HeaderHeight);
            GUILayout.BeginHorizontal();
            if (leftMargin > 0f)
            {
                GUILayout.Space(leftMargin);
            }
            if (editor)
            {
                editor.OnHeaderControlsGUI();
            }
            else
            {
                EditorGUILayout.GetControlRect();
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            Rect fullRect = GUILayoutUtility.GetLastRect();

            // Content rect
            Rect r = new Rect(fullRect.x + leftMargin, fullRect.y, fullRect.width - leftMargin, fullRect.height);

            // Icon
            Rect iconRect = new Rect(r.x + 6, r.y + 6, 32, 32);

            if (editor)
            {
                editor.OnHeaderIconGUI(iconRect);
            }
            else
            {
                GUI.Label(iconRect, AssetPreview.GetMiniTypeThumbnail(typeof(UnityObject)), BaseStyles.centerStyle);
            }

            if (editor)
            {
                editor.DrawPostIconContent(iconRect);
            }

            // Help and Settings
            Rect titleRect;

            if (editor)
            {
                Rect  helpAndSettingsRect = editor.DrawHeaderHelpAndSettingsGUI(r);
                float rectX = r.x + kImageSectionWidth;
                titleRect = new Rect(rectX, r.y + 6, (helpAndSettingsRect.x - rectX) - 4, 16);
            }
            else
            {
                titleRect = new Rect(r.x + kImageSectionWidth, r.y + 6, r.width - kImageSectionWidth, 16);
            }

            // Title
            if (editor)
            {
                editor.OnHeaderTitleGUI(titleRect, header);
            }
            else
            {
                GUI.Label(titleRect, header, EditorStyles.largeLabel);
            }

            // Context Menu
            Event evt = Event.current;

            if (editor != null && evt.type == EventType.MouseDown && evt.button == 1 && r.Contains(evt.mousePosition))
            {
                EditorUtility.DisplayObjectContextMenu(new Rect(evt.mousePosition.x, evt.mousePosition.y, 0, 0), editor.targets, 0);
                evt.Use();
            }

            return(fullRect);
        }
示例#20
0
 internal static Texture2D GetAssetPreview(int instanceID)
 {
     return(AssetPreview.GetAssetPreview(instanceID, 0));
 }
示例#21
0
 public TypeSelection(string typeName, UnityEngine.Object[] objects)
 {
     this.objects     = objects;
     this.label       = new GUIContent(objects.Length.ToString() + " " + ObjectNames.NicifyVariableName(typeName) + (objects.Length <= 1 ? string.Empty : "s"));
     this.label.image = (Texture)AssetPreview.GetMiniTypeThumbnail(objects[0]);
 }
示例#22
0
 /// <summary>
 ///   <para>Loading previews is asynchronous so it is useful to know if a specific asset preview is in the process of being loaded so client code e.g can repaint while waiting for the loading to finish.</para>
 /// </summary>
 /// <param name="instanceID">InstanceID of the assset that a preview has been requested for by: AssetPreview.GetAssetPreview().</param>
 public static bool IsLoadingAssetPreview(int instanceID)
 {
     return(AssetPreview.IsLoadingAssetPreview(instanceID, 0));
 }
示例#23
0
        public void OnGUI(float width, bool fixedWidth)
        {
            bool isRepaintEvent = Event.current.type == EventType.Repaint;

            // Name of current emitter
            string selectedEmitterName = null;

            if (m_ParticleSystems.Length > 1)
            {
                selectedEmitterName = "Multiple Particle Systems";
            }
            else if (m_ParticleSystems.Length > 0)
            {
                selectedEmitterName = m_ParticleSystems[0].gameObject.name;
            }

            if (fixedWidth)
            {
                EditorGUIUtility.labelWidth = width * 0.4f;
                EditorGUILayout.BeginVertical(GUILayout.Width(width));
            }
            else
            {
                // First make sure labelWidth is at default width, then subtract
                EditorGUIUtility.labelWidth = 0;
                EditorGUIUtility.labelWidth = EditorGUIUtility.labelWidth - 4;

                EditorGUILayout.BeginVertical();
            }

            {
                InitialModuleUI initial = (InitialModuleUI)m_Modules[0];
                for (int i = 0; i < m_Modules.Length; ++i)
                {
                    ModuleUI module = m_Modules[i];
                    if (module == null)
                    {
                        continue;
                    }

                    bool initialModule = (module == m_Modules[0]);

                    // Skip if not visible (except initial module which should always be visible)
                    if (!module.visibleUI && !initialModule)
                    {
                        continue;
                    }

                    // Module header size
                    GUIContent headerLabel = new GUIContent();
                    Rect       moduleHeaderRect;
                    if (initialModule)
                    {
                        moduleHeaderRect = GUILayoutUtility.GetRect(width, 25);
                    }
                    else
                    {
                        moduleHeaderRect = GUILayoutUtility.GetRect(width, 15);
                    }

                    // Module content here to render it below the the header
                    if (module.foldout)
                    {
                        using (new EditorGUI.DisabledScope(!module.enabled))
                        {
                            Rect moduleSize = EditorGUILayout.BeginVertical(ParticleSystemStyles.Get().modulePadding);
                            {
                                moduleSize.y      -= 4; // pull background 'up' behind title to fill rounded corners.
                                moduleSize.height += 4;
                                GUI.Label(moduleSize, GUIContent.none, ParticleSystemStyles.Get().moduleBgStyle);
                                module.OnInspectorGUI(initial);
                            }
                            EditorGUILayout.EndVertical();
                        }
                    }

                    // TODO: Get Texture instead of static preview. Render Icon (below titlebar due to rounded corners)
                    if (initialModule)
                    {
                        // Get preview of material or mesh
                        ParticleSystemRenderer renderer = m_ParticleSystems[0].GetComponent <ParticleSystemRenderer>();
                        float iconSize = 21;
                        Rect  iconRect = new Rect(moduleHeaderRect.x + 4, moduleHeaderRect.y + 2, iconSize, iconSize);

                        if (isRepaintEvent && renderer != null)
                        {
                            bool iconRendered = false;

                            if (!multiEdit)
                            {
                                int instanceID = 0;

                                if (renderer.renderMode == ParticleSystemRenderMode.Mesh)
                                {
                                    if (renderer.mesh != null)
                                    {
                                        instanceID = renderer.mesh.GetInstanceID();

                                        // If the asset is dirty we ensure to get a updated one by clearing cache of temporary previews
                                        if (m_CachedMeshInstanceID != instanceID)
                                        {
                                            m_CachedMeshInstanceID = instanceID;
                                            m_CachedMeshDirtyCount = -1;
                                        }
                                        if (EditorUtility.GetDirtyCount(instanceID) != m_CachedMeshDirtyCount)
                                        {
                                            AssetPreview.ClearTemporaryAssetPreviews();
                                            m_CachedMeshDirtyCount = EditorUtility.GetDirtyCount(instanceID);
                                        }
                                    }
                                }
                                else if (renderer.sharedMaterial != null)
                                {
                                    instanceID = renderer.sharedMaterial.GetInstanceID();

                                    // If the asset is dirty we ensure to get a updated one by clearing cache of temporary previews
                                    if (m_CachedMaterialInstanceID != instanceID)
                                    {
                                        m_CachedMaterialInstanceID = instanceID;
                                        m_CachedMaterialDirtyCount = -1;
                                    }
                                    if (EditorUtility.GetDirtyCount(instanceID) != m_CachedMaterialDirtyCount)
                                    {
                                        AssetPreview.ClearTemporaryAssetPreviews();
                                        m_CachedMaterialDirtyCount = EditorUtility.GetDirtyCount(instanceID);
                                    }
                                }

                                if (instanceID != 0)
                                {
                                    Texture2D icon = AssetPreview.GetAssetPreview(instanceID);
                                    if (icon != null)
                                    {
                                        GUI.DrawTexture(iconRect, icon, ScaleMode.StretchToFill, true);
                                        iconRendered = true;
                                    }
                                }
                            }

                            // Fill so we do not see the background when we have no icon (eg multi-edit)
                            if (!iconRendered)
                            {
                                GUI.Label(iconRect, GUIContent.none, ParticleSystemStyles.Get().moduleBgStyle);
                            }
                        }

                        // Select gameObject when clicking on icon
                        if (!multiEdit && EditorGUI.DropdownButton(iconRect, GUIContent.none, FocusType.Passive, GUIStyle.none))
                        {
                            // Toggle selected particle system from selection
                            if (EditorGUI.actionKey)
                            {
                                List <int> newSelection = new List <int>();
                                int        instanceID   = m_ParticleSystems[0].gameObject.GetInstanceID();
                                newSelection.AddRange(Selection.instanceIDs);
                                if (!newSelection.Contains(instanceID) || newSelection.Count != 1)
                                {
                                    if (newSelection.Contains(instanceID))
                                    {
                                        newSelection.Remove(instanceID);
                                    }
                                    else
                                    {
                                        newSelection.Add(instanceID);
                                    }
                                }

                                Selection.instanceIDs = newSelection.ToArray();
                            }
                            else
                            {
                                Selection.instanceIDs      = new int[0];
                                Selection.activeInstanceID = m_ParticleSystems[0].gameObject.GetInstanceID();
                            }
                        }
                    }

                    // Button logic for enabledness (see below for UI)
                    Rect checkMarkRect = new Rect(moduleHeaderRect.x + 2, moduleHeaderRect.y + 1, 13, 13);
                    if (!initialModule && GUI.Button(checkMarkRect, GUIContent.none, GUIStyle.none))
                    {
                        module.enabled = !module.enabled;
                    }

                    // Button logic for plus/minus (see below for UI)
                    Rect plusRect         = new Rect(moduleHeaderRect.x + moduleHeaderRect.width - 10, moduleHeaderRect.y + moduleHeaderRect.height - 10, 10, 10);
                    Rect plusRectInteract = new Rect(plusRect.x - 4, plusRect.y - 4, plusRect.width + 4, plusRect.height + 4);
                    Rect infoRect         = new Rect(plusRect.x - 23, plusRect.y - 8, 20, 20);

                    if (initialModule && EditorGUI.DropdownButton(plusRectInteract, s_Texts.addModules, FocusType.Passive, GUIStyle.none))
                    {
                        ShowAddModuleMenu();
                    }

                    // Module header (last to become top most renderered)
                    if (!string.IsNullOrEmpty(selectedEmitterName))
                    {
                        headerLabel.text = initialModule ? selectedEmitterName : module.displayName;
                    }
                    else
                    {
                        headerLabel.text = module.displayName;
                    }
                    headerLabel.tooltip = module.toolTip;

                    bool newToggleState = module.DrawHeader(moduleHeaderRect, headerLabel);

                    if (newToggleState != module.foldout)
                    {
                        switch (Event.current.button)
                        {
                        case 0:
                            bool newFoldoutState = !module.foldout;
                            if (Event.current.control)
                            {
                                foreach (var moduleUi in m_Modules)
                                {
                                    if (moduleUi != null && moduleUi.visibleUI)
                                    {
                                        moduleUi.foldout = newFoldoutState;
                                    }
                                }
                            }
                            else
                            {
                                module.foldout = newFoldoutState;
                            }
                            break;

                        case 1:
                            if (initialModule)
                            {
                                ShowEmitterMenu();
                            }
                            else
                            {
                                ShowModuleMenu(i);
                            }
                            break;
                        }
                    }

                    // Render checkmark on top (logic: see above)
                    if (!initialModule)
                    {
                        EditorGUI.showMixedValue = module.enabledHasMultipleDifferentValues;
                        GUIStyle style = EditorGUI.showMixedValue ? ParticleSystemStyles.Get().toggleMixed : ParticleSystemStyles.Get().toggle;
                        GUI.Toggle(checkMarkRect, module.enabled, GUIContent.none, style);
                        EditorGUI.showMixedValue = false;
                    }

                    // Render plus/minus on top
                    if (isRepaintEvent && initialModule)
                    {
                        GUI.Label(plusRect, GUIContent.none, ParticleSystemStyles.Get().plus);
                    }

                    if (initialModule && !string.IsNullOrEmpty(m_SupportsCullingTextLabel))
                    {
                        var supportsCullingText = new GUIContent("", ParticleSystemStyles.Get().warningIcon, m_SupportsCullingTextLabel);
                        GUI.Label(infoRect, supportsCullingText);
                    }

                    GUILayout.Space(1); // dist to next module
                } // foreach module
                GUILayout.Space(-1);
            }
            EditorGUILayout.EndVertical(); // end fixed moduleWidth

            // Apply the property, handle undo
            ApplyProperties();
        }
示例#24
0
 /// <summary>
 ///   <para>Loading previews is asynchronous so it is useful to know if any requested previews are in the process of being loaded so client code e.g can repaint while waiting.</para>
 /// </summary>
 public static bool IsLoadingAssetPreviews()
 {
     return(AssetPreview.IsLoadingAssetPreviews(0));
 }
示例#25
0
        internal static Object DoObjectField(Rect position, Rect dropRect, int id, Object obj, System.Type objType, SerializedProperty property, ObjectFieldValidator validator, bool allowSceneObjects, GUIStyle style)
        {
            if (validator == null)
            {
                validator = ValidateObjectFieldAssignment;
            }
            Event     evt       = Event.current;
            EventType eventType = evt.type;

            // special case test, so we continue to ping/select objects with the object field disabled
            if (!GUI.enabled && GUIClip.enabled && (Event.current.rawType == EventType.MouseDown))
            {
                eventType = Event.current.rawType;
            }

            bool hasThumbnail = EditorGUIUtility.HasObjectThumbnail(objType);

            // Determine visual type
            ObjectFieldVisualType visualType = ObjectFieldVisualType.IconAndText;

            if (hasThumbnail && position.height <= kObjectFieldMiniThumbnailHeight && position.width <= kObjectFieldMiniThumbnailWidth)
            {
                visualType = ObjectFieldVisualType.MiniPreview;
            }
            else if (hasThumbnail && position.height > kSingleLineHeight)
            {
                visualType = ObjectFieldVisualType.LargePreview;
            }

            Vector2 oldIconSize = EditorGUIUtility.GetIconSize();

            if (visualType == ObjectFieldVisualType.IconAndText)
            {
                EditorGUIUtility.SetIconSize(new Vector2(12, 12));  // Have to be this small to fit inside a single line height ObjectField
            }
            else if (visualType == ObjectFieldVisualType.LargePreview)
            {
                EditorGUIUtility.SetIconSize(new Vector2(64, 64));
            }

            switch (eventType)
            {
            case EventType.DragExited:
                if (GUI.enabled)
                {
                    HandleUtility.Repaint();
                }

                break;

            case EventType.DragUpdated:
            case EventType.DragPerform:

                if (dropRect.Contains(Event.current.mousePosition) && GUI.enabled)
                {
                    Object[] references      = DragAndDrop.objectReferences;
                    Object   validatedObject = validator(references, objType, property, ObjectFieldValidatorOptions.None);

                    if (validatedObject != null)
                    {
                        // If scene objects are not allowed and object is a scene object then clear
                        if (!allowSceneObjects && !EditorUtility.IsPersistent(validatedObject))
                        {
                            validatedObject = null;
                        }
                    }

                    if (validatedObject != null)
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
                        if (eventType == EventType.DragPerform)
                        {
                            if (property != null)
                            {
                                property.objectReferenceValue = validatedObject;
                            }
                            else
                            {
                                obj = validatedObject;
                            }

                            GUI.changed = true;
                            DragAndDrop.AcceptDrag();
                            DragAndDrop.activeControlID = 0;
                        }
                        else
                        {
                            DragAndDrop.activeControlID = id;
                        }
                        Event.current.Use();
                    }
                }
                break;

            case EventType.MouseDown:
                // Ignore right clicks
                if (Event.current.button != 0)
                {
                    break;
                }
                if (position.Contains(Event.current.mousePosition))
                {
                    // Get button rect for Object Selector
                    Rect buttonRect = GetButtonRect(visualType, position);

                    EditorGUIUtility.editingTextField = false;

                    if (buttonRect.Contains(Event.current.mousePosition))
                    {
                        if (GUI.enabled)
                        {
                            GUIUtility.keyboardControl = id;
                            ObjectSelector.get.Show(obj, objType, property, allowSceneObjects);
                            ObjectSelector.get.objectSelectorID = id;

                            evt.Use();
                            GUIUtility.ExitGUI();
                        }
                    }
                    else
                    {
                        Object    actualTargetObject = property != null ? property.objectReferenceValue : obj;
                        Component com = actualTargetObject as Component;
                        if (com)
                        {
                            actualTargetObject = com.gameObject;
                        }
                        if (showMixedValue)
                        {
                            actualTargetObject = null;
                        }

                        // One click shows where the referenced object is, or pops up a preview
                        if (Event.current.clickCount == 1)
                        {
                            GUIUtility.keyboardControl = id;

                            PingObjectOrShowPreviewOnClick(actualTargetObject, position);
                            evt.Use();
                        }
                        // Double click opens the asset in external app or changes selection to referenced object
                        else if (Event.current.clickCount == 2)
                        {
                            if (actualTargetObject)
                            {
                                AssetDatabase.OpenAsset(actualTargetObject);
                                GUIUtility.ExitGUI();
                            }
                            evt.Use();
                        }
                    }
                }
                break;

            case EventType.ExecuteCommand:
                string commandName = evt.commandName;
                if (commandName == ObjectSelector.ObjectSelectorUpdatedCommand && ObjectSelector.get.objectSelectorID == id && GUIUtility.keyboardControl == id && (property == null || !property.isScript))
                {
                    return(AssignSelectedObject(property, validator, objType, evt));
                }
                else if (commandName == ObjectSelector.ObjectSelectorClosedCommand && ObjectSelector.get.objectSelectorID == id && GUIUtility.keyboardControl == id && property != null && property.isScript)
                {
                    if (ObjectSelector.get.GetInstanceID() == 0)
                    {
                        // User canceled object selection; don't apply
                        evt.Use();
                        break;
                    }
                    return(AssignSelectedObject(property, validator, objType, evt));
                }
                break;

            case EventType.KeyDown:
                if (GUIUtility.keyboardControl == id)
                {
                    if (evt.keyCode == KeyCode.Backspace || (evt.keyCode == KeyCode.Delete && (evt.modifiers & EventModifiers.Shift) == 0))
                    {
                        if (property != null)
                        {
                            property.objectReferenceValue = null;
                        }
                        else
                        {
                            obj = null;
                        }

                        GUI.changed = true;
                        evt.Use();
                    }

                    // Apparently we have to check for the character being space instead of the keyCode,
                    // otherwise the Inspector will maximize upon pressing space.
                    if (evt.MainActionKeyForControl(id))
                    {
                        ObjectSelector.get.Show(obj, objType, property, allowSceneObjects);
                        ObjectSelector.get.objectSelectorID = id;
                        evt.Use();
                        GUIUtility.ExitGUI();
                    }
                }
                break;

            case EventType.Repaint:
                GUIContent temp;
                if (showMixedValue)
                {
                    temp = s_MixedValueContent;
                }
                else if (property != null)
                {
                    temp = EditorGUIUtility.TempContent(property.objectReferenceStringValue, AssetPreview.GetMiniThumbnail(property.objectReferenceValue));
                    obj  = property.objectReferenceValue;
                    if (obj != null)
                    {
                        Object[] references = { obj };
                        if (EditorSceneManager.preventCrossSceneReferences && CheckForCrossSceneReferencing(obj, property.serializedObject.targetObject))
                        {
                            if (!EditorApplication.isPlaying)
                            {
                                temp = s_SceneMismatch;
                            }
                            else
                            {
                                temp.text = temp.text + string.Format(" ({0})", GetGameObjectFromObject(obj).scene.name);
                            }
                        }
                        else if (validator(references, objType, property, ObjectFieldValidatorOptions.ExactObjectTypeValidation) == null)
                        {
                            temp = s_TypeMismatch;
                        }
                    }
                }
                else
                {
                    temp = EditorGUIUtility.ObjectContent(obj, objType);
                }

                switch (visualType)
                {
                case ObjectFieldVisualType.IconAndText:
                    BeginHandleMixedValueContentColor();
                    style.Draw(position, temp, id, DragAndDrop.activeControlID == id, position.Contains(Event.current.mousePosition));

                    Rect buttonRect = EditorStyles.objectFieldButton.margin.Remove(GetButtonRect(visualType, position));
                    EditorStyles.objectFieldButton.Draw(buttonRect, GUIContent.none, id, DragAndDrop.activeControlID == id, buttonRect.Contains(Event.current.mousePosition));
                    EndHandleMixedValueContentColor();
                    break;

                case ObjectFieldVisualType.LargePreview:
                    DrawObjectFieldLargeThumb(position, id, obj, temp);
                    break;

                case ObjectFieldVisualType.MiniPreview:
                    DrawObjectFieldMiniThumb(position, id, obj, temp);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;
            }

            EditorGUIUtility.SetIconSize(oldIconSize);

            return(obj);
        }
示例#26
0
 internal static bool HasAnyNewPreviewTexturesAvailable()
 {
     return(AssetPreview.HasAnyNewPreviewTexturesAvailable(0));
 }
        void DrawListElement(Rect rect, bool even, AInfo ainfo)
        {
            if (ainfo == null)
            {
                Debug.LogError("DrawListElement: AInfo not valid!");
                return;
            }

            string tooltip;
            float  togglerSize   = 17;
            float  disabledAlpha = 0.3f;

            // We maintain our own gui.changed
            bool  orgGUIChanged = GUI.changed;
            bool  orgGUIEnabled = GUI.enabled;
            Color orgColor      = GUI.color;

            GUI.changed = false;
            GUI.enabled = true;

            // Bg
            GUIStyle backgroundStyle = even ? m_Styles.listEvenBg : m_Styles.listOddBg;

            GUI.Label(rect, GUIContent.Temp(""), backgroundStyle);


            // Text
            Rect textRect = rect;

            //textRect.x += 22;
            textRect.width = rect.width - iconRightAlign - 22; // ensure text doesnt flow behind toggles
            GUI.Label(textRect, ainfo.m_DisplayText, m_Styles.listTextStyle);


            // Icon toggle
            float   iconSize = 16;
            Rect    iconRect = new Rect(rect.width - iconRightAlign, rect.y + (rect.height - iconSize) * 0.5f, iconSize, iconSize);
            Texture thumb    = null;

            if (ainfo.m_ScriptClass != "")
            {
                // Icon for scripts
                thumb = EditorGUIUtility.GetIconForObject(EditorGUIUtility.GetScript(ainfo.m_ScriptClass));

                Rect div = iconRect;
                div.x     += 18;
                div.y     += 1;
                div.width  = 1;
                div.height = 12;

                if (!EditorGUIUtility.isProSkin)
                {
                    GUI.color = new Color(0, 0, 0, 0.33f);
                }
                else
                {
                    GUI.color = new Color(1, 1, 1, 0.13f);
                }

                GUI.DrawTexture(div, EditorGUIUtility.whiteTexture, ScaleMode.StretchToFill);
                GUI.color = Color.white;

                Rect arrowRect = iconRect;
                arrowRect.x    += 18;
                arrowRect.y    += 0;
                arrowRect.width = 9;

                if (GUI.Button(arrowRect, iconSelectContent, m_Styles.iconDropDown))
                {
                    Object script = EditorGUIUtility.GetScript(ainfo.m_ScriptClass);
                    if (script != null)
                    {
                        m_LastScriptThatHasShownTheIconSelector = ainfo.m_ScriptClass;
                        if (IconSelector.ShowAtPosition(script, arrowRect, true))
                        {
                            IconSelector.SetMonoScriptIconChangedCallback(MonoScriptIconChanged);
                            GUIUtility.ExitGUI();
                        }
                    }
                }
            }
            else
            {
                // Icon for builtin components
                if (ainfo.HasIcon())
                {
                    thumb = AssetPreview.GetMiniTypeThumbnailFromClassID(ainfo.m_ClassID);
                }
            }

            if (thumb != null)
            {
                if (!ainfo.m_IconEnabled)
                {
                    GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, disabledAlpha);
                    tooltip   = "";
                }

                iconToggleContent.image = thumb;
                if (GUI.Button(iconRect, iconToggleContent, GUIStyle.none))
                {
                    ainfo.m_IconEnabled = !ainfo.m_IconEnabled;
                    SetIconState(ainfo);
                }

                GUI.color = orgColor;
            }

            if (GUI.changed)
            {
                SetIconState(ainfo);
                GUI.changed = false;
            }

            GUI.enabled = true;
            GUI.color   = orgColor;

            // Gizmo toggle
            if (ainfo.HasGizmo())
            {
                tooltip = textGizmoVisible;

                Rect togglerRect = new Rect(rect.width - gizmoRightAlign, rect.y + (rect.height - togglerSize) * 0.5f, togglerSize, togglerSize);
                ainfo.m_GizmoEnabled = GUI.Toggle(togglerRect, ainfo.m_GizmoEnabled, new GUIContent("", tooltip), m_Styles.toggle);
                if (GUI.changed)
                {
                    SetGizmoState(ainfo);
                }
            }

            GUI.enabled = orgGUIEnabled;
            GUI.changed = orgGUIChanged;
            GUI.color   = orgColor;
        }
示例#28
0
 /// <summary>
 ///   <para>Set the asset preview cache to a size that can hold all visible previews on the screen at once.</para>
 /// </summary>
 /// <param name="size">The number of previews that can be loaded into the cache before the least used previews are being unloaded.</param>
 public static void SetPreviewTextureCacheSize(int size)
 {
     AssetPreview.SetPreviewTextureCacheSize(size, 0);
 }
示例#29
0
        public void OnGUI(ParticleSystem root, float width, bool fixedWidth)
        {
            if (s_Texts == null)
            {
                s_Texts = new Texts();
            }
            bool   flag = Event.current.type == EventType.Repaint;
            string name = this.m_ParticleSystem?.gameObject.name;

            if (fixedWidth)
            {
                EditorGUIUtility.labelWidth = width * 0.4f;
                GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(width) };
                EditorGUILayout.BeginVertical(options);
            }
            else
            {
                EditorGUIUtility.labelWidth  = 0f;
                EditorGUIUtility.labelWidth -= 4f;
                EditorGUILayout.BeginVertical(new GUILayoutOption[0]);
            }
            for (int i = 0; i < this.m_Modules.Length; i++)
            {
                GUIStyle emitterHeaderStyle;
                Rect     rect;
                bool     flag5;
                ModuleUI eui = this.m_Modules[i];
                if (eui == null)
                {
                    continue;
                }
                bool flag2 = eui == this.m_Modules[0];
                if (!eui.visibleUI && !flag2)
                {
                    continue;
                }
                GUIContent content = new GUIContent();
                if (flag2)
                {
                    rect = GUILayoutUtility.GetRect(width, 25f);
                    emitterHeaderStyle = ParticleSystemStyles.Get().emitterHeaderStyle;
                }
                else
                {
                    rect = GUILayoutUtility.GetRect(width, 15f);
                    emitterHeaderStyle = ParticleSystemStyles.Get().moduleHeaderStyle;
                }
                if (eui.foldout)
                {
                    using (new EditorGUI.DisabledScope(!eui.enabled))
                    {
                        Rect rect2 = EditorGUILayout.BeginVertical(ParticleSystemStyles.Get().modulePadding, new GUILayoutOption[0]);
                        rect2.y      -= 4f;
                        rect2.height += 4f;
                        GUI.Label(rect2, GUIContent.none, ParticleSystemStyles.Get().moduleBgStyle);
                        eui.OnInspectorGUI(this.m_ParticleSystem);
                        EditorGUILayout.EndVertical();
                    }
                }
                if (flag2)
                {
                    ParticleSystemRenderer particleSystemRenderer = this.GetParticleSystemRenderer();
                    float num2  = 21f;
                    Rect  rect3 = new Rect(rect.x + 4f, rect.y + 2f, num2, num2);
                    if (flag && (particleSystemRenderer != null))
                    {
                        bool             flag3      = false;
                        int              instanceID = 0;
                        RendererModuleUI eui2       = this.m_Modules[this.m_Modules.Length - 1] as RendererModuleUI;
                        if (eui2 != null)
                        {
                            if (eui2.IsMeshEmitter())
                            {
                                if (particleSystemRenderer.mesh != null)
                                {
                                    instanceID = particleSystemRenderer.mesh.GetInstanceID();
                                }
                            }
                            else if (particleSystemRenderer.sharedMaterial != null)
                            {
                                instanceID = particleSystemRenderer.sharedMaterial.GetInstanceID();
                            }
                            if (EditorUtility.IsDirty(instanceID))
                            {
                                AssetPreview.ClearTemporaryAssetPreviews();
                            }
                        }
                        if (instanceID != 0)
                        {
                            Texture2D assetPreview = AssetPreview.GetAssetPreview(instanceID);
                            if (assetPreview != null)
                            {
                                GUI.DrawTexture(rect3, assetPreview, ScaleMode.StretchToFill, true);
                                flag3 = true;
                            }
                        }
                        if (!flag3)
                        {
                            GUI.Label(rect3, GUIContent.none, ParticleSystemStyles.Get().moduleBgStyle);
                        }
                    }
                    if (EditorGUI.ButtonMouseDown(rect3, GUIContent.none, FocusType.Passive, GUIStyle.none))
                    {
                        if (EditorGUI.actionKey)
                        {
                            List <int> list = new List <int>();
                            int        item = this.m_ParticleSystem.gameObject.GetInstanceID();
                            list.AddRange(Selection.instanceIDs);
                            if (!list.Contains(item) || (list.Count != 1))
                            {
                                if (list.Contains(item))
                                {
                                    list.Remove(item);
                                }
                                else
                                {
                                    list.Add(item);
                                }
                            }
                            Selection.instanceIDs = list.ToArray();
                        }
                        else
                        {
                            Selection.instanceIDs      = new int[0];
                            Selection.activeInstanceID = this.m_ParticleSystem.gameObject.GetInstanceID();
                        }
                    }
                }
                Rect position = new Rect(rect.x + 2f, rect.y + 1f, 13f, 13f);
                if (!flag2 && GUI.Button(position, GUIContent.none, GUIStyle.none))
                {
                    eui.enabled = !eui.enabled;
                }
                Rect rect5 = new Rect((rect.x + rect.width) - 10f, (rect.y + rect.height) - 10f, 10f, 10f);
                Rect rect6 = new Rect(rect5.x - 4f, rect5.y - 4f, rect5.width + 4f, rect5.height + 4f);
                Rect rect7 = new Rect(rect5.x - 23f, rect5.y - 3f, 16f, 16f);
                if (flag2 && EditorGUI.ButtonMouseDown(rect6, s_Texts.addModules, FocusType.Passive, GUIStyle.none))
                {
                    this.ShowAddModuleMenu();
                }
                if (!string.IsNullOrEmpty(name))
                {
                    content.text = !flag2 ? eui.displayName : name;
                }
                else
                {
                    content.text = eui.displayName;
                }
                content.tooltip = eui.toolTip;
                if (GUI.Toggle(rect, eui.foldout, content, emitterHeaderStyle) != eui.foldout)
                {
                    switch (Event.current.button)
                    {
                    case 0:
                        flag5 = !eui.foldout;
                        if (!Event.current.control)
                        {
                            goto Label_05BB;
                        }
                        foreach (ModuleUI eui3 in this.m_Modules)
                        {
                            if ((eui3 != null) && eui3.visibleUI)
                            {
                                eui3.foldout = flag5;
                            }
                        }
                        break;

                    case 1:
                        if (flag2)
                        {
                            this.ShowEmitterMenu();
                        }
                        else
                        {
                            this.ShowModuleMenu(i);
                        }
                        break;
                    }
                }
                goto Label_05E9;
Label_05BB:
                eui.foldout = flag5;
Label_05E9:
                if (!flag2)
                {
                    GUI.Toggle(position, eui.enabled, GUIContent.none, ParticleSystemStyles.Get().checkmark);
                }
                if (flag && flag2)
                {
                    GUI.Label(rect5, GUIContent.none, ParticleSystemStyles.Get().plus);
                }
                s_Texts.supportsCullingText.tooltip = this.m_SupportsCullingText;
                if (flag2 && (s_Texts.supportsCullingText.tooltip != null))
                {
                    GUI.Label(rect7, s_Texts.supportsCullingText);
                }
                GUILayout.Space(1f);
            }
            GUILayout.Space(-1f);
            EditorGUILayout.EndVertical();
            this.ApplyProperties();
        }
 internal override void OnHeaderIconGUI(Rect iconRect)
 {
     // Even though we have a Preview panel, we don't want to reuse it for the header icon, because it looks very odd when
     // you start scrubbing through different slices etc. Just render the default icon for Texture2DArray objects.
     GUI.Label(iconRect, AssetPreview.GetMiniThumbnail(target));
 }