码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-05-23 23:38:53      阅读:267      评论:0      收藏:0      [点我收藏+]

标签:call   Once   bug   null   update   unit   this   class   arch   

参考: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信息

标签:call   Once   bug   null   update   unit   this   class   arch   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!