zoukankan      html  css  js  c++  java
  • 拓展Scene视图——场景编辑Vector2/3

    Test.cs

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Test : MonoBehaviour {
        
        [SerializeField]
        private Vector2 _pt=new Vector2(0,0);
    
        public Vector2 point{
            get { return _pt; }
            set { _pt=value; }
        }
    }

    MyEditor.cs

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEditor;
    
    [CustomEditor(typeof(Test))]
    public class MyEditor : Editor {
        private void OnSceneGUI() {
            Test test=(Test)target;
            
            //绘制文本框
             Handles.Label(test.point,string.Format("({0},{1})",test.point.x,test.point.y));
            
            EditorGUI.BeginChangeCheck();
            float size=HandleUtility.GetHandleSize(test.point)*0.05f;
            Vector2 snap=Vector2.one*0.05f;
            Vector2 newPoint=Handles.FreeMoveHandle(test.point,Quaternion.identity,size,snap,Handles.DotHandleCap);
            if(EditorGUI.EndChangeCheck()){
                Undo.RecordObject(test,"change point");//记录更改,实现撤消回退
                test.point=newPoint;
            }
        }
    
    }

  • 相关阅读:
    Java面向对象(继承、抽象类)
    Java面向对象(类、封装)
    Java基础语法(Eclipse)
    JavaScript new对象的四个过程
    原生js实现深复制
    es6 实现双链表
    快速排序
    跨域问题
    pm2 使用
    js冒泡排序
  • 原文地址:https://www.cnblogs.com/kingBook/p/7650487.html
Copyright © 2011-2022 走看看