void RepaintWhileLoadingTextures()
 {
     if (AssetPreview.IsLoadingAssetPreviews())
     {
         repaint = true;
     }
 }
Beispiel #2
0
        private void DrawPreview(SearchContext context, SearchItem item)
        {
            if (item.provider.fetchPreview == null)
            {
                return;
            }
            var now = EditorApplication.timeSinceStartup;

            if (now - m_LastPreviewStamp > 2.5)
            {
                m_PreviewTexture = null;
            }

            if (!m_PreviewTexture || m_LastPreviewItemId != item.id)
            {
                m_LastPreviewStamp  = now;
                m_PreviewTexture    = item.provider.fetchPreview(item, context, Styles.previewSize, FetchPreviewOptions.Preview2D | FetchPreviewOptions.Large);
                m_LastPreviewItemId = item.id;
            }

            if (m_PreviewTexture == null || AssetPreview.IsLoadingAssetPreviews())
            {
                m_SearchView.Repaint();
            }

            GUILayout.Space(10);
            GUILayout.Label(m_PreviewTexture, Styles.largePreview, GUILayout.MaxWidth(Styles.previewSize.x), GUILayout.MaxHeight(Styles.previewSize.y));
        }
Beispiel #3
0
        private void DrawPreview(SearchContext context, SearchItem item, float size)
        {
            if (item.provider.fetchPreview == null)
            {
                return;
            }

            if (m_Editors != null && m_Editors.Length == 1 && m_Editors[0].HasPreviewGUI())
            {
                var e           = m_Editors[0];
                var previewRect = EditorGUILayout.GetControlRect(GUILayout.MaxWidth(size), GUILayout.MaxHeight(size));
                if (previewRect.width > 0 && previewRect.height > 0)
                {
                    e.OnPreviewGUI(previewRect, Styles.largePreview);
                }
            }
            else
            {
                var now = EditorApplication.timeSinceStartup;
                if (now - m_LastPreviewStamp > 2.5)
                {
                    m_PreviewTexture = null;
                }

                if (!m_PreviewTexture || m_LastPreviewItemId != item.id)
                {
                    m_LastPreviewStamp  = now;
                    m_PreviewTexture    = item.provider.fetchPreview(item, context, Styles.previewSize, FetchPreviewOptions.Preview2D | FetchPreviewOptions.Large);
                    m_LastPreviewItemId = item.id;
                }

                if (m_PreviewTexture == null || AssetPreview.IsLoadingAssetPreviews())
                {
                    m_SearchView.Repaint();
                }

                size -= (Styles.largePreview.margin.left + Styles.largePreview.margin.right);
                GUILayout.Space(10);
                GUILayout.Label(m_PreviewTexture, Styles.largePreview, GUILayout.MaxWidth(size), GUILayout.MaxHeight(size));
            }
        }
    void OnGUI()
    {
        EditorGUILayout.Space();

        int paletteIndex = palettes.IndexOf(palette);

        paletteIndex = EditorGUILayout.Popup("Palette", paletteIndex, paletteNames);
        palette      = paletteIndex < 0 ? null : palettes[paletteIndex];

        if (palette == null)
        {
            return;
        }

        if (ev.isMouse)
        {
            mousePos = ev.mousePosition;
            Repaint();
        }

        optionsToggle = EditorGUILayout.Foldout(optionsToggle, "Options");
        if (optionsToggle)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.Space();
            EditorGUILayout.BeginVertical();

            raycastMask = LayerMaskField("Raycast Mask", raycastMask);

            var par = EditorGUILayout.ObjectField("Parent To", parentTo, typeof(Transform), true) as Transform;
            if (par != parentTo)
            {
                if (par == null || (PrefabUtility.GetCorrespondingObjectFromSource(par) == null && PrefabUtility.GetPrefabObject(par) == null))
                {
                    parentTo = par;
                }
            }

            onlyUpwards = EditorGUILayout.Toggle("Only Up Normals", onlyUpwards);

            //Snapping
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Snap");
            snap        = EditorGUILayout.Toggle(snap, GUILayout.Width(15f));
            GUI.enabled = snap;
            snapValue   = EditorGUILayout.FloatField(snapValue);
            snapValue   = Mathf.Max(snapValue, 0f);
            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();

            //Rotation mode
            rotationMode = (RotationType)EditorGUILayout.EnumPopup("Rotation Mode", rotationMode);
            if (rotationMode == RotationType.Random)
            {
                minRotation = EditorGUILayout.Vector3Field("Min Rotation", minRotation);
                maxRotation = EditorGUILayout.Vector3Field("Max Rotation", maxRotation);
            }
            else if (rotationMode == RotationType.Custom)
            {
                customRotation = EditorGUILayout.Vector3Field("Rotation", customRotation);
            }

            //Scale mode
            scaleMode = (ScaleType)EditorGUILayout.EnumPopup("Scale Mode", scaleMode);
            if (scaleMode == ScaleType.Random)
            {
                minScale = EditorGUILayout.Vector3Field("Min Scale", minScale);
                maxScale = EditorGUILayout.Vector3Field("Max Scale", maxScale);
            }
            else if (scaleMode == ScaleType.RandomXYZ)
            {
                minScaleU = EditorGUILayout.FloatField("Min Scale", minScaleU);
                maxScaleU = EditorGUILayout.FloatField("Max Scale", maxScaleU);
            }
            else if (scaleMode == ScaleType.Custom)
            {
                customScale = EditorGUILayout.Vector3Field("Scale", customScale);
            }

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.Space();

        var header = EditorGUILayout.GetControlRect();

        GUI.Label(header, "Prefabs", EditorStyles.boldLabel);
        header.y     += header.height - 1f;
        header.height = 1f;
        EditorGUI.DrawRect(header, EditorStyles.label.normal.textColor);

        GUILayout.Space(2f);

        GUI.enabled = selected != null;
        if (GUILayout.Button("Stop Placement (ESC)", EditorStyles.miniButton))
        {
            Deselect();
        }
        GUI.enabled = true;
        if (ev.type == EventType.KeyDown && ev.keyCode == KeyCode.Escape)
        {
            Deselect();
        }

        var buttonHeight = EditorGUIUtility.singleLineHeight * 2f;
        var heightStyle  = GUILayout.Height(buttonHeight);

        var lastRect    = GUILayoutUtility.GetLastRect();
        var scrollMouse = mousePos;

        scrollMouse.x -= lastRect.xMin - prefabScroll.x;
        scrollMouse.y -= lastRect.yMax - prefabScroll.y;

        prefabScroll = EditorGUILayout.BeginScrollView(prefabScroll);

        foreach (var prefab in palette.prefabs)
        {
            if (prefab == null)
            {
                continue;
            }

            var rect = EditorGUILayout.GetControlRect(heightStyle);

            var bgRect = rect;
            bgRect.x      -= 1f;
            bgRect.y      -= 1f;
            bgRect.width  += 2f;
            bgRect.height += 2f;
            if (prefab == selected)
            {
                EditorGUI.DrawRect(bgRect, new Color32(0x42, 0x80, 0xe4, 0xff));
            }
            else
            {
                EditorGUIUtility.AddCursorRect(bgRect, MouseCursor.Link);

                if (bgRect.Contains(scrollMouse))
                {
                    EditorGUI.DrawRect(bgRect, new Color32(0x42, 0x80, 0xe4, 0x40));
                    if (ev.type == EventType.MouseDown)
                    {
                        EditorApplication.delayCall += () =>
                        {
                            selected = prefab;
                            SceneView.RepaintAll();
                        };
                    }
                }
            }

            var iconRect = new Rect(rect.x, rect.y, rect.height, rect.height);

            var icon = AssetPreview.GetAssetPreview(prefab);
            if (icon != null)
            {
                GUI.DrawTexture(iconRect, icon, ScaleMode.ScaleToFit, true, 1f, Color.white, Vector4.zero, Vector4.one * 4f);
            }
            else
            {
                EditorGUI.DrawRect(iconRect, EditorStyles.label.normal.textColor * 0.25f);
            }

            var labelRect = rect;
            labelRect.x     += iconRect.width + 4f;
            labelRect.width -= iconRect.width + 4f;
            labelRect.height = EditorGUIUtility.singleLineHeight;
            labelRect.y     += (buttonHeight - labelRect.height) * 0.5f;
            var labelStyle = prefab == selected ? EditorStyles.whiteBoldLabel : EditorStyles.label;
            GUI.Label(labelRect, prefab.name, labelStyle);
        }

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

        if (AssetPreview.IsLoadingAssetPreviews())
        {
            Repaint();
        }
    }
