コード例 #1
0
        void Awake()
        {
            Animator = GetComponent <Animator>();
            aoc      = new AnimatorOverrideController(BaseController);
            Animator.runtimeAnimatorController = aoc;

            if (Data != null)
            {
                aoc["Idle"] = Data.SideIdleAnimation;
                if (Data.HasRandomAnimation)
                {
                    aoc["Random"] = Data.RandomAnimation;
                }
            }
        }
コード例 #2
0
 private void SwapAnimationClip(AnimationClip anim)
 {
     if (anim)
     {
         AnimatorOverrideController aoc = new AnimatorOverrideController(animator.runtimeAnimatorController);
         var anims = new List <KeyValuePair <AnimationClip, AnimationClip> >();
         foreach (var a in aoc.animationClips)
         {
             anims.Add(new KeyValuePair <AnimationClip, AnimationClip>(a, anim));
         }
         aoc.ApplyOverrides(anims);
         animator.runtimeAnimatorController = aoc;
         _animationClip = anim;
     }
 }
コード例 #3
0
    // Start is called before the first frame update
    protected virtual void Start()
    {
        agent    = GetComponent <NavMeshAgent>();
        animator = GetComponentInChildren <Animator>();
        combat   = GetComponent <CharacterCombat>();

        if (overrideController == null)
        {
            overrideController = new AnimatorOverrideController(animator.runtimeAnimatorController);
        }
        animator.runtimeAnimatorController = overrideController;

        currentAttackAnimSet = defaultAttackAnimSet;
        combat.OnAttack     += OnAttack;
    }
コード例 #4
0
 public void Init(Animator animator, string path)
 {
     _animator             = animator;
     _runtimeAnimatorProxy = ResourceMgr.Instance.LoadAssetProxy(AssetType.AnimeCtrl, path);
     _runtimeAnimatorProxy.AddLoadFinishCallBack(() =>
     {
         RuntimeAnimatorController ctrl = _runtimeAnimatorProxy.LoadUnitySharedAsset <RuntimeAnimatorController>();
         if (ctrl)
         {
             _animator.runtimeAnimatorController = ctrl;
             _animatorOverrideController         = ctrl as AnimatorOverrideController;
             _animator.Rebind();
         }
     });
 }
コード例 #5
0
    void Awake()
    {
        transform.LookAt();
        _animator               = GetComponent <Animator>();
        _overrideController     = new AnimatorOverrideController();
        _animationClipOverrides = new AnimationClipOverrides();

        _overrideController.runtimeAnimatorController = _animator.runtimeAnimatorController;
        _animator.runtimeAnimatorController           = _overrideController;
        _overrideController.GetOverrides(_animationClipOverrides);
        _animationClipOverrides["Idle"] = _idleClip;
        _animationClipOverrides["Run"]  = _moveClip;
        _overrideController.ApplyOverrides(_animationClipOverrides);
        _actionState = ActionState.Idle;
    }
コード例 #6
0
        void Awake()
        {
            overrideController = new AnimatorOverrideController();
            overrideController.runtimeAnimatorController = controller;

            var animator = gameObject.GetComponent <Animator> ();

            if (animator == null)
            {
                animator = gameObject.AddComponent <Animator> ();
            }
            animator.runtimeAnimatorController = overrideController;

            ChangeAnimation(0);
        }
コード例 #7
0
    static void DoCreateAnimationAssets()
    {
        //创建animationController文件,保存在Assets路径下
        string strRoleID                = "102005";
        string strRolePartName          = "102005";
        string strRoleTemplateContrller = "Assets/Resources/AnimaCtrl/Roles/[email protected]";

        {
            AnimatorOverrideController overrideController = new AnimatorOverrideController();
            overrideController.runtimeAnimatorController = AssetDatabase.LoadAssetAtPath(strRoleTemplateContrller, typeof(UnityEditor.Animations.AnimatorController)) as UnityEditor.Animations.AnimatorController;
            NewRoleOverFromRoleControler(strRoleID, strRolePartName, ref overrideController);
            AssetDatabase.CreateAsset(overrideController, "Assets/Resources/AnimaCtrl/Roles/[email protected]");
            AssetDatabase.SaveAssets();
        }
    }
コード例 #8
0
    // Start is called before the first frame update
    protected virtual void Start()
    {
        agent    = GetComponent <NavMeshAgent>();
        animator = GetComponentInChildren <Animator>();
        combat   = GetComponent <CharacterCombat>();

        if (overrideController == null)
        {
            overrideController = new AnimatorOverrideController(animator.runtimeAnimatorController);
        }
        animator.runtimeAnimatorController = overrideController;          //swap out different combat animations depending on weapon used

        currentAttackAnimSet = defaultAttackAnimSet;
        combat.OnAttack     += OnAttack;     // subscribe to the OnAttack action in the CharacterCombat script
    }
