void Start() { EmeraldComponent = transform.parent.GetComponent <Emerald_AI>(); m_Camera = Camera.main; //GlobalScale = transform.root.localScale; GlobalScale = EmeraldComponent.transform.localScale; }
void Update() { //Draw a ray foward from our player at a distance according to the TameDistance if (Physics.Raycast(transform.position, transform.forward, out hit, TameDistance)) { if (hit.collider.CompareTag(AITag)) { //Color our crosshair red to indicate a valid target if (CrosshairImage != null) { CrosshairImage.color = Color.green; } if (Input.GetKeyDown(KeyCode.F)) { //Check to see if the object we have hit contains an Emerald AI component if (hit.collider.gameObject.GetComponent <Emerald_AI>() != null) { //Get a reference to the Emerald AI object that was hit Emerald_AI EmeraldAIRef = hit.collider.gameObject.GetComponent <Emerald_AI>(); //Check to see if our hit Emerald AI's behavior is not aggressive or companion so we can tame it if (EmeraldAIRef.BehaviorRef != Emerald_AI.CurrentBehavior.Aggressive && EmeraldAIRef.BehaviorRef != Emerald_AI.CurrentBehavior.Companion) { EmeraldAIRef.SetFollowerCompanion(transform.parent); } } } } else { //Color our crosshair white because there is no target if (CrosshairImage != null) { CrosshairImage.color = Color.white; } } } else { //Color our crosshair white because there is no target if (CrosshairImage != null) { CrosshairImage.color = Color.white; } } }
void Update() { //Draw a ray foward from our player at a distance according to the DetectDistance if (Physics.Raycast(transform.position, transform.forward, out hit, DetectDistance)) { if (hit.collider.CompareTag(AITag)) { //Color our crosshair red to indicate a valid target if (CrosshairImage != null) { CrosshairImage.color = Color.green; } if (Input.GetKeyDown(KeyCode.F)) { //Check to see if the object we have hit contains an Emerald AI component if (hit.collider.gameObject.GetComponent <Emerald_AI>() != null) { //Get a reference to the Emerald AI object that was hit Emerald_AI EmeraldAIRef = hit.collider.gameObject.GetComponent <Emerald_AI>(); //Play the AI's Emote animation with the ID of EmoteID EmeraldAIRef.PlayEmoteAnimation(EmoteID); } } } else { //Color our crosshair white because there is no target if (CrosshairImage != null) { CrosshairImage.color = Color.white; } } } else { //Color our crosshair white because there is no target if (CrosshairImage != null) { CrosshairImage.color = Color.white; } } }
/// <summary> /// snaps the bullet to the hit point (for proper 3d audio positioning) /// and tries to spawn a UFPS surface effect /// </summary> protected override void TrySpawnFX() { // move transform to impact point in order for the audio source to play // impact sound at the correct 3d position m_Transform.position = m_Hit.point; //Damage Emerald AI object if (m_Hit.collider.gameObject.tag == "Emerald AI") { if (m_Hit.collider.gameObject.GetComponent <Emerald_AI>() != null) { Emerald_AI EmeraldComponent = m_Hit.collider.gameObject.GetComponent <Emerald_AI>(); EmeraldComponent.Damage((int)Damage, Emerald_AI.TargetType.Player); } } vp_SurfaceManager.SpawnEffect(m_Hit, ImpactEvent, m_Audio); }
void AssignEmeraldAIComponents() { List <SkinnedMeshRenderer> ObjRenderer = new List <SkinnedMeshRenderer>(); if (ObjectToSetup != null && ObjectToSetup.GetComponent <Emerald_AI>() == null && ObjectToSetup.GetComponent <Animator>() != null) { secs = 1.5f; ObjectToSetup.AddComponent <Emerald_AI>(); ObjectToSetup.GetComponent <AudioSource>().spatialBlend = 1; ObjectToSetup.GetComponent <AudioSource>().dopplerLevel = 0; ObjectToSetup.GetComponent <AudioSource>().rolloffMode = AudioRolloffMode.Linear; ObjectToSetup.GetComponent <AudioSource>().minDistance = 1; ObjectToSetup.GetComponent <AudioSource>().maxDistance = 50; Emerald_AI Emerald = ObjectToSetup.GetComponent <Emerald_AI>(); if (SetupAnimationsRef == SetupAnimations.Later) { //Get the AI's Animator and set the default Runtime Controller Emerald.AIAnimator = ObjectToSetup.GetComponent <Animator>(); Emerald.AIAnimator.runtimeAnimatorController = AssetDatabase.LoadAssetAtPath("Assets/Emerald AI 2.0/Animator/Temp Emerald Animator (Do Not Edit).controller", typeof(RuntimeAnimatorController)) as RuntimeAnimatorController; } Emerald.BehaviorRef = (Emerald_AI.CurrentBehavior)AIBehaviorRef; Emerald.ConfidenceRef = (Emerald_AI.ConfidenceType)ConfidenceRef; Emerald.WanderTypeRef = (Emerald_AI.WanderType)WanderTypeRef; if (SetupAnimationsRef == SetupAnimations.Now) { Emerald.AIAnimator = ObjectToSetup.GetComponent <Animator>(); Emerald.overrideController = overrideController; Emerald.Idle1 = Idle1; Emerald.Idle2 = Idle2; Emerald.Idle3 = Idle3; Emerald.IdleAlert = IdleAlert; Emerald.IdleWarning = IdleWarning; Emerald.IdleCombat = IdleCombat; Emerald.Walk = Walk; Emerald.Run = Run; Emerald.TurnLeft = TurnLeft; Emerald.TurnRight = TurnRight; Emerald.RunAttack = RunAttack; Emerald.Attack1 = Attack1; Emerald.Attack2 = Attack2; Emerald.Attack3 = Attack3; if (Hit1 != null) { Emerald.HitAnimationList.Clear(); Emerald.HitAnimationList.Add(new Emerald_AI.HitAnimationClass()); Emerald.HitAnimationList[0].AnimationSpeed = 1; Emerald.HitAnimationList[0].HitAnimationClip = Hit1; } if (DeadAnim != null) { Emerald.DeathAnimationList.Clear(); Emerald.DeathAnimationList.Add(new Emerald_AI.DeathAnimationClass()); Emerald.DeathAnimationList[0].AnimationSpeed = 1; Emerald.DeathAnimationList[0].DeathAnimationClip = DeadAnim; } if (Idle3 != null && Idle2 != null) { Emerald.TotalIdleAnimationsRef = (Emerald_AI.TotalIdleAnimations) 2; } if (Idle3 == null && Idle2 != null) { Emerald.TotalIdleAnimationsRef = (Emerald_AI.TotalIdleAnimations) 1; } if (Idle2 == null && Idle3 == null) { Emerald.TotalIdleAnimationsRef = (Emerald_AI.TotalIdleAnimations) 0; } if (Attack3 != null && Attack2 != null) { Emerald.TotalAttackAnimationsRef = (Emerald_AI.TotalAttackAnimations) 2; } if (Attack3 == null && Attack2 != null) { Emerald.TotalAttackAnimationsRef = (Emerald_AI.TotalAttackAnimations) 1; } if (Attack2 == null && Attack3 == null) { Emerald.TotalAttackAnimationsRef = (Emerald_AI.TotalAttackAnimations) 0; } Emerald.SetupAnimations(AIAnimator); } if (SetupOptimizationSettingsRef == SetupOptimizationSettings.Yes) { Emerald.DisableAIWhenNotInViewRef = Emerald_AI.YesOrNo.Yes; if (ObjectToSetup.GetComponent <LODGroup>() != null) { LODGroup _LODGroup = ObjectToSetup.GetComponentInChildren <LODGroup>(); if (_LODGroup != null) { LOD[] AllLODs = _LODGroup.GetLODs(); if (_LODGroup.lodCount <= 4) { Emerald.TotalLODsRef = (Emerald_AI.TotalLODsEnum)(_LODGroup.lodCount - 2); Emerald.HasMultipleLODsRef = Emerald_AI.YesOrNo.Yes; } if (_LODGroup.lodCount > 1) { for (int i = 0; i < _LODGroup.lodCount; i++) { if (i == 0) { Emerald.Renderer1 = AllLODs[i].renderers[0]; } if (i == 1) { Emerald.Renderer2 = AllLODs[i].renderers[0]; } if (i == 2) { Emerald.Renderer3 = AllLODs[i].renderers[0]; } if (i == 3) { Emerald.Renderer4 = AllLODs[i].renderers[0]; } } } else if (_LODGroup.lodCount == 1) { Emerald.HasMultipleLODsRef = Emerald_AI.YesOrNo.No; } } else if (_LODGroup == null) { Emerald.HasMultipleLODsRef = Emerald_AI.YesOrNo.No; } } } Component[] AllComponents = ObjectToSetup.GetComponents <Component>(); for (int i = 0; i < AllComponents.Length; i++) { UnityEditorInternal.ComponentUtility.MoveComponentUp(Emerald); } foreach (SkinnedMeshRenderer R in ObjectToSetup.GetComponentsInChildren <SkinnedMeshRenderer>()) { if (R != ObjectToSetup.GetComponent <SkinnedMeshRenderer>()) { ObjRenderer.Add(R); } } if (ObjRenderer.Count > 0) { Bounds RendererBounds = ObjRenderer[0].bounds; ObjectToSetup.GetComponent <BoxCollider>().size = new Vector3(RendererBounds.extents.x, RendererBounds.size.y, RendererBounds.extents.z); ObjectToSetup.GetComponent <BoxCollider>().center = new Vector3(ObjectToSetup.GetComponent <BoxCollider>().center.x, RendererBounds.extents.y, ObjectToSetup.GetComponent <BoxCollider>().center.z); } overrideController = null; ObjectToSetup = null; } else if (ObjectToSetup == null) { EditorUtility.DisplayDialog("Emerald AI Setup Manager - Oops!", "There is no object assigned to the AI Object slot. Please assign one and try again.", "Okay"); } else if (ObjectToSetup.GetComponent <Emerald_AI>() != null) { EditorUtility.DisplayDialog("Emerald AI Setup Manager - Oops!", "There is already an Emerald AI component on this object. Please choose another object to apply an Emerald AI component to.", "Okay"); } else if (ObjectToSetup.GetComponent <Animator>() == null) { EditorUtility.DisplayDialog("Emerald AI Setup Manager - Oops!", "There is no Animator component attached to your AI. Please assign one and try again.", "Okay"); } }