Example #1
0
        public void RemoveObject(BuildableObject buildableObject)
        {
            if (_branches == null)
            {
                for (int i = 0; i < _currentObjectCount; i++)
                {
                    if (_buildableObjects[i] == buildableObject)
                    {
                        _buildableObjects[i] = null;
                        _buildableObjects[i] = _buildableObjects[_currentObjectCount - 1];

                        _currentObjectCount--;

                        break;
                    }
                }
            }
            else
            {
                for (int i = 0; i < 4; i++)
                {
                    _branches[i].RemoveObject(buildableObject);
                }
            }
        }
Example #2
0
        public void AddObject(BuildableObject buildableObject)
        {
            if (_currentObjectCount < MaxObjectsInBranch && _branches == null)
            {
                _buildableObjects[_currentObjectCount] = buildableObject;

                buildableObject.transform.parent = transform;

                _currentObjectCount++;
            }
            else if (_branches != null)
            {
                DivideInSubranch(buildableObject);
            }
            else
            {
                CreateSubBranches();

                foreach (BuildableObject b in _buildableObjects)
                {
                    DivideInSubranch(b);
                }

                _buildableObjects = new BuildableObject[MaxObjectsInBranch];

                DivideInSubranch(buildableObject);
            }
        }
Example #3
0
        private void DivideInSubranch(BuildableObject buildableObject)
        {
            for (int i = 0; i < 4; i++)
            {
                if (_branches[i].Bounds.Contains(buildableObject.transform.position))
                {
                    _branches[i].AddObject(buildableObject);

                    break;
                }
            }
        }
Example #4
0
        void OnGUI()
        {
            for (int i = 0; i < _buildableObjects.Count; i++)
            {
                if (GUI.Button(new Rect(10, i * 25, 100, 20), _buildableObjects[i].name))
                {
                    if (_currentObjectPreview != null)
                    {
                        Destroy(_currentObjectPreview);
                    }

                    _currentObject = _buildableObjects[i].GetComponent<BuildableObject>();
                    _currentObjectPreview = Instantiate(_buildableObjects[i].gameObject, Vector3.zero, Quaternion.identity) as GameObject;
                }
            }
        }
 public void RemoveObject(BuildableObject buildableObject)
 {
     Branch.RemoveObject(buildableObject);
 }
 public void AddObject(BuildableObject buildableObject)
 {
     Branch.AddObject(buildableObject);
 }