Example #1
0
    void PointCamera()
    {
        if (curMode == DialogMode.PC)
        {
            // Make the camera point at the PC
            // Focus on the speaker
            GameObject pc = stateManager.PC.gameObject;

            // Calculate a camera position in front of the speaker, facing them
            Camera.main.transform.position = pc.transform.position + pc.transform.forward * 0.5f + pc.transform.up * 1.6f;
            Camera.main.transform.rotation = Quaternion.LookRotation(
                pc.transform.forward * -0.5f,
                pc.transform.up
                );
        }
        else if (curMode == DialogMode.NPC)
        {
            // Play the current camera animation, if there is one
            // Use the default camera pointing via camera angle
            GameObject speaker, listener;
            Vector3    cameraPosition = Camera.main.transform.position;
            Quaternion cameraRotation = Camera.main.transform.rotation;

            if (curEntry.Speaker == "")
            {
                // Speaker is the current owner
                speaker = owner.gameObject;
            }
            else
            {
                speaker = stateManager.GetObjectByTag(curEntry.Speaker).gameObject;
            }

            // TODO: Support other listeners, will be important in K2?
            listener = stateManager.PC.gameObject;


            switch (curEntry.CameraAngle)
            {
            case 0:
            case 1:
                // Focus on the speaker
                // Calculate a camera position in front of the speaker, facing them
                cameraPosition = speaker.transform.position +
                                 speaker.transform.forward * 0.5f +
                                 speaker.transform.up * 1.5f;
                cameraRotation = Quaternion.LookRotation(speaker.transform.forward * -0.5f, speaker.transform.up);
                break;

            case 2:
                Vector3 delta = listener.transform.position - speaker.transform.position;
                // Behind the listener, facing the speaker
                cameraPosition = listener.transform.position +
                                 listener.transform.forward * -1f +
                                 speaker.transform.up * 1.5f;
                cameraRotation = Quaternion.LookRotation(delta, speaker.transform.up);
                break;

            case 3:
            case 5:
            case 6:
                cameraPosition = speaker.transform.position +
                                 speaker.transform.forward * 2.5f +
                                 speaker.transform.up * 1.5f;
                cameraRotation = Quaternion.LookRotation(speaker.transform.forward * -2.5f, speaker.transform.up);
                break;

            case 4:
                // Animated camera
                AnimationState selectedClip = GetAnimationState();

                Animation animator = cameraModel.GetComponent <Animation>();
                if (selectedClip != null)
                {
                    // Play the selected clip
                    animator.Play(selectedClip.name);
                }

                // Bind the camera transform to the camera model transform
                Transform cameraPos = null;
                foreach (Transform t in cameraModel.transform)
                {
                    if (t.name == "camerahook")
                    {
                        cameraPos = t;
                        break;
                    }
                }

                Camera.main.transform.localPosition = priorCamPos;
                Camera.main.transform.localRotation = priorCamRot;

                if (cameraPos != null)
                {
                    cameraPosition = cameraPos.transform.position;
                    cameraRotation = Quaternion.Euler(
                        cameraPos.transform.rotation.eulerAngles +
                        new Vector3(90, 0, 0)
                        );
                }
                break;

            //case 5:
            //    // Focus on listener (is broken in original game)
            //    break;
            //case 6:
            //    // Module-specific static camera
            //    break;
            default:
                // In this case, "break" is used literally
                break;
            }


            Camera.main.transform.position = cameraPosition;
            Camera.main.transform.rotation = cameraRotation;

            // Play animations for the current entry
            foreach (AuroraDLG.AEntry.AAnim anim in curEntry.AnimList)
            {
                string participant = anim.Participant;

                Debug.Log("Triggering dialog animation for " + participant);

                int animID = (int)anim.Animation;

                AuroraObject target = null;
                if (participant == "PLAYER")
                {
                    target = stateManager.PC;
                }
                else if (participant == null)
                {
                    // Not sure what to do here?
                }
                else
                {
                    target = stateManager.GetObjectByTag(participant);
                }

                if (target != null)
                {
                    target.PlayAnimation(animID);
                }
                else
                {
                    Debug.Log("Could not find target " + participant);
                }
            }
        }
    }