zoukankan      html  css  js  c++  java
  • 选择物体生成Prefab

    // Creates a prefab at the given path.
    // If a prefab already exists it asks if you want to replace it
    
    using UnityEngine;
    using UnityEditor;
    
    public class CreateNewPrefab : EditorWindow
    {
        [MenuItem("Prefab/Create New Prefab")]
        static void CreatePrefab()
        {
            GameObject[] objs = Selection.gameObjects;
    
            foreach (GameObject go in objs)
            {
                string localPath = "Assets/" + go.name + ".prefab";
                if (AssetDatabase.LoadAssetAtPath(localPath, typeof(GameObject)))
                {
                    if (EditorUtility.DisplayDialog("Are you sure?",
                        "The prefab already exists. Do you want to overwrite it?",
                        "Yes",
                        "No"))
                    {
                        CreateNew(go, localPath);
                    }
                }
                else
                {
                    Debug.Log(go.name + " Prefab Created");
                    CreateNew(go, localPath);
                }
            }
        }
    
        // Disable the menu item if no selection is in place
        [MenuItem("Prefab/Create New Prefab", true)]
        static bool ValidateCreatePrefab()
        {
            return Selection.activeGameObject != null;
        }
    
        static void CreateNew(GameObject obj, string localPath)
        {
            Object prefab = PrefabUtility.CreateEmptyPrefab(localPath);
            PrefabUtility.ReplacePrefab(obj, prefab, ReplacePrefabOptions.ConnectToPrefab);
        }
    }
  • 相关阅读:
    常用业务接口界面化 in python flask
    git命令中带有特殊符号如@
    生成唯一标识 字符串跟时间戳的结合
    MD5 in JAVA
    修改(同步)linux时间
    jenkins 从git拉取代码
    Git 默认不区分大小写
    postman也可以使用F12功能
    Session
    WebXML部署服务
  • 原文地址:https://www.cnblogs.com/JimmyCode/p/9178336.html
Copyright © 2011-2022 走看看