Beispiel #5
0
        public override void OnInspectorGUI()
        {
            // Get the target block world
            BlockWorld t = target as BlockWorld;

            int materialCount = t.BlockTypes.GetVisibleLength();

            // Material selection area
            {
                // Update texture cache size, if needed
                if (iconTextures == null || iconTextures.Length != materialCount)
                {
                    iconTextures = new Texture[materialCount];

                    // Cap the selected material index to the length of this list
                    // Selected index returns -1 if the material list is empty
                    if (t.selectedMaterialIndex >= iconTextures.Length || t.selectedMaterialIndex < 0)
                    {
                        t.selectedMaterialIndex = iconTextures.Length - 1;
                    }
                }

                // Render material list
                {
                    for (int i = 0; i < iconTextures.Length; i++)
                    {
                        MaterialBlock props = t.BlockTypes.GetVisibleAt(i);
                        iconTextures[i] = AssetPreview.GetAssetPreview(props.Material);

                        EditorGUILayout.BeginHorizontal();

                        bool selected = GUILayout.Toggle(t.selectedMaterialIndex == i, iconTextures[i], EditorStyles.miniButton,
                                                         GUILayout.Width(64), GUILayout.Height(64));
                        if (selected)
                        {
                            t.selectedMaterialIndex = i;
                        }

                        {
                            // Material Properties
                            EditorGUI.BeginChangeCheck();

                            EditorGUILayout.BeginVertical();
                            props.Transparent = GUILayout.Toggle(props.Transparent, "Transparent");
                            props.GroupBlocks = GUILayout.Toggle(props.GroupBlocks, "Group Blocks");
                            props.ViewInsides = GUILayout.Toggle(props.ViewInsides, "View Insides");
                            EditorGUILayout.EndVertical();

                            EditorGUILayout.BeginVertical();
                            props.DepthSort = GUILayout.Toggle(props.DepthSort, "Depth Sort");
                            EditorGUILayout.EndVertical();

                            if (EditorGUI.EndChangeCheck())
                            {
                                EditorUtility.SetDirty(t);
                                t.UpdateAllBlockStates(props.Id, props.BlockState);
                            }
                        }

                        if (GUILayout.Button("X", GUILayout.Width(30), GUILayout.Height(30)))
                        {
                            // Record undo point and remove material
                            Undo.RecordObject(t, "Removed Material from BlockWorld");
                            props.HiddenInInspector = true;
                            EditorUtility.SetDirty(t);
                        }

                        EditorGUILayout.EndHorizontal();
                    }

                    GUILayout.Space(20);
                }

                // If we are still loading asset previews, queue the inspector for another repaint
                if (AssetPreview.IsLoadingAssetPreviews())
                {
                    EditorUtility.SetDirty(t);
                }
            }

            // Add/Remove material area
            {
                // Show an object field for quickly adding new materials to the list
                Material newMaterial = EditorGUILayout.ObjectField("Add Material", null, typeof(Material), false) as Material;
                if (newMaterial != null)
                {
                    MaterialBlock matProps = t.BlockTypes.GetMaterialProperties(newMaterial);
                    if (matProps.HiddenInInspector)
                    {
                        // Record undo point and add material
                        Undo.RecordObject(t, "Added Material to BlockWorld");
                        matProps.HiddenInInspector = false;
                        EditorUtility.SetDirty(t);
                    }
                }

                GUILayout.Space(30);
            }

            // Regen and Clear buttons
            {
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Regen") && materialCount > 0)
                {
                    t.Clear();
                    t.SetBlock(0, 0, 0, t.BlockTypes.GetVisibleAt(t.selectedMaterialIndex).Material);
                }
                if (GUILayout.Button("Clear"))
                {
                    t.Clear();
                }
                if (GUILayout.Button("Remesh"))
                {
                    t.RemeshAllChunks();
                }
                EditorGUILayout.EndHorizontal();
            }
        }
