맥을 사용하게 기존에 사용하던 tortoise svn과 호환이 되지 않아

versions등 여러가지를 찾아보다가

snailSVN을 찾게 되어 lite가 아닌 유료버전을 설치하였다.

사용방법에 대해 자세히 설명해놓은 분의 글이 있어서 포스팅한다.

 

 

 

 

 

https://orbit-orbit.tistory.com/entry/Mac-%EB%A7%A5-%EC%9A%A9-SVN-

%EC%97%B0%EA%B2%B0%ED%95%98%EA%B8%B0-SnailSVN-Lite

 

[Mac] 맥 용 SVN 연결하기 : SnailSVN Lite

회사 업무로 인해 Mac에서 SVN을 사용하게 되었으므로 SnailSVN Lite를 활용하게 되었다. Mac의 SnailSVN은 window의 tortoiseSVN과 비슷하다고 하지만, 사용해 본 적이 없어서 모름. 우선 App Store에서 SnailSVN Lit

orbit-orbit.tistory.com

 

'Study > ' 카테고리의 다른 글

[Tip] 텍스트 코루틴 애니메이션  (0) 2024.07.16
[Tip]룰렛 원하는 곳에 위치 + 텍스트 출력  (0) 2024.06.29
[Tip] Mathf.DeltaAngle  (0) 2024.06.29
[Tip] Object.FindObjectOfType  (0) 2024.06.11
[Tip] RenderSettings  (0) 2024.06.05

 

 

 

 

 

 

IEnumerator CoTextFlow(string text)
{
    dialogText.text = "";
    string str = null;
    int length = 0;
    bool isScriptEnd = false;
    while (!isScriptEnd)
    {
        foreach (char ch in text)
        {
            str = str + ch;
            yield return new WaitForSeconds(0.035f);
            dialogText.text = str;
        }
        isScriptEnd = true;
    }
}

'Study > ' 카테고리의 다른 글

[Tip] 맥 SVN 설치 - snailSVN  (0) 2024.07.21
[Tip]룰렛 원하는 곳에 위치 + 텍스트 출력  (0) 2024.06.29
[Tip] Mathf.DeltaAngle  (0) 2024.06.29
[Tip] Object.FindObjectOfType  (0) 2024.06.11
[Tip] RenderSettings  (0) 2024.06.05

현재 룰렛은 8등분이 되어 있고

각각 360 / 8인 45도로 구성되어 있다.

그러므로 이 가운데 값은 22.5도이다.

룰렛을 개발자가 편하게 컨트롤 할 수 있도록 만들었다.

 

360도 * 횟수를 적용하여 여러번 돌아가고 거기에 지정한 extraAngle을 더해주면된다.

 

회전횟수를 선택할 수 있고 스탭을 조절함으로서 속도를 조절할 수 있다.

 

 

아래는 개발자들은 이미 사전에 클릭을 하면 알 수 있게 항목을 출력하도록 변경

나오는 것은 랜덤으로 변경

즉, 랜덤에 따라 특정 각도가 결정되고 그에 따라 개발자들은 출력결과를 미리 알수 있고,

유저들은 원하는 각도를 보게 되는 것이다.

 

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

public class RouletteTest : MonoBehaviour
{
    [SerializeField] private Button btnGetIem;
    [SerializeField] private Roulette _roulette;
    //[SerializeField] private float targetAngle = -22.5f; //클로버를 겨냥

    private string[] itemNames = { "폭탄" , "기력회복", "폭탄", "체력회복", "폭탄", "금화획득","폭탄", "네잎클로버"};
    private float[] targetAngles =
    {
        22.5f, 67.5f, 112.5f, 157.5f, 202.5f, 247.5f, 292.5f, 337.5f
    };
    void Start()
    {
        btnGetIem.onClick.AddListener(() =>
        {
            int idx = UnityEngine.Random.Range(0, 8); // 0 ~ 7
            Debug.Log($"<color=yellow>{itemNames[idx]}</color>");
            _roulette.StartRotate(targetAngles[idx]);
        });
    }

}

 

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

public class RouletteTest : MonoBehaviour
{
    [SerializeField] private Button btnGetIem;
    [SerializeField] private Roulette _roulette;
    //[SerializeField] private float targetAngle = -22.5f; //클로버를 겨냥

