Exemple #1
0
        private void OnDownloadSuccess(int serialId, string downloadPath, string downloadUri, int currentLength, object userData)
        {
            UpdateInfo updateInfo = userData as UpdateInfo;

            if (updateInfo == null)
            {
                return;
            }

            using (FileStream fileStream = new FileStream(downloadPath, FileMode.Open, FileAccess.ReadWrite))
            {
                bool zip = (updateInfo.Length != updateInfo.ZipLength || updateInfo.HashCode != updateInfo.ZipHashCode);

                int length = (int)fileStream.Length;
                if (length != updateInfo.ZipLength)
                {
                    fileStream.Close();
                    string errorMessage = TextUtil.Format("Zip length error, need '{0}', downloaded '{1}'.", updateInfo.ZipLength.ToString(), length.ToString());
                    OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData);
                    return;
                }

                if (m_ResourceManager.UpdateFileCacheLength < length)
                {
                    m_ResourceManager.UpdateFileCacheLength = (length / OneMegaBytes + 1) * OneMegaBytes;
                }

                int offset = 0;
                int count  = length;
                while (count > 0)
                {
                    int bytesRead = fileStream.Read(m_ResourceManager.UpdateFileCache, offset, count);
                    if (bytesRead <= 0)
                    {
                        throw new Exception(TextUtil.Format("Unknown error when load file '{0}'.", downloadPath));
                    }

                    offset += bytesRead;
                    count  -= bytesRead;
                }

                int hashCode = ConverterUtil.GetInt32(VerifierUtil.GetCrc32(m_ResourceManager.UpdateFileCache, 0, length));
                if (hashCode != updateInfo.ZipHashCode)
                {
                    fileStream.Close();
                    string errorMessage = TextUtil.Format("Zip hash code error, need '{0}', downloaded '{1}'.", updateInfo.ZipHashCode.ToString("X8"), hashCode.ToString("X8"));
                    OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData);
                    return;
                }

                if (zip)
                {
                    try
                    {
                        if (m_ResourceManager.DecompressCache == null)
                        {
                            m_ResourceManager.DecompressCache = new MemoryStream();
                        }

                        m_ResourceManager.DecompressCache.Position = 0L;
                        m_ResourceManager.DecompressCache.SetLength(0L);
                        if (!ZipUtil.Decompress(m_ResourceManager.UpdateFileCache, 0, length, m_ResourceManager.DecompressCache))
                        {
                            fileStream.Close();
                            string errorMessage = TextUtil.Format("Unable to decompress from file '{0}'.", downloadPath);
                            OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData);
                            return;
                        }

                        if (m_ResourceManager.DecompressCache.Length != updateInfo.Length)
                        {
                            fileStream.Close();
                            string errorMessage = TextUtil.Format("Resource length error, need '{0}', downloaded '{1}'.", updateInfo.Length.ToString(), m_ResourceManager.UpdateFileCache.Length.ToString());
                            OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData);
                            return;
                        }

                        fileStream.Position = 0L;
                        fileStream.SetLength(0L);
                        m_ResourceManager.DecompressCache.Position = 0L;
                        int bytesRead = 0;
                        while ((bytesRead = m_ResourceManager.DecompressCache.Read(m_ResourceManager.UpdateFileCache, 0, m_ResourceManager.UpdateFileCache.Length)) > 0)
                        {
                            fileStream.Write(m_ResourceManager.UpdateFileCache, 0, bytesRead);
                        }
                    }
                    catch (Exception exception)
                    {
                        fileStream.Close();
                        string errorMessage = TextUtil.Format("Unable to decompress from file '{0}' with error message '{1}'.", downloadPath, exception.Message);
                        OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData);
                        return;
                    }
                }
            }

            m_UpdatingCount--;

            if (m_ResourceManager.ResourceInfos.ContainsKey(updateInfo.ResourceName))
            {
                throw new Exception(TextUtil.Format("Resource info '{0}' is already exist.", updateInfo.ResourceName));
            }

            m_ResourceManager.ResourceInfos.Add(updateInfo.ResourceName, new ResourceInfo(updateInfo.ResourceName, updateInfo.Length, updateInfo.HashCode, false));
            m_ResourceManager.ResourceNames.Add(updateInfo.ResourceName);

            if (m_ResourceManager.ReadWriteResourceInfos.ContainsKey(updateInfo.ResourceName))
            {
                throw new Exception(TextUtil.Format("Read-write resource info '{0}' is already exist.", updateInfo.ResourceName));
            }

            m_ResourceManager.ReadWriteResourceInfos.Add(updateInfo.ResourceName, new ReadWriteResourceInfo(updateInfo.Length, updateInfo.HashCode));

            m_CurrentGenerateReadWriteListLength += updateInfo.ZipLength;
            if (m_UpdatingCount <= 0 || m_CurrentGenerateReadWriteListLength >= m_GenerateReadWriteListLength)
            {
                m_CurrentGenerateReadWriteListLength = 0;
                GenerateReadWriteList();
            }

            if (ResourceUpdateSuccess != null)
            {
                ResourceUpdateSuccess(updateInfo.ResourceName, downloadPath, downloadUri, updateInfo.Length, updateInfo.ZipLength);
            }
        }
