2022년 9월 28일 수요일

git upload

 



git 업로드

서버와 다를상황(로컬에서 작업했을때)

git add .
git commit -m
git push 에서 에러남

에러가 난다(서버의 변경사항이 있다)
일단 커밋을 취소하고 stash해야함

git reset --soft HEAD^
git stash
git pull
git stash pop

여기서 충돌이 있으면 pop에서도 에러가 남

pop에러가나면
git reset HEAD origin/master

풀어준다음
git add . 아니면 git add [file]

그리고 git status 확인해주고

다시 commit하고 push 해주면 됨
git commit -m "변경이력저장"
git push -u origin master







2022년 9월 27일 화요일

unity mouse on ui

 


public bool IsPointerOverUIElement()
    {
        return IsPointerOverUIElement(GetEventSystemRaycastResults());
    }
    private bool IsPointerOverUIElement(List<RaycastResult> eventSystemRaysastResults)
    {
        for (int index = 0; index < eventSystemRaysastResults.Count; index++)
        {
            RaycastResult curRaysastResult = eventSystemRaysastResults[index];
            if (curRaysastResult.gameObject.layer == 5)
                return true;
        }
        return false;
    }
    static List<RaycastResult> GetEventSystemRaycastResults()
    {
        PointerEventData eventData = new PointerEventData(EventSystem.current);
        eventData.position = Input.mousePosition;
        List<RaycastResult> raysastResults = new List<RaycastResult>();
        EventSystem.current.RaycastAll(eventData, raysastResults);
        return raysastResults;
    }

    void Update()
    {

        if (!PlayerCam.gameObject.activeSelf)
            return;

        if (IsPointerOverUIElement())
        {
            HidePointObject();
            return;
        }


클릭했을때 체크라서 땟을때(MouseUP)는 또 변수가 하나 더 필요하다



 if (IsPointerOverUIElement())
        {
            isOnUi = true;
            HidePointObject();
            return;
        }

       


        if (Input.GetMouseButton(0))
        {
            ///현재 부딛힌 객체 확인하기
            isOnUi = false;
            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
            {


                //Debug.Log("tag:" + hit.transform.tag);
                if (hit.transform.tag == "ClickableFloor")
                {
                    ShowPointObject();
                    if (PointObject.activeSelf)
                    {
                        PointObject.transform.position = new Vector3(hit.point.x, Player.transform.position.y+1.2f, hit.point.z); ;
                    }
                }
                else
                {
                    HidePointObject();
                }
            }
        }



        if (Input.GetMouseButtonUp(0) && !isOnUi)
        {

            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
            {
                if (hit.transform.tag == "ClickableFloor")
                {
                    isOnUi=false;
                    PlayerSmoothMove(new Vector3(PointObject.transform.position.x, Player.transform.position.y, PointObject.transform.position.z));
                }
            }
        }







2022년 9월 25일 일요일

fade 효과

 



using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CilckMoveFade : MonoBehaviour
{
    public float animTime = 0.5f;         // Fade 애니메이션 재생 시간 (단위:초).  
    public Image fadeImage;            // UGUI의 Image컴포넌트 참조 변수.  

    void Awake()
    {
        // Image 컴포넌트를 검색해서 참조 변수 값 설정.  
       
    }


    public void FadeIn(float fadeOutTime, System.Action nextEvent = null)
    {
        StartCoroutine(CoFadeIn(fadeOutTime, nextEvent));
    }

    public void FadeOut(System.Action nextEvent = null)
    {
        StartCoroutine(CoFadeOut(animTime, nextEvent));
    }

    // 투명 -> 불투명
    IEnumerator CoFadeIn(float fadeOutTime, System.Action nextEvent = null)
    {
       
        Color tempColor = fadeImage.color;
        while (tempColor.a < 1f)
        {
            tempColor.a += Time.deltaTime / fadeOutTime;
            fadeImage.color = tempColor;

            if (tempColor.a >= 1f) tempColor.a = 1f;

            yield return null;
        }

        fadeImage.color = tempColor;
        if (nextEvent != null) nextEvent();
    }

    // 불투명 -> 투명
    IEnumerator CoFadeOut(float fadeOutTime, System.Action nextEvent = null)
    {
       
        Color tempColor = fadeImage.color;
        tempColor.a = 1;///불투명으로 설정
        while (tempColor.a > 0f)
        {
            tempColor.a -= Time.deltaTime / fadeOutTime;
            fadeImage.color = tempColor;

            if (tempColor.a <= 0f) tempColor.a = 0f;

            yield return null;
        }
        fadeImage.color = tempColor;
        if (nextEvent != null) nextEvent();
    }


}







2022년 9월 21일 수요일

unity tts

 




using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class tts : MonoBehaviour
{
    public AudioSource audioSource;

    // Start is called before the first frame update
    void Start()
    {
        audioSource = gameObject.GetComponent<AudioSource>();
        StartCoroutine(DownloadTheAudio());
    }

    IEnumerator DownloadTheAudio()
    {
// SampleText 에 원하는 글 넣으면 됨
// En-gb 한국어로 하고싶으면 Ko-gb 하니까 됨

        string url = "https://translate.google.com/translate_tts?ie=UTF-8&total=1&idx=0&textlen=32&client=tw-ob&q=SampleText&tl=En-gb";
        WWW www = new WWW(url);
        yield return www;

        audioSource.clip = www.GetAudioClip(false,true, AudioType.MPEG);
        audioSource.Play();
    }
}


unity array get next prev index

 


Clamp를 사용하면 원하는 값을 딱 얻을 수 있네


    설명
Clamps a value between a minimum float and maximum float value.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Update() {
        transform.position = new Vector3(Mathf.Clamp(Time.time, 1.0F, 3.0F), 0, 0);
    }
}
public static int Clamp (int value, int min, int max);
설명
Clamps value between min and max and returns value.

