OnPreviewGUI() public method

Implement to create your own custom preview for the preview area of the inspector, primary editor headers and the object selector.

public OnPreviewGUI ( Rect r, GUIStyle background ) : void
r UnityEngine.Rect Rectangle in which to draw the preview.
background UnityEngine.GUIStyle Background image.
return void
Esempio n. 1
0
        public override void OnGUI(Rect rect)
        {
            if (m_Editor == null)
            {
                editorWindow.Close();
                return;
            }

            if (s_Styles == null)
            {
                s_Styles = new Styles();
            }


            // Toolbar
            GUILayout.BeginArea(new Rect(rect.x, rect.y, rect.width, kToolbarHeight), s_Styles.toolbar);
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            m_Editor.OnPreviewSettings();
            EditorGUILayout.EndHorizontal();
            GUILayout.EndArea();

            const float kMaxSettingsWidth = 140f;

            GUI.Label(new Rect(rect.x + 5f, rect.y, rect.width - kMaxSettingsWidth, kToolbarHeight), m_ObjectName, s_Styles.toolbarText);

            // Object preview
            Rect previewRect = new Rect(rect.x, rect.y + kToolbarHeight, rect.width, rect.height - kToolbarHeight);

            m_Editor.OnPreviewGUI(previewRect, s_Styles.background);
        }
Esempio n. 2
0
        public override void OnPreviewGUI(Rect position, GUIStyle style)
        {
            Editor selectedMaterialInspector = this.GetSelectedMaterialInspector();

            if (selectedMaterialInspector)
            {
                selectedMaterialInspector.OnPreviewGUI(position, style);
            }
        }
        public override void OnPreviewGUI(Rect position, GUIStyle style)
        {
            Editor materialInspector = this.GetSelectedMaterialInspector();

            if (!(bool)((UnityEngine.Object)materialInspector))
            {
                return;
            }
            materialInspector.OnPreviewGUI(position, style);
        }
