Unity基础

unity

unity 3大场景
Asset Scene Component

Asset :资源导入导出

右击资源,选择导出Unity包
导入可以直接将只有复制到Asset文件夹

创建场景

File->New Scene

第一个启动的场景:
File->Build Setting 里面第一个

游戏都是由多个场景构成


GameObject

Create Empty创建一个GameObject

写有些就是要完成的就是编写Component
右键->Create->C# Script就可以创建脚本了

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

public class NewBehaviourScript : MonoBehaviour {

    public int a = 2;
    public int[] intArry;

    // Use this for initialization
    void Start () {
    }
    
    // Update is called once per frame
    void Update () {
        Debug.Log("Hello Unity");
    }
}

Prefab

Select Prefab
将Hierarchy中的文件拖动到Asset里面,就可以生成一个预制,然后拖动到Scene里就可以使用了,预制可以多次使用,一次修改可以影响多个相同的预制对象,使用Apply确认应用到同一预制对象
预制? 预制保存用Apply
取消预制:GameObject->Break Prefab Instance

Tag和Static

Tag:可以用于标记标签
Static:
Nothing:没有任何属性;
Everyting:所有的都是静态的,Unity可以优化;
LightMap Static:光照阴影是固定不变的;
Occluder Static: 遮挡静态
Batching Static:
Navigation Static:
Occludee Static:
Off Mesh Link Generation:
Reflection Probe Static:

c#编码中出现的变量可以直接在Unity里面进行调节

private,protected是不暴露的

private int p;  //  private,protected是不暴露的

想要私有变量被访问到写法

// 想要私有变量被访问到写法
[SerializeField]
private string player;

不想将这个字段暴露,使用这个[HideInInspector]

[HideInInspector]
public string name; //不想将这个字段暴露,使用这个[HideInInspector]

定义结构体添加[System.Serializable]标签后也能够访问到

// 定义结构体添加[System.Serializable]标签后也能够访问到
[System.Serializable]
public class customStruct
{
    public int a = 2;
    public int[] intArry;
    public List<string> kk;
}
public class NewBehaviourScript : MonoBehaviour {

    public customStruct cus;    // 结构体
    // Use this for initialization
    void Start () {
    }

    // Update is called once per frame
    void Update () {
       
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


// 定义结构体添加[System.Serializable]标签后也能够访问到
[System.Serializable]
public class customStruct
{
    public int a = 2;
    public int[] intArry;
    public List<string> kk;
}

public class NewBehaviourScript : MonoBehaviour {

    public customStruct cus;    // 结构体

    public int a = 2;
    public int[] intArry;
    public List<string> kk;

    public Color c; //颜色
    public AnimationCurve curve;    //曲线
    public Gradient g;  // 渐变

    // private,protected是不暴露的
    private int p;


    // 想要私有变量被访问到写法
    [SerializeField]
    private string player;

    [HideInInspector]
    public string name; //不想将这个字段暴露,使用这个[HideInInspector]

    // Use this for initialization
    void Start () {
        if (intArry != null)
        {
            Debug.Log(intArry.Length);
        }
        Debug.Log(kk.Count);

    }

    // Update is called once per frame
    void Update () {
       
    }
}

效果如下:

Scene与Game窗口使用

Scene

旋转 位移 缩放
Shift+F 快速定位
Shift+Ctrl+f 当前视角与主相机视图对齐

点击三个方向的坐标轴切换视角
Persp 透视视角
Iso正交视图2d投影

以不同的方法渲染:
Shaded
Wireframe
Shadow Cascades
Render Paths
Alpha Channel 透明度
Overdraw
Mipmaps

Gizmos:游戏中的提示信息

Game

分辨率调整
Maximize On Play 运行时最大化
Mute audio 静音
State 信息,性能统计

编辑器内搜索

资源搜索

直接搜索
按类型搜索
按Tag搜索

场景搜索

直接搜索名字
场景内搜索中包含的材料,比如搜索那些组件包含了粒子系统,mesh,

一些重要的设置

Edit->Project Settings 对于文件夹里的Project Setting文件夹的设置文件

QualitySettings:勾选变成绿色的小勾后即显示设置成功
Fast和Simple比较常用与手机游戏
Good以上为PC

Editor Settigns:
Version Control: Hidden Meta Files;Asset Server(Unity自己的版本控制);Visible Meta Files(svn可以使用,meta文件保存有关参数设置,合作时需要共享,单机个人开发可以不需要);
(开发需要上传的文件:Library不需要上传,ProjectSettings需要上传,Asset需要上传,Temp不需要上传)

Asset Serialization:
Mode :Mixed;Force Binary(推荐,如果选择Asset文件打开由2进制);Force Text(多人合作选择Text,由yaml语言书写,更加清晰明白);设置不会影响后面的发布,发布都是使用Binary发布的

posted @ 2019-04-09 13:51  cicarius  阅读(241)  评论(0编辑  收藏  举报