Exemple #2
0
        /// <summary>
        /// 设置对象的优先级
        /// </summary>
        /// <param name="target">要设置优先级的对象</param>
        /// <param name="priority">优先级</param>
        public void SetPriority(object target, int priority)
        {
            if (target == null)
            {
                throw new Exception("Target is invalid.");
            }

            Object <T> internalObject = GetObject(target);

            if (internalObject != null)
            {
                internalObject.Priority = priority;
            }
            else
            {
                throw new Exception(TextUtil.Format("Can not find target in object pool '{0}'.", TextUtil.GetFullName <T>(Name)));
            }
        }
Exemple #3
0
 /// <summary>
 /// 显示进度
 /// </summary>
 /// <param name="message">进度信息</param>
 /// <param name="value">进度值</param>
 public void ShowProgress(string message, float value)
 {
     m_TxtMessage.text  = message;
     m_TxtProgress.text = TextUtil.Format("{0}%", (int)(value * 100));
 }
Exemple #4
0
        /// <summary>
        /// 回收对象
        /// </summary>
        /// <param name="target">要回收的对象</param>
        public void Unspawn(object target)
        {
            if (target == null)
            {
                throw new Exception("Target is invalid.");
            }

            Object <T> internalObject = GetObject(target);

            if (internalObject != null)
            {
                internalObject.Unspawn();
                if (Count > m_Capacity && internalObject.SpawnCount <= 0)
                {
                    Release();
                }
            }
            else
            {
                throw new Exception(TextUtil.Format("Can not find target in object pool '{0}'.", TextUtil.GetFullName <T>(Name)));
            }
        }
Exemple #5
0
        /// <summary>
        /// 设置对象是否被加锁
        /// </summary>
        /// <param name="target">要设置被加锁的对象</param>
        /// <param name="locked">是否被加锁</param>
        public void SetLocked(object target, bool locked)
        {
            if (target == null)
            {
                throw new Exception("Target is invalid.");
            }

            Object <T> internalObject = GetObject(target);

            if (internalObject != null)
            {
                internalObject.Locked = locked;
            }
            else
            {
                throw new Exception(TextUtil.Format("Can not find target in object pool '{0}'.", TextUtil.GetFullName <T>(Name)));
            }
        }
