Beispiel #1
0
        public bool GetButtonBits(Motive.Tag tag, out int bits)
        {
            LiveObjectStorage storage;

            lock (lockObject) {
                if (!liveObjects.TryGetValue(Motive.GetName(tag), out storage))
                {
                    bits = 0;
                    return(false);
                }
                else
                {
                    bits = storage.bits;
                    return(true);
                }
            }
        }
Beispiel #2
0
        void InitObjectControllers()
        {
            GameObject[] objs = new GameObject[5] {
                head.gameObject, leftHand.gameObject, rightHand.gameObject,
                leftFoot.gameObject, rightFoot.gameObject
            };
            Motive.Tag[] tags = new Motive.Tag[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];
            }
        }
Beispiel #3
0
        public bool GetPosition(Motive.Tag tag, out Vector3 position)
        {
            LiveObjectStorage storage;

            lock (lockObject) {
                if (!liveObjects.TryGetValue(Motive.GetName(tag), out storage))
                {
                    position = LiveObjectStorage.DEFAULT_VECTOR_POSITION;
                    return(false);
                }
                else
                {
                    position = storage.position;
                    if (position.Equals(LiveObjectStorage.DEFAULT_VECTOR_POSITION))
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
        }
Beispiel #4
0
        public bool GetRotation(Motive.Tag tag, out Quaternion rotation)
        {
            LiveObjectStorage storage;

            lock (lockObject) {
                if (!liveObjects.TryGetValue(Motive.GetName(tag), out storage))
                {
                    rotation = LiveObjectStorage.DEFAULT_QUATERNION_ROTATION;
                    return(false);
                }
                else
                {
                    rotation = storage.rotation;
                    if (rotation.Equals(LiveObjectStorage.DEFAULT_QUATERNION_ROTATION))
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
        }
Beispiel #5
0
        Result Index(bool force = false)
        {
            int count = transform.GetComponentsInChildren <Actor>(true).Length;

            if (actors.Length != count)
            {
                actors = new Actor[count];
            }
            int[] indices = new int[count];

            bool equal = indexCache != null && indexCache.Length == indices.Length;
            //Build actor array and cache
            int index = 0;

            for (int i = 0; i < transform.childCount; ++i)
            {
                Actor a = transform.GetChild(i).GetComponent <Actor>();
                if (a == null)
                {
                    continue;    //Skip non-actor children
                }
                if (actors[index] == null)
                {
                    actors[index] = a;
                }

                indices[index] = actors[index].index; //Cache indices for comparison
                equal          = equal && indices[index] == indexCache[index];
                index++;
            }

            //Index anyway on preview mode
            equal             = equal && cachedPreviewMode != previewMode;
            cachedPreviewMode = previewMode;

            //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.EMPTY);
            }

            bool setBuild = false;

            //Index each actor
            foreach (Actor a in actors)
            {
                //Is this the build actor?
                bool isBuild = a.trackingTag == buildTag;
                if (isBuild && setBuild)
                {
                    Debug.LogWarning("ActorManager: Duplicate build actor!");
                    isBuild = false;
                }
                else if (isBuild)
                {
                    ba = a;           //Assign reference
                }
                a.gameObject.name = "[" + (a.index + 1) + "] " + a.handle + (isBuild?" (Build)":"");

                //Activate mask
                if (a.mask != null)
                {
                    a.mask.SetActive(previewMode || !isBuild);
                }
                else
                {
                    Debug.Log("ActorManager: No mask found for Actor " + (a.index + 1));
                }

                setBuild = setBuild || isBuild;
            }
            if (!setBuild)
            {
                Debug.LogWarning("ActorManager: No actor found with matching build tag!");
                return(Result.NOBUILD);
            }
            //Update viewer
            if (viewer == null)
            {
                Debug.LogWarning("ActorManager: Viewer prefab reference is null");
                return(Result.NOVIEW);
            }
            else
            {
                viewer.actor = buildActor;
            #if UNITY_EDITOR
                EditorUtility.SetDirty(viewer);
            #endif
            }

            return(Result.INDEXED);
        }
Beispiel #6
0
        ///////////////////////////////////////////////////////////////////////////
        //
        // API functions
        //

        public bool IsLiveObject(Motive.Tag tag)
        {
            return(liveObjects.ContainsKey(Motive.GetName(tag)));
        }