Exemple #1
0
    public void SceneReferences()
    {
        BuilderInWorldController builderInWorldController = Resources.FindObjectsOfTypeAll <BuilderInWorldController>()[0];

        Assert.IsNotNull(builderInWorldController.avatarRenderer, "References on the builder-in-world prefab are null, check them all!");
        Assert.IsNotNull(builderInWorldController.cursorGO, "References on the builder-in-world prefab are null, check them all!");
        Assert.IsNotNull(builderInWorldController.inputController, "References on the builder-in-world prefab are null, check them all!");
        Assert.IsNotNull(builderInWorldController.cameraParentGO, "References on the builder-in-world prefab are null, check them all!");


        BuilderInWorldGodMode godMode = builderInWorldController.GetComponentInChildren <BuilderInWorldGodMode>();


        Assert.IsNotNull(godMode.mouseCatcher, "References on the builder-in-world god mode are null, check them all!");
        Assert.IsNotNull(godMode.cameraController, "References on the builder-in-world god mode are null, check them all!");
        Assert.IsNotNull(godMode.freeCameraController, "References on the builder-in-world god mode are null, check them all!");

        DCLBuilderRaycast dCLBuilderRaycast = godMode.GetComponentInChildren <DCLBuilderRaycast>();

        Assert.IsNotNull(dCLBuilderRaycast.builderCamera, "Camera reference on the builder-in-world god mode children are null, check them all!");

        VoxelController voxelController = godMode.GetComponent <VoxelController>();

        Assert.IsNotNull(voxelController.freeCameraMovement, "Camera reference on the builder-in-world voxel controller are null, check them all!");
    }
    public void Load()
    {
        for (int x = xMin; x < xMax; x++)
        {
            cursorMatrix.Add(new List <Cursor>());
            for (int z = zMin; z < zMax; z++)
            {
                int        elevation    = VoxelController.GetElevation(x, z);
                GameObject cursorObject = Instantiate(cursorPrefab, new Vector3(0, 0, 0), Quaternion.identity);
                cursorObject.transform.parent = GameObject.Find("Cursors").transform;
                Cursor cursor = cursorObject.GetComponent <Cursor>();
                cursor.originalColor = Color.gray;
                cursor.xPos          = x;
                cursor.zPos          = z;
                cursor.yPos          = elevation;
                if (elevation < 0)
                {
                    cursor.useable = false;
                }
                cursorMatrix[x].Add(cursor);
            }
        }

        StartCoroutine(SetLoaded());
    }
Exemple #3
0
    // Use this for initialization
    void Start()
    {
        instance  = this;
        _grid     = GameObject.Find("Grid").GetComponent <RectGrid>();
        _renderer = _grid.gameObject.GetComponent <Parallelepiped>();
        xMin      = 0;  //(int)_renderer.From[0];
        xMax      = 20; //(int)_renderer.To[0];
        zMin      = 0;  //(int)_renderer.From[2];
        zMax      = 20; //(int)_renderer.To[2];

        for (int x = xMin; x < xMax; x++)
        {
            for (int z = zMin; z < zMax; z++)
            {
                int        elevationMax = mapTopography[x][z];
                Coordinate coordinate   = new Coordinate();
                coordinate.x             = x;
                coordinate.z             = z;
                coordinate.y             = elevationMax - 1;
                coordinate.respawnMarker = respawnMarkerList.Exists(r => r[0] == x && r[1] == z);
                syncCoordinates.Add(coordinate);
            }
        }

        CacheMatrix();

        RenderVoxels();

        CursorController.instance.Load();
    }
