示例#1
0
        /// <summary>
        /// 读取打包资源配置信息.
        /// </summary>
        /// <returns>打包资源配置信息.</returns>
        /// <param name="iDirPath">Asset存放目录文件(不指定:当前选定对象所在目录).</param>
        public static T ReadSetting <T>(string iDirPath = null) where T : UnityEngine.ScriptableObject
        {
            T      objRet = default(T);
            string path   = null;

            try {
                path = GetAssetFilePath <T>(iDirPath);
                if (true == string.IsNullOrEmpty(path))
                {
                    UtilsLog.Error("UtilityAsset", "GetAssetFilePath():Failed!!!(Dir:{0})",
                                   true == string.IsNullOrEmpty(iDirPath) ? "null" : iDirPath);
                    return(objRet);
                }
                UtilsLog.Info("UtilityAsset", "ReadSetting:{0}", path);
                objRet = UtilsAsset.LoadAssetFile <T>(path);

                SetAssetDirty(objRet);
            }
            catch (System.IO.DirectoryNotFoundException exp)
            {
                UtilsLog.Fatal("UtilityAsset", "ReadSetting()::Failed!!! DetailInfo ClassName:{0} \n AssetFile:{1} \n Error:{2}",
                               typeof(T).ToString(),
                               (path == null) ? "null" : path,
                               exp.Message);
            }

            if (default(T) == objRet)
            {
                objRet = UtilsAsset.CreateAsset <T> (iDirPath);
                AssetsRefresh();
                SetAssetDirty(objRet);
            }

            return(objRet);
        }
示例#2
0
        /// <summary>
        //	创建Asset.
        /// </summary>
        /// <param name="iDirPath">创建目录.</param>
        public static T CreateAsset <T> (string iDirPath = null) where T : UnityEngine.ScriptableObject
        {
            T objRet = default(T);

#if UNITY_EDITOR
            string assetFullPath = null;
            try {
                assetFullPath = GetAssetFilePath <T> (iDirPath);
                if (assetFullPath.StartsWith("Resources/") == true)
                {
                    assetFullPath = string.Format("{0}/{1}", _dataPath, assetFullPath);
                }
                if (assetFullPath.EndsWith(".asset") == false)
                {
                    assetFullPath = string.Format("{0}.asset", assetFullPath);
                }
                if (File.Exists(assetFullPath) == true)
                {
                    File.Delete(assetFullPath);
                }
                assetFullPath = assetFullPath.Replace(_dataPath, "Assets");
                assetFullPath = AssetDatabase.GenerateUniqueAssetPath(assetFullPath);

                T asset = ScriptableObject.CreateInstance <T> ();
                AssetDatabase.CreateAsset(asset, assetFullPath);
                AssetsRefresh();
                EditorUtility.FocusProjectWindow();
                Selection.activeObject = asset;

                if (File.Exists(assetFullPath) == true)
                {
                    UtilsLog.Info("UtilityAsset", "CreateAsset Successed!!!(File:{0})",
                                  assetFullPath);
                    // 读取并返回创建对象实例
                    objRet = AssetDatabase.LoadAssetAtPath <T> (assetFullPath);
                }
                else
                {
                    UtilsLog.Error("UtilityAsset", "CreateAsset Failed!!!(File:{0})",
                                   assetFullPath);
                }
            }
            catch (UnityException exp) {
                UtilsLog.Fatal("UtilityAsset", "CreateAsset()::Failed!!! DetailInfo ClassName:{0} \n AssetFile:{1} \n Error:{2}",
                               typeof(T).ToString(),
                               (assetFullPath == null) ? "null" : assetFullPath,
                               exp.Message);
            }
#endif

            if (objRet != null)
            {
                return(objRet);
            }
            else
            {
                return(default(T));
            }
        }
示例#3
0
        /// <summary>
        /// 日志输出:错误.
        /// </summary>
        /// <param name="iScript">脚本.</param>
        /// <param name="iFormat">格式.</param>
        /// <param name="iArgs">参数.</param>
        public void Error(string iFormat, params object[] iArgs)
        {
#if BUILD_DEBUG
            if (false == this._logOutput)
            {
                return;
            }
            UtilsLog.Error(this.ClassName, iFormat, iArgs);
#endif
        }
