Exemple #1
0
        /// <summary>
        /// Initializes all of the SharedFields and default values.
        /// </summary>
        private void Start()
        {
            SharedManager.InitializeSharedFields(m_GameObject, this);

            if ((enabled = m_PlayerInput != null))
            {
                m_PrevMousePosition = Vector3.one * float.MaxValue;
#if ENABLE_MULTIPLAYER
                if (isLocalPlayer)
                {
#endif
                m_Camera          = Utility.FindCamera(m_GameObject);
                m_CameraTransform = m_Camera.transform;
#if ENABLE_MULTIPLAYER
            }
#endif
                // Call update immediately to force the horizontal, forward, and look rotation values to update before FixedUpdate is called.
                Update();
            }

            SharedManager.InitializeSharedFields(m_GameObject, this);

#if !UNITY_5_1 && !UNITY_5_2 && !UNITY_5_3
            SceneManager.sceneLoaded += OnSceneLoaded;
#endif
        }
Exemple #2
0
        /// <summary>
        /// Try to throw the object. An object may not be able to be thrown if another object was thrown too recently, or if there are no more thrown objects remaining (out of ammo).
        /// <returns>True if the item was used.</returns>
        /// </summary>
        public bool TryUse()
        {
            // Throwable Items aren't always visible (such a Secondary item) so Start() isn't always called. Initialize the SharedFields when the item is trying to be used.
            if (!m_Initialized)
            {
                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);
                }
                m_Initialized = true;
            }
            if (m_LastThrowTime + m_ThrowDelay < Time.time && m_Inventory.GetItemCount(m_ItemType) > 0)
            {
                // Returns true to tell the ItemHandler that the item was used. The Used callback will be registered and the object will actually be thrown within that method.
                m_Throwing = true;
                EventHandler.ExecuteEvent(m_Character, "OnItemUse");
                return(true);
            }
            return(false);
        }
Exemple #3
0
        /// <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 override void Init(Item item, Inventory inventory)
        {
            base.Init(item, inventory);

            // When the projectile is instantiated it should ignore all of the character's colliders.
            if (m_Projectile != null)
            {
                m_CharacterColliders = m_Character.GetComponentsInChildren <Collider>(true);
            }

            // Register for character events within Init to allow the weapon to recieve the callback even when the weapon isn't active. This allows
            // the character to pickup ammo for a weapon before picking up the weapon and having the ammo already loaded.
            EventHandler.RegisterEvent <Item, bool, bool>(m_Character, "OnInventoryConsumableItemCountChange", ConsumableItemCountChange);
            EventHandler.RegisterEvent <Item>(m_Character, "OnInventoryPrimaryItemChange", PrimaryItemChange);

            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);
            }
        }
Exemple #4
0
        /// <summary>
        /// Play the default states after the inventory has been initialized.
        /// </summary>
        private void Initialize()
        {
            // Do not listen for item events until the inventory initialization is complete.
            EventHandler.RegisterEvent(m_GameObject, "OnUpdateAnimator", DetermineStates);
            EventHandler.RegisterEvent(m_GameObject, "OnItemUse", DetermineStates);
            EventHandler.RegisterEvent(m_GameObject, "OnItemStopUse", DetermineStates);
            EventHandler.RegisterEvent(m_GameObject, "OnItemReload", DetermineStates);
            EventHandler.RegisterEvent(m_GameObject, "OnItemReloadComplete", DetermineStates);
            EventHandler.RegisterEvent(m_GameObject, "OnInventoryLoadDefaultLoadout", PlayDefaultStates);
#if ENABLE_MULTIPLAYER
            EventHandler.RegisterEvent(m_GameObject, "OnInventoryNetworkMessageAdd", PlayDefaultStates);
#endif
            EventHandler.RegisterEvent <Item>(m_GameObject, "OnInventoryDualWieldItemChange", OnDualWieldItemChange);

            // The SharedFields may not have been initialized yet so load them now.
            if (m_ItemName == null)
            {
                SharedManager.InitializeSharedFields(m_GameObject, this);
            }
            // The inventory may be initialized before Awake is called in which case there needs to be a reference to the controller.
            if (m_Controller == null)
            {
                m_Controller = GetComponent <RigidbodyCharacterController>();
            }
            // Set the correct states.
            PlayDefaultStates();
        }