Exemple #4
0
    private IEnumerator SpawnTreasure()
    {
        print("spawning treasure");
        GameController.treasureCount++;
        int x = Random.Range(0, 19);
        int z = Random.Range(0, 19);

        while (!Helpers.GetTile(x, z).CanHaveTreasure())
        {
            x = Random.Range(0, 19);
            z = Random.Range(0, 19);
        }

        int y = VoxelController.GetElevation(x, z);

        GameObject treasure = Instantiate(Resources.Load("Treasure"), Vector3.zero, Quaternion.identity) as GameObject;
        Cursor     cursor   = Helpers.GetTile(x, z);

        cursor.standingTreasure = treasure.GetComponent <Treasure>();
        print(treasure.GetComponent <Treasure>());
        treasure.GetComponent <Treasure>().cursor = cursor;

        Helpers.SetTransformPosition(treasure.transform, x, y, z);
        MainCamera.Lock();
        MainCamera.CenterOnWorldPoint(treasure.transform.position);
        yield return(new WaitForSeconds(3f));

        MainCamera.Unlock();
        instance.ContinueNextTurn();
    }
    public void SpawnVoxels(VoxelizationInfo info)
    {
        List <VoxelizationServer.AABCGrid> aABCGrids = info.aABCGrids;

        //int total = 0;
        if (aABCGrids != null)
        {
            foreach (VoxelizationServer.AABCGrid aABCGrid in aABCGrids)
            {
                Vector3 preCalc = aABCGrid.GetOrigin();
                for (short x = 0; x < aABCGrid.GetWidth(); ++x)
                {
                    for (short y = 0; y < aABCGrid.GetHeight(); ++y)
                    {
                        for (short z = 0; z < aABCGrid.GetDepth(); ++z)
                        {
                            if (aABCGrid.IsAABCActiveUnsafe(x, y, z))
                            {
                                Vector3 cubeCenter = aABCGrid.GetAABCCenterUnsafe(x, y, z) + preCalc;

                                voxelController = voxelPool.GetObject();
                                if (voxelController != null)
                                {
                                    //++total;
                                    Transform voxelTrans = voxelController.gameObject.transform;
                                    voxelTrans.position = cubeCenter;
                                    voxelTrans.rotation = Quaternion.identity;
                                    //voxelTrans.rotation = Random.rotation;
                                    voxelTrans.localScale = info.voxelScale;
                                    if (!info.randomMaterial)
                                    {
                                        voxelController.GetComponent <Renderer>().sharedMaterial = info.mat;
                                    }
                                    else
                                    {
                                        voxelController.GetComponent <Renderer>().sharedMaterial = colorObjMng.GetVoxelRandomMaterial();
                                    }

                                    voxelController.spawnLevels = 1;
                                }
                            }
                        }
                    }
                }

                //Set a collider in place to make voxels "explode"
                if (info.spawnCollider)
                {
                    GameObject voxelCollider = voxelColliderPool.GetObject();
                    if (voxelCollider != null)
                    {
                        voxelCollider.transform.localScale = info.voxelColliderScale;
                        voxelCollider.transform.position   = aABCGrid.GetCenter();
                    }
                }
            }
        }
        //Debug.Log("Spider spawned: " + total);
    }
Exemple #6
0
    private static bool CanMoveToNextTile(Cursor target, Cursor origin, int allowance)
    {
        int targetElevation = VoxelController.GetElevation(target.xPos, target.zPos);
        int originElevation = VoxelController.GetElevation(origin.xPos, origin.zPos);
        int diff            = Mathf.Abs(targetElevation - originElevation);

        return(diff <= allowance);
    }
Exemple #7
0
    public VoxelController GetVoxel(ChromaColor color)
    {
        //Get a voxel from pool
        VoxelController voxel = voxelPool.GetObject();

        if (voxel != null)
        {
            voxel.GetComponent <Renderer>().sharedMaterial = GetMaterial(voxelMats, color);
        }

        return(voxel);
    }
Exemple #8
0
    //Voxel methods
    public VoxelController GetVoxel()
    {
        //Get a voxel from pool
        VoxelController voxel = voxelPool.GetObject();

        if (voxel != null)
        {
            voxel.GetComponent <Renderer>().sharedMaterial = currentVoxelMat;
        }

        return(voxel);
    }
Exemple #9
0
 public void Apply(VoxelController voxelController)
 {
     switch (_type) {
     case Type.Add:
             voxelController.AddVoxel(_voxel);
         break;
     case Type.Remove:
             voxelController.RemoveVoxel(_pos);
         break;
     default:
         throw new UnityException();
     }
 }
