Beispiel #1
0
    public T CallAPI <T>(string apiName, params object[] args)
    {
        if (IsTestType())
        {
            return(default(T));
        }
#if UNITY_STANDALONE_WIN || UNITY_EDITOR
        return(default(T));
#elif UNITY_ANDROID
        T result;
        using (AndroidJavaClass cls = new AndroidJavaClass(ClassName)){
            try
            {
                result = cls.CallStatic <T>(apiName, args);
            }
            catch (Exception e)
            {
                JZLog.LogError("CallAPI:" + apiName + "," + ClassName + "," + e.Message + "," + e.StackTrace);
                result = default(T);
            }
        }
        return(result);
#elif UNITY_IPHONE
        return(default(T));
#endif
    }
Beispiel #2
0
        public void SetEndValue(float endValue, string loadingHint = null, Action onProgressEnd = null)
        {
#if UNITY_EDITOR
            if (endValue < 1f)
            {
                JZLog.Log(" ===== 加载进度条到 ====>> " + endValue);
            }
            else
            {
                JZLog.Log(" ===== 结束加载进度条 ====>> ");
            }
#endif

            m_endValue = endValue;
            if (m_endValue - m_curValue > 0.2f)
            {
                m_speed = (m_endValue - m_curValue) / 12;
            }

            if (null != loadingHint)
            {
                txtLoadingHint.text = loadingHint;
            }

            if (endValue >= 1f)
            {
                if (null != onProgressEnd)
                {
                    m_onProgressEnd = onProgressEnd;
                }
            }
        }
Beispiel #3
0
    public void PlayAnimations(tk2dSpriteAnimationClip.WrapMode mode, float fps)
    {
        string clipName = GetClipName();

        Dictionary <string, tk2dSpriteAnimator> .Enumerator etor = animators.GetEnumerator();
        while (etor.MoveNext())
        {
            tk2dSpriteAnimator animator = etor.Current.Value;
            if (!animator.gameObject.activeInHierarchy)
            {
                continue;
            }

            tk2dSpriteAnimationClip clip = animator.GetClipByName(clipName);
            if (null == clip)
            {
                clipName = GetClipName(PlayerAniConifg.directionStatus.SOUTHEAST, action, isRiding);
                clip     = animator.GetClipByName(clipName);
            }

            if (null == clip)
            {
                JZLog.LogWarning(etor.Current.Key + " 没有该动画数据: " + clipName);
                continue;
            }

            clip.wrapMode          = mode;
            clip.fps               = fps;
            animator.DefaultClipId = 0;
            animator.PlayFromFrame(clip, 0);

            CheckRotation(etor.Current.Key, direction, animator);
            CheckLayer(etor.Current.Key, animator.gameObject.transform);
        }
    }
Beispiel #4
0
    /// <summary>
    /// 写入版本配置文件
    /// </summary>
    /// <param name="url"></param>
    /// <param name="config"></param>
    private void M_Write(string name, VersionBundleConfig config)
    {
#if !UNITY_WEBPLAYER
        string path = PathUtils.MakeFilePath(name, PathUtils.PathType.MobileDiskWrite);
        Debug.LogWarning("write path: " + path);
        try
        {
            StreamWriter sw;
            FileInfo     fInfo = new FileInfo(path);
            if (!fInfo.Exists)
            {
                string directoryPath = path.Substring(0, path.LastIndexOf('/'));
                if (!Directory.Exists(directoryPath))
                {
                    Directory.CreateDirectory(directoryPath);
                }
                sw = fInfo.CreateText();
            }
            else
            {
                fInfo.Delete();
                fInfo = new FileInfo(path);
                sw    = fInfo.CreateText();
            }
            string content = JsonFx.Json.JsonWriter.Serialize(config);
            sw.Write(content);
            sw.Close();
            sw.Dispose();
        }
        catch (Exception error)
        {
            JZLog.LogError("VersionManager:Write - " + "Error: " + error.Message);
        }
#endif
    }
