//碰撞框测试 //private List<GameObject> m_lstObject = new List<GameObject>(); public void Update(TSVector curPosition, TSVector curForward) { //if (m_lstObject.Count < m_lstColliders.Count) //{ // for (int i = 0; i < m_lstColliders.Count; i++) // { // if (m_lstColliders[i] is C2D_Rect) // { // GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube); // RectColliderData data = (RectColliderData)m_cColliderItem.mLstData[i]; // go.transform.localScale = new Vector3(data.halfWidth.AsFloat() * 2f, 1, data.halfHeight.AsFloat() * 2f); // go.name = "RectCollider"; // m_lstObject.Add(go); // } // else if (m_lstColliders[i] is C2D_Circle) // { // GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere); // CircleColliderData data = (CircleColliderData)m_cColliderItem.mLstData[i]; // go.transform.localScale = new Vector3(data.radius.AsFloat() * 2f, data.radius.AsFloat() * 2f, data.radius.AsFloat() * 2f); // go.name = "CircleCollider"; // m_lstObject.Add(go); // } // } //} for (int i = 0; i < m_lstColliders.Count; i++) { var collider = m_lstColliders[i]; BaseGameColliderData colliderData = m_cColliderItem.mLstData[i]; UpdateCollider2(collider, curPosition, curForward, colliderData); //m_lstObject[i].transform.position = new Vector3(collider.center.x.AsFloat(), 0, collider.center.y.AsFloat()); //m_lstObject[i].transform.forward = new Vector3(collider.forward.x.AsFloat(), 0, collider.forward.y.AsFloat()); } Reculate(); }
private Check2DCollider Create2DCollider(BaseGameColliderData data) { Check2DCollider collider = null; if (data.gameColliderType == GameColliderType.RectCollider) { C2D_Rect rect = ObjectPool <C2D_Rect> .Instance.GetObject(); RectColliderData rectData = (RectColliderData)data; rect.halfWidth = rectData.halfWidth; rect.halfHeight = rectData.halfHeight; collider = rect; } else if (data.gameColliderType == GameColliderType.CircleCollider) { C2D_Circle circle = ObjectPool <C2D_Circle> .Instance.GetObject(); CircleColliderData circleData = (CircleColliderData)data; circle.radius = circleData.radius; collider = circle; } return(collider); }
private void UpdateCollider2(Check2DCollider collider, TSVector curPosition, TSVector curForward, BaseGameColliderData colliderData) { FP nAngle = TSVector.Angle(TSVector.forward, curForward); if (curForward.x < 0) { nAngle = 360 - nAngle; } TSQuaternion sQuat = TSQuaternion.AngleAxis(nAngle, TSVector.up); TSVector center = curPosition + sQuat * colliderData.center; TSVector forward = sQuat * colliderData.forward; collider.center = new TSVector2(center.x, center.z); collider.forward = new TSVector2(forward.x, forward.z); }