Esempio n. 1
0
        public void GenerateQuadTree(string obstructionLayer, int numObjectsPerNode)
        {
            ObstructionLayer  = obstructionLayer;
            numObjectsPerNode = Mathf.Clamp(numObjectsPerNode, 1, int.MaxValue);
            DestroyTree();
            if (AllIndiciesInTree.Length <= 1)
            {
                Debug.LogError("QuadTree: Only one object in quad tree. Need more.");
                return;
            }

            float minX = AllIndiciesInTree.Min(a => a.Position.x) - 0.5f;
            float minY = AllIndiciesInTree.Min(a => a.Position.y) - 0.5f;
            float maxX = AllIndiciesInTree.Max(a => a.Position.x) + 0.5f;
            float maxY = AllIndiciesInTree.Max(a => a.Position.y) + 0.5f;

            NodeIndexQuadTreeNode = ScriptableObject.CreateInstance <NodeIndexQuadTreeNode>();
            NodeIndexQuadTreeNode.Init(new Rect(minX, minY, Mathf.Abs(minX - maxX), Mathf.Abs(minY - maxY)), AllIndiciesInTree, obstructionLayer, numObjectsPerNode);
        }
        public void GenerateQuadTree(string obstructionLayer, int numObjectsPerNode)
        {
            ObstructionLayer = obstructionLayer;
            numObjectsPerNode = Mathf.Clamp(numObjectsPerNode,1, int.MaxValue);
            DestroyTree();
            if(AllIndiciesInTree.Length <= 1)
            {
                Debug.LogError("QuadTree: Only one object in quad tree. Need more.");
                return;
            }

            float minX = AllIndiciesInTree.Min(a => a.Position.x) - 0.5f;
            float minY = AllIndiciesInTree.Min(a => a.Position.y) - 0.5f;
            float maxX = AllIndiciesInTree.Max(a => a.Position.x) + 0.5f;
            float maxY = AllIndiciesInTree.Max(a => a.Position.y) + 0.5f;

            NodeIndexQuadTreeNode = ScriptableObject.CreateInstance<NodeIndexQuadTreeNode>();
            NodeIndexQuadTreeNode.Init(new Rect(minX, minY, Mathf.Abs(minX - maxX), Mathf.Abs(minY - maxY)), AllIndiciesInTree, obstructionLayer,numObjectsPerNode);
        }