Beispiel #5
0
 void OnApplicationQuit()
 {
     isQuit = true;
     JZLog.Log("Quit GameWorld");
     NetworkManager.instance.Close();
     ResHelper.Instance().StopDownloadHttp();
 }
Beispiel #6
0
    IEnumerator M_LoadConfig(Action onComplete, Action onError)
    {
        string url    = GameConfig.HOST_RES() + "ab/" + GameConfig.LOCAL_CONFIG_FILE + "?t=" + TimeUtils.CurLocalTimeMilliSecond();
        WWW    loader = new WWW(url);

        yield return(loader);

        if (string.IsNullOrEmpty(loader.error))
        {
            VersionBundleConfig config = JsonFx.Json.JsonReader.Deserialize <VersionBundleConfig>(loader.text);
            m_loadedConfig = config;
            M_CacheBundles();
            if (onComplete != null)
            {
                onComplete();
            }
        }
        else
        {
            JZLog.LogError(loader.error);
            if (onError != null)
            {
                onError();
            }
        }
    }
Beispiel #7
0
        public void StartProgress(float endValue, string loadingHint, string imgBG)
        {
#if UNITY_EDITOR
            JZLog.Log(" ===== 开始加载进度条到 ====>> " + endValue);
#endif

            m_endValue          = endValue;
            txtLoadingHint.text = loadingHint;
            P_SetProgress(0f);
        }
Beispiel #8
0
        public void StartProgress(int career, float endValue, string loadingHint)
        {
#if UNITY_EDITOR
            JZLog.Log(" ===== 开始加载进度条到 ====>> " + endValue);
#endif

            m_endValue            = endValue;
            m_txtLoadingHint.text = loadingHint;
            P_SetProgress(0f);
            m_startRotation = true;
        }
Beispiel #9
0
 public void Init()
 {
     try
     {
         OnInit();
     }
     catch (Exception e)
     {
         JZLog.LogError(GetName() + " Init Fail, Message:" + e.Message + ",StackTrace:" + e.StackTrace);
     }
 }
Beispiel #10
0
 public void Disable()
 {
     try
     {
         OnDisable();
     }
     catch (Exception e)
     {
         JZLog.LogError(GetName() + " Disable Fail, Message:" + e.Message + ",StackTrace:" + e.StackTrace);
     }
 }
Beispiel #11
0
 /// <summary>
 /// 注销管理者,注意:该方法仅供GlobalManager调用,其他地方想要触发Destroy,请使用GlobalManager.RemoveManager方法
 /// </summary>
 public void Destroy()
 {
     try
     {
         OnDisable();
         OnDestroy();
     }
     catch (Exception e)
     {
         JZLog.LogError("Message:" + e.Message + ",StackTrace:" + e.StackTrace + ",Source:" + e.Source);
     }
 }
Beispiel #12
0
    private string M_GetOT(Language language, string key)
    {
        if (m_ots.ContainsKey(language))
        {
            Dictionary <string, string> content = m_ots[language];
            if (content.ContainsKey(key))
            {
                return(content[key]);
            }
        }

        JZLog.Log(" 没有该多语言配置:" + language.ToString() + " ==> " + key);
        return("");
    }
Beispiel #13
0
 /*********************************
 * 函数说明: 添加一个管理器
 * 返 回 值: void
 * 参数说明: manager
 * 注意事项: 无
 *********************************/
 public void AddManager(IManager manager)
 {
     if (manager == null)
     {
         JZLog.LogError("You can not add a null manager");
         return;
     }
     // 防止重复添加
     if (m_managers.ContainsKey(manager.GetNameHash()) == true)
     {
         JZLog.LogError("You can not add mulit manager : " + manager.GetName());
         return;
     }
     m_managers.Add(manager.GetNameHash(), manager);
 }
