コード例 #1
0
    private void Update()
    {
        if ((Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.Mouse0)) && !grabSensorScript.isGrabbing && !isInteracting)
        {
            Debug.Log("Click!");
            doInteraction = true;
        }
        Ray ray = mainCamera.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2));

        if (Physics.Raycast(ray, out raycastHit, maxDistance, 1 << interactionLayer) && doInteraction)
        {
            doInteraction = false;
            Debug.Log("Raycast Hit");
            EnterInteraction();
            currentInteraction = raycastHit.collider.gameObject;
            if (currentInteraction.name == "Computer Base")
            {
                ComputerMainScript computerScript = currentInteraction.transform.GetChild(0).GetChild(0).GetComponent <ComputerMainScript>();
                computerScript.gameObject.SetActive(true);
                computerScript.currentPlayer = gameObject;
                computerScript.OnInteract.Invoke();
            }
            else
            {
                Interactable interactionScript = currentInteraction.GetComponent <Interactable>();
                interactionScript.currentPlayer = gameObject;
            }
            Interactable interactDetails = currentInteraction.GetComponent <Interactable>();
            Vector3      newPos          = currentInteraction.transform.TransformPoint(interactDetails.xOffset, 0, interactDetails.viewDistance);
            newPos.y = interactDetails.viewHeight;
            Vector3 newRotation = currentInteraction.transform.rotation.eulerAngles;
            newRotation.y -= 180;
            gameObject.transform.position      = newPos;
            gameObject.transform.rotation      = Quaternion.Euler(newRotation);
            mainCamera.transform.localRotation = Quaternion.identity;
        }
        if (currentInteraction != null)
        {
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                if (currentInteraction.name != "Computer Base")
                {
                    ExitInteraction();
                }
                else
                {
                    currentInteraction.transform.Find("Computer").Find("Computer Screen").gameObject.GetComponent <ComputerMainScript>().ExitComputer();
                }
            }
        }
        doInteraction = false;
    }
コード例 #2
0
 private void Start()
 {
     computer = GetComponent <ComputerMainScript>();
 }
コード例 #3
0
    private void OnGUI()
    {
        if (!computer)
        {
            computerObject = (GameObject)EditorGUILayout.ObjectField("Computer screen", computerObject, typeof(GameObject), true);
            if (computerObject)
            {
                computer = computerObject.GetComponent <ComputerMainScript>();
                LoadUsers();
            }
        }
        else
        {
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos, false, false);
            if (computerObject)
            {
                chosenUser = (ComputerMainScript.EnumUsers)EditorGUILayout.EnumPopup("User", chosenUser);

                currentUser = computer.ConvertEnumToUser(chosenUser);
            }
            if (currentUser != null)
            {
                if (currentUser.notes != null)
                {
                    for (int i = 0; i < currentUser.notes.Count; i++)
                    {
                        EditorGUILayout.LabelField("Note #" + (i + 1).ToString());
                        {
                            currentUser.notes[i].subject     = EditorGUILayout.TextField(currentUser.notes[i].subject, EditorStyles.textField);
                            currentUser.notes[i].content     = EditorGUILayout.TextArea(currentUser.notes[i].content, EditorStyles.textArea, GUILayout.Height(80));
                            currentUser.notes[i].notepadText = EditorGUILayout.TextArea(currentUser.notes[i].notepadText, EditorStyles.textArea, GUILayout.Height(80));
                        }
                    }
                }

                if (GUILayout.Button("Add new note"))
                {
                    currentUser.notes.Add(new Note());
                }

                if (GUILayout.Button("Remove last note"))
                {
                    currentUser.notes.RemoveAt(currentUser.notes.Count - 1);
                }

                EditorGUILayout.Space(10);

                if (currentUser.emails != null)
                {
                    for (int i = 0; i < currentUser.emails.Count; i++)
                    {
                        EditorGUILayout.LabelField("Email #" + (i + 1).ToString());
                        {
                            currentUser.emails[i].subject     = EditorGUILayout.TextField(currentUser.emails[i].subject, EditorStyles.textField);
                            currentUser.emails[i].recipient   = EditorGUILayout.TextField(currentUser.emails[i].recipient, EditorStyles.textField);
                            currentUser.emails[i].sender      = EditorGUILayout.TextField(currentUser.emails[i].sender, EditorStyles.textField);
                            currentUser.emails[i].content     = EditorGUILayout.TextArea(currentUser.emails[i].content, EditorStyles.textArea, GUILayout.Height(80));
                            currentUser.emails[i].notepadText = EditorGUILayout.TextArea(currentUser.emails[i].notepadText, EditorStyles.textArea, GUILayout.Height(80));
                        }
                    }
                }

                if (GUILayout.Button("Add new email"))
                {
                    currentUser.emails.Add(new Email());
                }

                if (GUILayout.Button("Remove last email"))
                {
                    currentUser.emails.RemoveAt(currentUser.emails.Count - 1);
                }

                EditorGUILayout.Space(10);

                if (GUILayout.Button("Save"))
                {
                    SaveUsers();
                }

                if (GUILayout.Button("Cancel"))
                {
                    LoadUsers();
                }
            }
            EditorGUILayout.EndScrollView();
        }
    }