Esempio n. 1
0
 void Awake()
 {
     _playerController = GetComponent <RigidbodyCharacterController>();
     _movementEnabled  = true;
     Cursor.visible    = false;
     Cursor.lockState  = CursorLockMode.Locked;
 }
Esempio n. 2
0
        /// <summary>
        /// Indicate which character the camera should monitor.
        /// </summary>
        /// <param name="character">The character to initialize. Can be null.</param>
        private void InitializeCharacter(GameObject character)
        {
            if (m_Character != null)
            {
                EventHandler.UnregisterEvent(m_Character, "OnRespawn", OnRespawn);
            }

            m_Character = character;
            // Don't call OnCameraAttackCharacter until after Start has been called.
            if (m_CameraOffset != null)
            {
                EventHandler.ExecuteEvent <GameObject>("OnCameraAttachCharacter", character);
            }

            if (m_Character == null)
            {
                m_CharacterTransform  = null;
                m_CharacterController = null;
                m_PlayerInput         = null;
                enabled = false;
                return;
            }

            m_CharacterTransform  = character.transform;
            m_CharacterController = character.GetComponent <RigidbodyCharacterController>();
            m_PlayerInput         = character.GetComponent <PlayerInput>();
            m_PrevMousePosition   = Vector3.one * float.MaxValue;
            EventHandler.RegisterEvent(character, "OnRespawn", OnRespawn);
            enabled = true;
        }
Esempio n. 3
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();
        }
