Пример #1
0
        private IEnumerator disableGroup(string groupName)
        {
            yield return(new WaitForEndOfFrame());

            ModelGroup group = null;

            for (int i = 0; i < ModelPool.Count; i++)
            {
                if (ModelPool[i].GroupName == groupName)
                {
                    group = ModelPool[i];
                    for (int m = 0; m < group.modelsCheckedOut.Count; m++)
                    {
                        HandModelBase      model = group.modelsCheckedOut[m];
                        HandRepresentation handRep;
                        if (modelToHandRepMapping.TryGetValue(model, out handRep))
                        {
                            handRep.RemoveModel(model);
                            group.ReturnToGroup(model);
                            m--;
                        }
                    }
                    Assert.AreEqual(0, group.modelsCheckedOut.Count, group.GroupName + "'s modelsCheckedOut List has not been cleared");
                    group.IsEnabled = false;
                }
            }
            if (group == null)
            {
                Debug.LogWarning("A group matching that name does not exisit in the modelPool");
            }
        }
Пример #2
0
 /*Looks for suitable HandModelBase is the ModelGroup's modelList, if found, it is added to modelsCheckedOut.
  * If not, one can be cloned*/
 public HandModelBase TryGetModel(Chirality chirality, ModelType modelType)
 {
     for (int i = 0; i < modelList.Count; i++)
     {
         if (modelList[i].HandModelType == modelType && modelList[i].Handedness == chirality)
         {
             HandModelBase model = modelList[i];
             modelList.RemoveAt(i);
             modelsCheckedOut.Add(model);
             return(model);
         }
     }
     if (CanDuplicate)
     {
         for (int i = 0; i < modelsCheckedOut.Count; i++)
         {
             if (modelsCheckedOut[i].HandModelType == modelType && modelsCheckedOut[i].Handedness == chirality)
             {
                 HandModelBase modelToSpawn = modelsCheckedOut[i];
                 HandModelBase spawnedModel = GameObject.Instantiate(modelToSpawn);
                 spawnedModel.transform.parent = _handModelManager.transform;
                 _handModelManager.modelGroupMapping.Add(spawnedModel, this);
                 modelsCheckedOut.Add(spawnedModel);
                 return(spawnedModel);
             }
         }
     }
     return(null);
 }
Пример #3
0
        private IEnumerator enableGroup(string groupName)
        {
            yield return(new WaitForEndOfFrame());

            ModelGroup group = null;

            for (int i = 0; i < ModelPool.Count; i++)
            {
                if (ModelPool[i].GroupName == groupName)
                {
                    group = ModelPool[i];
                    for (int hp = 0; hp < activeHandReps.Count; hp++)
                    {
                        HandRepresentation handRep = activeHandReps[hp];
                        HandModelBase      model   = group.TryGetModel(handRep.RepChirality, handRep.RepType);
                        if (model != null)
                        {
                            handRep.AddModel(model);
                            modelToHandRepMapping.Add(model, handRep);
                        }
                    }
                    group.IsEnabled = true;
                }
            }
            if (group == null)
            {
                Debug.LogWarning("A group matching that name does not exisit in the modelPool");
            }
        }
Пример #4
0
        /**
         * MakeHandRepresentation receives a Hand and combines that with a HandModelBase to create a HandRepresentation
         * @param hand The Leap Hand data to be drive a HandModelBase
         * @param modelType Filters for a type of hand model, for example, physics or graphics hands.
         */
        public HandRepresentation MakeHandRepresentation(Hand hand, ModelType modelType)
        {
            Chirality          handChirality = hand.IsRight ? Chirality.Right : Chirality.Left;
            HandRepresentation handRep       = new HandRepresentation(this, hand, handChirality, modelType);

            for (int i = 0; i < ModelPool.Count; i++)
            {
                ModelGroup group = ModelPool[i];
                if (group.IsEnabled)
                {
                    HandModelBase model = group.TryGetModel(handChirality, modelType);
                    if (model != null)
                    {
                        handRep.AddModel(model);
                        if (!modelToHandRepMapping.ContainsKey(model))
                        {
                            model.group = group;
                            modelToHandRepMapping.Add(model, handRep);
                        }
                    }
                }
            }
            activeHandReps.Add(handRep);
            return(handRep);
        }