Exemple #10
0
    public void Apply(VoxelController voxelController)
    {
        switch (_type)
        {
        case Type.Add:
            voxelController.AddVoxel(_voxel);
            break;

        case Type.Remove:
            voxelController.RemoveVoxel(_pos);
            break;

        default:
            throw new UnityException();
        }
    }
Exemple #11
0
 // Use this for initialization
 void Start()
 {
     _voxelController = FindObjectOfType <VoxelController>();
     _saveButton.onClick.AddListener(() =>
     {
         try
         {
             print("Button clicked!");
             _voxelController.SaveToFile(_filepathInputField.text);
         }
         catch (Exception e)
         {
             // TODO: print error to user
             Debug.Log("Could not save to '" + _filepathInputField.text + "' due to " + e.ToString());
         }
     });
 }
Exemple #12
0
 // Use this for initialization
 void Start()
 {
     _voxelController = FindObjectOfType<VoxelController>();
     _saveButton.onClick.AddListener(() =>
     {
         try
         {
             print("Button clicked!");
             _voxelController.SaveToFile(_filepathInputField.text);
         }
         catch (Exception e)
         {
             // TODO: print error to user
             Debug.Log("Could not save to '" + _filepathInputField.text + "' due to " + e.ToString());
         }
     });
 }
Exemple #13
0
    private void Start()
    {
        ChunksController = new ChunksController();
        VoxelController  = new VoxelController();

        WorldData = SaveSystem.LoadWorld("test_world");

        Vector3 spawnPosition = new Vector3(
            Settings.Get.WorldCentre,
            //Settings.Get.ChunkHeight / 2 - 50,
            TerrainAttributes.solidGroundHeight + 10,
            Settings.Get.WorldCentre);

        Player.transform.position = spawnPosition;
        playerLastCoord           = CoordConvertor.GetChunkCoord(Player.transform.position);

        LoadWorld();

        GenerateWorld();
    }
Exemple #14
0
    public static List <int[]> DeriveShortestPath(int xPos, int zPos, int originX, int originZ, Unit requestor)
    {
        List <int[]> queue        = new List <int[]>();
        List <int[]> shortestPath = new List <int[]>();

        queue.Add(new int[] { xPos, zPos, 0, VoxelController.GetElevation(xPos, zPos) });
        for (int i = 0; i < queue.Count; i++)
        {
            int[] entry   = queue[i];
            int   counter = entry[2] + 1;

            List <Cursor> neighbors = Helpers.Neighbors(entry[0], entry[1]);

            List <int[]> newCells = new List <int[]>();

            foreach (Cursor cursor in neighbors)
            {
                if (!cursor.standingUnit || cursor.standingUnit == requestor)
                {
                    int  elevation = VoxelController.GetElevation(cursor.xPos, cursor.zPos);
                    bool movable   = elevation >= 0 && Helpers.CanMoveToNextTile(cursor, Helpers.GetTile(entry[0], entry[1]), requestor.JumpHeight());

                    if (movable)
                    {
                        newCells.Add(new int[] { cursor.xPos, cursor.zPos, counter, elevation });
                    }
                }
            }

            bool reachedDestination = false;

            for (int a = 0; a < newCells.Count; a++)
            {
                if (newCells[a][0] == originX && newCells[a][1] == originZ)
                {
                    reachedDestination = true;
                    break;
                }
            }

            for (int a = newCells.Count - 1; a >= 0; a--)
            {
                for (int g = 0; g < queue.Count; g++)
                {
                    if (newCells[a][0] == queue[g][0] &&
                        newCells[a][1] == queue[g][1] &&
                        newCells[a][2] >= queue[g][2])
                    {
                        newCells.RemoveAt(a);
                        break;
                    }
                }
            }

            for (int a = 0; a < newCells.Count; a++)
            {
                queue.Add(newCells[a]);
            }

            if (reachedDestination)
            {
                queue.Reverse();
                int firstIndex = queue.FindIndex(r => (r[0] == originX && r[1] == originZ));
                shortestPath.Add(queue[firstIndex]);

                int[] previousElement = queue[firstIndex];

                for (int b = firstIndex; b < queue.Count; b++)
                {
                    int[] currentElement = queue[b];

                    if (
                        (
                            (
                                currentElement[0] == previousElement[0] - 1 &&
                                currentElement[1] == previousElement[1]
                            ) ||
                            (
                                currentElement[0] == previousElement[0] + 1 &&
                                currentElement[1] == previousElement[1]
                            ) ||
                            (
                                currentElement[0] == previousElement[0] &&
                                currentElement[1] == previousElement[1] + 1
                            ) ||
                            (
                                currentElement[0] == previousElement[0] &&
                                currentElement[1] == previousElement[1] - 1
                            )
                        ) && currentElement[2] == previousElement[2] - 1
                        )
                    {
                        shortestPath.Add(currentElement);
                        previousElement = currentElement;
                    }
                }

                break;
            }
        }

        return(shortestPath);
    }
