Ejemplo n.º 1
0
    internal static void SerializeItemInfo(uLink.BitStream stream, object value, params object[] codecOptions)
    {
        CreatItemInfo itemInfo = value as CreatItemInfo;

        stream.Write <int>(itemInfo.mItemId);
        stream.Write <Vector3>(itemInfo.mPos);
        stream.Write <Quaternion>(itemInfo.mRotation);
    }
Ejemplo n.º 2
0
    internal static object DeserializeItemInfo(uLink.BitStream stream, params object[] codecOptions)
    {
        CreatItemInfo itemInfo = new CreatItemInfo();

        itemInfo.mItemId   = stream.Read <int>();
        itemInfo.mPos      = stream.Read <Vector3>();
        itemInfo.mRotation = stream.Read <Quaternion>();
        return(itemInfo);
    }
Ejemplo n.º 3
0
    public void GetBuildingInfo(out Vector3 size, out Dictionary <IntVector3, B45Block> blocks, out List <Vector3> npcPosition
                                , out List <CreatItemInfo> itemList, out Dictionary <int, BuildingNpc> npcIdPosRot)
    {
        Bounds bound = new Bounds(Vector3.zero, Vector3.zero);

        blocks      = new Dictionary <IntVector3, B45Block>();
        npcPosition = new List <Vector3>();
        itemList    = new List <CreatItemInfo>();
        npcIdPosRot = new Dictionary <int, BuildingNpc>();

        TextAsset    textFile = Resources.Load(mPath) as TextAsset;
        MemoryStream ms       = new MemoryStream(textFile.bytes);
        BinaryReader _in      = new BinaryReader(ms);

        int readVersion = _in.ReadInt32();

        switch (readVersion)
        {
        case 2:
            int Size = _in.ReadInt32();
            for (int i = 0; i < Size; i++)
            {
                IntVector3 index = new IntVector3(_in.ReadInt32(), _in.ReadInt32(), _in.ReadInt32());
                B45Block   block = new B45Block(_in.ReadByte(), _in.ReadByte());
                if ((block.blockType >> 2) != 0)
                {
                    blocks[index] = block;
                    index         = new IntVector3(index);
                    index.x      += 1;
                    index.z      += 1;
                    bound.Encapsulate(BSBlock45Data.s_Scale * index.ToVector3());
                }
            }
            break;
        }


        _in.Close();
        ms.Close();

        BoundSize = size = bound.size;
        UnityEngine.Object subInfo = Resources.Load(mPath + "SubInfo");
        if (null != subInfo)
        {
            textFile = subInfo as TextAsset;
            ms       = new MemoryStream(textFile.bytes);
            _in      = new BinaryReader(ms);

            int version = _in.ReadInt32();
            int count   = _in.ReadInt32();
            switch (version)
            {
            case 1:
                for (int i = 0; i < count; i++)
                {
                    npcPosition.Add(new Vector3(_in.ReadSingle(), _in.ReadSingle(), _in.ReadSingle()));
                }
                break;

            case 2:
                for (int i = 0; i < count; i++)
                {
                    npcPosition.Add(new Vector3(_in.ReadSingle(), _in.ReadSingle(), _in.ReadSingle()));
                }
                count = _in.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    CreatItemInfo addItem = new CreatItemInfo();
                    addItem.mPos      = new Vector3(_in.ReadSingle(), _in.ReadSingle(), _in.ReadSingle());
                    addItem.mRotation = Quaternion.Euler(new Vector3(_in.ReadSingle(), _in.ReadSingle(), _in.ReadSingle()));
                    addItem.mItemId   = _in.ReadInt32();
                    itemList.Add(addItem);
                }
                break;
            }
            _in.Close();
            ms.Close();
        }

        //npc stand
        if (!mNpcIdPosRotStand.Equals("") && mNpcIdPosRotStand.Length > 1)
        {
            string[] npcs = mNpcIdPosRotStand.Split('_');
            for (int i = 0; i < npcs.Count(); i++)
            {
                string[]    npcIdPosRotStr = npcs[i].Split('~');
                int         id             = Convert.ToInt32(npcIdPosRotStr[0]);
                string[]    posRot         = npcIdPosRotStr[1].Split(';');
                string[]    posStr         = posRot[0].Split(',');
                Vector3     pos            = new Vector3(float.Parse(posStr[0]), float.Parse(posStr[1]), float.Parse(posStr[2]));
                float       rot            = float.Parse(posRot[1]);
                BuildingNpc bdnpc          = new BuildingNpc(id, pos, rot, true);
                npcIdPosRot.Add(id, bdnpc);
            }
        }

        //npc move
        if (!mNpcIdPosRotMove.Equals("") && mNpcIdPosRotMove.Length > 1)
        {
            string[] npcs = mNpcIdPosRotMove.Split('_');
            for (int i = 0; i < npcs.Count(); i++)
            {
                string[]    npcIdPosRotStr = npcs[i].Split('~');
                int         id             = Convert.ToInt32(npcIdPosRotStr[0]);
                string[]    posRot         = npcIdPosRotStr[1].Split(';');
                string[]    posStr         = posRot[0].Split(',');
                Vector3     pos            = new Vector3(float.Parse(posStr[0]), float.Parse(posStr[1]), float.Parse(posStr[2]));
                float       rot            = float.Parse(posRot[1]);
                BuildingNpc bdnpc          = new BuildingNpc(id, pos, rot, false);
                npcIdPosRot.Add(id, bdnpc);
            }
        }
    }