static void OnProviderGUI(string searchBarContents)
    {
        MyCustomSettings mcs = Resources.Load("My Settings") as MyCustomSettings;

        if (!myCustomSettingsProvider)
        {
            Editor.CreateCachedEditor(mcs, null, ref myCustomSettingsProvider);
        }
        myCustomSettingsProvider.OnInspectorGUI();
    }
Пример #2
0
 public override void Preview(Vector3Int closestCell, GridLayout grid)
 {
     if (!isDragging)
     {
         base.Preview(closestCell, grid);
     }
     else
     {
         Vector3 size   = (mouseStart - mouseEnd);
         Bounds  bounds = new Bounds(mouseStart - size / 2, vecAbs(size));
         Handles.color = MyCustomSettings.GetSerializedSettings().FindProperty("handleColor").colorValue;
         Handles.DrawWireCube(bounds.center, size);
     }
 }
        public static SettingsProvider CreateMyCustomSettingsProvider()
        {
            // First parameter is the path in the Settings window.
            // Second parameter is the scope of this setting: it only appears in the Settings window for the Project scope.
            var provider = new SettingsProvider("Project/MyCustomUIElementsSettings", SettingsScope.Project)
            {
                label = "Custom UI Elements",
                // activateHandler is called when the user clicks on the Settings item in the Settings window.
                activateHandler = (searchContext, rootElement) => {
                    var settings = MyCustomSettings.GetSerializedSettings();

                    // rootElement is a VisualElement. If you add any children to it, the OnGUI function
                    // isn't called because the SettingsProvider uses the UIElements drawing framework.
                    var styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/Unity Attributes Example/43.SettingsProvider/Editor/settings_ui.uss");
                    rootElement.styleSheets.Add(styleSheet);
                    var title = new Label()
                    {
                        text = "Custom UI Elements"
                    };
                    title.AddToClassList("title");
                    rootElement.Add(title);

                    var properties = new VisualElement()
                    {
                        style =
                        {
                            flexDirection = FlexDirection.Column
                        }
                    };
                    properties.AddToClassList("property-list");
                    rootElement.Add(properties);

                    var tf = new TextField()
                    {
                        value = settings.FindProperty("m_SomeString").stringValue
                    };
                    tf.AddToClassList("property-value");
                    properties.Add(tf);
                },

                // Populate the search keywords to enable smart search filtering and label highlighting:
                keywords = new HashSet <string>(new[] { "Number", "Some String" })
            };

            return(provider);
        }
Пример #4
0
 public override void Preview(Vector3Int closestCell, GridLayout grid)
 {
     if (!isDragging)
     {
         base.Preview(closestCell, grid);
     }
     else
     {
         Vector3 size   = (mouseStart - mouseEnd);
         Bounds  bounds = new Bounds(mouseStart - size / 2, vecAbs(size));
         Handles.color = MyCustomSettings.GetSerializedSettings().FindProperty("handleColor").colorValue;
         Vector2 labelSize = GUI.skin.label.CalcSize(new GUIContent("Width"));
         Handles.Label(new Vector3((bounds.min.x + vecAbs(size).x / 2), 0, bounds.min.z - 2), new GUIContent("Width: " + Mathf.Abs(size.x)));
         Handles.Label(new Vector3(bounds.min.x - 2, 0, (bounds.min.z + vecAbs(size).z / 2)), new GUIContent("Height: " + Mathf.Abs(size.z)));
         Handles.DrawWireCube(bounds.center, size);
     }
 }
Пример #5
0
        private void OnDrawGizmos()
        {
            bool showDebug = MyCustomSettings.GetSerializedSettings().FindProperty("showDebug").boolValue;

            if (neighbours == null || !showDebug)
            {
                return;
            }
            for (int i = 0; i < neighbours.Length; i++)
            {
                if (neighbours[i] != null && neighbours[i].obj != null)
                {
                    Gizmos.color = Color.red;
                    Gizmos.DrawCube(neighbours[i].obj.transform.position, new Vector3(.1f, .1f, .1f));
                    Gizmos.DrawLine(transform.position, neighbours[i].obj.transform.position);
                }
            }
        }
Пример #6
0
    public static SettingsProvider CreateMyCustomSettingsProvider()
    {
        // First parameter is the path in the Settings window.
        // Second parameter is the scope of this setting: it only appears in the Project Settings window.
        var provider = new SettingsProvider("Project/MyCustomIMGUISettings", SettingsScope.Project)
        {
            // By default the last token of the path is used as display name if no label is provided.
            label = "Custom IMGUI",
            // Create the SettingsProvider and initialize its drawing (IMGUI) function in place:
            guiHandler = (searchContext) => {
                var settings = MyCustomSettings.GetSerializedSettings();
                EditorGUILayout.PropertyField(settings.FindProperty("m_Number"), new GUIContent("My Number"));
                EditorGUILayout.PropertyField(settings.FindProperty("m_SomeString"), new GUIContent("My String"));
            },

            // Populate the search keywords to enable smart search filtering and label highlighting:
            keywords = new HashSet <string> (new [] { "Number", "Some String" })
        };

        return(provider);
    }
Пример #7
0
        //hack
        static void drawString(string text, Vector3 worldPos, Color?colour = null)
        {
            bool showDebug = MyCustomSettings.GetSerializedSettings().FindProperty("showDebug").boolValue;

            if (Application.isEditor && !Application.isPlaying && showDebug)
            {
                UnityEditor.Handles.BeginGUI();
                if (colour.HasValue)
                {
                    GUI.color = colour.Value;
                }
                var view = UnityEditor.SceneView.currentDrawingSceneView;
                if (view == null || view.camera == null)
                {
                    return;
                }
                Vector3 screenPos = view.camera.WorldToScreenPoint(worldPos);
                Vector2 size      = GUI.skin.label.CalcSize(new GUIContent(text));
                GUI.Label(new Rect(screenPos.x - (size.x / 2), -screenPos.y + view.position.height + 4, size.x, size.y), text);
                UnityEditor.Handles.EndGUI();
            }
        }
Пример #8
0
 public override void OnActivate(string searchContext, VisualElement rootElement)
 {
     // This function is called when the user clicks on the MyCustom element in the Settings window.
     m_CustomSettings = MyCustomSettings.GetSerializedSettings();
 }
Пример #9
0
        public virtual void Preview(Vector3Int closestCell, GridLayout grid)
        {
            Handles.color = MyCustomSettings.GetSerializedSettings().FindProperty("handleColor").colorValue;

            Handles.DrawWireCube(GridUtility.GetCellCenter(closestCell, grid), new Vector3(grid.cellSize.x, 0, grid.cellSize.y));
        }