Esempio n. 4
0
        protected override bool Initialize(Vehicle vehicle)
        {
            if (!base.Initialize(vehicle))
            {
                return(false);
            }

            characterController = vehicle.GetComponent <RigidbodyCharacterController>();
            torsoGimbal         = vehicle.GetComponent <GimballedVehicleController>();
            triggerablesManager = vehicle.GetComponent <TriggerablesManager>();
            weapons             = vehicle.GetComponent <Weapons>();

            if (characterController != null && torsoGimbal != null)
            {
                moveTargetPosition = vehicle.transform.position;

                Damageable[] damageables = vehicle.transform.GetComponentsInChildren <Damageable>();
                foreach (Damageable damageable in damageables)
                {
                    damageable.onDamaged.AddListener(delegate { OnHit(); });
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 5
0
 private void Awake()
 {
     if (m_Character == null)
     {
         m_Character = GameObject.FindGameObjectWithTag("Player");
     }
     m_controller = m_Character.GetComponent <RigidbodyCharacterController>();
 }
Esempio n. 6
0
 /// <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>();
 }
Esempio n. 7
0
        /// <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);
        }
Esempio n. 8
0
        /// <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);
        }
 private void DestroyAllAbilities(RigidbodyCharacterController controller)
 {
     DestroyImmediate(controller.GetComponent <RTSDamageVisualization>(), true);
     DestroyImmediate(controller.GetComponent <Abilities.Fall>(), true);
     DestroyImmediate(controller.GetComponent <Abilities.Jump>(), true);
     //DestroyImmediate(controller.GetComponent<SpeedChange>(), true);
     DestroyImmediate(controller.GetComponent <RTSHeightChange>(), true);
     DestroyImmediate(controller.GetComponent <Abilities.Die>(), true);
     DestroyImmediate(controller.GetComponent <RTSAreaEffectAbility>(), true);
     DestroyImmediate(controller.GetComponent <RTSSelfHealAbility>(), true);
 }
 /// <summary>
 /// Used To Add All Abilties Needed In Both Event Calls
 /// </summary>
 private void AddAllAbilities(RigidbodyCharacterController controller)
 {
     AddAbility <RTSDamageVisualization>(controller, typeof(RTSDamageVisualization), "", Ability.AbilityStartType.Manual, Ability.AbilityStopType.Manual);
     AddAbility <Abilities.Fall>(controller, typeof(Abilities.Fall), "", Abilities.Ability.AbilityStartType.Automatic, Abilities.Ability.AbilityStopType.Manual);
     AddAbility <Abilities.Jump>(controller, typeof(Abilities.Jump), "Jump", Abilities.Ability.AbilityStartType.ButtonDown, Abilities.Ability.AbilityStopType.Automatic);
     //AddAbility<SpeedChange>(controller, typeof(SpeedChange), "", Ability.AbilityStartType.Manual, Ability.AbilityStopType.Manual);
     AddAbility <RTSHeightChange>(controller, typeof(RTSHeightChange), "Crouch", Ability.AbilityStartType.Manual, Ability.AbilityStopType.Manual);
     AddAbility <Abilities.Die>(controller, typeof(Abilities.Die), "", Abilities.Ability.AbilityStartType.Manual, Abilities.Ability.AbilityStopType.Manual);
     AddAbility <RTSAreaEffectAbility>(controller, typeof(RTSAreaEffectAbility), "", Ability.AbilityStartType.Manual, Ability.AbilityStopType.Manual);
     AddAbility <RTSSelfHealAbility>(controller, typeof(RTSSelfHealAbility), "", Ability.AbilityStartType.Manual, Ability.AbilityStopType.Manual);
 }
        protected override void OnEnable()
        {
            base.OnEnable();

            if (target == null)
            {
                return;
            }
            m_controller = (RigidbodyCharacterController)target;


            m_LineHeight = EditorGUIUtility.singleLineHeight;
            m_DefaultActionTextStyle.fontStyle = FontStyle.Normal;
            m_ActiveActionTextStyle.fontStyle  = FontStyle.Bold;


            m_motorSettings     = serializedObject.FindProperty("m_motor");
            m_physicsSettings   = serializedObject.FindProperty("m_physics");
            m_collisionSettings = serializedObject.FindProperty("m_collision");
            m_advanceSettings   = serializedObject.FindProperty("m_advance");
            m_animationSettings = serializedObject.FindProperty("m_animation");
            debugger            = serializedObject.FindProperty("debugger");

            if (motorGUIContent == null)
            {
                motorGUIContent = new GUIContent();
            }
            if (physicsGUIContent == null)
            {
                physicsGUIContent = new GUIContent();
            }
            if (collisionsGUIContent == null)
            {
                collisionsGUIContent = new GUIContent();
            }
            if (animationGUIContent == null)
            {
                animationGUIContent = new GUIContent();
            }
            if (advanceGUIContent == null)
            {
                advanceGUIContent = new GUIContent();
            }


            displayMovement   = serializedObject.FindProperty("displayMovement");
            displayPhysics    = serializedObject.FindProperty("displayPhysics");
            displayCollisions = serializedObject.FindProperty("displayCollisions");
            displayAnimations = serializedObject.FindProperty("displayAnimations");
            displayActions    = serializedObject.FindProperty("displayActions");
            m_ActionsList     = new ReorderableList(serializedObject, serializedObject.FindProperty("m_actions"), true, true, true, true);
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
        // Called when the game agent enters a vehicle
        protected override bool Initialize(Vehicle vehicle)
        {
            if (!base.Initialize(vehicle))
            {
                return(false);
            }

            // Grab necessary components
            m_RigidbodyCharacterController = vehicle.GetComponent <RigidbodyCharacterController>();
            lookController = vehicle.GetComponent <GimballedVehicleController>();

            return(m_RigidbodyCharacterController != null);
        }
Esempio n. 14
0
    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());
    }
Esempio n. 15
0
        /// <summary>
        /// Cache the component references.
        /// </summary>
        protected virtual void Awake()
        {
            m_GameObject   = gameObject;
            m_Transform    = transform;
            m_Controller   = GetComponent <RigidbodyCharacterController>();
            m_NavMeshAgent = GetComponent <NavMeshAgent>();
            m_JumpAbility  = GetComponent <Abilities.Jump>();
            m_FallAbility  = GetComponent <Abilities.Fall>();

            m_NavMeshAgent.autoTraverseOffMeshLink = false;

            EventHandler.RegisterEvent(m_GameObject, "OnDeath", OnDeath);
            EventHandler.RegisterEvent <bool>(m_GameObject, "OnControllerGrounded", OnGrounded);
        }
