728x90
Unity Editor๋ผ๋ ๋ค์์คํ์ด์ค(ํด๋์ค์ ์งํฉ)์ ํด๋์ค๋ฅผ ํ์ฉํ๋ฉด ์ ๋ํฐ ์๋ํฐ๋ฅผ ์ปค์คํฐ๋ง์ด์งํ ์ ์๋ค. ์๋ฅผ ๋ค์ด, ์ํ๋ ๋งคํฌ๋ก๋ฅผ ๋ง๋ค๊ณ ๋ฉ๋ด ์ฐฝ์ ์ถ๊ฐํ๋ค๋ ๊ฐ..!
๊ฐ๋ฐํด์ ์ปค์คํฐ๋ง์ด์งํด๋ณธ ๊ฑด ์ฒ์์ด๋ผ ์ ๊ธฐํด์ ์ ๋ฆฌํด๋ด
๊ธฐ๋ฅ์ ๋ณด๋ ค๊ณ , ์ค์ ์ฌ์ฉํ ์ฝ๋ ์ค ์ผ๋ถ๋ฅผ ๋ณํํด์ ๊ฐ์ ธ์จ ๊ฑฐ๋ผ
๋ณ์, ๋ฉ์๋๋ช ๋ฑ์ ์ฝ๋ ๊ฐ ํธํ์ด ์๋ ์๋ ์์ผ๋ฉฐ ๋ง๋ ์ปค์คํ ๋ฉ์๋ ์ค๋ช ์ ์๋ตํ๋ค.
1. Assets/Editor์ ์คํฌ๋ฆฝํธ๋ฅผ ๋ง๋ ๋ค.

2. Unity Editor ๋ค์์คํ์ด์ค๋ฅผ ์ฌ์ฉํ๋ค.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor; // ์ถ๊ฐํจ
// EditorWindow ํด๋์ค๋ฅผ ์ฌ์ฉํ์ฌ, ์๋ํฐ ์๋์ ๋ฉ๋ด ์ถ๊ฐ
public class MyWindow : EditorWindow
{
//***** Add Window Menu
[MenuItem("MyWindow/AddComponent")]
static void init()
{
// AddComponent ๋ฉ๋ด๋ฅผ ๋๋ฅด๋ฉด ์ ์ฐฝ์ด ๋ฌ๋ค.
MyWindow window = (MyWindow)EditorWindow.GetWindow(typeof(MyWindow));
window.Show();
}
//***** Window Design
private void OnGUI()
{
if (GUILayout.Button("add component"))
// Selection ํด๋์ค์ activeTransform์ ์ฌ์ฉํ๋ฉด
// ํ์ฌ ์ ํ๋ ์ค๋ธ์ ํธ์ transform์ ๊ฐ์ ธ์ฌ ์ ์๋ค.
// ์ค๋ธ์ ํธ ํ์
์ผ๋ก ๊ฐ์ ธ์ค๋ ค๊ณ .gameObject ์ถ๊ฐํจ
UserCustomMethod(Selection.activeTransform.gameObject);
}
3. ( ๋ฉ์๋: ์ฌ์ฉํ API๋ง ์ฐธ๊ณ )
// ....
public GameObject targetObject;
public GameObject parentObject;
int finMeshCount = 0;
// Function
void UserCustomMethod(GameObject gameObject)
{
for(int i=0; i<gameObject.transform.childCount; i++)
{
// ์ค๋ธ์ ํธ์ child์ ์ ๊ทผํ๋ ค๋ฉด transform์์ Getchild ์ฌ์ฉํด์ผ ํจ
GameObject childObject = gameObject.transform.GetChild(i).gameObject;
AddForStructureParent(childObject);
AddForStructureChild(childObject);
parentObject = childObject;
// GameObject.GetComponent<Type>()์ผ๋ก ์ค๋ธ์ ํธ์ ์ปดํฌ๋ํธ ์ป์ ์ ์์
// .์์ฑ๋ช
์ผ๋ก ์ปดํฌ๋ํธ ์์ฑ๋ get, setํ ์ ์์
childObject.GetComponent<CustomScript>().parentObj = parentObject.GetComponent<CustomScript>();
}
}
void UserCustomMethod3(GameObject gameObject)
{
if (gameObject.GetComponent<MeshCollider>() == null)
// ์ค๋ธ์ ํธ์ ํ์
์ ์ง์ ํ์ฌ ์ปดํฌ๋ํธ๋ฅผ ์ถ๊ฐํ๋ ๊ฒ๋ ๊ฐ๋ฅํ๋ค.
gameObject.AddComponent<MeshCollider>();
// ์คํฌ๋ฆฝํธ๋ช
์ <ํ์
>์ ๋ฃ์ด์ฃผ๋ฉด ์คํฌ๋ฆฝํธ ์ปดํฌ๋ํธ๋ ์ถ๊ฐ ๊ฐ๋ฅ
if (gameObject.GetComponent<MyScript>() == null)
gameObject.AddComponent<MyScript>();
}

728x90
'๐ ํ์ต๊ณผ ๊ฐ๋ฐ ๊ธฐ๋ก > Unity' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Shader ๊ธฐ๋ณธ๊ฐ๋ (0) | 2021.09.07 |
---|---|
Unity - ์๋๋ก์ด๋ ๋น๋ ์ฝ์ง ๊ธฐ๋ก (0) | 2021.08.25 |
ํน์ ๊ฑด๋ฌผ์ ๋ง์ปค ์์ฑํ๊ธฐ (0) | 2021.08.12 |
Visual Studio์์ ๋ฐ์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ Unity์์ ์คํฌ๋ฆฝํธ ์คํ ์ ์ ์ฉ ์๋ ๋ (0) | 2021.08.12 |
์ ๋ํฐ ์ค์น ๋ฐ ํ๋ก์ ํธ ์์ฑ (0) | 2021.08.08 |