Ejemplo n.º 1
0
        public void Initialize()
        {
            Rigidbody = this.GetComponent <Rigidbody>();
            if (Rigidbody == null)
            {
                Rigidbody = this.gameObject.AddComponent <Rigidbody>();
            }
            Rigidbody.isKinematic        = true;
            Rigidbody.maxAngularVelocity = float.MaxValue;
            Rigidbody.useGravity         = false;

            Collider[] colliders = null;

            if (CustomModel == null)
            {
                colliders = InputDevice.SetupDefaultColliders();
            }
            else
            {
                colliders = RenderModel.GetComponentsInChildren <Collider>(); //note: these should be trigger colliders
            }

            Player.RegisterHand(this);

            if (Player.PhysicalHands == true)
            {
                if (PhysicalController != null)
                {
                    PhysicalController.Kill();
                }

                PhysicalController = this.gameObject.AddComponent <NVRPhysicalController>();
                PhysicalController.Initialize(this, false);

                if (Player.AutomaticallySetControllerTransparency == true)
                {
                    Color transparentcolor = Color.white;
                    transparentcolor.a = (float)VisibilityLevel.Ghost / 100f;

                    GhostRenderers = this.GetComponentsInChildren <Renderer>();
                    for (int rendererIndex = 0; rendererIndex < GhostRenderers.Length; rendererIndex++)
                    {
                        NVRHelpers.SetTransparent(GhostRenderers[rendererIndex].material, transparentcolor);
                    }
                }

                if (colliders != null)
                {
                    GhostColliders = colliders;
                }

                CurrentVisibility = VisibilityLevel.Ghost;
            }
            else
            {
                if (Player.AutomaticallySetControllerTransparency == true)
                {
                    Color transparentcolor = Color.white;
                    transparentcolor.a = (float)VisibilityLevel.Ghost / 100f;

                    GhostRenderers = this.GetComponentsInChildren <Renderer>();
                    for (int rendererIndex = 0; rendererIndex < GhostRenderers.Length; rendererIndex++)
                    {
                        NVRHelpers.SetTransparent(GhostRenderers[rendererIndex].material, transparentcolor);
                    }
                }

                if (colliders != null)
                {
                    GhostColliders = colliders;
                }

                CurrentVisibility = VisibilityLevel.Ghost;
            }

            CurrentHandState = HandState.Idle;
        }
Ejemplo n.º 2
0
        public void DoInitialize()
        {
            Rigidbody = this.GetComponent <Rigidbody>();
            if (Rigidbody == null)
            {
                Rigidbody = this.gameObject.AddComponent <Rigidbody>();
            }
            Rigidbody.isKinematic        = true;
            Rigidbody.maxAngularVelocity = float.MaxValue;
            Rigidbody.useGravity         = false;

            Collider[] Colliders = null;

            if (CustomModel != null)
            {
                GameObject CustomModelObject = GameObject.Instantiate(CustomModel);
                Colliders = CustomModelObject.GetComponentsInChildren <Collider>();
                foreach (var collider in Colliders)
                {
                    collider.isTrigger = true;
                }

                CustomModelObject.transform.parent        = this.transform;
                CustomModelObject.transform.localScale    = Vector3.one;
                CustomModelObject.transform.localPosition = Vector3.zero;
                CustomModelObject.transform.localRotation = Quaternion.identity;
            }
            else if (GhostColliders == null)
            {
                Colliders = this.GetComponentsInChildren <Collider>();
            }

            if (ExternalColliders != null)
            {
                ExternalColliders.Subscribe(this);
            }

            player.RegisterHand(this);

            if (player.PhysicalHands == true)
            {
                bool InitialState = false;

                if (PhysicalController != null)
                {
                    if (PhysicalController.State == true)
                    {
                        InitialState = true;
                    }
                    else
                    {
                        InitialState = false;
                    }
                    PhysicalController.Kill();
                }

                PhysicalController = this.gameObject.AddComponent <NVRPhysicalController>();
                PhysicalController.Initialize(this, InitialState);

                if (InitialState == true)
                {
                    ForceGhost();
                }

                GhostRenderers = this.GetComponentsInChildren <Renderer>();
                for (int rendererIndex = 0; rendererIndex < GhostRenderers.Length; rendererIndex++)
                {
                    Color transparentcolor = new Color(0.38f, 0.67f, 0.85f); // GhostRenderers[rendererIndex].material.color;
                    transparentcolor.a = (float)VisibilityLevel.Ghost / 100f;
                    NVRHelpers.SetTransparent(GhostRenderers[rendererIndex].material, transparentcolor);
                }

                if (Colliders != null)
                {
                    GhostColliders = Colliders;
                }

                CurrentVisibility = VisibilityLevel.Ghost;
            }
            else
            {
                GhostRenderers = this.GetComponentsInChildren <Renderer>();
                for (int rendererIndex = 0; rendererIndex < GhostRenderers.Length; rendererIndex++)
                {
                    Color transparentcolor = new Color(0.38f, 0.67f, 0.85f);// GhostRenderers[rendererIndex].material.color;
                    transparentcolor.a = (float)VisibilityLevel.Ghost / 100f;
                    NVRHelpers.SetTransparent(GhostRenderers[rendererIndex].material, transparentcolor);
                }

                if (Colliders != null)
                {
                    GhostColliders = Colliders;
                }

                CurrentVisibility = VisibilityLevel.Ghost;
            }

            CurrentHandState = HandState.Idle;
        }