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; } } }
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; } }
// 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; }
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(); } }); }
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; }
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); }
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(); } }
// 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 }
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); }
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); } }
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"); }
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); }
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); }
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); } } }); }
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); } } }
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); }
/// <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; } }
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); }
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); }
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)); }
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); }
/// <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; } }
/// <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); }
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); }
/// <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; }
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; }
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; }
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); }
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 = ""; }