Example #1
0
    public override void OnInspectorGUI()
    {
        tile            = (WrapTile)target;
        wdiv            = ((EditorGUIUtility.currentViewWidth - 30) / 3);
        spaceTrack      = 0;
        baseRect.width  = wdiv;
        baseRect.height = wdiv;
        baseRect.y      = 50;

        // recreation of key parts from base inspector
        GUILayout.BeginHorizontal();
        GUILayout.Label("Sprite");
        tile.sprite = (Sprite)EditorGUILayout.ObjectField(tile.sprite, typeof(Sprite), false, GUILayout.Width(EditorGUIUtility.currentViewWidth / 2));
        GUILayout.EndHorizontal();
        tile.color = EditorGUI.ColorField(new Rect(EditorGUIUtility.currentViewWidth / 2 - 5, 70, EditorGUIUtility.currentViewWidth / 2, 20), tile.color);
        GUILayout.Label("Color");

        baseRect.y += 40;
        spaceTrack += baseRect.y - (50 + spaceTrack);

        //Base Tiles Foldout (Dropdown)
        BaseTileEdit = EditorGUILayout.Foldout(BaseTileEdit, "Base Tiles");
        baseRect.y  += 18;
        spaceTrack  += baseRect.y - (50 + spaceTrack);
        if (BaseTileEdit)
        {
            // main set of 9 tiles
            baseTitle("Base border Tiles and center");
            DrawOutside(6, 14, 10);
            baseRect.y += wdiv;
            DrawOutside(7, 15, 11);
            baseRect.y += wdiv;
            DrawOutside(5, 13, 9);

            // single width tiles
            baseRect.y += 20 + wdiv;
            baseTitle("Base single Width Horizontl Tiles");
            DrawOutside(4, 12, 8);
            baseRect.y += 10 + wdiv;
            baseTitle("Base single Width Vertical Tiles");
            baseTitle("Left(Top) - Right(Bottom)");
            DrawOutside(2, 3, 1);
            baseRect.y += 10 + wdiv;
            baseTitle("Base single Tile");
            baseRect.x      = 10;
            tile.outside[0] = (Sprite)EditorGUI.ObjectField(baseRect, tile.outside[0], typeof(Sprite), false);
            baseRect.y     += wdiv;
            baseTitle("");
        }

        //Center Internal Conner Tiles Foldout (Dropdown)
        CenterInternTileEdit = EditorGUILayout.Foldout(CenterInternTileEdit, "Central Internal Conner Tiles");
        baseRect.y          += 18;
        spaceTrack          += baseRect.y - (50 + spaceTrack);
        if (CenterInternTileEdit)
        {
            // main set of 9 tiles
            baseTitle("internal facing corner Tiles and center");
            DrawCenterInternal(13, 9, 11);
            baseRect.y += wdiv;
            DrawCenterInternal(12, 0, 3);
            baseRect.y += wdiv;
            DrawCenterInternal(14, 6, 7);

            // single width tiles
            baseRect.y += 20 + wdiv;
            baseTitle("diagnal interior corner Tiles");
            baseRect.x            = 10;
            tile.interiorMain[5]  = (Sprite)EditorGUI.ObjectField(baseRect, tile.interiorMain[5], typeof(Sprite), false);
            baseRect.x           += wdiv;
            tile.interiorMain[10] = (Sprite)EditorGUI.ObjectField(baseRect, tile.interiorMain[10], typeof(Sprite), false);


            baseRect.y += 10 + wdiv;
            baseTitle("three interior corner Tiles");
            baseRect.x           = 10;
            tile.interiorMain[8] = (Sprite)EditorGUI.ObjectField(baseRect, tile.interiorMain[8], typeof(Sprite), false);
            baseRect.x          += wdiv;
            tile.interiorMain[1] = (Sprite)EditorGUI.ObjectField(baseRect, tile.interiorMain[1], typeof(Sprite), false);
            baseRect.y          += wdiv;
            baseRect.x           = 10;
            tile.interiorMain[4] = (Sprite)EditorGUI.ObjectField(baseRect, tile.interiorMain[4], typeof(Sprite), false);
            baseRect.x          += wdiv;
            tile.interiorMain[2] = (Sprite)EditorGUI.ObjectField(baseRect, tile.interiorMain[2], typeof(Sprite), false);


            baseRect.y += 10 + wdiv;
            baseTitle("Base single Tile");
            baseRect.x            = 10;
            tile.interiorMain[15] = (Sprite)EditorGUI.ObjectField(baseRect, tile.interiorMain[15], typeof(Sprite), false);
            baseRect.y           += wdiv;
            baseTitle("");
        }

        // Edge Internal Corner Tiles Foldout (Dropdown)
        EdgeInternTileEdit = EditorGUILayout.Foldout(EdgeInternTileEdit, "Edge Internal Conner Tiles");
        baseRect.y        += 18;
        spaceTrack        += baseRect.y - (50 + spaceTrack);
        if (EdgeInternTileEdit)
        {
            baseTitle("Horizontal Edge Interior corner Tiles");
            DrawEdgeInternal(4, 5, 6);
            baseRect.y += wdiv;
            DrawEdgeInternal(7, 8, 9);

            baseRect.y += 10 + wdiv;
            baseTitle("Vertical Edge Interior corner Tiles");
            DrawEdgeInternal2Set(10, 13);
            DrawEdgeInternal2Set(11, 14);
            DrawEdgeInternal2Set(12, 15);

            baseRect.y += 10;
            baseTitle("outside corner with Internal corner Tiles");
            DrawEdgeInternal2Set(0, 1);
            DrawEdgeInternal2Set(2, 3);
        }

        // acepted tiels to merger on borders with
        GUILayout.Space(6);
        AceptedEdit = EditorGUILayout.Foldout(AceptedEdit, "Acepted Edge Merge Tiles - (" + tile.accept.Count + ")");
        baseRect.y += 14;
        if (AceptedEdit)
        {
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("+", GUILayout.Width(20)))
            {
                tile.accept.Add(null);
            }
            GUILayout.Label(" add a new tile to list");
            GUILayout.EndHorizontal();
            baseRect.y += 28;
            for (int i = 0; i < tile.accept.Count; i++)
            {
                GUILayout.BeginHorizontal();
                tile.accept[i] = (Tile)EditorGUILayout.ObjectField(tile.accept[i], typeof(Tile), false);
                bool deleteCheck = false;
                if (GUILayout.Button("-", GUILayout.Width(20)))
                {
                    deleteCheck = true;
                }
                baseRect.y += 20;
                GUILayout.EndHorizontal();

                if (deleteCheck)
                {
                    tile.accept.RemoveAt(i);
                }
                else
                {
                    if (tile.accept[i])
                    {
                        GUI.Box(baseRect, AssetPreview.GetAssetPreview(tile.accept[i].sprite));
                        GUILayout.Space(wdiv);
                        baseRect.y += wdiv;
                    }
                }
            }
            spaceTrack += baseRect.y - (50 + spaceTrack);
        }

        EditorUtility.SetDirty(tile);

        // remove coment slashes to add Original unity GUI to the bottom
        baseRect.y += 30;
        baseTitle("[[ Original GUI ]]");
        base.OnInspectorGUI();
    }
Example #2
0
        public void ShowReadme()
        {
            var readme = (Readme)target;

            Init();

            if (readme.sections != null)
            {
                foreach (var section in readme.sections)
                {
                    #region DefineOrderVariables
                    bool referensesAtTop = false;

                    #region Logic
                    if (section.assetReferences != null)
                    {
                        if (section.ShowRefsBeforeText)
                        {
                            referensesAtTop = true;
                        }
                    }

                    #endregion

                    #endregion

                    if (!string.IsNullOrEmpty(section.heading))
                    {
                        GUILayout.Label(section.heading, HeadingStyle);
                    }


                    if (referensesAtTop)
                    {
                        ShowRefs(section.assetReferences);
                        if (!string.IsNullOrEmpty(section.text))
                        {
                            GUILayout.Label(section.text, BodyStyle);
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(section.text))
                        {
                            GUILayout.Label(section.text, BodyStyle);
                        }
                        ShowRefs(section.assetReferences);
                    }

                    if (section.CheckMarks != null)
                    {
                        foreach (var cm in section.CheckMarks)
                        {
                            cm.Value = GUILayout.Toggle(cm.Value, cm.Text);
                        }
                    }


                    if (!string.IsNullOrEmpty(section.linkText))
                    {
                        if (LinkLabel(new GUIContent(section.linkText)))
                        {
                            Application.OpenURL(section.url);
                        }
                    }
                    GUILayout.Space(kSpace);
                }
            }



            if (readme.prefabForPreview != null)
            {
                var pf = readme.prefabForPreview;

                var img = AssetPreview.GetAssetPreview(pf);

                //EditorGUI.DrawPreviewTexture(position, img);

                GUILayout.Label(img, GUILayout.Width(img.width), GUILayout.Height(img.height));
            }
            if (Event.current.type == EventType.MouseDown && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
            {
                Debug.Log("Pressing prefab");
            }
        }
Example #3
0
    // Draw the GUI
    public void DrawGUI(int gridWidth)
    {
        EditorGUILayout.BeginHorizontal();

        _groupName = EditorGUILayout.TextField("Prefab Group Name", _groupName);

        if (GUILayout.Button("Set") && _groupName.Length > 0)
        {
            if (_groupingObjects.ContainsKey(_groupName))
            {
                groupingObject = _groupingObjects[_groupName] ? _groupingObjects[_groupName] : new GameObject(_groupName);
            }
            else
            if (!(groupingObject = GameObject.Find(_groupName)))
            {
                _groupingObjects.Add(_groupName, groupingObject = new GameObject(_groupName));
            }
        }

        if (_groupName.Length == 0)
        {
            groupingObject = null;
        }

        EditorGUILayout.EndHorizontal();

        EditorGUILayout.LabelField("Prefab Selection");

        _menuScroll = EditorGUILayout.BeginScrollView(_menuScroll);
        EditorGUILayout.BeginHorizontal();

        // keeping track of the accumulative slider values
        float slider_whole = 0.0f;

        // for each prefab draw all of its options
        for (int i = 0; i < _prefabs.Count; ++i)
        {
            if (0 == i % gridWidth && i > 0)
            {
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Separator();
                EditorGUILayout.BeginHorizontal();
            }
            _prefabs[i].rect = EditorGUILayout.BeginVertical(GUILayout.Width(125));
            _prefabs[i].rect = EditorGUILayout.BeginHorizontal();
            _prefabs[i].rect = EditorGUILayout.BeginVertical();
            GUILayout.Label(AssetPreview.GetAssetPreview(_prefabs[i].gameObject), GUILayout.Width(120));
            if (GUI.Button(new Rect(_prefabs[i].rect.x + 90, _prefabs[i].rect.y + 5.0f, 20, 20), "X"))
            {
                _prefabs.RemoveAt(i--);
                continue;
            }
            if (_prefabs[i].gameObject)
            {
                Rect rect = _prefabs[i].rect;
                _prefabs[i].toggle = GUI.Toggle(new Rect(rect.x + 7.5f, rect.y + 5.0f, 50, 35), _prefabs[i].toggle, "");
                _prefabs[i].layer  = _prefabs[i].layerMenu.DrawGUI(new Rect(rect.x + 5, rect.y + 100, 75, 20));
                string percent = (_prefabs[i].percent * 100).ToString();
                percent = ((percent.Length > 4) ? percent.Substring(0, 4) : percent) + "%";
                EditorGUI.LabelField(new Rect(rect.x + 79, rect.y + 100, 40, 20), percent);
            }
            EditorGUILayout.EndVertical();
            _prefabs[i].slider = GUILayout.VerticalSlider(_prefabs[i].slider, 1.0f, 0.0f, GUILayout.Height(120));
            slider_whole      += _prefabs[i].gameObject ? _prefabs[i].slider : 0f;
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            _prefabs[i].lockOrientation = EditorGUILayout.Toggle(_prefabs[i].lockOrientation, GUILayout.Width(10));
            EditorGUILayout.LabelField("Lock Orientation", GUILayout.Width(110));
            EditorGUILayout.EndHorizontal();

            //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

            EditorGUILayout.BeginHorizontal();
            _prefabs[i].FixRotToggle = EditorGUILayout.Toggle(_prefabs[i].FixRotToggle, GUILayout.Width(10));
            EditorGUILayout.LabelField("Initial Rotation", GUILayout.Width(105));
            EditorGUILayout.EndHorizontal();
            if (_prefabs[i].FixRotToggle)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("X", GUILayout.Width(60));
                EditorGUILayout.LabelField("Y", GUILayout.Width(60));
                EditorGUILayout.LabelField("Z", GUILayout.Width(60));
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                _prefabs[i].FixRotXYZ[0] = EditorGUILayout.FloatField(_prefabs[i].FixRotXYZ[0], GUILayout.Width(60));
                _prefabs[i].FixRotXYZ[1] = EditorGUILayout.FloatField(_prefabs[i].FixRotXYZ[1], GUILayout.Width(60));
                _prefabs[i].FixRotXYZ[2] = EditorGUILayout.FloatField(_prefabs[i].FixRotXYZ[2], GUILayout.Width(60));
                EditorGUILayout.EndHorizontal();
            }

            //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

            EditorGUILayout.BeginHorizontal();
            _prefabs[i].randRotToggle = EditorGUILayout.Toggle(_prefabs[i].randRotToggle, GUILayout.Width(10));
            EditorGUILayout.LabelField("Random Rotation", GUILayout.Width(105));
            EditorGUILayout.EndHorizontal();
            if (_prefabs[i].randRotToggle)
            {
                EditorGUILayout.BeginHorizontal();
                _prefabs[i].randRotXYZ[0] = EditorGUILayout.ToggleLeft("X", _prefabs[i].randRotXYZ[0], GUILayout.Width(25));
                _prefabs[i].randRotXYZ[1] = EditorGUILayout.ToggleLeft("Y", _prefabs[i].randRotXYZ[1], GUILayout.Width(25));
                _prefabs[i].randRotXYZ[2] = EditorGUILayout.ToggleLeft("Z", _prefabs[i].randRotXYZ[2], GUILayout.Width(25));
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.BeginHorizontal();
            _prefabs[i].randScaleToggle = EditorGUILayout.Toggle(_prefabs[i].randScaleToggle, GUILayout.Width(10));
            EditorGUILayout.LabelField("Random Scale", GUILayout.Width(105));
            EditorGUILayout.EndHorizontal();
            if (_prefabs[i].randScaleToggle)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Min", GUILayout.Width(60));
                EditorGUILayout.LabelField("Max", GUILayout.Width(60));
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                _prefabs[i].randScaleMin = EditorGUILayout.FloatField(_prefabs[i].randScaleMin, GUILayout.Width(60));
                _prefabs[i].randScaleMax = EditorGUILayout.FloatField(_prefabs[i].randScaleMax, GUILayout.Width(60));
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Depth", GUILayout.Width(70));
            _prefabs[i].depth = EditorGUILayout.FloatField(_prefabs[i].depth, GUILayout.Width(40));
            EditorGUILayout.EndHorizontal();
            _prefabs[i].gameObject = EditorGUILayout.ObjectField(_prefabs[i].gameObject, typeof(GameObject), false);
            EditorGUILayout.EndVertical();
        }

        EditorGUILayout.EndHorizontal();

        // button for adding another prefab slot
        if (GUILayout.Button("Add \nPrefab Slot"))
        {
            _prefabs.Add(new Prefab());
        }

        EditorGUILayout.EndScrollView();

        // calculate and display the percentages
        if (slider_whole > 0.0f)
        {
            for (int i = 0; i < _prefabs.Count; ++i)
            {
                _prefabs[i].percent = _prefabs[i].slider / slider_whole;
            }
        }
        else
        {
            for (int i = 0; i < _prefabs.Count; ++i)
            {
                _prefabs[i].percent = 0.0f;
            }
        }
    }
Example #4
0
 public static Texture2D GetMiniTypeThumbnail(this Type self)
 {
     return(AssetPreview.GetMiniTypeThumbnail(self));
 }
    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();
        }
    }
