using UnityEngine;
using UnityEditor;



public class TexturePostProcessor : AssetPostprocessor

{

	void OnPostprocessTexture(Texture2D texture)

	{

		TextureImporter importer = assetImporter as TextureImporter;

		importer.textureType = TextureImporterType.Default;

		importer.anisoLevel = 1;

		importer.filterMode = FilterMode.Bilinear;

		importer.mipmapEnabled = false; // 밉맵설정

		importer.maxTextureSize = 1024; // 텍스쳐 사이즈 설정
		
		var textureImporter = assetImporter as TextureImporter;
		textureImporter.SetPlatformTextureSettings(new TextureImporterPlatformSettings
		{
			overridden = true,//탭킨다.
			name = "Standalone",//PC설정
			maxTextureSize=1024,//사이즈설정
			format = TextureImporterFormat.DXT1Crunched //포멧설정
        });


	}

	}

}

참고: 두나미스 테크니컬 아트 & 애니메이터 (Tech Art / Anim)

도움주신분들: 핑속님,성국님.

 

 

https://docs.unity3d.com/ScriptReference/TextureFormat.html

 

Unity - Scripting API: TextureFormat

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

 

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

텍스쳐 애니메이션 타일셋  (0) 2020.12.11
C# 기초 기억창고2  (0) 2020.12.11
유니티의 Object 이해  (0) 2020.12.06
Scene 재시작  (0) 2020.11.21
캐릭터 랜덤 모션  (0) 2020.11.02

- 스크립트 안에서 gameObject는 '나자신=해당Object 자신'이고 GameObject는 '다른 Object' 이다?

- 유니티에서 대문자로 시작되는 것들은 Class로 생각하면...

- 같은이름인데 소문자의 경우 클래스의 인스턴스라고 생각하면..

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

C# 기초 기억창고2  (0) 2020.12.11
텍스쳐를 자동으로 설정해봅시다.  (0) 2020.12.06
Scene 재시작  (0) 2020.11.21
캐릭터 랜덤 모션  (0) 2020.11.02
EditorWindow  (0) 2020.10.30
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class restart : MonoBehaviour
{
    void Update()
    {
        if (Input.GetKey(KeyCode.Space))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
        }
    }
}

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

텍스쳐를 자동으로 설정해봅시다.  (0) 2020.12.06
유니티의 Object 이해  (0) 2020.12.06
캐릭터 랜덤 모션  (0) 2020.11.02
EditorWindow  (0) 2020.10.30
간단한 애니메이션 스크립트  (0) 2020.09.08
public class NPC_Animation : MonoBehaviour
{
    Animator anim;

    // Start is called before the first frame update
    void Start()
    {
        anim = GetComponent<Animator>();
        anim.applyRootMotion = false;//humanoid에서 캐릭터 위치가 바뀌는것을 방지한다.
        
    }

    // Update is called once per frame
    void Update()
    {
        int pickAnumber = Random.Range(1, 6);
        anim.SetInteger("ani", pickAnumber); //ani라는 int를 animator에 추가

    }
}

캐릭터의 모션 파라미터 타입을 int로 설정한후에 랜덤으로 동작하게 만들었습니다.

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

유니티의 Object 이해  (0) 2020.12.06
Scene 재시작  (0) 2020.11.21
EditorWindow  (0) 2020.10.30
간단한 애니메이션 스크립트  (0) 2020.09.08
C# 기초 기억창고  (0) 2020.08.09
using UnityEngine;
using UnityEditor;
using System.Collections;

public class ryo_dir : EditorWindow
{
    [MenuItem("ZCustom/ryo_direct",false, priority:1)]//메뉴생성


    static void ShowWindow()
    {
        // 생성되어있는 윈도우를 가져온다. 없으면 새로 생성한다. 싱글턴 구조인듯하다
        ryo_dir window = (ryo_dir)EditorWindow.GetWindow(typeof(ryo_dir));

    }

    public string ABB;
    int BoxMaker=1;
    Object GoObject = null;
    Object SceneObject3 = null;

