altas(ajax)控件(四):模糊匹配控件AutoComplete

 
AutoComplete控件是一个让TextBox拥有匹配功能的TextBox辅助控件。它可以在输入时给你一些提示,Google的搜索页面已经使用了类似功能。
它的效果图如下:
 
例子如下:
有一个名为“myTextBoxTextBox,有一个WebService名为“AutoComplete.asmx”,当客户在TextBox输入字符时,TextBox把字符发回服务器端,并返回匹配的字符组,把他们显示在TextBox供客户选择。
这样的设计在ajax中是一个典型的应用,那么我们来看看atlas给我们提供的解决方案。
Atlas中存在一个控件AutoCompleteExtender
在网页前端输入:
 
            <asp:TextBox runat="server" ID="myTextBox" Width="300" autocomplete="off" />
            <ajaxToolkit:AutoCompleteExtender
                runat="server"
                BehaviorID="AutoCompleteEx"
                ID="autoComplete1"
                TargetControlID="myTextBox"
                ServicePath="AutoComplete.asmx"
                ServiceMethod="GetCompletionList"
                MinimumPrefixLength="4"
                CompletionInterval="500"
                EnableCaching="true"
                CompletionSetCount="13"
                CompletionListCssClass="autocomplete_completionListElement"
                CompletionListItemCssClass="autocomplete_listItem"
                CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
                DelimiterCharacters=";, :">
                <Animations>
                    <OnShow>
                        <Sequence>
                            <%-- Make the completion list transparent and then show it --%>
                            <OpacityAction Opacity="100" />
                            <HideAction Visible="true" />
                           
                            <%--Cache the original size of the completion list the first time
                                the animation is played and then set it to zero -- %>
                            <ScriptAction Script="
                                // Cache the size and setup the initial size
                                var behavior = $find('AutoCompleteEx');
                                if (!behavior._height) {
                                    var target = behavior.get_completionList();
                                    behavior._height = target.offsetHeight - 2;
                                    target.style.height = '0px';
                                }" />
                           
                            <%-- Expand from 0px to the appropriate size while fading in --%>
                            <Parallel Duration=".4">
                                <FadeIn />
                                <Length PropertyKey="height" StartValue="0" EndValueScript="$find('AutoCompleteEx')._height" />
                            </Parallel>
                        </Sequence>
                    </OnShow>
                    <OnHide>
                        <%-- Collapse down to 0px and fade out --%>
                        <Parallel Duration=".4">
                            <FadeOut />
                            <Length PropertyKey="height" StartValueScript="$find('AutoCompleteEx')._height" EndValue="0" />
                        </Parallel>
                    </OnHide>
                </Animations>
            </ajaxToolkit:AutoCompleteExtender>
常用属性
属性名称
说明
BehaviorID
显示在 TextBox 下的下拉列表的ID
ID
当前控件的 ID
TargetControlID
要匹配的 TextBox ID
ServicePath
WebService 相对路径
ServiceMethod
WebService 中用来匹配的方法
MinimumPrefixLength
开始匹配的字符位数,从第几个字符开始匹配
CompletionInterval
下拉列表出现的延时
EnableCaching
是否使用缓存
CompletionSetCount
显示的下拉列表的列数
DelimiterCharacters
不需要匹配的字符集
 
 
 
 
再看中的匹配方法
WebService
    ///<summary>
    /// 返回匹配字符组
    ///</summary>
    ///<param name="prefixText"> 用来匹配的字符</param>
    ///<param name="count"> 返回匹配字符组数 </param>
    ///<returns></returns>   
[WebMethod]
    public string[] GetCompletionList(string prefixText, int count)
    {
        if (count == 0)
        {
            count = 10;
        }
 
        if (prefixText.Equals("xyz"))
        {
            return new string[0];
        }
 
        Random random = new Random();
        List<string> items = new List<string>(count);
        for (int i = 0; i < count; i++)
        {
            char c1 = (char) random.Next(65, 90);
            char c2 = (char) random.Next(97, 122);
            char c3 = (char) random.Next(97, 122);
 
            items.Add(prefixText + c1 + c2 + c3);
        }
 
        return items.ToArray();
    }
 
 
 
 
 
Unity Atlas(Unity图集)是一种将多个小图像合并成一个大图像的技术,以减少内存和渲染开销。使用Unity Atlas可以将多个Sprite(精灵)打包到一个图像中,并通过一个脚本来管理和使用这些精灵。 在Unity中,可以使用Sprite Packer工具将多个精灵打包到一个图集中。首先,我们需要为我们的asset文件创建一个脚本,该脚本需要继承自ScriptableObject,并使用[Serializable]将其转化为资源文件,以实现序列化和反序列化。然后,我们可以创建一个UGUISpriteAsset类,继承自ScriptableObject,用于存储图像资源和其他Sprite信息。该类包含一个Texture类型的变量用于存储图像资源,以及一个SpriteAssetInfor类型的列表用于存储具体的Sprite信息。 接下来,我们需要设置输出尺寸和图像深度。根据选择的字符数量确定输出尺寸,一般常用中文字体加一块大概千左右的大小的图片即可完全容纳。设置图像深度为32比特,因为我们需要用到Alpha通道。在Presets选项下选择带有Alpha通道的输出设置,可以选择白色或黑色作为字体颜色,然后将Textures设置为PNG格式。 最后,我们可以编写一个测试脚本ChangeUGUISprite,在Update函数中不停地切换图片。这个脚本可以通过索引或名称来获取Sprite,并将其赋值给Image组件的sprite属性。 总结起来,Unity Atlas是一种将多个Sprite打包到一个图集中的技术,在Unity中可以通过使用ScriptableObject和Serializable来实现序列化和反序列化,并通过Sprite Packer工具进行打包和管理。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Unity 图集Atlas功能需求实现](https://blog.csdn.net/qq_45506643/article/details/107505454)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [NGUI系列教程(自定义Atlas,Font)](https://blog.csdn.net/jbjwpzyl3611421/article/details/10593567)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值