Exemple #15
0
 private void Awake()
 {
     _voxelController = GameObject.FindObjectOfType<VoxelController>();
 }
Exemple #16
0
    private void PickNext()
    {
        if (_canWalkPath)
        {
            Vector3 direction;

            if (_pathIndex >= _path.Count)
            {
                return;
            }

            CursorController.Coordinate nextStep = _path[_pathIndex];

            _pathIndex++;
            if (_pathIndex >= _path.Count)
            {
                _resetPath   = true;
                _canWalkPath = false;
                _pathIndex   = 0;
            }

            int newY = nextStep.elevation - _unit.yPos;
            _jumpHeight = nextStep.elevation - _unit.yPos;
            _unit.yPos  = _unit.yPos + newY;

            if (nextStep.x > _currentxPos)
            {
                print("going x");
                direction = new Vector3(1, newY, 0);
                _currentxPos++;
            }
            else if (nextStep.x < _currentxPos)
            {
                direction = new Vector3(-1, newY, 0);
                _currentxPos--;
            }
            else if (nextStep.z > _currentzPos)
            {
                direction = new Vector3(0, newY, 1);
                _currentzPos++;
            }
            else if (nextStep.z < _currentzPos)
            {
                direction = new Vector3(0, newY, -1);
                _currentzPos--;
            }
            else
            {
                print("return case");
                return;
            }

            _unit.lookDirection = new Vector3(direction.x, 0, direction.z);

            _goal = VoxelController.Grid().WorldToGrid(transform.position) + direction;

            _goal     = VoxelController.Grid().GridToWorld(_goal);
            _isMoving = true;

            if (newY > 0)
            {
                _isMovingUp = true;
            }
            if (newY < 0)
            {
                _isMovingDown = true;
            }
        }
    }
    public void SpawnVoxels()
    {
        //int total = 0;
        if (aABCGrids != null)
        {
            foreach (VoxelizationServer.AABCGrid aABCGrid in aABCGrids)
            {
                Vector3 preCalc = aABCGrid.GetOrigin();
                for (short x = 0; x < aABCGrid.GetWidth(); ++x)
                {
                    for (short y = 0; y < aABCGrid.GetHeight(); ++y)
                    {
                        for (short z = 0; z < aABCGrid.GetDepth(); ++z)
                        {
                            if (aABCGrid.IsAABCActiveUnsafe(x, y, z))
                            {
                                Vector3 cubeCenter = aABCGrid.GetAABCCenterUnsafe(x, y, z) + preCalc;
                                /*voxel = voxelPool.GetObject();
                                if (voxel != null)
                                {
                                    voxel.transform.position = cubeCenter;
                                    voxel.transform.rotation = Quaternion.identity;
                                    voxel.GetComponent<Renderer>().material = mat;
                                    voxel.SetActive(true);
                                }*/
                                //++total;
                                voxelController = voxelPool.GetObject();
                                if(voxelController != null)
                                {
                                    Transform voxelTrans = voxelController.gameObject.transform;
                                    voxelTrans.position = cubeCenter;
                                    //voxelTrans.rotation = Quaternion.identity;
                                    voxelTrans.rotation = Random.rotation;
                                    voxelTrans.localScale = voxelScale;
                                    if(!randomMaterial)
                                    {
                                        voxelController.GetComponent<Renderer>().material = mat;
                                    }
                                    else
                                    {
                                        voxelController.GetComponent<Renderer>().material = colorObjMng.GetVoxelRandomMaterial();
                                    }
                                                                        
                                    //voxelController.gameObject.SetActive(true);
                                    voxelController.spawnLevels = 1;
                                }

                                //Set a collider in place to make voxels "explode"
                                GameObject voxelCollider = voxelColliderPool.GetObject();
                                if (voxelCollider != null)
                                {
                                    voxelCollider.transform.position = cubeCenter;
                                }
                            }
                        }
                    }
                }
            }
        }
        //Debug.Log("Spider spawned: " + total);
    }
