浏览代码

Feature : discover images (#16)

* Added Images to Discover Components

* Added Images to DiscoverAsset

* Fixed Aspect Ratio + Possible Nulls
/main
GitHub 5 年前
当前提交
adc6c83e
共有 5 个文件被更改,包括 51 次插入3 次删除
  1. 1
      CHANGELOG.md
  2. 3
      Editor/Discover/DiscoverAsset.cs
  3. 17
      Editor/Discover/DiscoverEditor.cs
  4. 26
      Editor/Discover/DiscoverWindow.cs
  5. 7
      Runtime/Discover/Discover.cs

1
CHANGELOG.md


#### Added
- Discover : Tag Filtering System
- Discover : Images in Discover Window
## 2019.3.4

3
Editor/Discover/DiscoverAsset.cs


[Header("General Properties")]
public string WindowTitle = "Discover";
public Texture2D HeaderTexture;
public bool dockable = false;
[Tooltip("Width of the Window, in pixels")]
public int WindowWidth = 640;

[Header("Content")]
public string Title = "Welcome!";
public Texture2D Image;
[Multiline]
public string Description = "This is a sample body for your discover window.";
[Header("Scenes")]

public struct DiscoverSceneInfo
{
public string Title;
public Texture2D Image;
[Multiline]
public string Description;
public EditorSceneSetup[] SceneSetups;

17
Editor/Discover/DiscoverEditor.cs


GUILayout.Space(8);
if (discover.image != null)
{
DrawImage(discover.image);
}
foreach (var section in discover.Sections)
{
SectionGUI(section);

}
public static void DrawImage(Texture texture)
{
float aspect = (float)texture.width / texture.height;
var rect = GUILayoutUtility.GetAspectRect(aspect);
GUI.DrawTexture(rect, texture, ScaleMode.ScaleToFit, false);
}
public static void SectionGUI(DiscoverSection section)
{
using (new DiscoverWindow.GroupLabelScope(section.SectionName))

GUILayout.Label(section.SectionContent, DiscoverWindow.Styles.body);
if(section.image != null)
{
DrawImage(section.image);
}
if (section.Actions != null && section.Actions.Length > 0)
{

26
Editor/Discover/DiscoverWindow.cs


{
if (discoverAsset != null)
{
var window = GetWindow<DiscoverWindow>(true);
var window = GetWindow<DiscoverWindow>(!discoverAsset.dockable);
window.SetDiscoverAsset(discoverAsset);
}
else

/// <returns>true to discard, false to keep</returns>
static bool FilterDiscoverObject(DiscoverAsset asset, Discover discoverObject)
{
if (string.IsNullOrEmpty(asset.Tags))
asset.Tags = string.Empty;
if (string.IsNullOrEmpty(discoverObject.Tags))
discoverObject.Tags = string.Empty;
string[] assetTags = asset.Tags.Split(' ');
string[] objectTags = discoverObject.Tags.Split(' ');

GUILayout.Label(discoverAsset.Title, Styles.header);
using (new GUILayout.VerticalScope(Styles.indent))
{
if(discoverAsset.Image != null)
{
DiscoverEditor.DrawImage(discoverAsset.Image);
}
GUILayout.Label(discoverAsset.Description, Styles.body);
if(discoverAsset.Scenes != null)

using (new GroupLabelScope(map.Title))
{
if(map.Image != null)
{
DiscoverEditor.DrawImage(map.Image);
}
GUILayout.Label(map.Description, Styles.body);
using (new GUILayout.HorizontalScope())

public static GUIStyle tabContainer;
public static GUIStyle image;
static Styles()
{
header = new GUIStyle(EditorStyles.wordWrappedLabel);

boxHeader = new GUIStyle(GUI.skin.box);
boxHeader.normal.textColor = GUI.skin.label.normal.textColor;
boxHeader.fixedHeight = 20;
boxHeader.fontSize = 11;
boxHeader.fixedHeight = 24;
boxHeader.fontSize = 16;
boxHeader.fontStyle = FontStyle.Bold;
boxHeader.alignment = TextAnchor.UpperLeft;
boxHeader.margin = new RectOffset(0, 0, 0, 6);

tabContainer = new GUIStyle(EditorStyles.miniButton);
tabContainer.padding = new RectOffset(4, 4, 0, 0);
image = new GUIStyle(GUIStyle.none);
image.stretchWidth = true ;
}
}

7
Runtime/Discover/Discover.cs


public bool DefaultSelected = false;
public bool AlignViewToTransform = false;
#if UNITY_EDITOR
public Texture2D image;
#endif
public GameObjectToggle[] ObjectsToToggle = new GameObjectToggle[0];
[Multiline]
public string Description = "Some Description of the Component\n\nCan be set as multiple lines.";

public struct DiscoverSection
{
public string SectionName;
#if UNITY_EDITOR
public Texture2D image;
#endif
[Multiline]
public string SectionContent;
public SectionAction[] Actions;

正在加载...
取消
保存