Exemple #1
0
        public void Init()
        {
            // 引擎参数设置,不开垂直同步,默认30帧
            Screen.sleepTimeout         = SleepTimeout.NeverSleep;
            Application.runInBackground = true;
            QualitySettings.vSyncCount  = 0;
            Time.fixedDeltaTime         = 0.1f; //0.033333333f;
            Time.maximumDeltaTime       = 0.16f;

            // 重要系统的实例化
            GlobalSettings.GetInstance();
            NetClient.GetBaseClient();

            // 本地玩家的ID
            mLocalPlayerID         = new UnitID();
            mLocalPlayerID.type    = (byte)EUnitType.UNITTYPE_PLAYER;
            mLocalPlayerID.obj_idx = 0xffffffff;

            // 网络初始化
            mNetHandlers = new Dictionary <ushort, List <DataReplyDelegate> >();
            // Now we directly connect to server.
            NetClient.GetBaseClient().mListener = this;

            // 所有系统的初始化和网络消息的注册
            RegisterAllMessage();

            // 日志回调
            Application.logMessageReceived += OnLog;
            xpatch.XPatchManager.Instance.onPatchFinished += OnPatchFinished;

    #if !UNITY_MOBILE_LOCAL
            VoiceManager.Instance.Init();
    #endif
        }
Exemple #2
0
        /// <summary>
        /// 设备自适应
        /// </summary>
        public static void DeviceAdaptation()
        {
            GlobalSettings.GetInstance();

            // 获取当前设备推荐的画面等级
            int level = GetAdviceGraphicLevel();

            // 获取已经设置的画面等级
            if (UserPlayerPrefs.Instance.Contain("GraphicLevel"))
            {
                // 当前设置的比推荐画质高时,使用推荐画质
                var local_setting = GlobalSettings.Instance.GraphicLevel;
                if (local_setting >= level)
                {
                    level = local_setting;
                }
            }
            else
            {
                // ios提审默认使用低配置画质
                if (AuditManager.Instance.AuditAndIOS())
                {
                    level = 2;
                }
            }

            // 设置默认同屏玩家数量
            if (UserPlayerPrefs.Instance.Contain("MaxPlayerCount") == false)
            {
                GlobalSettings.Instance.MaxPlayerCount = (int)AdviceMaxPlayerCount;
            }

            QualitySetting.GraphicLevel = level;
            GlobalSettings.GetInstance().Save();
        }
Exemple #3
0
        public void Quit(bool callApplicationQuit)
        {
            // 保存用户配置
            GlobalSettings.GetInstance().Save();

            // 如果开启了跨服,关闭跨服Socket
            if (Net.NetClient.CrossToggle)
            {
                CrossServerIntegration.GetInstance().Stop();
            }

            StopNetClient();

            // 关闭Sqlite连接
            DBManager.Instance.CloseAllSqliteDB();

            //发送客户端关闭通知
            ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_QUIT_GAME, null);

            LuaScriptMgr.Instance.Destroy();
#if !UNITY_EDITOR
            if (callApplicationQuit)
            {
                Application.Quit();
            }
#endif
        }
Exemple #4
0
        public uint PlayBattleSFX(string res_path, SoundType type)
        {
            float volume = GlobalSettings.GetInstance().SFXVolume;

            if (!GlobalSettings.GetInstance().SFXMute&& volume > 0.01f)
            {
                uint id = GetNewSoundId();
                if (string.IsNullOrEmpty(res_path) == false)
                {
                    MainGame.HeartBehavior.StartCoroutine(LoadSFXAudio(res_path, type, id));
                }
                return(id);
            }
            return(0);
        }
 public void SetTranVO(TranVO tran)
 {
     mTranVO = tran;
     if (mAudio != null)
     {
         if (mTranVO != null)
         {
             mAudio.volume = mTranVO.OriValue;
             if (mTranVO.Clip != null)
             {
                 mAudio.clip = mTranVO.Clip;
             }
         }
         if (mAudio.isPlaying == false)
         {
             PauseMusic(GlobalSettings.GetInstance().MusicMute);
         }
     }
 }
Exemple #6
0
        /// <summary>
        /// 播放音效
        /// </summary>
        /// <param name="clip"></param>
        /// <param name="is_loop"></param>
        /// <returns></returns>
        public void PlayAudio(AudioClip clip, bool is_loop = false, UnityAction cbFunc = null)
        {
            float volume = GlobalSettings.GetInstance().SFXVolume;

            if (clip != null && volume > 0.01f)
            {
                InitListener();

                if (m_Listener != null && m_Listener.enabled && UGUITools.GetActive(m_Listener.gameObject))
                {
                    AudioSource source = m_Listener.GetComponent <AudioSource>();
                    if (source == null)
                    {
                        source = m_Listener.gameObject.AddComponent <AudioSource>();
                    }

                    if (is_loop)
                    {
                        source.loop = true;
                        source.clip = clip;
                        source.Play();

                        return;
                    }

                    source.pitch = 1.0f;
                    if (!GlobalSettings.GetInstance().SFXMute)
                    {
                        source.PlayOneShot(clip, volume);

                        if (null != cbFunc)
                        {
                            xc.MainGame.GetGlobalMono().StartCoroutine(DelayedCallback(clip.length, cbFunc));
                        }
                    }
                }
            }
        }