Esempio n. 16
0
        /// <summary>
        /// Cache the component references and initialize the default values.
        /// </summary>
        private void Awake()
        {
            m_GameObject = gameObject;
            m_Animator   = GetComponent <Animator>();
            m_Controller = GetComponent <RigidbodyCharacterController>();

            if (m_Animator.avatar == null)
            {
                Debug.LogError("Error: The Animator Avatar on " + m_GameObject + " is not assigned. Please assign an avatar within the inspector.");
            }

            EventHandler.RegisterEvent(m_GameObject, "OnDeath", OnDeath);
            EventHandler.RegisterEvent(m_GameObject, "OnInventoryInitialized", Initialize);
        }
Esempio n. 17
0
        /// <summary>
        /// Cache the component references and register for any network events.
        /// </summary>
        protected virtual void Awake()
        {
            m_GameObject  = gameObject;
            m_Transform   = transform;
            m_Controller  = GetComponent <RigidbodyCharacterController>();
            m_PlayerInput = GetComponent <PlayerInput>();

#if ENABLE_MULTIPLAYER
            EventHandler.RegisterEvent("OnNetworkStopClient", OnNetworkDestroy);
#endif
            EventHandler.RegisterEvent <bool>(m_GameObject, "OnAllowGameplayInput", AllowGameplayInput);
            EventHandler.RegisterEvent <string, string, string>(m_GameObject, "OnAbilityRegisterInput", RegisterAbilityInput);
            EventHandler.RegisterEvent <string, string, string>(m_GameObject, "OnAbilityUnregisterInput", UnregisterAbilityInput);
        }
Esempio n. 18
0
        // ------------


        private void Awake()
        {
            m_controller = GetComponent <RigidbodyCharacterController>();
            m_transform  = transform;
            m_inventory  = GetComponent <Inventory>();
            //m_finalIKController = GetComponent<FinalIKController>();
            if (m_camera == null)
            {
                m_camera = Camera.main.transform;
            }
            if (vcamTarget == null)
            {
                vcamTarget = m_transform;
            }
        }
Esempio n. 19
0
    protected void Reset()
    {
        vehicle             = GetComponent <Vehicle>();
        characterController = GetComponent <RigidbodyCharacterController>();
        m_Animator          = GetComponent <Animator>();
        trackable           = GetComponent <Trackable>();
        m_Animator          = GetComponent <Animator>();
        capsuleCollider     = GetComponent <CapsuleCollider>();

        Collider[] collidersArray = transform.GetComponentsInChildren <Collider>();
        foreach (Collider collider in collidersArray)
        {
            bodyColliders.Add(collider);
        }
    }
Esempio n. 20
0
        /// <summary>
        /// Cache the component references and initialize the default values.
        /// </summary>
        private void Awake()
        {
            m_GameObject = gameObject;
            m_Transform  = transform;
            m_Animator   = GetComponent <Animator>();
            m_Controller = GetComponent <RigidbodyCharacterController>();

            // Prevent a divide by zero.
            if (m_LookAtClampWeight == 0)
            {
                m_LookAtClampWeight = 0.001f;
            }

            if (m_Animator.GetBoneTransform(HumanBodyBones.Head) == null)
            {
                Debug.LogError("Error: The CharacterIK component can only work with humanoid models.");
                enabled = false;
                return;
            }

            // Initialize the variables used for IK.
            m_Head               = m_Animator.GetBoneTransform(HumanBodyBones.Head);
            m_Hips               = m_Animator.GetBoneTransform(HumanBodyBones.Hips);
            m_HipsOffset         = 0;
            m_HipsPosition       = m_Hips.position;
            m_Foot               = new Transform[2];
            m_LegLength          = new float[2];
            m_LegPotentialLength = new float[2];
            m_FootOffset         = new float[2];
            m_FootPosition       = new Vector3[2];
            m_FootRotation       = new Quaternion[2];
            m_FootIKWeight       = new float[2];

            for (int i = 0; i < 2; ++i)
            {
                m_Foot[i]       = m_Animator.GetBoneTransform(i == 0 ? HumanBodyBones.LeftFoot : HumanBodyBones.RightFoot);
                m_FootOffset[i] = m_Foot[i].position.y - m_Transform.position.y - 0.03f;
                m_LegLength[i]  = m_Hips.position.y - m_Foot[i].position.y + m_FootOffset[i] + 0.03f;
                var bendLegth = m_Animator.GetBoneTransform(i == 0 ? HumanBodyBones.LeftUpperLeg : HumanBodyBones.RightUpperLeg).position.y - m_Foot[i].position.y;
                m_LegPotentialLength[i] = m_LegLength[i] + bendLegth / 2;
                m_FootPosition[i]       = m_Foot[i].position;
                m_FootRotation[i]       = m_Foot[i].rotation;
            }

            m_LeftHand           = m_Animator.GetBoneTransform(HumanBodyBones.LeftHand);
            m_RightHand          = m_Animator.GetBoneTransform(HumanBodyBones.RightHand);
            m_HandRotationWeight = new float[2];
        }