Beispiel #14
0
    /// <summary>
    /// 更新所有序列帧
    /// </summary>
    public void playAllAnimation()
    {
        string clipName = GetClipName();

        Dictionary <string, tk2dSpriteAnimator> .Enumerator etor = animators.GetEnumerator();
        while (etor.MoveNext())
        {
            tk2dSpriteAnimator animator = etor.Current.Value;
            if (!animator.gameObject.activeSelf)
            {
                continue;
            }

            tk2dSpriteAnimationClip clip = animator.GetClipByName(clipName);

            if (null == clip)
            {
                clipName = GetClipName(PlayerAniConifg.directionStatus.SOUTHEAST, action, isRiding);
                clip     = animator.GetClipByName(clipName);
            }

            if (null == clip)
            {
                JZLog.LogWarning(etor.Current.Key + " 没有该动画数据: " + clipName);
                continue;
            }

            switch (action)
            {
            case PlayerAniConifg.actionStatus.DIE:
            case PlayerAniConifg.actionStatus.ATTACK:
            case PlayerAniConifg.actionStatus.HURT:
                clip.wrapMode = tk2dSpriteAnimationClip.WrapMode.Once;
                break;

            default:
                clip.wrapMode = tk2dSpriteAnimationClip.WrapMode.Loop;
                break;
            }

            clip.fps = 30f;
            animator.DefaultClipId = 0;
            animator.PlayFromFrame(clip, 0);

            CheckRotation(etor.Current.Key, direction, animator);
            CheckLayer(etor.Current.Key, animator.gameObject.transform);
        }
    }
Beispiel #15
0
    void Awake()
    {
#if UNITY_EDITOR
        Resources.UnloadUnusedAssets();
        System.GC.Collect();
#endif
        Application.runInBackground = true;
        Application.targetFrameRate = defaultFPS;
        JZLog.Init(useLog, reportError, logLevel);
        GameConfig.useLocalRes    = useLocalRes;
        GameConfig.showFPS        = showFPS;
        GameConfig.language       = language;
        GameConfig.showLogConsole = showLogConsole;
        PathUtils.Init();
#if UNITY_EDITOR
        SceneHelper.instance.SetTransitionType(type);
        //Debug.Log(Application.persistentDataPath);
#endif
    }
Beispiel #16
0
    public void CallAPI(string apiName, params object[] args)
    {
        if (IsTestType())
        {
            return;
        }
#if UNITY_STANDALONE_WIN || UNITY_EDITOR
#elif UNITY_ANDROID
        using (AndroidJavaClass cls = new AndroidJavaClass(ClassName)){
            try
            {
                cls.CallStatic(apiName, args);
            }
            catch (Exception e)
            {
                JZLog.LogError("CallAPI:" + apiName + "," + ClassName + "," + e.Message + "," + e.StackTrace);
            }
        }
#elif UNITY_IPHONE
#endif
    }
Beispiel #17
0
 /*********************************
 * 函数说明: 移除一个管理器
 * 返 回 值: void
 * 参数说明: manager
 * 注意事项: 无
 *********************************/
 public void RemoveManager(IManager manager)
 {
     if (manager == null)
     {
         JZLog.LogError("You can not remove a null " + name);
         return;
     }
     if (m_managers.ContainsKey(manager.GetNameHash()) == false)
     {
         JZLog.LogError("You have not add manager " + manager.GetName());
         return;
     }
     if (manager != m_managers[manager.GetNameHash()])
     {
         JZLog.LogError(manager.GetName() + " is not match the exist manager!!");
         return;
     }
     manager.Destroy();
     m_managers.Remove(manager.GetNameHash());
     manager = null;
 }