Exemple #7
0
        private void PlayBattleSFX(AudioClip clip, SoundType type, uint id)
        {
            float volume = GlobalSettings.GetInstance().SFXVolume;

            if (clip != null && !GlobalSettings.GetInstance().SFXMute&& volume > 0.01f)
            {
                InitListener();

                if (m_Listener != null && m_Listener.enabled && UGUITools.GetActive(m_Listener.gameObject))
                {
                    BattleSFXAudioSource source = GetSFXAudioSource();
                    if (source != null)
                    {
                        bool playSuccess = source.PlaySound(clip, type, id);
                        if (!playSuccess)
                        {
                            PlayAudio(clip);
                            DestroySFX(id, clip.length);
                        }
                    }
                }
            }
        }
        public void OnPostDeviceInitFinished(string url, string error, string reply, System.Object userData)
        {
            int       result    = 0;
            Hashtable hashtable = MiniJSON.JsonDecode(reply) as Hashtable;

            if (hashtable != null)
            {
                result = DBTextResource.ParseI(hashtable["result"].ToString());
            }

            bool      ret           = false;
            string    errorMsg      = "";
            Hashtable argsHashtable = hashtable["args"] as Hashtable;

            if (result == 1)
            {
                if (argsHashtable != null)
                {
                    string deviceMark = argsHashtable["device_mark"].ToString();

                    if (GlobalConfig.Instance.DeviceMark.Equals(deviceMark) == false)
                    {
                        GlobalConfig.Instance.DeviceMark = deviceMark;

                        GlobalSettings.GetInstance();
                        UserPlayerPrefs.Instance.SetString("DeviceMark", deviceMark);
                        UserPlayerPrefs.Instance.Save();
                    }

                    ret = true;
                }
            }
            else
            {
                if (argsHashtable != null)
                {
                    errorMsg = argsHashtable["error_msg"].ToString();
                }
            }

            if (ret == true)
            {
                // DeviceInit成功
                ControlServerLogHelper.Instance.PostPlayerFollowRecord(PlayerFollowRecordSceneId.DeviceInitEnd, "", false);
                ControlServerLogHelper.Instance.PostCloudLadderEventAction(CloudLadderMarkEnum.boot_app);
            }
            else
            {
                // DeviceInit失败
                if (string.IsNullOrEmpty(errorMsg) == true)
                {
                    if (string.IsNullOrEmpty(error) == false)
                    {
                        ControlServerLogHelper.Instance.PostPlayerFollowRecord(PlayerFollowRecordSceneId.DeviceInitFail, error, false);
                    }
                    else
                    {
                        ControlServerLogHelper.Instance.PostPlayerFollowRecord(PlayerFollowRecordSceneId.DeviceInitFail, "Unknown error", false);
                    }
                }
                else
                {
                    ControlServerLogHelper.Instance.PostPlayerFollowRecord(PlayerFollowRecordSceneId.DeviceInitFail, errorMsg, false);
                }
            }

            // action保存了NewInitSceneLoader中的函数,调用之后需要赋空
            if (mPostDeviceInitFinishedCallback != null)
            {
                mPostDeviceInitFinishedCallback.Invoke(ret);
                mPostDeviceInitFinishedCallback = null;
            }
        }