    void OnGUI()
    {
        ABB = EditorGUI.TextField(new Rect(10,10,300,17), "글자써봐", ABB);

        
        //버튼으로 오브젝트 실행
        BoxMaker = EditorGUI.IntField(new Rect(10, 30, 300, 17), "게임오브젝트", BoxMaker);

        if (GUI.Button(new Rect(100, 80, 80, 40), "BoxMaker"))
        {
            for (int i = 0; i < BoxMaker; i++)
            {
                GameObject obj = new GameObject();
                obj.name = "GameObject" + i;
            }
 
        }

        //버튼 위치보기
        GUI.Button(new Rect(100, 140, 80, 40), "Button2");  // 가로위치,세로위치,박스세로, 박스가로


        //버튼 띄우기
        GUILayout.Space(200);
        
        
        //오브젝트필드
        GoObject = EditorGUILayout.ObjectField("오브젝트넣기", GoObject, typeof(GameObject));
  
  		//씬넣기
        GUILayout.Space(5);
        SceneObject3 = EditorGUILayout.ObjectField("씬넣기", SceneObject3, typeof(SceneAsset));

    }

    // 또하나의 탭만들기
    [MenuItem("ZCustom/ryo_what2",false,priority:2)]
    static void Twwoo()
    {
        

    }

}

이것저것 모아봤습니다.

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

Scene 재시작  (0) 2020.11.21
캐릭터 랜덤 모션  (0) 2020.11.02
간단한 애니메이션 스크립트  (0) 2020.09.08
C# 기초 기억창고  (0) 2020.08.09
MiniPorfiler  (0) 2020.07.29
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class test_ani : MonoBehaviour
{
    Animator m_Animator;

    void Start()
    {
        //오브젝트에 넣는부분
        m_Animator = gameObject.GetComponent<Animator>();
    }

    void Update()
    {
        //트러거에 원하는 키패드를 넣고. 애니메이션 트리거 이름을 넣음 된다.
        if (Input.GetKey(KeyCode.Keypad0))
        {
            
            m_Animator.SetTrigger("sliding");
        }

        if (Input.GetKey(KeyCode.Keypad1))
        {
            
            m_Animator.SetTrigger("fall");
        }

        if (Input.GetKey(KeyCode.Keypad2))
        {
            
            m_Animator.SetTrigger("catch");
        }

        if (Input.GetKey(KeyCode.Keypad3))
        {
            
            m_Animator.SetTrigger("kick");
        }

        if (Input.GetKey(KeyCode.Keypad4))
        {
            
            m_Animator.SetTrigger("win");
        }

        if (Input.GetKey(KeyCode.Keypad5))
        {
            
            m_Animator.SetTrigger("jump");
        }


    }
}

넘버키를 누르면 해당되는 애니메이션이 발동하도록 짠 스크립트 입니다.

Animator가 물론 존재해야한다.

 

 

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

캐릭터 랜덤 모션  (0) 2020.11.02
EditorWindow  (0) 2020.10.30
C# 기초 기억창고  (0) 2020.08.09
MiniPorfiler  (0) 2020.07.29
object rotate by tag  (0) 2020.07.29

find / name / print

void start(){
    GameObject monster = GameObject.Find("Cube");
    GameObject koko = GameObject.Find("Cube");
    
    monster.name = "Orc";
    
    print(koko.name);
    }

결과 = orc

 

 

Public -스크립트 외부에서 수치를 변경이 가능해진다.

[Sytem.NonSerialized] - public 변수를 외부에서 변경을 못하게 한다. 

(애초에 public으로 안하면 될것을 왜이리 하는지 알수는 없지만...나중에 알게되겄지...)

public int myAge =10;

[Sytem.NonSerialized]
public int myAge =10;

void start(){
	print (myAge);
    }
    

결과 = 10 이거나 외부에서 넣은 수치

 

 

변수사용

int gogo =10;

void start(){
    print("who is"+ gogo);
    print("what is"+ gogo);
    print("where is"+ gogo);
    }
    
   

결과 = who is 10 , what is 10 , where is 10

 

void 활용영역

void는 공허(빈)라는 뜻이고 함수를 만드는데 사용된다. 함수는 ()가 있으며 가능하면 함수명 앞은 대문자로 한다.

void Start(){
	GoGo();
    GoGo();
    GoGo();
    GoGo();    
    }
    
void GoGo(){
    print ("What");
    print ("How");
    print ("YEA");
    }

결과 = what How YEA, what How YEA, what How YEA

 

int intOk; // intOk라는 정수형 변수를 만든다.
float Afloat = 10.5f //Afloat라는 실수형을 만들고 그 값을 10.5라고 넣는다.
float Bfloat = 9.5f //Bfloat라는 실수형을 만들고 그 값을 9.5라고 넣는다.

