ngui怎么得到uiroot的gameobject.destroy

Posts Tagged NGUI
SHADDERRRRS! Well that is it, I’m caught in shader land. The thing is, I don’t know jack **** about them. What I am missing mostly from Flash in Unity are filters like blur, drop shadow and glow. How you would go about doing that in Unity would be with shaders (I guess), so I stuck my nose in them. Here is my first version of a Blur filter/shader.
Shader &Unlit/Transparent Colored Blurred&
Properties
_MainTex (&Base (RGB), Alpha (A)&, 2D) = &white& {}
_Distance (&Distance&, Float) = 0.015
&Queue& = &Transparent&
&IgnoreProjector& = &True&
&RenderType& = &Transparent&
Lighting Off
ZWrite Off
Fog { Mode Off }
Offset -1, -1
Blend SrcAlpha OneMinusSrcAlpha
#pragma vertex vertexProgram
#pragma fragment fragmentProgram
#include &UnityCG.cginc&
struct appdata_t
float4 vertex : POSITION;
float2 textureCoordinate : TEXCOORD0;
fixed4 color : COLOR;
struct vertexToFragment
float4 vertex : SV_POSITION;
half2 textureCoordinate : TEXCOORD0;
fixed4 color : COLOR;
sampler2D _MainT
float4 _MainTex_ST;
vertexToFragment vertexProgram (appdata_t vertexData)
output.vertex = mul(UNITY_MATRIX_MVP, vertexData.vertex);
output.textureCoordinate = TRANSFORM_TEX(vertexData.textureCoordinate, _MainTex);
output.color = vertexData.color;
fixed4 fragmentProgram (vertexToFragment input) : COLOR
float distance = _D
fixed4 computedColor = tex2D(_MainTex, input.textureCoordinate) * input.color;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x + distance , input.textureCoordinate.y + distance )) * input.color;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x + distance , input.textureCoordinate.y)) * input.color;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x , input.textureCoordinate.y + distance )) * input.color;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x - distance , input.textureCoordinate.y - distance )) * input.color;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x + distance , input.textureCoordinate.y - distance )) * input.color;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x - distance , input.textureCoordinate.y + distance )) * input.color;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x - distance , input.textureCoordinate.y)) * input.color;
computedColor += tex2D(_MainTex, half2(input.textureCoordinate.x , input.textureCoordinate.y - distance )) * input.color;
computedColor = computedColor / 9;
return computedC
It works ok, with a lot of restrictions. First, you can only use it for NGUI UITextures. I would love it to work with UISPrites, but they all share the same atlas, so if you blur one sprite you blur them all! Also, for now, you should leave a padding of 10 transparent pixels around your texture for a better effect.
The Distance parameter is relative to the size of your texture so correct values will change from one texture to the other. Anyway you have it, I will keep working on it, but if you see anything that can be improved, don’t be afraid to tell me, I would really like to make it better.
I did a s so that it doesn’t have to be rectangular. Turns out I was using an old version of NGUI, so when I updated (to version 2.65) my previous shader didn’t work anymore. Also Nicki Thomas Hansen made another shader so that you could use the . In doing so he also explained what NGUI was doing and how it was selecting the correct shader. So, based on his AlphaClip, I remade my shader so that it works on the new version of NGUI. Here is the code for it:
Shader &Unlit/Transparent Colored Masked&
Properties
_MainTex (&Base (RGB), Alpha (A)&, 2D) = &white& {}
_AlphaTex (&MaskTexture&, 2D) = &white& {}
&Queue& = &Transparent&
&IgnoreProjector& = &True&
&RenderType& = &Transparent&
Lighting Off
ZWrite Off
Fog { Mode Off }
Offset -1, -1
Blend SrcAlpha OneMinusSrcAlpha
#pragma vertex vertexProgram
#pragma fragment fragmentProgram
#include &UnityCG.cginc&
struct appdata_t
float4 vertex : POSITION;
float2 textureCoordinate : TEXCOORD0;
fixed4 color : COLOR;
struct vertexToFragment
float4 vertex : SV_POSITION;
half2 textureCoordinate : TEXCOORD0;
fixed4 color : COLOR;
sampler2D _MainT
float4 _MainTex_ST;
sampler2D _AlphaT
vertexToFragment vertexProgram (appdata_t vertexData)
output.vertex = mul(UNITY_MATRIX_MVP, vertexData.vertex);
output.textureCoordinate = TRANSFORM_TEX(vertexData.textureCoordinate, _MainTex);
output.color = vertexData.color;
fixed4 fragmentProgram (vertexToFragment input) : COLOR
fixed4 computedColor = tex2D(_MainTex, input.textureCoordinate) * input.color;
fixed4 alphaGuide = tex2D(_AlphaTex, input.textureCoordinate);
if (alphaGuide.a & computedColor.a) computedColor.a = alphaGuide.a;
return computedC
Funny how writing my previous post solved my future problem by someone else writing an answer post.
I will update the
so that it points to this post also.
UPDATE: I renamed all the variables to something readable, I thought it might be useful to understand what it is doing.
As you might have guessed it from previous posts, I am currently building UI using NGUI in Unity3D. It is quite challenging to do everything I am used to with Flash. So when I saw this video from Unite 2013 by ArenMook, you can’t believe how happy I was. It solve mostly all the problems I have with doing 2D in Unity. Also I am pretty happy they didn’t go further with the OnGUI stuff, that was really awkward to use.
Here is the video (at the 10 minute mark is the very nice slide!):
Now all I am missing are Bitmap filters like blur, drop shadow and glow and you’ll find a pretty happy person in me!
I have been playing with input fields in NGUI and it didn’t seem very straightforward what each keyboard was, so I took a screenshot of every type accessible. Here they are:
ASCIICapable
NumbersAndPunctuation
NamePhonePad
EmailAddress
As you can see, some are exactly the same (maybe they are different in portrait) so there is not as many options as it seems at first. I wish I could have done this for Android also, but I don’t have access to an Android tablet…
Hey, I am working on a bigger post, but in the mean time, allow me to write this quick tip. In NGUI, when you don’t use an atlas for your sprites, you use the UITexture class. At first I was having so much trouble with it because the make pixel perfect button just didn’t seem to make my texture look pixel perfect. That was until I figured it out.
Making it work
When you select your texture file in Unity (the actual png file), the inspector will show you settings for it. By default, the type is set to ‘Texture’, which seems fine, but what you really want to be setting it at is ‘Advanced’. Than you will be able to change the next combobox. In 3D you want to have images (textures) that their width and height are powers of 2, example: 2, 4, 8, 16, 32, 64, 128, 512, 1024. When you do 2D (UI) that
never. That is why you will likely set the Non Power of 2 to ‘None’. That is the most important setting. Now when you will press Make Pixel Perfect button in NGUI, it will resize the texture to the correct size.
Figuring out compression
To be frank, I don’t totally understand the rest of the settings as they refer to 3D stuff, but by setting the Wrap Mode to ‘Clamp’, Filter Mode to ‘Trilinear’ and Aniso Level to * , your texture will look better at run time. Also, as you probably don’t need it, you should remove the check mark after Generate Mip Maps.
Well that is it for this quick tip, I hope it saved you some time when dealing with textures.
If you follow this blog, you know that I am having some problems with Unity3d and NGUI. Mostly it’s because I was so familiar with Flash/AS3 that I am feeling kinda lost. But I am getting better at this 2D in a 3D world thing. One of the thing that I miss the most is masks. In Flash they are very easy to use and with them you can do a plethora of effects and animations. Now with bitmap based technologies, it is not such a simple task to implement a mask.
NGUI Panels have the option of being clipped panels, which means that only a rectangle of the panel will be shown. This is great for some cases, like when you need your masked region to be a rectangle, but for most masking cases it won’t work. Also, it doesn’t allow nested clipping which is a bummer.
Using another camera
Also, . It looks good, and it does the desired effect, but there is one drawback, for every mask, you need a new camera… That makes it very hard to manage in a large project or if you have multiple masks. I would use clipping more than this technique because it is easier to deal with.
Transparency shader
Now, this is the technique I devised that allows you to have multiple textures masked at the same time each with their own masks. This is really good if you load images (thumbnails) from a server and need them to be masked.
To do it we need to create a new shader. We start that by taking the Unlit – Transparent Colored shader and we will add two lines of code to it. First we will give it another texture for input. Secondly, we will take the output of the shader, use its rgb colors, but use the alpha of the new input texture we added.
Here is the code :
Shader &Unlit/Transparent Colored with mask& {
Properties {
_MainTex (&Base (RGB), Alpha (A)&, 2D) = &white& {}
_AlphaTex (&Yeahyeah&, 2D) = &white& {}
SubShader{
Tags{
&Queue& = &Transparent&
&IgnoreProjector& = &True&
&RenderType& = &Transparent&
Pass {
Lighting Off
ZWrite Off
Fog { Mode Off }
Offset -1, -1
ColorMask RGB
AlphaTest Greater .01
Blend SrcAlpha OneMinusSrcAlpha
ColorMaterial AmbientAndDiffuse
SetTexture [_MainTex] {
Combine Texture * Primary
SetTexture [_AlphaTex] {
Combine previous, texture
So that is the shader, but now we have to use it. This is actually what I found to be the most difficult part because there is a lot of documentation about how to make shaders, but not how to use them. So in the next chunk of code, we will create a texture in NGUI, give it a shader. After that we will feed the shader the textures it need to calculate the mask.
_newTexture = NGUITools.AddWidget&UITexture&(gameObject);
_newTexture.pivot = UIWidget.Pivot.TopLeft;
_newTexture.material = new Material(Shader.Find(&Unlit/Transparent Colored with mask&));
_newTexture.mainTexture = myTexture2D;
_newTexture.MakePixelPerfect();
//now we give the shader the textures
_newTexture.material.SetTexture(&wbr /&&_MainTex&, testRed);
_newTexture.material.SetTexture(&wbr /&&_AlphaTex&, testAlpha);
In this testRed is the image we want to mask and testAlpha is the alpha channel we want our previous image to use.
So here you have it, I will add pictures later to illustrate it better, but for now that’s how it is. Note that with this technique you can’t really animate or nest the masks, but you can have a lot of them at the same time.
UPDATE : If you are using a version of NGUI that is higher than 2.64, you should probably use
I have been doing some Unity recently and so far it has been going very well. Hum, I bang my head on the wall sometimes but overall it’s fun. Except for when you search for something trivial and you can’t find anything. You see, they can say what they want but Unity isn’t a mature tech yet.
I am mostly doing UI, so I am using NGUI. It’s pretty neat, does pretty much what I want, but sometimes it doesn’t expose what I need, like the size of the screen. Well Unity has the Screen class where you can get the width and height of the screen and that is what I was using until I ran into some problems. I started by testing on my Nexus 4, then on the Nexus 7 and everything was fine until I tested on the Nexus 10. You see the Nexus 10 has a huge resolution and it was bigger than a little value that I hadn’t figured out what it was doing yet. The maximum height value on the UIRoot Script. This is actually a pretty nifty little thing. You see NGUI does some magic in the back when the resolution of the device exceed this value. It will scale the size of a pixel to be bigger that 1×1, scaling your content at the same time. When this happens the values of Screen.width and Screen.height are not measured in the same pixel unit has the NGUI one. So if you scale some background according to the number of pixels of your screen, it will be scaled way too big.
DisplaySize.instance.width
So I made this little static class to get myself the screen size in NGUI’s unit. I basically get the activeHeight from the UIRoot and I derive the NGUI Screen height and width from it. Here is the code:
public class DisplaySize{
protected static DisplaySize _
public static DisplaySize instance{
get {
if (_instance == null){
_instance = new DisplaySize();
public GameObject gameO
public float width;
public float height;
public void CalculateSize(){
UIRoot mRoot = NGUITools.FindInParents&UIRoot&(gameObject);
float ratio = (float)mRoot.activeHeight / Screen.height;
width = Mathf.Ceil(Screen.width * ratio);
height = Mathf.Ceil(Screen.height * ratio);
So somewhere in your initializing code you need to pass it a gameObject that is a children of UIRoot and call CalculateSize. After that you can call DisplaySize.instance.width from anywhere in the code.
I am pretty new to Unity, so if you got a better way to do this, leave it in the comments.
Recent Posts
CategoriesCinema4Dという3DCGソフトに関するメモ書きです。
※このエリアは、60日間投稿が無い場合に表示されます。すると、表示されなくなります。
前回、ヘルプ画面をunityのOnGUIを使っていたのをNGUIで作り直そうとしていたわけですが、OnGUIでやる場合、現在のシーンの他にヘルプ画面用のシーンを用意しておいて、
Application.LoadLevelAdditive("guide_01");
なんて感じで、呼び出していたんです。LoadLevelAdditiveを使うと、すると現在のシーンに呼び出したシーンが融合されます。同じことを、NGUIを使って行うと、NGUIのUIの階層構造(UIRoot(2D)以下)がもう一つ読み込まれて、合計2つになってしまって、おかしなことになってしまいました。(前後関係の設定が正しく出来なかった?)
そんで、どうやって解決するのかと考えていたんだけど、「別にもう一つのシーンを読み込む必要ないんじゃね?」ということに気づき、現在のシーンのNGUIのUIにヘルプ画面と、元の画面に戻るための「もどる」ボタンを用意して、必要に応じて表示することにしました。そして実際にこれはうまく行くように見えました。しかし、新たな問題が発生しました。それは非アクティブにしているボタンをGameObject.Findで探すことができないということでした(つまりSetActive(true);ができない)。そして、このことを回避するために、ボタンのコライダとボタンの画像のUIスクリプトのenabledをスクリプトでtrue,falseでコントロールしてみました。ちょっとスマートじゃないような気がしましたが、これでほぼうまく行きました。しかしちょっとボタンの挙動がおかしいかったけど。
この問題を回避するためにいろいろ調べ回った結果、解決策は、最初はボタンを表示しておいて、そのボタンを変数に格納し、その後すぐ隠してしまうということでした。
スクリプトは下のようになりました。
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
using&UnityEngine;using&System.Collections;public&class&Stage01Help&:&MonoBehaviour&{&&&&private&GameObject&BackButton;&&&&void&Awake(){&&&&&&&&//最初から非アクティブ化しておくとGameObject.Findで探せないので、&&&&&&&&//最初は表示しておいて、変数に格納した後に非アクティブ化して隠す&&&&&&&&BackButton&=&GameObject.Find("ButtonBackToStage01");&&&&&&&&BackButton.SetActive(false);&&&&}&&&&public&void&HelpButtonClick()&{&&&&&&&&Debug.Log("Help&Button&is&Pushed!");&&&&&&&&//ザ?ワールド!時よ止まれ!&&&&&&&&Time.timeScale&=&0;&&&&&&&&//ターゲットカメラのオーディオソースを止める(Stage01のBGMを止める)&&&&&&&&GameObject.Find&("TargetCamera").GetComponent&AudioSource&().enabled&=&false;&&&&&&&&//自動車のエンジン音を止める&&&&&&&&GameObject.Find&("Car").GetComponent&AudioSource&().enabled&=&false;&&&&&&&&//Helpのオーディオソースを鳴らす&&&&&&&&GameObject.Find&("Help").GetComponent&AudioSource&().enabled&=&true;&&&&&&&&//ヘルプのテクスチャを表示する&&&&&&&&GameObject.Find("Sprite&(Stage1_Playguide)").GetComponent&UISprite&().enabled&=&true;&&&&&&&&//Help画面のもどるボタンを表示する&&&&&&&&BackButton.SetActive(true);&&&&}&&&&public&void&BackToStage01ButtonClick(){&&&&&&&&//時は動きだす!&&&&&&&&Time.timeScale&=&1;&&&&&&&&//ターゲットカメラのオーディオソースを元に戻す&&&&&&&&GameObject.Find&("TargetCamera").GetComponent&AudioSource&().enabled&=&true;&&&&&&&&//自動車のエンジン音を元に戻す&&&&&&&&GameObject.Find&("Car").GetComponent&AudioSource&().enabled&=&true;&&&&&&&&//Helpのオーディオソースを止める&&&&&&&&GameObject.Find&("Help").GetComponent&AudioSource&().enabled&=&false;&&&&&&&&//ヘルプのテクスチャを隠す&&&&&&&&GameObject.Find("Sprite&(Stage1_Playguide)").GetComponent&UISprite&().enabled&=&false;&&&&&&&&//Help画面のもどるボタンを隠す&&&&&&&&BackButton.SetActive(false);&&&&}}
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
というかんじ。な& 何を言ってるのか わからねーと思うが
おれもよくかわからない&
Time.timeScale&=&0;というのがあって、これのおかげで、ヘルプ画面の表示中はスタートからの時間を計っている時計も止まります。
«&&|&&|&&»
このブログの人気記事
「」カテゴリの最新記事
関連するみんなの記事
カレンダー
2017年12月
カテゴリー
最新コメント
アクセス状況
ランキング
ブックマーク
バックナンバー
プロフィール
以前業務でCinema4Dの6~8を使用。現在は別の職に就います。半額キャンペーンに惹かれてR11を購入。子供向けアニメーションの製作を目指しています。急がないと子供が大人になってしまいます><
gooブログ&お知らせ
<td valign="top" width="10%
gooブログ&おすすめ
今週のgoodなブログ!
暮らしのアイデア集请使用支持脚本的浏览器!
暂无权限访问pop163
网易公司版权所有 & ICP备:浙B2-增值电信业务经营许可证:浙B2-相关文章推荐
unity学习,希望我的博客能给喜欢unity的朋友带来帮助
今天完成了游戏的第一个关卡,觉得和别的组不同之处之一就是按钮的不同,登录注册等按钮我没用GUI的Button来做,而是用GUIT...
在使用Standard Shader的时候 Rendering Model选择Transparent模式就可以调整颜色的透明度。...
NGUI在unity3d游戏开发中非常常用,而NGUI对于每一个UI场景,都是以一个UIRoot为UI游戏对象树的根的,那么这个UIRoot是起什么作用的呢?
先简单看一下UIRoot中的基本属...
是NGUI最根本和最重要的脚本,在实际UI开发过程中都是以UIRoot为根的GameObject树,那他的作用到底是什么,先看下UIRoot的Inspection选项:
看到这个,大致可以猜到是跟U...
UIRoot是NGUI最根本和最重要的脚本,在实际UI开发过程中都是以UIRoot为根的GameObject树,那他的作用到底是什么,先看下UIRoot的Inspection选项:
看到这个,大致可...
NGUI在Unity3D游戏开发中非常常用,而NGUI对于每一个UI场景,都是以一个UIRoot为UI游戏对象树的根的,那么这个UIRoot是起什么作用的呢?
先简单看一下UIRoot中的基本属性
/blog/1964679
UIRoot是NGUI最根本和最重要的脚本,在实际UI开发过程中都是以UIRoot为根的GameObject树,那他的作...
PixelPerfect.
In this mode, your UI will always be in pixels, and a 300x200 widget will always tak...
转自:http://blog.csdn.net/yaokang522/article/details/
NGUI所见即所得之UIRoot
Unity3D 2...
NGUI在Unity3D游戏开发中非常常用,而NGUI对于每一个UI场景,都是以一个UIRoot为UI游戏对象树的根的,那么这个UIRoot是起什么作用的呢?
先简单看一下UIRoot中的基本属...
他的最新文章
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)相关文章推荐
接下来我们讲解下UILabel,UILabel是用来显示文本的脚本,继承自UIWidget。
名字牌包括2D,3D名字牌两种,区别在于2D是基于屏幕坐标的名字牌,将名字牌的gameobject结点挂在UI相机下,不会受3D场景中物件的影响,3D名字牌可以视为游戏场景内的一部分物件,名字牌跟随角...
有关NGUI的介绍我这里就不多说了,由于unity3d自带的界面绘制工具GUI效率低下,所以NGUI被广泛使用,它的原理也很简单,就是把UI绘制到一张plane上,然后摄像机用平行投影垂直摄像,这样就...
通过前面十三篇文章的介绍,我的游戏场景基本搭建完成了,我们在玩任何一款手游产品时,都是先上来个logo界面,游戏欢迎界面等,这就意味着我们要做一款游戏需要多个场景,场景之间来回切换实现游戏逻辑,uni...
本系列文章由Aimar_Johnny编写,欢迎转载,转载请标明出处,谢谢。
http://blog.csdn.net/lzhq1982/article/details/
本系列文章由Aimar_Johnny编写,欢迎转载,转载请标明出处,谢谢。
http://blog.csdn.net/lzhq1982/article/details/
/thread-.html
用NGUI 显示游戏物体的名字,当然也可以显示物体的血条 状...
在Unity中,可以使用代码控制其自身所携带的GUI来sh
接下来我们看下
接下来我们看下ProgeressBar,进度条,它是UISlider和UIScrollBar的基类,属性如下图:
Value:百分比
Alpha:透明度
他的最新文章
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)}

我要回帖

更多关于 unity gameobject数组 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信