Exemple #1
0
    void Update()
    {
        // Set origin of ray to 'center of screen' and direction of ray to 'cameraview'
        Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0F));

        RaycastHit hit; // Variable reading information about the collider hit

        // Cast ray from center of the screen towards where the player is looking
        if (Physics.Raycast(ray, out hit, Reach))
        {
            if (hit.collider.tag == "Throwable")
            {
                InReach = true;

                // Display the UI element when the player is in reach of the door
                if (TextActive == false && TextPrefab != null)
                {
                    TextPrefabInstance = Instantiate(TextPrefab);
                    TextActive         = true;
                    TextPrefabInstance.transform.SetParent(transform, true); // Make the player the parent object of the text element
                }

                // Give the object that was hit the name 'Door'
                GameObject Door = hit.transform.gameObject;

                // Get access to the 'Door' script attached to the object that was hit
                DoorRotationLite dooropening = Door.GetComponent <DoorRotationLite>();
            }



            else
            {
                InReach = false;

                // Destroy the UI element when Player is no longer in reach of the door
                if (TextActive == true)
                {
                    DestroyImmediate(TextPrefabInstance);
                    TextActive = false;
                }
            }
        }

        else
        {
            InReach = false;

            // Destroy the UI element when Player is no longer in reach of the door
            if (TextActive == true)
            {
                DestroyImmediate(TextPrefabInstance);
                TextActive = false;
            }
        }

        //Draw the ray as a colored line for debugging purposes.
        Debug.DrawRay(ray.origin, ray.direction * Reach, DebugRayColor);
    }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        DoorRotationLite DoorRotationLite = target as DoorRotationLite;

        string[] menuOptions = new string[2];
        menuOptions[0] = "Door";
        menuOptions[1] = "Rotations";

        EditorGUILayout.Space();

        ToolBarIndex = GUILayout.Toolbar(ToolBarIndex, menuOptions);

        GUIStyle style = new GUIStyle()
        {
            richText = true
        };

        switch (ToolBarIndex)
        {
        //Door and hinge settings
        case 0:
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("<b>Door Settings</b>", style);
            EditorGUILayout.PropertyField(doorScaleProp, new GUIContent("Scale"));
            EditorGUILayout.PropertyField(pivotPositionProp, new GUIContent("Pivot Position"));
            EditorGUILayout.Space();
            if (DoorRotationLite.DoorScale == DoorRotationLite.ScaleOfDoor.Unity3DUnits && DoorRotationLite.PivotPosition == DoorRotationLite.PositionOfPivot.Centered)
            {
                EditorGUILayout.LabelField("<b>Hinge Settings</b>", style);
                EditorGUILayout.PropertyField(hingePositionProp, new GUIContent("Position"));
                EditorGUILayout.Space();
            }

            if (DoorRotationLite.DoorScale == DoorRotationLite.ScaleOfDoor.Other && DoorRotationLite.PivotPosition == DoorRotationLite.PositionOfPivot.Centered)
            {
                EditorGUILayout.HelpBox("If your door is not scaled in Unity3D units and the pivot position is not already positioned correctly, the hinge algorithm will not work as expected.", MessageType.Error);
            }

            else if (Tools.pivotMode == PivotMode.Center)
            {
                EditorGUILayout.HelpBox("Make sure the tool handle is placed at the active object's pivot point.", MessageType.Warning);
            }

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("<b>Debug Settings</b>", style);
            EditorGUILayout.PropertyField(visualizeHingeProp, new GUIContent("Visualize Hinge", "Visualizes the position of the hinge in-game by a colored cube."));
            if (DoorRotationLite.VisualizeHinge)
            {
                EditorGUILayout.PropertyField(hingeColorProp, new GUIContent("Hinge Color", "The color of the visualization of the hinge."));
            }

            EditorGUILayout.Space();
            EditorGUILayout.LabelField(Styles.VersionLabel, Styles.centeredVersionLabel);
            serializedObject.ApplyModifiedProperties();
            break;

        case 1:
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("<b>Rotation Settings</b>", style);
            EditorGUILayout.PropertyField(initialAngleProp, new GUIContent("Initial Angle", "The initial angle of the door/window."));
            EditorGUILayout.PropertyField(rotationAngleProp, new GUIContent("Rotation Angle", "The amount of degrees the door/window rotates."));
            EditorGUILayout.PropertyField(rotationSideProp, new GUIContent("Rotation Side", "Which way the door will rotate."));
            EditorGUILayout.PropertyField(speedProp, new GUIContent("Speed", "The speed of the door."));
            EditorGUILayout.PropertyField(timesMoveableProp, new GUIContent("Times Moveable", "0 = infinite times"));

            EditorGUILayout.Space();
            EditorGUILayout.LabelField(Styles.VersionLabel, Styles.centeredVersionLabel);
            serializedObject.ApplyModifiedProperties();
            break;

        default: break;
        }

        if (Application.isPlaying)
        {
            return;
        }

        serializedObject.ApplyModifiedProperties();
    }
