: :其他软件 2019-09-15 14:45:23
这些方法写的很乱。。平时想要什么功能就加上什么功能。。。主要是方便自己的。
本想整理下再发出来,但这这9月大学刚刚开学,事情有一些多,所以一直没空整理,
具体使用方法就是dnspy把Assembly-CSharp.dll拖进去后 把整个类添加进去, 然后在需要的地方调用对应的方法就行。
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
namespace NutUnityDebug
{
public delegate void gm_keydown_Action();
public class Nut : MonoBehaviour
{
public Nut(MonoBehaviour theMonoBehaviour)
{
this.MyMonoBehaviour = theMonoBehaviour;
}
//打印出当前的场景名字以及Unity版本
public static void NutDBG_showNowSencen()
{
UnityEngine.SceneManagement.Scene scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
Debug.Log(scene.buildIndex + "==NutDBG_showNowSencen==" + scene.name);
Debug.Log(Application.unityVersion + " ==Application.unityVersion==Application.version==" + Application.version);
}
//获取参数GameObject在场景中的路径
public static string NutDBG_getThePath(GameObject theGameObject)
{
string text = Nut.NutDBG_getThePath_temp(theGameObject, theGameObject.name);
Text component = theGameObject.GetComponent<Text>();
if (component != null)
{
text = text + "----Text->" + component.text;
}
return text;
}
private static string NutDBG_getThePath_temp(GameObject theGameObject, string returnPath)
{
Transform temp = theGameObject.transform.parent;
if (temp != null)
{
returnPath = temp.name + "/" + returnPath;
GameObject theTemp;
returnPath = NutDBG_getThePath_temp(temp.gameObject, returnPath);
}
return returnPath;
}
//按下对应的按键执行对应的功能
static float theConTime = 1;
public static void NutDBG_keydown(gm_keydown_Action temp)
{
theConTime -= Time.deltaTime;
if(theConTime < 0)
{
if (Input.GetKey(KeyCode.D))//按下D键
{
theConTime = 10;
NutDBG_showAll(); //把当前场景所有GameObject的名字显示在物体上
}
if (Input.GetKey(KeyCode.P))//按下P键
{
theConTime = 10;
NutDBG_showAllPath(); //显示当前场景所有GameObject的路径
}
if (Input.GetKey(KeyCode.S))//按下S键
{
theConTime = 10;
NutDBG_showNowSencen(); //打印出当前的场景名字以及Unity版本
}
}
}
//显示当前场景所有GameObject的路径
public static void NutDBG_showAllPath()
{
string text = "";
int thei = 0;
foreach (GameObject gameObject in Resources.FindObjectsOfTypeAll(typeof(GameObject)) as GameObject[])
{
MonoBehaviour.print(thei + "==NutDBG_showAllPath==>" + Nut.NutDBG_getThePath(gameObject));
thei++;
}
Debug.Log("-->" + text);
}
//把当前场景所有GameObject的名字显示在物体上
public static void NutDBG_showAll()
{
Debug.Log("NutDBG_showAll-------------->");
string text = "";
foreach (GameObject gameObject in Resources.FindObjectsOfTypeAll(typeof(GameObject)) as GameObject[])
{
if (gameObject.GetComponent<RectTransform>() != null)
{
GameObject gameObject2 = new GameObject("new=" + gameObject.name);
gameObject2.transform.parent = gameObject.transform;
gameObject2.transform.localPosition = new Vector3(0f, -30f + UnityEngine.Random.value * 60f, 0f);
gameObject2.AddComponent<Text>().text = "==" + gameObject.name;
gameObject2.GetComponent<Text>().color = new Color(1f, 0f, 1f);
gameObject2.GetComponent<Text>().fontSize = 12;
gameObject2.GetComponent<Text>().horizontalOverflow = HorizontalWrapMode.Overflow;
gameObject2.GetComponent<Text>().font = Font.CreateDynamicFontFromOSFont(Font.GetOSInstalledFontNames()[0], 20);
}
text = text + "|" + gameObject.transform.name;
}
Debug.Log("-->" + text);
}
// 获取Button上绑定的脚本,以及调用的方法名字
public static void NutDBG_getTheButtonScript(GameObject the_gameObject)
{
Button.ButtonClickedEvent onClick = the_gameObject.GetComponent<Button>().onClick;
for (int i = 0; i < onClick.GetPersistentEventCount(); i++)
{
Debug.Log(string.Concat(new object[]
{
"Ugui_getTheButtonScript-->",
onClick.GetPersistentTarget(i),
".",
onClick.GetPersistentMethodName(i)
}));
}
}
// 获取GameObject上绑定的所有脚本/组件
public static void NutDBG_getGameObjectScript(GameObject the_gameObject)
{
if(the_gameObject == null)
{
Debug.Log("Ugui_gm_getGameObjectScript-->fail-->no GameOBJ-->");
return;
}
Component[] components = the_gameObject.transform.GetComponents(typeof(Component));
for (int i = 0; i < components.Length; i++)
{
Debug.Log("Ugui_getGameObjectScript-->" + components[i]);
}
}
//向游戏中加入自己的图片
public GameObject NutDBG_create(string theName, Transform theParent, Vector3 theLocalPosition, string theUrl)
{
GameObject gameObject = new GameObject(theName);
gameObject.transform.parent = theParent;
gameObject.transform.localPosition = theLocalPosition;
gameObject.AddComponent<RawImage>();
this.MyMonoBehaviour.StartCoroutine(this.LoadTheImage(theUrl, gameObject));
return gameObject;
}
// 加载指定路径的图片
private IEnumerator LoadTheImage(string theUrl, GameObject theGameOBJ)
{
Debug.Log("传入的URL:" + theUrl);
WWW www = new WWW("jar:file://" + theUrl);
yield return www;
if (string.IsNullOrEmpty(www.error))
{
Texture2D texture = www.texture;
theGameOBJ.GetComponent<RawImage>().texture = www.texture;
theGameOBJ.GetComponent<RawImage>().SetNativeSize();
}
yield break;
}
//向安卓层发消息 methodName为安卓层接收消息的方法名
public static void NutDBG_sendMsgToAndroid(string methodName, string msg = null)
{
Debug.Log("SendMsgToAndroid " + methodName + " and msg is " + msg);
using (AndroidJavaClass androidJavaClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
using (AndroidJavaObject [url=home.php?mod=space&uid=452844]@static[/url] = androidJavaClass.GetStatic<AndroidJavaObject>("currentActivity"))
{
if (msg == null)
{
@static.Call(methodName, new object[0]);
}
else
{
@static.Call(methodName, new object[]
{
msg
});
}
}
}
}
//NutDBG_sendMsgToAndroid() 这个方法的封装版本。。
//默认安卓层接收消息的方法名为u3dToJava_msg
//后面的两个string参数是为了自己方便输出的Log
public static void NutDBG_SendMessageToJava(string msg, string CallBackObjName, string CallBackMethodName)
{
try
{
if (msg != null)
{
Nut.NutDBG_sendMsgToAndroid("u3dToJava_msg", msg);
Debug.Log(string.Concat(new string[]
{
"SendMsg_msg ",
msg,
" Your CallBack Path is:("",
CallBackObjName,
"","",
CallBackMethodName,
"""
}));
}
else
{
Nut.NutDBG_sendMsgToAndroid("u3dToJava_exit", null);
Debug.Log(string.Concat(new string[]
{
"SendMsg_exit ",
msg,
" Your CallBack Path is:("",
CallBackObjName,
"","",
CallBackMethodName,
"""
}));
}
}
catch (Exception e)
{
if (e.ToString().Contains("UnityPlayerActivity"))
{
Debug.Log(string.Concat(new string[]
{
"SendMsg_Fail ",
msg,
" Your CallBack Path is:("",
CallBackObjName,
"","",
CallBackMethodName,
"""
}));
}
else
{
Debug.Log(string.Concat(new object[]
{
"NutDBG_sendMsgToAndroid=",
msg,
"=",
e
}));
}
}
}
//寻找该物体下所有包含Text组件的子物体
public static void NutDBG_GetTextFromChild(GameObject the_gameObject)
{
int Count = 0;
Transform[] AllObj = the_gameObject.GetComponentsInChildren<Transform>(true);
foreach (Transform child in AllObj)
{
if (child.gameObject.GetComponent<Text>() != null)
{
Debug.Log("Nut_Ugui__ --FatherName:" + the_gameObject.name + " ChildName:" + child.name + " Text:" + child.gameObject.GetComponent<Text>().text);
Count++;
}
}
if (Count == 0)
{
Debug.Log("Nut_Ugui__GetTextFromChild Sorry I Can't Find Text with this GameObj");
}
else
{
Debug.Log("Nut_Ugui__GetTextFromChild Query completed, " + Count.ToString() + " locations found");
}
}
//显示按钮的所有信息
//此方法加在UnityEngine.UI.Press()方法下 可打印出当前被点击按钮的所有信息
public static void NutDBG_ShowBtnInfo(GameObject Button)
{
Debug.Log("==UGUI=button=="+Button.name+"==localPosition=="+Button.transform.localPosition+"==anchorMin=="+Button.GetComponent<RectTransform>().anchorMin+"==anchorMax=="+Button.GetComponent<RectTransform>().anchorMax);
NutUnityDebug.Nut.NutDBG_getTheButtonScript(Button);
NutUnityDebug.Nut.NutDBG_getThePath(Button);
NutUnityDebug.Nut.NutDBG_getGameObjectScript(Button);
}
private MonoBehaviour MyMonoBehaviour;
}
}
10-13《游戏编程All In One》代码
10-13Scratch:打方砖游戏.sb3
10-12计算机游戏程序设计(基础篇)
10-12次世代游戏高端制作技术与游戏引擎
10-12三维游戏引擎设计与实现
10-12游戏程序设计教程,从游戏引擎构建到实际应
10-12游戏引擎原理与实践 卷2:高级技术
10-12游戏引擎原理与实践 卷1:基础框架
10-04Excel动态图表添加复选框控件
10-03Excel如何制作动态图表的方法
08-28ppt动态图添加方法讲解
11-28Excel给动态图表添加滚动条
11-26PPT动态按钮和超链接有什么区别
11-26Word相关特定文字添加动态效果
11-24ppt设置动态背景,背景图片不可以裁剪
11-19在ppt中插入动态图片方法