Example #6
0
 private static Texture2D GetAssetPreviewFromGUID(string guid)
 {
     return(AssetPreview.GetAssetPreviewFromGUID(guid));
 }
        /// <summary>
        /// Called on GUI events.
        /// </summary>
        internal void OnGUI()
        {
            EditorGUILayout.BeginVertical();
            this.scrollPos = EditorGUILayout.BeginScrollView(this.scrollPos, false, false);

            GUILayout.Label(string.Format("Scenes In Build Settings ({0} opened)", EditorSceneManager.sceneCount), EditorStyles.boldLabel);
            for (int i = 0; i < EditorBuildSettings.scenes.Length; i++)
            {
                EditorBuildSettingsScene buildSettingsScene = EditorBuildSettings.scenes[i];
                string sceneName = Path.GetFileNameWithoutExtension(buildSettingsScene.path);
                if (!buildSettingsScene.enabled)
                {
                    sceneName += " (disabled)";
                }
                EditorGUILayout.BeginHorizontal();
                {
                    using (new EditorGUI.DisabledScope(IsSceneOpen(buildSettingsScene)))
                    {
                        GUIContent content = new GUIContent(sceneName, AssetPreview.GetMiniTypeThumbnail(typeof(SceneAsset)));
                        GUIStyle   style   = new GUIStyle(GUI.skin.GetStyle("Button"))
                        {
                            alignment    = TextAnchor.MiddleLeft,
                            stretchWidth = true,
                            fixedHeight  = 25
                        };
                        bool pressed = GUILayout.Button(content, style);
                        if (pressed)
                        {
                            if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
                            {
                                EditorSceneManager.OpenScene(buildSettingsScene.path);
                            }
                        }
                    }
                }
                if (!IsSceneOpen(buildSettingsScene))
                {
                    GUIContent content = new GUIContent("Add", "Adds the scene to the current open ones");
                    GUIStyle   style   = new GUIStyle(GUI.skin.GetStyle("Button"))
                    {
                        alignment   = TextAnchor.MiddleLeft,
                        fixedWidth  = 60,
                        fixedHeight = 25
                    };
                    bool pressed = GUILayout.Button(content, style);
                    if (pressed)
                    {
                        EditorSceneManager.OpenScene(buildSettingsScene.path, OpenSceneMode.Additive);
                    }
                }
                else if (EditorSceneManager.sceneCount > 1)
                {
                    GUIContent content = new GUIContent("Remove", "Unloads and removes the scene");
                    GUIStyle   style   = new GUIStyle(GUI.skin.GetStyle("Button"))
                    {
                        alignment   = TextAnchor.MiddleLeft,
                        fixedWidth  = 60,
                        fixedHeight = 25
                    };
                    bool pressed = GUILayout.Button(content, style);
                    if (pressed)
                    {
                        Scene scene = FromBuildSettingsScene(buildSettingsScene);
                        if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
                        {
                            EditorSceneManager.CloseScene(scene, true);
                        }
                    }
                }

                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndVertical();
        }
Example #8
0
        private void renderUiForSingleMazeSelected()
        {
            EditorGUILayout.BeginVertical();

            GUILayout.Label("Replace Units");

            replacementPrefab = (GameObject)EditorGUILayout.ObjectField(replacementPrefab, typeof(UnityEngine.GameObject), false);

            MazeUnit mazeUnit = null;

            string errorMessage = "No prefab selected!";

            if (replacementPrefab != null)
            {
                mazeUnit = replacementPrefab.GetComponent <MazeUnit>();
            }
            else
            {
                EditorGUILayout.HelpBox(errorMessage, MessageType.Error);
            }

            if (mazeUnit == null)
            {
                if (replacementPrefab != null)
                {
                    errorMessage = "Selected Asset is no MazeUnit!";

                    EditorGUILayout.HelpBox(errorMessage, MessageType.Error);
                }
            }
            else
            {
                if (GUILayout.Button(new GUIContent("Replace Maze Units \n with this prefab.", ToolTip_Replace_Units), GUILayout.Height(50f)))
                {
                    CallReplaceAlgorithm();
                }

                EditorGUILayout.HelpBox(MsgBox_Replace_Action, MessageType.Warning);
            }

            EditorGUILayout.EndVertical();

            if (replacementPrefab)
            {
                var previewTexture = AssetPreview.GetAssetPreview(replacementPrefab);

                GUILayout.Box(previewTexture);
            }

            if (GUILayout.Button(new GUIContent("Save as new prefab?", "Creates a new prefab instead of overwriting the old one!")))
            {
                var targetPath = EditorUtility.SaveFilePanelInProject("Save new maze prefab", "ResizedMaze", EditorEnvironmentConstants.PREFAB_EXTENSION, "sdfsfd");

                if (targetPath != null)
                {
                    PrefabUtility.CreatePrefab(targetPath, selectedMaze.gameObject);
                }
            }

            // Resize currently through replacement of Units!
            //GUILayout.Label("Change:", EditorStyles.boldLabel);

            //selectedMaze.RoomDimension = EditorGUILayout.Vector3Field("Room dimension", selectedMaze.RoomDimension );

            //if (GUILayout.Button(new GUIContent("Resize (recommended)", "Resize the geometry"), GUILayout.Height(30)))
            //{
            //    var modificationModel = new UnitMeshModificationModel(selectedMaze.RoomDimension, Vector3.zero ,true);
            //    ApplyToAllMazeUnits(selectedMaze, (u) => {

            //        MazeEditorUtil.ResizeUnitByMeshModification(u.gameObject, modificationModel);
            //    });
            //}

            //if (GUILayout.Button(new GUIContent("Rescale", "Rescale over the localScale value")))
            //{
            //    MazeEditorUtil.Rescale(selectedMaze, selectedMaze.RoomDimension, unitFloorOffset);
            //    MazeEditorUtil.RebuildGrid(selectedMaze);
            //}
        }
Example #9
0
        internal void AddEntries(List <SearchTreeEntry> cache, IEnumerable <UdonNodeDefinition> definitions, int level,
                                 bool stripToLastDot = false)
        {
            Texture2D icon = AssetPreview.GetMiniTypeThumbnail(typeof(GameObject));
            Texture2D iconGetComponents = EditorGUIUtility.FindTexture("d_ViewToolZoom");
            Texture2D iconOther         = new Texture2D(1, 1);

            iconOther.SetPixel(0, 0, new Color(0, 0, 0, 0));
            iconOther.Apply();

            Dictionary <string, UdonNodeDefinition> baseNodeDefinition = new Dictionary <string, UdonNodeDefinition>();

            foreach (UdonNodeDefinition nodeDefinition in definitions.OrderBy(
                         s => UdonGraphExtensions.PrettyFullName(s)))
            {
                string   baseIdentifier      = nodeDefinition.fullName;
                string[] splitBaseIdentifier = baseIdentifier.Split(new[] { "__" }, StringSplitOptions.None);
                if (splitBaseIdentifier.Length >= 2)
                {
                    baseIdentifier = $"{splitBaseIdentifier[0]}__{splitBaseIdentifier[1]}";
                }

                if (baseNodeDefinition.ContainsKey(baseIdentifier))
                {
                    continue;
                }

                baseNodeDefinition.Add(baseIdentifier, nodeDefinition);
            }

            var nodesOfGetComponentType = new List <SearchTreeEntry>();
            var nodesOfOtherType        = new List <SearchTreeEntry>();

            // add all subTypes
            foreach (KeyValuePair <string, UdonNodeDefinition> nodeDefinitionsEntry in baseNodeDefinition)
            {
                string nodeName = UdonGraphExtensions.PrettyBaseName(nodeDefinitionsEntry.Key);
                nodeName = nodeName.UppercaseFirst();
                nodeName = nodeName.Replace("_", " ");
                if (stripToLastDot)
                {
                    int lastDotIndex = nodeName.LastIndexOf('.');
                    nodeName = nodeName.Substring(lastDotIndex + 1);
                }

                // don't add Variable or Comment nodes
                if (nodeName.StartsWithCached("Variable") || nodeName.StartsWithCached("Get Var") ||
                    nodeName.StartsWithCached("Set Var") || nodeName.StartsWithCached("Comment"))
                {
                    continue;
                }

                if (nodeName.StartsWithCached("Object"))
                {
                    nodeName = $"{nodeDefinitionsEntry.Value.type.Namespace}.{nodeName}";
                }
                // temp skip first-gen midi event nodes. Todo: remove this before release
                if (nodeName.StartsWithCached("Event OnNote") || nodeName.StartsWithCached("Event OnControlChange"))
                {
                    continue;
                }
                if (nodeNamesGetComponentType.Contains(nodeName))
                {
                    nodesOfGetComponentType.Add(new SearchTreeEntry(new GUIContent(nodeName, iconGetComponents))
                    {
                        level = level + 1, userData = nodeDefinitionsEntry.Value
                    });
                    continue;
                }

                // Only put 'Equals' in the 'Other' category if this definition is not an Enum
                if (nodeNamesOtherType.Contains(nodeName) || nodeName == "Equals" && !nodeDefinitionsEntry.Value.type.IsEnum)
                {
                    nodesOfOtherType.Add(new SearchTreeEntry(new GUIContent(nodeName, iconOther))
                    {
                        level = level + 1, userData = nodeDefinitionsEntry.Value
                    });
                    continue;
                }

                cache.Add(new SearchTreeEntry(new GUIContent(nodeName, icon))
                {
                    level = level, userData = nodeDefinitionsEntry.Value
                });
            }

            // add getComponents level
            if (nodesOfGetComponentType.Count > 0)
            {
                cache.Add(new SearchTreeGroupEntry(new GUIContent("GetComponents"), level));
                foreach (var entry in nodesOfGetComponentType)
                {
                    cache.Add(entry);
                }
            }

            // add other level
            if (nodesOfOtherType.Count > 0)
            {
                cache.Add(new SearchTreeGroupEntry(new GUIContent("Other"), level));
                foreach (var entry in nodesOfOtherType)
                {
                    cache.Add(entry);
                }
            }
        }
    //------------------------------------------------------------------

    void GameObjectsMenu()
    {
        EditorGUILayout.BeginVertical("Box");
        {
            EditorGUILayout.Space();

            SerializedProperty playerStartupFreeRadius = serializedObject.FindProperty("playerStartupFreeRadius");
            EditorGUILayout.PropertyField(playerStartupFreeRadius, new GUIContent("Player Free Radius"));

            EditorGUILayout.Space();

            SerializedProperty gameObjectsProperties = serializedObject.FindProperty("gameObjectsProperties");
            //EditorGUILayout.PropertyField(gameObjectsProperties, true);

            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField("Prototypes: " + gameObjectsProperties.arraySize, EditorStyles.boldLabel, GUILayout.Width(84));

                GUI.enabled = GUI_Enabled() && (gameObjectsProperties.arraySize >= 0);
                if (GUILayout.Button("+"))
                {
                    gameObjectsProperties.arraySize++;
                    EasyTerrain.PropertiesGameObject gameObjectPropertiesDefault = new EasyTerrain.PropertiesGameObject();
                    if (gameObjectsProperties.arraySize > 1)
                    {
                        gameObjectPropertiesDefault.prototype                 = gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 2).FindPropertyRelative("prototype").objectReferenceValue as GameObject;
                        gameObjectPropertiesDefault.density                   = gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 2).FindPropertyRelative("density").floatValue;
                        gameObjectPropertiesDefault.preventMeshOverlap        = gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 2).FindPropertyRelative("preventMeshOverlap").boolValue;
                        gameObjectPropertiesDefault.minScale                  = gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 2).FindPropertyRelative("minScale").floatValue;
                        gameObjectPropertiesDefault.maxScale                  = gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 2).FindPropertyRelative("maxScale").floatValue;
                        gameObjectPropertiesDefault.minSteepness              = gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 2).FindPropertyRelative("minSteepness").floatValue;
                        gameObjectPropertiesDefault.maxSteepness              = gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 2).FindPropertyRelative("maxSteepness").floatValue;
                        gameObjectPropertiesDefault.forceHorizontalPlacement  = gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 2).FindPropertyRelative("forceHorizontalPlacement").boolValue;
                        gameObjectPropertiesDefault.useNoiseLayer             = gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 2).FindPropertyRelative("useNoiseLayer").boolValue;
                        gameObjectPropertiesDefault.noiseSettings.frequency   = gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 2).FindPropertyRelative("noiseSettings").FindPropertyRelative("frequency").floatValue;
                        gameObjectPropertiesDefault.noiseSettings.octaves     = gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 2).FindPropertyRelative("noiseSettings").FindPropertyRelative("octaves").intValue;
                        gameObjectPropertiesDefault.noiseSettings.lacunarity  = gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 2).FindPropertyRelative("noiseSettings").FindPropertyRelative("lacunarity").floatValue;
                        gameObjectPropertiesDefault.noiseSettings.persistence = gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 2).FindPropertyRelative("noiseSettings").FindPropertyRelative("persistence").floatValue;
                        gameObjectPropertiesDefault.noiseSettings.threshold   = gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 2).FindPropertyRelative("noiseSettings").FindPropertyRelative("threshold").floatValue;
                        gameObjectPropertiesDefault.noiseSettings.falloff     = gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 2).FindPropertyRelative("noiseSettings").FindPropertyRelative("falloff").floatValue;
                    }
                    else
                    {
                        gameObjectPropertiesDefault.noiseSettings.type        = NoiseGenerator.NoiseMethodType.Perlin3D;
                        gameObjectPropertiesDefault.noiseSettings.frequency   = 0.002f;
                        gameObjectPropertiesDefault.noiseSettings.octaves     = 1;
                        gameObjectPropertiesDefault.noiseSettings.lacunarity  = 2f;
                        gameObjectPropertiesDefault.noiseSettings.persistence = 0.5f;
                        gameObjectPropertiesDefault.noiseSettings.threshold   = 0.5f;
                        gameObjectPropertiesDefault.noiseSettings.falloff     = 0.5f;
                    }
                    gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 1).FindPropertyRelative("density").floatValue                 = gameObjectPropertiesDefault.density;
                    gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 1).FindPropertyRelative("preventMeshOverlap").boolValue       = gameObjectPropertiesDefault.preventMeshOverlap;
                    gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 1).FindPropertyRelative("minScale").floatValue                = gameObjectPropertiesDefault.minScale;
                    gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 1).FindPropertyRelative("maxScale").floatValue                = gameObjectPropertiesDefault.maxScale;
                    gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 1).FindPropertyRelative("minSteepness").floatValue            = gameObjectPropertiesDefault.minSteepness;
                    gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 1).FindPropertyRelative("maxSteepness").floatValue            = gameObjectPropertiesDefault.maxSteepness;
                    gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 1).FindPropertyRelative("forceHorizontalPlacement").boolValue = gameObjectPropertiesDefault.forceHorizontalPlacement;
                    gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 1).FindPropertyRelative("prototype").objectReferenceValue     = gameObjectPropertiesDefault.prototype;
                    gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 1).FindPropertyRelative("useNoiseLayer").boolValue            = gameObjectPropertiesDefault.useNoiseLayer;
                    gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 1).FindPropertyRelative("noiseSettings").FindPropertyRelative("type").enumValueIndex    = (int)gameObjectPropertiesDefault.noiseSettings.type;
                    gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 1).FindPropertyRelative("noiseSettings").FindPropertyRelative("frequency").floatValue   = gameObjectPropertiesDefault.noiseSettings.frequency;
                    gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 1).FindPropertyRelative("noiseSettings").FindPropertyRelative("octaves").intValue       = gameObjectPropertiesDefault.noiseSettings.octaves;
                    gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 1).FindPropertyRelative("noiseSettings").FindPropertyRelative("lacunarity").floatValue  = gameObjectPropertiesDefault.noiseSettings.lacunarity;
                    gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 1).FindPropertyRelative("noiseSettings").FindPropertyRelative("persistence").floatValue = gameObjectPropertiesDefault.noiseSettings.persistence;
                    gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 1).FindPropertyRelative("noiseSettings").FindPropertyRelative("threshold").floatValue   = gameObjectPropertiesDefault.noiseSettings.threshold;
                    gameObjectsProperties.GetArrayElementAtIndex(gameObjectsProperties.arraySize - 1).FindPropertyRelative("noiseSettings").FindPropertyRelative("falloff").floatValue     = gameObjectPropertiesDefault.noiseSettings.falloff;
                    SerializedProperty inspGameObjectSelectorIndex = serializedObject.FindProperty("inspGameObjectSelectorIndex");
                    inspGameObjectSelectorIndex.intValue = gameObjectsProperties.arraySize - 1;
                }
                GUI.enabled = GUI_Enabled() && (gameObjectsProperties.arraySize > 0);
                if (GUILayout.Button("-"))
                {
                    gameObjectsProperties.arraySize--;
                }
                GUI_Enabled();
            }
            EditorGUILayout.EndHorizontal();

            if (gameObjectsProperties.arraySize > 0)
            {
                SerializedProperty inspGameObjectSelectorIndex = serializedObject.FindProperty("inspGameObjectSelectorIndex");
                inspGameObjectSelectorIndex.intValue = Mathf.Clamp(inspGameObjectSelectorIndex.intValue, 0, gameObjectsProperties.arraySize - 1);
                string[] menuTexts = new string[gameObjectsProperties.arraySize];
                for (int j = 0; j < gameObjectsProperties.arraySize; j++)
                {
                    menuTexts[j] = "#" + j;
                }
                EditorGUILayout.Space();
                inspGameObjectSelectorIndex.intValue = GUILayout.SelectionGrid(inspGameObjectSelectorIndex.intValue, menuTexts, gameObjectsProperties.arraySize);
                EditorGUILayout.Space();

                int i = inspGameObjectSelectorIndex.intValue;

                SerializedProperty prototype = gameObjectsProperties.GetArrayElementAtIndex(i).FindPropertyRelative("prototype");

                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.BeginVertical();
                    {
                        float labelWidth = 66f;
                        EditorGUILayout.PropertyField(prototype, GUIContent.none);
                        EditorGUILayout.BeginHorizontal();
                        {
                            SerializedProperty density = gameObjectsProperties.GetArrayElementAtIndex(i).FindPropertyRelative("density");
                            EditorGUILayout.LabelField("Density", GUILayout.MaxWidth(labelWidth));
                            EditorGUILayout.PropertyField(density, GUIContent.none);
                        }
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.BeginHorizontal();
                        {
                            SerializedProperty preventMeshOverlap = gameObjectsProperties.GetArrayElementAtIndex(i).FindPropertyRelative("preventMeshOverlap");
                            //EditorGUILayout.LabelField("", GUILayout.Width(labelWidth));
                            preventMeshOverlap.boolValue = EditorGUILayout.ToggleLeft("Prevent Mesh Overlap", preventMeshOverlap.boolValue, GUILayout.MinWidth(0));
                        }
                        EditorGUILayout.EndHorizontal();
                        //EditorGUILayout.BeginHorizontal();
                        //{
                        //    SerializedProperty minDistance = trees.GetArrayElementAtIndex(i).FindPropertyRelative("minDistance");
                        //    EditorGUILayout.LabelField("minDistance", GUILayout.Width(labelWidth*2f));
                        //    GUI.enabled = false;
                        //    EditorGUILayout.FloatField(minDistance.floatValue);
                        //    GUI_Enabled();
                        //}
                        //EditorGUILayout.EndHorizontal();
                        EditorGUILayout.BeginHorizontal();
                        {
                            SerializedProperty minScale = gameObjectsProperties.GetArrayElementAtIndex(i).FindPropertyRelative("minScale");
                            SerializedProperty maxScale = gameObjectsProperties.GetArrayElementAtIndex(i).FindPropertyRelative("maxScale");
                            float minScaleValue         = minScale.floatValue;
                            float maxScaleValue         = maxScale.floatValue;
                            EditorGUILayout.LabelField("Scale", GUILayout.MaxWidth(labelWidth));
                            minScaleValue = EditorGUILayout.FloatField(minScaleValue, GUILayout.MaxWidth(46), GUILayout.MinWidth(28));
                            EditorGUILayout.MinMaxSlider(ref minScaleValue, ref maxScaleValue, 0f, 20f, GUILayout.MinWidth(0));
                            maxScaleValue       = EditorGUILayout.FloatField(maxScaleValue, GUILayout.MaxWidth(46), GUILayout.MinWidth(28));
                            minScale.floatValue = minScaleValue;
                            maxScale.floatValue = maxScaleValue;
                        }
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.BeginHorizontal();
                        {
                            SerializedProperty minSteepness = gameObjectsProperties.GetArrayElementAtIndex(i).FindPropertyRelative("minSteepness");
                            SerializedProperty maxSteepness = gameObjectsProperties.GetArrayElementAtIndex(i).FindPropertyRelative("maxSteepness");
                            float minSteepnessValue         = minSteepness.floatValue;
                            float maxSteepnessValue         = maxSteepness.floatValue;
                            EditorGUILayout.LabelField("Steepness", GUILayout.MaxWidth(labelWidth));
                            minSteepnessValue = EditorGUILayout.FloatField(minSteepnessValue, GUILayout.MaxWidth(46), GUILayout.MinWidth(28));
                            EditorGUILayout.MinMaxSlider(ref minSteepnessValue, ref maxSteepnessValue, 0f, 90f, GUILayout.MinWidth(0));
                            maxSteepnessValue       = EditorGUILayout.FloatField(maxSteepnessValue, GUILayout.MaxWidth(46), GUILayout.MinWidth(28));
                            minSteepness.floatValue = minSteepnessValue;
                            maxSteepness.floatValue = maxSteepnessValue;
                        }
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.BeginHorizontal();
                        {
                            SerializedProperty forceHorizontalPlacement = gameObjectsProperties.GetArrayElementAtIndex(i).FindPropertyRelative("forceHorizontalPlacement");
                            forceHorizontalPlacement.boolValue = EditorGUILayout.ToggleLeft("Force Horizontal", forceHorizontalPlacement.boolValue, GUILayout.MinWidth(140f));
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUILayout.EndVertical();

                    EditorGUILayout.BeginVertical();
                    {
                        guiRect = EditorGUILayout.GetControlRect(false, GUILayout.Height(100), GUILayout.Width(100));
                        if (prototype.objectReferenceValue == true)
                        {
                            Texture2D pTexture = AssetPreview.GetAssetPreview(prototype.objectReferenceValue as GameObject);
                            if (pTexture != null)
                            {
                                EditorGUI.DrawPreviewTexture(guiRect, pTexture);
                            }
                        }
                    }
                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space();

                EditorGUILayout.LabelField("Apply to Splat Textures:");
                SerializedProperty applyToSplatTexture = gameObjectsProperties.GetArrayElementAtIndex(i).FindPropertyRelative("applyToSplatTexture");
                ApplyToSplatTextures(ref applyToSplatTexture);

                EditorGUILayout.Space();

                SerializedProperty useNoiseLayer = gameObjectsProperties.GetArrayElementAtIndex(inspGameObjectSelectorIndex.intValue).FindPropertyRelative("useNoiseLayer");
                useNoiseLayer.boolValue = EditorGUILayout.ToggleLeft(new GUIContent("Use noise layer (Perlin3D)"), useNoiseLayer.boolValue);

                if (useNoiseLayer.boolValue)
                {
                    SerializedProperty noiseSettings      = gameObjectsProperties.GetArrayElementAtIndex(inspGameObjectSelectorIndex.intValue).FindPropertyRelative("noiseSettings");
                    SerializedProperty noiseSettings_type = noiseSettings.FindPropertyRelative("type");
                    noiseSettings_type.enumValueIndex = (int)NoiseGenerator.NoiseMethodType.Perlin3D;
                    //EditorGUILayout.PropertyField (noiseSettings_type, new GUIContent("Type"));

                    SerializedProperty noiseSettings_offsetX = noiseSettings.FindPropertyRelative("offsetX");
                    //EditorGUILayout.PropertyField (noiseSettings_offsetX, new GUIContent("Offset X"));
                    noiseSettings_offsetX.floatValue = 0f;

                    SerializedProperty noiseSettings_offsetY = noiseSettings.FindPropertyRelative("offsetY");
                    //EditorGUILayout.PropertyField (noiseSettings_offsetY, new GUIContent("Offset Y"));
                    EditorGUILayout.PropertyField(noiseSettings_offsetY, new GUIContent("Seed"));

                    SerializedProperty noiseSettings_offsetZ = noiseSettings.FindPropertyRelative("offsetZ");
                    //EditorGUILayout.PropertyField (noiseSettings_offsetZ, new GUIContent("Offset Z"));
                    noiseSettings_offsetZ.floatValue = 0f;

                    SerializedProperty noiseSettings_frequency = noiseSettings.FindPropertyRelative("frequency");
                    //noiseSettings_frequency.floatValue = EditorGUILayout.Slider("Frequency",noiseSettings_frequency.floatValue,0.0005f, 0.1f);
                    float scale = Mathf.RoundToInt(1f / noiseSettings_frequency.floatValue);
                    scale = EditorGUILayout.Slider(new GUIContent("Scale"), scale, 1f, 2000f);
                    noiseSettings_frequency.floatValue = 1f / scale;

                    SerializedProperty threshold = noiseSettings.FindPropertyRelative("threshold");
                    EditorGUILayout.PropertyField(threshold, new GUIContent("Threshold"));
                    SerializedProperty falloff = noiseSettings.FindPropertyRelative("falloff");
                    EditorGUILayout.PropertyField(falloff, new GUIContent("Smoothness"));

                    SerializedProperty noiseSettings_octaves = noiseSettings.FindPropertyRelative("octaves");
                    noiseSettings_octaves.intValue = 1;
                    SerializedProperty noiseSettings_lacunarity = noiseSettings.FindPropertyRelative("lacunarity");
                    noiseSettings_lacunarity.floatValue = 1;
                    SerializedProperty noiseSettings_persistence = noiseSettings.FindPropertyRelative("persistence");
                    noiseSettings_persistence.floatValue = 1;
                    //SerializedProperty noiseSettings_adjustmentCurve = noiseSettings.FindPropertyRelative("adjustmentCurve");
                    //noiseSettings_adjustmentCurve.animationCurveValue = AnimationCurve.Linear(0f, 0f, 1f, 1f);
                }

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

                _applyToSplatTexture = new bool[applyToSplatTexture.arraySize];
                for (int splatindex = 0; splatindex < applyToSplatTexture.arraySize; splatindex++)
                {
                    _applyToSplatTexture[splatindex] = applyToSplatTexture.GetArrayElementAtIndex(splatindex).boolValue;
                }
                _useNoiseLayer  = useNoiseLayer.boolValue;
                _noiseFrequency = gameObjectsProperties.GetArrayElementAtIndex(inspGameObjectSelectorIndex.intValue).FindPropertyRelative("noiseSettings").FindPropertyRelative("frequency").floatValue;
                _noiseOffsetX   = gameObjectsProperties.GetArrayElementAtIndex(inspGameObjectSelectorIndex.intValue).FindPropertyRelative("noiseSettings").FindPropertyRelative("offsetX").floatValue;
                _noiseOffsetY   = gameObjectsProperties.GetArrayElementAtIndex(inspGameObjectSelectorIndex.intValue).FindPropertyRelative("noiseSettings").FindPropertyRelative("offsetY").floatValue;
                _noiseOffsetZ   = gameObjectsProperties.GetArrayElementAtIndex(inspGameObjectSelectorIndex.intValue).FindPropertyRelative("noiseSettings").FindPropertyRelative("offsetZ").floatValue;
                _threshold      = gameObjectsProperties.GetArrayElementAtIndex(inspGameObjectSelectorIndex.intValue).FindPropertyRelative("noiseSettings").FindPropertyRelative("threshold").floatValue;
                _falloff        = gameObjectsProperties.GetArrayElementAtIndex(inspGameObjectSelectorIndex.intValue).FindPropertyRelative("noiseSettings").FindPropertyRelative("falloff").floatValue;

                DrawPreviewTexture();
            } // if (gameObjectsProperties.arraySize > 0)

            EditorGUILayout.Space();
        } //        EditorGUILayout.BeginVertical ("Box");
        EditorGUILayout.EndVertical();
    }