Exemple #18
0
    public static List <Cursor> GetRadialTiles(int originX, int originZ, int maxHops, int maxHeightChange, bool allowOthers,
                                               int minDistance = 0, bool heightAugmented = false, bool forMovement = false)
    {
        print("max height diff: " + maxHeightChange);
        Cursor       origin = GetTile(originX, originZ);
        List <int[]> queue  = new List <int[]>();

        queue.Add(new int[] { originX, originZ, 0 });
        for (int i = 0; i < queue.Count; i++)
        {
            int[] entry      = queue[i];
            int   counter    = entry[2] + 1;
            int   hopAugment = heightAugmented ? origin.yPos : 0;
            if (counter > maxHops + hopAugment)
            {
                continue;
            }

            List <Cursor> neighbors = Neighbors(entry[0], entry[1]);

            List <int[]> newCells = new List <int[]>();

            foreach (Cursor cursor in neighbors)
            {
                if (allowOthers || !cursor.standingUnit || cursor.standingUnit == Unit.Subject())
                {
                    if (forMovement)
                    {
                        Unit unit = Helpers.GetTile(originX, originZ).standingUnit;
                        if (!CanMoveThere(unit, cursor))
                        {
                            continue;
                        }
                    }

                    int  elevation = VoxelController.GetElevation(cursor.xPos, cursor.zPos);
                    bool movable   = (!forMovement && Mathf.Abs(elevation - origin.yPos) <= maxHeightChange) || (elevation >= 0 && Helpers.CanMoveToNextTile(cursor, Helpers.GetTile(entry[0], entry[1]), maxHeightChange));
                    if (movable)
                    {
                        newCells.Add(new int[] { cursor.xPos, cursor.zPos, counter, elevation });
                    }
                }
            }

            for (int a = newCells.Count - 1; a >= 0; a--)
            {
                for (int g = 0; g < queue.Count; g++)
                {
                    if (newCells[a][0] == queue[g][0] &&
                        newCells[a][1] == queue[g][1] &&
                        newCells[a][2] <= queue[g][2])
                    {
                        newCells.RemoveAt(a);
                        break;
                    }
                }
            }

            for (int a = 0; a < newCells.Count; a++)
            {
                queue.Add(newCells[a]);
            }
        }

        HashSet <Cursor> cursors = new HashSet <Cursor>();

        foreach (int[] entry in queue)
        {
            int  distance              = Mathf.Abs(entry[0] - originX) + Mathf.Abs(entry[1] - originZ);
            bool satisfiesMinDistance  = distance >= minDistance;
            bool satisfiesHeightOffset = !heightAugmented;
            if (heightAugmented)
            {
                Cursor destination  = GetTile(entry[0], entry[1]);
                int    distanceDiff = distance - maxHops;
                int    heightDiff   = origin.yPos - destination.yPos;
                satisfiesHeightOffset = distanceDiff <= heightDiff;
            }

            if (satisfiesMinDistance && satisfiesHeightOffset)
            {
                cursors.Add(GetTile(entry[0], entry[1]));
            }
        }

        return(cursors.ToList());
    }
 private void Awake()
 {
     _voxelController = GameObject.FindObjectOfType <VoxelController>();
 }
Exemple #20
0
 private void Awake()
 {
     _hsvColorPicker  = FindObjectOfType <HSVPicker>();
     _voxelController = FindObjectOfType <VoxelController>();
 }
Exemple #21
0
 private void Awake()
 {
     _hsvColorPicker = FindObjectOfType<HSVPicker>();
     _voxelController = FindObjectOfType<VoxelController>();
 }