コード例 #9
0
        public static List <AnimationClip> GetUnusedAnimations(this AnimatorOverrideController controller)
        {
            List <AnimationClip> clips = new List <AnimationClip>();
            var includeClips           = LoadChildAssets <AnimationClip>(controller);

            foreach (AnimationClip includeClip in includeClips)
            {
                if (!controller.animationClips.Contains(includeClip))
                {
                    clips.Add(includeClip);
                }
            }

            return(clips);
        }
コード例 #10
0
 public void OnStopMoving()
 {
     OnMoveStateChange(false);
     //on stop, do all actions
     if (newAnimator != null)
     {
         cachedAnimator.runtimeAnimatorController = newAnimator;
         newAnimator = null;
     }
     if (queuedAct)
     {
         queuedAct = false;
         cachedAnimator.SetBool(IS_ACTING, true);
     }
 }
コード例 #11
0
    public void PlayAnimation(string animationName, BulletType type)
    {
        AnimatorOverrideController animationController = new AnimatorOverrideController();

        animationController.runtimeAnimatorController = Resources.Load <RuntimeAnimatorController>("sprites/BulletDeathAnimationController");
        string resourcePath = string.Concat("sprites/weaponDeaths/", animationName);

        foreach (AnimationClip clip in Resources.LoadAll <AnimationClip>(resourcePath))
        {
            animationController[clip.name] = clip;
        }
        anim.runtimeAnimatorController = animationController;
        anim.SetInteger("type", (int)type);
        anim.SetTrigger("play");
    }
コード例 #12
0
    public static float GetClipLengthByOverrideController(this Animator animator, string key)
    {
        if (null == animator || string.IsNullOrEmpty(key) || null == animator.runtimeAnimatorController)
        {
            return(0);
        }
        AnimatorOverrideController ac = animator.runtimeAnimatorController as AnimatorOverrideController;
        AnimationClip tAnimationClip  = ac[key];

        if (null != tAnimationClip)
        {
            return(tAnimationClip.length);
        }
        return(0F);
    }
コード例 #13
0
    public AnimatorOverrideController GetAnimationControllerByName(EquipmentAnimationControllerName name)
    {
        AnimatorOverrideController con = null;

//		con.clips[0].overrideClip.SampleAnimation
        foreach (NamedAnimationController mapping in animationStore)
        {
            if (mapping.name == name)
            {
                con = mapping.controller;
                break;
            }
        }
        return(con);
    }
コード例 #14
0
        public void Initialize()
        {
            if (null == Entity)
            {
                return;
            }
            Animator = Entity.Animator;
            _runtimeAnimatorProxy = ResourceMgr.singleton.LoadAssetAsync(AssetPath);
            _runtimeAnimatorProxy.AddLoadFinishCallBack(() =>
            {
                var ctrl = _runtimeAnimatorProxy.GetUnityAsset <RuntimeAnimatorController>();
                if (ctrl)
                {
                    AnimatorOverrideController         = new AnimatorOverrideController(ctrl);
                    Animator.runtimeAnimatorController = AnimatorOverrideController;
                    Animator.Rebind();
                    Enable = true;
                    TransToDefault();

                    //TODO
                    foreach (var state in StateList)
                    {
                        var str = string.Empty;
                        if (state.StateName == StateNameEnum.Idle.ToString())
                        {
                            str = "Assets/Bundles/Animation/Skeleton/Idle.anim";
                        }
                        if (state.StateName == StateNameEnum.Move.ToString())
                        {
                            str = "Assets/Bundles/Animation/Skeleton/Run.anim";
                        }
                        if (state.StateName == StateNameEnum.Skill.ToString())
                        {
                            str = "Assets/Bundles/Animation/Skeleton/Attack.anim";
                        }
                        if (state.StateName == StateNameEnum.Special.ToString())
                        {
                            str = "Assets/Bundles/Animation/Skeleton/Damage.anim";
                        }
                        if (state.StateName == StateNameEnum.Dead.ToString())
                        {
                            str = "Assets/Bundles/Animation/Skeleton/Death.anim";
                        }
                        state.Initialize(str);
                    }
                }
            });
        }
