// Saves individual hand
        public void SaveToList(BKI_Hand hand, BKI_SingleGestureClass ges, bool isOverwrite = false)
        {
            BKI_SingleGestureStruct struc = new BKI_SingleGestureStruct(ges);

            if (!EntryAlreadyExists(hand, ges) || isOverwrite)
            {
                if (isOverwrite)
                {
                    foreach (var item in ((hand == BKI_Hand.right) ? rhGesturesList : lhGesturesList))
                    {
                        if (item.gesture.gestureIdentifier == ges.gestureIdentifier)
                        {
                            ((hand == BKI_Hand.right) ? rhGesturesList : lhGesturesList).Remove(item);
                            break;
                        }
                    }
                    if (((hand == BKI_Hand.right) ? rhDictionary : lhDictionary).ContainsKey(ges.gestureIdentifier))
                    {
                        ((hand == BKI_Hand.right) ? rhDictionary : lhDictionary).Remove(ges.gestureIdentifier);
                    }
                }
                ((hand == BKI_Hand.right) ? rhGesturesList : lhGesturesList).Add(struc);
                ((hand == BKI_Hand.right) ? rhDictionary : lhDictionary).Add(ges.gestureIdentifier, ges);
                AssetDatabase.Refresh();
                EditorUtility.SetDirty(this);
                AssetDatabase.SaveAssets();
            }
        }
        public bool EntryAlreadyExists(BKI_Hand hand, BKI_SingleGestureClass ges)
        {
            SweepDictionaries();
            bool returnVal = false;

            if (!returnVal)
            {
                returnVal = ((hand == BKI_Hand.right) ? rhDictionary : lhDictionary).ContainsKey(ges.gestureIdentifier);
            }
            if (!returnVal)
            {
                if (hand == BKI_Hand.right)
                {
                    foreach (var g in rhGesturesList)
                    {
                        if (g.gesture == ges)
                        {
                            return(true);
                        }
                    }
                }
                else
                {
                    foreach (var g in lhGesturesList)
                    {
                        if (g.gesture == ges)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(returnVal);
        }
Beispiel #3
0
        private BKI_SingleGestureClass SaveObjectToResources(BKI_SingleGestureClass o, BKI_Hand hand)
        {
            string path = "";

            switch (hand)
            {
            case BKI_Hand.left:
            {
                path = RESOURCES_LEFTHAND_PATH + "/lhGes_" + o.gestureIdentifier + ".asset";
            }
            break;

            case BKI_Hand.right:
            {
                path = RESOURCES_RIGHTHAND_PATH + "/rhGes_" + o.gestureIdentifier + ".asset";
            }
            break;
            }

            AssetDatabase.CreateAsset(o, path);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            return(AssetDatabase.LoadAssetAtPath <BKI_SingleGestureClass>(path));
        }
Beispiel #4
0
        private BKI_CombiGestureClass SerializeToolToGesture(string identifier, BKI_SingleGestureClass lhGes, BKI_SingleGestureClass rhGes)
        {
            BKI_CombiGestureClass returnVal = new BKI_CombiGestureClass();

            returnVal.SetValues(identifier, lhGes, rhGes);
            return(returnVal);
        }
Beispiel #5
0
 public void SetValues(string id, BKI_SingleGestureClass lh, BKI_SingleGestureClass rh)
 {
     gestureIdentifier       = id;
     leftHandGesture         = lh;
     rightHandGesture        = rh;
     assignedGesturePriority = leftHandGesture.GetGesturePriority() + rightHandGesture.GetGesturePriority();
 }
Beispiel #6
0
        /// <summary>
        /// Function that converts the mirror class to the class that will be used at runtime.
        /// Cannot return null. If the input class is null, it returns a freshly generated BKI_GestureMirrorClass.
        /// </summary>
        private BKI_GestureMirrorClass DeserializeGesture(BKI_SingleGestureClass gesture)
        {
            BKI_GestureMirrorClass returnVal = new BKI_GestureMirrorClass();

            if (gesture == null)
            {
                return(returnVal);
            }

            returnVal.SetValues(gesture.gestureIdentifier, gesture.requiresClench, gesture.fingerStates);

            return(returnVal);
        }
Beispiel #7
0
        /// <summary>
        /// Function that converts the mirror class to the class that will be used at runtime.
        /// Cannot return null. If the input class is null, it returns a freshly generated BKI_GestureClass.
        /// </summary>
        private BKI_SingleGestureClass SerializeGesture(BKI_Hand h, BKI_GestureMirrorClass mirror)
        {
            BKI_SingleGestureClass returnVal = ScriptableObject.CreateInstance <BKI_SingleGestureClass>();

            if (mirror == null)
            {
                return(returnVal);
            }

            returnVal.SetValues(h, mirror.gestureIdentifier, mirror.requiresClench, mirror.fingerStates);

            return(returnVal);
        }
        public override bool Equals(object o)
        {
            if (o == null)
            {
                return(false);
            }

            BKI_SingleGestureClass other = o as BKI_SingleGestureClass;

            if (other == null)
            {
                return(false);
            }

            return(this.GetHashCode() == other.GetHashCode());
        }
Beispiel #9
0
        // Happens when the "Save Gesture" button is pressed. Starts the saving process. Returns the object referenced in the resources folder.
        private BKI_SingleGestureClass SubmitSingleHandGesture(BKI_Hand hand, BKI_SingleGestureClass ges, bool fromResources)
        {
            BKI_SingleGestureClass returnObj = null;

            if (gestureStorage == null)
            {
                Debug.LogError("Gesture storage could not be found. Exiting save function.");
                return(null);
            }

            if (!gestureStorage.EntryAlreadyExists(hand, ges) || fromResources)
            {
                returnObj = SaveObjectToResources(ges, hand);
                gestureStorage.SaveToList(hand, returnObj, fromResources);
            }

            return(returnObj);
        }
        // Starts the saving sequence of the combination gesture.
        private void SubmitCombinationGesture(BKI_CombiGestureClass ges, bool fromResources)
        {
            if (gestureStorage == null)
            {
                Debug.LogError("Gesture storage could not be found. Exiting save function.");
                return;
            }

            if (!gestureStorage.EntryAlreadyExists(ges) || fromResources)
            {
                //ges.leftHandGesture =
                //ges.rightHandGesture =
                BKI_SingleGestureClass lh = SubmitSingleHandGesture(BKI_Hand.left, ges.leftHandGesture, isOpenedFromResourcesLh);
                BKI_SingleGestureClass rh = SubmitSingleHandGesture(BKI_Hand.right, ges.rightHandGesture, isOpenedFromResourcesRh);

                BKI_CombiGestureClass g = SaveObjectToResources(ges);

                g.leftHandGesture  = lh;
                g.rightHandGesture = lh;

                gestureStorage.SaveToList(g, fromResources);
            }
        }
 public BKI_SingleGestureStruct(BKI_SingleGestureClass gesture)
 {
     this.gesture = gesture;
 }
Beispiel #12
0
        private void CatchPickerObject(object o, BKI_UIType ls)
        {
            if (o == null)
            {
                return;
            }

            switch (ls)
            {
            case BKI_UIType.left:
                BKI_SingleGestureClass t = o as BKI_SingleGestureClass;

                if (t == null)
                {
                    Debug.LogError("Object invalid. Stopping opening.");
                    break;
                }
                if (t.hand != BKI_Hand.left)
                {
                    Debug.LogError("You tried to open a right handed gesture into the left hand editor. Stopping opening.");
                    break;
                }

                lhGesture               = ScriptableObject.Instantiate(t);
                leftHandValues          = DeserializeGesture(lhGesture);
                lhMirror                = DeserializeGesture(lhGesture);
                isOpenedFromResourcesLh = true;
                currentGestureSavedLh   = true;
                pickerWindowGNameLh     = t.gestureIdentifier;
                break;

            case BKI_UIType.right:
                BKI_SingleGestureClass u = o as BKI_SingleGestureClass;

                if (u == null)
                {
                    Debug.LogError("Object invalid. Stopping opening.");
                    break;
                }
                if (u.hand != BKI_Hand.right)
                {
                    Debug.LogError("You tried to open a left handed gesture into the left hand editor. Stopping opening.");
                    break;
                }

                rhGesture               = ScriptableObject.Instantiate(u);
                rightHandValues         = DeserializeGesture(rhGesture);
                rhMirror                = DeserializeGesture(rhGesture);
                isOpenedFromResourcesRh = true;
                currentGestureSavedRh   = true;
                pickerWindowGNameRh     = u.gestureIdentifier;
                break;

            case BKI_UIType.combi:
                BKI_CombiGestureClass ges = o as BKI_CombiGestureClass;

                if (ges == null)
                {
                    Debug.LogError("Object invalid. Stopping opening.");
                    break;
                }
                if (!ges.name.Contains("combi"))
                {
                    Debug.LogError("You tried to open a gesture other than a combination gesture. Terminating.");
                    break;
                }

                combiGesture = ScriptableObject.Instantiate(ges);
                CatchPickerObject(combiGesture.leftHandGesture, BKI_UIType.left);
                CatchPickerObject(combiGesture.rightHandGesture, BKI_UIType.right);
                pickerWindowGNameCombi     = ges.gestureIdentifier;
                currentGestureSavedCombi   = true;
                isOpenedFromResourcesCombi = true;
                break;
            }
        }