unity editor下选中GameObject粘贴复制pos信息

Posted sun_dust_shadow

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了unity editor下选中GameObject粘贴复制pos信息相关的知识,希望对你有一定的参考价值。

参考:https://blog.uwa4d.com/archives/USparkle_Continuous-optimization.html

 实现:运行时 选中GameObject后copy坐标信息可粘贴出来

实现代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestCopyPosHelper : MonoBehaviour {

    private void OnEnable()
    {
        UnityEditor.Selection.selectionChanged += OnSelectChanged;
    }

    // Use this for initialization
    void Start ()
    {
		
	}
	
	// Update is called once per frame
	void Update ()
    {

    }

    private void OnDisable()
    {
        UnityEditor.Selection.selectionChanged -= OnSelectChanged;
    }


    private void OnSelectChanged()
    {
        GameObject tempSelectObject = UnityEditor.Selection.activeGameObject;
        if(tempSelectObject!=null)
        {
            string ret = tempSelectObject.transform.localPosition.x.ToString("0.0") + "," +
                         tempSelectObject.transform.localPosition.y.ToString("0.0") + "," +
                         tempSelectObject.transform.localPosition.z.ToString("0.0");
            Debug.LogError(ret);
            GUIUtility.systemCopyBuffer = ret;
        }
    }
}

  

以上是关于unity editor下选中GameObject粘贴复制pos信息的主要内容,如果未能解决你的问题,请参考以下文章

Unity Editor 脚本用指定 GameObject 的子级填充序列化数组 [关闭]

Unity Editor模式下,操作选中对象

Unity 怎么获取场景中顶级节点的所有GameObject

Unity查找Editor下Project视图中特定的资源

图解unity下gameobject和transform的区别和关联

unity C# 一个public gameobject 怎么在 同一个场景下的另一个script中 引用这个gameobject获取属性??