Exemple #6
0
            protected override void OnDrawScrollableWindow()
            {
                GUILayout.Label("<b>Quality Level</b>");
                GUILayout.BeginVertical("box");
                {
                    int currentQualityLevel = QualitySettings.GetQualityLevel();

                    DrawItem("Current Quality Level:", QualitySettings.names[currentQualityLevel]);
                    m_ApplyExpensiveChanges = GUILayout.Toggle(m_ApplyExpensiveChanges, "Apply expensive changes on quality level change.");

                    int newQualityLevel = GUILayout.SelectionGrid(currentQualityLevel, QualitySettings.names, 3, "toggle");
                    if (newQualityLevel != currentQualityLevel)
                    {
                        QualitySettings.SetQualityLevel(newQualityLevel, m_ApplyExpensiveChanges);
                    }
                }
                GUILayout.EndVertical();

                GUILayout.Label("<b>Rendering Information</b>");
                GUILayout.BeginVertical("box");
                {
                    DrawItem("Active Color Space:", QualitySettings.activeColorSpace.ToString());
                    DrawItem("Desired Color Space:", QualitySettings.desiredColorSpace.ToString());
                    DrawItem("Max Queued Frames:", QualitySettings.maxQueuedFrames.ToString());
                    DrawItem("Pixel Light Count:", QualitySettings.pixelLightCount.ToString());
                    DrawItem("Master Texture Limit:", QualitySettings.masterTextureLimit.ToString());
                    DrawItem("Anisotropic Filtering:", QualitySettings.anisotropicFiltering.ToString());
                    DrawItem("Anti Aliasing:", QualitySettings.antiAliasing.ToString());
#if UNITY_5_5_OR_NEWER
                    DrawItem("Soft Particles:", QualitySettings.softParticles.ToString());
#endif
                    DrawItem("Soft Vegetation:", QualitySettings.softVegetation.ToString());
                    DrawItem("Realtime Reflection Probes:", QualitySettings.realtimeReflectionProbes.ToString());
                    DrawItem("Billboards Face Camera Position:", QualitySettings.billboardsFaceCameraPosition.ToString());
#if UNITY_2017_1_OR_NEWER
                    DrawItem("Resolution Scaling Fixed DPI Factor:", QualitySettings.resolutionScalingFixedDPIFactor.ToString());
#endif
#if UNITY_2018_2_OR_NEWER
                    DrawItem("Texture Streaming Enabled", QualitySettings.streamingMipmapsActive.ToString());
                    DrawItem("Texture Streaming Add All Cameras", QualitySettings.streamingMipmapsAddAllCameras.ToString());
                    DrawItem("Texture Streaming Memory Budget", QualitySettings.streamingMipmapsMemoryBudget.ToString());
                    DrawItem("Texture Streaming Renderers Per Frame", QualitySettings.streamingMipmapsRenderersPerFrame.ToString());
                    DrawItem("Texture Streaming Max Level Reduction", QualitySettings.streamingMipmapsMaxLevelReduction.ToString());
                    DrawItem("Texture Streaming Max File IO Requests", QualitySettings.streamingMipmapsMaxFileIORequests.ToString());
#endif
                }
                GUILayout.EndVertical();

                GUILayout.Label("<b>Shadows Information</b>");
                GUILayout.BeginVertical("box");
                {
#if UNITY_2017_1_OR_NEWER
                    DrawItem("Shadowmask Mode:", QualitySettings.shadowmaskMode.ToString());
#endif
#if UNITY_5_5_OR_NEWER
                    DrawItem("Shadow Quality:", QualitySettings.shadows.ToString());
#endif
#if UNITY_5_4_OR_NEWER
                    DrawItem("Shadow Resolution:", QualitySettings.shadowResolution.ToString());
#endif
                    DrawItem("Shadow Projection:", QualitySettings.shadowProjection.ToString());
                    DrawItem("Shadow Distance:", QualitySettings.shadowDistance.ToString());
                    DrawItem("Shadow Near Plane Offset:", QualitySettings.shadowNearPlaneOffset.ToString());
                    DrawItem("Shadow Cascades:", QualitySettings.shadowCascades.ToString());
                    DrawItem("Shadow Cascade 2 Split:", QualitySettings.shadowCascade2Split.ToString());
                    DrawItem("Shadow Cascade 4 Split:", QualitySettings.shadowCascade4Split.ToString());
                }
                GUILayout.EndVertical();

                GUILayout.Label("<b>Other Information</b>");
                GUILayout.BeginVertical("box");
                {
#if UNITY_2019_1_OR_NEWER
                    DrawItem("Skin Weights:", QualitySettings.skinWeights.ToString());
#else
                    DrawItem("Blend Weights:", QualitySettings.blendWeights.ToString());
#endif
                    DrawItem("VSync Count:", QualitySettings.vSyncCount.ToString());
                    DrawItem("LOD Bias:", QualitySettings.lodBias.ToString());
                    DrawItem("Maximum LOD Level:", QualitySettings.maximumLODLevel.ToString());
                    DrawItem("Particle Raycast Budget:", QualitySettings.particleRaycastBudget.ToString());
                    DrawItem("Async Upload Time Slice:", TextUtil.Format("{0} ms", QualitySettings.asyncUploadTimeSlice.ToString()));
                    DrawItem("Async Upload Buffer Size:", TextUtil.Format("{0} MB", QualitySettings.asyncUploadBufferSize.ToString()));
#if UNITY_2018_3_OR_NEWER
                    DrawItem("Async Upload Persistent Buffer:", QualitySettings.asyncUploadPersistentBuffer.ToString());
#endif
                }
                GUILayout.EndVertical();
            }
