This content originally appeared on DEV Community and was authored by Kazuhiro Hara™
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. - 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 Package
and importNRSDKForUnityAndroid_1.7.0.unitypackage
. - Check
Build Settings
>Player Settings
by referring to Configure Build Settings - Press
Build
formBuild Settings
panel - 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.
- Download NRSDK 1.7.0 from https://nreal-public.nreal.ai/download/NRSDKForUnityAndroid_1.7.0.unitypackage
- Open
Project
, selectAssets
>import package
>Custom Package
and importNRSDKForUnityAndroid_1.7.0.unitypackage
.
2. Put a Cube in the scene and convert it to Prefab
- Open
Project
, createResource
folder inAssets
>Scenes
- Create
Cube
on current scene, change name toMyCube
. - Drag
MyCube
toAssets
>Scenes
>Resource
folder. - Delete
MyCube
fromHierarchy
.
3. Create an empty GameObject and attach C# script to it.
- Create an empty GameObject on
Hierarchy
with the nameBaseCubeSize
. - Create the following C# script named
CubeSize
and 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
Build
formBuild Settings
panel - Install *.apk on Android or DevKit.
This content originally appeared on DEV Community and was authored by Kazuhiro Hara™
Kazuhiro Hara™ | Sciencx (2022-02-12T09:18:45+00:00) Check size of a lot of cubes on Nreal light – MR Tutorial for Nreal light. Retrieved from https://www.scien.cx/2022/02/12/check-size-of-a-lot-of-cubes-on-nreal-light-mr-tutorial-for-nreal-light/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.