Beispiel #18
0
    private static void AddOT(Language language, string text)
    {
        if (!m_ots.ContainsKey(language))
        {
            m_ots.Add(language, new Dictionary <string, string>());
        }

        Dictionary <string, string> _text = m_ots[language];


        string[] noComment = Regex.Split(text, @"\s*//.*\s*");
        for (int it = 0; it < noComment.Length; it++)
        {
            string item = noComment[it];
            if (string.IsNullOrEmpty(item))
            {
                continue;
            }
            MatchCollection matches = Regex.Matches(item, @"\w+=");
            string[]        values  = Regex.Split(item, @"\w+=");
            for (int i = 0; i < matches.Count; i++)
            {
                string key = matches[i].Value;
                key = key.Substring(0, key.Length - 1);
                if (_text.ContainsKey(key))
                {
#if  UNITY_EDITOR
                    JZLog.LogError("AddOT - " + "Error: Duplicate " + key + " in OT files");
                    continue;
#endif
                    _text.Remove(key);
                }
                string value = values[i + 1];
                value = Regex.Replace(value, @"[\t\r\n]+", ""); //去掉TAB,回车符
                value = Regex.Replace(value, @"\\n", "\n");     //将\n替换成换行符
                _text.Add(key, value);
            }
        }
    }
Beispiel #19
0
        /// <summary>
        /// 异步连接回调
        /// </summary>
        /// <param name="ar"></param>
        private void M_ConnectCallBack(IAsyncResult ar)
        {
            try
            {
                Socket client = ar.AsyncState as Socket;
                if (null != client)
                {
                    client.EndConnect(ar);
                    if (m_socket.Connected)
                    {
                        m_socket.ReceiveBufferSize = SIZE_READ_BUFFER;
                        m_socket.SendBufferSize    = SIZE_WRITE_BUFFER;
                        m_socket.NoDelay           = true;

                        m_status      = SocketStatus.Connected;
                        m_asyncStatus = AsyncStatus.ConnectSucceed;
                        m_active      = true;
                        m_Receive.PrepareReadHeader(HEAD_LENGTH);
                        Receive();
                    }
                }
                else
                {
                    JZLog.LogError(" connect fail reason  ar.AsyncStat return null ");
                    m_asyncStatus = AsyncStatus.ConnectFailed;
                    m_socket.Close();
                    m_status = SocketStatus.Closed;
                }
            }
            catch (Exception e)
            {
                JZLog.LogError("M_ConnectCallBack fail error " + e.Message);
                m_asyncStatus = AsyncStatus.ConnectFailed;
                m_socket.Close();
                m_status = SocketStatus.Closed;
            }
        }
Beispiel #20
0
    /************************************
    * 函数说明: 获取本地可读资源路径
    * 返 回 值: string
    ************************************/
    public static string GetReadablePath(string fileName, ref PathUtils.PathType eType, bool addPre = true)
    {
        string szUrl = "";

        do
        {
            //if (!GameConfig.useLocalRes)
            {
                if (eType == PathUtils.PathType.None)
                {
                    switch (platform)
                    {
                    case RuntimePlatform.OSXEditor:
                    case RuntimePlatform.OSXPlayer:
                    case RuntimePlatform.WindowsPlayer:
                    case RuntimePlatform.WindowsEditor:
                        szUrl = PathUtils.MakeFilePath(fileName, PathUtils.PathType.MobileDiskWrite);
                        break;

                    case RuntimePlatform.Android:
                        szUrl = PathUtils.MakeFilePath(fileName, PathUtils.PathType.MobileDiskWrite);
                        break;

                    case RuntimePlatform.IPhonePlayer:
                        szUrl = PathUtils.MakeFilePath(fileName, PathUtils.PathType.MobileDiskWrite);
                        break;

                    default:
                        JZLog.LogError("GetBundle : Error For Platform");
                        break;
                    }

                    if (GameUtils.FileExist(szUrl) == true)
                    {
                        eType = PathUtils.PathType.MobileDiskWrite;
                        break;
                    }
                }
            }

            /** @brief: 默认手机盘只读数据 */
            if (eType == PathUtils.PathType.None)
            {
                switch (platform)
                {
                case RuntimePlatform.OSXEditor:
                case RuntimePlatform.OSXPlayer:
                case RuntimePlatform.WindowsPlayer:
                case RuntimePlatform.WindowsEditor:
                    szUrl = PathUtils.MakeFilePath(fileName, PathUtils.PathType.MobileDiskStreamAssert);
                    break;

                case RuntimePlatform.Android:
                    szUrl = dataPath + "!assets/" + fileName;
                    break;

                case RuntimePlatform.IPhonePlayer:
                    szUrl = PathUtils.MakeFilePath(fileName, PathUtils.PathType.MobileDiskStreamAssert);
                    break;

                default:
                    JZLog.LogError("GetBundle : Error For Platform");
                    break;
                }

                eType = PathUtils.PathType.MobileDiskStreamAssert;
            }
        } while (false);
        return(szUrl);
    }
