Пример #1
0
    public bool Load(int avatarAssetId, bool playDefaultAnim, bool useShadow)
    {
        this.avatarAssetId = avatarAssetId;

        // Save the avatar id.
        this.avatarTypeId = AvatarAssetConfig.ComponentIdToAvatarTypeId(avatarAssetId);

        // Check avatar id.
        if (ConfigDatabase.DefaultCfg.AvatarAssetConfig.GetAvatarById(avatarTypeId) == null)
        {
            Debug.LogError(System.String.Format("Invalid avatar id: {0:X}", avatarTypeId));
            return(false);
        }

        // Save old scale.
        Vector3 oldScale = gameObject.transform.localScale;

        gameObject.transform.localScale = new Vector3(1, 1, 1);

        // Create avatar object.
        if (avatarComponent.UseComponent(avatarAssetId, ""))
        {
            // Create avatar animation
            avatarAnimation.CreateAnimation();

            // Play the default animation.
            if (playDefaultAnim)
            {
                avatarAnimation.PlayDefaultAnim(avatarTypeId);
            }
        }

        // Create shadow.
        if (useShadow)
        {
            GameObject shadowGO = ResourceManager.Instance.InstantiateAsset <GameObject>(GameDefines.avtShadow);
            if (shadowGO != null)
            {
                shadow = shadowGO.transform;
                ObjectUtility.AttachToParentAndKeepLocalTrans(gameObject, shadow.gameObject);
                shadow.gameObject.name = "shadow";
            }
        }

        // Finished loading recover old scale
        gameObject.transform.localScale = oldScale;

        // Process delay used styles.
        avatarComponent.ReuseDelayStyles();

        return(true);
    }
Пример #2
0
    public bool UseComponent(int componentId, string mountBone)
    {
        // Check if the style is for the avatar
        if (AvatarAssetConfig.IsCommomComponent(componentId) == false && AvatarAssetConfig.ComponentIdToAvatarTypeId(componentId) != avatar.AvatarTypeId)
        {
#if ENABLE_AVATAR_COMPONENT_LOG
            Debug.LogWarning(System.String.Format("This usedComponent {0:X} is not for this avatar {1:X}", componentId, avatar.AvatarTypeId));
#endif
            return(false);
        }

        // Create used usedComponent.
        UsedComponent usdCmp = new UsedComponent(componentId, mountBone);

//		// If avatar object not created, delay use.
//		if (avatar.AvatarObject == null)
//		{
//			dlyUsedList.Add(usdCmp);
//			return true;
//		}

        // Process old usedComponent.
        int oldComponentIdx = FindComponentWithSamePartTypeId(usdCmp.componentId, mountBone);

        if (oldComponentIdx >= 0)
        {
            UsedComponent oldCmp = usedComponents[oldComponentIdx];

            // The same usedComponent and style, do nothing.
            if (oldCmp.componentId == usdCmp.componentId)
            {
                return(true);
            }

            // Need not add the usedCmp here, it will replace the oldComponent after download.
        }
        else
        {
            // Add this usedComponent.
            usedComponents.Add(usdCmp);
        }

        // Download usedComponent and style.
        OnUseComponentProcess(oldComponentIdx, usdCmp);

        return(true);
    }
Пример #3
0
    private GameObject CreateComponent(string assetName)
    {
        AvatarAssetConfig avatarAssetCfg = ConfigDatabase.DefaultCfg.AvatarAssetConfig;

        string path = PathUtility.Combine(avatarAssetCfg.assetPath, assetName);
        // Create new usedComponent.
        GameObject newComponent = ResourceManager.Instance.InstantiateAsset <GameObject>(PathUtility.Combine(avatarAssetCfg.assetPath, assetName));

        if (newComponent == null)
        {
#if ENABLE_AVATAR_COMPONENT_LOG
            Debug.LogWarning("Failed to create model: " + assetName);
#endif
            return(null);
        }

        newComponent.name = assetName;
        return(newComponent);
    }
Пример #4
0
    /// <summary>
    /// 非战斗中使用
    /// </summary>
    public void PlayAnimationByActionType(int actionType, int weaponType, int combatStateType)
    {
        int actionCount = ConfigDatabase.DefaultCfg.ActionConfig.GetActionCountInType(weaponType, combatStateType, actionType);

        if (actionCount == 0)
        {
            AvatarAnimation.PlayDefaultAnim(AvatarAssetConfig.ComponentIdToAvatarTypeId(AvatarAssetId));
            return;
        }

        AvatarAction animAction = ConfigDatabase.DefaultCfg.ActionConfig.GetActionInTypeByIndex(weaponType, combatStateType, actionType, 0);

        if (animAction.GetAnimationName(AvatarAssetId) == "")
        {
            Debug.LogError(string.Format("Animation name is empty in action({0})", animAction.id.ToString("X")));
            return;
        }

        PlayAnim(animAction.GetAnimationName(AvatarAssetId));
    }
Пример #5
0
 private int FindComponentWithSamePartTypeId(int componentId, string mountBone)
 {
     return(FindCmpByType(AvatarAssetConfig.ComponentIdToPartTypeId(componentId), mountBone));
 }