Advertisement
matbiz01

Untitled

Apr 5th, 2023
598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.29 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5.  
  6. enum FieldType {
  7.     Cube,
  8.     Recursive,
  9.     Empty
  10. }
  11.  
  12. class Level {
  13.     int depth;
  14.     int recLimit;
  15.     public static float sideSize = 10.0f;
  16.     Level[,,] lowerLevel = new Level[3,3,3];
  17.     public Level(int depth, int recLimit, FieldType fieldType, Vector3 position){
  18.         Debug.Log(position);
  19.         switch(fieldType){
  20.             case FieldType.Recursive:
  21.                 if(depth < recLimit){
  22.                     float sideLen = sideSize / (float)Math.Pow(3, depth);
  23.                     for(int x = 0; x < 3; x++){
  24.                         for(int y = 0; y < 3; y++){
  25.                             for(int z = 0; z < 3; z++){
  26.                                 if(
  27.                                     (x != 1 || z != 1 || y != 0) &&
  28.                                     (x != 1 || z != 1 || y != 1) &&
  29.                                     (x != 0 || z != 1 || y != 1) &&
  30.                                     (x != 1 || z != 0 || y != 1) &&
  31.                                     (x != 2 || z != 1 || y != 1) &&
  32.                                     (x != 1 || z != 2 || y != 1) &&
  33.                                     (x != 1 || z != 1 || y != 2)
  34.                                 ) {
  35.                                 lowerLevel[x, y, z] = new Level(
  36.                                     depth+1,
  37.                                     recLimit,
  38.                                     FieldType.Recursive,
  39.                                     position + new Vector3(x, y, z) * sideLen
  40.                                 );
  41.                                 }
  42.                             }
  43.                         }
  44.                     }
  45.                     break;
  46.                 }
  47.                 goto case FieldType.Cube;
  48.                
  49.             case FieldType.Cube:
  50.                 GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
  51.                 cube.transform.position = position;
  52.                 cube.transform.localScale = new Vector3(1, 1, 1) * sideSize / (float)Math.Pow(3, depth - 1);
  53.                 break;
  54.         }
  55.     }
  56. }
  57.  
  58. public class SpawnCubes : MonoBehaviour
  59. {
  60.     void Start()
  61.     {
  62.         Level l = new Level(0, 4, FieldType.Recursive, new Vector3(1, 1, 1));
  63.     }
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement