示例#1
0
        private void Awake()
        {
            if (_instance != null && _instance != this)
            {
                Destroy(gameObject);
                return;
            }
            _instance = this;

            brushLookup = new Dictionary <string, VoxelPaintBrush>();
            foreach (var entry in brushes)
            {
                brushLookup[entry.key] = entry.brush;
            }
        }
示例#2
0
        private void Paint(Ray ray)
        {
            RaycastHit hitInfo;

            if (Physics.Raycast(ray, out hitInfo) && hitInfo.transform.CompareTag("Voxel"))
            {
                var collidedTrunk = hitInfo.transform.GetComponent <VoxelTrunk>();
                var pos           = hitInfo.point;
                var brush         = VoxelBrushLibrary.GetBrush(brushKey);
                collidedTrunk.GetNearbyTrunksAtPos(pos, Vector3.one * brush.radius, affectedTrunkList);
                foreach (var trunk in affectedTrunkList)
                {
                    brush.Apply(trunk, pos);
                }
                foreach (var trunk in affectedTrunkList)
                {
                    trunk.Triangulate();
                }
            }
        }