void FloatToint() //FloatToint라는 함수를 만든다.
{
}

void FloatToint(flaot _Af, float _Bf, String _TEX = "디폴트") //()안에는 입력받을 것을 넣는데 사용된다.
// _TEX에 넣을것이 없을때 디폴트라는 글자를 출력한다.
{
	intOk =(int)(_Af+_Bf); //_Af과 _Bf 더한것을 int정수형으로 변경하여, intOK에 담는다.
    print(intOk); //intOK를 출력한다.
    print(_TEX);
    
}

void Start() // 유니티에서 첫번째 실행하는 함수이다.
{
	FloatToint(Afloat,Bfloat, "Good"); // Afloat은 _Af에 들어가게 되고, Bfloat은 _Bf에 들어가게된다.
                                       // Good은 _TEX안에 들어가게 된다.
}

 

 

retrun 은 void를 사용하지 않는 함수를 사용할때 필요하다.

void Start(){
     int yourAge = GetYourAge();
     print(yourAge);    
     }
     
     
int GetYourAge(){
    return 30;
    }

결과 = 30

 

오버로딩

void Start(){
   int answerInt = AddTo(12,2);
   int answerInt2 = AddTo(2,4,6);
   float answerFloat = AddTo(5.2f,2f);
   
   print(answerFloat);
  
}

int AddTo(int numA, int numB){
    int sum = numA +numB
    return sum;
}

int AddTo(int numA, int numB, int numC){
    int sum = numA + numB + numC
    return sum;
}




float AddTo(float numA, float numB){
    float sum = numA +numB
    return sum;
}

결과 = 7.2

 

조건문

int hp =100;

void Start(){
}

void OnMouseDonw(){
     hp = hp-10;
     
     if(hp < 1){
         print("killed")
         print("HP:" +hp);
         Destroy(gameObject);
         
     }else if(hp<20){
         print("hurt...");
         print("HP:" +hp);
     
     }else{
         print("OK");
         print("HP:" +hp);
         }
    }

 

Switch문

pulbic int myHp= 50;

void Start(){
   }

vod OnMouseDonw(){
   case 10:
      print("NONO")
      break;
   case 20:
      print("NO")
      break;
   case 30:
      print("more")
      break;
   default:
      print("OK")
      break;
      
  }

결과 = OK

 

for 와  while (Loop문)

------ for ------ 반복횟수가 명확할때 주로 사용한다.

for (시작수:언제까지:증가수)

void Start(){
}

void OnMouseDown(){
    for( int i =0 ; i<10 ; i++){
        MoveForward();
    }
}

void MoveForward(){
        transform.Translate(0, 0, 0.1f);
}

다른 응용법
<<<<
int add = 0; // 시작수

void Start()
{

	for(;;) // ;만 남기고 나머지는 따로 처리하는 방식
	{
	if(add>5) // 언제까지
		break; // if 멈춤
    num = add+2; //(add +=2) 증가수
    }
}
>>>>>

------ while ------ 반복횟수가 명확하지 않을때 주로 사용한다.(어찌되었건 비슷하다.)

    void OnMouseDown()
    {
        int count = 0;
        while (count < 10)
        {
            MoveForward();
            count++;
        }
    }

    void MoveForward()
    {
        transform.Translate(0, 0, 0.1f);
    }

배열

int[ ] numbers = new int[5];

void Start(){
     numbers[0]=6;
     numbers[1]=2;
     numbers[2]=11;
     numbers[3]=3;
     numbers[4]=9;

     print(numbers[3]);
}

------ public ------

    public int[] numb;

    void Start()
    {
    }

    void OnMouseDown()
    {
        print(numb[numb.Length - 1]);
    }

void Start(){
    int[] points = {10,20,30,40};
    
    int sum = 0;// 무언가 우선 들어있어야한다.
    for(int i=0; i<point.Lenght;i++)
    { sum +=points[i]; }
    
    int average = sum / points.Length;
    Debug.Log(average);
    }
    

결과: 25

 

new 와 static

new는 클래스의 변수를 사용할때 재지정하여 사용하는것.

Static은 클래수의 변수에 직접 변수를 넣어서 사용하는것.