Example #11
0
        private void renderUiForUnitSetCustomization()
        {
            EditorGUILayout.Space();

            EditorGUILayout.BeginVertical();

            GUILayout.Label("Change Materials for each unit");

            #region Materials

            EditorGUILayout.BeginHorizontal();
            WallMaterial = EditorGUILayout.ObjectField("Wall: ", WallMaterial, typeof(Material), false) as Material;
            if (WallMaterial != null && GUILayout.Button("Apply"))
            {
                selectedMaze.ApplyToAllMazeUnits((u) =>
                {
                    int c = u.transform.childCount;
                    for (int i = 0; i < c; i++)
                    {
                        var child = u.transform.GetChild(i);

                        if (child.name.Equals("East") ||
                            child.name.Equals("West") ||
                            child.name.Equals("North") ||
                            child.name.Equals("South"))
                        {
                            var renderer      = child.gameObject.GetComponent <Renderer>();
                            renderer.material = WallMaterial;
                        }
                    }
                });
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            FloorMaterial = EditorGUILayout.ObjectField("Floor: ", FloorMaterial, typeof(Material), false) as Material;
            if (FloorMaterial != null && GUILayout.Button("Apply"))
            {
                selectedMaze.ApplyToAllMazeUnits((u) =>
                {
                    int c = u.transform.childCount;
                    for (int i = 0; i < c; i++)
                    {
                        var child = u.transform.GetChild(i);

                        if (child.name.Equals("Floor"))
                        {
                            var renderer      = child.gameObject.GetComponent <Renderer>();
                            renderer.material = FloorMaterial;
                        }
                    }
                });
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            TopMaterial = EditorGUILayout.ObjectField("Top: ", TopMaterial, typeof(Material), false) as Material;
            if (TopMaterial && GUILayout.Button("Apply"))
            {
                selectedMaze.ApplyToAllMazeUnits((u) =>
                {
                    int c = u.transform.childCount;
                    for (int i = 0; i < c; i++)
                    {
                        var child = u.transform.GetChild(i);

                        if (child.name.Equals("Top"))
                        {
                            var renderer      = child.gameObject.GetComponent <Renderer>();
                            renderer.material = TopMaterial;
                        }
                    }
                });
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Disable Floor"))
            {
                selectedMaze.ApplyToAllMazeUnits((u) =>
                {
                    var floor = u.transform.AllChildren().Where(c => c.name.Equals("Floor"));
                    foreach (var item in floor)
                    {
                        item.SetActive(false);
                    }
                });
            }

            EditorGUILayout.EndHorizontal();

            #endregion

            EditorGUILayout.LabelField("Lighting", EditorStyles.boldLabel);

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.BeginVertical();

            RenderUIForRequestedPrefab <GameObject, TopLighting>(ref lightPrefab, typeof(TopLighting));

            if (lightPrefab != null && GUILayout.Button("Add Lighting to each unit.", GUILayout.Height(50f)))
            {
                AddLightingToMaze();
            }

            if (GUILayout.Button("Remove Lighting to each unit.", GUILayout.Height(20f)))
            {
                RemoveLightingFromMaze();
            }

            if (GUILayout.Button("Remove only the Light from Top lightning.", GUILayout.Height(20f)))
            {
                RemoveTheLightFromLighting();
            }

            EditorGUILayout.EndHorizontal();

            if (lightPrefab)
            {
                var previewTexture = AssetPreview.GetAssetPreview(lightPrefab);

                GUILayout.Box(previewTexture);
            }

            EditorGUILayout.EndHorizontal();


            EditorGUILayout.EndVertical();
        }
Example #12
0
    void ListMaterials()
    {
        materialListScrollPos = EditorGUILayout.BeginScrollView(materialListScrollPos);

        foreach (MaterialDetails tDetails in ActiveMaterials)
        {
            if (tDetails.material != null)
            {
                GUILayout.BeginHorizontal();

                GUILayout.Box(AssetPreview.GetAssetPreview(tDetails.material), GUILayout.Width(ThumbnailWidth), GUILayout.Height(ThumbnailHeight));

                if (tDetails.instance == true)
                {
                    GUI.color = new Color(0.8f, 0.8f, defColor.b, 1.0f);
                }
                if (tDetails.isgui == true)
                {
                    GUI.color = new Color(defColor.r, 0.95f, 0.8f, 1.0f);
                }
                if (tDetails.isSky)
                {
                    GUI.color = new Color(0.9f, defColor.g, defColor.b, 1.0f);
                }
                if (GUILayout.Button(tDetails.material.name, GUILayout.Width(150)))
                {
                    SelectObject(tDetails.material, ctrlPressed);
                }
                GUI.color = defColor;

                string shaderLabel = tDetails.material.shader != null ? tDetails.material.shader.name : "no shader";
                GUILayout.Label(shaderLabel, GUILayout.Width(200));

                if (GUILayout.Button((tDetails.FoundInRenderers.Count + tDetails.FoundInGraphics.Count) + " GO", GUILayout.Width(50)))
                {
                    List <Object> FoundObjects = new List <Object>();
                    foreach (Renderer renderer in tDetails.FoundInRenderers)
                    {
                        FoundObjects.Add(renderer.gameObject);
                    }
                    foreach (Graphic graphic in tDetails.FoundInGraphics)
                    {
                        FoundObjects.Add(graphic.gameObject);
                    }
                    SelectObjects(FoundObjects, ctrlPressed);
                }

                var queue = tDetails.material.renderQueue;
                EditorGUI.BeginChangeCheck();
                queue = EditorGUILayout.DelayedIntField(queue, GUILayout.Width(35));
                if (EditorGUI.EndChangeCheck())
                {
                    tDetails.material.renderQueue = queue;
                    ActiveMaterials.Sort(MaterialSorter);
                    GUIUtility.ExitGUI();
                    break;
                }

                GUILayout.EndHorizontal();
            }
        }
        EditorGUILayout.EndScrollView();
    }
Example #13
0
        ///Get icon for type
        public static Texture GetTypeIcon(MemberInfo info, bool fallbackToDefault = true)
        {
            //SL--
            //if (!EditorGUIUtility.isProSkin){ return null; }
            if (info == null)
            {
                return(null);
            }
            var type = info is Type ? info as Type : info.ReflectedType;

            if (type == null)
            {
                return(null);
            }

            Texture texture = null;

            if (typeIcons.TryGetValue(type.FullName, out texture))
            {
                if (texture != null)
                {
                    if (texture.name != DEFAULT_TYPE_ICON_NAME || fallbackToDefault)
                    {
                        return(texture);
                    }
                }
                return(null);
            }

            if (texture == null)
            {
                if (type.IsEnumerableCollection())
                {
                    var elementType = type.GetEnumerableElementType();
                    if (elementType != null)
                    {
                        texture = GetTypeIcon(elementType);
                    }
                }
            }

            if (typeof(UnityEngine.Object).IsAssignableFrom(type))
            {
                texture = AssetPreview.GetMiniTypeThumbnail(type);
                if (texture == null && (typeof(MonoBehaviour).IsAssignableFrom(type) || typeof(ScriptableObject).IsAssignableFrom(type)))
                {
                    texture = EditorGUIUtility.ObjectContent(EditorUtils.MonoScriptFromType(type), null).image;
                    if (texture == null)
                    {
                        texture = Icons.csIcon;
                    }
                }
            }

            if (texture == null)
            {
                texture = Resources.Load <Texture>(IMPLICIT_ICONS_PATH + type.FullName);
            }

            ///Explicit icons not in dark theme
            if (EditorGUIUtility.isProSkin)
            {
                if (texture == null)
                {
                    var iconAtt = type.RTGetAttribute <IconAttribute>(true);
                    if (iconAtt != null)
                    {
                        texture = GetTypeIcon(iconAtt, null);
                    }
                }
            }

            if (texture == null)
            {
                var current = type.BaseType;
                while (current != null)
                {
                    texture = Resources.Load <Texture>(IMPLICIT_ICONS_PATH + current.FullName);
                    current = current.BaseType;
                    if (texture != null)
                    {
                        break;
                    }
                }
            }

            if (texture == null)
            {
                texture = Resources.Load <Texture>(IMPLICIT_ICONS_PATH + DEFAULT_TYPE_ICON_NAME);
            }

            typeIcons[type.FullName] = texture;

            if (texture != null)
            { //it should not be
                if (texture.name != DEFAULT_TYPE_ICON_NAME || fallbackToDefault)
                {
                    return(texture);
                }
            }
            return(null);
        }
Example #14
0
        public static void AddToUnityPackage(string pathToFileOrDirectory, string targetDir, ref Dictionary <string, string> guidToFile)
        {
            if (!File.Exists(pathToFileOrDirectory) && !Directory.Exists(pathToFileOrDirectory))
            {
                Debug.LogError("File " + pathToFileOrDirectory + " does not exist");
                return;
            }
            if (Directory.Exists(targetDir))
            {
                Directory.CreateDirectory(targetDir);
            }

            if (guidToFile.ContainsValue(pathToFileOrDirectory))
            {
                throw new ArgumentException($"Duplicate Path exported! {pathToFileOrDirectory}");
            }

            var isFile = File.Exists(pathToFileOrDirectory);

            if (pathToFileOrDirectory.EndsWith(".meta", StringComparison.Ordinal))
            {
                return;
            }
            var metaPath    = pathToFileOrDirectory + ".meta";
            var guid        = default(string);
            var hasMetaFile = File.Exists(metaPath);

            if (hasMetaFile)
            {
                using (var reader = new StreamReader(metaPath))
                {
                    var line = reader.ReadLine();
                    while (line != null)
                    {
                        if (line.StartsWith("guid:", StringComparison.Ordinal))
                        {
                            guid = line.Substring("guid:".Length).Trim();
                            if (guidToFile.ContainsKey(guid))
                            {
                                throw new ArgumentException($"Duplicate GUID in AssetDatabase ({guid})?! Existing: {guidToFile[guid]}, new: {pathToFileOrDirectory}");
                            }
                            guidToFile.Add(guid, pathToFileOrDirectory);
                            break;
                        }
                        line = reader.ReadLine();
                    }
                }
            }
            else
            {
                if (File.Exists(pathToFileOrDirectory))
                {
                    var bytes = File.ReadAllBytes(pathToFileOrDirectory);
                    using (var md5 = MD5.Create()) {
                        md5.TransformFinalBlock(bytes, 0, bytes.Length);
                        var hash = md5.Hash;
                        // guid = BitConverter.ToString(hash).Replace("-","");//(md5.Hash);

                        guid = new Guid(hash).ToString("N");
                        int maxTries = 200;
                        while (guidToFile.ContainsKey(guid))
                        {
                            Debug.LogWarning($"GUID collision ({guid}), Existing: {guidToFile[guid]}, new: {pathToFileOrDirectory}");
                            hash[0]++;
                            guid = new Guid(hash).ToString("N");
                            maxTries--;
                            if (maxTries < 0)
                            {
                                throw new ArgumentException($"GUID collision on file: {pathToFileOrDirectory} with GUID {guid} even after 200 attempts of finding a new one. Aborting.");
                            }
                        }
                        guidToFile.Add(guid, pathToFileOrDirectory);
                    }
                }
            }

            if (guid == null)
            {
                Debug.LogError("No guid for " + pathToFileOrDirectory);
            }
            pathToFileOrDirectory = pathToFileOrDirectory.Replace("\\", "/");
            var projectPath = Path.GetFullPath(Application.dataPath + "/../").Replace("\\", "/");
            var relPath     = pathToFileOrDirectory;

            if (relPath.StartsWith(projectPath, StringComparison.Ordinal))
            {
                relPath = relPath.Substring(projectPath.Length);
            }

            var outDir = targetDir + "/" + guid;

            if (!Directory.Exists(outDir))
            {
                Directory.CreateDirectory(outDir);
            }
            var pathNameFilePath = outDir + "/pathname";

            if (File.Exists(pathNameFilePath))
            {
                File.Delete(pathNameFilePath);
            }
            File.WriteAllText(pathNameFilePath, relPath);
            if (isFile)
            {
                File.Copy(pathToFileOrDirectory, outDir + "/asset", true);
            }
            if (hasMetaFile)
            {
                File.Copy(metaPath, outDir + "/asset.meta", true);
            }

            if (IncludePreviewImages && isFile && !extensionsWithoutThumbnails.Contains(Path.GetExtension(pathToFileOrDirectory).ToLowerInvariant()))
            {
#if UNITY_2020_1_OR_NEWER
                var preview = AssetPreview.GetAssetPreviewFromGUID(guid);
#else
                var assetPath = AssetDatabase.GUIDToAssetPath(guid);
                var asset     = string.IsNullOrEmpty(assetPath) ? null : AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(assetPath);
                var preview   = asset ? AssetPreview.GetAssetPreview(asset) : default;
#endif
                if (preview)
                {
                    var thumbnailWidth  = Mathf.Min(preview.width, 128);
                    var thumbnailHeight = Mathf.Min(preview.height, 128);
                    var rt = RenderTexture.GetTemporary(thumbnailWidth, thumbnailHeight, 0, RenderTextureFormat.Default, RenderTextureReadWrite.sRGB);

                    var copy = new Texture2D(rt.width, rt.height, TextureFormat.ARGB32, false);//, preview.graphicsFormat, preview.mipmapCount, TextureCreationFlags.None);

                    RenderTexture.active = rt;
                    GL.Clear(true, true, new Color(0, 0, 0, 0));
                    Graphics.Blit(preview, rt);
                    copy.ReadPixels(new Rect(0, 0, copy.width, copy.height), 0, 0, false);
                    copy.Apply();
                    RenderTexture.active = null;

                    var bytes = copy.EncodeToPNG();
                    if (bytes != null && bytes.Length > 0)
                    {
                        File.WriteAllBytes(outDir + "/preview.png", bytes);
                    }

                    RenderTexture.ReleaseTemporary(rt);
                }
            }
        }
Example #15
0
    //public static void DrawPrefabSelectorGrid(List<GameObject> prefabList, int imageSize, ref int selectedGridIndex)
    //{
    //    GUIContent[] imageButtons = new GUIContent[prefabList.Count];

    //    for (int i = 0; i <= prefabList.Count - 1; i++)
    //    {
    //        imageButtons[i] = new GUIContent
    //        {
    //            image = AssetPreviewCache.GetAssetPreview(prefabList[i])
    //        };


    //    }
    //    int imageWidth = imageSize;
    //    int columns = Mathf.FloorToInt((EditorGUIUtility.currentViewWidth - 50) / imageWidth);
    //    int rows = Mathf.CeilToInt((float)imageButtons.Length / columns);
    //    int gridHeight = (rows) * imageWidth;

    //    if (imageButtons.Length > 0)
    //    {
    //        selectedGridIndex = GUILayout.SelectionGrid(selectedGridIndex, imageButtons, columns, GUILayout.MaxWidth(columns * imageWidth), GUILayout.MaxHeight(gridHeight));
    //    }
    //}

    //public static void DrawTextureSelectorGrid(List<Texture2D> textureList, int imageSize, ref int selectedGridIndex)
    //{


    //    GUIContent[] imageButtons = new GUIContent[textureList.Count];

    //    for (int i = 0; i <= textureList.Count - 1; i++)
    //    {
    //        imageButtons[i] = new GUIContent
    //        {
    //            image = AssetPreviewCache.GetAssetPreview(textureList[i])
    //        };
    //    }
    //    int imageWidth = imageSize;
    //    int columns = Mathf.FloorToInt((EditorGUIUtility.currentViewWidth - 50) / imageWidth);
    //    int rows = Mathf.CeilToInt((float)imageButtons.Length / columns);
    //    int gridHeight = (rows) * imageWidth;

    //    if (imageButtons.Length > 0)
    //    {
    //        selectedGridIndex = GUILayout.SelectionGrid(selectedGridIndex, imageButtons, columns, GUILayout.MaxWidth(columns * imageWidth), GUILayout.MaxHeight(gridHeight));
    //    }
    //}

    public static void DrawVegetationItemSelector(VegetationPackagePro vegetationPackage, List <string> vegetationInfoIdList, int imageSize, ref string selectedVegetationItemId)
    {
        AssetPreview.SetPreviewTextureCacheSize(100 + vegetationPackage.VegetationInfoList.Count);

        VegetationInfoIDComparer vIc = new VegetationInfoIDComparer
        {
            VegetationInfoList = vegetationPackage.VegetationInfoList
        };

        vegetationInfoIdList.Sort(vIc.Compare);

        GUIContent[] imageButtons = new GUIContent[vegetationInfoIdList.Count];

        for (int i = 0; i <= vegetationInfoIdList.Count - 1; i++)
        {
            VegetationItemInfoPro vegetationItemInfo = vegetationPackage.GetVegetationInfo(vegetationInfoIdList[i]);
            if (vegetationItemInfo == null)
            {
                imageButtons[i] = new GUIContent
                {
                    image = AssetPreviewCache.GetAssetPreview(null)
                };
            }
            else
            {
                if (vegetationItemInfo.PrefabType == VegetationPrefabType.Mesh)
                {
                    imageButtons[i] = new GUIContent
                    {
                        image = AssetPreviewCache.GetAssetPreview(vegetationItemInfo.VegetationPrefab)
                    };
                }
                else
                {
                    imageButtons[i] = new GUIContent
                    {
                        image = AssetPreviewCache.GetAssetPreview(vegetationItemInfo.VegetationTexture)
                    };
                }
            }
        }
        int imageWidth = imageSize;
        int columns    = Mathf.FloorToInt((EditorGUIUtility.currentViewWidth - imageWidth / 2f) / imageWidth);
        int rows       = Mathf.CeilToInt((float)imageButtons.Length / columns);
        int gridHeight = (rows) * imageWidth;


        int selectedGridIndex = vegetationInfoIdList.IndexOf(selectedVegetationItemId);

        if (selectedGridIndex < 0)
        {
            selectedGridIndex = 0;
        }

        if (imageButtons.Length > 0)
        {
            selectedGridIndex = GUILayout.SelectionGrid(selectedGridIndex, imageButtons, columns, GUILayout.MaxWidth(columns * imageWidth), GUILayout.MaxHeight(gridHeight));
        }

        selectedVegetationItemId = vegetationInfoIdList.Count > selectedGridIndex ? vegetationInfoIdList[selectedGridIndex] : "";
        DrawSelectedName(selectedVegetationItemId, vegetationPackage);
    }
Example #16
0
        private static void OnSceneGUI(SceneView sceneView)
        {
            Event e = Event.current;

            if (e.type == EventType.Used || !e.control || !e.isMouse || e.button != 1 || e.shift || e.alt)
            {
                return;
            }

            switch (e.rawType)
            {
            case EventType.MouseDown:
                _mouseRightIsDownWithoutDrag = true;
                break;

            case EventType.MouseDrag:
                _mouseRightIsDownWithoutDrag = false;
                break;
            }

            //The actual CTRL+RIGHT-MOUSE functionality
            if (!_mouseRightIsDownWithoutDrag || e.rawType != EventType.MouseUp)
            {
                return;
            }

            IEnumerable <GameObject> allOverlapping = GetAllOverlapping(e.mousePosition);
            List <SelectionItem>     totalSelection = SelectionPopup.TotalSelection;

            totalSelection.Clear();
            foreach (GameObject overlapping in allOverlapping)
            {
                //Check whether the parents of a rect transform have a disabled canvas in them.
                if (overlapping.transform is RectTransform rectTransform)
                {
                    var canvas = rectTransform.GetComponentInParent <Canvas>();
                    if (canvas != null)
                    {
                        if (!canvas.enabled)
                        {
                            continue;
                        }
                        bool canvasInParentsEnabled = true;
                        while (canvas != null)
                        {
                            Transform parent = canvas.transform.parent;
                            if (parent != null)
                            {
                                canvas = parent.GetComponentInParent <Canvas>();
                                if (canvas == null || canvas.enabled)
                                {
                                    continue;
                                }
                                canvasInParentsEnabled = false;
                            }

                            break;
                        }

                        if (!canvasInParentsEnabled)
                        {
                            continue;
                        }
                    }
                }

                Component[]  components = overlapping.GetComponents <Component>();
                GUIContent[] icons      = new GUIContent[components.Length - 1];
                for (var i = 1; i < components.Length; i++)
                {
                    if (components[i] == null)
                    {
                        icons[i - 1] = GUIContent.none;
                        continue;
                    }

                    //Skip the Transform component because it's always the first object
                    icons[i - 1] = new GUIContent(AssetPreview.GetMiniThumbnail(components[i]),
                                                  ObjectNames.NicifyVariableName(components[i].GetType().Name));
                }

                totalSelection.Add(new SelectionItem(overlapping, icons));
            }

            if (totalSelection.Count == 0)
            {
                return;
            }

            Vector2 selectionPosition = e.mousePosition;
            float   xOffset;

            // Screen-rect limits offset.
            if (selectionPosition.x + SelectionPopup.Width > sceneView.position.width)
            {
                xOffset = -SelectionPopup.Width;
            }
            else
            {
                xOffset = 0;
            }
            int value = Mathf.CeilToInt((selectionPosition.y + SelectionPopup.Height * totalSelection.Count -
                                         sceneView.position.height + 10) / SelectionPopup.Height);

            SelectionPopup.ScrollPosition = Mathf.Max(0, value);

            // Display popup.
            var buttonRect = new Rect(
                e.mousePosition.x + xOffset - 1,
                e.mousePosition.y - 6,
                0, 0
                );

            e.alt = false;
            _mouseRightIsDownWithoutDrag = false;
            e.Use();

            PopupWindow.Show(buttonRect, new SelectionPopup());

            // No events after Show. ExitGUI is called.
        }
Example #17
0
    public static void DrawVegetationItemSelector(VegetationSystemPro vegetationSystemPro, VegetationPackagePro vegetationPackage, ref int selectedGridIndex, ref int vegIndex, ref int selectionCount, VegetationItemTypeSelection vegetationItemTypeSelection, int imageSize)
    {
        if (vegetationPackage == null)
        {
            return;
        }
        //AssetPreview.SetPreviewTextureCacheSize(100 + vegetationPackage.VegetationInfoList.Count);
        AssetPreview.SetPreviewTextureCacheSize(100 + vegetationSystemPro.GetMaxVegetationPackageItemCount());

        List <int> vegetationItemIndexList = new List <int>();

        for (int i = 0;
             i <= vegetationPackage.VegetationInfoList.Count - 1;
             i++)
        {
            VegetationItemInfoPro vegetationItemInfo = vegetationPackage.VegetationInfoList[i];
            switch (vegetationItemTypeSelection)
            {
            case VegetationItemTypeSelection.AllVegetationItems:
                vegetationItemIndexList.Add(i);
                break;

            case VegetationItemTypeSelection.LargeItems:

                if (vegetationItemInfo.VegetationType == VegetationType.Objects ||
                    vegetationItemInfo.VegetationType == VegetationType.LargeObjects ||
                    vegetationItemInfo.VegetationType == VegetationType.Tree)
                {
                    vegetationItemIndexList.Add(i);
                }
                break;

            case VegetationItemTypeSelection.Grass:
                if (vegetationItemInfo.VegetationType == VegetationType.Grass)
                {
                    vegetationItemIndexList.Add(i);
                }
                break;

            case VegetationItemTypeSelection.Plants:
                if (vegetationItemInfo.VegetationType == VegetationType.Plant)
                {
                    vegetationItemIndexList.Add(i);
                }
                break;

            case VegetationItemTypeSelection.Trees:
                if (vegetationItemInfo.VegetationType == VegetationType.Tree)
                {
                    vegetationItemIndexList.Add(i);
                }
                break;

            case VegetationItemTypeSelection.Objects:
                if (vegetationItemInfo.VegetationType == VegetationType.Objects)
                {
                    vegetationItemIndexList.Add(i);
                }
                break;

            case VegetationItemTypeSelection.LargeObjects:
                if (vegetationItemInfo.VegetationType == VegetationType.LargeObjects)
                {
                    vegetationItemIndexList.Add(i);
                }
                break;
            }
        }

        selectionCount = vegetationItemIndexList.Count;

        VegetationInfoComparer vIc = new VegetationInfoComparer
        {
            VegetationInfoList = vegetationPackage.VegetationInfoList
        };

        vegetationItemIndexList.Sort(vIc.Compare);

        GUIContent[] imageButtons = new GUIContent[vegetationItemIndexList.Count];

        for (int i = 0; i <= vegetationItemIndexList.Count - 1; i++)
        {
            if (vegetationPackage.VegetationInfoList[vegetationItemIndexList[i]].PrefabType == VegetationPrefabType.Mesh)
            {
                imageButtons[i] = new GUIContent
                {
                    image = AssetPreviewCache.GetAssetPreview(vegetationPackage.VegetationInfoList[vegetationItemIndexList[i]].VegetationPrefab)
                };
            }
            else
            {
                imageButtons[i] = new GUIContent
                {
                    image = AssetPreviewCache.GetAssetPreview(vegetationPackage.VegetationInfoList[vegetationItemIndexList[i]].VegetationTexture)
                };
            }
        }
        int imageWidth = imageSize;
        int columns    = Mathf.FloorToInt((EditorGUIUtility.currentViewWidth - 50) / imageWidth);
        int rows       = Mathf.CeilToInt((float)imageButtons.Length / columns);
        int gridHeight = (rows) * imageWidth;


        if (selectedGridIndex > imageButtons.Length - 1)
        {
            selectedGridIndex = 0;
        }
        if (imageButtons.Length > 0)
        {
            selectedGridIndex = GUILayout.SelectionGrid(selectedGridIndex, imageButtons, columns, GUILayout.MaxWidth(columns * imageWidth), GUILayout.MaxHeight(gridHeight));
        }

        vegIndex = vegetationItemIndexList.Count > selectedGridIndex ? vegetationItemIndexList[selectedGridIndex] : 0;
    }
        public void Step2()
        {
            EditorGUILayout.BeginVertical();
            EditorGUILayout.LabelField("Selected type: " + firstStepType.Name, (GUIStyle)"BoldLabel");


            var style = new GUIStyle(EditorStyles.boxStyle);

            style.alignment = TextAnchor.MiddleCenter;

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Cube (Default)", GUILayout.ExpandWidth(true), GUILayout.Height(30)) || step2Model == null)
            {
                // Use a box
                step2Model = GameObject.CreatePrimitive(PrimitiveType.Cube);
            }
            if (GUILayout.Button("None (Be warned...)", GUILayout.ExpandWidth(true), GUILayout.Height(30)))
            {
                step2Model = new GameObject("__Empty");
            }
            EditorGUILayout.EndHorizontal();
            if (GUILayout.Button("2D sprite with trigger", GUILayout.ExpandWidth(true), GUILayout.Height(30)))
            {
                // Use a box
                step2Model = new GameObject("2D Sprite");
                step2Model.GetOrAddComponent <SpriteRenderer>();
                var col = step2Model.GetOrAddComponent <BoxCollider2D>();
                col.isTrigger = true;
            }



            ShowOr();


            EditorGUILayout.BeginVertical();
            var boxStyle = new GUIStyle("HelpBox");

            boxStyle.stretchWidth = true;
            boxStyle.fixedHeight  = 200;
            boxStyle.alignment    = TextAnchor.MiddleCenter;
            var rect = GUILayoutUtility.GetRect(390, 390, 200, 200);

            rect.x    += 5;
            rect.width = 390;


            #region Accepting drag for box

            switch (Event.current.type)
            {
            case EventType.DragUpdated:
            case EventType.DragPerform:
                if (rect.Contains(Event.current.mousePosition) == false)
                {
                    break;
                }

                DragAndDrop.visualMode = DragAndDropVisualMode.Link;

                if (Event.current.type == EventType.DragPerform)
                {
                    if (DragAndDrop.objectReferences.Length == 1)
                    {
                        step2Model = DragAndDrop.objectReferences[0] as GameObject;
                        var sprite = DragAndDrop.objectReferences[0] as Sprite;

                        if (step2Model != null)
                        {
                            DragAndDrop.AcceptDrag();
                        }
                        else
                        {
                            if (sprite != null)
                            {
                                DragAndDrop.AcceptDrag();

                                step2Model = new GameObject("2D Sprite");
                                var spr = step2Model.GetOrAddComponent <SpriteRenderer>();
                                spr.sprite = sprite;

                                var col = step2Model.GetOrAddComponent <BoxCollider2D>();
                                col.isTrigger = true;
                            }
                        }
                    }
                }
                break;
            }

            #endregion


            if (step2Model == null)
            {
                GUI.Box(rect, "Drag object here", boxStyle);
            }
            else
            {
                var rect2 = rect;
                rect2.width /= 2;

                Texture2D preview = AssetPreview.GetAssetPreview(step2Model);
                if (preview != null)
                {
                    EditorGUI.DrawPreviewTexture(rect2, preview);

                    rect.width -= rect2.width;
                    rect.x     += rect2.width;
                }

                GUI.Box(rect, step2Model.name, boxStyle);
            }
            GUI.color = Color.white;


            ShowOr();


            if (Event.current.commandName == "ObjectSelectorUpdated")
            {
                if (EditorGUIUtility.GetObjectPickerControlID() == 123)
                {
                    step2Model = (GameObject)EditorGUIUtility.GetObjectPickerObject();
                    forceFocus = true;
                }
            }
            if (Event.current.commandName == "ObjectSelectorUpdated")
            {
                if (EditorGUIUtility.GetObjectPickerControlID() == 124)
                {
                    var sprite = (Sprite)EditorGUIUtility.GetObjectPickerObject();

                    step2Model = new GameObject("2D Sprite");
                    var spr = step2Model.GetOrAddComponent <SpriteRenderer>();
                    spr.sprite = sprite;

                    var col = step2Model.GetOrAddComponent <BoxCollider2D>();
                    col.isTrigger = true;

                    forceFocus = true;
                }
            }
            if (GUILayout.Button("Select model", GUILayout.ExpandWidth(true), GUILayout.Height(30)))
            {
                EditorGUIUtility.ShowObjectPicker <GameObject>(step2Model, false, "", 123);
                forceFocus = false;
            }
            if (GUILayout.Button("Select sprite", GUILayout.ExpandWidth(true), GUILayout.Height(30)))
            {
                EditorGUIUtility.ShowObjectPicker <Sprite>(step2Model, false, "", 124);
                forceFocus = false;
            }
            EditorGUILayout.EndVertical();

            if (step2Model == null)
            {
                GUI.enabled = false;
            }

            GUI.color = Color.green;
            if (GUILayout.Button("Create item", (GUIStyle)"LargeButton"))
            {
                if (step2Model != null)
                {
                    CreateItem(firstStepType, step2Model);
                }
            }
            GUI.color   = Color.white;
            GUI.enabled = true;

            EditorGUILayout.EndVertical();
        }
Example #19
0
        public override void OnPaintInspectorGUI()
        {
            if (m_GridTileBrush.pickedTile)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Currently Picked Tiles (Pick Tool)", EditorStyles.boldLabel);
                if (GUILayout.Button("Unpick Tiles"))
                {
                    m_GridTileBrush.ResetPick();
                    return;
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space(7.5f);

                int rowLength = 1;
                int maxRowLength = m_GridTileBrush.size.x;
                var previewSize = Mathf.Min(((Screen.width - 35) / maxRowLength), 100);

                _scrollViewScrollPosition = EditorGUILayout.BeginScrollView(_scrollViewScrollPosition, false, false);

                if (maxRowLength < 1)
                {
                    maxRowLength = 1;
                }

                foreach (TilePaletteGridTileBrush.BrushCell tileBrush in m_GridTileBrush.cells)
                {
                    //check if row is longer than max row length
                    if (rowLength > maxRowLength)
                    {
                        rowLength = 1;
                        EditorGUILayout.EndHorizontal();
                    }
                    //begin row if rowLength == 1
                    if (rowLength == 1)
                    {
                        EditorGUILayout.BeginHorizontal();
                    }

                    GUIContent btnContent = tileBrush != null && tileBrush.gridTile != null ?
                    new GUIContent(AssetPreview.GetAssetPreview(tileBrush.gridTile.gameObject), tileBrush.gridTile.gameObject.name) :
                    new GUIContent("", "There is no tile at this position.");
                    if (GUILayout.Button(btnContent, GUILayout.Width(previewSize), GUILayout.Height(previewSize)))
                    {

                    }
                    rowLength++;
                }

                //check if row is longer than max row length
                if (rowLength > maxRowLength)
                {
                    rowLength = 1;
                    EditorGUILayout.EndHorizontal();
                }
                if (rowLength == 1)
                {
                    EditorGUILayout.BeginHorizontal();
                }

                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndScrollView();
            }
            else
            { // If there is no tile picked show the collections GUI
                #region GridTile Collection
                SerializedObject serializedObject_brushObject = null;
                int prevSelectedGridTileCollectionIndex = m_SelectedGridTileCollectionIndex;
                if (m_Collection != null)
                {
                    serializedObject_brushObject = new SerializedObject(m_Collection);
                }

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Active GridTile Collection:");
                GridTileCollection.GridTileCollectionList gridTileCollectionList = GridTileCollection.GetBrushCollectionsInProject();
                m_SelectedGridTileCollectionIndex = EditorGUILayout.Popup(m_SelectedGridTileCollectionIndex, gridTileCollectionList.GetNameList());
                if (prevSelectedGridTileCollectionIndex != m_SelectedGridTileCollectionIndex || m_Collection == null) //select only when brush collection changed or is null
                {
                    m_Collection = gridTileCollectionList.brushCollections[m_SelectedGridTileCollectionIndex];
                    m_Collection.SetLastUsedGridTileCollection();
                    m_GridTileBrush.ClearCellFromEditor();
                    var tileBrush = m_Collection.m_SelectedGridTileBrush;
                    if (tileBrush != null)
                    {
                        m_GridTileBrush.SetCellFromEditor(Vector3Int.zero, tileBrush.m_GridTile, tileBrush.m_Height, tileBrush.m_Offset, Quaternion.Euler(tileBrush.m_Rotation));
                    }
                }

                if (GUILayout.Button("+"))
                {
                    Debug.Log("Create a new collection");
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.Space(7.5f);
                int rowLength = 1;
                int maxRowLength = Mathf.FloorToInt((Screen.width - 15) / 100);
                int columns = Mathf.CeilToInt((m_Collection.m_GridTileBrushes.Count / maxRowLength)) * 3;
                _scrollViewScrollPosition = EditorGUILayout.BeginScrollView(_scrollViewScrollPosition, false, false);

                if (maxRowLength < 1)
                {
                    maxRowLength = 1;
                }

                foreach (GridTileBrush tileBrush in m_Collection.m_GridTileBrushes)
                {
                    //check if brushObject is null, if so skip this brush
                    if (tileBrush == null || tileBrush.m_GridTile == null)
                    {
                        continue;
                    }

                    //check if row is longer than max row length
                    if (rowLength > maxRowLength)
                    {
                        rowLength = 1;
                        EditorGUILayout.EndHorizontal();
                    }
                    //begin row if rowLength == 1
                    if (rowLength == 1)
                    {
                        EditorGUILayout.BeginHorizontal();
                    }

                    //change color
                    Color guiColor = GUI.backgroundColor;
                    if (m_Collection.m_SelectedGridTileBrush != null && m_Collection.m_SelectedGridTileBrush.m_GridTile != null && m_Collection.m_SelectedGridTileBrush.m_GridTile == tileBrush.m_GridTile)
                    {
                        GUI.backgroundColor = PrimarySelectedColor;
                        if (m_GridTileBrush.editorCell != null && m_GridTileBrush.editorCell.gridTile != tileBrush.m_GridTile)
                        {
                            m_GridTileBrush.SetCellFromEditor(Vector3Int.zero, tileBrush.m_GridTile, tileBrush.m_Height, tileBrush.m_Offset, Quaternion.Euler(tileBrush.m_Rotation));
                        }
                    }

                    //Create the brush entry in the scroll view and check if the user clicked on the created button (change the currently selected/edited brush accordingly and add it to the current brushes if possible)
                    GUIContent btnContent = new GUIContent(AssetPreview.GetAssetPreview(tileBrush.m_GridTile.gameObject), tileBrush.m_GridTile.gameObject.name);
                    if (GUILayout.Button(btnContent, GUILayout.Width(100), GUILayout.Height(100)))
                    {
                        //select the currently edited brush and deselect all selected brushes
                        if (m_Collection.m_SelectedGridTileBrush != tileBrush)
                        {

                            m_Collection.m_SelectedGridTileBrushIndex = m_Collection.m_GridTileBrushes.IndexOf(tileBrush);
                            m_GridTileBrush.SetCellFromEditor(Vector3Int.zero, tileBrush.m_GridTile, tileBrush.m_Height, tileBrush.m_Offset, Quaternion.Euler(tileBrush.m_Rotation));
                        }
                        else
                        {
                            m_Collection.m_SelectedGridTileBrushIndex = -1;
                            m_GridTileBrush.ClearCellFromEditor();
                        }
                    }
                    GUI.backgroundColor = guiColor;
                    rowLength++;
                }

                //check if row is longer than max row length
                if (rowLength > maxRowLength)
                {
                    rowLength = 1;
                    EditorGUILayout.EndHorizontal();
                }
                if (rowLength == 1)
                {
                    EditorGUILayout.BeginHorizontal();
                }
                //add button
                if (GUILayout.Button(new GUIContent("+", "Add a GridTile to the collection."), GUILayout.Width(100), GUILayout.Height(100)))
                {
                    AddGridTileBrushPopup.Initialize(m_Collection.m_GridTileBrushes);
                }
                Color guiBGColor = GUI.backgroundColor;
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndScrollView();

                EditorGUILayout.BeginHorizontal();
                GUI.backgroundColor = green;
                if (GUILayout.Button(new GUIContent("Add GridTile", "Add a GridTile to the collection.")))
                {
                    AddGridTileBrushPopup.Initialize(m_Collection.m_GridTileBrushes);
                }
                EditorGUI.BeginDisabledGroup(m_Collection.m_SelectedGridTileBrush == null || m_Collection.m_SelectedGridTileBrush.m_GridTile == null);
                GUI.backgroundColor = red;
                //remove selected brushes button
                if (GUILayout.Button(new GUIContent("Remove Selected Tile", "Removes the selected gridtile from the collection.")))
                {
                    if (m_Collection.m_SelectedGridTileBrush != null)
                    {
                        m_Collection.RemoveTile(m_Collection.m_SelectedGridTileBrush);
                        m_Collection.m_SelectedGridTileBrushIndex = -1;
                        m_Collection.Save();
                    }
                }
                EditorGUI.EndDisabledGroup();
                //remove all brushes button
                EditorGUI.BeginDisabledGroup(m_Collection.m_GridTileBrushes.Count == 0);
                if (GUILayout.Button(new GUIContent("Remove All Tiles", "Removes all tiles from the collection.")) && RemoveAllBrushes_Dialog(m_Collection.m_GridTileBrushes.Count))
                {
                    m_Collection.RemoveAllTiles();
                    m_Collection.Save();
                }
                EditorGUI.EndDisabledGroup();

                EditorGUILayout.EndHorizontal();
                GUI.backgroundColor = guiBGColor;

                if (m_Collection.m_GridTileBrushes != null && m_Collection.m_GridTileBrushes.Count > 0 && m_Collection.m_SelectedGridTileBrush != null && m_Collection.m_SelectedGridTileBrush.m_GridTile != null)
                {
                    EditorGUILayout.Space(10f);
                    EditorGUILayout.BeginHorizontal();
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.LabelField("Tile Settings:" + "  (" + m_Collection.m_SelectedGridTileBrush.m_GridTile.gameObject.name + ")", EditorStyles.boldLabel);
                    if (GUILayout.Button(new GUIContent("Reset Settings", "Restores the settings for the current GridTile."), GUILayout.MaxWidth(120)))
                    {
                        m_Collection.m_SelectedGridTileBrush.ResetParameters();
                    }
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.Space(5f);
                    EditorGUILayout.BeginHorizontal();
                    m_Collection.m_SelectedGridTileBrush.m_Height = EditorGUILayout.IntField(new GUIContent("Height in Grid", "Changes the height parameter of the tile."), m_Collection.m_SelectedGridTileBrush.m_Height);
                    if (GUILayout.Button(new GUIContent("Reset Height", "Restores the tile height to 0."), GUILayout.MaxWidth(230)))
                    {
                        m_Collection.m_SelectedGridTileBrush.m_Height = 0;
                    }
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();
                    m_Collection.m_SelectedGridTileBrush.m_Offset = EditorGUILayout.Vector3Field(new GUIContent("Position Offsets", "Changes the position offset from the Cell center."), m_Collection.m_SelectedGridTileBrush.m_Offset);
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();
                    m_Collection.m_SelectedGridTileBrush.m_Rotation = EditorGUILayout.Vector3Field(new GUIContent("Rotation Offset", "Changes the rotation offset from the current orientation."), m_Collection.m_SelectedGridTileBrush.m_Rotation);
                    EditorGUILayout.EndHorizontal();
                    if (EditorGUI.EndChangeCheck())
                    {
                        // Update the cell's settings
                        m_GridTileBrush.SetCellFromEditor(Vector3Int.zero, m_Collection.m_SelectedGridTileBrush.m_GridTile, m_Collection.m_SelectedGridTileBrush.m_Height, m_Collection.m_SelectedGridTileBrush.m_Offset, Quaternion.Euler(m_Collection.m_SelectedGridTileBrush.m_Rotation));
                    }
                }
                EditorGUILayout.Space(10f);
                /*
                if (GUI.changed && m_Collection != null)
                {
                    m_Collection.Save();
                }
                */
                #endregion
            }
        }
Example #20
0
        public InSceneDependencyFinder(Object target, string scenePath)
        {
            Target     = new SearchTarget(target, FindModeEnum.Scene, scenePath);
            _scenePath = scenePath;
            Title      = scenePath;

            var name = target is Component?target.GetType().Name : target.name;

            TabContent = new GUIContent
            {
                text  = name,
                image = AssetPreview.GetMiniTypeThumbnail(Target.Target.GetType()) ?? AssetPreview.GetMiniThumbnail(Target.Target)
            };

            FindDependencies();
        }
Example #21
0
        public SceneProvider(string providerId, string filterId, string displayName)
            : base(providerId, displayName)
        {
            priority         = 50;
            this.filterId    = filterId;
            this.showDetails = true;

            subCategories = new List <NameEntry>
            {
                new NameEntry("fuzzy", "fuzzy"),
                new NameEntry("components", "components (c:)")
            };

            isEnabledForContextualSearch = () =>
                                           QuickSearch.IsFocusedWindowTypeName("SceneView") ||
                                           QuickSearch.IsFocusedWindowTypeName("SceneHierarchyWindow");

            EditorApplication.hierarchyChanged += () => m_HierarchyChanged = true;

            onEnable = () =>
            {
                if (m_HierarchyChanged)
                {
                    m_BuildIndexEnumerator = null;
                    m_HierarchyChanged     = false;
                }
            };

            onDisable = () =>
            {
                // Only track changes that occurs when Quick Search is not active.
                m_HierarchyChanged = false;
            };

            fetchItems = (context, items, provider) => SearchItems(context, provider);

            fetchLabel = (item, context) =>
            {
                if (item.label != null)
                {
                    return(item.label);
                }

                var go = ObjectFromItem(item);
                if (!go)
                {
                    return(item.id);
                }

                var transformPath = GetTransformPath(go.transform);
                var components    = go.GetComponents <Component>();
                if (components.Length > 2 && components[1] && components[components.Length - 1])
                {
                    item.label = $"{transformPath} ({components[1].GetType().Name}..{components[components.Length-1].GetType().Name})";
                }
                else if (components.Length > 1 && components[1])
                {
                    item.label = $"{transformPath} ({components[1].GetType().Name})";
                }
                else
                {
                    item.label = $"{transformPath} ({item.id})";
                }

                long       score   = 1;
                List <int> matches = new List <int>();
                var        sq      = CleanString(context.searchQuery);
                if (FuzzySearch.FuzzyMatch(sq, CleanString(item.label), ref score, matches))
                {
                    item.label = RichTextFormatter.FormatSuggestionTitle(item.label, matches);
                }

                return(item.label);
            };

            fetchDescription = (item, context) =>
            {
                var go = ObjectFromItem(item);
                return(item.description = GetHierarchyPath(go));
            };

            fetchThumbnail = (item, context) =>
            {
                var obj = ObjectFromItem(item);
                if (obj == null)
                {
                    return(null);
                }

                return(item.thumbnail = Utils.GetThumbnailForGameObject(obj));
            };

            fetchPreview = (item, context, size, options) =>
            {
                var obj = ObjectFromItem(item);
                if (obj == null)
                {
                    return(item.thumbnail);
                }

                var assetPath = GetHierarchyAssetPath(obj, true);
                if (String.IsNullOrEmpty(assetPath))
                {
                    return(item.thumbnail);
                }
                return(AssetPreview.GetAssetPreview(obj) ?? Utils.GetAssetPreviewFromPath(assetPath, size, options));
            };

            startDrag = (item, context) =>
            {
                var obj = ObjectFromItem(item);
                if (obj != null)
                {
                    DragAndDrop.PrepareStartDrag();
                    DragAndDrop.objectReferences = new[] { obj };
                    DragAndDrop.StartDrag("Drag scene object");
                }
            };

            fetchGameObjects       = FetchGameObjects;
            buildKeywordComponents = o => null;

            trackSelection = (item, context) => PingItem(item);
        }
Example #22
0
    private void OnGUI()
    {
        ReloadComboBox();
        if (firstTime)
        {
            LoadInfo();
            firstTime = false;

            if (tcNames.Count > 0)
            {
                LoadTileConnectionInfoByID(selGridInt);
                SetComboBoxes();
            }
        }

        if (selGridInt != lastSelGridInt)
        {
            lastSelGridInt = selGridInt;
            LoadTileConnectionInfoByID(selGridInt);
            SetComboBoxes();
            this.Repaint();
        }

        GUI.Label(new Rect(10, 10, 200, 30), "Create new Tile Connection: ");
        newTileConnectionName = GUI.TextField(new Rect(170, 10, 120, 18), newTileConnectionName);

        if (GUI.Button(new Rect(300, 10, 80, 20), "Create"))
        {
            CreateNewTileConnection(newTileConnectionName);
        }

        int x              = 0;
        int y              = 0;
        int tileBoxSize    = 140;
        int tileBoxSizePad = tileBoxSize + 5;
        int clickedIndex   = -1;

        if (tcNames.Count > 0)
        {
            GUI.Box(new Rect(130, 40, tileBoxSizePad * 3 + 15, tileBoxSizePad * 2 + 55), tcNames[selGridInt].ToString());
            GUI.Label(new Rect(130, tileBoxSizePad * 2 + 100, 400, 30), "IMPORTANT: For tile-connections to work, all 5 tiles must be set up.");
            GUI.Box(new Rect(431, 206, 140, 140), "Default Y Rotations");

            for (int i = 0; i < maxTileCount; i++)
            {
                if (lastSelectedRotIndexes[i] != rotsComboBox[i].selectedItemIndex)
                {
                    lastSelectedRotIndexes[i] = rotsComboBox[i].selectedItemIndex;
                    if (!firstTime)
                    {
                        RewriteAllInfoToFile();
                    }
                }
            }

            if (currentRots.Count > 0)
            {
                for (int j = 0; j < maxTileCount; j++)
                {
                    if (rotsComboBox[j].isClickedComboButton)
                    {
                        clickedIndex = j;
                    }
                }

                for (int i = 0; i < maxTileCount; i++)
                {
                    selectedRotIndexes[i] = rotsComboBox[i].GetSelectedItemIndex();
                    GUI.Label(new Rect(436, 230 + (i * 20), 110, 22), tStrs[i]);

                    if (clickedIndex == -1)
                    {
                        selectedRotIndexes[i] = rotsComboBox[i].List(new Rect(515, 230 + (i * 20), 50, 15), rotsComboInfo[selectedRotIndexes[i]].text + " ^", rotsComboInfo, listStyle);
                    }
                    else
                    {
                        if (clickedIndex == i)
                        {
                            selectedRotIndexes[i] = rotsComboBox[i].List(new Rect(515, 230 + (i * 20), 50, 15), rotsComboInfo[selectedRotIndexes[i]].text + " ^", rotsComboInfo, listStyle);
                        }
                    }
                }
            }
        }

        for (int i = 0; i < maxTileCount; i++)
        {
            if (currentObjs.Count > 0)
            {
                string guid_c = currentObjs[i].ToString();

                if (!guid_c.Equals(""))
                {
                    string    objpath  = AssetDatabase.GUIDToAssetPath(guid_c);
                    Object    _obj     = (Object)AssetDatabase.LoadMainAssetAtPath(objpath);
                    Texture2D previewT = new Texture2D(2, 2);

                    if (_obj)
                    {
                        previewT = AssetPreview.GetAssetPreview(_obj);

                        if (previewT)
                        {
                            GUI.DrawTexture(new Rect(141 + (tileBoxSizePad * x), 61 + (tileBoxSizePad * y), tileBoxSize, tileBoxSize), previewT, ScaleMode.ScaleToFit);
                        }
                        else
                        {
                            GUI.Box(new Rect(141 + (tileBoxSizePad * x), 61 + (tileBoxSizePad * y), tileBoxSize, tileBoxSize), "");
                            GUI.Label(new Rect(165 + (tileBoxSizePad * x), 116 + (tileBoxSizePad * y), 100, 70), "NO PREVIEW");
                        }

                        GUI.Label(new Rect(150 + (tileBoxSizePad * x), 63 + (tileBoxSizePad * y), 100, 30), _obj.name + "\n(" + tStrs[i] + ")");

                        if (GUI.Button(new Rect(141 + (tileBoxSizePad * x), 182 + (tileBoxSizePad * y), 70, 18), "Remove"))
                        {
                            AddGUIDToCurrentTileConnection(i, "-1");
                        }

                        x++;
                        if (x == 3)
                        {
                            x = 0;
                            y++;
                        }
                    }
                    else
                    {
                        GUI.Box(new Rect(141 + (tileBoxSizePad * x), 61 + (tileBoxSizePad * y), tileBoxSize, tileBoxSize), tStrs[i]);
                        GUI.DrawTexture(new Rect(178 + (tileBoxSizePad * x), 104 + (tileBoxSizePad * y), 64, 64), tImgs[i], ScaleMode.ScaleToFit);
                        GUI.Label(new Rect(162 + (tileBoxSizePad * x), 176 + (tileBoxSizePad * y), 110, 150), "Drag Prefab Here");

                        x++;
                        if (x == 3)
                        {
                            x = 0;
                            y++;
                        }
                    }
                }
            }
            else
            {
                LoadInfo();
            }
        }

        if (tcNames.Count > 0 && clickedIndex == -1)
        {
            GUI.Box(new Rect(5, 40, 110, 5 + ((tcNames.Count + 1) * 25)), "Tile Connections");
            selGridInt = GUI.SelectionGrid(new Rect(10, 65, 100, tcNames.Count * 25), selGridInt, tcNamesStr, 1);

            if (GUI.Button(new Rect(140, 355, 140, 25), "Delete Tile Connection"))
            {
                RemoveWholeTileConnection(selGridInt);
                this.Repaint();
            }

            if (GUI.Button(new Rect(285, 355, 140, 25), "Clear all Tiles"))
            {
                ClearAllTilesFromCurrentTileConnection();
                this.Repaint();
            }

            if (GUI.Button(new Rect(430, 355, 140, 25), "Reset Y Rotations"))
            {
                ResetAllDefaultYRotations();
                this.Repaint();
            }

            HandleDragContent(tileBoxSize, tileBoxSizePad);
        }
    }
Example #23
0
        /// <summary>
        /// Assigns the specified icon to the last menu item in the collection.
        /// </summary>
        public static IEnumerable <OdinMenuItem> AddIcon(this IEnumerable <OdinMenuItem> menuItems, Sprite icon)
        {
            menuItems.AddIcon(AssetPreview.GetAssetPreview(icon));

            return(menuItems);
        }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        if (go == null)
        {
            go = GameObject.FindGameObjectWithTag("LevelCreator");
        }
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Instiantiate", GUILayout.MaxWidth(80), GUILayout.MaxHeight(20)))
        {
            if (!go.GetComponent <LevelCreator>().isSpawned)
            {
                go.GetComponent <LevelCreator>().isSpawned = true;
                SpawnFromCorner();
            }
            EditorWindow.FocusWindowIfItsOpen <SceneView>();
        }
        if (GUILayout.Button("Replace", GUILayout.MaxWidth(80), GUILayout.MaxHeight(20)))
        {
            // selectedPrefab = go.GetComponent<Map>().pList[j].prefab[i];
            //  selectedPrefabIndex = j;//go.GetComponent<Map>().pList[j].prefab.Length;
            ///   ReplaceFromCorner();
            EditorWindow.FocusWindowIfItsOpen <SceneView>();
        }
        GUILayout.EndHorizontal();
        #region List
        for (int j = 0; j < go.GetComponent <LevelCreator>().pList.Count; j++)
        {
            GUILayout.BeginHorizontal();
            if (EditorPrefs.GetBool("BOOLS" + j))
            {
                GUI.backgroundColor = new Color32(0, 255, 0, 255);
            }

            var style = new GUIStyle(EditorStyles.toolbarButton);
            style.normal.textColor = Color.black;
            if (GUILayout.Button("Show/Hide " + go.GetComponent <LevelCreator>().pList[j].Name, style)) //, GUILayout.MaxWidth(210), GUILayout.MaxHeight(20)
            {
                EditorPrefs.SetBool("BOOLS" + j, !EditorPrefs.GetBool("BOOLS" + j));
            }
            GUI.backgroundColor = Color.white;
            //  GUILayout.Label(" Element " + j.ToString());
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            if (go.GetComponent <LevelCreator>().pList[j].prefab != null && EditorPrefs.GetBool("BOOLS" + j))
            {
                int elementsInThisRow = 0;
                for (int i = 0; i < go.GetComponent <LevelCreator>().pList[j].prefab.Length; i++)
                {
                    elementsInThisRow++;

                    Texture prefabTexture = AssetPreview.GetAssetPreview(go.GetComponent <LevelCreator>().pList[j].prefab[i]);


                    if (GUILayout.Button(prefabTexture, GUILayout.MaxWidth(50), GUILayout.MaxHeight(50)))
                    {
                        selectedPrefab      = go.GetComponent <LevelCreator>().pList[j].prefab[i];
                        selectedPrefabIndex = j;//go.GetComponent<Map>().pList[j].prefab.Length;
                        EditorWindow.FocusWindowIfItsOpen <SceneView>();
                    }
                    //move to next row after creating a certain number of buttons so it doesn't overflow horizontally
                    if (elementsInThisRow > Screen.width / 70)
                    {
                        elementsInThisRow = 0;
                        GUILayout.EndHorizontal();
                        GUILayout.BeginHorizontal();
                    }
                }
            }

            GUILayout.EndHorizontal();
        }

        #endregion

        #region unused code

        /*
         * GUILayout.Label("Sides");
         #region sideprefabs
         * GUILayout.BeginHorizontal();
         * if (sidePrefabs != null)
         * {
         *  int elementsInThisRow = 0;
         *  for (int i = 0; i < sidePrefabs.Length; i++)
         *  {
         *      elementsInThisRow++;
         *      //get the texture from the prefabs
         *      Texture prefabTexture = AssetPreview.GetAssetPreview(sidePrefabs[i]);// groundPrefabs[i].GetComponent().sprite.texture;
         *      //create one button for each prefab
         *      //if a button is clicked, select that prefab and focus on the scene view
         *      if (GUILayout.Button(prefabTexture, GUILayout.MaxWidth(50), GUILayout.MaxHeight(50)))
         *      {
         *          selectedPrefab = sidePrefabs[i];
         *          if (!go.GetComponent<Map>().isSpawned)
         *          {
         *
         *              go.GetComponent<Map>().isSpawned = true;
         *              SpawnFromCorner();
         *          }
         *          EditorWindow.FocusWindowIfItsOpen<SceneView>();
         *      }
         *      //move to next row after creating a certain number of buttons so it doesn't overflow horizontally
         *      if (elementsInThisRow > Screen.width / 70)
         *      {
         *          elementsInThisRow = 0;
         *          GUILayout.EndHorizontal();
         *          GUILayout.BeginHorizontal();
         *      }
         *  }
         * }
         * GUILayout.EndHorizontal();
         #endregion
         * GUILayout.Label("Trees");
         #region treePrefabs
         * GUILayout.BeginHorizontal();
         * if (treePrefabs != null)
         * {
         *  int elementsInThisRow = 0;
         *  for (int i = 0; i < treePrefabs.Length; i++)
         *  {
         *      elementsInThisRow++;
         *      //get the texture from the prefabs
         *      Texture prefabTexture = AssetPreview.GetAssetPreview(treePrefabs[i]);// groundPrefabs[i].GetComponent().sprite.texture;
         *      //create one button for each prefab
         *      //if a button is clicked, select that prefab and focus on the scene view
         *      if (GUILayout.Button(prefabTexture, GUILayout.MaxWidth(50), GUILayout.MaxHeight(50)))
         *      {
         *          selectedPrefab = treePrefabs[i];
         *          EditorWindow.FocusWindowIfItsOpen<SceneView>();
         *      }
         *      //move to next row after creating a certain number of buttons so it doesn't overflow horizontally
         *      if (elementsInThisRow > Screen.width / 70)
         *      {
         *          elementsInThisRow = 0;
         *          GUILayout.EndHorizontal();
         *          GUILayout.BeginHorizontal();
         *      }
         *  }
         * }
         * GUILayout.EndHorizontal();
         #endregion
         * GUILayout.Label("Toppings");
         #region toppingsPrefabs
         * GUILayout.BeginHorizontal();
         * if (toppingPrefabs != null)
         * {
         *  int elementsInThisRow = 0;
         *  for (int i = 0; i < toppingPrefabs.Length; i++)
         *  {
         *      elementsInThisRow++;
         *      //get the texture from the prefabs
         *      Texture prefabTexture = AssetPreview.GetAssetPreview(toppingPrefabs[i]);// groundPrefabs[i].GetComponent().sprite.texture;
         *      //create one button for each prefab
         *      //if a button is clicked, select that prefab and focus on the scene view
         *      if (GUILayout.Button(prefabTexture, GUILayout.MaxWidth(50), GUILayout.MaxHeight(50)))
         *      {
         *          selectedPrefab = toppingPrefabs[i];
         *          EditorWindow.FocusWindowIfItsOpen<SceneView>();
         *      }
         *      //move to next row after creating a certain number of buttons so it doesn't overflow horizontally
         *      if (elementsInThisRow > Screen.width / 70)
         *      {
         *          elementsInThisRow = 0;
         *          GUILayout.EndHorizontal();
         *          GUILayout.BeginHorizontal();
         *      }
         *  }
         * }
         * GUILayout.EndHorizontal();
         #endregion
         *
         */

        #endregion
    }
Example #25
0
                public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
                {
                    EditorGUI.BeginChangeCheck();
                    EditorGUI.BeginProperty(position, label, property);

                    var prefabProp = property.FindPropertyRelative("_prefab");
                    var amountProp = property.FindPropertyRelative("_reserveAmount");
                    var icon       = (Texture2D)property.FindPropertyRelative("_icon").objectReferenceValue;

                    var iconRect = new Rect(position)
                    {
                        width  = 32,
                        height = 32
                    };
                    var prefabRect = new Rect(position)
                    {
                        x      = position.x + iconRect.width,
                        width  = position.width - iconRect.width,
                        height = position.height * 0.5f
                    };
                    var amountRect = new Rect(prefabRect)
                    {
                        x     = position.x + iconRect.width,
                        width = prefabRect.width,
                        y     = prefabRect.y + prefabRect.height
                    };

                    if (icon != null)
                    {
                        EditorGUI.DrawTextureTransparent(iconRect, icon);
                    }
                    else
                    {
                        EditorGUI.LabelField(iconRect, "NULL");
                    }
                    prefabProp.objectReferenceValue = EditorGUI.ObjectField(prefabRect, "Prefab", prefabProp.objectReferenceValue, typeof(GameObject), false);
                    EditorGUI.BeginDisabledGroup(prefabProp.objectReferenceValue == null);
                    EditorGUI.PropertyField(amountRect, amountProp);
                    EditorGUI.EndDisabledGroup();

                    EditorGUI.EndProperty();
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (prefabProp.objectReferenceValue != null)
                        {
                            property.FindPropertyRelative("_icon").objectReferenceValue = AssetPreview.GetMiniThumbnail(prefabProp.objectReferenceValue);
                        }
                        else
                        {
                            property.FindPropertyRelative("_icon").objectReferenceValue = null;
                        }
                    }
                }
Example #26
0
        public Texture getPreviewAsset()
        {
            var texture = AssetPreview.GetAssetPreview(_sourceMesh);

            return(texture);
        }
        void OnGUI()
        {
            if (!Application.isPlaying)
            {
                SerializedObject serializedObject_brushObject = null;
                int prevSelectedBrushCollectionIndex          = selectedBrushCollectionIndex;
                if (brushes != null)
                {
                    serializedObject_brushObject = new SerializedObject(brushes);
                }
                EditorGUIUtility.wideMode = true;


                #region Header

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Brush Collection:", EditorStyles.boldLabel);
                BrushCollection.BrushCollectionList brushCollectionList = BrushCollection.GetBrushCollectionsInProject();
                selectedBrushCollectionIndex = EditorGUILayout.Popup(selectedBrushCollectionIndex, brushCollectionList.GetNameList());
                if (prevSelectedBrushCollectionIndex != selectedBrushCollectionIndex)                                                       //select only when brush collection changed
                {
                    brushes = brushCollectionList.brushCollections[selectedBrushCollectionIndex];
                    brushes.SetLastUsedBrushCollection();
                }
                if (GUILayout.Button("+"))
                {
                    StringPopupWindow.Init(this, BrushCollection.CreateInstance, BrushCollection.newBrushCollectionName, "Create new BrushCollection", "Asset Name");
                }
                EditorGUILayout.EndHorizontal();


                //The active BrushList asset
                //brushes = EditorGUILayout.ObjectField(brushes, typeof(Object), true) as BrushCollection;


                #endregion

                #region Scroll view
                //scroll view
                scrollViewScrollPosition = EditorGUILayout.BeginScrollView(scrollViewScrollPosition, false, false);
                int rowLength    = 1;
                int maxRowLength = Mathf.FloorToInt((this.position.width - 35) / 100);
                if (maxRowLength < 1)
                {
                    maxRowLength = 1;
                }

                foreach (BrushObject brObj in brushes.brushes)
                {
                    //check if brushObject is null, if so skip this brush
                    if (brObj == null || brObj.brushObject == null)
                    {
                        continue;
                    }

                    //check if row is longer than max row length
                    if (rowLength > maxRowLength)
                    {
                        rowLength = 1;
                        EditorGUILayout.EndHorizontal();
                    }
                    //begin row if rowLength == 1
                    if (rowLength == 1)
                    {
                        EditorGUILayout.BeginHorizontal();
                    }

                    //change color
                    Color guiColor = GUI.backgroundColor;
                    if (brushes.selectedBrushes.Contains(brObj))
                    {
                        GUI.backgroundColor = SelectedColor;
                        if (brushes.primarySelectedBrush == brObj)
                        {
                            GUI.backgroundColor = PrimarySelectedColor;
                        }
                    }

                    //Create the brush entry in the scroll view and check if the user clicked on the created button (change the currently selected/edited brush accordingly and add it to the current brushes if possible)
                    GUIContent btnContent = new GUIContent(AssetPreview.GetAssetPreview(brObj.brushObject), brObj.brushObject.name);
                    if (GUILayout.Button(btnContent, GUILayout.Width(100), GUILayout.Height(100)))
                    {
                        //Add and remove brushes from the current brushes list
                        if (Event.current.control && !brushes.selectedBrushes.Contains(brObj))
                        {
                            brushes.selectedBrushes.Add(brObj);
                        }
                        else if (brushes.selectedBrushes.Contains(brObj))
                        {
                            brushes.selectedBrushes.Remove(brObj);
                        }

                        //select the currently edited brush and deselect all selected brushes
                        if (!Event.current.control)
                        {
                            brushes.selectedBrushes.Clear();
                            brushes.primarySelectedBrush = brObj;
                            brushes.selectedBrushes.Add(brObj);
                        }
                    }

                    GUI.backgroundColor = guiColor;
                    rowLength++;
                }

                //check if row is longer than max row length
                if (rowLength > maxRowLength)
                {
                    rowLength = 1;
                    EditorGUILayout.EndHorizontal();
                }
                //begin row if rowLength == 1
                if (rowLength == 1)
                {
                    EditorGUILayout.BeginHorizontal();
                }

                //add button
                if (GUILayout.Button("+", GUILayout.Width(100), GUILayout.Height(100)))
                {
                    AddObjectPopup.Init(brushes.brushes, this);
                }
                Color guiColorBGC = GUI.backgroundColor;

                //end horizontal and scroll view again
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndScrollView();

                #endregion

                #region Actions Group


                EditorGUILayout.BeginHorizontal();

                GUI.backgroundColor = green;
                if (GUILayout.Button(new GUIContent("Add Brush", "Add a new brush to the selection.")))
                {
                    AddObjectPopup.Init(brushes.brushes, this);
                }

                EditorGUI.BeginDisabledGroup(brushes.selectedBrushes.Count == 0 || brushes.primarySelectedBrush == null);
                GUI.backgroundColor = red;
                //remove selected brushes button
                if (GUILayout.Button(new GUIContent("Remove Current Brush(es)", "Removes the currently selected brush.")))
                {
                    if (brushes.selectedBrushes != null)
                    {
                        foreach (BrushObject brush in brushes.selectedBrushes)
                        {
                            brushes.brushes.Remove(brush);
                        }
                        brushes.selectedBrushes = new List <BrushObject>();
                    }
                }
                EditorGUI.EndDisabledGroup();
                //remove all brushes button
                EditorGUI.BeginDisabledGroup(brushes.brushes.Count == 0);
                if (GUILayout.Button(new GUIContent("Clear Brushes", "Removes all brushes.")) && RemoveAllBrushes_Dialog(brushes.brushes.Count))
                {
                    brushes.RemoveAllBrushes();
                    copy = null;
                }
                EditorGUI.EndDisabledGroup();

                EditorGUILayout.EndHorizontal();
                GUI.backgroundColor = guiColorBGC;

                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Actions", EditorStyles.boldLabel);
                EditorGUILayout.BeginHorizontal();
                isPlacingEnabled = EditorGUILayout.Toggle(new GUIContent("Painting ebanled", "Should painting of gameobjects via left click be enabled?"), isPlacingEnabled);
                isErasingEnabled = EditorGUILayout.Toggle(new GUIContent("Erasing ebanled", "Should erasing of gameobjects via right click be enabled?"), isErasingEnabled);
                EditorGUILayout.EndHorizontal();
                guiColorBGC = GUI.backgroundColor;

                if (brushes.selectedBrushes.Count > 0)
                {
                    EditorGUI.BeginDisabledGroup(brushes.spawnedObjects.Count == 0);

                    GUI.backgroundColor = green;
                    if (GUILayout.Button(new GUIContent("Permanently Apply Spawned GameObjects (" + brushes.spawnedObjects.Count + ")", "Permanently apply the gameobjects that have been spawned with GO brush, so they can not be erased by accident anymore.")))
                    {
                        brushes.ApplyCachedObjects();
                        lastPlacementPositions.Clear();
                    }


                    GUI.backgroundColor = red;
                    if (GUILayout.Button(new GUIContent("Remove All Spawned GameObjects (" + brushes.spawnedObjects.Count + ")", "Removes all spawned objects from the scene that have not been applied before.")) && RemoveAllCachedObjects_Dialog(brushes.spawnedObjects.Count))
                    {
                        brushes.DeleteSpawnedObjects();
                        lastPlacementPositions.Clear();
                    }
                    EditorGUI.EndDisabledGroup();
                }



                GUI.backgroundColor = guiColorBGC;

                #endregion

                #region Brush Details
                //don't show the details of the current brush if we do not have selected a current brush
                if (brushes.selectedBrushes != null && brushes.primarySelectedBrush != null && brushes.brushes.Count > 0 && brushes.selectedBrushes.Count > 0)
                {
                    EditorGUILayout.Space();
                    EditorGUILayout.Space();
                    EditorGUILayout.Space();

                    EditorGUILayout.BeginHorizontal();
                    GUI.backgroundColor = yellow;
                    EditorGUILayout.LabelField("Brush Details" + " - (" + brushes.primarySelectedBrush.brushObject.name + ")", EditorStyles.boldLabel);
                    if (GUILayout.Button(new GUIContent("Copy", "Copies the brush."), GUILayout.MaxWidth(50)))
                    {
                        copy = brushes.primarySelectedBrush;
                    }
                    EditorGUI.BeginDisabledGroup(copy == null);
                    if (GUILayout.Button(new GUIContent("Paste", "Pastes the details of the brush in the clipboard."), GUILayout.MaxWidth(50)))
                    {
                        brushes.primarySelectedBrush.PasteDetails(copy);
                    }
                    GUI.backgroundColor = guiColorBGC;
                    EditorGUI.EndDisabledGroup();
                    if (GUILayout.Button(new GUIContent("Reset", "Restores the defaults settings of the brush details."), GUILayout.MaxWidth(50)))
                    {
                        brushes.primarySelectedBrush.ResetDetails();
                    }
                    EditorGUILayout.EndHorizontal();

                    brushes.primarySelectedBrush.parentContainer    = EditorGUILayout.ObjectField("Parent", brushes.primarySelectedBrush.parentContainer, typeof(Transform), true) as Transform;
                    brushes.primarySelectedBrush.density            = EditorGUILayout.Slider(new GUIContent("Density", "Changes the density of the brush, i.e. how many gameobjects are spawned inside the radius of the brush."), brushes.primarySelectedBrush.density, 0f, 5f);
                    brushes.primarySelectedBrush.brushSize          = EditorGUILayout.Slider(new GUIContent("Brush Size", "The radius of the brush."), brushes.primarySelectedBrush.brushSize, 0f, 25f);
                    brushes.primarySelectedBrush.offsetFromPivot    = EditorGUILayout.Vector3Field(new GUIContent("Offset from Pivot", "Changes the offset of the spawned gameobject from the calculated position. This allows you to correct the position of the spawned objects, if you find they are floating for example due to a not that correct pivot on the gameobject/prefab."), brushes.primarySelectedBrush.offsetFromPivot);
                    brushes.primarySelectedBrush.rotOffsetFromPivot = EditorGUILayout.Vector3Field(new GUIContent("Rotational Offset", "Changes the rotational offset that is applied to the prefab/gameobject when spawning it. This allows you to current the rotation of the spawned objects."), brushes.primarySelectedBrush.rotOffsetFromPivot);


                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(new GUIContent("Min and Max Scale", "The min and max range of the spawned gameobject. If they are not the same value a random value in between the min and max is going to be picked."));
                    EditorGUILayout.MinMaxSlider(ref brushes.primarySelectedBrush.minScale, ref brushes.primarySelectedBrush.maxScale, 0.001f, 50);
                    brushes.primarySelectedBrush.minScale = EditorGUILayout.FloatField(brushes.primarySelectedBrush.minScale);
                    brushes.primarySelectedBrush.maxScale = EditorGUILayout.FloatField(brushes.primarySelectedBrush.maxScale);
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    brushes.primarySelectedBrush.randomizeXRotation = EditorGUILayout.Toggle(new GUIContent("Randomize X Rotation", "Should the rotation be randomized on the x axis?"), brushes.primarySelectedBrush.randomizeXRotation);
                    brushes.primarySelectedBrush.randomizeYRotation = EditorGUILayout.Toggle(new GUIContent("Randomize Y Rotation", "Should the rotation be randomized on the y axis?"), brushes.primarySelectedBrush.randomizeYRotation);
                    brushes.primarySelectedBrush.randomizeZRotation = EditorGUILayout.Toggle(new GUIContent("Randomize Z Rotation", "Should the rotation be randomized on the z axis?"), brushes.primarySelectedBrush.randomizeZRotation);
                    EditorGUILayout.EndHorizontal();

                    brushes.primarySelectedBrush.alignToSurface = EditorGUILayout.Toggle(new GUIContent("Align to Surface", "This option allows you to align the instantiated gameobjects to the surface you are painting on."), brushes.primarySelectedBrush.alignToSurface);

                    brushes.primarySelectedBrush.allowIntercollision = EditorGUILayout.Toggle(new GUIContent("Allow Intercollision", "Should the spawned objects be considered for the spawning of new objects? If so, newly spawned objects can be placed on top of previously (not yet applied) objects."), brushes.primarySelectedBrush.allowIntercollision);


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


                    GUI.backgroundColor = yellow;
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Filters" + " - (" + brushes.primarySelectedBrush.brushObject.name + ")", EditorStyles.boldLabel);
                    if (GUILayout.Button(new GUIContent("Copy", "Copies the brush."), GUILayout.MaxWidth(50)))
                    {
                        copy = brushes.primarySelectedBrush;
                    }
                    EditorGUI.BeginDisabledGroup(copy == null);
                    if (GUILayout.Button(new GUIContent("Paste", "Pastes the filters of the brush in the clipboard."), GUILayout.MaxWidth(50)))
                    {
                        brushes.primarySelectedBrush.PasteFilters(copy);
                    }
                    EditorGUI.EndDisabledGroup();
                    GUI.backgroundColor = guiColorBGC;
                    if (GUILayout.Button(new GUIContent("Reset", "Restores the defaults settings of the brush filters."), GUILayout.MaxWidth(50)))
                    {
                        brushes.primarySelectedBrush.ResetFilters();
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(new GUIContent("Min and Max Slope", "The range of slope that is required for an object to be placed. If the slope is not in that range, no object is going to be placed."));
                    EditorGUILayout.MinMaxSlider(ref brushes.primarySelectedBrush.minSlope, ref brushes.primarySelectedBrush.maxSlope, 0, 360);
                    brushes.primarySelectedBrush.minSlope = EditorGUILayout.FloatField(brushes.primarySelectedBrush.minSlope);
                    brushes.primarySelectedBrush.maxSlope = EditorGUILayout.FloatField(brushes.primarySelectedBrush.maxSlope);
                    EditorGUILayout.EndHorizontal();

                    SerializedProperty sp = serializedObject_brushObject.FindProperty("primarySelectedBrush").FindPropertyRelative("layerFilter");

                    EditorGUILayout.BeginHorizontal();
                    brushes.primarySelectedBrush.isTagFilteringEnabled = EditorGUILayout.Toggle("Enable Tag Filtering", brushes.primarySelectedBrush.isTagFilteringEnabled);
                    if (brushes.primarySelectedBrush.isTagFilteringEnabled)
                    {
                        brushes.primarySelectedBrush.tagFilter = EditorGUILayout.TagField(new GUIContent("Tag Filter", "Limits the painting to objects that have a specific tag on them."), brushes.primarySelectedBrush.tagFilter);
                    }
                    EditorGUILayout.EndHorizontal();

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

                    serializedObject_brushObject.ApplyModifiedProperties();
                }

                //save AssetDatabase on any change
                if (GUI.changed && brushes != null)
                {
                    brushes.Save();
                }
                #endregion
            }
        }
Example #28
0
    void ListTextures()
    {
        textureListScrollPos = EditorGUILayout.BeginScrollView(textureListScrollPos);

        foreach (TextureDetails tDetails in ActiveTextures)
        {
            GUILayout.BeginHorizontal();
            Texture tex = tDetails.texture;
            if (tDetails.texture.GetType() == typeof(Texture2DArray) || tDetails.texture.GetType() == typeof(Cubemap))
            {
                tex = AssetPreview.GetMiniThumbnail(tDetails.texture);
            }
            GUILayout.Box(tex, GUILayout.Width(ThumbnailWidth), GUILayout.Height(ThumbnailHeight));

            if (tDetails.instance == true)
            {
                GUI.color = new Color(0.8f, 0.8f, defColor.b, 1.0f);
            }
            if (tDetails.isgui == true)
            {
                GUI.color = new Color(defColor.r, 0.95f, 0.8f, 1.0f);
            }
            if (tDetails.isSky)
            {
                GUI.color = new Color(0.9f, defColor.g, defColor.b, 1.0f);
            }
            if (GUILayout.Button(tDetails.texture.name, GUILayout.Width(150)))
            {
                SelectObject(tDetails.texture, ctrlPressed);
            }
            GUI.color = defColor;

            string sizeLabel = "" + tDetails.texture.width + "x" + tDetails.texture.height;
            if (tDetails.isCubeMap)
            {
                sizeLabel += "x6";
            }
            if (tDetails.texture.GetType() == typeof(Texture2DArray))
            {
                sizeLabel += "[]\n" + ((Texture2DArray)tDetails.texture).depth + "depths";
            }
            sizeLabel += " - " + tDetails.mipMapCount + "mip\n" + FormatSizeString(tDetails.memSizeKB) + " - " + tDetails.format;

            GUILayout.Label(sizeLabel, GUILayout.Width(120));

            if (GUILayout.Button(tDetails.FoundInMaterials.Count + " Mat", GUILayout.Width(50)))
            {
                SelectObjects(tDetails.FoundInMaterials, ctrlPressed);
            }

            HashSet <Object> FoundObjects = new HashSet <Object>();
            foreach (Renderer renderer in tDetails.FoundInRenderers)
            {
                FoundObjects.Add(renderer.gameObject);
            }
            foreach (Animator animator in tDetails.FoundInAnimators)
            {
                FoundObjects.Add(animator.gameObject);
            }
            foreach (Graphic graphic in tDetails.FoundInGraphics)
            {
                FoundObjects.Add(graphic.gameObject);
            }
            foreach (Button button in tDetails.FoundInButtons)
            {
                FoundObjects.Add(button.gameObject);
            }
            foreach (MonoBehaviour script in tDetails.FoundInScripts)
            {
                FoundObjects.Add(script.gameObject);
            }
            if (GUILayout.Button(FoundObjects.Count + " GO", GUILayout.Width(50)))
            {
                SelectObjects(new List <Object>(FoundObjects), ctrlPressed);
            }

            GUILayout.EndHorizontal();
        }
        if (ActiveTextures.Count > 0)
        {
            EditorGUILayout.Space();
            GUILayout.BeginHorizontal();
            //GUILayout.Box(" ",GUILayout.Width(ThumbnailWidth),GUILayout.Height(ThumbnailHeight));
            if (GUILayout.Button("Select \n All", GUILayout.Width(ThumbnailWidth * 2)))
            {
                List <Object> AllTextures = new List <Object>();
                foreach (TextureDetails tDetails in ActiveTextures)
                {
                    AllTextures.Add(tDetails.texture);
                }
                SelectObjects(AllTextures, ctrlPressed);
            }
            EditorGUILayout.EndHorizontal();
        }
        EditorGUILayout.EndScrollView();
    }
Example #29
0
        private void DrawNodeWindow(int id)
        {
            if (Event.current.type == EventType.Layout)
            {
                return;
            }

            var node = targetGraph.AllNodes[id];

            if (EventType.MouseDown == currentEvent.type || EventType.MouseUp == currentEvent.type ||
                EventType.MouseDrag == currentEvent.type || EventType.MouseMove == currentEvent.type)
            {
                selectedWindow = id;
                EditorUtility.SetDirty(node);
            }

            if (!node.lastDrawRect.Overlaps(screenRect))
            {
                return;
            }

            var settingsRect = new Rect(node.lastDrawRect.width - 20, 5, 20, 20);
            var iconRect     = new Rect(0, 0, 18, 18);

            if (GUI.Button(settingsRect, "", BehaviourGUIStyles.Instance.settingsStyle))
            {
                rightClickedNode = node;
                BasicNodeMenu.ShowAsContext();
            }

            var originalColour = GUI.color;

            GUI.color = new Color(1.0f, 1.0f, 1.0f, 0.65f);
            EditorGUI.LabelField(iconRect, new GUIContent(AssetPreview.GetMiniThumbnail(node)));
            GUI.color = originalColour;

            if (currentEvent.type == EventType.MouseDown)
            {
                if (iconRect.Contains(currentEvent.mousePosition))
                {
                    if (currentEvent.button == 0)
                    {
                        if (currentEvent.clickCount == 1)
                        {
                            rightClickedNode = node;
                            PingSourceCallback();
                        }
                        else
                        {
                            rightClickedNode = node;
                            OpenScriptCallback();
                        }
                        currentEvent.Use();
                    }
                }
            }

            var serializedObject = SerializedObjectPool.Grab(node);

            //Undo.RecordObject (node, "Edit Node");

            float originalLabelWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = node.lastDrawRect.width / 2;

            serializedObject.FindProperty("Position").vector2Value = node.Position;

            //EditorGUI.BeginChangeCheck ();
            //string newName = EditorGUILayout.DelayedTextField (node.name);
            //if (EditorGUI.EndChangeCheck ())
            //{
            //	RenameAction (node, newName);
            //}

            var contentRect = BehaviourGraphResources.Instance.NodeStyle.padding.Remove(node.lastDrawRect);

            node.DrawGUI(serializedObject, new Rect(contentRect.x - node.Position.x - dragging_Position.x,
                                                    contentRect.y - node.Position.y - dragging_Position.y,
                                                    contentRect.width, contentRect.height));

            serializedObject.ApplyModifiedProperties();

            if (currentEvent.type == EventType.MouseDown)
            {
                if (currentEvent.button == 1)
                {
                    rightClickedNode = node;
                    BasicNodeMenu.ShowAsContext();
                }
            }

            EditorGUIUtility.labelWidth = originalLabelWidth;

#if HOVER_EFFECTS
            if (connection_Start == null && connection_End == null)
            {
                EditorGUIUtility.AddCursorRect(new Rect(node.lastDrawRect.x - node.Position.x - dragging_Position.x,
                                                        node.lastDrawRect.y - node.Position.y - dragging_Position.y,
                                                        node.lastDrawRect.width, node.lastDrawRect.height), MouseCursor.MoveArrow);
            }
#endif

            if (currentEvent.button != 2)
            {
                GUI.DragWindow();
            }
        }
Example #30
0
 bool CheckPreviewReady(Object obj, ref Texture2D texture)
 {
     texture = AssetPreview.GetAssetPreview(obj);
     return(!AssetPreview.IsLoadingAssetPreview(obj.GetInstanceID()));
 }