Esempio n. 1
0
    /// <summary>
    /// Use Coroutine to initialize the two base modules: Resource & UI
    /// </summary>
    IEnumerator DoInit()
    {
        ICModule[] baseModules = new ICModule[] {  // 基础三件套
            CResourceManager.Instance,
            CUIManager.Instance,
        };
        foreach (ICModule mod in baseModules)
        {
            yield return(StartCoroutine(mod.Init()));
        }

        CBase.Log("Finish Init ResourceManager + UIManager!");

        if (BeforeInitModules != null)
        {
            yield return(StartCoroutine(BeforeInitModules()));
        }


        yield return(StartCoroutine(DoInitModules()));

        if (AfterInitModules != null)
        {
            yield return(StartCoroutine(AfterInitModules()));
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Use Coroutine to initialize the two base modules: Resource & UI
    /// </summary>
    IEnumerator DoInit()
    {
        ICModule[] baseModules = new ICModule[] {  // 基础三件套
            CResourceManager.Instance,
            CUIManager.Instance,
        };
        foreach (ICModule mod in baseModules)
        {
            float startInitTime = Time.time;
            yield return(StartCoroutine(mod.Init()));

            if (Debug.isDebugBuild)
            {
                CBase.Log("Init Module: #{0}# Time:{1}", mod.GetType().FullName, Time.time - startInitTime);
            }
        }

        CBase.Log("Finish Init ResourceManager + UIManager!");

        if (BeforeInitModules != null)
        {
            yield return(StartCoroutine(BeforeInitModules()));
        }


        yield return(StartCoroutine(DoInitModules()));

        if (AfterInitModules != null)
        {
            yield return(StartCoroutine(AfterInitModules()));
        }
    }
    static void CheckConfigFile()
    {
        if (!File.Exists(ConfFilePath))
        {
            CTabFile confFile = new CTabFile();
            confFile.NewRow();
            confFile.NewColumn("Key");
            confFile.NewColumn("Value");
            confFile.NewColumn("Comment");


            foreach (string[] strArr in DefaultConfigFileContent)
            {
                int row = confFile.NewRow();
                confFile.SetValue <string>(row, "Key", strArr[0]);
                confFile.SetValue <string>(row, "Value", strArr[1]);
                confFile.SetValue <string>(row, "Comment", strArr[2]);
            }
            confFile.Save(ConfFilePath);

            CBase.Log("新建CosmosEngine配置文件: {0}", ConfFilePath);
            AssetDatabase.Refresh();
        }

        ConfFile = CTabFile.LoadFromFile(ConfFilePath);
    }
Esempio n. 4
0
    public static void LogLoadTime(string resType, string resPath, System.DateTime begin)
    {
        if (LogLevel < (int)LoadingLogLevel.ShowTime)
        {
            return;
        }

        CBase.Log("[Load] {0}, {1}, {2}s", resType, resPath, (System.DateTime.Now - begin).TotalSeconds);
    }
Esempio n. 5
0
    public static void LogRequest(string resType, string resPath)
    {
        if (LogLevel < (int)LoadingLogLevel.ShowDetail)
        {
            return;
        }

        CBase.Log("[Request] {0}, {1}", resType, resPath);
    }
Esempio n. 6
0
    public static uint BuildAssetBundle(Object asset, string path, BuildTarget buildTarget)
    {
        if (asset == null || string.IsNullOrEmpty(path))
        {
            BuildError("BuildAssetBundle: {0}", path);
            return(0);
        }

        string     tmpPrefabPath = string.Format("Assets/{0}.prefab", asset.name);
        PrefabType prefabType    = PrefabUtility.GetPrefabType(asset);
        GameObject tmpObj        = null;
        Object     tmpPrefab     = null;

        string relativePath = path;

        path = MakeSureExportPath(path, buildTarget);

        if ((prefabType == PrefabType.None && AssetDatabase.GetAssetPath(asset) == string.Empty) ||
            (prefabType == PrefabType.ModelPrefabInstance))
        {
            tmpObj    = (GameObject)GameObject.Instantiate(asset);
            tmpPrefab = PrefabUtility.CreatePrefab(tmpPrefabPath, tmpObj, ReplacePrefabOptions.ConnectToPrefab);
            asset     = tmpPrefab;
        }
        else if (prefabType == PrefabType.PrefabInstance)
        {
            asset = PrefabUtility.GetPrefabParent(asset);
        }


        HookFunc(typeof(CBuildTools), "BeforeBuildAssetBundle", asset, path, relativePath);

        uint crc;

        BuildPipeline.BuildAssetBundle(
            asset,
            null,
            path,
            out crc,
            BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.DeterministicAssetBundle,
            buildTarget);

        if (tmpObj != null)
        {
            GameObject.DestroyImmediate(tmpObj);
            AssetDatabase.DeleteAsset(tmpPrefabPath);
        }

        CBase.Log("生成文件: {0}", path);


        HookFunc(typeof(CBuildTools), "AfterBuildAssetBundle", asset, path, relativePath);

        return(crc);
    }
Esempio n. 7
0
    public override void Export(string path)
    {
        path = path.Replace('\\', '/');

        string[] fileArray = Directory.GetFiles(path, "*.prefab");
        foreach (string file in fileArray)
        {
            string filePath = file.Replace('\\', '/');
            CBase.Log("Build Func To: " + filePath);
        }
    }
Esempio n. 8
0
    public static string EndRecordTime(bool printLog = true)
    {
        RecordPos--;
        double s = (UnityEngine.Time.realtimeSinceStartup - RecordTime[RecordPos]);

        if (printLog)
        {
            CBase.Log("[RecordTime] {0} use {1}s", RecordKey[RecordPos], s);
        }
        return(string.Format("[RecordTime] {0} use {1}s.", RecordKey[RecordPos], s));
    }
Esempio n. 9
0
    void OnGameSettingsInit()
    {
        CGameSettings _ = CGameSettings.Instance;

        CBase.Log("Begin Load tab file...");
        _.LoadTab <CTestTabInfo>("setting/test_tab.bytes");
        CBase.Log("Output the tab file...");
        foreach (CTestTabInfo info in _.GetInfos <CTestTabInfo>())
        {
            CBase.Log("Id:{0}, Name: {1}", info.Id, info.Name);
        }
    }
Esempio n. 10
0
    IEnumerator DoInitModules()
    {
        foreach (ICModule initModule in GameModules)
        {
            float startInitTime = Time.time;
            yield return(StartCoroutine(initModule.Init()));

            if (Debug.isDebugBuild)
            {
                CBase.Log("Init Module: #{0}# Time:{1}", initModule.GetType().FullName, Time.time - startInitTime);
            }
        }
    }
Esempio n. 11
0
    void OnApplicationQuit()
    {
        if (!IsApplicationQuited)
        {
            CBase.Log("OnApplicationQuit!");
        }

        IsApplicationQuited = true;

        if (ApplicationQuitEvent != null)
        {
            ApplicationQuitEvent();
        }
    }
Esempio n. 12
0
    public IEnumerator Init()
    {
        switch (Application.platform)
        {
        case RuntimePlatform.Android:
        case RuntimePlatform.IPhonePlayer:
        case RuntimePlatform.WP8Player:
            SettingOutPackage = false;
            break;
        }

        CBase.Log("Load setting out of package = {0}", SettingOutPackage.ToString());
        yield return(CResourceManager.Instance.StartCoroutine(InitSetting()));
    }
Esempio n. 13
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;
    }
Esempio n. 14
0
    public void DestroyWindow(string name)
    {
        CUILoadState uiState;

        UIWindows.TryGetValue(name, out uiState);
        if (uiState == null || uiState.UIWindow == null)
        {
            CBase.Log("{0} has been destroyed", name);
            return;
        }

        UnityEngine.Object.Destroy(uiState.UIWindow.gameObject);

        uiState.UIWindow = null;

        UIWindows.Remove(name);
    }
Esempio n. 15
0
    // 鉤子函數, 動態改變某些打包行為
    public static bool HookFunc(System.Type classType, string funcName, params object[] args)
    {
        if (classType == null)
        {
            return(false);
        }

        MethodInfo methodInfo = classType.GetMethod(funcName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);

        if (methodInfo == null)
        {
            return(false);
        }

        CBase.Log("HookFunc- {0}:{1}", classType.Name, funcName);
        methodInfo.Invoke(null, args);

        return(true);
    }
Esempio n. 16
0
    static void PerformBuild(string outputpath, BuildTarget tag, BuildOptions opt)
    {
        RefreshProgramVersion();

        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);
        }

        CBase.Log("Build Client {0} to: {1}", tag, outputpath);
        BuildPipeline.BuildPlayer(GetScenePaths(), fullPath, tag, opt);
    }
