/// <summary>
		/// Init this instance.
		/// </summary>
		virtual protected void Init()
		{
			// Get character reference
			myCharacter = (IMob) gameObject.GetComponent(typeof(IMob));
			if (myCharacter == null) myCharacter = (IMob) gameObject.GetComponentInParent(typeof(IMob));
			if (myCharacter == null) Debug.LogError ("Mecanim Animation Bridge (3D) unable to find Character or Enemy reference");

			if (myCharacter != null )
			{
				// Events
				myCharacter.ChangeAnimationState += AnimationStateChanged;
				if (myCharacter is Character) ((Character)myCharacter).Respawned += HandleRespawned;

				myAnimator = GetComponentInChildren<Animator>();
				if (myAnimator == null) Debug.LogError ("Platform Animator unable to find Unity Animator reference");
				defaultController = myAnimator.runtimeAnimatorController;

				// Get an aimer if one is present
				ProjectileAimer tmpAimer = ((Component)myCharacter).gameObject.GetComponent<ProjectileAimer> ();
				if (tmpAimer != null && myCharacter is Character && (tmpAimer.aimType == ProjectileAimingTypes.EIGHT_WAY || tmpAimer.aimType == ProjectileAimingTypes.SIX_WAY)) {
					aimer = tmpAimer;
				}

				// Set up animation overrides
				animationStateOverrideLookup = new Dictionary<string, AnimatorOverrideController> ();
				foreach (AnimatorControllerMapping mapping in mappings)
				{
					animationStateOverrideLookup.Add (mapping.overrrideState, mapping.controller);
				}
			}
#if UNITY_EDITOR
	#if UNITY_5
			// In editor mode build a list of handled states for error messaging and the like
			if (myAnimator.runtimeAnimatorController is UnityEditor.Animations.AnimatorController)
			{
				editor_stateNames = new List<string>();
				UnityEditor.Animations.AnimatorStateMachine stateMachine = ((UnityEditor.Animations.AnimatorController)defaultController).layers[0].stateMachine;
				for (int i = 0; i < stateMachine.states.Length; i++)
				{
					editor_stateNames.Add (stateMachine.states[i].state.name);
				}
				if (!editor_stateNames.Contains("IDLE")) Debug.LogWarning("Its recommended that you have a default state called 'IDLE' which can act as a hard reset state for actions like respawning");
			}
	#else
			
			// In editor mode build a list of handled states for error messaging and the like
			if (myAnimator.runtimeAnimatorController is UnityEditorInternal.AnimatorController)
			{
				editor_stateNames = new List<string>();
				UnityEditorInternal.StateMachine stateMachine = ((UnityEditorInternal.AnimatorController)defaultController).GetLayer(0).stateMachine;
				for (int i = 0; i < stateMachine.stateCount; i++)
				{
					editor_stateNames.Add (stateMachine.GetState(i).name);
				}
				if (!editor_stateNames.Contains("IDLE")) Debug.LogWarning("Its recommended that you have a default state called 'IDLE' which can act as a hard reset state for actions like respawning");
			}
	#endif
#endif
		}
 /// <summary>
 /// Initialise this movement and return a reference to the ready to use movement.
 /// </summary>
 public override EnemyMovement Init(Enemy enemy)
 {
     this.enemy = enemy;
     projectileAimer = GetComponent<ProjectileAimer>();
     return this;
 }
示例#3
0
 /// <summary>
 /// Init this instance.
 /// </summary>
 protected virtual void PostInit()
 {
     bool hasCoolDowns = false;
     for (int i = 0; i < attacks.Count; i++)
     {
         if (attacks[i].hitBox != null) attacks[i].hitBox.Init(new DamageInfo(attacks[i].damageAmount, attacks[i].damageType, Vector2.zero, character));
         if (attacks[i].attackType == AttackType.PROJECTILE && attacks[i].ammoType != null && attacks[i].ammoType != "")
         {
             itemManager = character.GetComponentInChildren<ItemManager>();
             if (itemManager == null) Debug.LogWarning("Attack requires ammo but item manager could not be found");
         }
         if (attacks[i].coolDown > 0) hasCoolDowns = true;
     }
     if (hasCoolDowns) cooldownTimers = new float[attacks.Count];
     projectileAimer = GetComponent<ProjectileAimer>();
     currentAttack = -1;
 }
        /// <summary>
        /// Initialise this animation bridge.
        /// </summary>
        protected void Init()
        {
            // Get character reference
            myMob = (IMob) gameObject.GetComponent(typeof(IMob));
            if (myMob == null) myMob = (IMob) gameObject.GetComponentInParent(typeof(IMob));
            if (myMob == null) Debug.LogError ("Mecanim Animation Bridge (2D) unable to find Character or Enemy reference");
            myMob.ChangeAnimationState += AnimationStateChanged;
            myAnimator = GetComponentInChildren<Animator>();
            if (myAnimator == null) Debug.LogError ("Platform Animator unable to find Unity Animator reference");
            defaultController = myAnimator.runtimeAnimatorController;

            if (myMob is Character && (statesWithAimUpModifer.Count > 0 || statesWithAimDownModifer.Count > 0))
            {
                myCharacter = (Character) myMob;
                aimer = myCharacter.GetComponentInChildren<ProjectileAimer>();
            }
            if ((statesWithAimUpModifer.Count > 0 || statesWithAimDownModifer.Count > 0) && aimer == null) Debug.LogWarning ("Can't use UP or DOWN modifiers as no aimer could be found");

            animationStateOverrideLookup = new Dictionary<string, AnimatorOverrideController> ();
            foreach (AnimatorControllerMapping mapping in mappings)
            {
                animationStateOverrideLookup.Add (mapping.overrrideState, mapping.controller);
            }

            queuedStates = new Queue<string> ();
            queuedPriorities = new Queue<int> ();
            state = AnimationState.NONE.AsString();
            priority = -1;

            TimeManager.Instance.GamePaused += HandleGamePaused;
            TimeManager.Instance.GameUnPaused += HandleGameUnPaused;

            #if UNITY_EDITOR
            #if UNITY_5
            // TODO also check for up and down states
            // In editor mode build a list of handled states for error messaging and the like
            if (myAnimator.runtimeAnimatorController is UnityEditor.Animations.AnimatorController)
            {
                editor_stateNames = new List<string>();
                UnityEditor.Animations.AnimatorStateMachine stateMachine = ((UnityEditor.Animations.AnimatorController)defaultController).layers[0].stateMachine;
                for (int i = 0; i < stateMachine.states.Length; i++)
                {
                    editor_stateNames.Add (stateMachine.states[i].state.name);
                }
            }

            #else
            // TODO also check for up and down states
            // In editor mode build a list of handled states for error messaging and the like
            if (myAnimator.runtimeAnimatorController is UnityEditorInternal.AnimatorController)
            {
                editor_stateNames = new List<string>();
                UnityEditorInternal.StateMachine stateMachine = ((UnityEditorInternal.AnimatorController)defaultController).GetLayer(0).stateMachine;
                for (int i = 0; i < stateMachine.stateCount; i++)
                {
                    editor_stateNames.Add (stateMachine.GetState(i).name);
                }

            }
            #endif
            #endif
        }