/// <summary>
        /// initialize camera class
        /// </summary>
        public override void initialize()
        {
            if (m_initialized)
            {
                return;
            }

            base.initialize();

#if DEBUG_INFO
            if (Target == null)
            {
                Debug.LogError("object cannot be null" + " < " + this.ToString() + ">"); return;
            }
#endif

            m_ProtectFromWalls = GetComponent <ProtectFromWalls>();
            if (!m_ProtectFromWalls)
            {
                Debug.LogWarning("cannot find 'ProtectFromWalls' script");
            }

            m_currentTransform = Target;
            m_CurrentTargetPos = Target.position;
            m_offsetPosition   = transform.position - m_CurrentTargetPos;
            m_startingPosition = m_offsetPosition;

            Vector3 euler = transform.rotation.eulerAngles;
            m_StartRotationY = Quaternion.Euler(0.0f, euler.y, 0.0f);

            m_initialized = true;
        }
Пример #2
0
        BaseCamera _createCamera()
        {
            if (CharacterType == CharacterTypes.TopDown)
            {
                Transform camDefTargetXform = Utils.FindChildTransformByName(character.transform, "CameraDefaultTarget");
                if (!camDefTargetXform)
                {
                    GameObject cameraDefaultTarget = new GameObject("CameraDefaultTarget");
                    cameraDefaultTarget.transform.SetParent(character.transform);
                    Vector3 pos = new Vector3(0.0f, 1.63f, 0.0f);
                    cameraDefaultTarget.transform.localPosition = pos;
                    camDefTargetXform = cameraDefaultTarget.transform;
                }
                // check if camera exists
                GameObject camGO = GameObject.FindGameObjectWithTag("MainCamera");
                if (!camGO)
                {
                    Debug.Log("Creating camera...");
                    camGO = new GameObject("TopDownCamera");
                }
#if DEBUG_INFO
                else
                {
                    Debug.Log("Found camera...");
                }
#endif
                camGO.transform.SetParent(character.transform, false);
                Quaternion currentRotation = character.transform.rotation;
                Vector3    cpos            = new Vector3(6.744616f, 11.20537f, -0.4592583f);
                cpos = currentRotation * cpos;

                camGO.transform.position = character.transform.position + cpos;
                camGO.transform.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
                camGO.tag  = "MainCamera";
                camGO.name = "TopDownCamera";
                camGO.SetActive(true);
                addCommonCameraComponents(camGO);

                TopDownCamera tdc = camGO.GetComponent <TopDownCamera>();
                if (!tdc)
                {
                    tdc = Undo.AddComponent <TopDownCamera>(camGO);
                }
                tdc.Target = camDefTargetXform;

                Camera cam = camGO.GetComponent <Camera>();
                cam.hdr = true;

                return(tdc);
            }
            else
            {
                Transform camDefTargetXform = Utils.FindChildTransformByName(character.transform, "CameraDefaultTarget");
                if (!camDefTargetXform)
                {
                    GameObject cameraDefaultTarget = new GameObject("CameraDefaultTarget");
                    cameraDefaultTarget.transform.SetParent(character.transform);
                    Vector3 pos = new Vector3(0.184f, 1.771f, 0.0f);
                    cameraDefaultTarget.transform.localPosition = pos;
                    camDefTargetXform = cameraDefaultTarget.transform;
                }

                // check if camera exists on character
                Transform  camXform = Utils.FindChildTransformByTag(character.transform, "MainCamera");
                GameObject camGO    = null;
                if (!camXform)
                {
                    Debug.Log("Creating camera...");
                    camGO = new GameObject("OrbitCamera");
                }
                else
                {
                    Debug.Log("Found existing camera on character");
                    camGO = camXform.gameObject;
                }


                camGO.transform.SetParent(character.transform, false);

                Quaternion currentRotation = character.transform.rotation;
                Vector3    cpos            = new Vector3(0.03f, 2.04f, -3.167f);
                cpos = currentRotation * cpos;

                camGO.transform.position = character.transform.position + cpos;
                camGO.transform.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
                camGO.tag  = "MainCamera";
                camGO.name = "OrbitCamera";
                camGO.SetActive(true);

                addCommonCameraComponents(camGO);

                OrbitCameraController occ = camGO.GetComponent <OrbitCameraController>();
                if (!occ)
                {
                    occ = Undo.AddComponent <OrbitCameraController>(camGO);
                }
                occ.Target       = camDefTargetXform;
                occ.angularSpeed = 64.0f;
                occ.minXAngle    = -60.0f;
                occ.maxXAngle    = 45.0f;
                occ.minYAngle    = -180.0f;
                occ.maxYAngle    = 180.0f;
                occ.minZ         = 0.2f;
                occ.maxZ         = 1.6f;
                occ.zStep        = 0.1f;

                ProtectFromWalls pfw = camGO.GetComponent <ProtectFromWalls>();
                if (!pfw)
                {
                    pfw = Undo.AddComponent <ProtectFromWalls>(camGO);
                }
                // for some reason unity ( 5.2.2 ) dont recognize 'Default' layer in ' GetMask' method so i must add it after
                pfw.mask  = LayerMask.GetMask("DefaultSlope");
                pfw.mask |= 1 << LayerMask.NameToLayer("Default");


                pfw.clipMoveTime      = 0.0f;
                pfw.returnTime        = 0.5f;
                pfw.sphereCastRadius  = 0.05f;
                pfw.visualiseInEditor = true;
                pfw.closestDistance   = 0.05f;
                pfw.dontClipTag       = "Player";
                pfw.m_Pivot           = camDefTargetXform;

                Camera cam = camGO.GetComponent <Camera>();
                cam.hdr = true;

                return(occ);
            }
        }