Esempio n. 17
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;
    }
Esempio n. 18
0
    private void Init()
    {
        IsRootUser = CTool.HasWriteAccessToFolder(Application.dataPath);  // Root User运行时,能穿越沙盒写DataPath, 以此为依据

        if (Debug.isDebugBuild)
        {
            RenderWatcher = new CFpsWatcher(0.95f);
        }

        if (Debug.isDebugBuild)
        {
            CBase.Log("====================================================================================");
            CBase.Log("Application.platform = {0}", Application.platform);
            CBase.Log("Application.dataPath = {0} , WritePermission: {1}", Application.dataPath, IsRootUser);
            CBase.Log("Application.streamingAssetsPath = {0} , WritePermission: {1}", Application.streamingAssetsPath, CTool.HasWriteAccessToFolder(Application.streamingAssetsPath));
            CBase.Log("Application.persistentDataPath = {0} , WritePermission: {1}", Application.persistentDataPath, CTool.HasWriteAccessToFolder(Application.persistentDataPath));
            CBase.Log("Application.temporaryCachePath = {0} , WritePermission: {1}", Application.temporaryCachePath, CTool.HasWriteAccessToFolder(Application.temporaryCachePath));
            CBase.Log("Application.unityVersion = {0}", Application.unityVersion);
            CBase.Log("SystemInfo.deviceModel = {0}", SystemInfo.deviceModel);
            CBase.Log("SystemInfo.deviceUniqueIdentifier = {0}", SystemInfo.deviceUniqueIdentifier);
            CBase.Log("====================================================================================");
        }
        StartCoroutine(DoInit());
    }
