Inheritance: MonoBehaviour
Exemple #1
0
    // Use this for initialization
    void Start()
    {
        SkeletalHand hand = this.gameObject.GetComponent <SkeletalHand>();

        foreach (FingerModel finger in hand.fingers)
        {
            if (finger.GetType() == typeof(SkeletalFinger))
            {
                SkeletalFinger skeletalFinger = finger as SkeletalFinger;

                if (skeletalFinger.fingerType == Finger.FingerType.TYPE_INDEX)
                {
                    foreach (Transform bone in skeletalFinger.bones)
                    {
                        if (bone == null)
                        {
                            continue;
                        }
                        ParticleSystem ps = bone.gameObject.GetComponentInChildren <ParticleSystem>();
                        if (ps != null)
                        {
                            this.indexFingerProxy = ps;
                            break;
                        }
                    }
                }
                else if (skeletalFinger.fingerType == Finger.FingerType.TYPE_THUMB)
                {
                    foreach (Transform bone in skeletalFinger.bones)
                    {
                        if (bone == null)
                        {
                            continue;
                        }
                        ParticleSystem ps = bone.gameObject.GetComponentInChildren <ParticleSystem>();
                        if (ps != null)
                        {
                            this.thumbProxy = ps;
                            break;
                        }
                    }
                }
            }
        }

        if (this.indexFingerProxy == null)
        {
            Debug.LogError("index finger stimulation proxy is missing...");
        }
        if (this.thumbProxy == null)
        {
            Debug.LogError("thumb stimulation proxy is missing...");
        }

        this.stopParticleSystems();
    }
    new protected HandModel CreateHand(HandModel model)
    {
        HandModel hand_model = Instantiate(model, transform.position, transform.rotation)
                               as HandModel;

        hand_model.gameObject.SetActive(true);

        ParticleSystem[] particleSystems = hand_model.GetComponentsInChildren <ParticleSystem>();
        foreach (ParticleSystem system in particleSystems)
        {
            system.Stop();
        }

        Utils.IgnoreCollisions(hand_model.gameObject, gameObject);

        // add scripts...
        foreach (FingerModel finger in hand_model.fingers)
        {
            if (finger.GetType() == typeof(RigidFinger))
            {
                RigidFinger rigidFinger = finger as RigidFinger;
                foreach (Transform bone in rigidFinger.bones)
                {
                    if (bone == null)
                    {
                        continue;
                    }
                    GameObject bGameObject = bone.gameObject;
                    Rigidbody  bRigidBody  = bGameObject.gameObject.GetComponent <Rigidbody>() as Rigidbody;
                    bRigidBody.isKinematic            = false;
                    bRigidBody.useGravity             = false;
                    bRigidBody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
                }

                rigidFinger.bones[rigidFinger.bones.Length - 1].gameObject.tag = "FingerTip";
            }
        }

        // add grasp script
        if (hand_model.GetType() == typeof(RigidHand))
        {
            hand_model.gameObject.AddComponent <GraspController>();
            GraspController graspController = hand_model.gameObject.GetComponent <GraspController>();
            //graspController.GraspTriggerDistance = 1.0f * this.GraspDistanceScale;
            //graspController.ReleaseTriggerDistance = 2.5f * this.GraspDistanceScale;
            graspController.GraspObjectDistance = 3.5f * this.GraspDistanceScale * transform.localScale.x;
        }

        Collider[] allCls = hand_model.GetComponentsInChildren <Collider>();
        foreach (Collider lcl in allCls)
        {
            foreach (Collider refCl in allCls)
            {
                if (!lcl.Equals(refCl))
                {
                    Physics.IgnoreCollision(lcl, refCl, true);
                }
            }
        }

        if (this.enableFingerParticleSystems && hand_model.GetType() == typeof(SkeletalHand))
        {
            SkeletalHand skeletalHand = hand_model as SkeletalHand;
            foreach (FingerModel finger in skeletalHand.fingers)
            {
                if (finger.GetType() == typeof(SkeletalFinger))
                {
                    SkeletalFinger skeletalFinger = finger as SkeletalFinger;

                    if (skeletalFinger.fingerType == Finger.FingerType.TYPE_INDEX)
                    {
                        Transform bone = skeletalFinger.bones[skeletalFinger.bones.Length - 1];

                        /*GameObject indexProxy = GameObject.Instantiate(this.IndexStimulationProxyPrefab, Vector3.zero, Quaternion.identity) as GameObject;
                         * indexProxy.transform.parent = bone;
                         * indexProxy.transform.localPosition = Vector3.zero;*/
                    }
                    else if (skeletalFinger.fingerType == Finger.FingerType.TYPE_THUMB)
                    {
                        Transform bone = skeletalFinger.bones[skeletalFinger.bones.Length - 1];

                        /*GameObject thumbProxy = GameObject.Instantiate(this.ThumbStimulationProxyPrefab, Vector3.zero, Quaternion.identity) as GameObject;
                         * thumbProxy.transform.parent = bone;
                         * thumbProxy.transform.localPosition = Vector3.zero;*/
                    }
                }
            }
            //skeletalHand.gameObject.AddComponent<StimulationProxy>();
        }

        return(hand_model);
    }