TankGroup.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //write by shadow
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. public class TankGroup : MonoBehaviour
  6. {
  7. public static List<TankGroup> tankGroups;//所有组
  8. public LayerMask mask;//成员层
  9. public int groupID = 0;//组id
  10. public float keepDistance = 10, keepWeight = 1;//成员保持距离和保持距离权重
  11. public float targetCloseDistance = 20, targetWeight = 1.25f, moveWeight = 0.8f;//距离目标距离,距离目标权重和成员移动权重
  12. //~ public Color color=Color.green;
  13. private void Awake()
  14. {
  15. // tankGroups.Add(this.gameObject.GetComponent<TankGroup>());
  16. //tankGroups = new List<TankGroup>(Object.FindObjectsOfType(typeof(TankGroup)) as TankGroup[]);
  17. AddGroup(this.gameObject.GetComponent<TankGroup>());
  18. }
  19. public Vector3 targetPosition
  20. {
  21. //位置
  22. get { return transform.position; }
  23. }
  24. public static void AddGroup(TankGroup group)
  25. {
  26. if (tankGroups == null)
  27. tankGroups = new List<TankGroup>();
  28. if (!tankGroups.Contains(group))
  29. tankGroups.Add(group);
  30. }
  31. public static TankGroup GetTankGroup(int index)
  32. {
  33. tankGroups = new List<TankGroup>(Object.FindObjectsOfType(typeof(TankGroup)) as TankGroup[]);
  34. for (int i = 0; i < tankGroups.Count; i++)
  35. if (tankGroups[i].groupID == index)
  36. return tankGroups[i];
  37. throw new System.Exception("groupID not find");
  38. }
  39. private void OnDisable()
  40. {
  41. tankGroups.Clear();
  42. }
  43. //~ void OnDrawGizmos(){
  44. //~ Gizmos.color=color;
  45. //~ Gizmos.DrawSphere(targetPosition,1);
  46. //~ }
  47. }