Example #1
0
 /// <summary>
 /// 检测传入的限制时间是否大于0
 /// </summary>
 /// <param name="r_MaxTime"></param>
 /// <returns></returns>
 private bool IsGreaterZero(float r_MaxTime)
 {
     if (r_MaxTime > 0)
     {
         maxTime = r_MaxTime;
         return(true);
     }
     else
     {
         DeBug.LogError("注意:传入的上限时间低于或等于0,无法进行倒计时!");
         return(false);
     }
 }
Example #2
0
 /// <summary>
 /// 保存持久化本地数据类
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static bool SetPrefs <T>(T prefs) where T : class
 {
     try
     {
         string key   = typeof(T).GetType().FullName;
         string value = JsonUtility.ToJson(prefs);
         PlayerPrefs.SetString(key, value);
         //PlayerPrefs.Save();
         return(true);
     }
     catch (Exception e)
     {
         DeBug.LogError(e.ToString());
     }
     return(false);
 }
Example #3
0
    /// <summary>
    /// 查找某个子对象的Buttom,并添加点击事件
    /// </summary>
    /// <param name="r_form"></param>
    /// <param name="r_path"></param>
    /// <param name="action"></param>
    /// <returns></returns>
    public static Button FindOnButton(this Transform r_form, string r_path, UnityAction action)
    {
        if (r_form == null)
        {
            DeBug.LogError($">>>>>>>>>>> 注意:传入 Transform 为空");
            return(null);
        }
        Button buttom = r_form.Find(r_path).GetComponent <Button>();

        if (buttom == null)
        {
            Debug.LogError($">>>>>>>>>>> 注意:查找的子对象没有Buttom组件");
            return(null);
        }

        buttom?.onClick.AddListener(action);
        return(buttom);
    }
Example #4
0
//    public static T GetTextPrefs<T>() where T : class
//    {
//        T temp = default(T);
//        StreamReader reader = null;
//        try
//        {
//            string txtPath = SetPrefsTxtPath(typeof(T));
//            if (File.Exists(txtPath))
//            {
//                reader = new StreamReader(txtPath);
//                string t = reader.ReadToEnd();
//                DeBug.LogOrange($"获取文本流信息:{t}");
//                temp = JsonUtility.FromJson<T>(t);
//            }
//        }
//        catch (Exception e)
//        {
//            Debug.LogError(e.StackTrace);
//        }
//        finally
//        {
//            if (reader != null) reader.Close();
//        }
//        return temp;
//    }

//    public static void SetTextPrefs<T>(T t) where T : class
//    {
//        StreamWriter writer = null;
//        try
//        {
//            string txt = JsonUtility.ToJson(t);
//            if (!string.IsNullOrEmpty(txt))
//            {
//                string txtPath = SetPrefsTxtPath(typeof(T));
//                if (File.Exists(txtPath))
//                {
//                    writer = new StreamWriter(txtPath, false);
//                }
//                else
//                {
//                    writer = File.CreateText(txtPath);
//                }
//                writer.Write(txt);
//                DeBug.LogGreen("保存文本流成功:" + txt);
//            }
//        }
//        catch (Exception e)
//        {
//            Debug.LogError("保存文本流失败:" + e.StackTrace);
//        }
//        finally
//        {
//            if (writer != null) writer.Close();
//        }
//    }

//    private static string SetPrefsTxtPath(Type type)
//    {
//#if UNITY_EDITOR
//        string prefix = $"{nameof(UnityExpand)}/{type.Namespace}";
//        NetExpand.ExistsOfDirectory(prefix);
//        return $"{prefix}/{type.Name}.txt";
//#elif UNITY_ANDROID || UNITY_IPHONE
//        string t = type.FullName.Replace(".", "_");
//        DeBug.Log(t);
//        return $"{Application.persistentDataPath}/{t}.txt";
//#endif

//    }


    /// <summary>
    /// 获取持久化本地数据类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <returns></returns>
    public static T GetPrefs <T>() where T : class
    {
        T      temp = default(T);
        string key  = typeof(T).GetType().FullName;

        if (PlayerPrefs.HasKey(key))
        {
            try
            {
                string value = PlayerPrefs.GetString(key);
                DeBug.LogGolden(value);
                temp = JsonUtility.FromJson <T>(value);
            }
            catch (Exception e)
            {
                DeBug.LogError(e.ToString());
            }
        }
        return(temp);
    }
Example #5
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="r_form"></param>
    /// <param name="r_path"></param>
    /// <param name="action"></param>
    public static ExpandButton FindUserButton(this Transform r_form, string r_path, UnityAction action)
    {
        ExpandButton button = null;

        if (r_form == null)
        {
            DeBug.LogError($">>>>>>>>>>> 注意:传入 Transform 为空");
        }
        else
        {
            button = r_form.Find(r_path).GetComponent <ExpandButton>();

            if (button == null)
            {
                Debug.LogError($">>>>>>>>>>> 注意:查找的子对象没有 UserButton 组件");
            }
            else
            {
                button?.onClick.AddListener(action);
            }
        }
        return(button);
    }