Пример #5
0
 public void RemoveModel(HandModelBase model)
 {
     if (handModels != null)
     {
         model.FinishHand();
         handModels.Remove(model);
     }
 }
Пример #6
0
 protected virtual void Awake()
 {
     handModelBase = GetComponent <HandModelBase>();
     if (handModelBase == null)
     {
         Debug.LogWarning("HandTransitionBehavior components require a HandModelBase component attached to the same GameObject");
         return;
     }
     handModelBase.OnBegin  += HandReset;
     handModelBase.OnFinish += HandFinish;
 }
Пример #7
0
        public void AddNewGroup(string groupName, HandModelBase leftModel, HandModelBase rightModel)
        {
            ModelGroup newGroup = new ModelGroup();

            newGroup.LeftModel    = leftModel;
            newGroup.RightModel   = rightModel;
            newGroup.GroupName    = groupName;
            newGroup.CanDuplicate = false;
            newGroup.IsEnabled    = true;
            ModelPool.Add(newGroup);
            InitializeModelGroup(newGroup);
        }
Пример #8
0
        protected virtual void Awake()
        {
            handModelBase = GetComponent <HandModelBase>();

            handModelBase.OnBegin -= HandReset;
            handModelBase.OnBegin += HandReset;

            handModelBase.OnFinish -= HandFinish;
            handModelBase.OnFinish += HandFinish;

            this.gameObject.SetActive(disableOnAwake ? false : this.gameObject.activeInHierarchy);
        }
        protected virtual void OnDestroy()
        {
            if (handModelBase == null)
            {
                HandModelBase handModelBase = GetComponent <HandModelBase>();
                if (handModelBase == null)
                {
                    Debug.LogWarning("HandTransitionBehavior components require a HandModelBase "
                                     + "component attached to the same GameObject. (OnDestroy)");
                    return;
                }
            }

            handModelBase.OnBegin  -= HandReset;
            handModelBase.OnFinish -= HandFinish;
        }
Пример #10
0
 protected virtual void Awake()
 {
     if (GetComponent <HandModelBase>() != null && ControlsTransform == true)
     {
         Debug.LogWarning("Detector should not be control the HandModelBase's transform. Either attach it to its own transform or set ControlsTransform to false.");
     }
     if (_handModel == null)
     {
         _handModel = GetComponentInParent <HandModelBase>();
         if (_handModel == null)
         {
             Debug.LogWarning("The HandModel field of Detector was unassigned and the detector has been disabled.");
             enabled = false;
         }
     }
 }
Пример #11
0
        private void InitializeModelGroup(ModelGroup collectionGroup)
        {
            // Prevent the ModelGroup be initialized by multiple times
            if (modelGroupMapping.ContainsValue(collectionGroup))
            {
                return;
            }

            collectionGroup._handModelManager = this;
            HandModelBase leftModel;
            HandModelBase rightModel;

            if (collectionGroup.IsLeftToBeSpawned)
            {
                HandModelBase modelToSpawn = collectionGroup.LeftModel;
                GameObject    spawnedGO    = Instantiate(modelToSpawn.gameObject);
                leftModel = spawnedGO.GetComponent <HandModelBase>();
                leftModel.transform.parent = this.transform;
            }
            else
            {
                leftModel = collectionGroup.LeftModel;
            }
            if (leftModel != null)
            {
                collectionGroup.modelList.Add(leftModel);
                modelGroupMapping.Add(leftModel, collectionGroup);
            }

            if (collectionGroup.IsRightToBeSpawned)
            {
                HandModelBase modelToSpawn = collectionGroup.RightModel;
                GameObject    spawnedGO    = Instantiate(modelToSpawn.gameObject);
                rightModel = spawnedGO.GetComponent <HandModelBase>();
                rightModel.transform.parent = this.transform;
            }
            else
            {
                rightModel = collectionGroup.RightModel;
            }
            if (rightModel != null)
            {
                collectionGroup.modelList.Add(rightModel);
                modelGroupMapping.Add(rightModel, collectionGroup);
            }
        }
