12 第1页 | 共2 页下一页
返回列表 发新帖
查看: 3815|回复: 10
打印 上一主题 下一主题

[教程] 在unity3d中创建可交互的直线

[复制链接]

5552

主题

2

听众

8万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
11

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2011-11-23 14:47:00 |只看该作者 |倒序浏览


           具体效果在教程最后,主要用到了两段代码!比较简单实用的小教程了,虽然是英文的,不过很容易看明白的!
         

           Let’s see how Vectrosity can be used to create an ineractive line.
         

           So how is this accompished ? Open a scene. Add a GuiTexture in it. Add the DraggableGUIElement script to the GUITexture. This will serve as one of the handles. Choose an appropriate texture and adjust the width, height and pixel inset in the Inspector, under GUITexture. I choose 9, 9 and 4.  Under DraggableGUIElement I choose minX=0, maxX=1, minY=0 and maxX=0.75. This allows the GUITexture to be dragged by the mouse along the screen, 100% along the x axis, 75% along the y axis. Duplicate this game object and now we have two handles.
         

           Now simply add the following script to the main camera.
         

           // Interactive line by Bournellis Ippokratis, for Vectrosity
           

           // Move the white handles to manipulate the line
           

            
           

           var lineMaterial : Material;
           

            
           

           var anchor1T : Transform;
           

           var anchor2T : Transform;
           

           var myLine : VectorLine;
           

            
           

           private var linePoints : Vector2[];
           

            
           

           function Start () {
           

               // Set up the vector object camera (using the camera
           

               // tagged "Main Camera" by default)
           

               Vector.SetCamera();
           

               // Create an array to hold the points of the line
           

               linePoints = new Vector2[2];
           

               // Populate the array with data from
           

               SetLinePoints();
           

               // Create the line
           

               myLine = new VectorLine("myLine", linePoints,
           

                lineMaterial, 2.0, 0, 0, LineType.Continuous, Joins.Open);
           

               myLine.vectorObject.AddComponent(MeshCollider);
           

           }
           

            
           

           function SetLinePoints () {
           

               // Set the points of the array linePoints at the positions
           

               // of the GUI Textures in the slots anchor1T and anchor2T
           

               linePoints[0] = Camera.mainCamera.ViewportToScreenPoint(anchor1T.position);
           

               linePoints[1] = Camera.mainCamera.ViewportToScreenPoint(anchor2T.position);
           

           }
           

            
           

           function Update () {
           

               // By calling SetLinePoints in Update we refresh the points
           

               // of the line in every frame
           

               SetLinePoints ();
           

           }   
           

            
           

           function LateUpdate () {
           

               // Draw the line
           

               Vector.DrawLine(myLine);
           

           }
         

           You should now drag the 2 GUITextures in the slots named anchor1T and anchor2T. Hit play and it works
           

           Feel free to post questions and suggestions. If you wish to support me, buy me a coffee
         
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

沙发
发表于 2012-1-25 23:22:12 |只看该作者
新年狂欢,挥手过往,尘埃落定。迎接新年,快乐无敌。放松心情,能量积蓄。共盼美好,祝福真切。闪亮人生,精彩同行。祝春节愉快!
回复

使用道具 举报

462

主题

1

听众

31万

积分

首席设计师

Rank: 8Rank: 8

纳金币
2
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

板凳
发表于 2012-3-19 23:25:45 |只看该作者
加精、加亮滴铁子,尤其要多丁页丁页
回复

使用道具 举报

1023

主题

3

听众

359

积分

设计实习生

Rank: 2

纳金币
335582
精华
0

最佳新人

地板
发表于 2012-5-12 23:20:44 |只看该作者
“再次路过……”我造一个-----特别路过
回复

使用道具 举报

   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

5#
发表于 2012-7-13 23:22:46 |只看该作者
不会吧,太恐怖了
回复

使用道具 举报

5969

主题

1

听众

39万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

6#
发表于 2012-9-23 23:43:59 |只看该作者
其实楼主所说的这些,俺支很少用!
回复

使用道具 举报

5969

主题

1

听众

39万

积分

首席设计师

Rank: 8Rank: 8

纳金币
-1
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

7#
发表于 2012-10-16 23:18:23 |只看该作者
很有心,部分已收录自用,谢谢
回复

使用道具 举报

462

主题

1

听众

31万

积分

首席设计师

Rank: 8Rank: 8

纳金币
2
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

8#
发表于 2012-10-22 23:39:34 |只看该作者
跑着去顶朋友滴铁
回复

使用道具 举报

   

671

主题

1

听众

3247

积分

中级设计师

Rank: 5Rank: 5

纳金币
324742
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

9#
发表于 2013-2-8 23:27:16 |只看该作者
“再次路过……”我造一个-----特别路过
回复

使用道具 举报

nts    

3

主题

1

听众

743

积分

初级设计师

Rank: 3Rank: 3

纳金币
7
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

10#
发表于 2013-10-17 11:03:40 |只看该作者
交互式插件?不错
回复

使用道具 举报

12 第1页 | 共2 页下一页
返回列表 发新帖
您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-7 04:49 , Processed in 0.251251 second(s), 28 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部