/// <summary> /// The character has been attached to the camera. Update the UI reference and initialze the character-related values. /// </summary> /// <param name="character">The character that the UI is monitoring.</param> private void AttachCharacter(GameObject character) { if (m_Character == character) { return; } if (character == null) { // The object may be destroyed when Unity is ending. if (this != null) { EventHandler.UnregisterEvent <bool>(m_ItemWheelGameObject, "OnItemWheelToggleVisibility", ToggleVisiblity); m_GameObject.SetActive(false); m_Character = null; } return; } m_Character = character; SharedManager.InitializeSharedFields(m_Character, this); ToggleVisiblity(false); // Register for the events. Do not register within OnEnable because the character may not be known at that time. EventHandler.RegisterEvent <bool>(m_ItemWheelGameObject, "OnItemWheelToggleVisibility", ToggleVisiblity); }
/// <summary> /// The character has been attached to the camera. Update the UI reference and initialze the character-related values. /// </summary> /// <param name="character">The character that the UI is monitoring.</param> private void AttachCharacter(GameObject character) { if (m_Character == character) { return; } if (m_Character != null) { EventHandler.UnregisterEvent <bool>(m_Character, "OnItemShowScope", CanShowWheel); } m_Character = character; if (character == null) { // The object may be destroyed when Unity is ending. if (this != null) { enabled = false; } return; } EventHandler.RegisterEvent <bool>(m_Character, "OnItemShowScope", CanShowWheel); SharedManager.InitializeSharedFields(m_Character, this); m_Inventory = m_Character.GetComponent <Inventory>(); m_PlayerInput = m_Character.GetComponent <PlayerInput>(); enabled = true; }
/// <summary> /// The character has been attached to the camera. Update the UI reference and initialze the character-related values. /// </summary> /// <param name="character">The character that the UI is monitoring.</param> private void AttachCharacter(GameObject character) { if (m_Character != character && m_Character != null) { EventHandler.UnregisterEvent <Item>(m_Character, "OnInventoryPrimaryItemChange", PrimaryItemChange); EventHandler.UnregisterEvent <bool>(m_Character, "OnAllowGameplayInput", AllowGameplayInput); EventHandler.UnregisterEvent <float>(m_Character, "OnCameraUpdateRecoil", UpdateRecoil); EventHandler.UnregisterEvent <bool>(m_Character, "OnLaserSightUseableLaserSightActive", DisableCrosshairs); EventHandler.UnregisterEvent <bool>(m_Character, "OnItemShowScope", DisableCrosshairs); EventHandler.UnregisterEvent(m_Character, "OnDeath", OnDeath); if (m_OnlyVisibleOnAim) { EventHandler.UnregisterEvent <bool>(m_Character, "OnControllerAim", OnAim); } } if (m_Character == character) { return; } m_Character = character; if (m_Character == null || !m_GameObject.activeInHierarchy) { // The object may be destroyed when Unity is ending. if (this != null) { EnableCrosshairsImage(false); } return; } SharedManager.InitializeSharedFields(m_Character, this); m_Controller = m_Character.GetComponent <RigidbodyCharacterController>(); if (m_Camera == null) { m_Camera = Utility.FindCamera(m_Character); m_CameraMonitor = m_Camera.GetComponent <CameraMonitor>(); m_CameraMonitor.Crosshairs = transform; SharedManager.InitializeSharedFields(m_Camera.gameObject, this); } PrimaryItemChange(m_CurrentPrimaryItem.Get()); // Register for the events. Do not register within OnEnable because the character may not be known at that time. EventHandler.RegisterEvent <Item>(m_Character, "OnInventoryPrimaryItemChange", PrimaryItemChange); EventHandler.RegisterEvent <bool>(m_Character, "OnAllowGameplayInput", AllowGameplayInput); EventHandler.RegisterEvent <float>(m_Character, "OnCameraUpdateRecoil", UpdateRecoil); EventHandler.RegisterEvent <bool>(m_Character, "OnLaserSightUseableLaserSightActive", DisableCrosshairs); EventHandler.RegisterEvent <bool>(m_Character, "OnItemShowScope", DisableCrosshairs); EventHandler.RegisterEvent(m_Character, "OnDeath", OnDeath); if (m_OnlyVisibleOnAim) { EventHandler.RegisterEvent <bool>(m_Character, "OnControllerAim", OnAim); } EnableCrosshairsImage(!m_OnlyVisibleOnAim || m_Controller.Aiming); }
/// <summary> /// The character has been attached to the camera. Update the UI reference and initialze the character-related values. /// </summary> /// <param name="character">The character that the UI is monitoring.</param> private void AttachCharacter(GameObject character) { if (m_Character == character) { return; } if (m_Character != null) { if (m_MonitorHealth) { EventHandler.RegisterEvent <float>(m_Character, "OnHealthAmountChange", HealthAmountChange); } else { EventHandler.RegisterEvent <float>(m_Character, "OnHealthShieldAmountChange", HealthAmountChange); } } m_Character = character; if (character == null) { // The object may be destroyed when Unity is ending. if (this != null) { gameObject.SetActive(false); enabled = false; } return; } SharedManager.InitializeSharedFields(character, this); // Register for the events. Do not register within OnEnable because the character may not be known at that time. if (m_MonitorHealth) { EventHandler.RegisterEvent <float>(character, "OnHealthAmountChange", HealthAmountChange); HealthAmountChange(m_CurrentHealth.Get()); if (m_Slider != null) { m_Slider.maxValue = m_MaxHealth.Get(); } } else { EventHandler.RegisterEvent <float>(character, "OnHealthShieldAmountChange", HealthAmountChange); HealthAmountChange(m_CurrentShield.Get()); if (m_Slider != null) { m_Slider.maxValue = m_MaxShield.Get(); } } gameObject.SetActive(true); }
/// <summary> /// Initializes all of the SharedFields. /// </summary> protected override void Start() { base.Start(); #if !ENABLE_MULTIPLAYER if (!m_IndependentLook.Invoke()) { SharedManager.InitializeSharedFields(Utility.FindCamera(m_GameObject).gameObject, this); } #endif }
/// <summary> /// Initializes all of the SharedFields. /// </summary> protected virtual void Start() { SharedManager.InitializeSharedFields(m_GameObject, 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()) { SharedManager.InitializeSharedFields(Utility.FindCamera(m_GameObject).gameObject, this); } #endif }
/// <summary> /// The character has been attached to the camera. Update the UI reference and initialze the character-related values. /// </summary> /// <param name="character">The character that the UI is monitoring.</param> private void AttachCharacter(GameObject character) { if (m_Character == character) { return; } if (m_Character != null) { if (m_MonitorType != MonitorType.Secondary) { if (m_MonitorType == MonitorType.LeftHand || m_MonitorType == MonitorType.RightHand) { EventHandler.UnregisterEvent <Item>(m_Character, "OnInventoryPrimaryItemChange", PrimaryItemChange); EventHandler.UnregisterEvent <Item>(m_Character, "OnInventoryDualWieldItemChange", DualWieldItemChange); } else if (m_MonitorType == MonitorType.Primary || m_MonitorType == MonitorType.ItemExtension) { EventHandler.UnregisterEvent <Item>(m_Character, "OnInventoryPrimaryItemChange", PrimaryItemChange); } else { EventHandler.UnregisterEvent <Item>(m_Character, "OnInventoryDualWieldItemChange", DualWieldItemChange); } } else { EventHandler.UnregisterEvent(m_Character, "OnInventorySecondaryItemCountChange", SecondaryItemCountChange); } } m_Character = character; if (character == null) { // The object may be destroyed when Unity is ending. if (this != null) { gameObject.SetActive(false); } return; } SharedManager.InitializeSharedFields(m_Character, this); // Register for the events. Do not register within OnEnable because the character may not be known at that time. if (m_MonitorType != MonitorType.Secondary) { if (m_MonitorType == MonitorType.LeftHand || m_MonitorType == MonitorType.RightHand) { EventHandler.RegisterEvent <Item>(m_Character, "OnInventoryPrimaryItemChange", PrimaryItemChange); EventHandler.RegisterEvent <Item>(m_Character, "OnInventoryDualWieldItemChange", DualWieldItemChange); PrimaryItemChange(m_CurrentPrimaryItem.Get()); DualWieldItemChange(m_CurrentDualWieldItem.Get()); } else if (m_MonitorType == MonitorType.Primary || m_MonitorType == MonitorType.ItemExtension) { EventHandler.RegisterEvent <Item>(m_Character, "OnInventoryPrimaryItemChange", PrimaryItemChange); PrimaryItemChange(m_CurrentPrimaryItem.Get()); } else { EventHandler.RegisterEvent <Item>(m_Character, "OnInventoryDualWieldItemChange", DualWieldItemChange); DualWieldItemChange(m_CurrentDualWieldItem.Get()); } EventHandler.RegisterEvent <Item, bool, bool>(m_Character, "OnInventoryConsumableItemCountChange", ConsumableItemCountChange); } else { EventHandler.RegisterEvent(m_Character, "OnInventorySecondaryItemCountChange", SecondaryItemCountChange); // Initialize the secondary values. SecondaryItemCountChange(); } gameObject.SetActive(true); }
protected override void Start() { SharedManager.InitializeSharedFields(gameObject, this); }
protected override void Start() { base.Start(); SharedManager.InitializeSharedFields(this.gameObject, this); }