Esempio n. 4
0
 void OnGUI()
 {
     if (previewEditor != null)
     {
         if (previewEditor.HasPreviewGUI())
         {
             Rect r = GUILayoutUtility.GetRect(100, 100, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
             previewEditor.OnPreviewGUI(r, GUIStyle.none);
         }
     }
 }
Esempio n. 5
0
 public override void OnPreviewGUI(Rect r, GUIStyle background)
 {
     if (m_weapon.Model)
     {
         if (m_editor == null)
         {
             m_editor = UnityEditor.Editor.CreateEditor(m_weapon.Model);
         }
         m_editor.OnPreviewGUI(r, background);
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Draw the visual preview pane for a prefab.
        /// </summary>
        /// <param name="prefab">The prefab.</param>
        private static void DrawVisualPreview(GameObject prefab)
        {
            bool showPreview = true;

            // Unity 2017 will not display the preview window with OnPreviewGUI. A ticket has been submitted to them.
            //#if UNITY_2017
            //showPreview = false;
            //#endif

            // exit early if preview should not be visible
            if (!showPreview || prefab == null)
            {
                return;
            }

            SimpleLayout.BeginVertical(Box.StyleB);
            SimpleLayout.Label("Preview:");
            gameObjectEditor = UnityEditor.Editor.CreateEditor(prefab);
            gameObjectEditor.OnPreviewGUI(GUILayoutUtility.GetRect(200, 200), Box.StyleImagePreview);
            SimpleLayout.EndVertical();
            Object.DestroyImmediate(gameObjectEditor);
        }
Esempio n. 7
0
        public override void OnGUI(Rect rect)
        {
            if (m_Editor == null)
            {
                editorWindow.Close();
                return;
            }

            if (s_Styles == null)
            {
                s_Styles = new Styles();
            }

            // Toolbar
            Rect toolbarRect = EditorGUILayout.BeginHorizontal(GUIContent.none, s_Styles.toolbar, GUILayout.Height(kToolbarHeight));

            {
                GUILayout.FlexibleSpace();
                Rect contentRect = EditorGUILayout.BeginHorizontal();
                m_Editor.OnPreviewSettings();
                EditorGUILayout.EndHorizontal();

                const float kPadding  = 5f;
                Rect        labelRect = new Rect(toolbarRect.x + kPadding, toolbarRect.y, toolbarRect.width - contentRect.width - 2 * kPadding, toolbarRect.height);
                Vector2     labelSize = s_Styles.toolbarText.CalcSize(m_ObjectName);
                labelRect.width      = Mathf.Min(labelRect.width, labelSize.x);
                m_ObjectName.tooltip = m_ObjectName.text;
                GUI.Label(labelRect, m_ObjectName, s_Styles.toolbarText);
            }
            EditorGUILayout.EndHorizontal();

            // Object preview
            Rect previewRect = new Rect(rect.x, rect.y + kToolbarHeight, rect.width, rect.height - kToolbarHeight);

            m_Editor.OnPreviewGUI(previewRect, s_Styles.background);
        }
Esempio n. 8
0
        public void OnGUI(Rect rect)
        {
            Rect PreviewRect = new Rect(
                rect.x + rect.width * 0.6f - 10, rect.y + 10,
                rect.width * 0.4f, rect.height - 15
                );
            GUIStyle inputSt = new GUIStyle(GUI.skin.GetStyle("CN Box"));

            inputSt.fixedWidth    = PreviewRect.x - rect.x - TitleWidth - 10;
            inputSt.fixedHeight   = 30;
            inputSt.contentOffset = new Vector2(3, 0);
            inputSt.alignment     = TextAnchor.MiddleLeft;

            GUIStyle labelSt = new GUIStyle(GUI.skin.GetStyle("LODRendererAddButton"));

            labelSt.fixedWidth  = TitleWidth;
            labelSt.fixedHeight = 30;
            labelSt.alignment   = TextAnchor.MiddleRight;

            GUIStyle checkBoxSt = new GUIStyle(GUI.skin.GetStyle("BoldToggle"));

            checkBoxSt.alignment   = TextAnchor.MiddleLeft;
            checkBoxSt.fixedWidth  = 30;
            checkBoxSt.fixedHeight = 30;

            GUILayout.BeginArea(rect, GUI.skin.GetStyle("CN Box"));
            GUILayout.BeginVertical();
            GUILayout.Space(offset);
            if (this.mCurrentSelectAssets != null)
            {
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label(new GUIContent(Language.AssetName + ":"), labelSt);


                    if (mCurrentSelectAssets != null)
                    {
                        GUILayout.Label(mCurrentSelectAssets.data.address, inputSt);
                    }
                    else
                    {
                        GUILayout.Label("", inputSt);
                    }

                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                }
                GUILayout.Space(offset);
                GUILayout.BeginHorizontal();
                {
                    string type = "";
                    if (mCurrentSelectAssets != null)
                    {
                        type = mCurrentSelectAssets.data.type;
                    }

                    GUILayout.Label(new GUIContent(Language.AssetType + ":"), labelSt);
                    GUILayout.Label(type, inputSt);
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                }

                GUILayout.Space(offset);
                GUILayout.BeginHorizontal();
                {
                    string path = "";
                    if (mCurrentSelectAssets != null)
                    {
                        path = mCurrentSelectAssets.data.path;
                    }

                    GUILayout.Label(new GUIContent(Language.Path + ":"), labelSt);
                    GUILayout.Label(path, inputSt);
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                }

                GUILayout.Space(offset);

                GUILayout.BeginHorizontal();
                {
                    string url = "";
                    if (mCurrentSelectAssets != null)
                    {
                        url = mCurrentSelectAssets.data.url;
                    }

                    GUILayout.Label(new GUIContent(Language.ResUrl + ":"), labelSt);
                    GUILayout.Label(url, inputSt);
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                }

                GUILayout.Space(offset);

                GUILayout.BeginHorizontal();
                {
                    bool flag = false;
                    if (mCurrentSelectAssets != null)
                    {
                        flag = mCurrentSelectAssets.data.isResourcesPath;
                    }

                    GUILayout.Label(new GUIContent(Language.isResource + ":"), labelSt);

                    GUILayout.Label(flag ? Language.Yes : Language.No, inputSt);
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                }

                GUILayout.Space(offset);
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label(new GUIContent(Language.isKeepInMemory + ":"), labelSt);
                    if (mCurrentSelectAssets != null)
                    {
                        mCurrentSelectAssets.data.isKeepInMemory =
                            GUILayout.Toggle(mCurrentSelectAssets.data.isKeepInMemory, "", checkBoxSt);
                    }
                    else
                    {
                        GUILayout.Toggle(false, "", checkBoxSt);
                    }



                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                }
//                GUILayout.Space(offset);
//                GUILayout.BeginHorizontal();
//                {
//                    GUILayout.Label(new GUIContent("FGUI包:"), labelSt);
//                    if (mCurrentSelectAssets != null)
//                    {
//                        mCurrentSelectAssets.data.isFairyGuiPack =
//                            GUILayout.Toggle(mCurrentSelectAssets.data.isFairyGuiPack, "", checkBoxSt);
//                    }
//                    else
//                    {
//                        GUILayout.Toggle(false, "", checkBoxSt);
//                    }
//
//                    GUILayout.FlexibleSpace();
//                    GUILayout.EndHorizontal();
//                }
            }

            GUILayout.EndVertical();


            GUILayout.EndArea();


            //GUILayout.BeginArea(PreviewRect, GUI.skin.GetStyle("preBackground"));
            if (this.mCurrentSelectAssets != null)
            {
                Texture texture = EditorGUIUtility.FindTexture("Refresh");
                Type    t       = AssetDatabase.GetMainAssetTypeAtPath(this.mCurrentSelectAssets.data.path);
                texture = AssetDatabase.GetCachedIcon(this.mCurrentSelectAssets.data.path);

                if (preEditor == null)
                {
                    preEditor = UnityEditor.Editor.CreateEditor(AssetDatabase.LoadAssetAtPath(this.mCurrentSelectAssets.data.path, t));
                }

                if (preEditor != null && preEditor.HasPreviewGUI())
                {
                    try
                    {
                        preEditor.OnPreviewGUI(PreviewRect, GUI.skin.GetStyle("preBackground"));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        // throw;
                    }
                }
                else
                {
                    texture = AssetDatabase.GetCachedIcon(this.mCurrentSelectAssets.data.path);
                }
            }

            //GUILayout.EndArea();
        }
Esempio n. 9
0
        private void OnGUI()
        {
            emptyLayer = 0;
            UTUtils.GetLayerMasks();
            UTStyles.RenderHeader("Camera System Setup");
            UTStyles.RenderNote("This tool will set up a camera system in your scene, for more details on how to customize the camera - consult the documentation page.");
            if (GUILayout.Button("Documentation", GUILayout.ExpandWidth(true)))
            {
                Application.OpenURL(WikiURL);
            }

            UTStyles.RenderSectionHeader("Position and Style");

            var newCameraSpot = (Transform)EditorGUILayout.ObjectField("Camera Position", cameraSpot, typeof(Transform), true);

            if (newCameraSpot != cameraSpot)
            {
                setup = false;
            }

            cameraSpot = newCameraSpot;
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Watermark Overlay");
            watermark = (Texture)EditorGUILayout.ObjectField(watermark, typeof(Texture), true);
            EditorGUILayout.EndHorizontal();
            UTStyles.RenderNote("Overlay should be a 16:9 transparent texture");
            addGuide = EditorGUILayout.Toggle("Add Camera Guide", addGuide);
            if (addGuide)
            {
                var newGuideStyle = (GuideStyle)EditorGUILayout.EnumPopup("Guide Panel Style", guideStyle);
                if (newGuideStyle != guideStyle || standObj == null || standObjEditor == null)
                {
                    var standPath = newGuideStyle == GuideStyle.Futuristic ? SciFiStandPath : TikiStandPath;
                    standObj       = AssetDatabase.LoadAssetAtPath(GetAssetPath(standPath), typeof(object));
                    standObjEditor = UnityEditor.Editor.CreateEditor(standObj);
                }
                var r = GUILayoutUtility.GetRect(450, 150);
                standObjEditor.OnPreviewGUI(r, EditorStyles.helpBox);
                guideStyle = newGuideStyle;
            }

            UTStyles.RenderSectionHeader("PostProcessing and Collisions");
            UTStyles.RenderNote("Layers are very important to the overall setup. Make sure you follow the instructions below");

            layers.Clear();
            for (int i = 0; i < 32; i++)
            {
                var layerName = LayerMask.LayerToName(i);
                if (layerName.Length > 0)
                {
                    layers.Add($"[{i}] {layerName}");
                }
                else
                {
                    if (i > 22 && emptyLayer == 0)
                    {
                        emptyLayer = i;
                    }
                    layers.Add($"[{i}] -- not set --");
                }
            }

            var layersArr = layers.ToArray();

            if (emptyLayer != 0)
            {
                if (GUILayout.Button("Setup Layers"))
                {
                    SetupLayers();
                }
                UTStyles.RenderNote("It seems like you have empty layers available, UdonToolkit can set up everything for you if you click the button above");
                UTStyles.HorizontalLine();
            }

            cameraPPLayer = EditorGUILayout.Popup("Camera PP Layer", cameraPPLayer, layersArr);
            UTStyles.RenderNote("This layer will be used for detecting PP volumes for the Camera System");
            if (cameraPPLayer == 22)
            {
                EditorGUILayout.HelpBox("It is crucial to not put Camera PP volumes on the same layer as the main PostProcessing, or your own view will be affected by the camera effects", MessageType.Warning);
            }

            if (setup)
            {
                var oldColor = GUI.backgroundColor;
                GUI.backgroundColor = Color.green;
                UTStyles.RenderNote("Camera system has been set up in the scene!");
                GUI.backgroundColor = oldColor;
            }
            if (GUILayout.Button("Create Camera System", GUILayout.Height(30)))
            {
                RunCameraSetup();
            }

            if (GUILayout.Button("Add Guide Stand Only", GUILayout.Height(20)))
            {
                AddGuide();
            }
        }
Esempio n. 10
0
 public void OnPreviewGUI(Rect position, GUIStyle background)
 {
     editor.OnPreviewGUI(position, background);
 }
        private void OnGUI()
        {
            if (window)
            {
                GUILayout.BeginArea(new Rect(0, 0, window.position.size.x, window.position.size.y));
                GUILayout.BeginVertical();
                scrollPos = GUILayout.BeginScrollView(scrollPos, false, true, GUILayout.ExpandHeight(true));
            }

            GUIStyle BigBold = new GUIStyle
            {
                fontSize = 16, fontStyle = FontStyle.Bold, wordWrap = true, alignment = TextAnchor.MiddleCenter
            };

            GUIStyle Wrap = new GUIStyle {
                wordWrap = true, alignment = TextAnchor.MiddleCenter
            };

            GUIStyle warn = new GUIStyle
            {
                richText  = true,
                wordWrap  = true,
                fontStyle = FontStyle.Bold,
                alignment = TextAnchor.MiddleCenter,
                normal    = { textColor = new Color(0.7f, 0, 0) }
            };

            GUIStyle preview = new GUIStyle();

            preview.alignment = TextAnchor.UpperCenter;

            GUILayout.Space(10f);
            GUILayout.Label("Add grayscale images to be packed", BigBold);
            GUILayout.Label("Textures must be the same width and height", BigBold);
            GUILayout.Space(10f);
            GUILayout.Label("For accurate results, make sure your textures have sRGB unchecked", warn);
            GUILayout.Space(10f);

            //Metallic
            GUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Space(10f);
            Metallic = (Texture2D)EditorGUILayout.ObjectField("Metallic (R)", Metallic, typeof(Texture2D), false);
            if (!Metallic)
            {
                GUILayout.Label("No Metallic image found, use slider to set value", Wrap);
                defaultMetal = EditorGUILayout.Slider(defaultMetal, 0f, 1f);
            }
            if (Metallic && texSize == Vector2Int.zero)
            {
                texSize = new Vector2Int(Metallic.width, Metallic.height);
            }
            if (Metallic && texSize != new Vector2Int(Metallic.width, Metallic.height))
            {
                Metallic = null;
            }

            GUILayout.Space(10f);
            GUILayout.EndVertical();

            //Ambient Occlusion
            GUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Space(10f);
            AmbientOcclusion = (Texture2D)EditorGUILayout.ObjectField("Ambient Occlusion (G)", AmbientOcclusion, typeof(Texture2D), false);
            if (!AmbientOcclusion)
            {
                GUILayout.Label("No Ambient Occlusion image found, use slider to set value", Wrap);
                defaultAO = EditorGUILayout.Slider(defaultAO, 0f, 1f);
            }
            if (AmbientOcclusion && texSize == Vector2Int.zero)
            {
                texSize = new Vector2Int(AmbientOcclusion.width, AmbientOcclusion.height);
            }
            if (AmbientOcclusion && texSize != new Vector2Int(AmbientOcclusion.width, AmbientOcclusion.height))
            {
                AmbientOcclusion = null;
            }

            GUILayout.Space(10f);
            GUILayout.EndVertical();

            //Detail Mask
            GUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Space(10f);
            DetailMask = (Texture2D)EditorGUILayout.ObjectField("Detail Mask (B)", DetailMask, typeof(Texture2D), false);
            if (!DetailMask)
            {
                GUILayout.Label("No Detail Mask image found, use slider to set value", Wrap);
                defaultDetail = EditorGUILayout.Slider(defaultDetail, 0f, 1f);
            }
            if (DetailMask && texSize == Vector2Int.zero)
            {
                texSize = new Vector2Int(DetailMask.width, DetailMask.height);
            }
            if (DetailMask && texSize != new Vector2Int(DetailMask.width, DetailMask.height))
            {
                DetailMask = null;
            }

            GUILayout.Space(10f);
            GUILayout.EndVertical();

            //Roughness/Smoothness
            GUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Space(10f);

            // ReSharper disable once AssignmentInConditionalExpression
            if (useRough = EditorGUILayout.Toggle("Input Is Roughness Map", useRough))
            {
                Smooth_Rough = (Texture2D)EditorGUILayout.ObjectField("Rough Map (A)", Smooth_Rough, typeof(Texture2D), false);
            }
            else
            {
                Smooth_Rough = (Texture2D)EditorGUILayout.ObjectField("Smoothness Map (A)", Smooth_Rough, typeof(Texture2D), false);
            }
            if (!Smooth_Rough)
            {
                GUILayout.Label("No Smoothness or Roughness image found, use slider to set value", Wrap);
                defaultSmooth = EditorGUILayout.Slider(defaultSmooth, 0f, 1f);
                if (defaultSmooth == 0)
                {
                    GUILayout.Label("Slider set to 0, preview image will display alpha of 1", Wrap);
                }
            }
            if (Smooth_Rough && texSize == Vector2Int.zero)
            {
                texSize = new Vector2Int(Smooth_Rough.width, Smooth_Rough.height);
            }
            if (Smooth_Rough && texSize != new Vector2Int(Smooth_Rough.width, Smooth_Rough.height))
            {
                Smooth_Rough = null;
            }

            GUILayout.Space(10f);
            GUILayout.EndVertical();

            //Preview Albedo
            GUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Space(10f);
            Albedo = (Texture2D)EditorGUILayout.ObjectField("Albedo (Preview)", Albedo, typeof(Texture2D), false);

            GUILayout.Space(10f);
            GUILayout.EndVertical();

            //Preview Normal
            GUILayout.BeginVertical(EditorStyles.helpBox);
            GUILayout.Space(10f);
            Normal = (Texture2D)EditorGUILayout.ObjectField("Normal Map (Preview)", Normal, typeof(Texture2D), false);

            GUILayout.Space(10f);
            GUILayout.EndVertical();


            if (!Metallic && !AmbientOcclusion && !DetailMask && !Smooth_Rough)
            {
                texSize = Vector2Int.zero;
                GUILayout.Label("No Textures selected", Wrap);
            }
            else
            {
                if (finalTexture)
                {
                    if (!previewMat)
                    {
                        previewMat = new Material(Shader.Find("HDRP/Lit"));
                    }

                    if (previewMat != null)
                    {
                        if (previewMatViewer == null)
                        {
                            previewMatViewer = UnityEditor.Editor.CreateEditor(previewMat);
                        }

                        if (!MaterialMade)
                        {
                            //_HEIGHTMAP _MASKMAP _NORMALMAP _NORMALMAP_TANGENT_SPACE
                            if (Albedo)
                            {
                                previewMat.SetTexture("_BaseColorMap", Albedo);
                            }

                            if (Normal)
                            {
                                previewMat.EnableKeyword("_NORMALMAP");
                                previewMat.EnableKeyword("_NORMALMAP_TANGENT_SPACE");
                                previewMat.SetTexture("_NormalMap", Normal);
                            }

                            previewMat.EnableKeyword("_MASKMAP");
                            previewMat.SetTexture("_MaskMap", finalTexture);
                            MaterialMade = true;
                        }

                        if (MaterialMade && previewMatViewer != null)
                        {
                            GUILayout.BeginVertical(EditorStyles.helpBox);
                            GUILayout.Space(10f);
                            previewMatViewer.OnPreviewGUI(GUILayoutUtility.GetRect(256, 256), EditorStyles.objectField);
                            GUILayout.Space(10f);
                            GUILayout.EndVertical();
                        }
                    }
                }
                GUILayout.BeginVertical(EditorStyles.helpBox);
                GUILayout.Space(10f);
                if (GUILayout.Button("Update Preview Texture"))
                {
                    MaterialMade = false;
                    EditorUtility.DisplayProgressBar("Generating Preview, please wait...", "", 1f);
                    UpdateTexture(true);
                }
                GUILayout.Space(5f);
                if (GUILayout.Button("Pack and Save Texture"))
                {
                    EditorUtility.DisplayProgressBar("Packing Textures, please wait...", "", 1f);
                    PackTextures();
                }
                GUILayout.Space(5f);
                if (GUILayout.Button("Clear All"))
                {
                    MaterialMade     = false;
                    Albedo           = Normal = Metallic = AmbientOcclusion = DetailMask = Smooth_Rough = finalTexture = null;
                    previewMat       = null;
                    previewMatViewer = null;
                }
                GUILayout.Space(10f);
                GUILayout.EndVertical();
            }

            GUILayout.Label("Output texture will be the same height and width as input", Wrap);

            GUILayout.Space(100);
            if (!window)
            {
                return;
            }
            GUILayout.EndScrollView();
            GUILayout.EndVertical();
            GUILayout.EndArea();
        }
Esempio n. 12
0
        private void DrawPreviewGUI()
        {
            GUILayout.FlexibleSpace();

            if (_wavClipEditor == null)
            {
                _wavClipEditor = UnityEditor.Editor.CreateEditor(_wavClip);
            }

            if (_clipEditorBg == null)
            {
                _clipEditorBg = new GUIStyle();
                _clipEditorBg.normal.background = Texture2D.blackTexture;
            }

            int currentSample = GetSamplePosition();

            if (currentSample > 0)
            {
                // Playback position gets reset to zero after pausing. Save the last one to make
                // finding the desired loops easier.
                _lastPreviewSample = currentSample;
            }

            using (new EditorGUILayout.HorizontalScope())
            {
                GUILayout.Label("Preview");
                using (new EditorGUI.DisabledScope(_zoomLevel / 1.5f < 1.0f))
                {
                    if (GUILayout.Button("-"))
                    {
                        _zoomLevel /= 1.5f;
                    }
                }

                using (new EditorGUI.DisabledScope(_zoomLevel * 1.5f > 20.0f))
                {
                    if (GUILayout.Button("+"))
                    {
                        _zoomLevel *= 1.5f;
                    }
                }

                GUILayout.FlexibleSpace();
                _wavClipEditor.OnPreviewSettings();
            }

            using (var scrollView = new EditorGUILayout.ScrollViewScope(_previewScrollPos))
            {
                _previewScrollPos = scrollView.scrollPosition;
                _wavClipEditor.OnPreviewGUI(
                    GUILayoutUtility.GetRect(position.width * _zoomLevel, 100, GUILayout.ExpandWidth(false)),
                    _clipEditorBg);
            }

            using (new EditorGUILayout.HorizontalScope())
            {
                GUILayout.Label("Set Loop Point to Current Preview Position: ", GUILayout.ExpandWidth(false));
                GUILayout.Label(_useSeconds
                    ? SecondsToDurationString(SamplesToSeconds(_lastPreviewSample))
                    : _lastPreviewSample.ToString(),
                                GUILayout.Width(80));

                if (GUILayout.Button("Start", GUILayout.Width(80)))
                {
                    _wavData.GetOrAddFirstLoop().StartSample = _lastPreviewSample;
                }

                if (GUILayout.Button("End", GUILayout.Width(80)))
                {
                    _wavData.GetOrAddFirstLoop().EndSample = _lastPreviewSample;
                }
            }

            // Enable looping by default
            _wavClipEditor.GetType()
            .GetField("s_Loop", BindingFlags.Static | BindingFlags.NonPublic)?
            .SetValue(null, true);
        }
Esempio n. 13
0
    //displays the side bar
    void sideBarGUI()
    {
        if(m_Task == null)
        {
            //display the board we want to load
            GUILayout.BeginArea(new Rect(Screen.width-250,0, 250, Screen.height));
            EditorGUILayout.BeginVertical("GroupBox");

            EditorGUILayout.Space();
            ///CREATING BOARD
            EditorGUILayout.LabelField("Create A New Board");
            newBoardName = EditorGUILayout.TextField("Board Name: ", newBoardName);

            if(GUILayout.Button("Create New Board"))
            {
                if(newBoardName != "" && newBoardName != null && newBoardName != " ")
                {
                    CreateNewDatabase();
                    //Debug.Log("Created New Board");
                }
                else
                {
                    Debug.LogError("Enter A Valid Board Name");
                }
            }

            EditorGUILayout.Space();

            //END Creating BOARD

            ///loading a board
            if(n_FileLocation == null)
            {
                EditorGUILayout.LabelField("No Board Selected");
            }
            else
            {
                EditorGUILayout.LabelField(n_FileLocation);
            }
            if(GUILayout.Button("Select Board"))
            {
                n_FileLocation = EditorUtility.OpenFilePanel("Select A Board","Assets/Editor/TaskManager/TaskData/","asset");
                if (n_FileLocation.Length != 0)
                {

                    if(n_FileLocation.Contains("Assets"))
                    {
                        n_FileLocation = n_FileLocation.Replace(CurrentDataPath, "");
                        Debug.Log(n_FileLocation);
                    }

                    //load the board here
                    LoadOldDatabase();
                }
            }
            if(GUILayout.Button("Clear File Path"))
            {
                n_FileLocation = null;
                newBoardName = null;
            }
            ///END Loading Board

            EditorGUILayout.EndVertical();
            GUILayout.EndArea();
        }
        else
        {

            if(n_HideSideBar == false)
            {
                GUILayout.BeginArea(new Rect(Screen.width-250,0, 250, Screen.height));
                EditorGUILayout.BeginVertical("GroupBox");

                EditorGUILayout.Space();

                if(m_Task != null)
                {
                    EditorGUILayout.LabelField("Board Data");
                    EditorGUILayout.LabelField("Number of Tasks: " + m_Task.database.Count);
                }

                EditorGUILayout.Space();
                EditorGUILayout.Space();

                if (GUILayout.Button ("Add Task", GUILayout.Height(30)))
                {

                    m_Task.Add(new Task("", "", ""));
                    EditorUtility.SetDirty(m_Task);
                    Repaint();
                }

                EditorGUILayout.Space();

                if (gameObjectToDisplay != null)
                {

                    //if(gameObjectEditor != null)
                    //{
                        EditorGUILayout.LabelField("Asset From Task");
                        gameObjectEditor = Editor.CreateEditor(gameObjectToDisplay);
                        gameObjectEditor.OnPreviewGUI(GUILayoutUtility.GetRect(250, 150), EditorStyles.miniButton);

                    //}
                }

                EditorGUILayout.Space();
                EditorGUILayout.Space();

                if(GUILayout.Button("Hide SideBar"))
                {
                    n_HideSideBar = true;
                }

                if(GUILayout.Button("Close Board"))
                {
                    DeleteDatabase();
                }

                EditorGUILayout.EndVertical();
                GUILayout.EndArea();
            }
            else
            {
                GUILayout.BeginArea(new Rect(Screen.width-250,0, 250, Screen.height));
                EditorGUILayout.BeginHorizontal("GroupBox");

                if(GUILayout.Button("Show Sidebar"))
                {
                    n_HideSideBar = false;
                }

                EditorGUILayout.EndHorizontal();
                GUILayout.EndArea();
            }

        }
    }