Exemple #5
0
        /// <summary>
        /// Cache the component references and initialize the default values.
        /// </summary>
        private void Awake()
        {
            m_Camera           = GetComponent <Camera>();
            m_CameraController = GetComponent <CameraController>();

            SharedManager.Register(this);
        }
        /// <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 override void Init(Item item, Inventory inventory)
        {
            base.Init(item, inventory);

            m_CharacterRigidbody = inventory.GetComponent <Rigidbody>();

            // Register for character events if the GameObject is active. OnEnable normally registers for these callbacks but in this case OnEnable has already occurred.
            if (m_GameObject.activeSelf)
            {
                EventHandler.RegisterEvent(m_Character, "OnAnimatorItemEndUse", EndUse);
            }

            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);
            }

            // Initialize the animation states.
            m_RecoilStates.Initialize(m_ParentItem.ItemType);
        }
Exemple #7
0
        /// <summary>
        /// The client has joined a network game. Initialize the SharedFields so they are ready for when the server starts to send RPC calls.
        /// </summary>
        public override void OnStartClient()
        {
            base.OnStartClient();

            SharedManager.InitializeSharedFields(m_GameObject, this);
            EventHandler.RegisterEvent <bool>(m_GameObject, "OnAllowGameplayInput", AllowGameplayInput);
            EventHandler.RegisterEvent <bool>(m_GameObject, "OnAllowInventoryInput", AllowGameplayInput);
        }
Exemple #8
0
 /// <summary>
 /// Initializes all of the SharedFields.
 /// </summary>
 private void Start()
 {
     SharedManager.InitializeSharedFields(gameObject, this);
     if (m_Character != null)
     {
         EventHandler.ExecuteEvent <GameObject>("OnCameraAttachCharacter", m_Character);
     }
 }
        /// <summary>
        /// Cache the component references and initialize the default values.
        /// </summary>
        protected override void Awake()
        {
            base.Awake();

            m_PlayerInput = GetComponent <PlayerInput>();
            m_Camera      = Utility.FindCamera(gameObject);

            SharedManager.Register(this);
        }
Exemple #10
0
        /// <summary>
        /// Returns the point that the canera is looking at.
        /// </summary>
        /// <returns>The point that the camera is looking at.</returns>
        public Vector3 SharedMethod_TargetLookPosition()
        {
            // The SharedMethod may be called before Start is called.
            if (m_ViewMode == null)
            {
                SharedManager.InitializeSharedFields(Utility.FindCamera(gameObject).gameObject, this);
            }

            return(CameraMonitor.TargetLookPosition(m_CameraTargetLookRay, m_CameraTargetLock, m_CameraLookDistance, m_ViewMode.Get()));
        }
Exemple #11
0
        /// <summary>
        /// Initializes all of the SharedFields.
        /// </summary>
        private 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
        }
Exemple #12
0
        /// <summary>
        /// Initializes all of the SharedFields.
        /// </summary>
        private void Start()
        {
            SharedManager.InitializeSharedFields(m_GameObject, this);
            EventHandler.RegisterEvent <bool>(m_GameObject, "OnAllowGameplayInput", AllowGameplayInput);
            EventHandler.RegisterEvent <bool>(m_GameObject, "OnAllowInventoryInput", AllowGameplayInput);

            // An AI Agent does not use PlayerInput so Update does not need to run.
            if (GetComponent <PlayerInput>() == null)
            {
                enabled = false;
            }
        }
Exemple #13
0
        /// <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);
        }
