大牛专栏 收藏本版 已有21人收藏 +发表新主题
查看: 10414|回复: 0
打印 上一主题 下一主题

Capricorn|Unity3d中协同程序那点事儿(4)

[复制链接]

Capricorn|Unity3d中协同程序那点事儿(4)

zzlple 发表于 2016-5-10 00:59:35 浏览:  10414 回复:  0 只看该作者 复制链接
本帖最后由 zzlple 于 2016-5-20 21:59 编辑

上个教程我们讲到了unity网络访问的android的实现,本教程中我们着重讲述在IOS中网络访问的实现,先上代码大家一探究竟:
- (NSURLRequest *)connection:(NSURLConnection *)connection
        willSendRequest:(NSURLRequest *)request
        redirectResponse:(NSURLResponse *)response;
        {
            if (response && self.manuallyHandleRedirect)
            {
                // notify TransportiPhone of the redirect and signal to process the next response.
                if([response isKindOfClass:[NSHTTPURLResponse class]])
                {
                    NSHTTPURLResponse *httpresponse = (NSHTTPURLResponse*)response;
                    NSMutableDictionary *headers = [httpresponse.allHeaderFields mutableCopy;
                    // grab the correct URL from the request that would have
                    // automatically been called through NSURLConnection.
                    // The reason we do this is that WebRequestProto's state needs to
                    // get updated internally, so we intercept redirects, cancel the current
                    // NSURLConnection, notify WebRequestProto and let it construct a new
                    // request from the updated URL
                    [headers setObject:[request.URL absoluteString forKey:@"Location";
                    httpresponse = [[NSHTTPURLResponse alloc initWithURL:response.URL statusCode:httpresponse.statusCode HTTPVersion:nil headerFields:headers;
                    [self handleResponse:httpresponse;
                }
                else
                {
                    [self handleResponse:response;
                }
                SignalConnection(self);
                [connection cancel;
                return nil;
            }
            return request;
        }


我们可以发现unity基于ios平台网络访问基于ios原生的实现,基于NSHTTPURLResponse的一种实现,具体源码大家可以在unity安装目录下的PlaybackEngines目录寻找,这样大家就有思路是否可以扩展自己的unity引擎了呢?经过这几次的探索,相信大家对unity引擎有一个基础认识,正如那句话所言,你所见并非你所见,一切竟在发现的道路上,今天关于unity协程那点事儿的教程我们到这里结束,下一篇我们着重讲述如何扩展你的unity引擎,让大家真正灵活扩展自己的引擎,谢谢大家
   
分享至:
| 人收藏
回复

使用道具 举报

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中级会员

Copyright © 2013-2017 ARinChina-增强现实中国技术论坛   All Rights Reserved.