public bool GetRotation(LiveObjectTag tag, out Quaternion rotation) { if (!tagToMotiveName.ContainsKey(tag)) { throw new System.ArgumentException("Illegal tag."); } LiveObjectStorage storage; lock (lockObject) { if (!liveObjects.TryGetValue(tagToMotiveName[tag], out storage)) { rotation = DEFAULT_QUATERNION_ROTATION; return(false); } else { rotation = storage.rotation; if (rotation.Equals(DEFAULT_QUATERNION_ROTATION)) { return(false); } else { return(true); } } } }
public bool GetPosition(LiveObjectTag tag, out Vector3 position) { if (!tagToMotiveName.ContainsKey(tag)) { throw new System.ArgumentException("Illegal tag."); } LiveObjectStorage storage; lock (lockObject) { if (!liveObjects.TryGetValue(tagToMotiveName[tag], out storage)) { position = DEFAULT_VECTOR_POSITION; return(false); } else { position = storage.position; if (position.Equals(DEFAULT_VECTOR_POSITION)) { return(false); } else { return(true); } } } }
void InitObjectControllers() { GameObject[] objs = new GameObject[5] { head.gameObject, leftHand.gameObject, rightHand.gameObject, leftFoot.gameObject, rightFoot.gameObject }; LiveObjectTag[] tags = new LiveObjectTag[5] { headTag, leftHandTag, rightHandTag, leftFootTag, rightFootTag }; for (int i = 0; i < 5; i++) { GameObject go = objs[i]; TrackedObject trackedObject = go.GetComponent <TrackedObject>(); if (trackedObject == null) { trackedObject = go.AddComponent <TrackedObject>(); } trackedObject.liveObjectTag = tags[i]; } }
public bool GetButtonBits(LiveObjectTag tag, out int bits) { if (!tagToMotiveName.ContainsKey(tag)) { throw new System.ArgumentException("Illegal tag."); } LiveObjectStorage storage; lock (lockObject) { if (!liveObjects.TryGetValue(tagToMotiveName[tag], out storage)) { bits = 0; return(false); } else { bits = storage.buttonBits; return(true); } } }
Result Index(bool force = false) { if (actors.Length != transform.childCount) { actors = new Actor[transform.childCount]; } int[] indices = new int[transform.childCount]; bool equal = indexCache != null && indexCache.Length == indices.Length; //Build actor array and cache for (int i = 0; i < transform.childCount; ++i) { if (actors[i] == null) { actors[i] = transform.GetChild(i).GetComponent <Actor>(); } indices[i] = actors[i].index; equal = equal && indices[i] == indexCache[i]; } //If tags differ from last check, perform index if (equal && buildTag == cachedBuildTag && !force) { return(Result.PASSED); } indexCache = indices; cachedBuildTag = buildTag; if (actors.Length == 0) { if (Application.isPlaying) { Debug.LogWarning("ActorManager: No actors in hierarchy!"); } return(Result.ERROR); } if (viewer == null || shell == null) { Debug.LogWarning("ActorManager: Viewer/Shell prefab reference is null"); return(Result.ERROR); } //Index each actor bool setBuild = false; foreach (Actor a in actors) { a.transform.position = Vector3.zero; a.transform.rotation = Quaternion.identity; //Flush shell foreach (Transform child in a.transform) { if (child.name == "Shell") { if (Application.isEditor && !Application.isPlaying) { DestroyImmediate(child.gameObject); } else { Destroy(child.gameObject); } } } //Is this the build actor? bool isBuild = a.index == (int)buildTag; if (isBuild && setBuild) { Debug.LogWarning("ActorManager: Duplicate build actor!"); isBuild = false; } else if (isBuild) { ba = a; //Assign reference } a.gameObject.name = "Actor " + ((int)a.index + 1) + (isBuild?" (Build)":""); //Create shell if (!isBuild) { GameObject s = Instantiate(shell, a.transform.position, a.transform.rotation) as GameObject; s.transform.parent = a.transform; s.name = "Shell"; } setBuild = setBuild || isBuild; //Color actors (shells) a.ApplyMotif(); } if (!setBuild) { Debug.LogWarning("ActorManager: No actor found with matching build tag!"); return(Result.NOVIEW); } //Flush viewer if (viewerReference != null && Application.isEditor && !Application.isPlaying) { DestroyImmediate(viewerReference.gameObject); } else if (viewerReference != null) { Destroy(viewerReference.gameObject); } //Instantiate viewer GameObject v = Instantiate(viewer.gameObject, Vector3.zero, Quaternion.identity) as GameObject; v.name = "Viewer"; v.GetComponent <TrackedHeadset>().liveObjectTag = buildTag; viewerReference = v.GetComponent <TrackedHeadset>(); return(Result.INDEXED); }
/////////////////////////////////////////////////////////////////////////// // // API functions // public bool IsLiveObject(LiveObjectTag tag) { return(liveObjects.ContainsKey(tagToMotiveName[tag])); }