コード例 #1
0
 public static void AddScriptToObject()
 {
     if (Selection.activeTransform != null)
     {
         Vector3    pos      = Selection.activeTransform.position;
         GameObject gridRoot = new GameObject("UniTiled 3D Grid");
         gridRoot.transform.position = pos;
         Grid3DMaker gridMaker = gridRoot.AddComponent <Grid3DMaker>();
         gridRoot.AddComponent <TileCreator>();
         foreach (Transform child in Selection.GetTransforms(SelectionMode.TopLevel))
         {
             child.parent = gridRoot.transform;
         }
         gridMaker.Refresh();
     }
 }
コード例 #2
0
ファイル: TileCreator.cs プロジェクト: yjaffal/unitiled
    /// <summary>
    /// Starts by (1) finding "TileGenerationCam" and set its properties
    /// to match tile generation setting specified in the variables
    /// of this script, (2) refreshing the attached Grid3DMaker script to
    /// make sure all models are ready for tile generation, and (3) set orthogonal
    /// size of tile capturing camera to match the size of the 3D tiles as
    /// specified in the attached Grid3DMaker
    /// </summary>
    void Start()
    {
        GameObject captureCamObj = new GameObject("Tile Generation Cam");

        captureCamTrans             = captureCamObj.transform;
        captureCamTrans.eulerAngles = new Vector3(90.0f, 0, 0);

        captureCam                 = captureCamObj.AddComponent <Camera>();
        captureCam.clearFlags      = CameraClearFlags.Color;
        captureCam.backgroundColor = transparentColor;
        Grid3DMaker gMaker = GetComponent <Grid3DMaker>();

        captureCam.orthographicSize = Mathf.Min(gMaker.tileSize.x, gMaker.tileSize.z) * gMaker.maxDiff * 0.5f;
        captureCam.orthographic     = true;

        GameObject prevCamObj = GameObject.Find("Tile Preview Cam");

        if (prevCamObj == null)
        {
            Debug.LogWarning("Warning: tile preview cam not found. Refresh grid 3D maker to re-instantiate cam");
            UnityEditor.EditorApplication.isPlaying = false;
            return;
        }

        prevCam = prevCamObj.GetComponent <Camera>();
        if (prevCam == null)
        {
            prevCam = prevCamObj.AddComponent <Camera>();
        }
        prevCam.depth = 1;
        //prevCam.rect = new Rect(0, -0.65f, 0.35f, 1);

        captureCamTrans.position = new Vector3(0, 50, 0);

        Transform prevCamTrans = prevCamObj.transform;

        prevCamTrans.parent = captureCamTrans;

        gMaker.Refresh();
        generatedPaths = new List <string>();
        string tilesPath = Application.dataPath + "/" + TILES_FOLDER + "/" + collectionName;

        if (Directory.Exists(tilesPath))
        {
            Directory.Delete(tilesPath, true);
        }
    }