    private string[] itemNames = { "폭탄" , "기력회복", "폭탄", "체력회복", "폭탄", "금화획득","폭탄", "네잎클로버"};
    private float[] targetAngles =
    {
        22.5f, 67.5f, 112.5f, 157.5f, 202.5f, 247.5f, 292.5f, 337.5f
    };
    void Start()
    {
        btnGetIem.onClick.AddListener(() =>
        {
            int idx = UnityEngine.Random.Range(0, 8); // 0 ~ 7
            Debug.Log($"<color=yellow>{itemNames[idx]}</color>");
            _roulette.StartRotate(targetAngles[idx]);
        });
    }

}

'Study > ' 카테고리의 다른 글

[Tip] 맥 SVN 설치 - snailSVN  (0) 2024.07.21
[Tip] 텍스트 코루틴 애니메이션  (0) 2024.07.16
[Tip] Mathf.DeltaAngle  (0) 2024.06.29
[Tip] Object.FindObjectOfType  (0) 2024.06.11
[Tip] RenderSettings  (0) 2024.06.05

https://docs.unity3d.com/ScriptReference/Mathf.DeltaAngle.html

 

Unity - Scripting API: Mathf.DeltaAngle

Success! Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable. Close

docs.unity3d.com

'Study > ' 카테고리의 다른 글

[Tip] 텍스트 코루틴 애니메이션  (0) 2024.07.16
[Tip]룰렛 원하는 곳에 위치 + 텍스트 출력  (0) 2024.06.29
[Tip] Object.FindObjectOfType  (0) 2024.06.11
[Tip] RenderSettings  (0) 2024.06.05
[팁] Slider.onValueChanged  (0) 2024.06.05

블록에 BoxCollider2D를 부착한 후 클릭을 하면

해당 블록의 배열로서의 위치와 Vector2의 위치가 출력됨

 

 

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

public class AtlasManager : MonoBehaviour
{
    public static AtlasManager instance;
    public SpriteAtlas blockAtlas;
    //싱글톤
    private void Awake()
    {
        //AtlasManager 클래스의 인스턴스를 instance에 할당
        instance = this;
    }
}

 

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.U2D;
using Random = UnityEngine.Random;

public class Test : MonoBehaviour
{
    public Board board;
    private void Start()
    {
        board.CreateBoard();
    }
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            Debug.DrawRay(ray.origin, ray.direction * 100f, Color.red, 1);
            RaycastHit2D raycastHit2D = Physics2D.Raycast(ray.origin, ray.direction);
            if (raycastHit2D.collider != null)
            {
                Block block = raycastHit2D.collider.GetComponent<Block>();
                Debug.Log($"[{block.row}, {block.col}] ({block.transform.position.x}, {block.transform.position.y}), {block.blockType}");
            }
        }
    }
}

 

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using Random = UnityEngine.Random;

public class Board : MonoBehaviour
{
    private Block[,] board; //1차원 배열이 Block들을 관리
    public GameObject blockPrefab;

    public void CreateBoard()
    {
        //크기가 9인 BlockType의 1차원 배열 만들기
        board = new Block[5, 9]; // 2차원 배열로 변경
        //5행 9열의 Block타입의 2차원 배열 만들기
        for (int i = 0; i < board.GetLength(0); i++)
        {
            for (int j = 0; j < board.GetLength(1); j++)
            {
                CreateBlock(i, j);
            }
        }
        PrintBoard();
    }

    public void CreateBlock(int row, int col)
    {
        Vector2 pos = new Vector2(col, row);
        Block.BlockType blockType = (Block.BlockType)Random.Range(0, 5);
        GameObject blockGo = Instantiate(blockPrefab);
        Block block = blockGo.GetComponent<Block>();
        block.Init(blockType);
        block.SetPosition(pos);

        //배열의 요소에 블록 넣기
        board[row, col] = block;
    }

    public void PrintBoard()
    {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < board.GetLength(0); i++)
        {
            for (int j = 0; j < board.GetLength(1); j++)
            {
                sb.Append($"({i},{j})"); // StringBuilder에 문자열 추가
            }
            sb.AppendLine(); // 새로운 행 추가
        }
        Debug.Log(sb); // StringBuilder에 저장된 문자열을 출력
    }
}

 