Beispiel #6
0
        public override void OnInspectorGUI()
        {
            EditorGUI.indentLevel = 0;
            GUI.contentColor      = Color.white;
            bool isDirty = false;

            poolManager = (EZ_PoolManager)target;

            EZ_EditorUtility.DrawTexture(EZ_EditorAssets.poolManagerItemLogo);

            poolManager.autoAddMissingPrefabPool = EditorGUILayout.Toggle("Auto Add Missing Items", poolManager.autoAddMissingPrefabPool);
            poolManager.showDebugLog             = EditorGUILayout.Toggle("Show Debug Log", poolManager.showDebugLog);
            poolManager.usePoolManager           = EditorGUILayout.Toggle("Use EZ Pool Manager", poolManager.usePoolManager);

            EditorGUILayout.Separator();
            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);

            EditorGUI.indentLevel = 1;

            poolManager.isRootExpanded = EditorGUILayout.Foldout(poolManager.isRootExpanded, string.Format("Pools ({0})", poolManager.prefabPoolOptions.Count));

            // Add expand / collapse buttons if there are items in the list
            if (poolManager.prefabPoolOptions.Count > 0)
            {
                EZ_EditorUtility.BeginColor(EZ_EditorAssets.shiftPosColor);
                var masterCollapse = GUILayout.Button("Collapse All", EditorStyles.toolbarButton, GUILayout.Width(80));

                var masterExpand = GUILayout.Button("Expand All", EditorStyles.toolbarButton, GUILayout.Width(80));
                EZ_EditorUtility.EndColor();

                if (masterExpand)
                {
                    foreach (var item in poolManager.prefabPoolOptions)
                    {
                        item.isPoolExpanded = true;
                    }
                }

                if (masterCollapse)
                {
                    foreach (var item in poolManager.prefabPoolOptions)
                    {
                        item.isPoolExpanded = false;
                    }
                }
            }
            else
            {
                GUILayout.FlexibleSpace();
            }

            //only enable adding of pools when the application is NOT in play state
            if (!Application.isPlaying) //During Editor
            {
                EZ_EditorUtility.BeginColor(EZ_EditorAssets.addBtnColor);
                if (GUILayout.Button("Add", EditorStyles.toolbarButton, GUILayout.Width(32)))
                {
                    poolManager.prefabPoolOptions.Insert(0, new EZ_PrefabPoolOption()); //add to the top of the list
                    isDirty = true;
                }
                EZ_EditorUtility.EndColor();
            }

            EditorGUILayout.EndHorizontal();

            if (poolManager.isRootExpanded)
            {
                int i_ToRemove    = -1;
                int i_ToInsertAt  = -1;
                int i_ToShiftUp   = -1;
                int i_ToShiftDown = -1;

                EditorGUILayout.BeginVertical();

                scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(0), GUILayout.Height(0));

                for (var i = 0; i < poolManager.prefabPoolOptions.Count; ++i)
                {
                    var prefabPoolOption = poolManager.prefabPoolOptions[i];

                    EditorGUI.indentLevel = 2;
                    EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                    var name = prefabPoolOption.prefabTransform == null ? "[NO PREFAB]" : prefabPoolOption.prefabTransform.name;
                    if (!Application.isPlaying) //During Editor
                    {
                        prefabPoolOption.isPoolExpanded = EditorGUILayout.Foldout(prefabPoolOption.isPoolExpanded, name, EditorStyles.foldout);
                    }
                    else //During Play
                    {
                        var itemInfo = EZ_PoolManager.GetPool(name);
                        if (itemInfo != null)
                        {
                            var spawnedCount   = itemInfo.spawnedList.Count;
                            var despawnedCount = itemInfo.despawnedList.Count;
                            prefabPoolOption.isPoolExpanded = EditorGUILayout.Foldout(prefabPoolOption.isPoolExpanded, name + " - " + spawnedCount + " / " + (despawnedCount + spawnedCount), EditorStyles.foldout);
                        }
                    }



                    EZ_EditorUtility.BeginColor(EZ_EditorAssets.shiftPosColor);

                    if (i > 0)
                    {
                        // the up arrow.
                        if (GUILayout.Button("▲", EditorStyles.toolbarButton, GUILayout.Width(24)))
                        {
                            i_ToShiftUp = i;
                        }
                    }
                    else
                    {
                        GUILayout.Space(24);
                    }

                    if (i < poolManager.prefabPoolOptions.Count - 1)
                    {
                        // The down arrow will move things towards the end of the List
                        if (GUILayout.Button("▼", EditorStyles.toolbarButton, GUILayout.Width(24)))
                        {
                            i_ToShiftDown = i;
                        }
                    }
                    else
                    {
                        GUILayout.Space(24);
                    }

                    EZ_EditorUtility.EndColor();

                    //only enable adding or deleting of pools when the application is NOT in play state
                    if (!Application.isPlaying) //During Editor
                    {
                        EZ_EditorUtility.BeginColor(EZ_EditorAssets.addBtnColor);
                        if (GUILayout.Button("Add", EditorStyles.toolbarButton, GUILayout.Width(32)))
                        {
                            i_ToInsertAt = i + 1;
                        }
                        EZ_EditorUtility.EndColor();

                        EZ_EditorUtility.BeginColor(EZ_EditorAssets.delBtnColor);
                        if (GUILayout.Button("Del", EditorStyles.toolbarButton, GUILayout.Width(32)))
                        {
                            i_ToRemove = i;
                        }
                        EZ_EditorUtility.EndColor();
                    }

                    EditorGUILayout.EndHorizontal();

                    if (prefabPoolOption.isPoolExpanded)
                    {
                        EditorGUI.indentLevel = 1;

                        EZ_EditorUtility.DrawTexture(EZ_EditorAssets.poolItemTop);

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Space(12); //offset the prefab preview towards the center

                        Texture prefabPreviewIcon = null;
                        if (prefabPoolOption.prefabTransform && prefabPoolOption.prefabTransform.GetComponent <Renderer>() != null)
                        {
                            prefabPreviewIcon = AssetPreview.GetAssetPreview(prefabPoolOption.prefabTransform.gameObject);
                        }
                        else
                        {
                            prefabPreviewIcon = EZ_EditorUtility.LoadTexture(EZ_EditorAssets.missingPrefabIcon);
                        }

                        while (AssetPreview.IsLoadingAssetPreviews())
                        {
                            if (prefabPoolOption.prefabTransform)
                            {
                                prefabPreviewIcon = AssetPreview.GetAssetPreview(prefabPoolOption.prefabTransform.gameObject);
                            }
                            else
                            {
                                prefabPreviewIcon = EZ_EditorUtility.LoadTexture(EZ_EditorAssets.missingPrefabIcon);
                            }

                            System.Threading.Thread.Sleep(5);
                        }

                        EZ_EditorUtility.DrawTexture(prefabPreviewIcon, 100, 100);

                        EditorGUILayout.BeginVertical(GUILayout.MinHeight(prefabPreviewIcon.height));


                        if (!Application.isPlaying) //During Editor
                        {
                            prefabPoolOption.prefabTransform    = (Transform)EditorGUILayout.ObjectField("Prefab", prefabPoolOption.prefabTransform, typeof(Transform), false);
                            prefabPoolOption.showDebugLog       = EditorGUILayout.Toggle("Show Debug Log", prefabPoolOption.showDebugLog);
                            prefabPoolOption.instancesToPreload = EditorGUILayout.IntSlider("Preload Qty", prefabPoolOption.instancesToPreload, 0, 10000);


                            prefabPoolOption.poolCanGrow = EditorGUILayout.Toggle("Allow Pool to grow", prefabPoolOption.poolCanGrow);

                            if (prefabPoolOption.instancesToPreload == 0 && !prefabPoolOption.poolCanGrow)
                            {
                                EditorGUILayout.LabelField("*Preload Qty is 0 and Pool cannot grow. This pool will not be created.", EditorStyles.miniLabel);
                            }

                            if (prefabPoolOption.poolCanGrow)
                            {
                                prefabPoolOption.enableHardLimit = EditorGUILayout.Toggle("Enable Hard Limit", prefabPoolOption.enableHardLimit);

                                if (prefabPoolOption.enableHardLimit)
                                {
                                    prefabPoolOption.hardLimit = EditorGUILayout.IntSlider("Hard Limit", prefabPoolOption.hardLimit, 0, 10000);
                                }
                            }

                            prefabPoolOption.cullDespawned = EditorGUILayout.Toggle("Cull Despawned", prefabPoolOption.cullDespawned);

                            if (prefabPoolOption.cullDespawned)
                            {
                                prefabPoolOption.cullAbove  = EditorGUILayout.IntSlider("Cull Above", prefabPoolOption.cullAbove, 0, 1000);
                                prefabPoolOption.cullDelay  = EditorGUILayout.Slider("Cull Delay", prefabPoolOption.cullDelay, 0, 100);
                                prefabPoolOption.cullAmount = EditorGUILayout.IntSlider("Cull Amt", prefabPoolOption.cullAmount, 0, 100);
                            }

                            prefabPoolOption.recycle = EditorGUILayout.Toggle("Allow Pool to recycle", prefabPoolOption.recycle);
                        }
                        else //During Play mode
                        {
                            if (prefabPoolOption.prefabTransform != null)
                            {
                                var itemInfo = EZ_PoolManager.GetPool(name);
                                if (itemInfo != null)
                                {
                                    var spawnedCount   = itemInfo.spawnedList.Count;
                                    var despawnedCount = itemInfo.despawnedList.Count;

                                    EditorGUILayout.LabelField(string.Format("{0} / {1} Spawned", spawnedCount, despawnedCount + spawnedCount), EditorStyles.boldLabel);
                                    EditorGUILayout.Separator();
                                }
                            }

                            EditorGUILayout.LabelField("Preload Qty : " + prefabPoolOption.instancesToPreload, EditorStyles.miniLabel);
                            EditorGUILayout.LabelField("Allow Pool to grow : " + prefabPoolOption.poolCanGrow, EditorStyles.miniLabel);

                            if (prefabPoolOption.poolCanGrow)
                            {
                                if (prefabPoolOption.enableHardLimit)
                                {
                                    EditorGUILayout.LabelField("Hard Limit : " + prefabPoolOption.hardLimit, EditorStyles.miniLabel);
                                }
                            }

                            if (prefabPoolOption.cullDespawned)
                            {
                                EditorGUILayout.LabelField("Cull Above : " + prefabPoolOption.cullAbove, EditorStyles.miniLabel);
                                EditorGUILayout.LabelField("Cull Delay : " + prefabPoolOption.cullDelay, EditorStyles.miniLabel);
                                EditorGUILayout.LabelField("Cull Amt : " + prefabPoolOption.cullAmount, EditorStyles.miniLabel);
                            }

                            EditorGUILayout.LabelField("Allow Pool to recycle : " + prefabPoolOption.recycle, EditorStyles.miniLabel);
                        }
                        EditorGUILayout.EndVertical();
                        EditorGUILayout.EndHorizontal();

                        EZ_EditorUtility.DrawTexture(EZ_EditorAssets.poolItemBottom);
                    }
                }

                EditorGUILayout.EndScrollView();
                EditorGUILayout.EndVertical();

                if (i_ToRemove != -1)
                {
                    poolManager.prefabPoolOptions.RemoveAt(i_ToRemove);
                    isDirty = true;
                }
                if (i_ToInsertAt != -1)
                {
                    poolManager.prefabPoolOptions.Insert(i_ToInsertAt, new EZ_PrefabPoolOption());
                    isDirty = true;
                }
                if (i_ToShiftUp != -1)
                {
                    var item = poolManager.prefabPoolOptions[i_ToShiftUp];
                    poolManager.prefabPoolOptions.Insert(i_ToShiftUp - 1, item);
                    poolManager.prefabPoolOptions.RemoveAt(i_ToShiftUp + 1);
                    isDirty = true;
                }

                if (i_ToShiftDown != -1)
                {
                    var index = i_ToShiftDown + 1;
                    var item  = poolManager.prefabPoolOptions[index];
                    poolManager.prefabPoolOptions.Insert(index - 1, item);
                    poolManager.prefabPoolOptions.RemoveAt(index + 1);
                    isDirty = true;
                }
            }


            if (GUI.changed || isDirty)
            {
                EditorUtility.SetDirty(target);
            }

            this.Repaint();
        }
    void OnGUI()
    {
        EditorGUILayout.Space();

        int paletteIndex = palettes.IndexOf(palette);

        paletteIndex = EditorGUILayout.Popup("Palette", paletteIndex, paletteNames);
        palette      = paletteIndex < 0 ? null : palettes[paletteIndex];

        if (palette == null)
        {
            return;
        }

        if (palette != prevPalette)
        {
            foreach (GameObject obj in FindObjectsOfType(typeof(GameObject)))
            {
                if (obj.activeInHierarchy)
                {
                    var sheet = obj.GetComponent <PartsSheet>();
                    if (sheet != null)
                    {
                        if (sheet.palette == palette)
                        {
                            parentTo = sheet.transform;
                            Selection.activeGameObject = parentTo == null ? null : parentTo.gameObject;
                        }
                    }
                }
            }
            stageType = palette.stageType;
        }
        prevPalette = palette;

        if (ev.isMouse)
        {
            mousePos = ev.mousePosition;
            Repaint();
        }

        optionsToggle = EditorGUILayout.Foldout(optionsToggle, "Options");
        if (optionsToggle)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.Space();
            EditorGUILayout.BeginVertical();

            var par = EditorGUILayout.ObjectField("Parent To", parentTo, typeof(Transform), true) as Transform;
            if (par != parentTo)
            {
                if (par == null || (PrefabUtility.GetCorrespondingObjectFromSource(par) == null && PrefabUtility.GetPrefabInstanceHandle(par) == null))
                {
                    parentTo = par;
                }
            }

            var serializedObject = new SerializedObject(this);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("stageType"));
            serializedObject.ApplyModifiedProperties();

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.Space();

        var header = EditorGUILayout.GetControlRect();

        GUI.Label(header, "Prefabs", EditorStyles.boldLabel);
        header.y     += header.height - 1f;
        header.height = 1f;
        EditorGUI.DrawRect(header, EditorStyles.label.normal.textColor);

        GUILayout.Space(2f);

        GUI.enabled = selected != null;
        if (GUILayout.Button("設置を終了", EditorStyles.miniButton))
        {
            Deselect();
        }
        GUI.enabled = true;
        if (ev.type == EventType.KeyDown && ev.keyCode == KeyCode.Escape)
        {
            Deselect();
        }

        var buttonHeight = EditorGUIUtility.singleLineHeight * 2f;
        var heightStyle  = GUILayout.Height(buttonHeight);

        var lastRect    = GUILayoutUtility.GetLastRect();
        var scrollMouse = mousePos;

        scrollMouse.x -= lastRect.xMin - prefabScroll.x;
        scrollMouse.y -= lastRect.yMax - prefabScroll.y;

        prefabScroll = EditorGUILayout.BeginScrollView(prefabScroll);

        if (palette.prefabs != null)
        {
            foreach (var prefab in palette.prefabs)
            {
                if (prefab == null)
                {
                    continue;
                }

                var rect = EditorGUILayout.GetControlRect(heightStyle);

                var bgRect = rect;
                bgRect.x      -= 1f;
                bgRect.y      -= 1f;
                bgRect.width  += 2f;
                bgRect.height += 2f;
                if (prefab == selected)
                {
                    EditorGUI.DrawRect(bgRect, new Color32(0x42, 0x80, 0xe4, 0xff));
                }
                {
                    EditorGUIUtility.AddCursorRect(bgRect, MouseCursor.Link);

                    if (bgRect.Contains(scrollMouse))
                    {
                        EditorGUI.DrawRect(bgRect, new Color32(0x42, 0x80, 0xe4, 0x40));
                        if (ev.type == EventType.MouseDown)
                        {
                            EditorApplication.delayCall += () =>
                            {
                                if (selected != prefab)
                                {
                                    Tools.current = Tool.None;
                                    selected      = prefab;
                                    Selection.activeGameObject = parentTo == null ? null : parentTo.gameObject;
                                }
                                else
                                {
                                    selected = null;
                                }
                                SceneView.RepaintAll();
                            };
                        }
                    }
                }

                var iconRect = new Rect(rect.x, rect.y, rect.height, rect.height);

                var icon = AssetPreview.GetAssetPreview(prefab);
                if (icon != null)
                {
                    GUI.DrawTexture(iconRect, icon, ScaleMode.ScaleToFit, true, 1f, Color.white, Vector4.zero, Vector4.one * 4f);
                }
                else
                {
                    EditorGUI.DrawRect(iconRect, EditorStyles.label.normal.textColor * 0.25f);
                }

                var labelRect = rect;
                labelRect.x     += iconRect.width + 4f;
                labelRect.width -= iconRect.width + 4f;
                labelRect.height = EditorGUIUtility.singleLineHeight;
                labelRect.y     += (buttonHeight - labelRect.height) * 0.5f;
                var labelStyle = prefab == selected ? EditorStyles.whiteBoldLabel : EditorStyles.label;
                GUI.Label(labelRect, prefab.name, labelStyle);
            }
        }

        EditorGUILayout.EndScrollView();

        if (AssetPreview.IsLoadingAssetPreviews())
        {
            Repaint();
        }
    }
