public void OnEnable() { td_target = (TopDownAI)target; if (TopDownIcon == null) { TopDownIcon = Resources.Load("TopDownIcon") as Texture; } }
public void Spell_Damage(int damageValue) { TopDownCharacterCard tdcc = TopDownCharacterManager.instance.controllingCharacter.GetComponent <TopDownRpgSpellcaster>().previousTarget.GetComponent <TopDownCharacterCard>(); if (tdcc != null) { tdcc.health -= damageValue; TopDownAI tdccAi = tdcc.GetComponent <TopDownAI>(); if (tdccAi.playerInSight == false) { tdccAi.detected = true; tdccAi.playerInSight = true; tdccAi.focus = TopDownCharacterManager.instance.controllingCharacter.transform; } } }
void OnGUI() { GUIStyle boldCenteredLabel = new GUIStyle(EditorStyles.boldLabel) { alignment = TextAnchor.MiddleCenter }; EditorStyles.textField.wordWrap = true; EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); EditorGUILayout.BeginVertical("Box", GUILayout.Width(90 * Screen.width / 100)); EditorGUILayout.LabelField(new GUIContent(TopDownIcon), boldCenteredLabel, GUILayout.ExpandWidth(true), GUILayout.Height(32)); EditorGUILayout.LabelField("- TOP DOWN RPG -", boldCenteredLabel); EditorGUILayout.LabelField("Setup New AI", boldCenteredLabel); EditorGUILayout.HelpBox("This is used to setup new AI characters \nYou should setup your desired model that will be used to setup new AI character.", MessageType.Info); EditorGUILayout.EndVertical(); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); aiModel = (GameObject)EditorGUILayout.ObjectField("AI Model:", aiModel, typeof(GameObject), true); aiHostile = EditorGUILayout.Toggle("Is AI Hostile?", aiHostile); if (aiModel != null) { if (GUILayout.Button("Create AI")) { GameObject charObject = Instantiate(aiModel); if (charObject.GetComponent <Animator>() == null) { Animator charAnimator = charObject.AddComponent <Animator>(); RuntimeAnimatorController animController = Resources.Load("TopDownCharacterAnimationController") as RuntimeAnimatorController; charAnimator.runtimeAnimatorController = animController; } else { RuntimeAnimatorController animController = Resources.Load("TopDownCharacterAnimationController") as RuntimeAnimatorController; charObject.GetComponent <Animator>().runtimeAnimatorController = animController; } Rigidbody charRigidbody = charObject.AddComponent <Rigidbody>(); charRigidbody.useGravity = false; charRigidbody.isKinematic = false; charRigidbody.freezeRotation = true; CapsuleCollider charCollider = charObject.AddComponent <CapsuleCollider>(); charCollider.radius = 0.3f; charCollider.height = 1.5f; charCollider.center = new Vector3(0f, 0.75f, 0f); NavMeshAgent charAgent = charObject.AddComponent <NavMeshAgent>(); charAgent.speed = 1f; charAgent.stoppingDistance = 1.5f; charAgent.height = 1.5f; TopDownAI ai = charObject.AddComponent <TopDownAI>(); TopDownEquipmentManager charEquipManager = charObject.AddComponent <TopDownEquipmentManager>(); if (charObject.transform.Find("[Vision]") == false) { GameObject vision = new GameObject(); vision.name = "[Vision]"; vision.transform.SetParent(charObject.transform); vision.transform.localPosition = Vector3.zero; vision.layer = 1 << 1; SphereCollider col = vision.AddComponent <SphereCollider>(); col.isTrigger = true; col.center = Vector3.zero; col.radius = charObject.GetComponent <TopDownCharacterCard>().aiDetectRadius; col.gameObject.layer = 2; charObject.GetComponent <TopDownCharacterCard>().aiVision = col; //Debug.LogFormat("Setting up <b><color=yellow>Vision collider</color></b> as child of <b><color=red>" + charObject.gameObject.name + "</color></b>."); } Debug.LogFormat("New AI has been set up. You need to adjust weapon and shield mount and holster points for better visual. You should also setup basic values (name, health, voice set) inside TopDownAI component located on your new AI."); Transform[] allChildren = charObject.GetComponentsInChildren <Transform>(); for (int i = 0; i < allChildren.Length; i++) { if (charEquipManager.weaponMountPoint == null) { if ((allChildren[i].name.Contains("hand") || allChildren[i].name.Contains("HAND") || allChildren[i].name.Contains("Hand") || (allChildren[i].name.Contains("wrist") || allChildren[i].name.Contains("WRIST") || allChildren[i].name.Contains("Wrist")) && (allChildren[i].name.Contains("right") || allChildren[i].name.Contains("RIGHT") || allChildren[i].name.Contains("Right")))) { GameObject weaponMount = new GameObject(); weaponMount.name = "WEAPON_MOUNTPOINT"; weaponMount.transform.SetParent(allChildren[i]); weaponMount.transform.localPosition = Vector3.zero; weaponMount.transform.localEulerAngles = Vector3.zero; charEquipManager.weaponMountPoint = weaponMount.transform; } } if (charEquipManager.shieldMountPoint == null) { if ((allChildren[i].name.Contains("hand") || allChildren[i].name.Contains("HAND") || allChildren[i].name.Contains("Hand") || (allChildren[i].name.Contains("wrist") || allChildren[i].name.Contains("WRIST") || allChildren[i].name.Contains("Wrist")) && (allChildren[i].name.Contains("left") || allChildren[i].name.Contains("LEFT") || allChildren[i].name.Contains("Left")))) { GameObject shieldMount = new GameObject(); shieldMount.name = "SHIELD_MOUNTPOINT"; shieldMount.transform.SetParent(allChildren[i]); shieldMount.transform.localPosition = Vector3.zero; shieldMount.transform.localEulerAngles = Vector3.zero; charEquipManager.shieldMountPoint = shieldMount.transform; } } if (charEquipManager.shieldHolsterMountPoint == null) { if (allChildren[i].name.Contains("spine") || allChildren[i].name.Contains("SPINE") || allChildren[i].name.Contains("Spine")) { GameObject weaponHolsterPoint = new GameObject(); weaponHolsterPoint.name = "WEAPON_HOLSTER_MOUNTPOINT"; weaponHolsterPoint.transform.SetParent(allChildren[i]); weaponHolsterPoint.transform.localPosition = Vector3.zero; weaponHolsterPoint.transform.localEulerAngles = Vector3.zero; charEquipManager.weaponHolsterMountPoint = weaponHolsterPoint.transform; GameObject shieldHolsterPoint = new GameObject(); shieldHolsterPoint.name = "SHIELD_HOLSTER_MOUNTPOINT"; shieldHolsterPoint.transform.SetParent(allChildren[i]); shieldHolsterPoint.transform.localPosition = Vector3.zero; shieldHolsterPoint.transform.localEulerAngles = Vector3.zero; charEquipManager.shieldHolsterMountPoint = shieldHolsterPoint.transform; } } } if (aiHostile == true) { charObject.name = "Top Down Enemy"; charObject.tag = "Enemy"; charObject.layer = 0; ai.hostile = true; } else { charObject.name = "Top Down NPC"; charObject.tag = "NPC"; charObject.layer = 0; ai.hostile = false; } Selection.activeObject = charObject.gameObject; aiModel.SetActive(false); } } else { EditorGUILayout.HelpBox("You need to set your AI model before you can create your character.", MessageType.Warning); } }
private void Die() { if (GetComponent <TopDownAI>()) { TopDownAI ai = GetComponent <TopDownAI>(); if (ai.voiceSet != null) { if (ai.voiceSet.deathVoice != null) { Instantiate(ai.voiceSet.deathVoice, transform.position, Quaternion.identity); } } } mouseOver = false; npcBar.nameText.text = string.Empty; npcBar.healthBar.fillAmount = 0f; npcBar.energyBar.fillAmount = 0f; npcBar.portraitImage.enabled = false; npcBar.transform.position = new Vector2(-100f, 0f); main.tdcm_animator.SetLayerWeight(0, 0f); main.tdcm_animator.SetLayerWeight(1, 0f); //tdcm_animator.SetBool("Attacking", false); //tdcm_animator.SetBool("TargetInFront", false); main.tdcm_animator.SetBool("Dead", true); //gameObject.tag = "Dead"; main.onDeadEvent.Invoke(); Destroy(main.tdcm_rigidbody); Destroy(GetComponent <CapsuleCollider>()); Destroy(GetComponent <NavMeshAgent>()); if (GetComponent <TopDownAI>()) { Destroy(GetComponent <TopDownAI>()); } if (GetComponent <TopDownEquipmentManager>()) { Destroy(GetComponent <TopDownEquipmentManager>()); } if (GetComponent <TopDownControllerMain>()) { Destroy(GetComponent <TopDownControllerMain>()); } if (GetComponent <TopDownUIDialog>()) { Destroy(GetComponent <TopDownUIDialog>()); } if (transform.Find("[Vision]")) { Destroy(transform.Find("[Vision]").gameObject); } if (GetComponent <TopDownDecompose>()) { GetComponent <TopDownDecompose>().decompose = true; } if (GetComponent <TopDownRpgOnDeathEvent>()) { GetComponent <TopDownRpgOnDeathEvent>().InvokeOnDeathEvent(); } TopDownDecompose decompose = gameObject.AddComponent <TopDownDecompose>(); decompose.decompose = true; Destroy(this); return; }
public void AttackFocusedTarget() { if (tcc_Interact != null) { if (tcc_Interact.focusedTarget != null && td_characterCard.enemyFocus == null) { DealDamage(tcc_Interact.focusedTarget.gameObject, damagePointsValue); if (TopDownAudioManager.instance != null && TopDownAudioManager.instance.meleeHitAudio != null) { Instantiate(TopDownAudioManager.instance.meleeHitAudio, transform.position, Quaternion.identity); } if (TopDownParticleManager.instance != null && TopDownParticleManager.instance.hitParticle != null) { GameObject[] hit = TopDownParticleManager.instance.hitParticle; if (tcc_Interact.focusedTarget.GetComponent <NavMeshAgent>()) { float height = tcc_Interact.focusedTarget.GetComponent <NavMeshAgent>().height; Vector3 center = new Vector3(tcc_Interact.focusedTarget.position.x, height * 0.5f, tcc_Interact.focusedTarget.position.z); Instantiate(hit[Random.Range(0, hit.Length)], center, Quaternion.identity); } else { Vector3 center = new Vector3(tcc_Interact.focusedTarget.position.x, 1.5f, tcc_Interact.focusedTarget.position.z); Instantiate(hit[Random.Range(0, hit.Length)], center, Quaternion.identity); } if (tcc_Interact.focusedTarget.GetComponent <TopDownAI>()) { TopDownAI ai = tcc_Interact.focusedTarget.GetComponent <TopDownAI>(); if (ai.voiceSet != null) { if (ai.voiceSet.getHitVoice) { Instantiate(ai.voiceSet.getHitVoice, transform.position, Quaternion.identity); } } } } } else if (td_characterCard.enemyFocus != null) { DealDamage(td_characterCard.enemyFocus.gameObject, damagePointsValue); if (TopDownAudioManager.instance != null && TopDownAudioManager.instance.meleeHitAudio != null) { Instantiate(TopDownAudioManager.instance.meleeHitAudio, transform.position, Quaternion.identity); } if (TopDownParticleManager.instance != null && TopDownParticleManager.instance.hitParticle != null) { GameObject[] hit = TopDownParticleManager.instance.hitParticle; if (td_characterCard.enemyFocus.GetComponent <NavMeshAgent>()) { float height = td_characterCard.enemyFocus.GetComponent <NavMeshAgent>().height; Vector3 center = new Vector3(td_characterCard.enemyFocus.position.x, height * 0.5f, td_characterCard.enemyFocus.position.z); Instantiate(hit[Random.Range(0, hit.Length)], center, Quaternion.identity); } else { Vector3 center = new Vector3(td_characterCard.enemyFocus.position.x, 1.5f, td_characterCard.enemyFocus.position.z); Instantiate(hit[Random.Range(0, hit.Length)], center, Quaternion.identity); } if (td_characterCard.enemyFocus.GetComponent <TopDownAI>()) { TopDownAI ai = td_characterCard.enemyFocus.GetComponent <TopDownAI>(); if (ai.voiceSet != null) { if (ai.voiceSet.getHitVoice) { Instantiate(ai.voiceSet.getHitVoice, transform.position, Quaternion.identity); } } } } } } else { if (GetComponent <TopDownAI>()) { //print("This is AI character."); TopDownAI ai = GetComponent <TopDownAI>(); if (ai.focus != null) { DealDamage(ai.focus.gameObject, damagePointsValue); if (TopDownAudioManager.instance != null && TopDownAudioManager.instance.meleeHitAudio != null) { Instantiate(TopDownAudioManager.instance.meleeHitAudio, transform.position, Quaternion.identity); } if (TopDownParticleManager.instance != null && TopDownParticleManager.instance.hitParticle != null) { GameObject[] hit = TopDownParticleManager.instance.hitParticle; float height = ai.focus.GetComponent <NavMeshAgent>().height; Vector3 center = new Vector3(ai.focus.position.x, height * 0.5f, ai.focus.position.z); Instantiate(hit[Random.Range(0, hit.Length)], center, Quaternion.identity); } } } } }