Add expansion Editor
The code in the Editor folder, all the scripts in this folder will first be pre-compiled to run in front of the scene, and will not be packaged into it.
Script Editor
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor;
public class SpawnManager : EditorWindow {
[MenuItem ( "Tools / Click Me!" )] // create menu Tools / Click Me! static void PatternSystem() { GameObject spawnManager = GameObject.Find("PatternManager"); if(spawnManager != null) { var patternManager = spawnManager.GetComponent<PatternManager>(); if (Selection.gameObjects.Length == 1)//如果当前鼠标只点击了1个游戏物体 { var item = Selection.gameObjects[0].transform.Find("Item");//获取当前点击的游戏物体的item子节点 if (item != null) { //创建一套道路方案 Pattern pattern = new Pattern(); foreach (var child in item) { Transform childTrans = child as Transform; if(childTrans != null) { //找到它对应的预制体 var prefab = UnityEditor.PrefabUtility.GetPrefabParent(childTrans.gameObject);//返回游戏物体对应的预制体 if (prefab != null) { //设置道路上游戏物体的信息 PatterItem patternItem = new PatterItem { pos = childTrans.localPosition, prefabName = prefab.name }; pattern.PatterItems.Add(patternItem);//将游戏物体添加到方案里 } } } patternManager.Patterns.Add(pattern);//将道路方案添加到方案列表里 } } } } }
|
点击Pattern_1,点击Click Me!
批量生成