-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCustomBehaviour.cs
69 lines (64 loc) · 2.76 KB
/
CustomBehaviour.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**************************************************************************
* Copyright (C) echoAR, Inc. 2018-2020. *
* echoAR, Inc. proprietary and confidential. *
* *
* Use subject to the terms of the Terms of Service available at *
* https://www.echoar.xyz/terms, or another agreement *
* between echoAR, Inc. and you, your company or other organization. *
***************************************************************************/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
public class CustomBehaviour : MonoBehaviour
{
[HideInInspector]
public Entry entry;
/// <summary>
/// EXAMPLE BEHAVIOUR
/// Queries the database and names the object based on the result.
/// </summary>
// Use this for initialization
void Start()
{
// Add RemoteTransformations script to object and set its entry
this.gameObject.AddComponent<RemoteTransformations>().entry = entry;
// Qurey additional data to get the name
string value = "";
if (entry.getAdditionalData() != null && entry.getAdditionalData().TryGetValue("name", out value))
{
// Set name
this.gameObject.name = value;
}
}
// Update is called once per frame
void Update()
{
// Set image holgram as face texture
Hologram hologram = entry.getHologram();
Hologram.hologramType hologramType = hologram.getType();
// Check for image hologram
if (hologramType == Hologram.hologramType.IMAGE_HOLOGRAM)
{
// Get mesh renderer
MeshRenderer meshRenderer = this.GetComponent<MeshRenderer>();
// Get material and texture
Material material = meshRenderer.material;
Texture texture = material.mainTexture;
// Modify shader
Shader shader = Shader.Find("Transparent/Diffuse");
material.shader = shader;
// Get session and face switcher
GameObject session = GameObject.Find("AR Session Origin");
FaceMaterialSwitcher faceMaterialSwitcher = session.GetComponentInChildren<FaceMaterialSwitcher>();
// Set material and texture
if (faceMaterialSwitcher != null)
{
// Set materials (overwrite all other face materials)
int size = faceMaterialSwitcher.faceMaterials.Length;
faceMaterialSwitcher.faceMaterials = new Material[size];
for (int i = 0; i < size; i++) faceMaterialSwitcher.faceMaterials[i] = material;
}
}
}
}