using System.Collections;
using System.Collections.Generic;
using TMPro;
using Unity.Mathematics;
using UnityEngine;

public class Block : MonoBehaviour
{
    public enum BlockType
    {
        Blue, Gray, Green, Pink, Yellow
    }

    public BlockType blockType;
    public SpriteRenderer spriteRenderer;
    public TMP_Text debugText;
    public int row;
    public int col;
    public void Init(BlockType blockType)
    {
        this.blockType = blockType;
        //이미지 변경 
        ChangeSprite(blockType);
    }

    public void ChangeSprite(BlockType blockType)
    {
        //블록의 이름을 넣어서 아틀라스에서 같은 이름인 sprite를 찾고 할당
        Sprite sp =
            AtlasManager.instance.blockAtlas.GetSprite(blockType.ToString());
        spriteRenderer.sprite = sp;
    }

    public void SetPosition(Vector2 pos)
    {
        transform.position = pos;
        var index = Position2Index(pos);
        row = index.row;
        col = index.col;
        debugText.text = $"[{index.row}, {index.col}]";
    }

    public static (int row, int col) Position2Index(Vector2 pos)
    {
        return ((int)pos.y, (int)pos.x);
    }

    public static (int x, int y) Index2Position(Vector2 index)
    {
        return ((int)index.x, (int)index.y);
    }
}

구조체 형식?

사용자 정의 형식

 

데이터와 관련 기능을 캡슐화할 수 있는 값 형식

 

동작을 거의 제공하지 않거나 작은 데이터 중심 형식을 설계하는데 사용 권장

 

struct 키워드를 사용하여 정의

 

https://www.youtube.com/watch?v=zL5rb-Q5WzE&list=PLTFRwWXfOIYBmr3fK17E0VhKPyYrGy75z&index=41

 

 

 

 

인스턴스는 new 키워드사용

모든 구조체 형식은 하나 이상의 생성자를 갖는다.

 

 

 

※클래스와 다른점

1. 값형식

2. 상속 불가능

 

매개변수 없는 생성자를 포함 불가

 

맴버 메서드에 virtual, protected 사용 불가

 

유형의 인스턴스가 작고 일반적으로 수명이 짧거나 다른 개체에 포함되는 경우

클래스 대신 구조체를 사용하는 것을 고려

 

다른 모든 경우는 클래스를 사용하자

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Stet39
{
 
    internal class Program
    {
        static void Main(string[] args)
        {
            //Position pos = new Position(1,1);
            //Position pos = new Position();
            //Position pos;
            //pos.x = 1;
            //pos.y = 1;
            //Console.WriteLine(pos);
            //Position pos = new Position(1,1);
            //pos.SetOrigin();
            //Console.WriteLine("{0}, {1}", pos.x, pos.y);

            Marine marine = new Marine(new Position(1,1));
            Console.WriteLine("마린의 현재 위치 : {0}, {1}", marine.position.x, marine.position.y); ;

            marine.Move(new Position(2, 3));
            Position pos = marine.GetPostion();
            Console.WriteLine("마린의 현재 위치 : {0}, {1}", pos.x, pos.y);

        }
    }
}

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Stet39
{
    struct Position
    {
        public int x;
        public int y;

        public Position(int x, int y)//매개 변수 없는 생성자 사용불가
        {
            this.x = x;
            this.y = y;
        }

        public void SetOrigin()
        {
            this.x = 0;
            this.y = 0;
        }
    }
}

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Stet39
{
    internal class Marine
    {
        public Position position;
        public Marine(Position position)
        {
            this.position = position;
        }
        public void Move(Position targetPosition)
        {
            Console.WriteLine("{0}, {1}로 이동합니다", targetPosition.x, targetPosition.y);
            this.position = targetPosition;
        }

        public Position GetPostion()
        {
            return this.position;
        }
    }
}

'Study > C#' 카테고리의 다른 글

