先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
85 lines
3.6 KiB
C#
85 lines
3.6 KiB
C#
using UnityEditor;
|
||
using UnityEngine;
|
||
|
||
public class CopySelectedPath
|
||
{
|
||
[MenuItem("Tools/Screenshot &#S")]
|
||
static void Screenshot()
|
||
{
|
||
string path = EditorUtility.SaveFilePanel("Save Screenshot", "", "screenshot", "png");
|
||
if (!string.IsNullOrEmpty(path))
|
||
{
|
||
ScreenCapture.CaptureScreenshot(path);
|
||
}
|
||
}
|
||
[MenuItem("GameObject/Copy Selected Object Path to Clipboard")]
|
||
static void CopySelectedObjectPrefabPathToClipboard()
|
||
{
|
||
GameObject selectedObject = Selection.activeGameObject;
|
||
if (selectedObject != null)
|
||
{
|
||
//获得选中节点在当前场景中的路径
|
||
string prefabPath = GetTransformPath(selectedObject.transform);
|
||
prefabPath = prefabPath.Substring(prefabPath.IndexOf('/') + 1);
|
||
EditorGUIUtility.systemCopyBuffer = prefabPath;
|
||
Debug.Log("已将当前选中对象在Prefab中的路径复制到剪切板中:" + prefabPath);
|
||
}
|
||
else
|
||
{
|
||
Debug.Log("没有选中任何对象!");
|
||
}
|
||
}
|
||
public static string GetTransformPath(Transform transform, MonoBehaviour monoBehaviour = null)
|
||
{
|
||
if (transform.parent == null || transform.parent.name.Contains("Canvas") || (monoBehaviour != null && transform.GetComponent(monoBehaviour.GetType()) != null))
|
||
{
|
||
return transform.name;
|
||
}
|
||
else
|
||
{
|
||
return GetTransformPath(transform.parent, monoBehaviour) + "/" + transform.name;
|
||
}
|
||
}
|
||
[MenuItem("CONTEXT/MonoBehaviour/Get All Component")]
|
||
static void GetAllGameObjects(MenuCommand command)
|
||
{
|
||
MonoBehaviour monoBehaviour = command.context as MonoBehaviour;
|
||
if (monoBehaviour != null)
|
||
{
|
||
SerializedObject serializedObject = new SerializedObject(monoBehaviour);
|
||
SerializedProperty property = serializedObject.GetIterator();
|
||
string str = "";
|
||
|
||
while (property.NextVisible(true))
|
||
{
|
||
if (property.propertyType == SerializedPropertyType.ObjectReference && property.objectReferenceValue != null)
|
||
{
|
||
string type = property.type.Substring(property.type.IndexOf("$") + 1);
|
||
Component gameObject = property.objectReferenceValue as Component;
|
||
if (gameObject != null)
|
||
{
|
||
string prefabPath = GetTransformPath(gameObject.transform, monoBehaviour);
|
||
prefabPath = prefabPath.Substring(prefabPath.IndexOf('/') + 1);
|
||
Debug.Log("属性 " + property.name + " 对应的 Game Object:" + prefabPath);
|
||
str += $" {property.name}= transform.Find(\"{prefabPath}\").GetComponent<{type}();\n";
|
||
}
|
||
else
|
||
{
|
||
GameObject gameObject1 = property.objectReferenceValue as GameObject;
|
||
if (gameObject1 != null)
|
||
{
|
||
string prefabPath = GetTransformPath(gameObject1.transform, monoBehaviour);
|
||
prefabPath = prefabPath.Substring(prefabPath.IndexOf('/') + 1);
|
||
Debug.Log("属性 " + property.name + " 对应的 Game Object:" + prefabPath);
|
||
str += $" {property.name}= transform.Find(\"{prefabPath}\").gameObject;\n";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
EditorGUIUtility.systemCopyBuffer = str;
|
||
Debug.Log("已将当前选中对象在Prefab中的路径复制到剪切板中:\n" + str);
|
||
}
|
||
}
|
||
|
||
}
|