Exemple #9
0
        public GlobalConfig()
        {
            LoginInfo = new LoginInfoStruct();

            IBridge bridge = DBOSManager.getDBOSManager().getBridge();

            mDeviceMark = bridge.getDBMachineId();
            mSDKName    = bridge.getSDKName();
            mAppDocPath = bridge.getGameDocPath();
            mAppResPath = bridge.getGameResPath();

            mAppId      = 0;
            mChannel    = "";
            mSubChannel = "";

            // 从SDKName中解析出Channel
            string[] sdkNameStrs = mSDKName.Split('_');
#if UNITY_ANDROID
            if (sdkNameStrs.Length >= 3)
            {
                mAppId   = DBTextResource.ParseI_s(sdkNameStrs[1], 0);
                mChannel = sdkNameStrs[2];
            }
#elif UNITY_IPHONE
            if (sdkNameStrs.Length >= 2)
            {
                mAppId = DBTextResource.ParseI_s(sdkNameStrs[1], 0);
            }
#else
#endif

            int appId = bridge.getAppID();
            if (appId > 0)
            {
                mAppId = appId;
            }
            string channel = bridge.getCurrChannel();
            if (string.IsNullOrEmpty(channel) == false)
            {
                mChannel = channel;
            }
            string subChannel = bridge.getSubChannel();
            if (string.IsNullOrEmpty(subChannel) == false)
            {
                mSubChannel = subChannel;
            }

            // 获取游戏启动时间戳,非安卓平台在NewInitSceneLoader那边获取
#if UNITY_ANDROID
            mStartTimeStamp = bridge.getStartTimeStamp();
#endif

            if (bridge.isBridgeEnable() == false)
            {
                mIsEnterSDK   = false;
                mPlatformName = "";

#if UNITY_ANDROID
                mPlatformName = "android";
#elif UNITY_IPHONE
                mPlatformName = "ios";
#elif UNITY_EDITOR
                mPlatformName = "editor";
#else
                mPlatformName = "win";
#endif
                return;
            }

#if UNITY_ANDROID
#if HD_RESOURCE // 高清版
            mIsEnterSDK     = false;
            Const.IsFullApp = true;
#else
            mIsEnterSDK = true;
#endif

            mPlatformName = "android";
            mDeviceMark   = bridge.getDBMachineId();
#elif UNITY_IPHONE
            mIsEnterSDK = true;
            //mIsEnterUpgradeScene = false;
            mPlatformName = "ios";
            // iOS的DeviceMark需要从本地保存的文件读取
            GlobalSettings.GetInstance();
            mDeviceMark = UserPlayerPrefs.Instance.GetString("DeviceMark", "");

#if FULL_APP
            mIsEnterSDK     = true;
            Const.IsFullApp = true;
#else
            mIsEnterSDK = true;
#endif
#elif UNITY_STANDALONE_WIN
            mPlatformName = "win";
#else
            mPlatformName = "android";
            mDeviceMark   = bridge.getDBMachineId();
#endif

            mIsDebugMode = false;

#if TEST_HOST || CMPT_RELEASE
            //通过SDK登录
            mIsEnterSDK = false;
#if UNITY_ANDROID || UNITY_IPHONE
            mIsEnterSDK = false;
#endif
#endif
        }
Exemple #10
0
        /// <summary>
        /// 加载音效资源
        /// </summary>
        /// <returns></returns>
        IEnumerator LoadAudio_dynamic(DynamicAudioItem item)
        {
            if (item == null)
            {
                yield break;
            }
            if (item.is_destroy)
            {
                yield break;
            }

            GameObject go = ObjCachePoolMgr.Instance.LoadFromCache(ObjCachePoolType.SMALL_PREFAB, UISoundTemplate) as GameObject;

            if (go == null)
            {
                PrefabResource ar_prefab = new PrefabResource();

                yield return(ResourceLoader.Instance.StartCoroutine(ResourceLoader.Instance.load_prefab(UISoundTemplate, ar_prefab)));

                if (ar_prefab.obj_ == null)
                {
                    StopAudio_dynamic(item.unique_id);
                    yield break;
                }

                GameObject obj = ar_prefab.obj_;
                if (item.is_destroy)
                {
                    GameObject.DestroyImmediate(obj);
                    yield break;
                }

                PoolGameObject pg = obj.AddComponent <PoolGameObject>();
                if (pg != null)
                {
                    pg.poolType = ObjCachePoolType.SMALL_PREFAB;
                    pg.key      = UISoundTemplate;
                }
                go = obj;
            }

            item.audioSource = go.GetComponent <AudioSource>();
            if (item.audioSource == null)
            {
                item.audioSource = go.AddComponent <AudioSource>();
            }
            go.SetActive(true);
            Camera cam = Camera.main;

            if (cam == null)
            {
                cam = GameObject.FindObjectOfType(typeof(Camera)) as Camera;
            }
            if (cam != null)
            {
                item.audioSource.transform.SetParent(cam.transform);
                item.audioSource.transform.localScale       = Vector3.one;
                item.audioSource.transform.localPosition    = Vector3.zero;
                item.audioSource.transform.localEulerAngles = Vector3.zero;
            }

            AssetResource ar = new AssetResource();

            yield return(ResourceLoader.Instance.StartCoroutine(ResourceLoader.Instance.load_asset(item.res_path, typeof(Object), ar)));

            if (ar.asset_ == null)
            {
                GameDebug.LogError(string.Format("the res {0} does not exist", item.res_path));
                StopAudio_dynamic(item.unique_id);
                yield break;
            }
            if (item.is_destroy)
            {
                ar.destroy();
                yield break;
            }
            AudioClip audio_clip = ar.asset_ as AudioClip;

            if (audio_clip == null)
            {
                GameDebug.LogError(string.Format("the res {0} is not audio clip", item.res_path));
                ar.destroy();
                yield break;
            }

            item.clip             = audio_clip;
            item.audioSource.clip = item.clip;
            item.audioSource.loop = item.is_loop;
            float volume = GlobalSettings.GetInstance().SFXVolume;

            item.audioSource.volume = volume * item.volume;
            item.audioSource.mute   = GlobalSettings.GetInstance().SFXMute;
            item.audioSource.Play();
            UnityAction cbFunc = () =>
            {
                if (item != null)
                {
                    StopAudio_dynamic(item.unique_id);
                }
            };

            if (item.is_loop == false)
            {
                xc.MainGame.GetGlobalMono().StartCoroutine(DelayedCallback(item.clip.length, cbFunc));
            }
        }