月份:2021年4月

git退回或者git放弃当前修改时的各种基本操作

  1. 未使用git add 缓存代码
    使用git checkout -- filename,注意中间有--

    git checkout -- filename

    放弃所有文件修改 git checkout .

    git checkout .

    此命令用来放弃掉所有还没有加入到缓存区(就是 git add 命令)的修改:内容修改与整个文件删除
    此命令不会删除新建的文件,因为新建的文件还没加入git管理系统中,所以对git来说是未知,只需手动删除即可

  2. 已使用git add 缓存代码,未使用git commit
    使用 git reset HEAD filename

    git reset HEAD filename

    放弃所有文件修改 git reset HEAD

    git reset HEAD

    此命令用来清除 git 对于文件修改的缓存。相当于撤销 git add 命令所在的工作。在使用本命令后,本地的修改并不会消失,而是回到了第一步1. 未使用git add 缓存代码,继续使用用git checkout -- filename,就可以放弃本地修改

  3. 已经用 git commit 提交了代码
    使用 git reset --hard HEAD^ 来回退到上一次commit的状态

    git reset --hard HEAD^

    或者回退到任意版本git reset --hard commit id ,使用git log命令查看git提交历史和commit id

    git reset --hard commit id

解决wordpress无法上传2M以上大文件大图片的方法

修改/etc/php.ini文件

upload_max_filesize = 128M 
post_max_size = 128M 
max_execution_time = 300 

重启apache服务

service php-fpm restart

如果报错:php-fpm.service not found 的话,可以查看服务器/etc/init.d/下面,对应的php的fpm名称,有时候会出现带版本好的情况,比如php7.2-fpm之类的,就执行

service php7.2-fpm restart

转:Unity相机跟随多种实现方式

转自:https://blog.csdn.net/qq_37310110/article/details/94007394

一:设置目标物为相机的父节点
描述:最简单,最基础,效果最不理想,锁死跟随视角

二:常规设置固定相对向量偏移
描述:推荐指数***,代码实现简,效果比较生硬

 public Transform target;
    private Vector3 offset;
    void Start()
    {
        //设置相对偏移
        offset = target.position - this.transform.position;
    }
    void Update()
    {
        //更新位置
        this.transform.position = target.position - offset;
    }

三:添加旋转角度
描述:推荐指数***,在二的基础上添加距离差值和旋转角度差值,效果流畅

   private Vector3 offset;//相机相对于玩家的位置
    public Transform target;
    private Vector3 pos;
    public float speed = 2;
    private void Start()
    {
        offset =  transform.position - target.position;
    }
    // Update is called once per frame
    void Update()
    {
        pos = target.position + offset;
        this.transform.position = Vector3.Lerp(transform.position, pos, speed * Time.deltaTime);//调整相机与玩家之间的距离

        Quaternion angel = Quaternion.LookRotation(target.position - transform.position);//获取旋转角度
        transform.rotation = Quaternion.Slerp(transform.rotation, angel, speed * Time.deltaTime);
    }
 

四: 第三背后视角
描述:推荐指数*****,流畅参数可调。对相机的位置实时计算

 public Transform target;
    public float distanceUp = 10f;//相机与目标的竖直高度参数
    public float distanceAway = 10f;//相机与目标的水平距离参数
    public float smooth = 2f;//位置平滑移动插值参数值
    public float camDepthSmooth = 20f;

    void Update()
    {
        // 鼠标轴控制相机的远近
        if ((Input.mouseScrollDelta.y < 0 && Camera.main.fieldOfView >= 3) || Input.mouseScrollDelta.y > 0 && Camera.main.fieldOfView <= 80)
        {
            Camera.main.fieldOfView += Input.mouseScrollDelta.y * camDepthSmooth * Time.deltaTime;
        }
    }

    void LateUpdate()
    {
        //计算出相机的位置
        Vector3 disPos = target.position + Vector3.up * distanceUp - target.forward * distanceAway;

        transform.position = Vector3.Lerp(transform.position, disPos, Time.deltaTime * smooth);
        //相机的角度
        transform.LookAt(target.position);
    }

五:自由 视角

using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;

public class target_control : MonoBehaviour {

    public Transform _target;
    public float distance = 50.0f;
    public float xSpeed = 250.0f;
    public float ySpeed = 120.0f;

    public int yMinLimit = -20;
    public int yMaxLimit = 80;

    private bool orbit = false;
    private bool pan = false;
    private bool zoom = false;
    private float zoomValue = 0;

    public float orbitDampX = 0.0f;
    public float orbitDampY = 0.0f;
    float panDampX = 0.0f;
    float panDampY = 0.0f;
    public float zoomDamp = 0.0f;
    public float dampingTime = 0.0f;

    public float x = 180.0f;
    public float y = 0.0f;

    public int planFactor = 5;
    public float zoomFactor = 2.0f;
    public Vector2 distLimit;

    public static Quaternion _rotation;
    public static Vector3 _position;
    public static target_control _target_control;
    public float _z_distance;
    private Vector3 angles;

    private Vector2 oldPosition1;   
    private Vector2 oldPosition2;

    public float _target_distance = 5;

    private float target_x;
    private float target_y;
    private Vector3 _target_pos = Vector3.zero;

    public bool change_distance() 
    {
        distance = Mathf.Lerp(distance, _target_distance, 0.04f);
        Debug.Log(distance + "/" + _target_distance);
        updateCamera();
        if (Mathf.Abs(distance - _target_distance) < 0.01f)
            return false;
        return true;
    }
    public bool change_distance(float _dis)
    {
        distance = Mathf.Lerp(distance, _dis, 0.004f);

        updateCamera();
        if (Mathf.Abs(distance - _dis) < 0.01f)
            return false;
        return true;
    }

