コード例 #1
0
    void Preview()
    {
        Debug.Log(Application.isPlaying + "    " + EditorApplication.isPlaying);
        if (!EditorApplication.isPlaying)
        {
            Debug.LogError("请先运行游戏!");
            return;
        }

        GameObject rootGo = GameObject.Find("root");

        if (!rootGo)
        {
            Debug.LogError("缺少骨架!!把骨架信息拖到Hierarchy中");
            return;
        }

        //添加管理器
        RoleGenerateManager manager = rootGo.GetComponent <RoleGenerateManager>();

        if (!manager)
        {
            rootGo.AddComponent <RoleGenerateManager>();
        }

        //添加生成组件
        RoleGenerator generator = rootGo.GetComponent <RoleGenerator>();

        if (generator)
        {
            DestroyImmediate(generator);
        }
        generator = rootGo.AddComponent <RoleGenerator>();

        //----------解析各个部件的ID
        int headID           = ParserID(partDic["头部"][0]); //头部ID
        int hairDecorationID = ParserID(partDic["头部"][1]); //发饰
        int faceID           = ParserID(partDic["表情"][0]); //表情
        int clothID          = ParserID(partDic["上衣"][0]); //上衣
        int weaponID         = ParserID(partDic["上衣"][1]); //武器
        int bagID            = ParserID(partDic["背饰"][0]); //背饰
        int pantsID          = ParserID(partDic["下衣"][0]); //下衣
        int stockingsID      = ParserID(partDic["下衣"][1]); //丝袜
        int shoesID          = ParserID(partDic["下衣"][2]); //鞋子
        int tailID           = ParserID(partDic["尾巴"][0]); //尾巴

        generator.InitPartResID(headID, hairDecorationID, faceID, 0, clothID, weaponID, bagID, pantsID, stockingsID, shoesID, tailID);

        generator.SetAnimation("IDLE");
    }