Пример #12
0
 public void AddModel(HandModelBase model)
 {
     if (handModels == null)
     {
         handModels = new List <HandModelBase>();
     }
     handModels.Add(model);
     if (model.GetLeapHand() == null)
     {
         model.SetLeapHand(MostRecentHand);
         model.InitHand();
         model.BeginHand();
         model.UpdateHand();
     }
     else
     {
         model.SetLeapHand(MostRecentHand);
         model.BeginHand();
     }
 }
Пример #13
0
        private void Awake()
        {
            platformManager    = GetComponent <PlatformManager>();
            interactionManager = Leap.Unity.Interaction.InteractionManager.instance;
            if (interactionManager != null)
            {
                controllerManager = interactionManager.GetComponent <PlatformControllerManager>();
            }

            DataHand[] dataHands = modelManager.GetComponentsInChildren <DataHand>(true);

            leftAbstractHand  = (HandModelBase)dataHands.First(item => item is DataHand && item.Handedness == Chirality.Left);
            rightAbstractHand = (HandModelBase)dataHands.First(item => item is DataHand && item.Handedness == Chirality.Right);

            if (interactionManager)
            {
                foreach (InteractionController controller in interactionManager.interactionControllers)
                {
                    if (controller is InteractionHand)
                    {
                        InteractionHand hand = (InteractionHand)controller;

                        if (hand.isLeft)
                        {
                            leftInteractionHand = hand;
                        }
                        else
                        {
                            rightInteractionHand = hand;
                        }

                        hand.leapProvider = defaultProvider;
                    }
                }
            }

            SkeletalControllerHand[] hands = transform.parent.GetComponentsInChildren <SkeletalControllerHand>(true);
            leftSkeletalControllerHand  = hands.First(item => item.IsLeft);
            rightSkeletalControllerHand = hands.First(item => !item.IsLeft);
        }
Пример #14
0
        public void ReturnToPool(HandModelBase model)
        {
            ModelGroup modelGroup;
            bool       groupFound = modelGroupMapping.TryGetValue(model, out modelGroup);

            Assert.IsTrue(groupFound);
            //First see if there is another active Representation that can use this model
            for (int i = 0; i < activeHandReps.Count; i++)
            {
                HandRepresentation rep = activeHandReps[i];
                if (rep.RepChirality == model.Handedness && rep.RepType == model.HandModelType)
                {
                    bool modelFromGroupFound = false;
                    if (rep.handModels != null)
                    {
                        //And that Represention does not contain a model from this model's modelGroup
                        for (int j = 0; j < modelGroup.modelsCheckedOut.Count; j++)
                        {
                            HandModelBase modelToCompare = modelGroup.modelsCheckedOut[j];
                            for (int k = 0; k < rep.handModels.Count; k++)
                            {
                                if (rep.handModels[k] == modelToCompare)
                                {
                                    modelFromGroupFound = true;
                                }
                            }
                        }
                    }
                    if (!modelFromGroupFound)
                    {
                        rep.AddModel(model);
                        modelToHandRepMapping[model] = rep;
                        return;
                    }
                }
            }
            //Otherwise return to pool
            modelGroup.ReturnToGroup(model);
        }
Пример #15
0
 public void ReturnToGroup(HandModelBase model)
 {
     modelsCheckedOut.Remove(model);
     modelList.Add(model);
     this._handModelManager.modelToHandRepMapping.Remove(model);
 }