Exemple #1
0
    private void DoDestroy(bool disposeGRoot = true)
    {
        // 销毁UI残余界面,否则可能UI组件引用着LUA中的回调函数
        // 就会导致销毁lua虚拟机时抛异常
        FairyGUI.Timers.inst.Clear();
        FairyGUI.GRoot.inst.CleanupChildren();

        if (disposeGRoot)
        {
            FairyGUI.GRoot.inst.Dispose();
        }

        // 最后销毁大厅模块
        if (lobby != null)
        {
            lobby.OnDestroy();
            lobby = null;
        }

        if (gameLuaEnv != null)
        {
            gameLuaEnv.Dispose();
        }

        if (lobbyLuaEnv != null)
        {
            lobbyLuaEnv.Dispose();
        }
    }
Exemple #2
0
    public Texture2D LoadTexture2D(string assetPath)
    {
        assetPath = ModuleHub.AppendModPrefix(assetPath, moduleName);
        var go = LoadFromAssetsFolder <Texture2D>(assetPath);

        return(go);
    }
Exemple #3
0
    public byte[] LoadTextAsset(string assetPath)
    {
        assetPath = ModuleHub.AppendModPrefix(assetPath, moduleName);
        var assetPathInBundle = Path.Combine(UnityEngine.Application.dataPath, "modules", assetPath);

        return(NetHelper.UnityWebRequestLocalGet(assetPathInBundle));
    }
Exemple #4
0
    public GameObject LoadGameObject(string assetPath)
    {
        assetPath = ModuleHub.AppendModPrefix(assetPath, moduleName);
        var go = LoadFromAssetsFolder <GameObject>(assetPath);

        return(go);
    }
Exemple #5
0
    /// <summary>
    /// 构造一个新的ModuleHub,对应一个模块
    /// </summary>
    /// <param name="modName">模块的名字</param>
    /// <param name="parent">父模块,例如游戏模块的父模块是大厅模块</param>
    /// <param name="mountNode">视图节点,模块所有的view都挂在这个节点上</param>
    public ModuleHub(string modName, ModuleHub parent, MonoBehaviour monoBehaviour, XLua.LuaEnv luaenv)
    {
        this.modName       = modName;
        this.parent        = parent;
        this.luaenv        = luaenv;
        this.monoBehaviour = monoBehaviour;

        // 选择模块的使用的加载器
        SelectModuleLoader();
    }
Exemple #6
0
    public byte[] LoadTextAsset(string assetPath)
    {
        assetPath = ModuleHub.AppendModPrefix(assetPath, moduleName);
        var ta = LoadFromBundle <TextAsset>(assetPath);

        if (ta == null)
        {
            Debug.LogError($"load {assetPath} failed");
            return(null);
        }

        return(ta.bytes);
    }
 public ShipBuilder(GenomeWrapper genomeWrapper, ModuleHub rootHub)
 {
     _rootHub = rootHub;
     if (_rootHub == null)
     {
         throw new ArgumentNullException("shipToBuildOn", "shipToBuildOn must be a valid Transform.");
     }
     _moduleList = _rootHub.ModuleList;
     if (_moduleList == null)
     {
         throw new ArgumentNullException("moduleList", "moduleList must be a valid ModuleList objet.");
     }
     _genome         = genomeWrapper;
     _testCubePrefab = _rootHub.TestCube;
 }
Exemple #8
0
    public FairyGUILoader(ModuleHub lobby)
    {
        this.lobby = lobby;

        if (lobby.loader is AssetBundleLoader)
        {
            Debug.Log("lobby.loader is AssetBundleLoader, replace FairyGUI loader with ours");
            // 当且仅当目前的加载器类型是bundle加载器时,才需要替换fairygui的加载过程
            FairyGUI.UIPackage.customiseLoadFunc = myFairyUILoadFunc;
        }
        else
        {
            FairyGUI.UIPackage.customiseLoadFunc = null;
        }
    }
Exemple #9
0
    private void DoStart()
    {
        System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
        stopWatch.Start();

        lobbyLuaEnv = new XLua.LuaEnv();
        gameLuaEnv  = new XLua.LuaEnv();
        LuaEnvInit.AddBasicBuiltin(lobbyLuaEnv);
        LuaEnvInit.AddBasicBuiltin(gameLuaEnv);

        // 启动lobby大厅模块
        lobby = new ModuleHub("lobby", null, this, lobbyLuaEnv);

        floader = new FairyGUILoader(lobby);

        lobby.Launch();

        stopWatch.Stop();
        Debug.Log($"Boot.Start total time:{stopWatch.Elapsed.TotalMilliseconds} milliseconds");
    }
Exemple #10
0
    public UnityEngine.Object LoadFromBundleAsType(string assetPath, System.Type type)
    {
        assetPath = ModuleHub.AppendModPrefix(assetPath, moduleName);
        // 首先根据路径转为包名,这是打包的时候约定的:所有分隔符替换为下划线来组成bundle名
        var bundleName = Path2AssetBundleName(assetPath);
        var bundle     = GetBundle(bundleName);

        if (bundle == null)
        {
            Debug.LogError($"load {assetPath} failed, bundle {bundleName} not found");
            return(null);
        }

        // 打包的时候,通过addressableNames把bundle中的资源的访问名字改为
        // Assets/Lobby/Main.lua这样的风格,而不是 Assets/Tmp/Lobby/Main.lua.bytes
        var assetPathInBundle = pathPrefix + assetPath;
        var ta = bundle.LoadAsset(assetPathInBundle, type);

        return(ta);
    }
Exemple #11
0
    /// <summary>
    /// 新建一个游戏模块
    /// </summary>
    /// <param name="gameModName">游戏模块名字</param>
    public void LaunchGameModule(string gameModName, string jsonString)
    {
        // 只有大厅模块的parent才不为null,其他所有游戏模块的parent必须是null
        if (parent != null)
        {
            // 如果parent不等于null,表示模块是游戏模块,游戏模块不能创建新的游戏模块
            throw new System.Exception($"LaunchGameModule {gameModName} failed, module {modName} not lobby");
        }

        // 检查是否新建重复的游戏模块
        if (subModules.ContainsKey(gameModName))
        {
            throw new System.Exception($"LaunchGameModule {gameModName} failed, duplicate module");
        }

        // 检查是否启动多于一个游戏模块,目前仅允许一个游戏在运行
        if (subModules.Count > 0)
        {
            throw new System.Exception($"LaunchGameModule {gameModName} failed, only support 1 game module on running");
        }

        // 界面必须清空后才能进入子游戏
        var guiChildrenCount = FairyGUI.GRoot.inst._children.Count;

        if (guiChildrenCount > 0)
        {
            throw new System.Exception($"GRoot.inst's children count should be zero, but now it is {guiChildrenCount}");
        }

        // 新建子模块,并添加到子模块列表
        var m = new ModuleHub(gameModName, this, monoBehaviour, Boot.instance.gameLuaEnv);

        subModules.Add(gameModName, m);

        var envString = launchSubModuleLuaCode;

        m.Launch(envString, jsonString);
    }