public void AddCollistionData(NetData other) { if (!collisonDatas.Contains(other)) { collisonDatas.Add(other); } }
/// <summary> /// 向子节点添加对象 /// </summary> /// <param name="obj">添加的对象</param> public void Add(NetData obj) { for (int i = 0; i < 4; i++) { trees[i].Add(obj); } }
public static void Move(NetData obj) { Tree4[] trees = obj.trees.ToArray(); foreach (var item in trees) { item.SubMove(obj); } }
public static void SetActive(NetData obj) { foreach (var item in obj.trees) { item.collisonInfo.active = true; activeTreeList.Add(item); } }
public static GameObject Instantiate <T>(NetData data) where T : NetData, new() { GameObject obj = GameObject.Instantiate(GetPrefab(data), data.transform.Position.ToVector3(), data.transform.Rotation.ToUnityRotation()); obj.GetComponent <NetObjectView <T> >().data = data; data.view = obj.GetComponent <NetObjectView <T> >(); return(obj); }
public static void Remove(NetData obj) { Tree4[] trees = obj.trees.ToArray(); foreach (var item in trees) { item.DisLink(obj); } }
/// <summary> /// 添加对象 /// </summary> /// <param name="obj">游戏对象</param> public void Add(NetData obj) { shaps.Add(obj); if (!tree.Add(obj)) { UnityEngine.Debug.LogWarning("四叉树添加物体失败" + obj.name); } }
public void SubMove(NetData obj) { if (!IsIn(obj.Shap)) { DisLink(obj); } brother.Add(obj); //root.Add(obj); }
/// <summary> /// 向邻居节点添加对象 /// </summary> /// <param name="obj">移动的对象</param> public void Add(NetData obj) { for (int i = 0; i < 4; i++) { if (brothers[i] != null) { brothers[i].Add(obj); } } }
public GameObject GetPrefab(NetData data) { var prefab = Resources.Load(data.PrefabPath()) as GameObject; if (prefab == null) { Debug.LogError("{" + data.PrefabPath() + "}is Null"); } return(prefab); }
public bool IsIn(NetData obj) { if (((border.center.x - obj.transform.Position.x).Abs() <= (border.size + obj.Width / 2)) && ((border.center.y - obj.transform.Position.y).Abs() <= (border.size + obj.Height / 2)) ) { return(true); } return(false); }
public static bool BoxCheck(NetData objA, NetData objB) { if (FixedNumber.Abs((objA.transform.Position.x - objB.transform.Position.x)) < (objA.Width + objB.Width) / 2 && FixedNumber.Abs((objA.transform.Position.y - objB.transform.Position.y)) < (objA.Height + objB.Height) / 2 ) { return(true); } return(false); }
private void DisLink(NetData obj) { if (objs.Contains(obj)) { objs.Remove(obj); } if (obj.trees.Contains(this)) { obj.trees.Remove(this); } }
public bool CheckCollision(NetData a) { foreach (var item in collisonDatas) { if (!item.isTrigger) { return(true); } } return(false); }
public GameObject Instantiate(NetData data) { GameObject obj = GameObject.Instantiate(GetPrefab(data), data.transform.Position.ToVector3(), data.transform.Rotation.ToUnityRotation()); obj.transform.parent = (client.unityClient as MonoBehaviour).gameObject.transform; obj.transform.localScale = data.transform.Scale.ToVector3(1); var view = obj.GetComponent <View>(); view.netData = data; data.view = view; return(obj); }
/// <summary> /// 向子节点添加对象 /// </summary> /// <param name="obj">添加的对象</param> public bool Add(NetData obj) { bool flag = false; for (int i = 0; i < 4; i++) { if (trees[i].Add(obj)) { flag = true; } } return(flag); }
public void SetActive(NetData obj) { foreach (var item in obj.trees) { item.collisonInfo.active = true; if (!activeTreeList.Contains(item)) { activeTreeList.Add(item); } else { // Debug.LogError("多余的激活树"); } } }
public void Add(NetData obj) { if (!IsIn(obj)) { return; } if (objs.Contains(obj)) { return; } if (child == null) { Link(obj); if (objs.Count > SplitSize && depth <= MaxDepth) { Split(); } } else { child.Add(obj); } }
public bool Add(NetData obj) { if (!IsIn(obj.Shap)) { return(false); } if (objs.Contains(obj)) { return(true); } if (child == null) { Link(obj); if (objs.Count > SplitSize && depth <= MaxDepth) { Split(); } return(true); } else { return(child.Add(obj)); } }
/// <summary> /// 添加对象 /// </summary> /// <param name="obj">游戏对象</param> public void Add(NetData obj) { shaps.Add(obj); tree.Add(obj); }
/// <summary> /// 移除对象 /// </summary> /// <param name="obj">游戏对象</param> public void Remove(NetData obj) { shaps.Remove(obj); Tree4.Remove(obj); }
public void Init(NetData data) { this.data = data; }
//GJK算法原理 //两个物体进行明可夫斯基差操作 得到的新图形形状包含原点则这两个图形的是相交的 /// <summary> /// 立即检测两个物体是否发生细节碰撞 /// 先包围盒检测(粗略) 后GJK碰撞检测(细节) /// </summary> /// <param name="a">检测对象a</param> /// <param name="b">检测对象b</param> /// <returns>是否碰撞</returns> public static bool Check(NetData a, NetData b) { return(Tree4.BoxCheck(a, b) && GJKCheck(a.Shap, b.Shap));//;// xB&&yB; }
public virtual void OnPhysicsCheckExit(NetData other) { // UnityEngine.Debug.Log("Exit触发"); }
public virtual void OnPhysicsCheckEnter(NetData other) { }
public virtual void OnPhysicsCheckStay(NetData other) { // UnityEngine.Debug.Log("Stay触发"); }
public void InitNetData(NetData data) { this.netData = data; Init(); }
public static GameObject GetPrefab(NetData data) { return(Resources.Load(data.PrefabPath()) as GameObject); }
private void Link(NetData obj) { objs.Add(obj); obj.trees.Add(this); }