示例#1
0
    internal List <GameObjectsPair> CheckForPossibleCollisions()
    {
        List <GameObjectsPair> result     = new List <GameObjectsPair>();
        List <SearchNode>      searchList = new List <SearchNode>();

        foreach (GameObject gameObject in gameObjects)
        {
            CustomCollider collider = gameObject.GetComponent <CustomCollider>();
            searchList.Add(new SearchNode(collider.GetMinXYZ((int)SEARCH_AXIS), collider.GetMaxXYZ((int)SEARCH_AXIS), gameObject));
        }
        searchList = searchList.OrderBy(o => o.startValue).ToList();
        for (int i = 0; i < searchList.Count; i++)
        {
            SearchNode searchNodeI = searchList[i];
            for (int j = i + 1; j < searchList.Count; j++)
            {
                SearchNode searchNodeJ = searchList[j];
                if (IsOverlapping(searchNodeI.startValue, searchNodeI.endValue, searchNodeJ.startValue, searchNodeJ.endValue))
                {
                    result.Add(new GameObjectsPair
                    {
                        gameObject1 = searchNodeI.attachedGameobject,
                        gameObject2 = searchNodeJ.attachedGameobject
                    });
                }
            }
        }
        return(result);
    }