コード例 #15
0
    public void Init()
    {
        ////Util.LogColor("red", "MecanimControl Start");

        animator             = gameObject.GetComponent <Animator>();
        animator.cullingMode = AnimatorCullingMode.AlwaysAnimate;
        controller1          = (RuntimeAnimatorController)Resources.Load("controller1");

        animator.runtimeAnimatorController = GetController();
        cachedController = GetController();


        foreach (var pair in animations)
        {
            AnimationData animData = pair.Value;
            if (animData.wrapMode == WrapMode.Default)
            {
                animData.wrapMode = defaultWrapMode;
            }
            animData.clip.wrapMode = animData.wrapMode;
        }

        if (defaultAnimationData.clip == null && animations.Count > 0)
        {
            var e = animations.GetEnumerator();
            if (e.MoveNext())
            {
                var animData = e.Current.Value;
                SetDefaultClip(animData.clip, "Default", animData.speed, animData.wrapMode);
            }
        }

        if (defaultAnimationData.clip != null)
        {
            SetOverrideController(defaultAnimationData, defaultAnimationData, currentMirror);
            currentAnimationData = defaultAnimationData;

            if (playOnStart)
            {
                AnimatorPlay("State2", 0, 0);
                if (overrideRootMotion)
                {
                    animator.applyRootMotion = currentAnimationData.applyRootMotion;
                }
                SetSpeed(currentAnimationData.speed);
            }
        }
    }
コード例 #16
0
        public override bool Init()
        {
            //short circuit if this has clearly been initialized before
            if ((animator && animator.isInitialized && overrideController && animation &&
                 (!assignEndState || (assignEndState && state))))
            {
                assignAnimations();
                animator.runtimeAnimatorController = overrideController;
                actor.SetActive(true);
                return(true);
            }

            if (!findAnimations())
            {
                return(false);
            }
            animation.wrapMode = loop ? WrapMode.Loop : WrapMode.Once;
            //get the actor this animate action is supposed to affect
            if (actor == null &&
                !getActorByName(actorName, out actor))
            {
                Debug.LogError("actor[" + actorName + "] not found.  cannot animate");
                return(false);
            }

            //get the actor's current animator if it exists
            animator = actor.GetComponent <Animator>();
            if (animator == null)
            {
                animator = actor.AddComponent <Animator>();
            }

            //find or make an override controller
            if (animator.runtimeAnimatorController is AnimatorOverrideController)
            {
                overrideController = (AnimatorOverrideController)animator.runtimeAnimatorController;
            }
            else
            {
                overrideController = new AnimatorOverrideController();
                overrideController.runtimeAnimatorController = Resources.Load <RuntimeAnimatorController>("AnimatorControllers/Generic");
                animator.runtimeAnimatorController           = overrideController;
            }

            assignAnimations();
            animator.applyRootMotion = false;
            return(true);
        }
コード例 #17
0
    /// <summary>
    /// 设置动画
    /// </summary>
    /// <param name="itemsInfo"></param>
    public void SetAnimForEquip(Animator animator, AnimatorOverrideController animatorForTarget, ItemsInfoBean itemsInfo)
    {
        if (animatorForTarget == null || itemsInfo == null || itemsInfo.id == 0)
        {
            animatorForTarget["Original"] = animForOriginalClip;
            animator.enabled = false;
            return;
        }
        //设置动画
        if (!CheckUtil.StringIsNull(itemsInfo.anim_key))
        {
            GeneralEnum   itemType      = itemsInfo.GetItemsType();
            AnimationClip animationClip = null;
            switch (itemType)
            {
            case GeneralEnum.Mask:
            case GeneralEnum.Hat:
            case GeneralEnum.Clothes:
            case GeneralEnum.Shoes:
                animationClip = CharacterDressHandler.Instance.manager.GetAnimByName(itemType, itemsInfo.anim_key);
                break;

            case GeneralEnum.Chef:
            case GeneralEnum.Waiter:
            case GeneralEnum.Accoutant:
            case GeneralEnum.Accost:
            case GeneralEnum.Beater:
                animationClip = GameItemsHandler.Instance.manager.GetItemsAnimClipByName(itemsInfo.anim_key);
                break;
            }

            if (animationClip != null)
            {
                animator.enabled = true;
                animatorForTarget["Original"] = animationClip;
            }
            else
            {
                animatorForTarget["Original"] = animForOriginalClip;
                animator.enabled = false;
            }
        }
        else
        {
            animatorForTarget["Original"] = animForOriginalClip;
            animator.enabled = false;
        }
    }
