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;
        }
    }
}

  

改变自己
原文地址:https://www.cnblogs.com/sun-shadow/p/9080158.html