public class TestA
{
	private int a;
    public int b; // 이 부분을 활용.
    public static int c; // static처럼 외부에서 직접 사용되는 변수를 정적변수라고 한다.
}

public class Test : MonoBehaviour
{
	TestA a1 = new TestA(); //위에 클래스의 변수를 새로 지정해야 정상적으로 작동한다.
    TestA a2 = new TestA();
    TestA a3 = new TestA();
    
    void Start()
    {
    	Abc();    
    }
    
    void Abc()
    {
    a1.b = 5; // 클래스에 접근하여 수를 대입하는 방식이다.
    a2.b = 1;
    a3.b = 10;
    
    TestA.c = 20; // static의 경우 new를 사용하지 않고 직접 대입할수 있다. 클래스 자체를 수정하는것이다.
    //변수를 만들 필요가 없이 직접 대입한다.
    
    print(a1.b);
    print(a2.b);
    print(ac.b);
    print(TestA.c);
    
    
    }
    
    
}

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

캐릭터 랜덤 모션  (0) 2020.11.02
EditorWindow  (0) 2020.10.30
간단한 애니메이션 스크립트  (0) 2020.09.08
MiniPorfiler  (0) 2020.07.29
object rotate by tag  (0) 2020.07.29

유니티 보트어텍에 들어있는 포퍼먼스 테스트터 입니다.

using UnityEngine.Profiling;
using UnityEngine.Rendering;

namespace UnityEngine.Experimental.Rendering
{
    public class MiniProfiler : MonoBehaviour
    {
        private bool m_Enable = true;
        private const float kAverageStatDuration = 1.0f;            // stats refresh each second
        private int m_frameCount;
		private float m_AccDeltaTime;
        private string m_statsLabel;
        private GUIStyle m_style;

        private float[] m_frameTimes = new float[5000];
        private int m_totalFrames = 0;
        private float m_minFrameTime = 1000f;
        private float m_maxFrameTime = 0f;

        internal class RecorderEntry
        {
            public string name;
            public int callCount;
            public float accTime;
            public Profiling.Recorder recorder;
        };

		enum Markers
		{
			kRenderloop,
			kCulling,
            kShadows,
            kDraw,
            kPost,
		};
		
        RecorderEntry[] recordersList =
        {
			// Warning: Keep that list in the exact same order than SRPBMarkers enum
            new RecorderEntry() { name="UnityEngine.CoreModule.dll!UnityEngine.Rendering::RenderPipelineManager.DoRenderLoop_Internal()" },
            new RecorderEntry() { name="CullScriptable" },
            new RecorderEntry() { name="Shadows.ExecuteDrawShadows" },
            new RecorderEntry() { name="RenderLoop.ScheduleDraw" },
            new RecorderEntry() { name="Render PostProcessing Effects" },
        };

        void Awake()
        {
            for (int i = 0; i < recordersList.Length; i++)
            {
                var sampler = Sampler.Get(recordersList[i].name);
                if (sampler.isValid)
                    recordersList[i].recorder = sampler.GetRecorder();
            }

            m_style =new GUIStyle();
            m_style.fontSize = 18;
            m_style.normal.textColor = Color.white;

            ResetStats();

        }

        void RazCounters()
        {
            m_AccDeltaTime = 0.0f;
            m_frameCount = 0;
            for (int i = 0; i < recordersList.Length; i++)
            {
                recordersList[i].accTime = 0.0f;
                recordersList[i].callCount = 0;
            }
        }

        void    ResetStats()
        {
             m_statsLabel = "Gathering data...";
             RazCounters();
        }