Exemple #7
0
 private void LoadDataTable(string dataTableName)
 {
     m_LoadedFlag.Add(TextUtil.Format("DataTable.{0}", dataTableName), false);
     GameEntry.DataTable.LoadDataTable(dataTableName, this);
 }
Exemple #8
0
        protected internal override void OnAttachTo(EntityBase parentEntity, Transform parentTransform, object userData)
        {
            base.OnAttachTo(parentEntity, parentTransform, userData);

            Name = TextUtil.Format("Weapon of {0}", parentEntity.Name);
        }
Exemple #9
0
 private void PageIetmClick(int index)
 {
     m_Txttitle.text   = Titles[index];
     m_TxtContent.text = TextUtil.Format("\r\n\r\n\r\n{0}", GetConent(index));
 }
Exemple #10
0
        /// <summary>
        /// 切换当前有限状态机状态
        /// </summary>
        /// <typeparam name="stateType">要切换到的有限状态机状态类型</typeparam>
        public void ChangeState(Type stateType)
        {
            if (m_CurrentState == null)
            {
                throw new Exception("Current state is invalid.");
            }

            FsmState <T> state = GetState(stateType);

            if (state == null)
            {
                throw new Exception(TextUtil.Format("FSM '{0}' can not change state to '{1}' which is not exist.", TextUtil.GetFullName <T>(Name), stateType.FullName));
            }

            m_CurrentState.OnLeave();
            m_CurrentStateTime = 0f;
            m_CurrentState     = state;
            m_CurrentState.OnEnter();
        }
Exemple #11
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="name">有限状态机名称</param>
        /// <param name="owner">拥有者</param>
        /// <param name="states">状态数组</param>
        public Fsm(string name, T owner, FsmState <T>[] states) : base(name)
        {
            if (owner == null)
            {
                throw new Exception("FSM owner is invalid.");
            }

            if (states == null || states.Length < 1)
            {
                throw new Exception("FSM states is invalid.");
            }

            m_Owner  = owner;
            m_States = new Dictionary <string, FsmState <T> >();
            m_Datas  = new Dictionary <string, VariableBase>();

            //把状态加入字典
            foreach (FsmState <T> state in states)
            {
                if (state == null)
                {
                    throw new Exception("FSM states is invalid.");
                }

                string stateName = state.GetType().FullName;
                if (m_States.ContainsKey(stateName))
                {
                    throw new Exception(TextUtil.Format("FSM '{0}' state '{1}' is already exist.", TextUtil.GetFullName <T>(name), stateName));
                }

                m_States.Add(stateName, state);
                state.CurrFsm = this;
                state.OnInit();
            }

            m_CurrentStateTime = 0f;
            m_CurrentState     = null;
            m_IsDestroyed      = false;
        }