Esempio n. 21
0
        /// <summary>
        /// Cache the component references.
        /// </summary>
        private void Awake()
        {
            m_CameraController = Camera.main.GetComponent <CameraController>();
            if (m_CameraController == null)
            {
                Debug.LogError("Error: Unable to find the CameraController.");
                enabled = false;
            }
            m_CameraHandler = m_CameraController.GetComponent <CameraHandler>();

            m_BlitzCharacterController = m_Blitz.GetComponent <RigidbodyCharacterController>();
            m_BlitzPosition            = m_Blitz.transform.position;
            m_BlitzRotation            = m_Blitz.transform.rotation;

            EventHandler.RegisterEvent <bool>(m_Blitz, "OnAllowGameplayInput", OnBlitzAllowGameplayInput);
        }
Esempio n. 22
0
        protected void Reset()
        {
            m_RigidbodyCharacterController = GetComponent <RigidbodyCharacterController>();

            Animator animatorController = GetComponentInChildren <Animator>();

            if (animatorController != null)
            {
                forwardFloatParameterReceivers.Add(new AnimatorFloatParameterItem(animatorController, "Forward"));
                turnFloatParameterReceivers.Add(new AnimatorFloatParameterItem(animatorController, "Turn"));
                groundedBoolParameterReceivers.Add(new AnimatorBoolParameterItem(animatorController, "Grounded"));
                landedTriggerParameterReceivers.Add(new AnimatorTriggerParameterItem(animatorController, "Landed"));

                animatorStateSettings.Add(new AnimatorStateSettings(animatorController, "Landing", true));
            }
        }
Esempio n. 23
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);
            }
        }
Esempio n. 24
0
        void Start()
        {
            health              = GetComponent(typeof(CharacterHealth)) as CharacterHealth;
            behaviorTree        = GetComponent <BehaviorTree>();
            deathmatchAgent     = GetComponent <DeathmatchAgent>();
            navMeshAgent        = GetComponent <NavMeshAgent>();
            characterController = GetComponent <RigidbodyCharacterController>();
            speedChange         = GetComponent <SpeedChange>();
            inventory           = GetComponent <Opsive.ThirdPersonController.Wrappers.Inventory>();

            if (flowchart == null && flowchartName != null && flowchartName.Trim().Length != 0)
            {
                flowchart = GameObject.Find("/Fungus/Flowcharts/" + flowchartName).GetComponent <Fungus.Flowchart>();
            }

            trackEvent.AddListener(TrackTargetsInLayers);
        }
Esempio n. 25
0
        public override TaskStatus OnUpdate()
        {
            var target = GetDefaultGameObject(targetGameObject.Value);

            if (target != prevTarget)
            {
                controller = target.GetComponentInParent <RigidbodyCharacterController>();
                prevTarget = target;
            }

            if (controller == null)
            {
                return(TaskStatus.Failure);
            }
            controller.Move(horizontalMovement.Value, forwardMovement.Value, Quaternion.LookRotation(direction.Value));
            return(TaskStatus.Success);
        }
Esempio n. 26
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);
            }
        }
