This sample is to see what size you can actually feel by placing many 1x1x1 cubes in the space.
Sample Repository
Run the sample
- Clone Sample Repository, Change current directory to
CubeSize. And Open with Unity. - (If you don't have NRSDK) Download NRSDK 1.7.0 from https://nreal-public.nreal.ai/download/NRSDKForUnityAndroid_1.7.0.unitypackage
- Open
Build Setting, change Platform toAndroid - Open
Project, selectAssets>import package>Custom Packageand importNRSDKForUnityAndroid_1.7.0.unitypackage. - Check
Build Settings>Player Settingsby referring to Configure Build Settings - Press
BuildformBuild Settingspanel - Install *.apk on Android or DevKit.
Tutorial
1. Setting up the project for Nreal development
- See Quickstart for Android - NRSDK Documentation and configure the build settings.
- (If you don't have NRSDK) Download NRSDK 1.7.0 from https://nreal-public.nreal.ai/download/NRSDKForUnityAndroid_1.7.0.unitypackage
- Open
Project, selectAssets>import package>Custom Packageand importNRSDKForUnityAndroid_1.7.0.unitypackage.
2. Put a Cube in the scene and convert it to Prefab
- Open
Project, createResourcefolder inAssets>Scenes - Create
Cubeon current scene, change name toMyCube. - Drag
MyCubetoAssets>Scenes>Resourcefolder. - Delete
MyCubefromHierarchy.
3. Create an empty GameObject and attach C# script to it.
- Create an empty GameObject on
Hierarchywith the nameBaseCubeSize. - Create the following C# script named
CubeSizeand attach it to the empty GameObject you just created.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class CubeSize : MonoBehaviour
{
/// <summary>
/// Cube PreFab
/// </summary>
GameObject spherePrefab;
/// <summary>
/// Initial Position for cube layout
/// </summary>
static readonly Vector3 INITIAL_POSITION = new Vector3(0.0f, -0.35f, 3f);
/// <summary>
/// Number of Cubes list per axis
/// </summary>
static readonly float DEPTH = 20f;
/// <summary>
/// Space for each Cubes
/// </summary>
static readonly float SPAN = 2f;
// Start is called before the first frame update
void Start()
{
spherePrefab = Resources.Load<GameObject>("MyCube");
LayoutCubes(DEPTH, SPAN);
}
/// <summary>
/// Layout Cubes
/// </summary>
/// <param name="depth"></param>
/// <param name="span"></param>
void LayoutCubes(float depth, float span)
{
for (float x = -depth; x <= depth; x = x += span)
{
for (float y = -depth; y <= depth; y += span)
{
for (float z = -depth; z <= depth; z += span)
{
// Exclude own position
if (!(x == 0 && y == 0 && z == -2f))
{
CreateCube(x, y, z);
}
}
}
}
}
/// <summary>
/// Put a cube in the current scene
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
void CreateCube(float x, float y, float z)
{
GameObject sphere = Instantiate(spherePrefab);
sphere.transform.position = new Vector3(INITIAL_POSITION.x + x, INITIAL_POSITION.y + y, INITIAL_POSITION.z + z);
}
}
4. Build
- Press
BuildformBuild Settingspanel - Install *.apk on Android or DevKit.

Top comments (0)