        void Update()
        {
            if (m_Enable)
            {
                m_AccDeltaTime += Time.unscaledDeltaTime;
                m_frameCount++;

                m_frameTimes[(int) Mathf.Repeat(m_totalFrames, 5000)] = Time.unscaledDeltaTime;

                int frameFactor = Mathf.Clamp(m_totalFrames, 0, 5000);

                float m_averageFrameTime = 0f;
                
                for (int i = 0; i < frameFactor; i++)
                {
                    m_averageFrameTime += m_frameTimes[i];
                }

                if (m_frameCount > 10)
                {
                    m_minFrameTime = Time.unscaledDeltaTime < m_minFrameTime ? Time.unscaledDeltaTime : m_minFrameTime;
                    m_maxFrameTime = Time.unscaledDeltaTime > m_maxFrameTime ? Time.unscaledDeltaTime : m_maxFrameTime;
                }

                // get timing & update average accumulators
                for (int i = 0; i < recordersList.Length; i++)
                {
                    if (recordersList[i].recorder != null)
                    {
                        recordersList[i].accTime += recordersList[i].recorder.elapsedNanoseconds / 1000000.0f;      // acc time in ms
                        recordersList[i].callCount += recordersList[i].recorder.sampleBlockCount;
                    }
                }

				if (m_AccDeltaTime >= kAverageStatDuration)
				{

					float ooFrameCount = 1.0f / (float)m_frameCount;
					float avgLoop = recordersList[(int)Markers.kRenderloop].accTime * ooFrameCount;
					float avgCulling = recordersList[(int)Markers.kCulling].accTime * ooFrameCount;
					float avgShadow = recordersList[(int)Markers.kShadows].accTime * ooFrameCount;
					float avgDraw = recordersList[(int)Markers.kDraw].accTime * ooFrameCount;
					float avgPost = recordersList[(int)Markers.kPost].accTime * ooFrameCount;

					m_statsLabel = $"Rendering Loop Main Thread:{avgLoop:N}ms\n";
					m_statsLabel += $"    Culling:{avgCulling:N}ms\n";
					m_statsLabel += $"    Shadows:{avgShadow:N}ms\n";
					m_statsLabel += $"    Draws:{avgDraw:F2}ms\n";
					m_statsLabel += $"    PostProcessing:{avgPost:F2}ms\n";
					m_statsLabel += $"Total: {(m_AccDeltaTime * 1000.0f * ooFrameCount):F2}ms ({(int)(((float)m_frameCount) / m_AccDeltaTime)} FPS)\n";
                    
                    float frameMulti = 1f / frameFactor;
                    m_statsLabel += $"Average:{(m_averageFrameTime * 1000f * frameMulti):F2}ms\n";
                    m_statsLabel += $"Minimum:{m_minFrameTime * 1000f:F2}ms\n";
                    m_statsLabel += $"Maximum:{m_maxFrameTime * 1000f:F2}ms\n";
                    
					RazCounters();
				}
            }

            m_totalFrames++;
        }

        void OnGUI()
        {
            if (m_Enable)
            {
                bool SRPBatcher = UnityEngine.Rendering.Universal.UniversalRenderPipeline.asset.useSRPBatcher;

//                GUI.skin.label.fontSize = 15;
                GUI.color = new Color(1, 1, 1, 1);
                float w = 400, h = 300;

                if ( SRPBatcher )
                    GUILayout.BeginArea(new Rect(32, 50, w, h), "(SRP batcher ON)", GUI.skin.window);
                else
                    GUILayout.BeginArea(new Rect(32, 50, w, h), "(SRP batcher OFF)", GUI.skin.window);

                GUILayout.Label(m_statsLabel, m_style);

                GUILayout.EndArea();
            }
        }
    }
}

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

캐릭터 랜덤 모션  (0) 2020.11.02
EditorWindow  (0) 2020.10.30
간단한 애니메이션 스크립트  (0) 2020.09.08
C# 기초 기억창고  (0) 2020.08.09
object rotate by tag  (0) 2020.07.29

매번 물체에 회전을 넣기가 귀찮아서... 어렵사리 코딩하였습니다.(코딩은어려버.)

Tag를 설정하고, Y축으로 회전합니다.

 

쉐이더 테스트할때 사용하려고 만든겁니다.

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

public class rotate_tag : MonoBehaviour
{
    
    //Rotational Speed
    public float speed = 20f;



    //object

    GameObject[] objt;


    void Start()
    {
        objt = GameObject.FindGameObjectsWithTag("gogo");

    }


    //Forward Direction

    bool ForwardY = true;

    
    void _All()
    {

        for(int i = 0; i < objt.Length; i++)
        {
            objt[i].transform.Rotate(0, Time.deltaTime * speed, 0, Space.Self);

        }
                 
    }



    void Update()
    {
        //Forward Direction

        if (ForwardY == true)
        {

            _All();
            
        }


    }
}

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

캐릭터 랜덤 모션  (0) 2020.11.02
EditorWindow  (0) 2020.10.30
간단한 애니메이션 스크립트  (0) 2020.09.08
C# 기초 기억창고  (0) 2020.08.09
MiniPorfiler  (0) 2020.07.29