void Awake() { _playerController = GetComponent <RigidbodyCharacterController>(); _movementEnabled = true; Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; }
/// <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; }
/// <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(); }
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); } }
private void Awake() { if (m_Character == null) { m_Character = GameObject.FindGameObjectWithTag("Player"); } m_controller = m_Character.GetComponent <RigidbodyCharacterController>(); }
/// <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> /// 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> /// 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); }
/// <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); }
// 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); }
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> /// 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); }
/// <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); }
/// <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); }
// ------------ 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; } }
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); } }
/// <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]; }
/// <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); }
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)); } }
/// <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); } }
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); }
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); }
/// <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); } }
/// <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); } } }
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]); } }
/// <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; }