冯乐乐的《Unity Shader入门精要》附带项目,其中部分shader已经修改测试
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.3 KiB

3 years ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//编辑器管理类,用于加载配置文件并生成对应车辆
public class ChariotEditor : MonoBehaviour {
public TextAsset textAsset;
public GameObject Core;
public Transform CameraTrans;
//预添加区块列表
private List<Transform> addBlocks;
//预加载资源类
public ChariotModuleResource cResource;
//预添加id
private int BlockAddId;
// Use this for initialization
void Start () {
addBlocks = new List<Transform>();
for (int i = 0; i < Core.transform.childCount; i++) {
addBlocks.Add(Core.transform.GetChild(i));
}
//print(addBlocks.Count);
}
// Update is called once per frame
void Update () {
int layerMask = 1 << 8;
layerMask = ~layerMask;
RaycastHit hit;
// Does the ray intersect any objects excluding the player layer
if (Physics.Raycast(CameraTrans.position, CameraTrans.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, layerMask))
{
Debug.DrawRay(CameraTrans.position, CameraTrans.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
//Debug.Log(hit.collider.transform);
//Debug.Log(hit.point.x+"|"+hit.point.y+"|"+hit.point.z);
if (hit.point.z == -0.5f) {
TipsBlock(0);
}
else if(hit.point.z == 0.5f)
{
TipsBlock(1);
}
else if (hit.point.x == -0.5f)
{
TipsBlock(2);
}
else if (hit.point.x == 0.5f)
{
TipsBlock(3);
}
else if (hit.point.y == 2-0.5f)
{
TipsBlock(4);
}
else if (hit.point.y == 2+0.5f)
{
TipsBlock(5);
}
}
else
{
Debug.DrawRay(CameraTrans.position, CameraTrans.TransformDirection(Vector3.forward) * 1000, Color.white);
//Debug.Log("Did not Hit");
}
}
//设置添加区块是否可见,如果全不可见,请传入-1作为参数。
public void TipsBlock(int bid) {
foreach (Transform ab in addBlocks) {
ab.gameObject.SetActive(false);
}
addBlocks[bid].gameObject.SetActive(true);
BlockAddId = bid;
}
public void AddBlock(int cResourceId) {
Vector3 addPos = addBlocks[BlockAddId].GetChild(0).position;
GameObject addObj = Instantiate(cResource.cube[cResourceId].module,Core.transform);
addObj.transform.position = addPos;
}
public bool loadChariot(string fileName)
{
return true;
}
public bool SaveChariot(string fileName)
{
return true;
}
}