// Clamps the value 10 to be between 1 and 3.
// prints 3 to the console

Debug.Log(Mathf.Clamp(10, 1, 3));


무한루프


 public void Next_Color()
    {
        if (currnetIndex + 1 == color_materials.Length)
            currnetIndex = 0;
        else
            currnetIndex = Mathf.Clamp(currnetIndex + 1, 0, color_materials.Length- 1);


        SetObjectColor(color_materials[currnetIndex]);
    }
    public void Prev_Color()
    {
        if (currnetIndex-1 == -1)
            currnetIndex = color_materials.Length - 1;
        else
            currnetIndex = Mathf.Clamp(currnetIndex - 1, 0, color_materials.Length - 1);

        SetObjectColor(color_materials[currnetIndex]);
    }


예제


public void Prev_Help()
    {

        currnetIdx = Mathf.Clamp(currnetIdx - 1, 0, helpDatas.helperInfos.Count-1);
        tts.Instance.SpeechStop();

        HelperInfo result = helpDatas.helperInfos[currnetIdx];

        StartDroneMove(result.move, result.rotate);
        tts.Instance.Speech(result.txt_tts);

       
    }

    public void Next_Help()
    {

        currnetIdx = Mathf.Clamp(currnetIdx + 1, 0, helpDatas.helperInfos.Count-1);

       
        tts.Instance.SpeechStop();

        HelperInfo result = helpDatas.helperInfos[currnetIdx];
        StartDroneMove(result.move,result.rotate);
        tts.Instance.Speech(result.txt_tts);

       
       
    }

unity screen space to world space

 


screen space 에 있는 ui를 월드 오브젝트 (target), 쪽에 움직이고 싶을때

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using UnityEngine.UI;

public class ScreenSpaceToWorldPosition : MonoBehaviour
{

    public Transform Target;

    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
        transform.position = Camera.main.WorldToScreenPoint(new Vector3(Target.position.x, Target.position.y, Camera.main.nearClipPlane));
    }

    IEnumerator thread_positionUpdate()
    {
       
    }

}

2022년 9월 20일 화요일

unity grid laout cell size ChangebyScripts

 



using UnityEngine;
using System.Collections.Generic;
 
namespace UnityEngine.UI
{
    [AddComponentMenu("Layout/Auto Expand Grid Layout Group", 152)]
    public class AutoExpandGridLayoutGroup : LayoutGroup
    {
        public enum Corner { UpperLeft = 0, UpperRight = 1, LowerLeft = 2, LowerRight = 3 }
        public enum Axis { Horizontal = 0, Vertical = 1 }
        public enum Constraint { Flexible = 0, FixedColumnCount = 1, FixedRowCount = 2 }
 
