private static int _DoFileCallback(LuaState luaState) { // Use asset manager to replace original dofile process. // - mouguangyi try { var fileName = LuaLib.LuaToString(luaState, 1); using (var asset = ServiceCenter.GetService <IAssetManager>().Load(fileName + ".txt", AssetType.BYTES)) { var chunk = asset.Cast <byte[]>(); if (null == chunk) { throw new Exception("Can't load lua script: " + fileName); } else { int oldTop = LuaLib.LuaGetTop(luaState); if (0 == LuaLib.LuaLLoadBuffer(luaState, chunk, fileName)) { if (0 != LuaLib.LuaPCall(luaState, 0, -1, 0)) { _ThrowExceptionFromError(luaState, oldTop); } } else { _ThrowExceptionFromError(luaState, oldTop); } } } } catch (Exception e) { Logger <ILuaRuntime> .X(e); } return(0); }
public object[] DoFile(string fileName) { // Use asset manager to replace original load file process. // - mouguangyi try { using (var asset = ServiceCenter.GetService <IAssetManager>().Load(fileName + ".txt", AssetType.BYTES)) { var chunk = asset.Cast <byte[]>(); if (null == chunk) { throw new Exception("Can't load lua script: " + fileName); } else { int oldTop = LuaLib.LuaGetTop(this.luaState); if (0 == LuaLib.LuaLLoadBuffer(this.luaState, chunk, fileName)) { if (0 == LuaLib.LuaPCall(this.luaState, 0, -1, 0)) { return(_PopValues(this.luaState, oldTop)); } } _ThrowExceptionFromError(this.luaState, oldTop); } } } catch (Exception e) { Logger <ILuaRuntime> .X(e); } return(null); }
public void SetSpriteAtlasAsync(string path, string name, string defaultPath = "", Action callback = null) { _Clear(); if (!string.IsNullOrEmpty(path)) { this.image.enabled = false; ServiceCenter.GetService <IAssetManager>().LoadAsync(path, AssetType.SPRITEATLAS, asset => { this.asset = asset; var sprite = _GetSpriteInAtlas(this.asset, name); if (null != sprite) { this.image.enabled = true; this.image.sprite = sprite; } else { _SetSpriteAsync(defaultPath, null); } if (null != callback) { callback(); } }); } }
public void CheckGameVersion() { stCheckVerisonCmd checkVersion; checkVersion.data = 0; checkVersion.version = GameVersion; var server = ServiceCenter.GetService <IGiantFreeServer>(); server.SendMessage(stCheckVerisonCmd.byCmd, stCheckVerisonCmd.byParam, CmdSerializer.StructToBytes(checkVersion)); }
private void SendUserGameTime() { UserResponseGameTimeCmd cmd; ulong serverTime = this.GetServerTime(); cmd.userTmpID = this.loginModule.UserTmpID; cmd.gameTime = serverTime; var server = ServiceCenter.GetService <IGiantFreeServer>(); server.SendMessage(UserResponseGameTimeCmd.byCmd, UserResponseGameTimeCmd.byParam, CmdSerializer.StructToBytes(cmd)); }
public override void Load() { var prefabData = this.ObjectData as ScenePrefabData; this.recycleObject = _GetRecyclePool().Pick <GameObject>(prefabData.Path); if (null == this.recycleObject) { this.asset = ServiceCenter.GetService <IAssetManager>().Load(prefabData.Path, AssetType.PREFAB); this.recycleObject = GameObject.Instantiate(this.asset.Cast <GameObject>()) as GameObject; } _Init(this.recycleObject, prefabData); }
public void Load(Vector3 position, Quaternion orientation) { using (var asset = ServiceCenter.GetService <IAssetManager>().Load(levelPath + ".bytes", AssetType.BYTES)) { var bytes = asset.Cast <byte[]>(); using (var stream = new MemoryStream(bytes)) { // Parse data var levelData = SceneLevelData.Deserialize(stream, this.validateData); _InitData(levelData); _LoadAllChunks(); this.currentChunk = _FindChunk(position.x, position.z); this.currentChunk.OnEnter(); } } }
private Sprite _LoadSpriteFromAtlas(string spritePath, string spriteName) { using (var asset = ServiceCenter.GetService <IAssetManager>().Load(spritePath, AssetType.SPRITEATLAS)) { var sprites = asset.Cast <Sprite[]>(); for (var i = 0; i < sprites.Length; ++i) { if (sprites[i].name == spriteName) { return(sprites[i]); } } } return(null); }
public override void Enter(StateMachine stateMachine) { this.completed = false; var chunk = stateMachine.Model as SceneChunk; chunk._Objects = new List <SceneObject>(); ServiceCenter.GetService <IAssetManager>().LoadAsync(chunk._ChunkRefData.Path + ".bytes", AssetType.BYTES, asset => { if (null != asset) { var stream = new MemoryStream(asset.Cast <byte[]>()); SceneChunkData.DeserializeAsync(stream, chunk._ValidateData, chunkData => { stream.Close(); stream.Dispose(); for (var i = 0; i < chunkData.Objects.Count; ++i) { var go = new GameObject(); go.transform.SetParent(chunk._ChunkRoot.transform); var objectData = chunkData.Objects[i]; SceneObject obj = null; switch (objectData.Type) { case SceneObjectType.PREFAB: obj = new ScenePrefab(objectData, go); go.name = "_Prefab"; break; case SceneObjectType.LIGHTMODIFIER: obj = new SceneLightModifier(objectData, go); go.name = "_LightModifier"; break; default: go.name = "_SceneObject"; break; } chunk._Objects.Add(obj); } this.completed = true; }); } asset.Dispose(); }); }
public void LoadAsync(Vector3 position, Quaternion orientation, LevelLoadPolicy policy, Action handler) { this.policy = policy; ServiceCenter.GetService <IAssetManager>().LoadAsync(levelPath + ".bytes", AssetType.BYTES, asset => { if (null != asset) { var stream = new MemoryStream(asset.Cast <byte[]>()); SceneLevelData.DeserializeAsync(stream, this.validateData, levelData => { stream.Close(); stream.Dispose(); _InitData(levelData); switch (this.policy) { case LevelLoadPolicy.ALL: _LoadAllChunksAsync(() => { this.currentChunk = _FindChunk(position.x, position.z); this.currentChunk.OnEnter(); _NotifyCompleted(handler); }); break; case LevelLoadPolicy.SURROUNDING: // Start to load related chunks this.currentChunk = _FindChunk(position.x, position.z); if (null != this.currentChunk) { this.currentChunk.LoadAsync((target, message) => { this.currentChunk.OnEnter(); _NotifyCompleted(handler); }); } _LoadNearChunksAsync(this.currentChunk.Index); break; } }); } asset.Dispose(); }); }
private bool _SetSprite(string path) { _Clear(); if (!string.IsNullOrEmpty(path)) { this.asset = ServiceCenter.GetService <IAssetManager>().Load(path, AssetType.TEXTURE); var texture = this.asset.Cast <Texture2D>(); if (null != texture) { this.image.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); return(true); } } return(false); }
public void SetSpriteAtlas(string path, string name, string defaultPath = "") { _Clear(); if (!string.IsNullOrEmpty(path)) { this.asset = ServiceCenter.GetService <IAssetManager>().Load(path, AssetType.SPRITEATLAS); var sprite = _GetSpriteInAtlas(this.asset, name); if (null != sprite) { this.image.sprite = sprite; } else { _SetSprite(defaultPath); } } }
public void Load() { using (var asset = ServiceCenter.GetService <IAssetManager>().Load(this.chunkRefData.Path + ".bytes", AssetType.BYTES)) { var bytes = asset.Cast <byte[]>(); if (null != bytes) { this.objects = new List <SceneObject>(); using (var stream = new MemoryStream(bytes)) { var chunkData = SceneChunkData.Deserialize(stream, this.validateData); for (var i = 0; i < chunkData.Objects.Count; ++i) { var go = new GameObject(); go.transform.SetParent(this.chunkRoot.transform); var objectData = chunkData.Objects[i]; SceneObject obj = null; switch (objectData.Type) { case SceneObjectType.PREFAB: obj = new ScenePrefab(objectData, go); go.name = "_Prefab"; break; case SceneObjectType.LIGHTMODIFIER: obj = new SceneLightModifier(objectData, go); go.name = "_LightModifier"; break; default: go.name = "_SceneObject"; break; } this.objects.Add(obj); obj.Load(); } } } } }
public override void LoadAsync(Action handler) { var prefabData = this.ObjectData as ScenePrefabData; this.recycleObject = _GetRecyclePool().Pick <GameObject>(prefabData.Path); if (null != this.recycleObject) { _Init(this.recycleObject, prefabData); NotifyLoaded(handler); } else { ServiceCenter.GetService <IAssetManager>().LoadAsync(prefabData.Path, AssetType.PREFAB, asset => { this.asset = asset; this.recycleObject = GameObject.Instantiate(this.asset.Cast <GameObject>()) as GameObject; _Init(this.recycleObject, prefabData); NotifyLoaded(handler); }); } }
private static int _SearcherCallback(LuaState luaState) { try { var fileName = LuaLib.LuaToString(luaState, 1); using (var asset = ServiceCenter.GetService <IAssetManager>().Load(fileName + ".txt", AssetType.BYTES)) { var chunk = asset.Cast <byte[]>(); if (null == chunk) { throw new Exception("Can't load lua script: " + fileName); } else if (0 != LuaLib.LuaLLoadBuffer(luaState, chunk, fileName)) { var err = LuaLib.LuaToString(luaState, -1); throw new Exception(err); } } } catch (Exception e) { Logger <ILuaRuntime> .X(e); } return(1); }
//private HeartBeatMsg heartBeatMsg; public TcpConnection() { //GameWorld.Instance.OnApplicationQuit(Disconnect); new ServiceTask(new[] { typeof(IByteStorage), typeof(INetworkManager) }).Start().Continue(t => { _iNetworkManager = ServiceCenter.GetService <INetworkManager>(); _iSocketChannel = _iNetworkManager.Create("tcp") as ISocketChannel; _iSocketChannel.Setup(this); _iSocketChannel.OnChannelStateChange = OnServerStateChange; if (ServiceEventHandler != null) { ServiceEventHandler(); } // MsgHandler.Send((int)usercmd.MsgTypeCmd.Login, new usercmd.MsgLogin()); return(null); }); }
private void _SetSpriteAsync(string path, Action <bool> callback) { _Clear(); if (!string.IsNullOrEmpty(path)) { this.image.enabled = false; ServiceCenter.GetService <IAssetManager>().LoadAsync(path, AssetType.TEXTURE, asset => { this.asset = asset; var texture = asset.Cast <Texture2D>(); if (null != texture) { this.image.enabled = true; this.image.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); } if (null != callback) { callback(null != texture); } }); } }
private Sprite _LoadSpriteFromAtlas(string spritePath, string spriteName) { this.asset = ServiceCenter.GetService <IAssetManager>().Load(spritePath, AssetType.SPRITEATLAS); return(_GetSpriteInAtlas(this.asset, spriteName)); }
public static void CreateRecyclePool() { ServiceCenter.GetService <IRecycleManager>().Create(OBJECTPOOLTYPE, new ScenePrefabProcesser()); }
private IRecyclePool _GetRecyclePool() { return(ServiceCenter.GetService <IRecycleManager>().Find(OBJECTPOOLTYPE)); }