设置对象(Mesh)的锚点

本文介绍了两种在Unity3D中设置对象(Mesh)锚点的方法。第一种是通过参考SetPivot来调整对象的位置中心点,作为缩放和旋转的中心。第二种方法是利用父对象和子对象的关系,通过创建一个立方体作为锚点,调整其在模型中的位置,然后将模型设为立方体的子对象,实现锚点设置。完成设置后,可以通过旋转或缩放验证锚点的效果。
摘要由CSDN通过智能技术生成

2016.8.14   孙广东

 

第一种方式:

本文参考: http://wiki.unity3d.com/index.php?title=SetPivot

Pivot  (锚点),  熟悉 UGUI肯定熟悉 锚点,

锚点就是  对象的位置中心点, 缩放和旋转的中心!!!

/*
 * Version: 1.0
 * Author:  Yilmaz Kiymaz (@VoxelBoy)
 * Purpose: To be able to change the pivot of Game Objects
 *          without needing to use a separate 3D application.
 * License: Free to use and distribute, in both free and commercial projects.
 *          Do not try to sell as your own work. Simply put, play nice
 * Contact: VoxelBoy on Unity Forums
 */
 
using UnityEngine;
using UnityEditor;
 
public class SetPivot : EditorWindow
{
 
    Vector3 p; //Pivot value -1..1, calculated from Mesh bounds
    Vector3 last_p; //Last used pivot
 
    GameObject obj; //Selected object in the Hierarchy
    MeshFilter meshFilter; //Mesh Filter of the selected object
    Mesh mesh; //Mesh of the selected object
    Collider col; //Collider of the selected object
 
    bool pivotUnchanged; //Flag to decide when to instantiate a copy of the mesh
 
    [MenuItem("GameObject/Set Pivot")] //Place the Set Pivot menu item in the GameObject menu
    static void Init()
    {
        SetPivot window = (SetPivot)EditorWindow.GetWindow(typeof(SetPivot));
        window.RecognizeSelectedObject(); //Initialize the variables by calling RecognizeSelectedObject on the class instance
        window.Show();
    }
 
    void OnGUI()
    {
        if (obj)
        {
            if (mes
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值