    void Start()
    {
        _target_distance = distance;
        _z_distance = distance;
        angles = transform.eulerAngles;
        x = angles.y;
        y = angles.x;

        // Make the rigid body not change rotation
        if (GetComponent<Rigidbody>())
            GetComponent<Rigidbody>().freezeRotation = true;
    }
    // Update is called once per frame
    void LateUpdate () {

        if (EventSystem.current.IsPointerOverGameObject()||_target ==null)
        {
            return;
        }

        if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            if (Input.touchCount == 1)
            {
                if (Input.GetTouch(0).phase == TouchPhase.Moved)
                {
                    orbit = true;
                }
                else
                {
                    orbit = false;
                }
            }
            else
            {
                orbit = false;
            }

            if (Input.touchCount > 1)
            {
                if (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved)
                {
                    var tempPosition1 = Input.GetTouch(0).position;
                    var tempPosition2 = Input.GetTouch(1).position;
                    if (isEnlarge(oldPosition1, oldPosition2, tempPosition1, tempPosition2))
                    {
                        zoomValue = 0.1f;
                        zoom = true;
                    }
                    else
                    {
                        zoomValue = -0.1f;
                        zoom = true;
                    }
                    oldPosition1 = tempPosition1;
                    oldPosition2 = tempPosition2;
                }
                else
                {
                    zoom = false;
                }
            }
            else
            {
                zoom = false;
            }
        } 
       else if (Application.platform == RuntimePlatform.Android)
        {

            if (Input.touchCount == 1)
            {
                if (Input.GetTouch(0).phase == TouchPhase.Moved)
                {
                    orbit = true;
                }
                else
                {
                    orbit = false;
                }
            }
            else
            {
                orbit = false;
            }

            if (Input.touchCount > 1)
            {
                if (Input.GetTouch(0).phase == TouchPhase.Moved || Input.GetTouch(1).phase == TouchPhase.Moved)
                {
                    var tempPosition1 = Input.GetTouch(0).position;
                    var tempPosition2 = Input.GetTouch(1).position;
                    if (isEnlarge(oldPosition1, oldPosition2, tempPosition1, tempPosition2))
                    {
                        zoomValue = 0.1f;
                        zoom = true;
                    }
                    else
                    {
                        zoomValue = -0.1f;
                        zoom = true;
                    }
                    oldPosition1 = tempPosition1;
                    oldPosition2 = tempPosition2;
                }
                else
                {
                    zoom = false;
                }
            }
            else
            {
                zoom = false;
            }
        }
        else
        {
            if (Input.GetMouseButton(1))
            {
                orbit = true;
            }
            else
            {
                orbit = false;
            }

            if (Input.GetAxisRaw("Mouse ScrollWheel") != null)
            {
                zoomValue = Input.GetAxisRaw("Mouse ScrollWheel");
                zoom = true;
            }
            else
            {
                zoom = false;
            }
        }

        if (orbit)
        {

            orbitDampX = Mathf.Lerp(orbitDampX, Input.GetAxis("Mouse X"), dampingTime * Time.deltaTime);
            orbitDampY = Mathf.Lerp(orbitDampY, Input.GetAxis("Mouse Y"), dampingTime * Time.deltaTime);
        }
        else
        {
            orbitDampX = Mathf.Lerp(orbitDampX, 0, dampingTime * Time.deltaTime);
            orbitDampY = Mathf.Lerp(orbitDampY, 0, dampingTime * Time.deltaTime);
        }

        if (zoom)
        {
            zoomDamp = Mathf.Lerp(zoomDamp, zoomValue, dampingTime * Time.deltaTime);
        }
        else
        {
            zoomDamp = Mathf.Lerp(zoomDamp, 0, dampingTime * Time.deltaTime);
        }

        if (!checkLerp(orbitDampX, 0) || !checkLerp(orbitDampY, 0))
        {
            doOrbit();
        }
        if (!checkLerp(zoomDamp, 0))
        {
            doZoom();
        }

    }

    bool isEnlarge(Vector2 oP1,Vector2 oP2 , Vector2 nP1, Vector2 nP2 )  
    {   
        var leng1 =Mathf.Sqrt((oP1.x-oP2.x)*(oP1.x-oP2.x)+(oP1.y-oP2.y)*(oP1.y-oP2.y));   
        var leng2 =Mathf.Sqrt((nP1.x-nP2.x)*(nP1.x-nP2.x)+(nP1.y-nP2.y)*(nP1.y-nP2.y));   
        if(leng1<leng2)   
        {   
            //big
             return true;    
        }else   
        {   
            //small
            return false;    
        }   
    }

    bool checkLerp(float a,float b)
    {
        if (Mathf.Approximately(a, b))
        {
            return true;
        }
        return false;
    }
    void doOrbit()
    {
        if (_target) 
         {          
             x += orbitDampX * xSpeed * 0.02f;
             y -= orbitDampY * ySpeed * 0.02f;

            y = ClampAngle(y, yMinLimit, yMaxLimit);
            updateCamera();
        }
    }
    void doZoom()
    {
        distance -= zoomDamp * zoomFactor;
        distance = Mathf.Clamp(distance, -distLimit.x, distLimit.y);
        updateCamera();
    }

    void updateCamera()
    {
        var rotation = Quaternion.Euler(y, x, 0);
        var position = rotation * new Vector3(0.0f, 0.0f, -distance) + _target.position;

        transform.rotation = rotation;
        transform.position = position;
    }

    static float ClampAngle (float angle,float min,float max)
    {
        if (angle < -360)
            angle += 360;
        if (angle > 360)
            angle -= 360;
        return Mathf.Clamp(angle, min, max);
    }
}