Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        ray = mainCamera.ScreenPointToRay(Input.mousePosition);
        Debug.DrawRay(ray.origin, ray.direction * 100, Color.red);

        if (Input.GetMouseButtonDown(0))
        {
            if (Physics.Raycast(ray, out rayCastHit))
            {
                // Debug.Log(rayCastHit.transform.name);

                // ChangeMaterialRelatedStuff();


                // for the newly made script "TransformationAndHighlight"; does the same thing as above block of code
                SetSelectedGameObject(rayCastHit.transform.gameObject);
                TransformationAndHighlight transformationAndHighlightScript = rayCastHit.transform.GetComponent <TransformationAndHighlight>();
                if (transformationAndHighlightScript)
                {
                    SelectObjectRelatedStuff(transformationAndHighlightScript);

                    // if any GameObject is selected, enable the related UIs as well and vice versa
                    SetActiveUI(transformationAndHighlightScript.SelectedStatus());
                }
                else
                {
                    Debug.Log("TransformationAndHighlight script not found");
                }
            }
        }
    }
Esempio n. 2
0
    // Unselect all other GameObject, Select the GameObject
    // Or just unselect the already clicked selected GameObject
    public void SelectObjectRelatedStuff(TransformationAndHighlight inTransformationAndHighlightScript)
    {
        // if the object is already selected, then we just need to unselect it
        // no need to go unselect every object in the scene
        if (inTransformationAndHighlightScript.SelectedStatus() == false)
        {
            // unselect all, then select the object so that only
            // one object is selected at a time
            UnSelectAll();
        }

        // then select/unselect the current object
        inTransformationAndHighlightScript.ChangeSelectedStatus();

        // if the object is selected, then set it to variable selectedGameObject
        // if unselected, set it to null
        if (inTransformationAndHighlightScript.SelectedStatus())
        {
            // it was already set at the start
        }
        else
        {
            selectedGameObject = null;
        }
    }
    // Use this for initialization
    void Awake()
    {
        Instance = this;

        // Set up a GestureRecognizer to detect Select gestures.
        recognizer         = new GestureRecognizer();
        recognizer.Tapped += (args) =>
        {
            // Send an OnSelect message to the focused object and its ancestors.
            if (FocusedObject != null)
            {
                Debug.Log("Current object : " + this.transform.name + " : Gesture object : " + FocusedObject.name);
                FocusedObject.SendMessageUpwards("OnSelect", SendMessageOptions.DontRequireReceiver);

                this.GetComponent <MouseClickDetection>().SetSelectedGameObject(FocusedObject);
                TransformationAndHighlight transformAndHighlight = FocusedObject.GetComponent <TransformationAndHighlight>();
                if (transformAndHighlight)
                {
                    this.GetComponent <MouseClickDetection>().SelectObjectRelatedStuff(transformAndHighlight);
                    this.GetComponent <MouseClickDetection>().SetActiveUI(transformAndHighlight.SelectedStatus());
                }
            }
        };
        recognizer.StartCapturingGestures();
    }