コード例 #18
0
ファイル: UnitAnimMgr.cs プロジェクト: flzzyf/HOMMS
    public static bool hasAnimation(Unit _unit, Anim _anim)
    {
        AnimatorOverrideController ac = _unit.animator.runtimeAnimatorController as AnimatorOverrideController;

#pragma warning disable 0618
        for (int i = 0; i < ac.clips.Length; i++)
        {
            if (ac.clips[i].originalClip.name == _anim.ToString() &&
                ac.clips[i].overrideClip != null)
            {
                return(true);
            }
        }
#pragma warning restore 0618
        return(false);
    }
コード例 #19
0
	public void EmitFollowingEffect(string effectName, int lasting, MapObject owner){
		GameObject effect;
		if (_componentPool.Count > 0)
			effect = _componentPool.Pop ();
		else
			effect = GameObject.Instantiate (effectBasePrefab,effectLayer);

		AnimatorOverrideController animator = getEffect (effectName);
		BaseEffect be = effect.GetComponent<BaseEffect> ();
		effect.GetComponentInChildren<SpriteRenderer> ().sprite = null;


		effect.GetComponentInChildren<Animator>().runtimeAnimatorController = animator;

		be.init ((int)(animator["effect_default"].length*1000),owner);
	}
コード例 #20
0
        private void OnEnable()
        {
            AnimatorOverrideController animatorOverrideController = this.target as AnimatorOverrideController;

            this.m_Controller = base.serializedObject.FindProperty("m_Controller");
            if (this.m_ClipList == null)
            {
                this.m_ClipList = new ReorderableList(animatorOverrideController.clips, typeof(AnimationClipPair), false, true, false, false);
                this.m_ClipList.drawElementCallback = new ReorderableList.ElementCallbackDelegate(this.DrawClipElement);
                this.m_ClipList.drawHeaderCallback  = new ReorderableList.HeaderCallbackDelegate(this.DrawClipHeader);
                this.m_ClipList.elementHeight       = 16f;
            }
            AnimatorOverrideController expr_8B = animatorOverrideController;

            expr_8B.OnOverrideControllerDirty = (AnimatorOverrideController.OnOverrideControllerDirtyCallback)Delegate.Combine(expr_8B.OnOverrideControllerDirty, new AnimatorOverrideController.OnOverrideControllerDirtyCallback(base.Repaint));
        }
コード例 #21
0
        public AnimatorOverrideController GetExistingAnimatorOverrideController(string assetPath)
        {
            string name = Path.GetFileNameWithoutExtension(assetPath);

            ///NOTE - DDobyns experiment to fix animation naming issues
            // Ignore characters in master name after _ character
            string newName = name.Split('_')[0];

            string basePath        = GetBasePath(assetPath);
            string targetDirectory = sharedData.animationControllersTargetLocation.GetTargetDirectory(basePath);

            string pathForController = targetDirectory + "/" + newName + ".overrideController";
            AnimatorOverrideController controller = AssetDatabase.LoadAssetAtPath <AnimatorOverrideController>(pathForController);

            return(controller);
        }
コード例 #22
0
        /// <summary>
        /// Replace a clip with another one
        /// </summary>
        /// <param name="animator">Animator its being replaced on</param>
        /// <param name="clipName">Clip name</param>
        /// <param name="overrideClip">New clip</param>
        private void ReplaceClip(Animator animator, string clipName, AnimationClip overrideClip)
        {
            AnimatorOverrideController overrideController = animator.runtimeAnimatorController as AnimatorOverrideController;

            if (overrideController == null)
            {
                overrideController      = new AnimatorOverrideController();
                overrideController.name = "PegasusRuntimeController";
                overrideController.runtimeAnimatorController = animator.runtimeAnimatorController;
            }
            overrideController[clipName] = overrideClip;
            if (ReferenceEquals(animator.runtimeAnimatorController, overrideController) == false)
            {
                animator.runtimeAnimatorController = overrideController;
            }
        }
コード例 #23
0
    /// <summary>
    /// This method initializes all basic attribute and basic animations at the start up
    /// in BasicAnimation.
    /// </summary>
    protected override void InitializeStartUp()
    {
        base.InitializeStartUp();

        // Setting up the override controller
        _overrideController =
            new AnimatorOverrideController(CharacterAnimator.runtimeAnimatorController);
        CharacterAnimator.runtimeAnimatorController = _overrideController;

        // Setting the attack animations to default at start
        // NOTE: This may change in future and will depend on the weapon equipped
        _currentAnimationAttacks = DefaultAnimationAttacks;

        // Making the combat stance false at the start
        CharacterAnimator.SetBool(AnimationIsAttackIdle, false);
    }