示例#4
0
        /// <summary>
        /// 导出成JSON文件.
        /// </summary>
        /// <returns>导出文件(Json格式).</returns>
        /// <param name="iExportDir">导出路径.</param>
        public virtual string ExportToJsonFile(string iExportDir)
        {
            string exportDir = iExportDir;

            if (true == string.IsNullOrEmpty(exportDir))
            {
                exportDir = this.JsonPath;
            }
            if (false == UtilsAsset.CheckAndCreateDirByFullPath(this.JsonPath))
            {
                UtilsLog.Error(this.ClassName, "ExportToJsonFile -> CheckAndCreateDirByFullPath Failed!!! \n (Path:{0})",
                               this.JsonPath);
                return(null);
            }
            return(UtilsAsset.ExportData <T1> (this.Data, exportDir));
        }
示例#5
0
 public static bool CheckAndCreateDir(string iDir)
 {
     if (true == string.IsNullOrEmpty(iDir))
     {
         return(true);
     }
     if (false == Directory.Exists(iDir))
     {
         UtilsLog.Info("UtilityAsset", "CheckAndCreateDir():Dir:{0}", iDir);
         Directory.CreateDirectory(iDir);
         if (false == Directory.Exists(iDir))
         {
             UtilsLog.Error("UtilityAsset", "CheckAndCreateDir():Dir Failed!!!(Dir:{0})", iDir);
             return(false);
         }
     }
     return(true);
 }
示例#6
0
 /// <summary>
 /// 取得实例.
 /// </summary>
 /// <returns>实例.</returns>
 /// <param name="iPath">读取路径.</param>
 public static T1 GetInstance(string iPath = null)
 {
     if (_instance == null)
     {
         _instance = UtilsAsset.ReadSetting <T1>(iPath);
         string _name = typeof(T1).Name;
         if ((null != _instance) && (true == _instance.Init()))
         {
             UtilsLog.Info(_name, "GetInstance Successed!!!");
         }
         else
         {
             UtilsLog.Error(_name, "GetInstance Failed!!!");
             return(null);
         }
     }
     return(_instance);
 }
示例#7
0
 /// <summary>
 /// 取得实例.
 /// </summary>
 /// <returns>实例.</returns>
 /// <param name="iPath">读取路径.</param>
 public static T1 GetInstance(string iPath = null)
 {
     if (_instance == null)
     {
         _instance = UtilsAsset.ReadSetting <T1>(iPath);
         string _name = typeof(T1).Name;
         if ((null != _instance) && (true == _instance.Init()))
         {
             UtilsLog.Info(_name, "GetInstance()::Successed!!!(Path:{0})",
                           (true == string.IsNullOrEmpty(iPath)) ? "null" : iPath);
         }
         else
         {
             UtilsLog.Error(_name, "GetInstance()::Failed!!!(Path:{0})",
                            (true == string.IsNullOrEmpty(iPath)) ? "null" : iPath);
             return(null);
         }
     }
     return(_instance);
 }
        /// <summary>
        /// 创建时间计数器.
        /// </summary>
        /// <param name="iMaxValue">计数器最大值.</param>
        /// <param name="iOnCountOver">超过计时回调函数.</param>
        /// <param name="iMode">模式(默认为:倒计时).</param>
        public static TimeCounter Create(
            float iMaxValue,
            System.Action iOnCountOver = null,
            TCounterMode iMode         = TCounterMode.CountDown)
        {
            TimeCounter objRet = new TimeCounter();

            if (objRet != null)
            {
                objRet.InitCounter(iMaxValue, TCounterType.TimeCounter, iMode);
                if (iOnCountOver != null)
                {
                    objRet.OnCountOver += iOnCountOver;
                }
                return(objRet);
            }
            else
            {
                UtilsLog.Error("TimeCounter", "Create()::TimeCounter Create Failed!!!");
                return(null);
            }
        }
示例#9
0
 /// <summary>
 /// 错误日志.
 /// </summary>
 /// <param name="iScript">脚本.</param>
 /// <param name="iFormat">格式.</param>
 /// <param name="iArgs">参数.</param>
 public void Error(string iFormat, params object[] iArgs)
 {
     UtilsLog.Error(this.ClassName, iFormat, iArgs);
 }
示例#10
0
        /// <summary>
        /// 日志输出:错误.
        /// </summary>
        /// <param name="iScript">脚本.</param>
        /// <param name="iFormat">格式.</param>
        /// <param name="iArgs">参数.</param>
        public void Error(string iFormat, params object[] iArgs)
        {
#if BUILD_DEBUG
            UtilsLog.Error(this.ClassName, iFormat, iArgs);
#endif
        }