unity3d读取文件滚动条滚动字幕
Unity3D技术手机游戏引擎手游引擎3D建模技术
显示全部 10
1212 31
实名

通过了实名认证的内容创造者

发布于 2014-10-10 06:26:19

您需要 登录 才可以下载或查看,没有账号?注册

x
本帖最后由 悦动的喵 于 2019-3-23 15:31 编辑

unity3d读取文件(读取资源包中的文件,读取txt文件中的内容),滚动条,滚动字幕。

using UnityEngine;
using System.Collections;
using System;

public class MainGUI : MonoBehaviour {

    // 放大 缩小 滚动ui
    public GUISkin windowSkin;
    private float screenWidth = Screen.width;
    private float screenHeight = Screen.height;
    //项目名
    public string nameLabel;
    private float nameLabelWidth = 200;
    private float nameLabelHeight = 50;

    //工具按钮
    public GUIStyle[] toolBtnStyle;
    private float toolBtnWidth = 110;
    private float toolBtnHeight = 120;
    private Vector2 scrollPosition;
    private float scrollWidth = 1200;

    //
    public GameObject targetObj;
    public GameObject[] qianbiPrefabs;
    private GameObject qianbiObj;
    public string[] jieshaoStrs;
    private string jieshaoStr;
    private float weicha;
    private float jieshaoWidth = 2400;
    void Start () {
        //初始化滚动条位置
        scrollPosition [0] = 5f;
        scrollPosition [1] = 5f;
        //资源初始化
        for(int i = 0; i< toolBtnStyle.Length;i++){
            //底部小图标
            string icoTextureString = "Assets/UI/先秦钱币/B000" +(i+1) + ".png";
            Texture2D icoTexture = Resources.LoadAssetAtPath(icoTextureString,typeof

(Texture2D)) as Texture2D;
            toolBtnStyle .normal.background = icoTexture;
            //prefab 要旋转的模型
            string qianbiPrefabString = "Assets/Models/XIANQING/B000" +(i+1) + ".prefab";
            GameObject qianbiPrefab = Resources.LoadAssetAtPath(qianbiPrefabString,typeof

(GameObject)) as GameObject;
            qianbiPrefabs = qianbiPrefab;
            //文字介绍
            string jieshaoString = "Assets/Models/XIANQING/B000" +(i+1) + ".txt";
            TextAsset jieshaoTextAsset = Resources.LoadAssetAtPath(jieshaoString,typeof

(TextAsset)) as TextAsset;
            if(jieshaoTextAsset == null){
                jieshaoStrs ="";
            }else{
                jieshaoStrs = jieshaoTextAsset.text;
            }

        }
        //显示第一个
        qianbiObj = Instantiate(qianbiPrefabs

[0],targetObj.transform.position,targetObj.transform.localRotation) as GameObject;     
        qianbiObj.AddComponent("MouseRotate");
        jieshaoStr = jieshaoStrs[0];
    }
     
    // Update is called once per frame
    void Update () {
        weicha -= 50 * Time.deltaTime;
        if(weicha<-jieshaoWidth){
            weicha = 0;
        }
    }

    void OnGUI(){
        GUI.skin = windowSkin;
        GUI.Label (new Rect((screenWidth-

nameLabelWidth)/2,0,nameLabelWidth,nameLabelHeight),nameLabel);

        //滚动条 控制实现工具
        scrollWidth = (toolBtnWidth + 5) * toolBtnStyle.Length;
        if(scrollWidth < screenWidth-100){
            scrollWidth = screenWidth-100;
        }
        scrollPosition = GUI.BeginScrollView(new Rect(50,screenHeight-150,screenWidth-

100,135),scrollPosition,new Rect(0,0,scrollWidth,50),false,false);
        for (int i=0; i<toolBtnStyle.Length; i++) {
            if(GUI.Button(new Rect((toolBtnWidth+5)

*i,5,toolBtnWidth,toolBtnHeight),"",toolBtnStyle)){
                try{
                    weicha = 0;
                    Destroy(qianbiObj);
                    qianbiObj = Instantiate(qianbiPrefabs

,targetObj.transform.position,targetObj.transform.localRotation) as GameObject;

                    qianbiObj.AddComponent("MouseRotate");
                    jieshaoStr = jieshaoStrs;
                    Debug.Log(jieshaoStr.Length);
                    jieshaoWidth = jieshaoStr.Length * 15;
                }catch(Exception ex){
                    Debug.Log(ex.Message);
                }
                //

            }      
        }      
         
        GUI.EndScrollView();
        GUI.Label (new Rect(50+weicha,screenHeight-200,jieshaoWidth,80),jieshaoStr);
    }
}
98ffa58516433c7580eeb90f48e38bad_145818606321.png
还没有设置签名!您可以在此展示你的链接,或者个人主页!
使用道具 <
hahameng198706  发表于 2014-10-10 09:14:23  
2#
学习了
回复 收起回复
使用道具
请喊我歪哥  发表于 2014-10-10 11:29:06  
3#

学习了
回复 收起回复
使用道具
kuanyidairen235  发表于 2018-6-28 11:50:35  
4#
unity3d读取文件unity3d读取文件
回复 收起回复
使用道具
BloodCube  发表于 2018-11-9 22:38:16  
5#
感谢分享
回复 收起回复
使用道具
张前进  发表于 2018-11-10 06:13:49  
6#
内容很丰富
回复 收起回复
使用道具
madmonkey  发表于 2018-11-10 09:22:08  
7#
不错的资源,谢谢分享
回复 收起回复
使用道具
madmonkey  发表于 2018-11-10 09:22:13  
8#
不错的资源,谢谢分享
回复 收起回复
使用道具
今今屋迷  发表于 2018-11-10 09:24:53  
9#
谢楼主发这么好的资源~么么哒!
回复 收起回复
使用道具
bryi  发表于 2018-11-10 10:16:29  
10#
立刻提起了精神
回复 收起回复
使用道具
ps牛仔  发表于 2018-11-10 10:19:41  
11#
回复 收起回复
使用道具
东北白虎  发表于 2018-11-10 10:37:00  
12#

资源哪里好,肯定元素找!
回复 收起回复
使用道具
hqp123777  发表于 2018-11-12 09:13:51  
13#
千点万点,不如微元素指点
回复 收起回复
使用道具
玉灵龙  发表于 2018-11-12 18:17:06  
14#
谢谢分享!!!!
回复 收起回复
使用道具
qq_123_f3h  发表于 2018-11-12 18:46:39  
15#

不错
回复 收起回复
使用道具
刘亮亮-游戏果动  发表于 2018-11-12 20:19:09  
16#
从业不识微元素,做遍项目也枉然
回复 收起回复
使用道具
yanpeixin  发表于 2018-11-22 09:04:44  
17#
回复 收起回复
使用道具
黄小厨  发表于 2018-11-22 09:09:50  
18#
想要成大触,天天上元素!
回复 收起回复
使用道具
神州耗子  发表于 2018-11-22 09:17:27  
19#
感谢分享
回复 收起回复
使用道具
kuanyidairen235  发表于 2018-11-29 13:04:09  
20#
感谢分享感谢分享感谢分享
回复 收起回复
使用道具
12下一页
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表