[C#] 업캐스팅, 다운캐스팅  (0) 2024.06.13
[C#] 생성자 연결  (0) 2024.06.12
[C#] virtual, override  (0) 2024.06.12
[C#] 상속  (1) 2024.06.03
[C#] static 한정자  (0) 2024.06.02

업캐스팅?

인스턴스의 타입을 파생(자식) 클래스 타입에서

기본 클래스 타입으로 변환

 

다운 캐스팅?

인스턴스의 타입을 기본 클래스 타입에서

파생 클래스 타입으로 변환

 

업캐스팅은 암시적

https://www.youtube.com/watch?v=yVDljROH1Jg&list=PLTFRwWXfOIYBmr3fK17E0VhKPyYrGy75z&index=40
https://www.youtube.com/watch?v=yVDljROH1Jg&list=PLTFRwWXfOIYBmr3fK17E0VhKPyYrGy75z&index=40

 

다운캐스팅은 명시적

 

 

 

 

 

접근 가능한 맴버는 참조변수의 타입에 의해 결정됨

 

 

 

변환할 수 없는 경우 as 연산자가 null을 반환

캐스트 식과 달리 as 연산자는 예외를 throw하지 않는다.

 

as 연산자 변환 성공한 경우

 

as 연산자 변환 실패한 경우

 

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Step38
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Marine marine = new Marine();
            //marine.Attack();
            //marine.StimPack();

            //업캐스팅(암시적)
            //TerranUnit unit = new Marine();
            //unit.Attack();
            //unit.StimPack(); //호출 불가

            //업캐스팅 (명시적)
            //TerranUnit unit = (TerranUnit)new TerranUnit();
            //unit.Attack();
            //unit.StimPack(); //호출불가

            //TerranUnit unit =  new Marine(); //암시적 업캐스팅
            //Marine marine = (Marine)unit; //다운 캐스팅은 명시적이어야함
            //marine변수의 값은 Marine의 인스턴스
            //marine.Attack();
            //marine.StimPack(); //호출 가능

            /*주의 사항*/
            //부모 클래스 인스턴스 생성 후
            //자식 클래스 타입으로 (다운캐스팅) 할수 없다.
            //Marine marine = (Marine)new TerranUnit();
            //marine.Attack();
            //marine.StimPack(); //호출가능

            //is 연산자를 사용해서
            //형식 변환이 가능한지 테스트 가능

            //TerranUnit unit = new TerranUnit();
            //bool canDownCast = unit is Marine;
            //Console.WriteLine(canDownCast); //False

            //Marine marine = new Marine();
            //bool canUpCast = marine is TerranUnit;
            //Console.WriteLine(canUpCast); // True
            //TerranUnit unit = marine; //암시적 업캐스팅

            
            //TerranUnit unit = new Marine(); //암시적 업캐스팅
            //bool canUpCast = unit is TerranUnit;
            //Console.WriteLine(canUpCast); //True
            //Marine marine = (Marine)unit; //명시적 다운캐스팅

            //as 연산자를 사용해 명시적으로 캐스팅 하기
            //Marine marine = new Marine();
            //TerranUnit unit = marine as TerranUnit;
            //Console.WriteLine(unit); //Step38.Marine => 성공

            TerranUnit unit = new TerranUnit();
            Marine marine = unit as Marine;
            Console.WriteLine("marine : {0}", marine); //marine : => 변환이 실패하면 결과값은 null
            //즉, 예외를 발생시키지 않는다.

        }
    }
}

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Step38
{
    internal class TerranUnit
    {
        public void Attack()
        {
            Console.WriteLine("공격합니다.");
        }
        //public TerranUnit() { }
    }
}

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Step38
{
    internal class Marine : TerranUnit
    {
        public void StimPack()
        {
            Console.WriteLine("스팀팩을 활성화합니다.");
        }
    }
}

'Study > C#' 카테고리의 다른 글

[C#] 구조체  (0) 2024.06.14
[C#] 생성자 연결  (0) 2024.06.12
[C#] virtual, override  (0) 2024.06.12
[C#] 상속  (1) 2024.06.03
[C#] static 한정자  (0) 2024.06.02

생성자 연결은 생성자가 동일하거나

기본 클래스의 다른 생성자를 호출하는 접근 방식

즉, 생성자에서 다른 생성자 호출

 

여러 생성자를 정의하는 클래스가 있을 때 사용

 

 

가장 많은 매개변수로 구성된 하나의 생성자에만 값을 할당

그리고 다른 두 생성자가 호출될 때 해당 생성자 호출

 

상속에서 기본 생성자 연결

 

상속에서 매개변수 있는 생성자 연결

 

즉 , 생성자 연결을 통해 매개변수 수가 가장 많은 생성자가 호출된다

 

 

생성자 연결 과정

 

 

상속 생성자 연결 과정

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace Step37_3
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //new Marine();
            new Marine("홍길동");
            //new Marine("홍길동", 8);
        }
    }
}

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Step37_3
{
    internal class TerranUnit
    {
        protected string name;
        protected int damage;
        public TerranUnit()
        {
            Console.WriteLine("TerranUnit의 생성자");
        }

        public TerranUnit(string name) : this(name, 0)
        {
            this.name = name;
            Console.WriteLine("매개변수가 1개있는 생성자");
        }

        public TerranUnit(string name, int damage)
        {
            this.name = name;
            this.damage = damage;
            Console.Write("매개 변수가 2개 있는 TerranUnit 생성자");
        }
    }
}

 

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Step37_3
{
    internal class Marine : TerranUnit
    {
        public Marine() : base() //없으면 암시적으로 동작
        {
            Console.WriteLine("Marine 생성자");
        }

        public Marine(string name) : base(name) //매개변수 이름을 동일하게
        {
            Console.WriteLine("매개변수 1개 있는 Marine 생성자, name : {0} : ", this.name);
        }
        
        public Marine(string name, int damage) : base(name, damage)
        {
            Console.WriteLine("매개변수 2개 있는 Marine 생성자, name : {0}, damage : {1}", this.name, this.damage);
        }
    }
}

'Study > C#' 카테고리의 다른 글

[C#] 구조체  (0) 2024.06.14
[C#] 업캐스팅, 다운캐스팅  (0) 2024.06.13
[C#] virtual, override  (0) 2024.06.12
[C#] 상속  (1) 2024.06.03
[C#] static 한정자  (0) 2024.06.02

virtual 키워드는

기본 클래스에서 정의된 메서드를

파생 클래스에서 재정의하도록 허용

 

static, abstract, private 한정자와 함께 사용 불가

 

override 한정자?

상속된 메서드의 구현을 확장하거나 수정

 

https://www.youtube.com/watch?v=kmsocjH-keQ&list=PLTFRwWXfOIYBmr3fK17E0VhKPyYrGy75z&index=39

 

base 키워드?

파생 클래스 내에서 기본 클래스의 맴버에 엑세스하는데 사용

 

부모클래스에서 virtual
파생 클래스에서 override

자식 클래스에서 부모클래스 맴버 엑세스 base

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Step37_2
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Marine marine = new Marine();
            marine.name = "마린1";

            Firebat firebat = new Firebat();
            firebat.name = "파이어뱃1";

            marine.Attack();
            firebat.Attack();
        }
    }
}

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Step37_2
{
    class TerranUnit
    {
        public string name;
        //생성자
        public TerranUnit()
        {
            Console.WriteLine("TerranUnit 클래스의 생성자");
        }
        
        public virtual void Attack()
        {
            Console.WriteLine("{0}이(가) 공격 합니다", this.name);
        }
        protected void Reload(string weaponName) //자식만 접근 가능
        {
            Console.WriteLine("{0}이(가) {1}을 장전을 합니다", this.name, weaponName); ;
        }
    }
}

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Step37_2
{
    internal class Marine : TerranUnit
    {
        //생성자
        public Marine()
        {
            Console.WriteLine("Marine클래스의 생성자");
        }
        public override void Attack()
        {
            base.Reload("총");
            Console.WriteLine("{0}이(가) 총으로 공격합니다.", this.name);
        }
    }
}

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Step37_2
{
    internal class Firebat : TerranUnit
    {
        public Firebat()
        {
            Console.WriteLine("Firebat클래스의 생성자");
        }

        public override void Attack()
        {
            base.Reload("화염방사기");
            Console.WriteLine("{0}이(가) 화염방사기로 공격합니다.", this.name);
        }
        
        
    }
}

'Study > C#' 카테고리의 다른 글

[C#] 업캐스팅, 다운캐스팅  (0) 2024.06.13
[C#] 생성자 연결  (0) 2024.06.12
[C#] 상속  (1) 2024.06.03
[C#] static 한정자  (0) 2024.06.02
[C#] this 키워드  (0) 2024.05.31

한 것

2개 이하 클릭시 해제 하고 다른 스킬 선택가능

2개가 초과될 시 다른 스킬 버튼 interactable = fasle;

shuffle시 클릭 된 것들 초기화

 

+ 클릭 된 것들의 데이터를 매핑할 인포 클래스를 만들어 저장하여

지정된 경로에 저장이 된다.

 

해야 할 것

인포에 들어간 데이터를 위에 만들어논 슬롯에 들어가게 하며

슬롯에는 이미지

클릭 or 호버 시에는 각 스킬에 대한 정보가 나와야 한다.

 

 

using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.U2D;
using UnityEngine.UI;

public class SkillManager : MonoBehaviour
{
    public static SkillManager instance; // 싱글톤

    public SpriteAtlas skillsAtlas;
    public Button levelUpBtn;
    public Button closeBtn;
    public GameObject selectSkillPopUp;
    public SkillData[] skillDatas;
    private List<int> rememberRandomIndex = new List<int>();

    private void Awake() // 싱글톤
    {
        if (instance == null)
        {
            instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }
    }

    public void Start()
    {
        levelUpBtn.onClick.RemoveAllListeners();
        OnClickLevelUpBtn();
        OnClickCloseBtn();
        TextAsset asset = Resources.Load<TextAsset>("data/skills_data");
        string json = asset.text;

        skillDatas = JsonConvert.DeserializeObject<SkillData[]>(json);
    }

    public SkillData GetDataById(int id)
    {
        SkillData foundSkillData = null;
        foreach (SkillData skillData in skillDatas)
        {
            if (skillData.id == id)
            {
                foundSkillData = skillData;
                break;
            }
        }
        return foundSkillData;
    }

    public int GetRandomAtlasImgId(int randomIndex)
    {
        return skillDatas[randomIndex].id;
    }

    public string GetRandomAtlasName(int randomIndex)
    {
        return skillDatas[randomIndex].name;
    }

    public string GetRandomAtlasDesc(int randomIndex)
    {
        return skillDatas[randomIndex].desc;
    }

    public Sprite GetRandomAtlasImg(int randomIndex)
    {
        return skillsAtlas.GetSprite(skillDatas[randomIndex].name);
    }

    public int GetSkillsRandomNum()
    {
        int randomIndex;
        do
        {
            randomIndex = Random.Range(0, skillDatas.Length);
        } while (rememberRandomIndex.Contains(randomIndex));

        rememberRandomIndex.Add(randomIndex);

        Debug.Log("랜덤으로 선택된 스킬 인덱스: " + randomIndex);
        return randomIndex;
    }

    public void OnClickLevelUpBtn()
    {
        levelUpBtn.onClick.AddListener(() =>
        {
            selectSkillPopUp.SetActive(true);

            int randomIndex = GetSkillsRandomNum();

            GetRandomAtlasImg(randomIndex);
            GetRandomAtlasName(randomIndex);
            GetRandomAtlasDesc(randomIndex);
        });
    }

    public void OnClickCloseBtn()
    {
        closeBtn.onClick.AddListener(() =>
        {
            selectSkillPopUp.SetActive(false);
        });
    }
}

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
using UnityEngine.U2D;
using UnityEditor;
using Newtonsoft.Json;

public class SelectSkillPopUp : MonoBehaviour
{
    public GameObject[] selectSkills;
    public Image[] skillImgs;
    public TMP_Text[] skillIds;
    public TMP_Text[] skillNames;
    public TMP_Text[] skillDescs;

    public Button shuffleSkills;
    public Button selectBtn;
    public SpriteAtlas skillsAtlas;
    List<SkillData> skillList = new List<SkillData>();

    private int selectedCount = 0;
    private List<int> selectedIndexes = new List<int>();

    private List<SkillInfo> selectedSkillInfos = new List<SkillInfo>(); // 스킬 정보를 담을 리스트

    public void Start()
    {
        selectBtn.gameObject.SetActive(false);
        ShowLevelUp();

        foreach (var data in SkillManager.instance.skillDatas)
        {
            skillList.Add(data);
        }
        shuffleSkills.onClick.AddListener(ShuffleSkills);

        // Add click event to each skill object
        for (int i = 0; i < selectSkills.Length; i++)
        {
            int index = i;
            selectSkills[i].GetComponent<Button>().onClick.AddListener(() =>
            {
                ToggleSkill(index);
            });
        }

        // Select 버튼의 클릭 이벤트 추가
        selectBtn.onClick.AddListener(SaveSelectedSkillData);
    }

    public void ShowLevelUp()
    {
        selectedIndexes.Clear();

        for (int i = 0; i < skillImgs.Length; i++)
        {
            int randomIndex = SkillManager.instance.GetSkillsRandomNum();
            selectedIndexes.Add(randomIndex);

            skillImgs[i].sprite = SkillManager.instance.GetRandomAtlasImg(randomIndex);
            skillIds[i].text = SkillManager.instance.GetRandomAtlasImgId(randomIndex).ToString();
            skillNames[i].text = SkillManager.instance.GetRandomAtlasName(randomIndex);
            skillDescs[i].text = SkillManager.instance.GetRandomAtlasDesc(randomIndex);
        }
    }

    public void ShuffleSkills()
    {
        selectedCount = 0;

        for (int i = 0; i < skillImgs.Length; i++)
        {
            int randomIndex = GetUniqueRandomIndex();
            selectedIndexes[i] = randomIndex;

            skillIds[i].text = SkillManager.instance.GetRandomAtlasImgId(randomIndex).ToString();
            skillNames[i].text = SkillManager.instance.GetRandomAtlasName(randomIndex);
            skillDescs[i].text = SkillManager.instance.GetRandomAtlasDesc(randomIndex);
            skillImgs[i].sprite = SkillManager.instance.GetRandomAtlasImg(randomIndex);
            SetImageAlpha(skillImgs[i], 1f); // Reset alpha value
        }

        UpdateSelectBtn();
    }

    int GetUniqueRandomIndex()
    {
        int randomIndex;
        do
        {
            randomIndex = Random.Range(0, skillList.Count);
        } while (selectedIndexes.Contains(randomIndex));

        return randomIndex;
    }

    void SetImageAlpha(Image image, float alpha)
    {
        Color color = image.color;
        color.a = alpha;
        image.color = color;
    }

    void UpdateSelectBtn()
    {
        selectBtn.gameObject.SetActive(selectedCount == 2);
    }

    public void ToggleSkill(int index)
    {
        Image skillImage = skillImgs[index].GetComponent<Image>();
        float alpha = GetImageAlpha(skillImage);

        if (alpha == 1f)
        {
            // Select the skill
            if (selectedCount < 2)
            {
                SetImageAlpha(skillImage, 65f / 255f);
                selectedCount++;

                // 클릭된 스킬의 정보를 SkillInfo 객체에 담고 리스트에 추가
                SkillData selectedSkill = skillList[selectedIndexes[index]];
                SkillInfo skillInfo = new SkillInfo(selectedSkill.id, selectedSkill.name, selectedSkill.sprite_name, selectedSkill.desc);
                selectedSkillInfos.Add(skillInfo);
            }
        }
        else
        {
            // Deselect the skill
            SetImageAlpha(skillImage, 1f);
            selectedCount--;

            // 해당 스킬을 리스트에서 제거
            SkillData selectedSkill = skillList[selectedIndexes[index]];
            selectedSkillInfos.RemoveAll(skillInfo => skillInfo.id == selectedSkill.id);
        }

        UpdateSelectBtn();
    }

    float GetImageAlpha(Image image)
    {
        return image.color.a;
    }

    public void SaveSelectedSkillData()
    {
        // 선택된 스킬의 정보를 직렬화하여 로컬에 저장
        string json = JsonConvert.SerializeObject(selectedSkillInfos);
        // 저장할 경로를 지정하고 파일에 쓰기
        string filePath = Application.persistentDataPath + "/selected_skills.json";
        System.IO.File.WriteAllText(filePath, json);
        Debug.Log("Selected skill data saved to: " + filePath);
    }
    public List<SkillInfo> GetSelectedSkillInfos()
    {
        return selectedSkillInfos;
    }
}

 

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

public class SkillData
{
    public int id;
    public string name;
    public string sprite_name;
    public string desc;
}

 

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

public class SkillInfo
{
    public int id;
    public string name;
    public string sprite_name;
    public string desc;

    public SkillInfo(int id, string name, string sprite_name, string desc)
    {
        this.id = id;
        this.name = name;
        this.sprite_name = sprite_name;
        this.desc = desc;
    }
}

+ Recent posts