コード例 #24
0
 public override void OnInitial(NativeEntity enty)
 {
     base.OnInitial(enty);
     m_Animator = entity.EntityObject.GetComponent <Animator>();
     if (m_Animator.runtimeAnimatorController is AnimatorOverrideController)
     {
         m_overrideController = m_Animator.runtimeAnimatorController as AnimatorOverrideController;
     }
     else
     {
         m_overrideController = new AnimatorOverrideController();
         m_overrideController.runtimeAnimatorController = m_Animator.runtimeAnimatorController;
         m_Animator.runtimeAnimatorController           = m_overrideController;
     }
     m_Animator.Rebind();
 }
        private static List <AnimationClip> GetUnusedAnimations(AnimatorOverrideController controller)
        {
            List <AnimationClip> unusedClips = new List <AnimationClip> ();

            List <AnimationClip> includeClips = AnimatorOverrideControllerInspector.GetIncludeAnimations(controller);

            foreach (AnimationClip includeClip in includeClips)
            {
                if (!new List <AnimationClip> (controller.animationClips).Contains(includeClip))
                {
                    unusedClips.Add(includeClip);
                }
            }

            return(unusedClips);
        }
コード例 #26
0
        /// <summary>
        /// Sets all monster attack clips in monster animator controller.
        /// </summary>
        /// <remark>
        /// In Unity, the only way to load in different animations is to create an AnimatorOverrideController,
        /// set the animations of the AOC, and then set it to be the runtimeAnimatorController of the given animator.
        /// Overriding a clip in unity overrides all instances of a clip in an animator controller's
        /// state machine. Make sure to use individual placeholders for each clip you want overridden.
        /// </remark>
        public void SetMonsterAnimatorClips()
        {
            AnimatorOverrideController aoc = new AnimatorOverrideController(monsterAnimator.runtimeAnimatorController);
            List <KeyValuePair <AnimationClip, AnimationClip> > anims = new List <KeyValuePair <AnimationClip, AnimationClip> >(); // first clip is old clip to override, second is new clip

            for (int i = 0; i < displayedMonster.attackNum; i++)
            {
                AnimationClip oldClip           = aoc.animationClips[i];
                string        animationClipPath = "AnimationsAndControllers/Animations/" + displayedMonster.attacks[i].animationClipName;
                AnimationClip newClip           = Resources.Load <AnimationClip>(animationClipPath);
                anims.Add(new KeyValuePair <AnimationClip, AnimationClip> (oldClip, newClip));
            }

            aoc.ApplyOverrides(anims);
            monsterAnimator.runtimeAnimatorController = aoc;
        }
コード例 #27
0
    public void ChangeBottom(int pIndex)
    {
        pIndex += 1;

        AnimatorOverrideController aoc = new AnimatorOverrideController(BottomAnim.runtimeAnimatorController);

        AnimationClip[] clips = BottomAnim.runtimeAnimatorController.animationClips;

        foreach (AnimationClip clip in clips)
        {
            string        path    = "Character Art/Bottoms/Bottom" + pIndex + "/" + clip.name;
            AnimationClip newClip = Resources.Load(path) as AnimationClip;
            aoc[clip.name] = newClip;
        }
        BottomAnim.runtimeAnimatorController = aoc;
    }
コード例 #28
0
    public void Init(AnimationType type, float speedRate, float playTime)
    {
        var animators = GetComponentsInChildren <Animator>();

        if (animators.Length > 0)
        {
            animator = animators[0];

            overrideController = new AnimatorOverrideController();
            overrideController.runtimeAnimatorController = animator.runtimeAnimatorController;
            animator.runtimeAnimatorController           = overrideController;
        }

        ChangeClip(type, playTime);
        animator.speed = GetAnimationClip(type).Speed *speedRate;
    }
コード例 #29
0
        public static List <AnimationClip> GetUnusedAnimations(this AnimatorOverrideController controller)
        {
            List <AnimationClip> clips = new List <AnimationClip>();

            List <AnimationClip> includeClips = controller.LoadAllAsset <AnimationClip>();

            foreach (AnimationClip includeClip in includeClips)
            {
                if (!new List <AnimationClip>(controller.animationClips).Contains(includeClip))
                {
                    clips.Add(includeClip);
                }
            }

            return(clips);
        }
コード例 #30
0
 public void Reset()
 {
     if (m_Animator != null)
     {
         m_Animator.cullingMode = AnimatorCullingMode.CullUpdateTransforms;
         m_Animator.enabled     = false;
         m_Animator             = null;
     }
     ResetClips();
     m_overrideController = null;
     m_stateName          = "";
     m_value          = -1;
     m_playLayer      = -1;
     m_normalizedTime = float.NegativeInfinity;
     m_triggerName    = "";
 }