Exemple #12
0
 /// <summary>
 /// 读写目录读文件
 /// </summary>
 /// <param name="assetName">资源名称</param>
 private void ReadWriteByte(string assetName)
 {
     m_FilePath = TextUtil.Format("{0}/{1}", GameEntry.Resource.ReadWritePath, PathUtil.GetResourceNameWithSuffix(assetName));
     System.Threading.Tasks.Task.Factory.StartNew(ReadWriteByteAsync);
 }
Exemple #13
0
 private void SetProressValue(int value)
 {
     m_Imgvalue.fillAmount = value * 0.01f;
     m_Txtvalue.text       = TextUtil.Format("{0}%", value);
 }
Exemple #14
0
        private void OnDownloadSuccess(int serialId, string downloadPath, string downloadUri, int currentLength, object userData)
        {
            VersionListProcessor versionListProcessor = userData as VersionListProcessor;

            if (versionListProcessor == null || versionListProcessor != this)
            {
                return;
            }

            using (FileStream fileStream = new FileStream(downloadPath, FileMode.Open, FileAccess.ReadWrite))
            {
                int length = (int)fileStream.Length;
                if (length != m_VersionListZipLength)
                {
                    fileStream.Close();
                    string errorMessage = TextUtil.Format("Latest version list zip length error, need '{0}', downloaded '{1}'.", m_VersionListZipLength.ToString(), length.ToString());
                    OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData);
                    return;
                }

                if (m_UpdateFileCache == null || m_UpdateFileCache.Length < length)
                {
                    m_UpdateFileCache = new byte[(length / OneMegaBytes + 1) * OneMegaBytes];
                }

                int offset = 0;
                int count  = length;
                while (count > 0)
                {
                    int bytesRead = fileStream.Read(m_UpdateFileCache, offset, count);
                    if (bytesRead <= 0)
                    {
                        throw new Exception(TextUtil.Format("Unknown error when load file '{0}'.", downloadPath));
                    }

                    offset += bytesRead;
                    count  -= bytesRead;
                }

                int hashCode = ConverterUtil.GetInt32(VerifierUtil.GetCrc32(m_UpdateFileCache, 0, length));
                if (hashCode != m_VersionListZipHashCode)
                {
                    fileStream.Close();
                    string errorMessage = TextUtil.Format("Latest version list zip hash code error, need '{0}', downloaded '{1}'.", m_VersionListZipHashCode.ToString("X8"), hashCode.ToString("X8"));
                    OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData);
                    return;
                }

                try
                {
                    if (m_DecompressCache == null)
                    {
                        m_DecompressCache = new MemoryStream();
                    }

                    m_DecompressCache.Position = 0L;
                    m_DecompressCache.SetLength(0L);
                    if (!ZipUtil.Decompress(m_UpdateFileCache, 0, length, m_DecompressCache))
                    {
                        fileStream.Close();
                        string errorMessage = TextUtil.Format("Unable to decompress latest version list '{0}'.", downloadPath);
                        OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData);
                        return;
                    }


                    if (m_DecompressCache.Length != m_VersionListLength)
                    {
                        fileStream.Close();
                        string errorMessage = TextUtil.Format("Latest version list length error, need '{0}', downloaded '{1}'.", m_VersionListLength.ToString(), m_DecompressCache.Length.ToString());
                        OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData);
                        return;
                    }

                    fileStream.Position = 0L;
                    fileStream.SetLength(0L);
                    m_DecompressCache.Position = 0L;
                    int bytesRead = 0;
                    while ((bytesRead = m_DecompressCache.Read(m_UpdateFileCache, 0, m_UpdateFileCache.Length)) > 0)
                    {
                        fileStream.Write(m_UpdateFileCache, 0, bytesRead);
                    }
                }
                catch (Exception exception)
                {
                    fileStream.Close();
                    string errorMessage = TextUtil.Format("Unable to decompress latest version list '{0}' with error message '{1}'.", downloadPath, exception.Message);
                    OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData);
                    return;
                }
            }

            if (VersionListUpdateSuccess != null)
            {
                VersionListUpdateSuccess(downloadPath, downloadUri);
            }
        }