就直接用直接Live2d2.x练习那个项目开始做GalGame
直接包往里面导入 素材都已经被设置为精灵了就不用改了
然后先更改鼠标样子
鼠标的精灵图片设置为Cursor
这里就OK拉
创两个场景进入Start开始制作
设置相机 照射类型 背景颜色 还有正交模式
画布设置自适应比例 视图调制为16:9
扯个BG把调色板扔一边
然后整一下UI跟之前一样K一个一闪一闪星星效果
然后做一下特效掉花瓣的那种
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 特效产生器
/// </summary>
public class EffectSpawn : MonoBehaviour
{
public GameObject[] effectGos;
public Transform canvans;
// Start is called before the first frame update
void Start()
{
//延迟调用 方法 延迟几秒调用 几秒重复一次
InvokeRepeating("CreateEffectGo",0,2);
}
// Update is called once per frame
void Update()
{
}
void CreateEffectGo()
{
int randomIndex = Random.Range(0, effectGos.Length);
//随机旋转角度
transform.rotation = Quaternion.Euler(new Vector3(0,0,Random.Range(0,45)));
GameObject effectGo = Instantiate(effectGos[randomIndex],transform.position,transform.rotation);
effectGo.transform.SetParent(canvans);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 特效移动脚本
/// </summary>
public class EffectMove : MonoBehaviour
{
public float moveSpeed = 100;//世界坐标和屏幕坐标是100:1
float timeVal;
int randomYPos;
// Start is called before the first frame update
void Start()
{
Destroy(gameObject, 10);
}
// Update is called once per frame
void Update()
{
transform.Translate(-transform.right * Time.deltaTime* moveSpeed);
timeVal += Time.deltaTime;
if (timeVal >= 1)
{
timeVal = 0;
randomYPos = Random.Range(-1, 2);
}
else
{
transform.Translate(transform.up * randomYPos * Time.deltaTime);
}
}
}
然后Btn事件切换场景
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
/// <summary>
/// 开始游戏的按钮
/// </summary>
public class LoadGame : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
GetComponent<Button>().onClick.AddListener(LoadGameScence);
}
// Update is called once per frame
void Update()
{
}
void LoadGameScence()
{
SceneManager.LoadScene(1);
}
}
当然别忘了点Add Open Scences添加场景
开始制作游戏场景
跟之前一样操作好然后把
剩余两个文件导入一个是小姐姐资源 一个是官方的脚本
创建一个空节点挂人物属性这个
添加这么多就可以了
然后L App是加载人物的path填写json文件位置后面别忘了加上.json 还有个设置问题人是躺着的一开始 所以要X轴旋转-90度让人物站起来
拉个背景 用九宫格切割 这样拉伸边不会变形
做一下UI界面 写一个管理类
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
//单例
static GameManager _instance;
public static GameManager Instance
{
get
{
return _instance;
}
}
//玩家属性
public int gold;
public int favor;
public int haveDays;
public Text goldText;
public Text favorText;
public Text dateText;
private void Awake()
{
_instance = this;
gold = favor = 0;
haveDays = 20;
UpdateUI();
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
//更新玩家UI显示
void UpdateUI()
{
goldText.text = gold.ToString();
favorText.text = favor.ToString();
dateText.text = haveDays.ToString();
}
//改变金币
public void ChangeGold(int goldValue)
{
gold += goldValue;
if (gold<=0)
{
gold = 0;
}
UpdateUI();
}
//改变好感度
public void ChangeFavor(int favorValue)
{
favor += favorValue;
if (favor<=0)
{
favor = 0;
}
UpdateUI();
}
}
然后做一个Mask遮罩控制白天黑天 改透明度
就是一个全屏的Image 然后代码控制
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
//单例
static GameManager _instance;
public static GameManager Instance
{
get
{
return _instance;
}
}
//玩家属性
public int gold;
public int favor;
public int haveDays;
public Text goldText;
public Text favorText;
public Text dateText;
//天黑天亮属性
public Image mask;
public bool toAnotherDay;
public bool toBeDay;//即将天亮
float timeVal;
private void Awake()
{
_instance = this;
gold = favor = 0;
haveDays = 20;
UpdateUI();
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//是否过度到另外一天
if (toAnotherDay)
{
if (toBeDay)
{
timeVal += Time.deltaTime;
//天亮的方法
if (timeVal >= 2)
{
timeVal = 0;
ToDay();
}
}
else
{
//天黑方法
ToDark();
}
}
}
//天黑方法
void ToDark()
{
//差值当前值 目标值 时间
mask.color += new Color(0, 0, 0, Mathf.Lerp(0, 1, 0.1f));
if (mask.color.a >= 0.8f)
{
mask.color = new Color(0, 0, 0, 1);
toBeDay = true;
UpdateUI();
}
}
//天亮
void ToDay()
{
mask.color -= new Color(0, 0, 0, Mathf.Lerp(1, 0, 0.1f));
if (mask.color.a <= 0.2f)
{
mask.color = new Color(0, 0, 0, 0);
toAnotherDay = false;
toBeDay = false;
}
}
//更新玩家UI显示
void UpdateUI()
{
goldText.text = gold.ToString();
favorText.text = favor.ToString();
dateText.text = haveDays.ToString();
}
//改变金币
public void ChangeGold(int goldValue)
{
gold += goldValue;
if (gold <= 0)
{
gold = 0;
}
UpdateUI();
}
//改变好感度
public void ChangeFavor(int favorValue)
{
favor += favorValue;
if (favor <= 0)
{
favor = 0;
}
UpdateUI();
}
}
接下来制作打工属性
一个Work空节点3个Btn
然后隐藏人物 就这样很简单附代码 需要自己拖动赋值
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
//单例
static GameManager _instance;
public static GameManager Instance
{
get
{
return _instance;
}
}
//玩家属性
public int gold;
public int favor;
public int haveDays;
public Text goldText;
public Text favorText;
public Text dateText;
public LAppModelProxy lAppModelProxy;
public GameObject actionBtns;
public GameObject talkLine;
public Text talkLineText;
//天黑天亮属性
public Image mask;
public bool toAnotherDay;
public bool toBeDay;//即将天亮
float timeVal;
//打工
public GameObject workBtns;
public Sprite[] workSprites;
public Image workImage;
public GameObject workUI;
private void Awake()
{
_instance = this;
gold = favor = 0;
haveDays = 20;
UpdateUI();
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//是否过度到另外一天
if (toAnotherDay)
{
if (toBeDay)
{
timeVal += Time.deltaTime;
//天亮的方法
if (timeVal >= 2)
{
timeVal = 0;
ToDay();
}
}
else
{
//天黑方法
ToDark();
}
}
}
//即将天黑
public void ToBeDark()
{
toAnotherDay = true;
}
//天黑方法
void ToDark()
{
//差值当前值 目标值 时间
mask.color += new Color(0, 0, 0, Mathf.Lerp(0, 1, 0.1f));
if (mask.color.a >= 0.8f)
{
mask.color = new Color(0, 0, 0, 1);
toBeDay = true;
ResetUI();
UpdateUI();
}
}
//天亮
void ToDay()
{
mask.color -= new Color(0, 0, 0, Mathf.Lerp(1, 0, 0.1f));
if (mask.color.a <= 0.2f)
{
mask.color = new Color(0, 0, 0, 0);
toAnotherDay = false;
toBeDay = false;
}
}
/// <summary>
/// 打工
/// </summary>
public void ClickWorkBtn()
{
actionBtns.SetActive(false);
workBtns.SetActive(true);
//隐藏人物
lAppModelProxy.SetVisible(false);
}
public void GetMoney(int workIndex)
{
workBtns.SetActive(false);
ChangeGold((4 - workIndex) * 20);
workImage.overrideSprite = workSprites[workIndex];
workUI.SetActive(true);
talkLine.SetActive(true);
talkLineText.text = "一顿辛劳后获得" + ((4 - workIndex) * 20).ToString() + "金币";
}
public void ClickChat()
{
actionBtns.SetActive(false);
}
//更新玩家UI显示
void UpdateUI()
{
goldText.text = gold.ToString();
favorText.text = favor.ToString();
dateText.text = haveDays.ToString();
}
//改变金币
public void ChangeGold(int goldValue)
{
gold += goldValue;
if (gold <= 0)
{
gold = 0;
}
UpdateUI();
}
//改变好感度
public void ChangeFavor(int favorValue)
{
favor += favorValue;
if (favor <= 0)
{
favor = 0;
}
UpdateUI();
}
//重置所有UI
void ResetUI()
{
workUI.SetActive(false);
talkLine.SetActive(false);
actionBtns.SetActive(true);
lAppModelProxy.SetVisible(true);
haveDays--;
}
}
然后开始制作聊天系统
需要有配合动作
可以再haru的json表里面对照 跟打工一样不过调用了面部表情不太明显
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
//单例
static GameManager _instance;
public static GameManager Instance
{
get
{
return _instance;
}
}
//玩家属性
public int gold;
public int favor;
public int haveDays;
public Text goldText;
public Text favorText;
public Text dateText;
public LAppModelProxy lAppModelProxy;
public GameObject actionBtns;
public GameObject talkLine;
public Text talkLineText;
//天黑天亮属性
public Image mask;
public bool toAnotherDay;
public bool toBeDay;//即将天亮
float timeVal;
//打工
public GameObject workBtns;
public Sprite[] workSprites;
public Image workImage;
public GameObject workUI;
//聊天
public GameObject ChatUI;
private void Awake()
{
_instance = this;
gold = favor = 0;
haveDays = 20;
UpdateUI();
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//是否过度到另外一天
if (toAnotherDay)
{
if (toBeDay)
{
timeVal += Time.deltaTime;
//天亮的方法
if (timeVal >= 2)
{
timeVal = 0;
ToDay();
}
}
else
{
//天黑方法
ToDark();
}
}
}
//即将天黑
public void ToBeDark()
{
toAnotherDay = true;
}
//天黑方法
void ToDark()
{
//差值当前值 目标值 时间
mask.color += new Color(0, 0, 0, Mathf.Lerp(0, 1, 0.1f));
if (mask.color.a >= 0.8f)
{
mask.color = new Color(0, 0, 0, 1);
toBeDay = true;
ResetUI();
UpdateUI();
}
}
//天亮
void ToDay()
{
mask.color -= new Color(0, 0, 0, Mathf.Lerp(1, 0, 0.1f));
if (mask.color.a <= 0.2f)
{
mask.color = new Color(0, 0, 0, 0);
toAnotherDay = false;
toBeDay = false;
}
}
/// <summary>
/// 打工
/// </summary>
public void ClickWorkBtn()
{
actionBtns.SetActive(false);
workBtns.SetActive(true);
//隐藏人物
lAppModelProxy.SetVisible(false);
}
public void GetMoney(int workIndex)
{
workBtns.SetActive(false);
ChangeGold((4 - workIndex) * 20);
workImage.overrideSprite = workSprites[workIndex];
workUI.SetActive(true);
talkLine.SetActive(true);
talkLineText.text = "一顿辛劳后获得" + ((4 - workIndex) * 20).ToString() + "金币";
}
/// <summary>
/// 聊天
/// </summary>
public void ClickChat()
{
actionBtns.SetActive(false);
ChatUI.SetActive(true);
if (favor >= 100)
{
lAppModelProxy.GetModel().StartMotion("tap_body", 1, 2);
}
else
{
//参数 当前组的名字 组里面第几个 优先级
lAppModelProxy.GetModel().StartMotion("tap_body", 0, 2);
}
}
public void GetFavor(int chatIndex)
{
ChatUI.SetActive(false);
talkLine.SetActive(true);
switch (chatIndex)
{
case 0:
if (favor > 20)
{
ChangeFavor(8);
talkLineText.text = "谢谢你,你也很帅";
lAppModelProxy.GetModel().SetExpression("f02");
}
else
{
ChangeFavor(2);
talkLineText.text = "嗯";
lAppModelProxy.GetModel().SetExpression("f08");
}
break;
case 1:
if (favor > 60)
{
ChangeFavor(15);
talkLineText.text = "emmmmmm 啊~不好意思,谢谢你";
lAppModelProxy.GetModel().SetExpression("f07");
}
else
{
ChangeFavor(-20);
talkLineText.text = "去死!臭虫";
lAppModelProxy.GetModel().SetExpression("f04");
}
break;
case 2:
if (favor > 100)
{
ChangeFavor(35);
talkLineText.text = "那我们一起去玩吧,我也等了你好久";
lAppModelProxy.GetModel().SetExpression("f05");
}
else
{
ChangeFavor(-40);
talkLineText.text = "贱民!你配和我说话吗!";
lAppModelProxy.GetModel().SetExpression("f03");
}
break;
default:
break;
}
}
//更新玩家UI显示
void UpdateUI()
{
goldText.text = gold.ToString();
favorText.text = favor.ToString();
dateText.text = haveDays.ToString();
}
//改变金币
public void ChangeGold(int goldValue)
{
gold += goldValue;
if (gold <= 0)
{
gold = 0;
}
UpdateUI();
}
//改变好感度
public void ChangeFavor(int favorValue)
{
favor += favorValue;
if (favor <= 0)
{
favor = 0;
}
UpdateUI();
}
//重置所有UI
void ResetUI()
{
workUI.SetActive(false);
talkLine.SetActive(false);
actionBtns.SetActive(true);
lAppModelProxy.SetVisible(true);
lAppModelProxy.GetModel().SetExpression("f01");
haveDays--;
}
}
然后开始约会 表白系统 跟之前差不多
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameManager : MonoBehaviour
{
//单例
static GameManager _instance;
public static GameManager Instance
{
get
{
return _instance;
}
}
//玩家属性
public int gold;
public int favor;
public int haveDays;
public Text goldText;
public Text favorText;
public Text dateText;
public LAppModelProxy lAppModelProxy;
public GameObject actionBtns;
public GameObject talkLine;
public Text talkLineText;
//天黑天亮属性
public Image mask;
public bool toAnotherDay;
public bool toBeDay;//即将天亮
float timeVal;
//打工
public GameObject workBtns;
public Sprite[] workSprites;
public Image workImage;
public GameObject workUI;
//聊天
public GameObject ChatUI;
private void Awake()
{
_instance = this;
gold = favor = 0;
haveDays = 20;
UpdateUI();
}
//约会
public SpriteRenderer bgImage;
public Sprite[] dateSprites;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//是否过度到另外一天
if (toAnotherDay)
{
if (toBeDay)
{
timeVal += Time.deltaTime;
//天亮的方法
if (timeVal >= 2)
{
timeVal = 0;
ToDay();
}
}
else
{
//天黑方法
ToDark();
}
}
}
//即将天黑
public void ToBeDark()
{
toAnotherDay = true;
}
//天黑方法
void ToDark()
{
//差值当前值 目标值 时间
mask.color += new Color(0, 0, 0, Mathf.Lerp(0, 1, 0.1f));
if (mask.color.a >= 0.8f)
{
mask.color = new Color(0, 0, 0, 1);
toBeDay = true;
ResetUI();
UpdateUI();
}
}
//天亮
void ToDay()
{
mask.color -= new Color(0, 0, 0, Mathf.Lerp(1, 0, 0.1f));
if (mask.color.a <= 0.2f)
{
mask.color = new Color(0, 0, 0, 0);
toAnotherDay = false;
toBeDay = false;
}
}
/// <summary>
/// 打工
/// </summary>
public void ClickWorkBtn()
{
actionBtns.SetActive(false);
workBtns.SetActive(true);
//隐藏人物
lAppModelProxy.SetVisible(false);
}
public void GetMoney(int workIndex)
{
workBtns.SetActive(false);
ChangeGold((4 - workIndex) * 20);
workImage.overrideSprite = workSprites[workIndex];
workUI.SetActive(true);
talkLine.SetActive(true);
talkLineText.text = "一顿辛劳后获得" + ((4 - workIndex) * 20).ToString() + "金币";
}
/// <summary>
/// 聊天
/// </summary>
public void ClickChat()
{
actionBtns.SetActive(false);
ChatUI.SetActive(true);
if (favor >= 100)
{
lAppModelProxy.GetModel().StartMotion("tap_body", 1, 2);
}
else
{
//参数 当前组的名字 组里面第几个 优先级
lAppModelProxy.GetModel().StartMotion("tap_body", 0, 2);
}
}
public void GetFavor(int chatIndex)
{
ChatUI.SetActive(false);
talkLine.SetActive(true);
switch (chatIndex)
{
case 0:
if (favor > 20)
{
ChangeFavor(8);
talkLineText.text = "谢谢你,你也很帅";
lAppModelProxy.GetModel().SetExpression("f02");
}
else
{
ChangeFavor(2);
talkLineText.text = "嗯";
lAppModelProxy.GetModel().SetExpression("f08");
}
break;
case 1:
if (favor > 60)
{
ChangeFavor(15);
talkLineText.text = "emmmmmm 啊~不好意思,谢谢你";
lAppModelProxy.GetModel().SetExpression("f07");
}
else
{
ChangeFavor(-20);
talkLineText.text = "去死!臭虫";
lAppModelProxy.GetModel().SetExpression("f04");
}
break;
case 2:
if (favor > 100)
{
ChangeFavor(35);
talkLineText.text = "那我们一起去玩吧,我也等了你好久";
lAppModelProxy.GetModel().SetExpression("f05");
}
else
{
ChangeFavor(-40);
talkLineText.text = "贱民!你配和我说话吗!";
lAppModelProxy.GetModel().SetExpression("f03");
}
break;
default:
break;
}
}
/// <summary>
/// 约会
/// </summary>
public void ClickDateBtn()
{
actionBtns.SetActive(false);
talkLine.SetActive(true);
int randomNum = Random.Range(1, 4);
bool hasEnoughGold = false;
bgImage.sprite = dateSprites[randomNum];
switch (randomNum)
{
case 1:
if (gold>=50)
{
ChangeGold(-50);
ChangeFavor(100);
talkLineText.text = "学校门口好热闹啊! 真开心";
hasEnoughGold = true;
}
else
{
talkLineText.text = "穷鬼!!!气死我啦 出门不带钱";
ChangeFavor(-60);
}
break;
case 2:
if (gold >= 150)
{
ChangeGold(-150);
ChangeFavor(200);
talkLineText.text = "这里的饭真的好好吃啊 我下次还想来";
hasEnoughGold = true;
}
else
{
talkLineText.text = "真寒酸 我请你去死算了";
ChangeFavor(-150);
}
break;
case 3:
if (gold >= 250)
{
ChangeGold(-300);
ChangeFavor(350);
talkLineText.text = "礼物好漂亮!谢谢你 下次我也买给你";
hasEnoughGold = true;
}
else
{
talkLineText.text = "哎 一个玩具都买不起,你拿什么追我?";
ChangeFavor(-250);
}
break;
default:
break;
}
if (hasEnoughGold)
{
lAppModelProxy.GetModel().StartMotion("pinch_in",0,2);
}
else
{
lAppModelProxy.GetModel().StartMotion("flick_head", 0, 2);
}
}
/// <summary>
/// 表白
/// </summary>
public void ClickLoveBtn()
{
actionBtns.SetActive(false);
talkLine.SetActive(true);
if (favor>=1200)
{
talkLineText.text = "其实我也喜欢你很久了"+"/n"+"真好呢自己喜欢的人也喜欢自己"+ "/n"
+"今后多多指教";
lAppModelProxy.GetModel().StartMotion("pinch_out", 0, 2);
lAppModelProxy.GetModel().SetExpression("f07");
}
else
{
talkLineText.text = "啊~吓我一跳 对不起,你是个好人 最近不怎么想谈恋爱";
lAppModelProxy.GetModel().StartMotion("shake", 0, 2);
lAppModelProxy.GetModel().SetExpression("f04");
}
}
//更新玩家UI显示
void UpdateUI()
{
goldText.text = gold.ToString();
favorText.text = favor.ToString();
dateText.text = haveDays.ToString();
}
//改变金币
public void ChangeGold(int goldValue)
{
gold += goldValue;
if (gold <= 0)
{
gold = 0;
}
UpdateUI();
}
//改变好感度
public void ChangeFavor(int favorValue)
{
favor += favorValue;
if (favor <= 0)
{
favor = 0;
}
UpdateUI();
}
//重置所有UI
void ResetUI()
{
workUI.SetActive(false);
talkLine.SetActive(false);
actionBtns.SetActive(true);
lAppModelProxy.SetVisible(true);
lAppModelProxy.GetModel().SetExpression("f01");
bgImage.sprite = dateSprites[0];
haveDays--;
}
}
然后基本收工了
如何处理野生的Live2d模型文件
随便打开一个模型文件 .txt结尾是动作源文件 在结尾加上.mtn就可以使用
.dat结尾是模型属性后面加.txt就可以了
然后添加Boss
这个是转换完毕的野生文件 导入unity
因为名字问题 可能无法正常运行 这个是已经改好名字的 野生的还要自己改名和json表一致
跟之前一样导入就ok
但是我们不用 因为里面东西改比较麻烦 自己写一个简单的