Esempio n. 27
0
        /// <summary>
        /// Cache the component references and initialize the default values.
        /// </summary>
        private void Awake()
        {
            m_GameObject = gameObject;
            m_Controller = GetComponent <RigidbodyCharacterController>();

            // Notify each foot which index they are.
            for (int i = 0; i < m_Feet.Length; ++i)
            {
                var footTrigger = m_Feet[i].GetComponent <CharacterFootTrigger>();
                if (footTrigger != null)
                {
                    footTrigger.Index = i;
                }
            }

            m_FootAudioSource = new AudioSource[m_Feet.Length];
            for (int i = 0; i < m_Feet.Length; ++i)
            {
                m_FootAudioSource[i] = m_Feet[i].GetComponent <AudioSource>();
                if (m_FootAudioSource[i] == null)
                {
                    Debug.LogError("Error: The " + (i == 0 ? "left" : "right") + "foot does not have a AudioSource required for footsteps.");
                }
            }

            // Initialze the foot arrays if each foot has a specific sound.
            if (m_PerFootSounds)
            {
                m_PerFootSoundList = new List <List <AudioClip> >();
                for (int i = 0; i < m_Feet.Length; ++i)
                {
                    var footSounds = new List <AudioClip>();
                    for (int j = 0; j < m_Footsteps.Length; ++j)
                    {
                        if (m_Footsteps[j].Foot.Equals(m_Feet[i]))
                        {
                            footSounds.Add(m_Footsteps[i].Sound);
                        }
                    }
                    m_PerFootSoundList.Add(footSounds);
                }
            }
        }
Esempio n. 28
0
        public override TaskStatus OnUpdate()
        {
            var target = GetDefaultGameObject(targetGameObject.Value);

            if (target != prevTarget)
            {
                controller        = target.GetComponentInParent <RigidbodyCharacterController>();
                controllerHandler = target.GetComponentInParent <ControllerHandler>();
                var abilities = controller.GetComponents(TaskUtility.GetTypeWithinAssembly(abilityType.Value));
                if (abilities.Length > 1)
                {
                    if (priorityIndex.Value != -1)
                    {
                        for (int i = 0; i < abilities.Length; ++i)
                        {
                            var localAbility = abilities[i] as Ability;
                            if (localAbility.Index == priorityIndex.Value)
                            {
                                ability = localAbility;
                                break;
                            }
                        }
                    }
                    else
                    {
                        ability = abilities[0] as Ability;
                    }
                }
                else if (abilities.Length == 1)
                {
                    ability = abilities[0] as Ability;
                }
                prevTarget = target;
            }
            if (ability == null)
            {
                return(TaskStatus.Failure);
            }

            controllerHandler.TryStartAbility(ability);

            return(TaskStatus.Success);
        }
        /// <summary>
        /// Cache component references and initializes default values.
        /// </summary>
        protected override void Awake()
        {
            base.Awake();

            if (m_LookTransform == null)
            {
                m_LookTransform = GetComponent <Animator>().GetBoneTransform(HumanBodyBones.Head);
            }
            m_Controller      = GetComponent <RigidbodyCharacterController>();
            m_CapsuleCollider = GetComponent <CapsuleCollider>();
#if !(UNITY_5_1 || UNITY_5_2)
            m_HitColliders = new Collider[10];
#endif
            m_AvailableWeaponMap = new Dictionary <ItemType, WeaponStat>();
            for (int i = 0; i < m_AvailableWeapons.Length; ++i)
            {
                m_AvailableWeaponMap.Add(m_AvailableWeapons[i].ItemType, m_AvailableWeapons[i]);
            }
        }
Esempio n. 30
0
        /// <summary>
        /// Adds the ability to the RigidbodyCharacterController.
        /// </summary>
        /// <param name="controller">A reference to the RigidbodyCharacterController.</param>
        /// <param name="type">The type of ability to add.</param>
        /// <param name="inputName">The ability input name. Can be empty.</param>
        /// <param name="startType">The ability StartType.</param>
        /// <param name="stopType">The ability StopType.</param>
        private void AddAbility(RigidbodyCharacterController controller, Type type, string inputName, Abilities.Ability.AbilityStartType startType, Abilities.Ability.AbilityStopType stopType)
        {
            var ability = controller.gameObject.AddComponent(type) as Abilities.Ability;

            // The RigidbodyCharacterController will show the ability inspector.
            ability.hideFlags = HideFlags.HideInInspector;

            // Set the base class values.
            ability.StartType = startType;
            ability.StopType  = stopType;
            ability.InputName = inputName;

            // Add the ability to the RigidbodyCharacterController.
            var abilities = controller.Abilities;

            ability.Index = abilities.Length;
            Array.Resize(ref abilities, abilities.Length + 1);
            abilities[abilities.Length - 1] = ability;
            controller.Abilities            = abilities;
        }