Beispiel #8
0
        private void DrawGridItem(int index, SearchItem item, Rect itemRect, bool canHover, ICollection <int> selection, Event evt)
        {
            var backgroundRect = new Rect(itemRect.x + 1, itemRect.y + 1, itemRect.width - 2, itemRect.height - 2);
            var isSelected     = selection.Contains(index);
            var isHovered      = canHover && itemRect.Contains(evt.mousePosition);

            Texture2D thumbnail          = null;
            var       shouldFetchPreview = SearchSettings.fetchPreview;

            if (shouldFetchPreview)
            {
                thumbnail          = item.preview;
                shouldFetchPreview = !thumbnail && item.provider.fetchPreview != null;
                if (shouldFetchPreview)
                {
                    var previewSize = new Vector2(itemSize, itemSize);
                    thumbnail = item.provider.fetchPreview(item, context, previewSize, FetchPreviewOptions.Preview2D | FetchPreviewOptions.Normal);
                    if (thumbnail && !AssetPreview.IsLoadingAssetPreviews())
                    {
                        item.preview = thumbnail;
                    }
                }
            }

            if (!thumbnail)
            {
                thumbnail = item.thumbnail;
                if (!thumbnail && item.provider.fetchThumbnail != null)
                {
                    thumbnail = item.provider.fetchThumbnail(item, context);
                    if (thumbnail && !shouldFetchPreview && !AssetPreview.IsLoadingAssetPreviews())
                    {
                        item.thumbnail = thumbnail;
                    }
                }
            }

            var thumbnailRect = new Rect(itemRect.x + itemPadding, itemRect.y + itemPadding, itemSize, itemSize);

            Styles.gridItemBackground.Draw(thumbnailRect, thumbnail ?? Icons.quicksearch, isHovered, false, isSelected, false);

            var labelRect = new Rect(
                itemRect.x + itemPadding, itemRect.yMax - itemLabelHeight - itemPadding,
                itemRect.width - itemPadding * 2f, itemLabelHeight - itemPadding);
            var originalItemLabel = item.GetLabel(context, true);
            var itemLabel         = originalItemLabel;
            var textRectWidth     = (labelRect.width - Styles.gridItemLabel.padding.horizontal - 18) * 2f;
            var maxCharLength     = Utils.GetNumCharactersThatFitWithinWidth(Styles.gridItemLabel, originalItemLabel, textRectWidth);

            if (originalItemLabel.Length > maxCharLength)
            {
                maxCharLength = Math.Max(0, maxCharLength - 3);
                itemLabel     = originalItemLabel.Substring(0, maxCharLength / 2) + "\u2026" + originalItemLabel.Substring(originalItemLabel.Length - maxCharLength / 2);
            }
            else
            {
                var labelSize = Styles.gridItemLabel.CalcSize(new GUIContent(itemLabel));
                labelSize.x += 2;
                labelSize.y += 2;
                if (labelSize.x < labelRect.width)
                {
                    var c = labelRect.center;
                    labelRect = new Rect(c.x - labelSize.x / 2.0f, labelRect.y, labelSize.x, labelSize.y);
                }
            }
            Styles.gridItemLabel.Draw(labelRect, new GUIContent(itemLabel, originalItemLabel), false, false, isSelected || isHovered, isSelected);
        }
    void OnGUI()
    {
        if (guids1 == null)
        {
            setTiles();
        }

        //setTiles();
        GUILayout.BeginHorizontal();

        scrollPosSelection = EditorGUILayout.BeginScrollView(scrollPosSelection, GUILayout.MaxWidth(margin));
        var deleteButtonSize        = 30;
        var imageButtonSize         = 75;
        var labelSise               = 15;
        var marginSize              = 10;
        var numberOfVisibleElements = 12;
        var blockSize               = labelSise + imageButtonSize + marginSize;

        if (selectedButton == -1)
        {
            GUI.color = Color.red;
        }

        if (GUILayout.Button("Delete", GUILayout.MaxWidth(margin - scrollBarSize), GUILayout.Height(deleteButtonSize)))
        {
            selectedButton = -1;
        }
        GUI.color = Color.white;
        for (var i = 0; i < guids1.Length; i++)
        {
            if (i == selectedButton)
            {
                GUI.color = Color.green;
            }

            if (scrollPosSelection.y < (i * blockSize) + deleteButtonSize && scrollPosSelection.y > (i * blockSize) - blockSize * numberOfVisibleElements)
            {
                if (previews[i] == null && !AssetPreview.IsLoadingAssetPreviews())
                {
                    previews[i] = AssetPreview.GetAssetPreview(tilesModels[i]);
                }
            }
            else
            {
                previews[i] = null;
            }
            GUILayout.Label(tilesModels[i].name, GUILayout.MaxWidth(margin - scrollBarSize), GUILayout.Height(labelSise));
            if (GUILayout.Button(previews[i], GUILayout.Height(imageButtonSize)))
            {
                selectedButton = i;
            }
            GUI.color = Color.white;
        }

        GUILayout.EndScrollView();
        scrollPosTileEditor = EditorGUILayout.BeginScrollView(scrollPosTileEditor, GUILayout.Width(position.width - margin), GUILayout.Height(position.height));
        var decimals = 0;

        GUILayout.Label("", GUILayout.Width(mapSize * buttonSize), GUILayout.Height(mapSize * buttonSize));
        for (var i = 0; i < mapSize; i++)
        {
            for (var j = 0; j < mapSize; j++)
            {
                if (tileMapper.GetTiles()[i + (j * mapSize)] != null)
                {
                    GUI.color = Color.green;
                }

                if (GUI.Button(new Rect(i * buttonSize, j * buttonSize, buttonSize, buttonSize), (i + (j * mapSize)).ToString()))
                {
                    if (selectedButton != -1)
                    {
                        GameObject clone = PrefabUtility.InstantiatePrefab(tilesModels[selectedButton] as GameObject) as GameObject;
                        var        gameObjectInstance = tileMapper.AddTile(i + (j * mapSize), clone, new Vector3(i * tileSize, 0, -j * tileSize));

                        if (clone.gameObject.GetComponent <TileData>().TileSize.x > 1)
                        {
                            tileMapper.AddExtraSpace((i + 1) + (j * mapSize), gameObjectInstance, new Vector3(i * tileSize, 0, -j * tileSize));
                        }
                        if (clone.gameObject.GetComponent <TileData>().TileSize.y > 1)
                        {
                            tileMapper.AddExtraSpace(i + ((j + 1) * mapSize), gameObjectInstance, new Vector3(i * tileSize, 0, -j * tileSize));
                        }
                    }
                    else
                    {
                        tileMapper.RemoveTile(i + (j * mapSize));
                    }
                }
                GUI.color = Color.white;
            }
            decimals++;
        }

        GUILayout.EndScrollView();
        GUILayout.EndHorizontal();
    }