Ejemplo n.º 1
0
    public static string GetExportPath(BuildTarget platfrom)
    {
        string basePath = Path.GetFullPath(Application.dataPath + "/" + CCosmosEngine.GetConfig("AssetBundleRelPath") + "/");

        if (!Directory.Exists(basePath))
        {
            CBuildTools.ShowDialog("路径配置错误: " + basePath);
            throw new System.Exception("路径配置错误");
        }

        string path = null;

        switch (platfrom)
        {
        case BuildTarget.Android:
        case BuildTarget.iPhone:
        case BuildTarget.StandaloneWindows:
            path = basePath + CResourceManager.GetBuildPlatformName() + "/";
            break;

        default:
            CBuildTools.ShowDialog("构建平台配置错误");
            throw new System.Exception("构建平台配置错误");
        }
        return(path);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Extra Flag ->   ex:  Android/  AndroidSD/  AndroidHD/
    /// </summary>
    /// <param name="platfrom"></param>
    /// <param name="quality"></param>
    /// <returns></returns>
    public static string GetExportPath(BuildTarget platfrom, CResourceQuality quality = CResourceQuality.Sd)
    {
        string basePath = Path.GetFullPath(Application.dataPath + "/" + CCosmosEngine.GetConfig(CCosmosEngineDefaultConfig.AssetBundleBuildRelPath) + "/");

        if (!Directory.Exists(basePath))
        {
            CBuildTools.ShowDialog("路径配置错误: " + basePath);
            throw new System.Exception("路径配置错误");
        }

        string path = null;

        switch (platfrom)
        {
        case BuildTarget.Android:
        case BuildTarget.iPhone:
        case BuildTarget.StandaloneWindows:
            var platformName = CResourceModule.BuildPlatformName;
            if (quality != CResourceQuality.Sd)      // SD no need add
            {
                platformName += quality.ToString().ToUpper();
            }

            path = basePath + platformName + "/";
            break;

        default:
            CBuildTools.ShowDialog("构建平台配置错误");
            throw new System.Exception("构建平台配置错误");
        }
        return(path);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Engine entry.... all begins from here
    /// </summary>
    public static CCosmosEngine New(GameObject gameObjectToAttach, ICModule[] modules, CoroutineDelegate before, CoroutineDelegate after)
    {
        CBase.Assert(gameObjectToAttach != null && modules != null);
        CCosmosEngine engine = gameObjectToAttach.AddComponent <CCosmosEngine>();

        engine.GameModules       = modules;
        engine.BeforeInitModules = before;
        engine.AfterInitModules  = after;
        return(engine);
    }
Ejemplo n.º 4
0
    private void Awake()
    {
        if (EngineInstance != null)
        {
            CBase.LogError("Duplicated Instance CCosmosEngine!!!");
        }

        EngineInstance = this;

        Init();
    }
Ejemplo n.º 5
0
    private void Awake()
    {
        if (EngineInstance != null)
        {
            CBase.LogError("Duplicated Instance CCosmosEngine!!!");
        }

        EngineInstance = this;

        Init();
    }
Ejemplo n.º 6
0
    void Awake()
    {
        CGameSettings.Instance.InitAction += OnGameSettingsInit;

        CCosmosEngine.New(
            gameObject,
            new ICModule[] {
            CGameSettings.Instance,
        },
            null,
            null);

        CUIModule.Instance.OpenWindow <CUIDemoHome>();
    }
Ejemplo n.º 7
0
    void _Init(string path, string assetName, System.Action <UnityEngine.Object, object[]> assetFileLoadedCallback, object[] args)
    {
        AssetFileLoadedCallback = assetFileLoadedCallback;
        CallbackArgs            = args;
        AssetInBundleName       = assetName;

        if (CCosmosEngine.GetConfig("IsLoadAssetBundle").ToInt32() == 0)
        {
            CResourceManager.Instance.StartCoroutine(LoadInResourceFolder(path));
        }
        else
        {
            new CAssetBundleLoader(path, OnAssetBundleLoaded);
        }
    }
Ejemplo n.º 8
0
    public IEnumerator Init()
    {
        Type bridgeType = Type.GetType(string.Format("C{0}Bridge", CCosmosEngine.GetConfig("UIBridgeType")));

        if (bridgeType != null)
        {
            UiBridge = Activator.CreateInstance(bridgeType) as ICUIBridge;
            UiBridge.InitBridge();
        }
        else
        {
            CBase.Log("No UI Bridge in Use.");
        }

        yield break;
    }
Ejemplo n.º 9
0
    void OnGameSettingsInit()
    {
        CGameSettings _ = CGameSettings.Instance;

        CDebug.Log("Begin Load tab file...");

        //var tabContent = File.ReadAllText("Assets/" + CCosmosEngine.GetConfig("ProductRelPath") + "/setting/test_tab.bytes");
        //var path = CResourceModule.GetResourceFullPath("/setting/test_tab.bytes");
        var tabContent = File.ReadAllText(Application.dataPath + "/" + CCosmosEngine.GetConfig("ProductRelPath") + "/setting/test_tab.bytes");

        _.LoadTab <CTestTabInfo>(tabContent);
        CDebug.Log("Output the tab file...");
        foreach (CTestTabInfo info in _.GetInfos <CTestTabInfo>())
        {
            CDebug.Log("Id:{0}, Name: {1}", info.Id, info.Name);
        }
    }
Ejemplo n.º 10
0
    ///
    /// DES解密字符串
    /// 待解密的字符串
    /// 解密密钥,要求为8位,和加密密钥相同
    /// 解密成功返回解密后的字符串,失败返源串
    public string DecryptDES(string decryptString)
    {
        string decryptKey = CCosmosEngine.GetConfig("CryptKey");

        try
        {
            byte[] rgbKey                    = Encoding.UTF8.GetBytes(decryptKey);
            byte[] rgbIV                     = CustomKeys ?? DefaultKeys;
            byte[] inputByteArray            = Convert.FromBase64String(decryptString);
            DESCryptoServiceProvider DCSP    = new DESCryptoServiceProvider();
            MemoryStream             mStream = new MemoryStream();
            CryptoStream             cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
            cStream.Write(inputByteArray, 0, inputByteArray.Length);
            cStream.FlushFinalBlock();
            return(Encoding.UTF8.GetString(mStream.ToArray()));
        }
        catch
        {
            return(decryptString);
        }
    }
Ejemplo n.º 11
0
    IEnumerator InitSetting()
    {
        CAssetLoader assetLoader = new CAssetLoader("GameSetting" + CCosmosEngine.GetConfig("AssetBundleExt"), null);

        while (!assetLoader.IsFinished)
        {
            yield return(null);
        }

        CGameSettingFiles gameSetting = (CGameSettingFiles)assetLoader.Asset;

        for (int i = 0; i < gameSetting.SettingFiles.Length; ++i)
        {
            GameSettings.Add(gameSetting.SettingFiles[i], gameSetting.SettingContents[i]);
        }

        CBase.Log("{0} setting files loaded.", GameSettings.Count);

        Object.Destroy(gameSetting);
        LoadFinished = true;
    }
Ejemplo n.º 12
0
    IEnumerator InitSetting()
    {
        var assetLoader = CStaticAssetLoader.Load("GameSetting" + CCosmosEngine.GetConfig("AssetBundleExt"), null);

        while (!assetLoader.IsFinished)
        {
            yield return(null);
        }

        CGameSettingFiles gameSetting = (CGameSettingFiles)assetLoader.TheAsset;

        for (int i = 0; i < gameSetting.SettingFiles.Length; ++i)
        {
            GameSettings[gameSetting.SettingFiles[i]] = gameSetting.SettingContents[i];
        }

        CDebug.Log("{0} setting files loaded.", GameSettings.Count);

        Object.Destroy(gameSetting);
        assetLoader.Release();
        LoadFinished = true;
    }
Ejemplo n.º 13
0
    public CUILoadState LoadWindow(string name, bool openWhenFinish, params object[] args)
    {
        if (UIWindows.ContainsKey(name))
        {
            CBase.LogError("[LoadWindow]多次重复LoadWindow: {0}", name);
        }
        CBase.Assert(!UIWindows.ContainsKey(name));

        string path = string.Format("UI/{0}_UI{1}", name, CCosmosEngine.GetConfig("AssetBundleExt"));

        CUILoadState openState = new CUILoadState(name);

        openState.IsStaticUI     = true;
        openState.OpenArgs       = args;
        openState.OpenWhenFinish = openWhenFinish;

        CResourceManager.Instance.StartCoroutine(LoadUIAssetBundle(path, name, openState));

        UIWindows.Add(name, openState);

        return(openState);
    }
Ejemplo n.º 14
0
    private void DoLoadTab <T>(string tabPath) where T : CBaseInfo
    {
#if GAME_CLIENT
        //using (CTabReader tabFile = CTabReader.LoadFromString(tabPath, CSettingManager.Instance.LoadSetting(tabPath)))
        using (CTabFile tabFile = CTabFile.LoadFromString(CSettingManager.Instance.LoadSetting(tabPath)))
#else
        // Editor Only
        string p1 = System.IO.Path.GetFullPath("Assets/" + CCosmosEngine.GetConfig("ProductRelPath") + "/") + tabPath;
        using (CTabFile tabFile = CTabFile.LoadFromString(System.IO.File.ReadAllText(p1)))
#endif
        {
            int rowStart = 1;
            Dictionary <string, CBaseInfo> dict = new Dictionary <string, CBaseInfo>();
            for (int i = rowStart; i < tabFile.GetHeight(); i++)
            {
                // 先读取ID, 获取是否之前已经读取过配置,
                // 如果已经读取过,那么获取原配置对象,并重新赋值 (因为游戏中其它地方已经存在它的引用了,直接替换内存泄露)
                string    id = tabFile.GetString(i, "Id"); // 获取ID是否存在, 如果已经存在,那么替换其属性,不new一个
                CBaseInfo existOne;
                if (dict.TryGetValue(id, out existOne))
                {
                    CBaseInfo existT = existOne;
                    CBaseInfo.LoadFromTab(typeof(T), ref existT, tabFile, i);  // 修改原对象,不new
                    (existT as CBaseInfo).Parse();
                }
                else
                {
                    T pInfo = CBaseInfo.LoadFromTab(typeof(T), tabFile, i) as T;
                    pInfo.Parse();
                    dict[pInfo.Id] = pInfo;  // 不存在,直接new
                }
            }

            SettingInfos[typeof(T)] = dict;
        }
    }
Ejemplo n.º 15
0
    static void ParseArgs(ref BuildOptions opt, ref string outputpath)
    {
        string[] args = System.Environment.GetCommandLineArgs();

        string productPath = Path.Combine(Application.dataPath, CCosmosEngine.GetConfig("ProductRelPath"));

        if (!Directory.Exists(productPath))
        {
            Directory.CreateDirectory(productPath);
        }

        if (args.Length >= 2)
        {
            CommandArgs commandArg = CommandLine.Parse(args);
            //List<string> lparams = commandArg.Params;
            Dictionary <string, string> argPairs = commandArg.ArgPairs;

            foreach (KeyValuePair <string, string> item in argPairs)
            {
                switch (item.Key)
                {
                case "BundleVersion":
                    PlayerSettings.bundleVersion = item.Value;
                    break;

                case "AndroidVersionCode":
                    PlayerSettings.Android.bundleVersionCode = System.Int32.Parse(item.Value);
                    break;

                case "AndroidKeyStoreName":
                    PlayerSettings.Android.keystoreName = item.Value;
                    break;

                case "AndroidKeyStorePass":
                    PlayerSettings.Android.keystorePass = item.Value;
                    break;

                case "AndroidkeyAliasName":
                    PlayerSettings.Android.keyaliasName = item.Value;
                    break;

                case "AndroidKeyAliasPass":
                    PlayerSettings.Android.keyaliasPass = item.Value;
                    break;

                case "BuildOptions":
                {
                    opt = BuildOptions.None;
                    string[] opts = item.Value.Split('|');
                    foreach (string o in opts)
                    {
                        opt = opt | (BuildOptions)System.Enum.Parse(typeof(BuildOptions), o);
                    }
                }
                break;

                case "Outputpath":
                    outputpath = item.Value;
                    break;
                }
                UnityEngine.Debug.Log(item.Key + " : " + item.Value);
            }
        }
    }
Ejemplo n.º 16
0
    /// <summary>
    /// return full path or build
    /// </summary>
    /// <param name="outputpath"></param>
    /// <param name="tag"></param>
    /// <param name="opt"></param>
    /// <returns></returns>
    static string PerformBuild(string outputpath, BuildTarget tag, BuildOptions opt)
    {
        EditorUserBuildSettings.SwitchActiveBuildTarget(tag);

        ParseArgs(ref opt, ref outputpath);

        string fullPath = System.IO.Path.Combine(Application.dataPath, System.IO.Path.Combine(CCosmosEngine.GetConfig("ProductRelPath"), outputpath));

        string fullDir = System.IO.Path.GetDirectoryName(fullPath);

        if (!Directory.Exists(fullDir))
        {
            Directory.CreateDirectory(fullDir);
        }

        CDebug.Log("Build Client {0} to: {1}", tag, fullPath);
        BuildPipeline.BuildPlayer(GetScenePaths(), fullPath, tag, opt);

        return(fullPath);
    }
Ejemplo n.º 17
0
    /// <summary>
    /// Initialize the path of AssetBundles store place ( Maybe in PersitentDataPath or StreamingAssetsPath )
    /// </summary>
    /// <returns></returns>
    public static void InitResourcePath()
    {
        string productPath     = Path.Combine(Application.dataPath, CCosmosEngine.GetConfig("ProductRelPath"));
        string assetBundlePath = Path.Combine(Application.dataPath, CCosmosEngine.GetConfig("AssetBundleRelPath"));
        string resourceDirName = Path.GetFileName(CCosmosEngine.GetConfig("AssetBundleRelPath"));

        BuildPlatformName = GetBuildPlatformName();

        string fileProtocol = GetFileProtocol();

        DocumentResourcesPathWithOutFileStart = string.Format("{0}/{1}/{2}/", GetAppDataPath(), resourceDirName, GetBuildPlatformName());  // 各平台通用
        DocumentResourcesPath = fileProtocol + DocumentResourcesPathWithOutFileStart;

        switch (Application.platform)
        {
        case RuntimePlatform.WindowsEditor:
        case RuntimePlatform.OSXEditor:
        {
            ApplicationPath = string.Format("{0}{1}/", fileProtocol, productPath);
            ResourcesPath   = fileProtocol + assetBundlePath + "/" + BuildPlatformName + "/";
            ResourcesPathWithOutFileProtocol = assetBundlePath + "/" + BuildPlatformName + "/";
        }
        break;

        case RuntimePlatform.WindowsPlayer:
        case RuntimePlatform.OSXPlayer:
        {
            string path = Application.dataPath.Replace('\\', '/');
            path            = path.Substring(0, path.LastIndexOf('/') + 1);
            ApplicationPath = string.Format("{0}{1}/", fileProtocol, path);
            ResourcesPath   = string.Format("{0}{1}{2}/{3}", fileProtocol, path, resourceDirName, GetBuildPlatformName());
            ResourcesPathWithOutFileProtocol = string.Format("{0}{1}/{2}/", path, resourceDirName, GetBuildPlatformName());
        }
        break;

        case RuntimePlatform.Android:
        {
            ApplicationPath = string.Concat("jar:", fileProtocol, Application.dataPath, "!/assets/");

            ResourcesPath = string.Concat(ApplicationPath, GetBuildPlatformName(), "/");
            ResourcesPathWithOutFileProtocol = string.Concat(Application.dataPath, "!/assets/", GetBuildPlatformName() + "/");          // 注意,StramingAsset在Android平台中,是在壓縮的apk里,不做文件檢查
        }
        break;

        case RuntimePlatform.IPhonePlayer:
        {
            ApplicationPath = System.Uri.EscapeUriString(fileProtocol + Application.streamingAssetsPath + "/"); // MacOSX下,带空格的文件夹,空格字符需要转义成%20
            ResourcesPath   = string.Format("{0}{1}/", ApplicationPath, GetBuildPlatformName());                // only iPhone need to Escape the f*****g Url!!! other platform works without it!!! Keng Die!
            ResourcesPathWithOutFileProtocol = Application.streamingAssetsPath + "/" + GetBuildPlatformName() + "/";
        }
        break;

        default:
        {
            CBase.Assert(false);
        }
        break;
        }

        if (Debug.isDebugBuild)
        {
            CBase.Log("ResourceManager ApplicationPath: {0}", ApplicationPath);
            CBase.Log("ResourceManager ResourcesPath: {0}", ResourcesPath);
            CBase.Log("ResourceManager DocumentResourcesPath: {0}", DocumentResourcesPath);
            CBase.Log("================================================================================");
        }
    }
Ejemplo n.º 18
0
    IEnumerator _Init(string path, string assetName)
    {
        IsLoadAssetBundle = CCosmosEngine.GetConfig("IsLoadAssetBundle").ToInt32() != 0;
        AssetInBundleName = assetName;

        UnityEngine.Object getAsset = null;
        if (!IsLoadAssetBundle)
        {
            string extension = System.IO.Path.GetExtension(path);
            path = path.Substring(0, path.Length - extension.Length);  // remove extensions

            getAsset = Resources.Load <UnityEngine.Object>(path);
            if (getAsset == null)
            {
                CDebug.LogError("Asset is NULL(from Resources Folder): {0}", path);
            }
            OnFinish(getAsset);
        }
        else
        {
            var bundleLoader = CAssetBundleLoader.Load(path);

            while (!bundleLoader.IsFinished)
            {
                if (IsReadyDisposed)   // 中途释放
                {
                    bundleLoader.Release();
                    OnFinish(null);
                    yield break;
                }
                Progress = bundleLoader.Progress;
                yield return(null);
            }
            var assetBundle = bundleLoader.Bundle;

            System.DateTime beginTime = System.DateTime.Now;
            if (AssetInBundleName == null)
            {
                // 经过AddWatch调试,.mainAsset这个getter第一次执行时特别久,要做序列化
                //AssetBundleRequest request = assetBundle.LoadAsync("", typeof(Object));// mainAsset
                //while (!request.isDone)
                //{
                //    yield return null;
                //}
                try
                {
                    CDebug.Assert(getAsset = assetBundle.mainAsset);
                }
                catch
                {
                    CDebug.LogError("[OnAssetBundleLoaded:mainAsset]{0}", path);
                }
            }
            else
            {
                // TODO: 未测试过这几行!~~
                AssetBundleRequest request = assetBundle.LoadAsync(AssetInBundleName, typeof(Object));
                while (!request.isDone)
                {
                    yield return(null);
                }

                getAsset = request.asset;
            }

            CResourceModule.LogLoadTime("AssetFileBridge", path, beginTime);

            if (getAsset == null)
            {
                CDebug.LogError("Asset is NULL: {0}", path);
            }

            bundleLoader.Release();  // 释放Bundle(WebStream)
        }

        if (Application.isEditor)
        {
            if (getAsset != null)
            {
                CResourceLoadObjectDebugger.Create(getAsset.GetType().Name, Url, getAsset as UnityEngine.Object);
            }
        }

        if (getAsset != null)
        {
            // 更名~ 注明来源asset bundle 带有类型
            getAsset.name = string.Format("{0}~{1}", getAsset, Url);
        }
        OnFinish(getAsset);
    }
Ejemplo n.º 19
0
    public static System.Func <string, string> CustomGetResourcesPath;                                             // 自定义资源路径。。。

    /// <summary>
    /// 统一在字符串后加上.box, 取决于配置的AssetBundle后缀
    /// </summary>
    /// <param name="path"></param>
    /// <param name="formats"></param>
    /// <returns></returns>
    public static string GetAssetBundlePath(string path, params object[] formats)
    {
        return(string.Format(path + CCosmosEngine.GetConfig("AssetBundleExt"), formats));
    }
Ejemplo n.º 20
0
 public static string GetBuildRelPath(string uiName)
 {
     return(string.Format("UI/{0}_UI{1}", uiName, CCosmosEngine.GetConfig("AssetBundleExt")));
 }
Ejemplo n.º 21
0
    public bool BuildPkg(string file)
    {
        //if (!CBuildTools.CheckNeedBuild(file))
        //{
        //    return false;
        //}

        AudioClip audioClip = AssetDatabase.LoadAssetAtPath(file, typeof(AudioClip)) as AudioClip;

        if (audioClip != null)
        {
            string subDirName = Path.GetFileName(Path.GetDirectoryName(file));
            string exportFile = string.Format("Audio/{0}/{1}_Audio{2}", subDirName, Path.GetFileNameWithoutExtension(file), CCosmosEngine.GetConfig("AssetBundleExt"));

            CBuildTools.BuildAssetBundle(audioClip, exportFile);

            //CBuildTools.MarkBuildVersion(file);
        }

        return(true);
    }