Exemple #14
0
        /// <summary>
        /// Cache the component references and initialize the default values.
        /// </summary>
        private void Awake()
        {
            m_Transform     = transform;
            m_Camera        = GetComponent <Camera>();
            m_CameraHandler = GetComponent <CameraHandler>();
            m_CameraMonitor = GetComponent <CameraMonitor>();

            SharedManager.Register(this);

            m_StartPitch = m_Pitch = m_Transform.eulerAngles.x;

            // The active state is a unique state which is layered by the additional states.
            m_ActiveState = ScriptableObject.CreateInstance <CameraState>();
            if (m_CameraStates == null || m_CameraStates.Length == 0)
            {
                m_DefaultState = ScriptableObject.CreateInstance <CameraState>();
                m_CameraStates = new CameraState[] { m_DefaultState };
            }
            else
            {
                m_DefaultState = m_CameraStates[0];
            }
            for (int i = 0; i < m_CameraStates.Length; ++i)
            {
                m_CameraStatesMap.Add(m_CameraStates[i].name, m_CameraStates[i]);
            }
            ChangeState(m_DefaultState, true);

            // If the character is not initialized on start then disable the controller - the controller won't function without a character.
            if (m_InitCharacterOnStart)
            {
                if (m_Character == null)
                {
                    Debug.LogWarning("Warning: No character has been assigned to the Camera Controller. It will automatically be assigned to the GameObject with the Player tag.");
                    m_Character = GameObject.FindGameObjectWithTag("Player");
                    if (m_Character == null)
                    {
                        Debug.LogWarning("Error: Unable to find character with the Player tag. Disabling the Camera Controller.");
                        m_CameraHandler.enabled = enabled = false;
                        return;
                    }
                }
                InitializeCharacter(m_Character);
            }
            else
            {
                m_CameraHandler.enabled = enabled = m_Character != null;
            }
        }
Exemple #15
0
        /// <summary>
        /// Initializes all of the SharedFields.
        /// </summary>
        private void Start()
        {
            SharedManager.InitializeSharedFields(gameObject, this);

            // The NetworkMonitor only needs to update for the camera. There is no camera for a non-local player so disable the component if not local.
            if (isLocalPlayer)
            {
                var camera = Utility.FindCamera(gameObject);
                SharedManager.InitializeSharedFields(camera.gameObject, this);
                camera.GetComponent <CameraController>().Character = gameObject;
            }
            else
            {
                enabled = false;
            }
        }
Exemple #16
0
        /// <summary>
        /// Initializes all of the SharedFields.
        /// </summary>
        private void Start()
        {
            // The SharedFields would have already been initialized if in a network game.
            if (m_CurrentPrimaryItem == null)
            {
                SharedManager.InitializeSharedFields(m_GameObject, this);
                EventHandler.RegisterEvent <bool>(m_GameObject, "OnAllowGameplayInput", AllowGameplayInput);
                EventHandler.RegisterEvent <bool>(m_GameObject, "OnAllowInventoryInput", AllowGameplayInput);
            }

            // An AI Agent does not use PlayerInput so Update does not need to run.
            if (GetComponent <PlayerInput>() == null)
            {
                enabled = false;
            }
        }
Exemple #17
0
        /// <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);
            }
        }
Exemple #18
0
        /// <summary>
        /// Initializes all of the SharedFields.
        /// </summary>
        private void Start()
        {
            m_Character          = (m_Controller = transform.GetComponentInParent <RigidbodyCharacterController>()).gameObject;
            m_CharacterTransform = m_Controller.transform;

            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);
            }
        }
Exemple #19
0
        /// <summary>
        /// Cache the component references and initialize the default values.
        /// </summary>
        protected virtual void Awake()
        {
            m_GameObject = gameObject;
            m_Transform  = transform;
            m_Rigidbody  = GetComponent <Rigidbody>();

            SharedManager.Register(this);

            m_CurrentHealth = m_MaxHealth;
            m_CurrentShield = m_MaxShield;
            if (m_DamageMultipliers != null && m_DamageMultipliers.Length > 0)
            {
                m_DamageMultiplierMap = new Dictionary <GameObject, DamageMultiplier>();
                for (int i = 0; i < m_DamageMultipliers.Length; ++i)
                {
                    m_DamageMultiplierMap.Add(m_DamageMultipliers[i].GameObject, m_DamageMultipliers[i]);
                }
            }

            // Register for OnRespawn so the health and sheild can be reset.
            EventHandler.RegisterEvent(m_GameObject, "OnRespawn", OnRespawn);
        }
Exemple #20
0
        /// <summary>
        /// Cache the component references and initialize the default values.
        /// </summary>
        private void Awake()
        {
            m_NetworkTransform = GetComponent <NetworkTransform>();

            SharedManager.Register(this);
        }
Exemple #21
0
        /// <summary>
        /// The client has joined a network game. Initialize the SharedFields so they are ready for when the server starts to send RPC calls.
        /// </summary>
        public override void OnStartClient()
        {
            base.OnStartClient();

            SharedManager.InitializeSharedFields(m_GameObject, this);
        }