Advertisement
Guest User

asdfasdf

a guest
Oct 19th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.47 KB | None | 0 0
  1. public class DamageEffect : EffectBase {
  2.  
  3. public int dano;
  4. // Use this for initialization
  5. protected override void Effect(){
  6. targetBase.target.TomaDano (dano);
  7. }
  8. }
  9. ---
  10.  
  11. public abstract class EffectBase : MonoBehaviour {
  12.  
  13. protected Personagem dono;
  14. protected Skill skill;
  15. protected TargetBase targetBase;
  16.  
  17.  
  18. void Start(){
  19. skill = GetComponent<Skill> ();
  20. dono = skill.dono;
  21. targetBase = GetComponent<TargetBase> ();
  22. targetBase.onFindTargetDo.Add (Effect);
  23. }
  24.  
  25. protected virtual void Effect(){
  26.  
  27. }
  28.  
  29. }
  30.  
  31. ---
  32.  
  33. public class HealEffect : EffectBase {
  34.  
  35. public int cura;
  36. // Use this for initialization
  37. protected override void Effect(){
  38. if (targetBase.target != null) {
  39. targetBase.target.TomaHeal (cura);
  40. }
  41. }
  42. }
  43.  
  44. ---
  45.  
  46. public class InputController : MonoBehaviour {
  47.  
  48. float horizontalAxis;
  49. public float rotateSpeed;
  50.  
  51. float verticalAxis;
  52. public float moveSpeed;
  53.  
  54. public Transform player;
  55. Personagem personagem;
  56.  
  57. bool isShiftDown;
  58. // Use this for initialization
  59. void Start () {
  60. personagem = player.GetComponent<Personagem> ();
  61. }
  62.  
  63. // Update is called once per frame
  64. void Update () {
  65. if (Input.GetKey (KeyCode.LeftShift)) {
  66. isShiftDown = true;
  67. } else {
  68. isShiftDown = false;
  69. }
  70.  
  71. if (Input.GetKeyDown (KeyCode.Space) && isShiftDown) {
  72. Debug.Log ("Combo shift+space");
  73. }else if (Input.GetKeyDown (KeyCode.Space)) {
  74. Debug.Log ("Apertou espaço");
  75. personagem.skillBar [0].testeFire = true;
  76. }
  77.  
  78. horizontalAxis = Input.GetAxis ("Horizontal");
  79. player.Rotate (0, horizontalAxis*rotateSpeed*Time.deltaTime, 0);
  80.  
  81. verticalAxis = Input.GetAxis ("Vertical");
  82. player.Translate (new Vector3 (0, 0, moveSpeed * verticalAxis * Time.deltaTime));
  83.  
  84. }
  85. }
  86. ---
  87. public class Personagem : MonoBehaviour {
  88.  
  89. public int armor;
  90. public int vida;
  91. public List<Skill> skillBar;
  92.  
  93. public void TomaDano(int dano){
  94. if ((dano - armor) < 0)
  95. dano = 0;
  96. vida -= dano;
  97. Debug.Log ("Eu, " + transform + " tomei " + dano + " e fiquei com " +
  98. vida + " de vida");
  99. }
  100.  
  101. public void TomaHeal(int heal){
  102. vida += heal;
  103. }
  104. }
  105.  
  106. ---
  107. public class Skill : MonoBehaviour {
  108.  
  109. public List<OnSkillDo> onSkillDo;
  110. public bool testeFire;
  111.  
  112. public Personagem dono;
  113.  
  114. public float cooldown;
  115. public float cooldownTimer;
  116. float tickTime = 0.5f;
  117.  
  118. // Use this for initialization
  119.  
  120. void Awake(){
  121. dono = GetComponentInParent<Personagem> ();
  122. onSkillDo = new List<OnSkillDo> ();
  123. onSkillDo.Add (CooldownCounter);
  124. }
  125.  
  126. void CooldownCounter(){
  127. cooldownTimer = cooldown;
  128. StartCoroutine (CooldownCoroutine ());
  129. }
  130.  
  131. IEnumerator CooldownCoroutine(){
  132. while(cooldownTimer>0){
  133. yield return new WaitForSeconds(tickTime);
  134. cooldownTimer-=tickTime;
  135. }
  136. }
  137.  
  138. // Update is called once per frame
  139. void Update () {
  140. if (testeFire) {
  141. testeFire = false;
  142. if(cooldownTimer<=0)
  143. UsaSkill ();
  144. }
  145. }
  146.  
  147. void UsaSkill(){
  148. Debug.Log ("usou o skill");
  149. for (int i = 0; i < onSkillDo.Count; i++) {
  150. onSkillDo [i] ();
  151. }
  152. //target = null;
  153. }
  154.  
  155.  
  156. }
  157. ---
  158. public class ProjectileBehaviour : MonoBehaviour {
  159.  
  160. public float moveSpeed;
  161. public float duration;
  162. public float durationHitPenalty;
  163.  
  164. public TargetProjectile targetProjectile;
  165. // Use this for initialization
  166. void Start () {
  167. }
  168.  
  169. void DestroyProjectile(){
  170. Destroy (this.gameObject);
  171. }
  172. // Update is called once per frame
  173. void Update () {
  174. transform.Translate (0, 0, moveSpeed * Time.deltaTime);
  175. duration -= Time.deltaTime;
  176. if (duration <= 0)
  177. DestroyProjectile ();
  178. }
  179.  
  180. void OnTriggerEnter(Collider coll){
  181. if (coll.GetComponent<Personagem> ()) {
  182. Debug.Log ("Acertou " + coll);
  183. targetProjectile.OnHit(coll.GetComponent<Personagem>());
  184. duration -= durationHitPenalty;
  185. }
  186. }
  187. }
  188. ---
  189. public class SkillSoundFX : MonoBehaviour {
  190.  
  191. public AudioClip soundfx;
  192. public float duration;
  193. public float fadeSpeed;
  194. Skill skill;
  195. AudioSource source;
  196.  
  197. void Start(){
  198. skill = GetComponent<Skill> ();
  199. skill.onSkillDo.Add (PlaySoundFX);
  200. source = transform.parent.GetComponent<AudioSource> ();
  201. }
  202.  
  203. void PlaySoundFX(){
  204. source.clip = soundfx;
  205. source.pitch = RandomizePitch ();
  206. source.Play ();
  207. Invoke ("EndSound", duration);
  208. }
  209.  
  210. float RandomizePitch(){
  211. float pitch;
  212. pitch = Random.Range (0, 3f);
  213. return pitch;
  214. }
  215.  
  216. void EndSound(){
  217. //source.Stop ();
  218. StartCoroutine(Fade());
  219. }
  220.  
  221. IEnumerator Fade(){
  222.  
  223. float tempVolume = source.volume;
  224. while (source.volume>=0.1) {
  225. source.volume -= fadeSpeed;
  226. yield return null;
  227. }
  228. source.volume = tempVolume;
  229. source.Stop ();
  230. }
  231.  
  232. }
  233.  
  234. ---
  235. public class SkillVisualFX : MonoBehaviour {
  236.  
  237. public Transform particleHolder;
  238. List<ParticleSystem> particleSystems;
  239. Skill skill;
  240. // Use this for initialization
  241. void Start () {
  242. skill = GetComponent<Skill> ();
  243. skill.onSkillDo.Add (PlayFX);
  244. particleSystems = new List<ParticleSystem> ();
  245. particleSystems.AddRange(particleHolder.GetComponentsInChildren<ParticleSystem> ());
  246. }
  247.  
  248. void PlayFX(){
  249. for(int i=0; i<particleSystems.Count; i++){
  250. particleSystems [i].Play ();
  251. }
  252. }
  253.  
  254.  
  255. }
  256.  
  257.  
  258. ---
  259.  
  260. public abstract class TargetBase : MonoBehaviour {
  261.  
  262. protected Personagem dono;
  263. public Personagem target;
  264. protected Skill skill;
  265. public List<OnFindTargetDo> onFindTargetDo;
  266.  
  267.  
  268. void Awake(){
  269. onFindTargetDo = new List<OnFindTargetDo> ();
  270. dono = this.transform.GetComponent<Personagem> ();
  271. skill = GetComponent<Skill> ();
  272. }
  273.  
  274. void Start(){
  275. skill.onSkillDo.Add (FindTarget);
  276. }
  277.  
  278. protected virtual void FindTarget(){
  279. Debug.Log ("setou target");
  280. target = dono;
  281. ExecuteOnFindTarget ();
  282. }
  283.  
  284. protected void ExecuteOnFindTarget(){
  285. for (int i = 0; i < onFindTargetDo.Count; i++) {
  286. onFindTargetDo [i] ();
  287. }
  288. }
  289. }
  290.  
  291. ---
  292.  
  293. public class TargetManual : TargetBase {
  294.  
  295. public Personagem manualTarget;
  296.  
  297. protected override void FindTarget ()
  298. {
  299. Debug.Log ("setou target2");
  300. ExecuteOnFindTarget ();
  301. }
  302. }
  303.  
  304.  
  305. --
  306.  
  307. public class TargetProjectile : TargetBase {
  308.  
  309. public GameObject projectile;
  310. GameObject flyingProjectile;
  311. ProjectileBehaviour pb;
  312. Personagem wasHit;
  313.  
  314. // Use this for initialization
  315. void Start () {
  316. flyingProjectile = GameObject.Instantiate (projectile);
  317. pb = flyingProjectile.GetComponent<ProjectileBehaviour> ();
  318. pb.targetProjectile = this;
  319. }
  320.  
  321. public void OnHit(Personagem hit){
  322. wasHit = hit;
  323. FindTarget ();
  324. }
  325.  
  326. protected override void FindTarget ()
  327. {
  328. target = wasHit;
  329. }
  330.  
  331.  
  332. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement