2013-02-01 09:50:20 yang7474020 阅读数 1442
  • Unity轻松制作塔防游戏

    玩儿过塔防游戏吗?听说过《保卫萝卜》和《塔防战争》吗?本系列课程使用简单易懂的逻辑带你一起剖析这类游戏制作的过程。本案例完美展示了该类项目从搭建到完成的完整架构体系,无论代码设计还是结构布局都是悉心安排。想知道如何使用四元数跟随目标旋转吗?想知道如何使用曲线实现淡入淡出吗?本课程经过精心录制,带你轻松学习更多知识,只要你对Unity有一些基本操作的认识,就可以跟着老师一起完成这款游戏。

    9850 人正在学习 去看看 张增会

Unity3D教程:Unity制作连连看教程

GameManager.cs  游戏的核心代码,产生图片,判断是否可以销毁等。

[color=#008ef1][font=宋体]using UnityEngine;[/font][/color]
using System.Collections;
using System.Collections.Generic;
public class GameManager : MonoBehaviour
{
public DrawLine drawLine;//画线
public GameObject tilePrefab;//tile的预制
public List<Tile> tiles;//开始实例化的时候存放tile
public List<Tile> _tiles;//存放随机摆放的tile
public List<Tile> tilesEdge;//为了边界处可以有拐点,把棋盘四周的tile放在这里,这里的tile看不到
public int x, y;//棋牌的大小,两个数必须是偶数
private Tile tileA;
private Tile tileB;
private bool destroy;
private Vector3 mousePos;
private enum stepType//控制游戏的状态
{
one,
two,
three
}
private stepType _stepType;
void Start ()
{
this.gameObject.transform.position = Vector3.zero;
Spawn ();
_stepType = stepType.one;
}private void Spawn ()//实例化tile
{
float num = (x * y - (2 * x + 2 * y - 4)) * 0.5f;
for (int i = 0; i <num; i ++) {
int idTex = Random.Range (20, 45);
GameObject obj = Instantiate (tilePrefab) as GameObject;
GameObject obj2 = Instantiate (tilePrefab) as GameObject;
Tile tile = obj.GetComponent<Tile> ();
Tile tile2 = obj2.GetComponent<Tile> ();
tile.Init (idTex);
tile2.Init (idTex);
tiles.Add (tile);
tiles.Add (tile2);
}
for (int i = 0; i<((2*x+2*y) -4); i++) {//实例化边缘的tile
GameObject obj = Instantiate (tilePrefab) as GameObject;
obj.name = "edage";
Tile tile = obj.GetComponent<Tile> ();
tilesEdge.Add (tile);
}
CreatTile ();
for (int i = 0; i < _tiles.Count; i++) {
_tiles [i].transform.name = i.ToString ();
_tiles [i].id = i;
}
this.transform.position = new Vector3 (-(x / 2.0f - 0.5f), -(y / 2.0f - 0.5f), 0);
}private void CreatTile ()//随机摆放tile,如果是边缘的就放在边缘位置
{
int idTex = 0;
float _y = 0.0f;
for (int i = 0; i < y; i ++) {
float _x = 0.0f;
for (int j = 0; j < x; j ++) {
if (i == 0 || j == 0 || i == y - 1 || j == x - 1) {
tilesEdge [0].transform.position = new Vector3 (_x, _y, 0);
tilesEdge [0].pos = new Vector2 (_x, _y);
tilesEdge [0].transform.rotation = new Quaternion (0, 0, 180, 0);
tilesEdge [0].transform.parent = this.gameObject.transform;
_tiles.Add (tilesEdge [0]);
tilesEdge [0].transform.localScale = Vector3.zero;
tilesEdge [0].type = false;
tilesEdge.RemoveAt (0);
} else {
int id = Mathf.FloorToInt (Random.Range (0, tiles.Count));
tiles [id].transform.position = new Vector3 (_x, _y, 0);
tiles [id].pos = new Vector2 (_x, _y);
tiles [id].transform.rotation = new Quaternion (0, 0, 180, 0);
tiles [id].transform.parent = this.gameObject.transform;
_tiles.Add (tiles [id]);
tiles.RemoveAt (id);
}
_x += 1;
}
_y += 1;
}
}private void SelectTile ()//开始选择图片,通过射线方式选中,如果tileA和tileB不相同,则tileA等于tileB开始下一个检测
{
Ray ray = Camera.mainCamera.ScreenPointToRay (mousePos);
RaycastHit hit;
int mask = 1 << 8;
if (Physics.Raycast (ray, out hit, mask)) {
if (tileA == null) {
tileA = hit.transform.GetComponent<Tile> ();
tileA.SetTileTexture (1);
//                print ("tileA = hit.transform.GetComponent<Tile> ();" + tileA.transform.name);
} else {
tileB = hit.transform.GetComponent<Tile> ();
tileB.SetTileTexture (1);
//                print ("tileB = hit.transform.GetComponent<Tile> ();" + tileB.transform.name);
Compare (tileA, tileB);
if (tileA == null && tileB == null) {//                    print ("a and b is null");
}
}
//            hit.transform.GetComponent
}
}

private void Compare (Tile tile1, Tile tile2)//比较两个点是否可以连接到一起
{
// same card
_stepType = stepType.one;
drawLine.waypoints.Add (tile1.transform); //第一个选择的tile是画线的起始位置,
drawLine.transform.position = tile1.transform.position;
destroy = false;
print ("compare");
if (tile1.pos.x == tile2.pos.x && tile1.pos.y == tile2.pos.y) {如果选中的是同一个图片返回
tileA.SetTileTexture (0);
//            tileB.SetTileTexture (0);
tileA = tileB;
tileB = null;
//            tileA.SetTileTexture (1);
return;
} else if (tile1.pos.x == tile2.pos.x && tile1.pos.y != tile2.pos.y) {//如果两点的x相等,竖向检测
print ("check y");
destroy = CheckY (tile1, tile2);
if (destroy)
drawLine.waypoints.Add (tile2.transform);
} else if (tile1.pos.x != tile2.pos.x && tile1.pos.y == tile2.pos.y) {//如果两点的y相等,横向检测
print ("check x");
destroy = CheckX (tile1, tile2);
if (destroy)
drawLine.waypoints.Add (tile2.transform);
}
if (!destroy) {//不符合直线连接方式的开始进行一个拐点的检测
_stepType = stepType.two;
destroy = CheckTwoStep (tile1, tile2);
//            print ("destroy = CheckTwoStep (tile1, tile1);:" + destroy);
print ("check two step");
if (!destroy) {//不符合直线和一个拐点检测的开始进行两个拐点的检测
_stepType = stepType.three;
destroy = CheckThreeStep (tile1, tile2);
print ("check three:" + destroy);
print ("tile1.idTex:" + tile1.idTex + "tile1.idTex:" + tile1.idTex);
}
}
if (destroy) {//如果符合销毁条件销毁图片,并开始画线
tile1.transform.localScale = Vector3.zero;
tile2.transform.localScale = Vector3.zero;
tile1.type = false;
tile2.type = false;
tileA = null;
tileB = null;
drawLine.MoveToWaypoint ();
} else {//不符合的话,清除画线中的路径
drawLine.ClearPath ();
tileA.SetTileTexture (0);
//            tileB.SetTileTexture (0);
tileA = tileB;
tileB = null;
return;
}
}
// one step横向检测
private bool CheckX (Tile a, Tile b)
{
bool compare = true;
int _min, _max;
if (a.idTex == b.idTex) {
CompareID (a, b, out _min, out _max);
_min += 1;
if (_min == _max)
return true;
for (int i = _min; i < _max; i++) {
if (_tiles [i].type == true) {
compare = false;
break;
}
}
return compare;
} else
return false;
}
//竖向检测
private bool CheckY (Tile a, Tile b)
{
bool compare = true;
int _min, _max;
//        int idA = (int)(a.x * x + a.y);
//        int idB = (int)(b.x * x + b.y);
//        print (_tiles [idA].id.ToString () + "idA:" + idA);
//        print (_tiles [idB].id.ToString () + "idB:" + idB);
//        print ("a.idtex:" + a.idTex + "b.idtex:" + b.idTex);
if (a.idTex == b.idTex) {
CompareID (a, b, out _min, out _max);
_min += x;
if (_min == _max)
return true;
for (int i = _min; i < _max; i+=x) {
//                print ("1step");
if (_tiles [i].type == true) {
compare = false;
break;
}
}
//            if (compare) {
//                print ("2step");
//                a.type = false;
//                b.type = false;
//            }
return compare;
} else
return false;
}
// two step一个拐点的检测
private bool CheckTwoStep (Tile a, Tile b)
{
if (a.pos.x == b.pos.x || a.pos.y == b.pos.y)
return false;
int id1 = (int)(a.pos.y * x + b.pos.x);
if (_tiles [id1].type == false) {
_tiles [id1].idTex = a.idTex;

if (CheckY (_tiles [id1], b)) {
if (CheckX (a, _tiles [id1])) {
if (_stepType == stepType.two) {
drawLine.waypoints.Add (_tiles [id1].transform);
drawLine.waypoints.Add (b.transform);
} else if (_stepType == stepType.three) {
drawLine.waypoints.Add (_tiles [id1].transform);
print ("=====================:" + 1);
}
return true;
}
//                else
//                    return false;
}
}
int id2 = (int)(b.pos.y * x + a.pos.x);
if (_tiles [id2].type == false) {
_tiles [id2].idTex = b.idTex;

if (CheckY (a, _tiles [id2])) {
if (CheckX (b, _tiles [id2])) {
if (_stepType == stepType.two) {
drawLine.waypoints.Add (_tiles [id2].transform);
drawLine.waypoints.Add (b.transform);
} else if (_stepType == stepType.three) {
drawLine.waypoints.Add (_tiles [id2].transform);
print ("=====================:" + 2);
}
return true;
}
//                else
//                    return false;
}
}
return false;
}
// three step两个拐点的检测
private bool CheckThreeStep (Tile a, Tile b)
{
print ("a:" + a.idTex + "b:" + b.idTex);
//        if (a.pos.x == b.pos.x || a.pos.y == b.pos.y) return false;
bool returnValue = false;
print ("returnValue:" + returnValue);
List<Tile> _comparrPointsB;
ComparePoints (b, out _comparrPointsB);//返回b点可以横竖直线相连的点
for (int i =0; i<_comparrPointsB.Count; i++) {
returnValue = CheckTwoStep (a, _comparrPointsB [i]);
if (returnValue) {
drawLine.waypoints.Add (_comparrPointsB [i].transform);
drawLine.waypoints.Add (b.transform);
return returnValue;
}
}
if (!returnValue) {
List<Tile> _comparrPointsA;
ComparePoints (a, out _comparrPointsA);
print (a.name);
print (b.name);
for (int i =0; i<_comparrPointsA.Count; i++) {
print ("--------------" + b.idTex);
returnValue = CheckTwoStep (b, _comparrPointsA [i]);
if (returnValue) {
drawLine.waypoints.Add (_comparrPointsA [i].transform);
drawLine.waypoints.Add (b.transform);
return returnValue;
}
}

}
return returnValue;
}
//两个拐点的时候返回可以与a横竖直线相连的点
private void ComparePoints (Tile a, out List<Tile> comparePoints)
{
print ("a.idtex" + a.idTex);
comparePoints = new List<Tile> ();
comparePoints.Clear ();
//        for (int i = 0; i < y; i ++) {
//            if (i != a.y) {
//                int id = (int)(i * x + a.pos.x);
//                if (_tiles [id].type == false) {
//                    comparePoints.Add (_tiles [id]);
//                    _tiles [id].idTex = a.idTex;
//                }
//            }
//        }
for (int i = (int)a.pos.y - 1; i >-1; i--) {
int id = (int)(i * x + a.pos.x);
//            print ("three step :" + id);
if (_tiles [id].type == false) {
comparePoints.Add (_tiles [id]);
_tiles [id].idTex = a.idTex;
print ("_tiles [id].idTex = a.idTex; " + _tiles [id].idTex);
} else
break;
}
for (int i = (int)a.pos.y + 1; i < y; i++) {
int id = (int)(i * x + a.pos.x);
//            print ("three step :" + id);
if (_tiles [id].type == false) {
comparePoints.Add (_tiles [id]);
_tiles [id].idTex = a.idTex;
print ("_tiles [id].idTex = a.idTex; " + _tiles [id].idTex);
} else
break;
}
for (int i = (int)a.pos.x -1; i >-1; i --) {
int id = (int)(a.pos.y * x + i);
if (_tiles [id].type == false) {
comparePoints.Add (_tiles [id]);
_tiles [id].idTex = a.idTex;
print ("_tiles [id].idTex = a.idTex; " + _tiles [id].idTex);
} else
break;
}
for (int i = (int)a.pos.x +1; i < x; i ++) {
int id = (int)(a.pos.y * x + i);
if (_tiles [id].type == false) {
comparePoints.Add (_tiles [id]);
_tiles [id].idTex = a.idTex;
print ("_tiles [id].idTex = a.idTex; " + _tiles [id].idTex);
} else
break;
}
//        for (int i = 0; i < x; i ++) {
//            if (i != a.x) {
//                int id = (int)(a.pos.y * x + i);
//                if (_tiles [id].type == false) {
//                    comparePoints.Add (_tiles [id]);
//                    _tiles [id].idTex = a.idTex;
//                }
//            }
//        }
}
private void CompareID (Tile a, Tile b, out int min, out int max)
{

if (a.id < b.id) {
min = a.id;
max = b.id;
} else {
min = b.id;
max = a.id;
}
}
Vector2 TexSize ()
{
Vector2 size = new Vector2 (1 / x, 1 / y);
return size;
}
Vector2 TexOffset (int _idTex)
{
int a = (int)(_idTex / x);
//        print (a + "a:" + _idTex);
int b = (int)(_idTex % x);
//        print (b + "b:" + _idTex);
Vector2 offset = new Vector2 (b / x, (y - 1 - a) / y);
return offset;
}
void Update ()
{

if (Input.GetMouseButtonUp (0)) {
mousePos = Input.mousePosition;
SelectTile ();
}

}
private void ClearTiles (List<Tile> tiles)
{

tiles.Clear ();
//         this.gameObject.transform.DetachChildren();
}
}
// ari

DrawLine.cs,画线脚本,用的itween。

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class DrawLine : MonoBehaviour
{
public List<Transform> waypoints = new List<Transform> ();
public float rate = 1;
private int currentWaypoint = 1;
public void MoveToWaypoint ()
{
print ("public void MoveToWaypoint (): " + waypoints.Count);
StartCoroutine ("move");
}
public void ClearPath ()
{
waypoints.Clear ();
print ("path.Clear ();");
}
IEnumerator move ()
{
for (int i = 0; i < waypoints.Count; i++) {
iTween.MoveTo (this.gameObject, waypoints [i].position, rate);
print ("now id:" + i);
yield return new WaitForSeconds(rate);
}
waypoints.Clear ();
}
}

Tile.cs

using UnityEngine;
using System.Collections;
public class Tile : MonoBehaviour
{
public int id;
public int idTex; //通过这个判断两个图片是否相同
public Vector2 pos ;
public bool type = true;//控制图片的状态,当销毁的时候为false,其他判断的时候可以通过该点
public float x, y;
public Texture texA, texB;//鼠标选中的时候可以换贴图
public GameObject mask;//鼠标选中的时候上边显示的框框
public void Init (int _idTex)
{
idTex = _idTex;
Vector2 offset = TexOffset (_idTex);
this.renderer.material.SetTextureOffset ("_MainTex", offset);
this.renderer.material.SetTextureScale ("_MainTex", new Vector2 (0.2f, 0.1f));}
//设置tile显示的贴图和大小
public void SetTileTexture (int i)
{
if (i == 0) {
this.renderer.material.mainTexture = texA;
mask.transform.localScale = Vector3.zero;
}if (i == 1) {
this.renderer.material.mainTexture = texB;
mask.transform.localScale = new  Vector3 (0.1380835f, 0.1380835f, 0.1380835f);
}
}
//这个就是裁剪一张大图,变成一个个小的,贴到tile上
Vector2 TexOffset (int _idTex)
{
int a = (int)(_idTex / x);
int b = (int)(_idTex % x);
Vector2 offset = new Vector2 (b / x, (y - 1 - a) / y);
return offset;
}
Vector2 TexSize ()
{
Vector2 size = new Vector2 (1 / x, 1 / y);
return size;
}
}

Menu.cs,添加两个按钮。

using UnityEngine;
using System.Collections;
public class Menu : MonoBehaviour
{
public GameManager gameManager;
private GameManager _gameManger;
private bool start = true;void OnGUI ()
{
if (start) {
if (GUI.Button (new Rect (10, 10, 100, 50), "start")) {
start = false;
_gameManger = Instantiate (gameManager) as GameManager;
}
}
if (GUI.Button (new Rect (10, 70, 100, 50), "restart")) {
if (_gameManger != null) {
Destroy (_gameManger.gameObject);
print ("Destroy(_gameManger.gameObject);");
}
_gameManger = Instantiate (gameManager) as GameManager;
}}
}
2013-02-01 09:52:49 yang7474020 阅读数 668
  • Unity轻松制作塔防游戏

    玩儿过塔防游戏吗?听说过《保卫萝卜》和《塔防战争》吗?本系列课程使用简单易懂的逻辑带你一起剖析这类游戏制作的过程。本案例完美展示了该类项目从搭建到完成的完整架构体系,无论代码设计还是结构布局都是悉心安排。想知道如何使用四元数跟随目标旋转吗?想知道如何使用曲线实现淡入淡出吗?本课程经过精心录制,带你轻松学习更多知识,只要你对Unity有一些基本操作的认识,就可以跟着老师一起完成这款游戏。

    9850 人正在学习 去看看 张增会

 本文链接: http://www.unitymanual.com/1410.html        


首先需要确定好整个游戏开发的宽高比,比如 4:3(1024 * 768)  ,  3:2 (960 * 640) , 16:9(1280*720)等等,然后在场景内所有相机生成完毕后使用这段代码。

此方法是设置相机最终生成的图像比例,下面的代码是强制以 4 : 3 比例拉伸到当前选择的分辨率。此代码在IOS,Android,Mac和Windows下测试通过。

foreach (var cam in Camera.allCameras) {
cam.aspect = 4/3f;
}

2017-03-01 15:34:49 u012691505 阅读数 547
  • Unity轻松制作塔防游戏

    玩儿过塔防游戏吗?听说过《保卫萝卜》和《塔防战争》吗?本系列课程使用简单易懂的逻辑带你一起剖析这类游戏制作的过程。本案例完美展示了该类项目从搭建到完成的完整架构体系,无论代码设计还是结构布局都是悉心安排。想知道如何使用四元数跟随目标旋转吗?想知道如何使用曲线实现淡入淡出吗?本课程经过精心录制,带你轻松学习更多知识,只要你对Unity有一些基本操作的认识,就可以跟着老师一起完成这款游戏。

    9850 人正在学习 去看看 张增会
要想实现在Unity3d中调用Android代码,需要以下几个步骤
1.将需要的Android代码打包成jar
2.在Unity3d中导入并使用生成的jar,编写脚本控制Android程序

3.Unity3d发布Android应用

第一步   将需要的Android代码打包成jar(用eclipse的朋友可以自行百度eclipse打包jar)
 1.新建一个AndroidStudio项目:Unity3dDemo,目录结构如下

  
 2.在这个项目中新建一个Module:unity3d(试了好几种方式在studio里面打包jar,只有这种是成功的,至于为什么还请大神指导)
   File->New->New Module


   建好之后目录结构如下图:


   在项目中对Module添加依赖:File->Project Structure


   
   或者直接在gradle里面配置


 3.在安装好的Unity3d目录中找到classes.jar导入所建的unity3d Module中
   classes.jar路径(我用的5.5.1,不同版本可能路径不同):Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Variations\mono\Release\Classes

  导入,并且添加
   

 

4.编写代码(在Module中进行)

找到unity3d的MainActivity,让其继承UnityPlayerActivity,在里面编写你的功能代码。

5.打包jar
   打开Module 的Gradle,按下图添加(确保你是在Module中)
   //Copy类型
task makeJar(type: Copy) {
    //删除存在的
    delete 'build/libs/unity3d.jar'
    //设置拷贝的文件
    from('build/intermediates/bundles/release/')
    //打进jar包后的文件目录
    into('build/libs/')
    //将classes.jar放入build/libs/目录下
    //include ,exclude参数来设置过滤
    //(我们只关心classes.jar这个文件)
    include('classes.jar')
    //重命名
    rename ('classes.jar', 'unity3d.jar')
}

makeJar.dependsOn(build)



   
   在终端生成jar,打开Terminal输入:gradlew makeJar


   看到如图显示结果,生成jar成功。生成后的文件路径:Unity3dDemo->unity3d->build->libs
   

到此jar就打包成功,下一篇将介绍如何在Unity3d中引用打包好的jar

2017-10-25 09:58:42 nicepainkiller 阅读数 1039
  • Unity轻松制作塔防游戏

    玩儿过塔防游戏吗?听说过《保卫萝卜》和《塔防战争》吗?本系列课程使用简单易懂的逻辑带你一起剖析这类游戏制作的过程。本案例完美展示了该类项目从搭建到完成的完整架构体系,无论代码设计还是结构布局都是悉心安排。想知道如何使用四元数跟随目标旋转吗?想知道如何使用曲线实现淡入淡出吗?本课程经过精心录制,带你轻松学习更多知识,只要你对Unity有一些基本操作的认识,就可以跟着老师一起完成这款游戏。

    9850 人正在学习 去看看 张增会

其中stateText 为Text 当然也可以是 Image 等等UGUI的 组件

onTextClick 为方法的回调



            EventTrigger trigger        = stateText.gameObject.GetComponentEx<EventTrigger>();
            trigger.triggers            = new System.Collections.Generic.List<EventTrigger.Entry>();

            EventTrigger.Entry entry    = new EventTrigger.Entry();
            entry.eventID               = EventTriggerType.PointerClick;
            entry.callback              = new EventTrigger.TriggerEvent();

            entry.callback.AddListener(OnTextClick);
            trigger.triggers.Add(entry);


2013-11-19 11:24:07 u012600842 阅读数 1243
  • Unity轻松制作塔防游戏

    玩儿过塔防游戏吗?听说过《保卫萝卜》和《塔防战争》吗?本系列课程使用简单易懂的逻辑带你一起剖析这类游戏制作的过程。本案例完美展示了该类项目从搭建到完成的完整架构体系,无论代码设计还是结构布局都是悉心安排。想知道如何使用四元数跟随目标旋转吗?想知道如何使用曲线实现淡入淡出吗?本课程经过精心录制,带你轻松学习更多知识,只要你对Unity有一些基本操作的认识,就可以跟着老师一起完成这款游戏。

    9850 人正在学习 去看看 张增会
unity3d 中文教程在初学的时候很多朋友都会觉得代码是难题,而且在unity3d 中文教程当中会有大量的代码知识。我们在学习unity3d 中文教程的时候除了是基础性的理论性知识需要掌握之外,还要掌握的就是unity3d 的代码知识了。现在,我们就来看看unity3d 中文教程当中那些难懂但是又必须要学会的代码吧。
//自定义排序方法
-(NSComparisonResult)comparePerson:(Person *)person{
  //默认按年龄排序
    NSComparisonResult result = [[NSNumber numberWithInt:person.age] compare:[NSNumber numberWithInt:self.age]];//注意:基本数据类型要进行数据转换
  //如果年龄一样,就按照名字排序
    if (result == NSOrderedSame) {
        result = [self.name compare:person.name];
    }
    return result;
}


@end
主函数代码如下:
void sortArray2(){
    Person *p1 = [Person personWithAge:23 withName:@"zhangsan"];
    Person *p2 = [Person personWithAge:21 withName:@"lisi"];
    Person *p3 = [Person personWithAge:24 withName:@"wangwu"];
    Person *p4 = [Person personWithAge:24 withName:@"liwu"];
    Person *p5 = [Person personWithAge:20 withName:@"liwu"];
    NSArray *array = [NSArray arrayWithObjects:p1,p2,p3,p4,p5, nil];
    NSArray *sortedArray = [array sortedArrayUsingSelector:@selector(comparePerson:)];
    NSLog(@"排序后:%@",sortedArray);
}
2、利用block语法(sortedArrayUsingComparator:)
苹果官方提供了block语法,比较方便。其中数组排序可以用sortedArrayUsingComparator:方法,代码如下:


void sortArray3(){
    NSArray *array = [NSArray arrayWithObjects:@"1bc",@"4b6",@"123",@"789",@"3ef", nil];
    NSArray *sortedArray = [array sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {


   //这里的代码可以参照上面compare:默认的排序方法,也可以把自定义的方法写在这里,给对象排序
        NSComparisonResult result = [obj1 compare:obj2];
        return result;
    }];
    NSLog(@"排序后:%@",sortedArray);
}


3、高级排序(sortedArrayUsingDescriptors:)
如果是这样一种情况呢?Person类里有另外一个类的变量,比如说Person类除了name,age变量,还有一辆车Car类型,Car类里有个name属性。对Person对象进行排序,有这样的要求:按照Car的name排序,如果是同一辆车,也就是Car的name相同,那么再按照年龄进行排序,如果年龄也相同,最后按照Person的name进行排序。
  上面举例的unity3d 中文教程代码知识我们在刚开始学习的时候可能会觉得难度很大。但是当你真的熟悉掌握的时候就会知道,其实难度也不是想象当中的那么大,主要是看自己在学习以及掌握的时候是不是注意到了相关的技巧以及基本的知识基础。

unity3D加密

阅读数 670

没有更多推荐了,返回首页