Esempio n. 1
0
    public virtual void Awake()
    {
        StartPosition = transform.position;
        StartRotation = transform.rotation;

        var collider = GetComponent <Collider>();

        if (collider == null)
        {
            Debug.LogError(gameObject.name + "にColliderを付けてください。");
            return;
        }


        rigidBody = GetComponent <Rigidbody>();

        if (VRObjectMode != VRObjectMode.NeverMove)
        {
            if (ObjectTag == "")
            {
                transform.tag = "VRItem";
            }
            else
            {
                transform.tag = ObjectTag;
            }

            if (rigidBody == null)
            {
                rigidBody = gameObject.AddComponent <Rigidbody>();
            }
            rigidBody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
            rigidBody.useGravity             = UseGravity;
            if (Mass != 0)
            {
                rigidBody.mass = Mass;
            }

            //VelocityEstimat追加
            gameObject.AddComponent <VelocityEstimator>();

            //Interactable追加
            gameObject.AddComponent <Interactable>();

            if (VRObjectMode == VRObjectMode.Grabable)
            {
                //Throwable追加
                Throwable thro = gameObject.AddComponent <Throwable>();
                thro.onPickUp         = onPickUp;
                thro.onDetachFromHand = onThrowAway;

                //Attachイベント消去
                onAttachedToHand   = new UnityEvent();
                onDetachedFromHand = new UnityEvent();
            }

            //InteractableHoverEvents追加
            InteractableHoverEvents ihe = gameObject.AddComponent <InteractableHoverEvents>();
            ihe.onHandHoverBegin = onHandHoverBegin;
            ihe.onHandHoverEnd   = onHandHoverEnd;
            if (VRObjectMode != VRObjectMode.Attachable)
            {
                //Attachイベント消去
                onAttachedToHand   = new UnityEvent();
                onDetachedFromHand = new UnityEvent();
            }
            ihe.onAttachedToHand   = onAttachedToHand;
            ihe.onDetachedFromHand = onDetachedFromHand;
        }
        else
        {
            DestroyImmediate(rigidBody);
        }

        GameObject system = GameObject.Find("System");
    }
Esempio n. 2
0
    public void SetVRObjectMode(VRObjectMode mode)
    {
        this.VRObjectMode = mode;

        if (VRObjectMode != VRObjectMode.NeverMove)
        {
            transform.tag = "VRItem";

            if (rigidBody == null)
            {
                rigidBody = gameObject.AddComponent <Rigidbody>();
            }
            rigidBody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
            rigidBody.useGravity             = UseGravity;
            if (Mass != 0)
            {
                rigidBody.mass = Mass;
            }

            if (VRObjectMode == VRObjectMode.Grabable)
            {
                //Throwable追加
                Throwable thro = gameObject.GetComponent <Throwable>();
                if (!thro)
                {
                    thro = gameObject.AddComponent <Throwable>();
                }
                thro.onPickUp         = onPickUp;
                thro.onDetachFromHand = onThrowAway;

                //Attachイベント消去
                onAttachedToHand   = new UnityEvent();
                onDetachedFromHand = new UnityEvent();
            }
            else
            {
                Throwable thro = gameObject.GetComponent <Throwable>();
                if (thro)
                {
                    Destroy(thro);
                }
            }

            //InteractableHoverEvents追加
            InteractableHoverEvents ihe = gameObject.GetComponent <InteractableHoverEvents>();
            ihe.onHandHoverBegin = onHandHoverBegin;
            ihe.onHandHoverEnd   = onHandHoverEnd;
            if (VRObjectMode != VRObjectMode.Attachable)
            {
                //Attachイベント消去
                onAttachedToHand   = new UnityEvent();
                onDetachedFromHand = new UnityEvent();
            }
            ihe.onAttachedToHand   = onAttachedToHand;
            ihe.onDetachedFromHand = onDetachedFromHand;
        }
        else
        {
            DestroyImmediate(rigidBody);
            Throwable thro = gameObject.GetComponent <Throwable>();
            if (thro)
            {
                Destroy(thro);
            }
        }
    }