Exemple #3
0
    void Update()
    {
        if (ActionController.GetBlocked())
        {
            return;
        }

        // Set origin of ray to 'center of screen' and direction of ray to 'cameraview'
        Ray ray = MainCamera.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0F));

        RaycastHit hit; // Variable reading information about the collider hit

        // Cast ray from center of the screen towards where the player is looking
        if (Physics.Raycast(ray, out hit, Reach))
        {
            if (_interactibles.Contains(hit.collider.tag))
            {
                // Illuminate Object
                var newRenderer = hit.transform.GetComponent <Renderer>();
                if (newRenderer == null)
                {
                    newRenderer = hit.transform.GetComponentInChildren <Renderer>();
                }
                if (!_illuminatedObjectRenderer.Contains(newRenderer))
                {
                    DeIlluminate();
                }
                if (_illuminatedObjectRenderer.Count == 0 && (hit.collider.tag != "LightbulbHolder" || LightBulbsInHolder.Count > 0))
                {
                    _illuminatedObjectRenderer.Add(newRenderer);
                    _illuminatedObjectRenderer.AddRange(hit.transform.GetComponentsInChildren <Renderer>());
                    foreach (var r in _illuminatedObjectRenderer)
                    {
                        r.material.SetColor("_EmissionColor", _lighenColor);
                    }
                }
            }

            switch (hit.collider.tag)
            {
            case "Door":
                DoorRotationLite dooropening = hit.transform.gameObject.GetComponent <DoorRotationLite>();

                if (Input.GetButton("Action"))
                {
                    if (dooropening.RotationPending == false)
                    {
                        StartCoroutine(dooropening.Move());
                    }
                }
                break;

            case "Note":
                if (Input.GetButton("Action"))
                {
                    NotePanel.GetComponentInChildren <TextMeshProUGUI>().text = hit.collider.gameObject.name == "note" ? NoteText : BookText;
                    NotePanel.gameObject.SetActive(true);
                    ActionController.SetBlocked(true);
                }
                break;

            case "LightbulbHolder":
                if (Input.GetButton("Action"))
                {
                    while (_lightbulbGathered > 0)
                    {
                        var l = LightBulbsInHolder.First();
                        if (l != null)
                        {
                            l.SetActive(true);
                        }
                        _lightbulbGathered--;
                        LightBulbsInHolder.RemoveAt(0);
                    }
                }
                break;

            case "Bulb":
                if (Input.GetButton("Action"))
                {
                    hit.transform.gameObject.SetActive(false);
                    _lightbulbGathered++;
                }
                break;

            case "Switch":
                if (Input.GetButton("Action"))
                {
                    hit.transform.gameObject.tag = "Untagged";
                    hit.transform.gameObject.GetComponent <Animator>().SetTrigger("Press");
                    FrameSpriteObject.GetComponent <SpriteRenderer>().sprite = BagSprite;
                    ActionController.PressSwitch();
                    SoundsPlayer.PlayRipPaper();
                }
                break;

            case "Key":
                if (Input.GetButton("Action"))
                {
                    hit.transform.gameObject.SetActive(false);
                    ActionController.PossessKey();
                }
                break;

            case "LockedDoor":
                if (Input.GetButton("Action") && !hit.transform.gameObject.GetComponent <AudioSource>().isPlaying)
                {
                    hit.transform.gameObject.GetComponent <AudioSource>().Play();
                }
                break;

            default:
                DeIlluminate();
                break;
            }
        }
        else
        {
            DeIlluminate();
        }

        //Draw the ray as a colored line for debugging purposes.
        Debug.DrawRay(ray.origin, ray.direction * Reach, DebugRayColor);
    }