Beispiel #21
0
    /************************************
    * 函数说明: 内部加载资源
    * 返 回 值: System.Collections.IEnumerator
    * 参数说明: resRequest
    * 注意事项:
    ************************************/
    private IEnumerator LoadResources(string szPkgName, System.Action <string, AssetBundle> callback)
    {
        do
        {
            /** @brief: 检查参数 */
            if (string.IsNullOrEmpty(szPkgName))
            {
                //JZLog.LogError("AsyncLoadRes : Error szPkgName == null");
                yield break;
            }

            ResourceMgrData resourceData = null;
            /** @brief: 检查是否加载过此包 或者正在加载此包 */
            if (gDicPkgResource.ContainsKey(szPkgName) == false)
            {
                resourceData = new ResourceMgrData()
                {
                    eState      = ResourceMgrData.State.None,
                    assetBundle = null
                };
                gDicPkgResource[szPkgName] = resourceData;
            }
            else
            {
                resourceData = gDicPkgResource[szPkgName];
                if (resourceData.eState == ResourceMgrData.State.LoadFinish)
                {
                    if (null != callback)
                    {
                        callback(szPkgName, resourceData.assetBundle);
                        callback = null;
                    }
                    yield break;
                }
            }

            /** @brief: 避免一帧时间过长 */
            /** @brief: Non matching Profiler.EndSample (BeginSample and EndSample count must match) */
            /** @brief: One is catching an exception from another object, the other is long frame times. If it's either of those two, it can only be fixed by the Unity team. */
            // yield return new WaitForEndOfFrame();
            if (gDicPkgResource.ContainsKey(szPkgName) == false)
            {
                //JZLog.LogError("LoadResources : Warning Pkg == " + szPkgName + " Have no this Pkg , MayBe Remove it!");
                yield break;
            }

            if (resourceData.eState == ResourceMgrData.State.None)
            {
                resourceData.eState = ResourceMgrData.State.Loading;
            }
            else
            {
                break;
            }

            VersionBundle bundle = VersionHelper.instance.GetBundle(szPkgName);
            if (null != bundle && null != bundle.dependency && bundle.dependency.Length > 0)
            {
                for (int i = 0; i < bundle.dependency.Length; i++)
                {
                    string depName = bundle.dependency[i];
                    if (gDicPkgResource.ContainsKey(depName) == false || gDicPkgResource[depName].assetBundle == null)
                    {
                        yield return(GameWorld.instance.StartCoroutine(LoadResources(depName, null)));
                    }
                }
            }

            AssetBundle asset = null;
            if (VersionHelper.instance.HasBundleHttp(szPkgName))
            {
                VersionBundle httpAB = VersionHelper.instance.GetBundle(szPkgName);
                string        szUrl  = GameConfig.HOST_RES() + httpAB.id + "?v=" + httpAB.versionValue;
                WWW           www    = WWW.LoadFromCacheOrDownload(szUrl, httpAB.versionValue, httpAB.crc);
                yield return(www);

                if (null != www && null == www.error)
                {
                    asset = www.assetBundle;
                    www.Dispose();
                    www = null;
                }
                else
                {
                    JZLog.LogError("LoadResources : Load from www Error: " + szUrl + "\n" + www.error);
                }
            }
            else
            {
                PathUtils.PathType       eType = PathUtils.PathType.None;
                string                   szUrl = PathUtils.GetReadablePath(szPkgName, ref eType, false);
                AssetBundleCreateRequest abcr  = AssetBundle.LoadFromFileAsync(szUrl);
                yield return(abcr);

                if (null != abcr.assetBundle)
                {
                    asset = abcr.assetBundle;
                }
                else
                {
                    JZLog.LogError("LoadResources : Load from file Error: " + szUrl);
                }
            }

            if (null != asset)
            {
                if (resourceData.eState == ResourceMgrData.State.Loading)
                {
                    resourceData.assetBundle = asset;
#if UNITY_EDITOR
                    if ("shader_greymaterial.ab".Equals(szPkgName))
                    {
                        Material mat = gDicPkgResource[szPkgName].assetBundle.LoadAsset <Material>("GreyMaterial");
                        mat.shader = Shader.Find(mat.shader.name);
                    }
#endif
                }
            }
            else
            {
                resourceData.assetBundle = null;
            }

            /** @brief: 判断是否提前释放 */
            if (resourceData.eState == ResourceMgrData.State.Loading)
            {
                resourceData.eState = ResourceMgrData.State.LoadFinish;
            }
            else
            {
                if (IsInvalid(resourceData.assetBundle) == false)
                {
                    resourceData.assetBundle.Unload(true);
                    resourceData.assetBundle = null;
                }
            }
        } while (false);

        ResourceMgrData resourceMgrData = gDicPkgResource[szPkgName];
        /** @brief: 等待下载完成进行检测 */
        while (resourceMgrData.eState == ResourceMgrData.State.Loading)
        {
            yield return(new WaitForEndOfFrame());
        }

        /** @brief: 提前释放 */
        if (resourceMgrData.eState == ResourceMgrData.State.None)
        {
            callback = null;
            ////JZLog.LogWarning("LoadResources : You have Destroyed this bundle " + szPkgName + " , Ignore ...");
            yield break;
        }

        InitHideFlag(resourceMgrData.assetBundle);

        if (callback != null)
        {
            callback.Invoke(szPkgName, resourceMgrData.assetBundle);
            callback = null;
        }
    }
