用NGUI自做点击字(图片形式)输入到框中的效果——一个简单的填字游戏 (二) ...

继续上篇的我的博文 http://www.unitymanual.com/blog-3579-586.html ,发现一个问题,在电脑上可以安全无误的运行,但是发布到手机上就不行。经过多次测试修改
总结出了一个问题就是,在手机上使用UISprite[] s=new UISprite[20]这个数组字手机上就是不行。修改后的代码如下

[code]csharpcode:

001 using UnityEngine;
002 using System.Collections;
003  
004 public class Level02_2NGUIControl : MonoBehaviour {
005     public UIAtlas poem;
006     public UISprite SpriteFour;
007     public UISprite SpriteOne;
008     public UISprite SpriteThree;
009     public UISprite SpriteTwo;
010     public GameObject PanelFailure;
011     public GameObject PanelSucceed;
012     public AudioSource failureSound;
013     public AudioSource succeedSound;
014     Vector3 panelFailureScale=new Vector3();
015     Vector3 paneSucceedScale=new Vector3();
016     string[] imgBtnSpriteName;
017     BoxCollider[] imgBtnBoxCollider;
018     void Start()
019     {
020         imgBtnSpriteName=new string[20];
021         imgBtnBoxCollider=new BoxCollider[20];
022         panelFailureScale=PanelFailure.gameObject.transform.localScale;
023         PanelFailure.gameObject.transform.localScale=new Vector3(0,0,0);
024         paneSucceedScale=PanelSucceed.gameObject.transform.localScale;
025         PanelSucceed.gameObject.transform.localScale=new Vector3(0,0,0);
026     }
027     void Update()
028     {
029          
030     }
031     void SetPanelColumnSprite(string spriteName,Vector3 pos)
032     {
033         if(SpriteOne.atlas==null)
034         {
035             SpriteOne.atlas=poem;
036             SpriteOne.spriteName=spriteName;
037             SpriteOne.MakePixelPerfect ();
038             iTween.MoveFrom (SpriteOne.gameObject,pos,1.3f);
039             //iTween.MoveFrom (SpriteOne.gameObject,iTween.Hash ("x",pos.x,"time",0.3f,"delay",0));
040             return;
041         }
042         else if(SpriteTwo.atlas==null)
043         {
044             SpriteTwo.atlas=poem;
045             SpriteTwo.spriteName=spriteName;
046             SpriteTwo.MakePixelPerfect ();
047             iTween.MoveFrom (SpriteTwo.gameObject,pos,1.3f);
048             return;
049         }
050         else if(SpriteThree.atlas==null)
051         {
052             SpriteThree.atlas=poem;
053             SpriteThree.spriteName=spriteName;
054             iTween.MoveFrom (SpriteThree.gameObject,pos,1.3f);
055             return;
056         }
057         else if(SpriteFour.atlas==null)
058         {
059             SpriteFour.atlas=poem;
060             SpriteFour.spriteName=spriteName;
061             iTween.MoveFrom (SpriteFour.gameObject,pos,1.3f);
062             if(SpriteOne.spriteName.Equals ("c1_000001")&&SpriteTwo.spriteName.Equals ("c2_000101")
063                &&SpriteThree.spriteName.Equals ("c3_000201")&&SpriteFour.spriteName.Equals ("c4_000301"))
064             {
065                 TweenScale.Begin (PanelSucceed,0.3f,paneSucceedScale);
066                 succeedSound.Play ();
067             }
068             else
069             {
070                 TweenScale.Begin (PanelFailure,0.3f,panelFailureScale);
071                 failureSound.Play ();
072             }
073         }
074          
075     }
076     void Clear()
077     {
078         SpriteOne.atlas=null;
079         SpriteOne.spriteName="";
080         SpriteTwo.atlas=null;
081         SpriteTwo.spriteName="";
082         SpriteThree.atlas=null;
083         SpriteThree.spriteName="";
084         SpriteFour.atlas=null;
085         SpriteFour.spriteName="";
086         for(int i=0;i<imgBtnBoxCollider.Length;i++)
087         {
088             if(imgBtnBoxCollider[i]!=null)
089             {
090                 UIImageButton imgBtn=GameObject.Find (imgBtnBoxCollider[i].gameObject.name).GetComponent<UIImageButton>();
091                 imgBtn.normalSprite=imgBtnSpriteName[i];
092                 GameObject.Find (imgBtnBoxCollider[i].gameObject.name).GetComponentInChildren<UISprite>().spriteName=imgBtnSpriteName[i];
093                 imgBtnBoxCollider[i].enabled=true;
094             }
095         }
096  
097     }
098     void btnEventLister(int index,string btnName)
099     {
100         imgBtnBoxCollider[index]=GameObject.Find (btnName).GetComponent<BoxCollider>();
101         UIImageButton imgBtn=GameObject.Find (btnName).GetComponent<UIImageButton>();
102         if(imgBtnBoxCollider[index].enabled)
103         {
104             //Debug.Log (imgBtnSpriteName[index].ToString ());
105             Vector3 pos=new Vector3();
106             imgBtnSpriteName[index]=imgBtn.normalSprite;
107             pos=GameObject.Find (btnName).transform.position;
108             imgBtn.normalSprite=imgBtn.pressedSprite;
109             GameObject.Find (btnName).GetComponentInChildren<UISprite>().spriteName=imgBtn.pressedSprite;
110             imgBtnBoxCollider[index].enabled=false;
111             SetPanelColumnSprite (imgBtn.pressedSprite,pos);
112              
113         }
114     }
115     void imgBtn11nOnClik()
116     {
117         btnEventLister (0,"imgBtn11");
118          
119     }
120     void imgBtn12Onclik()
121     {
122         btnEventLister (1,"imgBtn12");
123     }
124     void imgBtn13Onclik()
125     {
126         btnEventLister (2,"imgBtn13");
127     }
128     void imgBtn14Onclik()
129     {
130         btnEventLister (3,"imgBtn14");
131     }
132     void imgBtn15Onclik()
133     {
134         btnEventLister (4,"imgBtn15");
135     }
136     void imgBtn21Onclik()
137     {
138         btnEventLister (5,"imgBtn21");
139     }
140     void imgBtn22Onclik()
141     {
142         btnEventLister (6,"imgBtn22");
143     }
144     void imgBtn23Onclik()
145     {
146         btnEventLister (7,"imgBtn23");
147     }
148     void imgBtn24Onclik()
149     {
150         btnEventLister (8,"imgBtn24");
151     }
152     void imgBtn25Onclik()
153     {
154         btnEventLister (9,"imgBtn25");
155     }
156     void imgBtn31Onclik()
157     {
158         btnEventLister (10,"imgBtn31");
159     }
160     void imgBtn32Onclik()
161     {
162         btnEventLister (11,"imgBtn32");
163     }
164     void imgBtn33Onclik()
165     {
166         btnEventLister (12,"imgBtn33");
167     }
168     void imgBtn34Onclik()
169     {
170         btnEventLister (13,"imgBtn34");
171     }
172     void imgBtn35Onclik()
173     {
174         btnEventLister (14,"imgBtn35");
175     }
176     void imgBtn41Onclik()
177     {
178         btnEventLister (15,"imgBtn41");
179     }
180     void imgBtn42Onclik()
181     {
182         btnEventLister (16,"imgBtn42");
183     }
184     void imgBtn44Onclik()
185     {
186         btnEventLister (18,"imgBtn44");
187     }
188     void imgBtn43Onclik()
189     {
190         btnEventLister (17,"imgBtn43");
191     }
192     void imgBtn45Onclik()
193     {
194         btnEventLister (19,"imgBtn45");
195     }
196     void imgBtnFailureOnclik()
197     {
198         Clear ();
199         TweenScale.Begin(PanelFailure,0.3f,new Vector3(0,0,0));
200     }
201     void imgBtnSucceedOnclik()
202     {
203         xml.XmlSaveReponseEvent("LevelName""Level03_1");
204         MainController.SceneChangeResponseEvent("MainLevel");
205     }
206     void  returnMainScreen()
207     {
208         MainController.SceneChangeResponseEvent("MainLevel");
209          
210     }
211      
212 }
由于本人比较懒,所以注释什么的都没有写,如果有不明白的地方可以留言,我一定尽力解答。当然还是很希望你能给本菜鸟一些好的建议,感激不尽!


转载自博客 http://www.unitymanual.com/blog-3579-602.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值