Esempio n. 19
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("================================================================================");
        }
    }
Esempio n. 20
0
    static void RefreshProgramVersion()
    {
        string cmd = string.Format("{0}/GetSvnInfo.bat", Application.dataPath);

        var p    = new Process();
        var si   = new ProcessStartInfo();
        var path = Environment.SystemDirectory;

        if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.iPhone)
        {
            path = Path.Combine(path, @"sh");
        }
        else
        {
            path = Path.Combine(path, @"cmd.exe");
        }

        si.FileName = path;
        if (!cmd.StartsWith(@"/"))
        {
            cmd = @"/c " + cmd;
        }
        si.Arguments              = cmd;
        si.UseShellExecute        = false;
        si.CreateNoWindow         = true;
        si.RedirectStandardOutput = true;
        si.RedirectStandardError  = true;
        p.StartInfo = si;

        p.Start();
        p.WaitForExit();

        var str = p.StandardOutput.ReadToEnd();

        if (!string.IsNullOrEmpty(str))
        {
            string programVersionFile = string.Format("{0}/Resources/ProgramVersion.txt", Application.dataPath);

            Regex regex = new Regex(@"Revision: (\d+)");  // 截取svn版本号
            Match match = regex.Match(str);

            string szRevision = match.Groups[1].ToString();
            int    nRevision  = szRevision.ToInt32();
            using (FileStream fs = new FileStream(programVersionFile, FileMode.Create))
            {
                using (StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8))
                {
                    sw.Write(nRevision.ToString());
                }
            }


            CBase.Log("Refresh ProgramVersion.txt!! SVN Version: {0}", nRevision);
        }
        else
        {
            CBase.LogError("Error Read svn Revision!");
        }


        str = p.StandardError.ReadToEnd();
        if (!string.IsNullOrEmpty(str))
        {
            CBase.LogError(str);
        }
    }