        [SerializeField]
        protected Corner m_StartCorner = Corner.UpperLeft;
        public Corner startCorner { get { return m_StartCorner; } set { SetProperty(ref m_StartCorner, value); } }
 
        [SerializeField]
        protected Axis m_StartAxis = Axis.Horizontal;
        public Axis startAxis { get { return m_StartAxis; } set { SetProperty(ref m_StartAxis, value); } }
 
        [SerializeField]
        protected Vector2 m_CellSize = new Vector2(100, 100);
        public Vector2 cellSize { get { return m_CellSize; } set { SetProperty(ref m_CellSize, value); } }
 
        [SerializeField]
        protected Vector2 m_Spacing = Vector2.zero;
        public Vector2 spacing { get { return m_Spacing; } set { SetProperty(ref m_Spacing, value); } }
 
        [SerializeField]
        protected Constraint m_Constraint = Constraint.Flexible;
        public Constraint constraint { get { return m_Constraint; } set { SetProperty(ref m_Constraint, value); } }
 
        [SerializeField]
        protected int m_ConstraintCount = 2;
        public int constraintCount { get { return m_ConstraintCount; } set { SetProperty(ref m_ConstraintCount, Mathf.Max(1, value)); } }
 
        protected AutoExpandGridLayoutGroup()
        { }
 
#if UNITY_EDITOR
        protected override void OnValidate()
        {
            base.OnValidate();
            constraintCount = constraintCount;
        }
#endif
 
        public override void CalculateLayoutInputHorizontal()
        {
            base.CalculateLayoutInputHorizontal();
 
            int minColumns = 0;
            int preferredColumns = 0;
            if (m_Constraint == Constraint.FixedColumnCount)
            {
                minColumns = preferredColumns = m_ConstraintCount;
            }
            else if (m_Constraint == Constraint.FixedRowCount)
            {
                minColumns = preferredColumns = Mathf.CeilToInt(rectChildren.Count / (float)m_ConstraintCount - 0.001f);
            }
            else
            {
                minColumns = 1;
                preferredColumns = Mathf.CeilToInt(Mathf.Sqrt(rectChildren.Count));
            }
 
            SetLayoutInputForAxis(
                padding.horizontal + (cellSize.x + spacing.x) * minColumns - spacing.x,
                padding.horizontal + (cellSize.x + spacing.x) * preferredColumns - spacing.x,
                -1, 0);
        }
 
        public override void CalculateLayoutInputVertical()
        {
            int minRows = 0;
            if (m_Constraint == Constraint.FixedColumnCount)
            {
                minRows = Mathf.CeilToInt(rectChildren.Count / (float)m_ConstraintCount - 0.001f);
            }
            else if (m_Constraint == Constraint.FixedRowCount)
            {
                minRows = m_ConstraintCount;
            }
            else
            {
                float width = rectTransform.rect.size.x;
                int cellCountX = Mathf.Max(1, Mathf.FloorToInt((width - padding.horizontal + spacing.x + 0.001f) / (cellSize.x + spacing.x)));
                minRows = Mathf.CeilToInt(rectChildren.Count / (float)cellCountX);
            }
 
            float minSpace = padding.vertical + (cellSize.y + spacing.y) * minRows - spacing.y;
            SetLayoutInputForAxis(minSpace, minSpace, -1, 1);
        }
 
        public override void SetLayoutHorizontal()
        {
            SetCellsAlongAxis(0);
        }
 
        public override void SetLayoutVertical()
        {
            SetCellsAlongAxis(1);
        }
 
