LoginSignup
12

More than 5 years have passed since last update.

コーネルボックスを作るUnityEditor拡張

Posted at

毎回コーネルボックスを作るのが面倒だったので
コーネルボックスを作成してくれるEditor拡張をつくってみました :)

using UnityEngine;
using UnityEditor;

public class ConelBoxGenerator
{
    [MenuItem ("Tools/Else/ConelboxGenerate")]
    static void Ceate ()
    {
        var conelbox = new GameObject ().transform;
        conelbox.name = "conelbox";
        SetPosition (conelbox, 0, 0, 0);
        //Left
        var plane0 = GameObject.CreatePrimitive (PrimitiveType.Plane).transform;
        SetPosition (plane0, -5, 0, 0);
        SetRotation (plane0, 0, 0, -90);
        //right
        var plane1 = GameObject.CreatePrimitive (PrimitiveType.Plane).transform;
        SetPosition (plane1, 5, 0, 0);
        SetRotation (plane1, 0, 0, 90);
        //up
        var plane2 = GameObject.CreatePrimitive (PrimitiveType.Plane).transform;
        SetPosition (plane2, 0, 5, 0);
        SetRotation (plane2, 0, 0, 180);
        //down
        var plane3 = GameObject.CreatePrimitive (PrimitiveType.Plane).transform;
        SetPosition (plane3, 0, -5, 0);
        SetRotation (plane3, 0, 0, 0);
        //back
        var plane4 = GameObject.CreatePrimitive (PrimitiveType.Plane).transform;
        SetPosition (plane4, 0, 0, -5);
        SetRotation (plane4, 90, 0, 0);
        //front
        var plane5 = GameObject.CreatePrimitive (PrimitiveType.Plane).transform;
        SetPosition (plane5, 0, 0, 5);
        SetRotation (plane5, -90, 0, 0);

        plane0.SetParent (conelbox, false);
        plane1.SetParent (conelbox, false);
        plane2.SetParent (conelbox, false);
        plane3.SetParent (conelbox, false);
        plane4.SetParent (conelbox, false);
        plane5.SetParent (conelbox, false);
        plane0.gameObject.isStatic = true;
        plane1.gameObject.isStatic = true;
        plane2.gameObject.isStatic = true;
        plane3.gameObject.isStatic = true;
        plane4.gameObject.isStatic = true;
        plane5.gameObject.isStatic = true;
        conelbox.gameObject.isStatic = true;

    }

    static void SetRotation (Transform transform, int x, int y, int z)
    {
        transform.rotation = Quaternion.Euler (x, y, z);
    }

    static void SetPosition (Transform transform, int x, int y, int z)
    {
        transform.position = new Vector3 (x, y, z);
    }
}

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12