/// <summary>
    ///  展示NPC
    /// </summary>
    public static GameObject ShowNpc(GameObject objNpcContainer, GameObject objNpcModel, CharacterBean characterData)
    {
        CptUtil.RemoveChildsByActiveInEditor(objNpcContainer);
        GameObject objNpc = GameObject.Instantiate(objNpcModel, objNpcContainer.transform);

        objNpc.SetActive(true);
        objNpc.transform.position = new Vector3(characterData.npcInfoData.position_x, characterData.npcInfoData.position_y);

        BaseNpcAI baseNpcAI = objNpc.GetComponent <BaseNpcAI>();

        baseNpcAI.Awake();

        CharacterDressCpt characterDress = CptUtil.GetCptInChildrenByName <CharacterDressCpt>(baseNpcAI.gameObject, "Body");

        characterDress.Awake();

        baseNpcAI.SetCharacterData(characterData);
        return(objNpc);
    }
Exemple #2
0
    public GameObject CreateNpc(long createNpcId, Vector3 position, int number)
    {
        CharacterBean characterData = null;
        GameObject    objNpc        = null;

        if (createNpcId == 0)
        {
            characterData = new CharacterBean();
        }
        else
        {
            characterData = new CharacterBean(mapNpcInfo[createNpcId]);
        }

        if (characterData == null)
        {
            LogUtil.LogError("没有找到id为" + createNpcId + "的NPC");
            return(null);
        }

        objNpc = Instantiate(StoryInfoHandler.Instance.manager.objNpcModel, StoryInfoHandler.Instance.builderForStory.transform);
        BaseNpcAI baseNpcAI = objNpc.GetComponent <BaseNpcAI>();

        baseNpcAI.Awake();

        CharacterDressCpt characterDress = CptUtil.GetCptInChildrenByName <CharacterDressCpt>(baseNpcAI.gameObject, "Body");

        characterDress.Awake();

        baseNpcAI.transform.localPosition = position;
        baseNpcAI.SetCharacterData(characterData);
        baseNpcAI.name = "character_" + number;
        objNpc.SetActive(true);

        return(objNpc);
    }