        private void SetCellsAlongAxis(int axis)
        {
            // Normally a Layout Controller should only set horizontal values when invoked for the horizontal axis
            // and only vertical values when invoked for the vertical axis.
            // However, in this case we set both the horizontal and vertical position when invoked for the vertical axis.
            // Since we only set the horizontal position and not the size, it shouldn't affect children's layout,
            // and thus shouldn't break the rule that all horizontal layout must be calculated before all vertical layout.
 
            if (axis == 0)
            {
                // Only set the sizes when invoked for horizontal axis, not the positions.
                for (int i = 0; i < rectChildren.Count; i++)
                {
                    RectTransform rect = rectChildren[i];
 
                    m_Tracker.Add(this, rect,
                        DrivenTransformProperties.Anchors |
                        DrivenTransformProperties.AnchoredPosition |
                        DrivenTransformProperties.SizeDelta);
 
                    rect.anchorMin = Vector2.up;
                    rect.anchorMax = Vector2.up;
                    rect.sizeDelta = cellSize;
                }
                return;
            }
 
            float width = rectTransform.rect.size.x;
            float height = rectTransform.rect.size.y;
 
            int cellCountX = 1;
            int cellCountY = 1;
            if (m_Constraint == Constraint.FixedColumnCount)
            {
                cellCountX = m_ConstraintCount;
                cellCountY = Mathf.CeilToInt(rectChildren.Count / (float)cellCountX - 0.001f);
            }
            else if (m_Constraint == Constraint.FixedRowCount)
            {
                cellCountY = m_ConstraintCount;
                cellCountX = Mathf.CeilToInt(rectChildren.Count / (float)cellCountY - 0.001f);
            }
            else
            {
                if (cellSize.x + spacing.x <= 0)
                    cellCountX = int.MaxValue;
                else
                    cellCountX = Mathf.Max(1, Mathf.FloorToInt((width - padding.horizontal + spacing.x + 0.001f) / (cellSize.x + spacing.x)));
 
                if (cellSize.y + spacing.y <= 0)
                    cellCountY = int.MaxValue;
                else
                    cellCountY = Mathf.Max(1, Mathf.FloorToInt((height - padding.vertical + spacing.y + 0.001f) / (cellSize.y + spacing.y)));
            }
 
            int cornerX = (int)startCorner % 2;
            int cornerY = (int)startCorner / 2;
 
            int cellsPerMainAxis, actualCellCountX, actualCellCountY;
            if (startAxis == Axis.Horizontal)
            {
                cellsPerMainAxis = cellCountX;
                actualCellCountX = Mathf.Clamp(cellCountX, 1, rectChildren.Count);
                actualCellCountY = Mathf.Clamp(cellCountY, 1, Mathf.CeilToInt(rectChildren.Count / (float)cellsPerMainAxis));
            }
            else
            {
                cellsPerMainAxis = cellCountY;
                actualCellCountY = Mathf.Clamp(cellCountY, 1, rectChildren.Count);
                actualCellCountX = Mathf.Clamp(cellCountX, 1, Mathf.CeilToInt(rectChildren.Count / (float)cellsPerMainAxis));
            }
 
            Vector2 requiredSpace = new Vector2(
                    actualCellCountX * cellSize.x + (actualCellCountX - 1) * spacing.x,
                    actualCellCountY * cellSize.y + (actualCellCountY - 1) * spacing.y
                    );
            Vector2 startOffset = new Vector2(
                    GetStartOffset(0, requiredSpace.x),
                    GetStartOffset(1, requiredSpace.y)
                    );
 
            for (int i = 0; i < rectChildren.Count; i++)
            {
                int positionX;
                int positionY;
                if (startAxis == Axis.Horizontal)
                {
                    positionX = i % cellsPerMainAxis;
                    positionY = i / cellsPerMainAxis;
                }
                else
                {
                    positionX = i / cellsPerMainAxis;
                    positionY = i % cellsPerMainAxis;
                }
 
                if (cornerX == 1)
                    positionX = actualCellCountX - 1 - positionX;
                if (cornerY == 1)
                    positionY = actualCellCountY - 1 - positionY;
 
                float realsize = ((width - (spacing[0] * (actualCellCountX - 1))) / actualCellCountX);
                SetChildAlongAxis(rectChildren[i], 0, startOffset.x + (realsize + spacing[0]) * positionX, realsize);
                SetChildAlongAxis(rectChildren[i], 1, startOffset.y + (cellSize[1] + spacing[1]) * positionY, cellSize[1]);
            }
        }
    }
}

git rejected error(feat. cherry-pick)

 문제 아무 생각 없이 pull을 받지않고 로컬에서 작업! 커밋, 푸시 진행을 해버렷다. push에선 remote와 다르니 당연히 pull을 진행해라고 하지만 로컬에서 작업한 내용을 백업하지 않고 진행하기에는 부담스럽다(로컬작업 유실 가능성) 해결하려...