/// <summary> /// Cache the component references and initialize the default values. /// </summary> protected virtual void Awake() { m_GameObject = gameObject; m_Transform = transform; m_Animator = GetComponent <Animator>(); m_Controller = GetComponent <RigidbodyCharacterController>(); m_AnimatorMonitor = GetComponent <AnimatorMonitor>(); }
/// <summary> /// A new genre has been selected. Switch characters. /// </summary> private void SwitchCharacters() { GameObject character = null; switch (m_CurrentGenre) { case Genre.Shooter: character = m_ShooterCharacter; break; case Genre.Adventure: character = m_AdventureCharacter; break; case Genre.RPG: character = m_RPGCharacter; break; case Genre.Platformer: character = m_PlatformerCharacter; break; case Genre.Pseudo3D: character = m_Pseudo3DCharacter; break; case Genre.TopDown: character = m_TopDownCharacter; break; case Genre.PointClick: character = m_PointClickCharacter; break; } character.SetActive(true); // Toggle the scheduler enable state by disabling and enabling it. var scheduler = GameObject.FindObjectOfType <Scheduler>(); scheduler.enabled = false; scheduler.enabled = true; m_ImageFader.Fade(); // Cache the character components. m_Character = character; m_CharacterController = character.GetComponent <RigidbodyCharacterController>(); m_CharacterInventory = character.GetComponent <Inventory>(); m_CharacterAnimatorMonitor = character.GetComponent <AnimatorMonitor>(); m_CameraController.Character = character; m_CameraController.Anchor = character.transform; m_CameraController.DeathAnchor = character.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.Head); m_CameraController.FadeTransform = character.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.Chest); }
/// <summary> /// Initializes the item after it has been added to the Inventory. /// </summary> /// <param name="item">The item that this extension belongs to.</param> /// <param name="inventory">The parent character's inventory.</param> public virtual void Init(Item item, Inventory inventory) { m_ParentItem = item; m_Inventory = inventory; m_Character = inventory.gameObject; #if ENABLE_MULTIPLAYER m_NetworkMonitor = m_Character.GetComponent <NetworkMonitor>(); #endif m_AnimatorMonitor = inventory.GetComponent <AnimatorMonitor>(); m_Controller = inventory.GetComponent <RigidbodyCharacterController>(); SharedManager.InitializeSharedFields(m_Character, this); }
private void SetCharacter() { // Cache the character components. m_Character = PlayerCharacter; m_CharacterController = PlayerCharacter.GetComponent <RigidbodyCharacterController>(); m_CharacterInventory = PlayerCharacter.GetComponent <Inventory>(); m_CharacterAnimatorMonitor = PlayerCharacter.GetComponent <AnimatorMonitor>(); m_CameraController.Character = PlayerCharacter; m_CameraController.Anchor = PlayerCharacter.transform; m_CameraController.DeathAnchor = PlayerCharacter.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.Head); m_CameraController.FadeTransform = PlayerCharacter.GetComponent <Animator>().GetBoneTransform(HumanBodyBones.Chest); StartCoroutine(DelayedStart()); }
/// <summary> /// Initializes the item after it has been added to the Inventory. /// </summary> /// <param name="inventory">The parent character's inventory.</param> public virtual void Init(Inventory inventory) { m_Inventory = inventory; m_Character = inventory.gameObject; #if ENABLE_MULTIPLAYER m_NetworkMonitor = m_Character.GetComponent <NetworkMonitor>(); #endif m_AnimatorMonitor = inventory.GetComponent <AnimatorMonitor>(); m_Controller = inventory.GetComponent <RigidbodyCharacterController>(); // Initialize the animation states. m_DefaultStates.Initialize(m_ItemType); if (m_CanAim) { m_AimStates.Initialize(m_ItemType); } m_EquipStates.Initialize(m_ItemType); m_UnequipStates.Initialize(m_ItemType); EventHandler.RegisterEvent(gameObject, "OnInventoryItemEquipping", OnItemEquipping); EventHandler.RegisterEvent(gameObject, "OnInventoryItemUnequipping", OnItemUnequipping); EventHandler.RegisterEvent(gameObject, "OnInventoryItemEquipped", OnItemEquipped); EventHandler.RegisterEvent(gameObject, "OnInventoryItemUnequipped", OnItemUnequipped); for (int i = 0; i < m_ItemExtensions.Length; ++i) { m_ItemExtensions[i].Init(this, inventory); } for (int i = 0; i < m_Colliders.Length; ++i) { m_Colliders[i].enabled = false; } SharedManager.InitializeSharedFields(m_Character, this); // Independent look characters do not need to communicate with the camera. Do not initialze the SharedFields on the network to prevent non-local characters from // using the main camera to determine their look direction. The SharedFields have been implemented by the NetworkMonitor component. #if ENABLE_MULTIPLAYER if (!m_IndependentLook.Invoke() && m_IsLocalPlayer.Invoke()) { #else if (!m_IndependentLook.Invoke()) { #endif SharedManager.InitializeSharedFields(Utility.FindCamera(m_Character).gameObject, this); } }