Beispiel #22
0
    IEnumerator ReadLocalConfig(Action onComplete, Action onError)
    {
        string path = PathUtils.MakeFilePath(GameConfig.LOCAL_CONFIG_FILE, PathUtils.PathType.MobileDiskWrite);

        try
        {
            if (File.Exists(path))
            {
                Loom.RunAsync(() => {
                    StreamReader sr = null;
                    sr             = File.OpenText(path);
                    string content = sr.ReadToEnd();
                    sr.Close();
                    m_localConfig = JsonFx.Json.JsonReader.Deserialize <VersionBundleConfig>(content);
                    if (null != onComplete)
                    {
                        Loom.QueueOnMainThread(() => {
                            onComplete();
                        });
                    }
                });
                yield break;
            }
        }
        catch (Exception error)
        {
            JZLog.LogError("VersionManager:Read - " + "Error: " + error.Message);
            if (null != onError)
            {
                onError();
            }
        }

        path = "file://" + PathUtils.MakeFilePath(GameConfig.LOCAL_CONFIG_FILE, PathUtils.PathType.MobileDiskStreamAssert);
        if (Application.platform == RuntimePlatform.Android)
        {
            path = "jar:" + path;
        }
        WWW www = new WWW(path);

        yield return(www);

        if (null != www && null == www.error)
        {
            JZLog.Log("load config success");
            string content = System.Text.Encoding.Default.GetString(www.bytes);
            Loom.RunAsync(() => {
                m_localConfig = JsonFx.Json.JsonReader.Deserialize <VersionBundleConfig>(content);
                if (null != onComplete)
                {
                    Loom.QueueOnMainThread(() =>
                    {
                        onComplete();
                    });
                }
            });
        }
        else
        {
            JZLog.LogError("VersionManager:Read - " + "Error: " + www.error);
            if (null != onError)
            {
                onError();
            }
        }
    }