我们在这篇把所有的弃用代码删除掉。
代码如下
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
namespace QFramework
{
public class TransformLocalPosImprovements
{
#if UNITY_EDITOR
[MenuItem("QFramework/10.Transform 赋值优化")]
#endif
private static void GenerateUnityPackageName()
{
var transform = new GameObject("transform").transform;
TransformSimplify.SetLocalPosX(transform, 5.0f);
TransformSimplify.SetLocalPosY(transform, 5.0f);
TransformSimplify.SetLocalPosZ(transform, 5.0f);
}
[Obsolete("方法已弃用,请使用 TransformSimplify")]
public static void SetLocalPosX(Transform transform, float x)
{
TransformSimplify.SetLocalPosX(transform, x);
}
[Obsolete("方法已弃用,请使用 TransformSimplify")]
public static void SetLocalPosY(Transform transform, float y)
{
TransformSimplify.SetLocalPosY(transform, y);
}
[Obsolete("方法已弃用,请使用 TransformSimplify")]
public static void SetLocalPosZ(Transform transform, float z)
{
TransformSimplify.SetLocalPosZ(transform, z);
}
[Obsolete("方法已弃用,请使用 TransformSimplify")]
public static void SetLocalPosXY(Transform transform, float x, float y)
{
TransformSimplify.SetLocalPosXY(transform, x, y);
}
[Obsolete("方法已弃用,请使用 TransformSimplify")]
public static void SetLocalPosXZ(Transform transform, float x, float z)
{
TransformSimplify.SetLocalPosXZ(transform, x, z);
}
[Obsolete("方法已弃用,请使用 TransformSimplify")]
public static void SetLocalPosYZ(Transform transform, float y, float z)
{
TransformSimplify.SetLocalPosYZ(transform, y, z);
}
}
}
删除的步骤如下:
每一个弃用的方法我们都要这样一个一个去解决。
解决按之后代码如下:
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
namespace QFramework
{
public class TransformLocalPosImprovements
{
#if UNITY_EDITOR
[MenuItem("QFramework/10.Transform 赋值优化")]
#endif
private static void GenerateUnityPackageName()
{
var transform = new GameObject("transform").transform;
TransformSimplify.SetLocalPosX(transform, 5.0f);
TransformSimplify.SetLocalPosY(transform, 5.0f);
TransformSimplify.SetLocalPosZ(transform, 5.0f);
}
}
}
第十个示例解决了。
使用以上的步骤,整理后的示例代码如下:
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using System;
using System.IO;
namespace QFramework
{
public class CommonUtil
{
public static void CopyText(string text)
{
GUIUtility.systemCopyBuffer = text;
}
}
public class Exporter
{
public static string GenerateUnityPackageName()
{
return "QFramework_" + DateTime.Now.ToString("yyyyMMdd_hh");
}
}
public class EditorUtil
{
#if UNITY_EDITOR
public static void CallMenuItem(string menuPath)
{
EditorApplication.ExecuteMenuItem(menuPath);
}
public static void OpenInFolder(string folderPath)
{
Application.OpenURL("file:///" + folderPath);
}
public static void ExportPackage(string assetPathName,string fileName)
{
AssetDatabase.ExportPackage(assetPathName, fileName, ExportPackageOptions.Recurse);
}
#endif
}
public class PreviousFunctions : MonoBehaviour
{
#if UNITY_EDITOR
[MenuItem("QFramework/8.总结之前的方法/1.获取文件名")]
private static void MenuClicked()
{
Debug.Log(Exporter.GenerateUnityPackageName());
}
[MenuItem("QFramework/8.总结之前的方法/2.复制文本到剪切板")]
private static void MenuClicked2()
{
CommonUtil.CopyText("要复制的关键字");
}
[MenuItem("QFramework/8.总结之前的方法/3.生成文件名到剪切板")]
private static void MenuClicked3()
{
CommonUtil.CopyText(Exporter.GenerateUnityPackageName());
}
[MenuItem("QFramework/8.总结之前的方法/4.导出 UnityPackage")]
private static void MenuClicked4()
{
EditorUtil.ExportPackage("Assets/QFramework",Exporter.GenerateUnityPackageName() + ".unitypackage");
}
[MenuItem("QFramework/8.总结之前的方法/5.打开所在文件夹")]
private static void MenuClicked5()
{
EditorUtil.OpenInFolder(Application.dataPath);
}
[MenuItem("QFramework/8.总结之前的方法/6.MenuItem 复用")]
private static void MenuClicked6()
{
EditorUtil.CallMenuItem("QFramework/8.总结之前的方法/4.导出 UnityPackage");
EditorUtil.OpenInFolder(Path.Combine(Application.dataPath, "../"));
}
#endif
}
}
是不是感觉清爽了很多?哈哈哈。
整理之后代码如下:
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
namespace QFramework
{
public class TransformSimplify
{
///
/// 重置操作
///
/// Trans.
public static void Identity(Transform trans)
{
trans.localPosition = Vector3.zero;
trans.localScale = Vector3.one;
trans.localRotation = Quaternion.identity;
}
public static void SetLocalPosX(Transform transform, float x)
{
var localPos = transform.localPosition;
localPos.x = x;
transform.localPosition = localPos;
}
public static void SetLocalPosY(Transform transform, float y)
{
var localPos = transform.localPosition;
localPos.y = y;
transform.localPosition = localPos;
}
public static void SetLocalPosZ(Transform transform, float z)
{
var localPos = transform.localPosition;
localPos.z = z;
transform.localPosition = localPos;
}
public static void SetLocalPosXY(Transform transform, float x, float y)
{
var localPos = transform.localPosition;
localPos.x = x;
localPos.y = y;
transform.localPosition = localPos;
}
public static void SetLocalPosXZ(Transform transform, float x, float z)
{
var localPos = transform.localPosition;
localPos.x = x;
localPos.z = z;
transform.localPosition = localPos;
}
public static void SetLocalPosYZ(Transform transform, float y, float z)
{
var localPos = transform.localPosition;
localPos.y = y;
localPos.z = z;
transform.localPosition = localPos;
}
}
public class TransformIdentity : MonoBehaviour
{
#if UNITY_EDITOR
[MenuItem("QFramework/11.Transform 归一化")]
#endif
private static void MenuClicked()
{
var transform = new GameObject("transform").transform;
TransformSimplify.Identity(transform);
}
}
}
整理之后代码如下:
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using Random = UnityEngine.Random;
namespace QFramework
{
public class MathUtil
{
///
/// 输入百分比返回是否命中概率
///
public static bool Percent(int percent)
{
return Random.Range (0, 100) <= percent;
}
}
public class PercentFunction : MonoBehaviour
{
#if UNITY_EDITOR
[MenuItem("QFramework/12.概率函数")]
#endif
private static void MenuClicked()
{
Debug.Log(MathUtil.Percent(50));
}
}
}
到目前为止,我们把所有的弃用的方法全部删除了。
全部删除之后,笔者的心情轻松了很多。
当前的状态如下:
注意:在约定和规则部分,增加了删除弃用代码的步骤。
今天内容就这些,我们在下篇接着整理。
转载请注明地址:凉鞋的笔记:liangxiegame.com
QFramework 地址:https://github.com/liangxiegame/QFramework
QQ 交流群:623597263
Unity 进阶小班:
关注公众号:liangxiegame 获取第一时间更新通知及更多的免费内容。