Ejemplo n.º 1
0
    public static BIsoCursor CreateIsoCursor(string full_path, int layer = 0)
    {
        GameObject res_go = Resources.Load(s_PrefabPath) as GameObject;

        if (res_go == null)
        {
            throw new Exception("Load iso cursor prefab failed");
        }

        BIsoCursor res_cursor = res_go.GetComponent <BIsoCursor>();

        if (res_cursor == null)
        {
            throw new Exception("Load iso cursor prefab failed");
        }

        BIsoCursor iso_cursor = BIsoCursor.Instantiate(res_cursor) as BIsoCursor;

        BSIsoData iso = LoadISO(full_path);

        iso_cursor.ISO = iso;

        if (iso.m_HeadInfo.Mode == EBSVoxelType.Block)
        {
            Vector3 size = new Vector3(iso.m_HeadInfo.xSize, iso.m_HeadInfo.ySize, iso.m_HeadInfo.zSize);
            iso_cursor.SetBoundSizeOfBlock(size, iso_cursor.gameObject);
            iso_cursor.Computer = iso_cursor.BlockGroup.gameObject.AddComponent <BSB45Computer>();

            foreach (KeyValuePair <int, BSVoxel> kvp in iso_cursor.ISO.m_Voxels)
            {
                IntVector3 index = BSIsoData.KeyToIPos(kvp.Key);
                iso_cursor.Computer.AlterBlockInBuild(index.x, index.y, index.z, kvp.Value.ToBlock());
            }

            iso_cursor.Computer.RebuildMesh();
        }
        else if (iso.m_HeadInfo.Mode == EBSVoxelType.Voxel)
        {
            Debug.LogError("Cant Support the iso voxel");
            Destroy(res_go);
            Destroy(iso_cursor.gameObject);
            return(null);
        }


        Transform[] ts = iso_cursor.gameObject.GetComponentsInChildren <Transform>(true);
        foreach (Transform t in ts)
        {
            t.gameObject.layer = layer;
        }

        iso_cursor.gameObject.SetActive(true);
        iso_cursor.BlockGroup.gameObject.SetActive(true);
        iso_cursor.Bound.gameObject.SetActive(true);

        iso_cursor.testHead = iso.m_HeadInfo;

        return(iso_cursor);
    }
Ejemplo n.º 2
0
    private void OnOutputBlocks(Dictionary <int, BSVoxel> voxels, Vector3 originalPos)
    {
        List <IntVector3> posLst   = new List <IntVector3>();
        List <B45Block>   blockLst = new List <B45Block>();

        foreach (KeyValuePair <int, BSVoxel> kvp in voxels)
        {
            posLst.Add(BSIsoData.KeyToIPos(kvp.Key));
            blockLst.Add(kvp.Value.ToBlock());
        }
        B45Block.RepositionBlocks(posLst, blockLst, m_Rot, originalPos);

        int n = posLst.Count;

        for (int i = 0; i < n; i++)
        {
            IntVector3 inpos = posLst[i];
            m_Indexes.Add(inpos);
            m_OldVoxel.Add(BuildingMan.Blocks.SafeRead(inpos.x, inpos.y, inpos.z));
            m_NewVoxel.Add(new BSVoxel(blockLst[i]));
            m_VoxelMap[inpos] = 0;
        }
    }