Unity WidgetsUI CreateTaskView Demo

  • 时间:
  • 浏览:2
  • 来源:彩神大发APP_神彩大发APP官方

Now we need to add event support in Task Component.

When Progress value changed will be called UpdateProgressbar function.

And we need test script to check how it works.

It will add task and task progress will be updated every second on random value in range 1..10.

Attach Scrollbar GameObject to ScrollRect Vertical Scrollbar.

Create button and attach test script to it.

Add AddTask() to OnClick event.

If we change Task.Progress value, it will not be displayed, but we can implement it.

Replace Task Progress field with property and add OnProgressChange event.

So now we can get event when Progress value changed.

public static readonly System.Comparison<Task> ItemComparsion = (x, y) => x.Name.CompareTo(y.Name);

Let's create own ListView, for this we need to write three classes:

using System.Collections;

using System.Collections.Generic;

using UIWidgets;

using UnityEngine;

And combine those classes to ListView.

Items displayed with correcty, but does not have any visual feedback to interactions. Let's fix it.

Set TaskView colors:

DefaultColor = 255, 215, 115, 255

DefaultBackgroundColor = 255, 215, 115, 0 (transparent)

HighlightedColor = 0, 0, 0, 255 (black)

HighlightedBackgroundColor = 181, 122, 36, 255

SelectedColor = 0, 0, 0, 255 (black)

SelectedBackgroundColor = 196, 156, 39, 255

Let's add some items to Task View.

Now we can add Task Component to DefaultItem and attach Name and Progressbar gameobjects to component fields.

Item class will have two fields: Name and Progress. Mark class as [System.Serializable] to edit Items in Editor.

Add Progressbar GameObject to DefaultItem, set anchors to middle right, position it to right side.

And check how it's works.

Component class should display this item, so it will be using Text to display name, Progressbar to display progress and implement IViewData<Task> to set it values.

public override void Start()

{

base.Start();

DataSource.Comparison = ItemComparsion;//通过ItemComparsion你这名来进行对数据进行排序

}

//改变

protected override void SetData(TaskComponent component, Task item)

{

component.SetData(item);

}

Run scene, and check if items sorted by name.

protected override void DefaultColoring(TaskComponent component)

{

base.DefaultColoring(component);

component.Name.color = DefaultColor;

}

//==========================

}

//===根据清况 动态改变文本颜色

protected override void HighlightColoring(TaskComponent component)

{

base.HighlightColoring(component);

component.Name.color = HighlightedColor;

}

PS:TaskView 的Image加上,背景才会变透明

Change DefaultItem Text color to 255, 215, 115, 255.

Here is step by step guide, but there is a faster way using ListViewIcons as source GameObject and redone it to you needs.

And run scene.

Add empty GameObject to ScrollRect, rename it to Viewport, set anchors to stretch, add Image and Mask components, disable Mask Show Mask Graphic.

This restricts ListView items to the shape of the Viewport.

Mask can be replaced with RectMask2D.

Add empty GameObject to Viewport, rename it to List, set anchors to stretch, Pivot.Y = 1, add EasyLayout and Content Size Fitter components.

Set EasyLayout: Layout Type = Grid; Grid Constraint = Fixed Column Count; Grid Constraint Count = 1.

Set Content Size Fitter: Vertical Fit = Preferred Size.

For Horizontal ListView you should set Grid Constraint = Fixed Row Count and Horizontal Fit = Preferred Size instead.

List will be contain items gameobjects and control layout.

You can use Vertical Layout Group or Horizontal Layout Group instead EasyLayout, but in this case changing ListView direction will be impossible in runtime.

源码地址:http://code.taobao.org/svn/UIWigetsTestDemo/trunk

Change DefaultItem Image color to transparent.

Add Image GameObject to List, rename it to DefaultItem, set anchors to top stretch, set height, set empty space from left and right.

Now text also change color with interactions.

Create empty GameObject, rename it to TaskView and set size 400x400.

TaskView is completed, but we can add some features.

Let's implement automatic sort for items.

ItemsComparison function compare tasks by name and used to sort items.

Add Text GameObject to DefaultItem, rename it to Name, set anchors to stretch, set right = 400, this will be space for Progressbar.

Set Text vertical alignment to middle.

Finally we add Task View component to TaskView GameObject.

Attach ScrollRect GameObject to ScrollRect field.

Attach List GameObject to Container field.

Attach DefaultItem GameObject to DefaultItem field.

public class TaskView : ListViewCustom<TaskComponent,Task> {

Add Scrollbar to ScrollRect, set direction Bottom to Top, anchors to stretch right and change size and position parametres.

protected override void SelectColoring(TaskComponent component)

{

base.SelectColoring(component);

component.Name.color = SelectedColor;

}

原文出处:https://ilih.ru/unity-assets/UIWidgets/docs/Manual.Creating_own_ListView/  或者和原文有写区别,将会是包用的不一样愿因的

Now run scene again and check interactions.

Background color changes on selection and mouse over.

Add empty GameObject to TaskView, rename it to ScrollRect and set anchors to stretch and ampty space at the right side for scrollbar.

Add ScrollRect component to GameObject. With this ListView will be scrollable.

This and some following steps can be skipped if ScrollView gameobject available in your Unity version.

Add new item.

Now it's time to GameObject for ListView.

Now add Text color changes on selection and mouse over.

For this override GraphicsForeground property in component class. (And you can also override GraphicsBackground property.)

GraphicsForeground and GraphicsBackground should return array of Graphic objects for coloring.

猜你喜欢

有什么关于音乐的小说吗 推荐下

简介:李特思意外的回到了十多年前,回到我人及 的高中时代。他惊奇的发现,我人及 岂都在拥有了可不能能弹奏我人及 内心曲调的不能!特殊的不能和十年的记忆,使得他心中拥有一首

2020-02-26

【阿里聚安全·安全周刊】IPv6安全防护准备好了吗?| 苹果的 iOS安全性已经今非昔比

【阿里聚安全·安全周刊】阿里云9大新年礼|正式上线移动直播问答补救方案【阿里聚安全·安全周刊】双十一身前的“霸下-七层流量清洗”系统|大疆VS“白帽子”,到底谁威胁了谁?【阿里

2020-02-26

【百川云栖分享】鬼道:手机淘宝 H5 和 Weex 容器的构建实践

【2016杭州·云栖大会】阿里百川在“淘宝移动技术实践&开放”专场演讲中,分别邀请了来自淘宝移动平台基础平台部负责人吴志华(花名:天施)和阿里百川负责人斯登宇(花名:承

2020-02-26

Java编程开发学习路线图(附所有免费课程+在线自测)

路线图:Java目前是全世界使用最广泛的语言,其跨平台性、面向对象、安全、多tcp连接以及简单易用的特征,使其在诞生20多年后深受开发者的喜爱。本文为云栖社区原创内容,未经允许

2020-02-26

认为学文也同样可以强国是什么意思

下载百度知道APP,抢鲜体验你对这名 回答的评价是? 我来答肯能国民素质教育高,人人不是非常强烈的爱国主义意识(不同于狭隘的民族主义)这么这名 国家在文化上假如有一天强大

2020-02-26