void OnEnable()
 {
     indexSelected           = 0;
     tpCamera                = (v3rdPersonCamera)target;
     tpCamera.indexLookPoint = 0;
     if (tpCamera.CameraStateList != null && (tpCamera.indexList < tpCamera.CameraStateList.tpCameraStates.Count) && tpCamera.CameraStateList.tpCameraStates[tpCamera.indexList].lookPoints.Count > 0)
     {
         tpCamera.transform.position = tpCamera.CameraStateList.tpCameraStates[tpCamera.indexList].lookPoints[0].positionPoint;
         tpCamera.transform.rotation = Quaternion.Euler(tpCamera.CameraStateList.tpCameraStates[tpCamera.indexList].lookPoints[0].eulerAngle);
     }
 }
    void OnSceneGUI()
    {
        if (Application.isPlaying)
        {
            return;
        }
        tpCamera = (v3rdPersonCamera)target;

        if (tpCamera.gameObject == Selection.activeGameObject)
        {
            if (tpCamera.CameraStateList != null && tpCamera.CameraStateList.tpCameraStates != null && tpCamera.CameraStateList.tpCameraStates.Count > 0)
            {
                if (tpCamera.CameraStateList.tpCameraStates[tpCamera.indexList].cameraMode != TPCameraMode.FixedPoint)
                {
                    return;
                }
                try
                {
                    for (int i = 0; i < tpCamera.CameraStateList.tpCameraStates[tpCamera.indexList].lookPoints.Count; i++)
                    {
                        if (indexSelected == i)
                        {
                            Handles.color = Color.blue;
                            tpCamera.CameraStateList.tpCameraStates[tpCamera.indexList].lookPoints[i].positionPoint = tpCamera.transform.position;
                            tpCamera.CameraStateList.tpCameraStates[tpCamera.indexList].lookPoints[i].eulerAngle    = tpCamera.transform.eulerAngles;
                            if (tpCamera.CameraStateList.tpCameraStates[tpCamera.indexList].lookPoints[indexSelected].freeRotation)
                            {
                                Handles.SphereCap(0, tpCamera.CameraStateList.tpCameraStates[tpCamera.indexList].lookPoints[i].eulerAngle, Quaternion.identity, 0.5f);
                            }
                            else
                            {
                                Handles.DrawLine(tpCamera.CameraStateList.tpCameraStates[tpCamera.indexList].lookPoints[i].positionPoint,
                                                 tpCamera.target.position);
                            }
                        }
                        else if (Handles.Button(tpCamera.CameraStateList.tpCameraStates[tpCamera.indexList].lookPoints[i].positionPoint, Quaternion.identity, 0.5f, 0.3f, Handles.SphereCap))
                        {
                            indexSelected               = i;
                            tpCamera.indexLookPoint     = i;
                            tpCamera.transform.position = tpCamera.CameraStateList.tpCameraStates[tpCamera.indexList].lookPoints[i].positionPoint;
                            tpCamera.transform.rotation = Quaternion.Euler(tpCamera.CameraStateList.tpCameraStates[tpCamera.indexList].lookPoints[i].eulerAngle);
                        }
                        Handles.color = Color.white;
                        Handles.Label(tpCamera.CameraStateList.tpCameraStates[tpCamera.indexList].lookPoints[i].positionPoint, tpCamera.CameraStateList.tpCameraStates[tpCamera.indexList].lookPoints[i].pointName);
                    }
                }
                catch { if (tpCamera.indexList > tpCamera.CameraStateList.tpCameraStates.Count - 1)
                        {
                            tpCamera.indexList = tpCamera.CameraStateList.tpCameraStates.Count - 1;
                        }
                }
            }
        }
    }
        private void Start()
        {
            m_Character      = GetComponent <CharacterControler>();
            m_camObject      = GameObject.FindWithTag("MainCamera");
            m_camControl     = m_camObject.GetComponent <v3rdPersonCamera>();
            m_DrainRescourse = GetComponent <DrainLucidityAct>();
            m_CastRescourse  = GetComponent <SpendLucidityAct>();
            m_mainCam        = GameObject.FindWithTag("MainCamera").GetComponent <Camera>();

            m_Cam = m_mainCam.transform;
        }
        protected virtual void CharacterInit()
        {
            cc = GetComponent <vThirdPersonController>();
            if (cc != null)
            {
                cc.Init();
            }

            tpCamera = FindObjectOfType <v3rdPersonCamera>();
            if (tpCamera)
            {
                tpCamera.SetMainTarget(this.transform);
            }

            // Cursor.visible = false;
            // Cursor.lockState = CursorLockMode.Locked;
        }
 protected virtual void UpdateCameraStates()
 {
     // CAMERA STATE - you can change the CameraState here, the bool means if you want lerp of not, make sure to use the same CameraState String that you named on TPCameraListData
     if (tpCamera == null)
     {
         tpCamera = FindObjectOfType <v3rdPersonCamera>();
         if (tpCamera == null)
         {
             return;
         }
         if (tpCamera)
         {
             tpCamera.SetMainTarget(this.transform);
             tpCamera.Init();
         }
     }
 }
    public override void OnInspectorGUI()
    {
        if (!skin)
        {
            skin = Resources.Load("skin") as GUISkin;
        }
        GUI.skin = skin;

        tpCamera = (v3rdPersonCamera)target;

        EditorGUILayout.Space();



        GUILayout.BeginVertical("3rd Person Camera by Invector", "window");
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();

        if (tpCamera.cullingLayer == 0)
        {
            EditorGUILayout.Space();
            EditorGUILayout.HelpBox("Please assign the Culling Layer to 'Default' ", MessageType.Warning);
            EditorGUILayout.Space();
        }

        EditorGUILayout.HelpBox("The target will be assign automatically to the current Character when start, check the InitialSetup method on the Motor.", MessageType.Info);

        base.OnInspectorGUI();
        GUILayout.EndVertical();

        GUILayout.BeginVertical("Camera States", "window");

        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();

        EditorGUILayout.HelpBox("This settings will always load in this List, you can create more List's with different settings for another characters or scenes", MessageType.Info);

        tpCamera.CameraStateList = (v3rdPersonCameraListData)EditorGUILayout.ObjectField("CameraState List", tpCamera.CameraStateList, typeof(v3rdPersonCameraListData), false);
        if (tpCamera.CameraStateList == null)
        {
            GUILayout.EndVertical();
            return;
        }
        GUILayout.BeginHorizontal();
        if (GUILayout.Button(new GUIContent("New CameraState")))
        {
            if (tpCamera.CameraStateList.tpCameraStates == null)
            {
                tpCamera.CameraStateList.tpCameraStates = new List <v3rdPersonCameraState>();
            }

            tpCamera.CameraStateList.tpCameraStates.Add(new v3rdPersonCameraState("New State" + tpCamera.CameraStateList.tpCameraStates.Count));
            tpCamera.indexList = tpCamera.CameraStateList.tpCameraStates.Count - 1;
        }

        if (GUILayout.Button(new GUIContent("Delete State")) && tpCamera.CameraStateList.tpCameraStates.Count > 1 && tpCamera.indexList != 0)
        {
            tpCamera.CameraStateList.tpCameraStates.RemoveAt(tpCamera.indexList);
            if (tpCamera.indexList - 1 >= 0)
            {
                tpCamera.indexList--;
            }
        }

        GUILayout.EndHorizontal();

        if (tpCamera.CameraStateList.tpCameraStates.Count > 0)
        {
            tpCamera.indexList = EditorGUILayout.Popup("State", tpCamera.indexList, getListName(tpCamera.CameraStateList.tpCameraStates));

            StateData(tpCamera.CameraStateList.tpCameraStates[tpCamera.indexList]);
        }

        GUILayout.EndVertical();
        EditorGUILayout.Space();

        if (GUI.changed)
        {
            EditorUtility.SetDirty(tpCamera);
            EditorUtility.SetDirty(tpCamera.CameraStateList);
        }
    }
        public void Init()
        {
            // this method is called on the ThirdPersonController or TopDownController - Start

            animator     = GetComponent <Animator>();
            tpCamera     = v3rdPersonCamera.instance;
            hud          = vHUDController.instance;
            meleeManager = GetComponent <vMeleeManager>();
            // create a offset pivot to the character, to align camera position when transition to ragdoll
            var hips = animator.GetBoneTransform(HumanBodyBones.Hips);

            offSetPivot = Vector3.Distance(transform.position, hips.position);

            if (tpCamera != null)
            {
                tpCamera.offSetPlayerPivot = offSetPivot;
                tpCamera.target            = transform;
            }

            if (hud == null)
            {
                Debug.LogWarning("Invector : Missing HUDController, please assign on ThirdPersonController");
            }

            // prevents the collider from slipping on ramps
            frictionPhysics                 = new PhysicMaterial();
            frictionPhysics.name            = "frictionPhysics";
            frictionPhysics.staticFriction  = 1f;
            frictionPhysics.dynamicFriction = 1f;

            // default physics
            slippyPhysics                 = new PhysicMaterial();
            slippyPhysics.name            = "slippyPhysics";
            slippyPhysics.staticFriction  = 0f;
            slippyPhysics.dynamicFriction = 0f;

            // rigidbody info
            _rigidbody = GetComponent <Rigidbody>();

            // capsule collider
            _capsuleCollider = GetComponent <CapsuleCollider>();

            // save your collider preferences
            colliderCenter = GetComponent <CapsuleCollider>().center;
            colliderRadius = GetComponent <CapsuleCollider>().radius;
            colliderHeight = GetComponent <CapsuleCollider>().height;

            // health info
            currentHealth = maxHealth;
            currentHealthRecoveryDelay = healthRecoveryDelay;
            currentStamina             = maxStamina;

            // stopmove info
            canMoveForward = true;
            canMoveRight   = true;
            canMoveLeft    = true;
            canMoveBack    = true;

            if (hud == null)
            {
                return;
            }

            hud.damageImage.color = new Color(0f, 0f, 0f, 0f);

            cameraTransform.SendMessage("Init", SendMessageOptions.DontRequireReceiver);
            UpdateHUD();
        }