示例#1
0
    public static void DrawPrimitives(
        int nPrimitiveCount,    //## 绘制的图元的数目
        IntPtr pPrimitives,     //## 描述图元的结构的数组
        uint uGenre,            //## Primitive类型,取值来自枚举值REPRESENT_UNIT_TYPE
        int bSinglePlaneCoord   //## 图元绘制操作提供的坐标是否为垂直与视线的单平面坐标。如果不是,则图元绘制操作提供的坐标是三维空间坐标。
        )
    {
        //Debug.Log("DrawPrimitives: ");
        switch (uGenre)
        {
        case (int)REPRESENT_UNIT_TYPE.RU_T_IMAGE:
        case (int)REPRESENT_UNIT_TYPE.RU_T_IMAGE_PART:
        case (int)REPRESENT_UNIT_TYPE.RU_T_IMAGE_4:
        case (int)REPRESENT_UNIT_TYPE.RU_T_IMAGE_STRETCH:
        {
            IntPtr pSpr = pPrimitives;
            for (int n = 0; n < nPrimitiveCount; n++, IntPtrOffset(pSpr, IntPtr.Size))
            {
                long      uuid = (long)pSpr;
                pic_cmd_t cmds = (pic_cmd_t)Marshal.PtrToStructure(pSpr, typeof(pic_cmd_t));
                //Debug.Log("uuid: " + uuid + ", Type: " + uGenre);
                //Debug.Log(GLB.GBK.GetString(cmds.filename));
                cmds.pos1.x /= 100;
                cmds.pos1.y /= 100;
                cmds.pos1.y  = 8.0f - cmds.pos1.y;
                cmds.pos1.z /= 100;
                cmds.pos1.z += zbuff;
                zbuff       -= 0.1f;
                //Debug.Log(string.Format("Image: {0},{4} at [{1},{2},{3}]", "", cmds.pos1.x, cmds.pos1.y, cmds.pos1.z, cmds.frame_index));
                if (cmds.filename[0] == 0)
                {
                    break;
                }
                SprMgr.DrawSpr(uuid, cmds);
            }
        }
        break;

        case (int)REPRESENT_UNIT_TYPE.RU_T_MODEL:
        {
            long uuid = (long)pPrimitives;
            space_obj_primitive_cmd_t cmds = (space_obj_primitive_cmd_t)Marshal.PtrToStructure(pPrimitives, typeof(space_obj_primitive_cmd_t));
            cmds.pos.x /= 100;
            cmds.pos.y /= 100;
            cmds.pos.y  = 8.0f - cmds.pos.y;
            cmds.pos.z += zbuff;
            zbuff      += 0.1f;
            //SprMgr.DrawModel(uuid, cmds);
        }
        break;
        }
    }
示例#2
0
文件: SprMgr.cs 项目: windlex/Jx2U
    public static bool DrawSpr(long cmd_addr, pic_cmd_t cmds)
    {
        SprMgr     self    = SprMgr.GetInstance();
        GameObject go      = self.GetSpr(cmd_addr);
        Vector3    pos     = new Vector3(cmds.pos1.x, cmds.pos1.y, cmds.pos1.z);
        bool       bReload = false;
        string     szImage = Encoding.UTF8.GetString(Encoding.Convert(GLB.GBK, Encoding.UTF8, cmds.filename));
        KSSprite   ksp;

        if (!go)
        {
            go  = new GameObject(szImage);
            ksp = go.AddComponent <KSSprite>();
            self.SprMap.Add(cmd_addr, ksp);
            //pos += new Vector3(tx.width/200, -tx.height/200, 0f);
            bReload = true;
        }
        else
        {
            ksp = go.GetComponent <KSSprite>();
            if (ksp.GetFrame() != cmds.frame_index)
            {
                bReload = true;
            }
        }
        if (bReload)
        {
            Texture2D tx = self.LoadSpr(szImage, cmds.frame_index);
            if (!tx)
            {
                Debug.LogError("Load Spr Error: " + szImage);
                return(false);
            }
            Sprite sp = Sprite.Create(tx, new Rect(0f, 0f, tx.width, tx.height), new Vector2(0.0f, 1.0f), 100.0f, 0, SpriteMeshType.FullRect);
            ksp.SetSprite(sp, cmds.frame_index);
        }

        go.transform.parent        = self.front.transform;
        go.transform.localPosition = pos;
        return(true);
    }