AllAssets
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
public enum CharacterAnimationType
|
||||
{
|
||||
move,
|
||||
}
|
||||
public enum CharacterStateType
|
||||
{
|
||||
move,
|
||||
idle,
|
||||
|
||||
}
|
||||
public enum CharacterHurtType
|
||||
{
|
||||
none,
|
||||
}
|
||||
public enum CharacterShieldType
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// 这里枚举可以多个 需要携程二进制形式
|
||||
/// </summary>
|
||||
public enum CharacterHealthyType
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public abstract class CharactersDataBase : ICharactersDataBase
|
||||
{
|
||||
public ICharactersHealth charactersHealth { get; set; }
|
||||
public CharactersDataBase(CharactersHealthBase health)
|
||||
{
|
||||
charactersHealth = health;
|
||||
}
|
||||
public CharactersDataBase() { }
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public abstract class CharactersHealthBase : ICharactersHealth
|
||||
{
|
||||
public CharacterHealthyType HealthType { get; set; }
|
||||
public float f_MaxHP { get; set ; }
|
||||
public float f_CurrHP { get ; set; }
|
||||
public float f_MaxMP { get; set; }
|
||||
public float f_CurrMP { get; set; }
|
||||
public Dictionary<CharacterShieldType, float> f_Shield { get; set; }
|
||||
|
||||
public CharactersHealthBase() { }
|
||||
public CharactersHealthBase(CharacterHealthyType healthType, float f_MaxHP, float f_CurrHP, float f_MaxMP, float f_CurrMP, Dictionary<CharacterShieldType, float> f_Shields)
|
||||
{
|
||||
HealthType = healthType;
|
||||
this.f_MaxHP = f_MaxHP;
|
||||
this.f_CurrHP = f_CurrHP;
|
||||
this.f_MaxMP = f_MaxMP;
|
||||
this.f_CurrMP = f_CurrMP;
|
||||
this.f_Shield = f_Shield;
|
||||
}
|
||||
|
||||
public virtual void OnDie()
|
||||
{
|
||||
//播放死亡动画
|
||||
}
|
||||
|
||||
public virtual void OnHurt(float harmNum, CharacterHurtType charactersHurtType)
|
||||
{
|
||||
f_CurrHP-=harmNum;
|
||||
//播放受击动画
|
||||
}
|
||||
|
||||
public virtual void OnRecoverBlood(float bloodNum)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public interface ICharactersDataBase
|
||||
{
|
||||
ICharactersHealth charactersHealth { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 这里主要是为了服务器传输数据
|
||||
/// </summary>
|
||||
public interface ICharactersHealth
|
||||
{
|
||||
public CharacterHealthyType HealthType { get; set; }
|
||||
/// <summary>
|
||||
/// 最大生命值
|
||||
/// </summary>
|
||||
public float f_MaxHP { get; set; }
|
||||
/// <summary>
|
||||
/// 当前生命值
|
||||
/// </summary>
|
||||
public float f_CurrHP { get; set; }
|
||||
/// <summary>
|
||||
/// 最大生命值
|
||||
/// </summary>
|
||||
public float f_MaxMP { get; set; }
|
||||
/// <summary>
|
||||
/// 当前生命值
|
||||
/// </summary>
|
||||
public float f_CurrMP { get; set; }
|
||||
/// <summary>
|
||||
/// 护盾列表
|
||||
/// </summary>
|
||||
public Dictionary<CharacterShieldType,float> f_Shield { get; set; }
|
||||
|
||||
void OnHurt(float harmNum,CharacterHurtType charactersHurtType);
|
||||
void OnRecoverBlood(float bloodNum);
|
||||
void OnDie();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
using Spine;
|
||||
using Spine.Unity;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public class MonsterControl : MonoBehaviour
|
||||
{
|
||||
public MonsterDataBase monsterData = new MonsterDataBase(new MonsterHealthBase());
|
||||
public SkeletonAnimation skeleton;
|
||||
public bool isSpine = true;
|
||||
public Dictionary<CharacterAnimationType, string> dic_AnimKeyAnimName = new Dictionary<CharacterAnimationType, string>();
|
||||
public CharacterStateType currState;
|
||||
//这里捕鱼的结构很简单可以穿模直接写移动
|
||||
void Update()
|
||||
{
|
||||
OnUpdate(currState);
|
||||
}
|
||||
public void Start()
|
||||
{
|
||||
ChangeState(CharacterStateType.move);
|
||||
}
|
||||
public virtual void OnMoveEnter()
|
||||
{
|
||||
PlayAnim(CharacterAnimationType.move);
|
||||
}
|
||||
public virtual void OnMoveExit()
|
||||
{
|
||||
|
||||
}
|
||||
float moveTime = 0;
|
||||
public virtual void OnMoveUpdata()
|
||||
{
|
||||
moveTime += Time.deltaTime;
|
||||
|
||||
//播放动画
|
||||
skeleton.AnimationState.SetAnimation(0, dic_AnimKeyAnimName[CharacterAnimationType.move], true);
|
||||
//transform.position = new Vector3();//等策划给路线
|
||||
Vector2 v2 = monsterData.moveLine.GetBezierPoint(moveTime);
|
||||
Debug.Log(v2);
|
||||
transform.position = v2;
|
||||
//transform.Translate(Vector3.down);
|
||||
|
||||
}
|
||||
|
||||
public void PlayAnim(CharacterAnimationType animType, bool loop = true)
|
||||
{
|
||||
skeleton.AnimationState.SetAnimation(0, dic_AnimKeyAnimName[animType], loop);
|
||||
}
|
||||
public void OnEnter(CharacterStateType stateType)
|
||||
{
|
||||
switch (stateType)
|
||||
{
|
||||
case CharacterStateType.move:
|
||||
OnMoveEnter();
|
||||
break;
|
||||
case CharacterStateType.idle:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void OnUpdate(CharacterStateType stateType)
|
||||
{
|
||||
switch (stateType)
|
||||
{
|
||||
case CharacterStateType.move:
|
||||
OnMoveUpdata();
|
||||
break;
|
||||
case CharacterStateType.idle:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void OnExit(CharacterStateType stateType)
|
||||
{
|
||||
switch (stateType)
|
||||
{
|
||||
case CharacterStateType.move:
|
||||
break;
|
||||
case CharacterStateType.idle:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void ChangeState(CharacterStateType stateType)
|
||||
{
|
||||
OnExit(currState);
|
||||
currState = stateType;
|
||||
OnEnter(currState);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
[System.Serializable]
|
||||
public class MonsterDataBase : CharactersDataBase
|
||||
{
|
||||
public MonsterMoveLine moveLine=new MonsterMoveLine();
|
||||
public MonsterDataBase(MonsterHealthBase health) : base(health)
|
||||
{
|
||||
|
||||
}
|
||||
public MonsterDataBase() { }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MonsterHealthBase : CharactersHealthBase
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
public class MonsterMoveLine
|
||||
{
|
||||
public static Dictionary<string, BezierCurveData> dic_BezierCurveDatas=new Dictionary<string, BezierCurveData>();
|
||||
public static List<BezierCurveData> curves = new List<BezierCurveData>();
|
||||
public class BezierCurveData
|
||||
{
|
||||
public string name;
|
||||
public Vector2 start;
|
||||
public List<Vector2> controlPoints = new List<Vector2>();
|
||||
public Vector2 end;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 读取数据 游戏开始时在awake调用aa包
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task LoadBezierTxtAsync(string path)
|
||||
{
|
||||
AsyncOperationHandle<TextAsset> handle = Addressables.LoadAssetAsync<TextAsset>(path);
|
||||
await handle.Task;
|
||||
var lines = handle.Result.text.Split('\n');
|
||||
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(line)) continue;
|
||||
|
||||
var parts = line.Split(';');
|
||||
BezierCurveData curve = new BezierCurveData();
|
||||
|
||||
// 第一个是曲线名
|
||||
curve.name = parts[0];
|
||||
|
||||
// 后面所有都是点
|
||||
List<Vector2> points = new List<Vector2>();
|
||||
for (int i = 1; i < parts.Length; i++)
|
||||
{
|
||||
points.Add(ParseVector(parts[i]));
|
||||
}
|
||||
|
||||
// 第一个点是 start
|
||||
curve.start = points[0];
|
||||
|
||||
// 最后一个点是 end
|
||||
curve.end = points[points.Count - 1];
|
||||
|
||||
// 中间的都是 controlPoints
|
||||
for (int i = 1; i < points.Count - 1; i++)
|
||||
{
|
||||
curve.controlPoints.Add(points[i]);
|
||||
}
|
||||
|
||||
curves.Add(curve);
|
||||
dic_BezierCurveDatas.Add(curve.name,curve);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static Vector2 ParseVector(string s)
|
||||
{
|
||||
var xy = s.Split(',');
|
||||
return new Vector2(float.Parse(xy[0]), float.Parse(xy[1]));
|
||||
}
|
||||
|
||||
|
||||
public BezierCurveData bezierCurveData;
|
||||
public float moveTime;
|
||||
public float moveSpeed;
|
||||
|
||||
public void Init(BezierCurveData bezierCurveData, float Time)
|
||||
{
|
||||
this.bezierCurveData = bezierCurveData;
|
||||
this.moveTime = Time;
|
||||
}
|
||||
public Vector2 GetBezierPoint(float t)
|
||||
{
|
||||
t = t / moveTime;
|
||||
BezierCurveData curve=bezierCurveData;
|
||||
List<Vector2> points = new List<Vector2>();
|
||||
points.Add(curve.start);
|
||||
points.AddRange(curve.controlPoints);
|
||||
points.Add(curve.end);
|
||||
|
||||
return DeCasteljau(points, t%1);
|
||||
}
|
||||
|
||||
private Vector2 DeCasteljau(List<Vector2> points, float t)
|
||||
{
|
||||
while (points.Count > 1)
|
||||
{
|
||||
List<Vector2> next = new List<Vector2>();
|
||||
for (int i = 0; i < points.Count - 1; i++)
|
||||
{
|
||||
next.Add(Vector2.Lerp(points[i], points[i + 1], t));
|
||||
}
|
||||
points = next;
|
||||
}
|
||||
return CanvasToWorld( points[0],UIManager.Instance.uiRoot.GetComponent<RectTransform>(),Camera.main);
|
||||
}
|
||||
public static Vector3 CanvasToWorld(Vector2 canvasPos, RectTransform canvas, Camera cam)
|
||||
{
|
||||
// 1. 获取 Canvas 实际像素尺寸(自动适配所有设备)
|
||||
float canvasWidth = canvas.rect.width;
|
||||
float canvasHeight = canvas.rect.height;
|
||||
|
||||
// 2. 正交相机的世界高度
|
||||
float worldHeight = cam.orthographicSize * 2f;
|
||||
|
||||
// 3. 世界宽度 = 世界高度 * 屏幕宽高比
|
||||
float worldWidth = worldHeight * cam.aspect;
|
||||
|
||||
// 4. 画布单位 → 世界单位比例(横竖一致)
|
||||
float scaleX = worldWidth / canvasWidth;
|
||||
float scaleY = worldHeight / canvasHeight;
|
||||
|
||||
// 5. 你的 canvasPos 是以中心为原点的坐标
|
||||
float worldX = canvasPos.x * scaleX;
|
||||
float worldY = canvasPos.y * scaleY;
|
||||
|
||||
// 6. 映射到世界 z = 0 平面
|
||||
return new Vector3(worldX, worldY, 0f);
|
||||
}
|
||||
|
||||
public static Vector2 AnchoredPos_ToCanvas(RectTransform target, Canvas canvas)
|
||||
{
|
||||
// 1. 先把 anchoredPosition(父坐标)转换成世界坐标
|
||||
Vector3 worldPos = target.TransformPoint(target.anchoredPosition);
|
||||
|
||||
// 2. 再把世界坐标转换成 Canvas 的局部坐标(等价于 Canvas 下的 anchoredPosition)
|
||||
RectTransform canvasRT = canvas.GetComponent<RectTransform>();
|
||||
|
||||
Vector2 canvasLocalPos;
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(
|
||||
canvasRT,
|
||||
RectTransformUtility.WorldToScreenPoint(canvas.worldCamera, worldPos),
|
||||
canvas.renderMode == RenderMode.ScreenSpaceOverlay ? null : canvas.worldCamera,
|
||||
out canvasLocalPos
|
||||
);
|
||||
|
||||
return canvasLocalPos;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerControl : MonoBehaviour
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BullitMove : MonoBehaviour
|
||||
{
|
||||
public float moveSpeed = 5;
|
||||
public float desTime = 10f;
|
||||
public string playerID;
|
||||
float currShowTime = 0f;
|
||||
Vector3 vector3_startPosition;
|
||||
public bool isTriggerFirst=true;
|
||||
// Start is called before the first frame update
|
||||
void Awake()
|
||||
{
|
||||
Init();
|
||||
Destroy(gameObject, desTime);
|
||||
}
|
||||
/// <summary>
|
||||
/// 对象池用
|
||||
/// </summary>
|
||||
public void Init()
|
||||
{
|
||||
vector3_startPosition = transform.position;
|
||||
}
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
//方便帧同步
|
||||
currShowTime += Time.deltaTime;
|
||||
Vector3 targetPoint = transform.up.normalized * currShowTime * moveSpeed;
|
||||
transform.position = vector3_startPosition + targetPoint;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
if (isTriggerFirst)
|
||||
{
|
||||
if (collision.tag == "Monster")
|
||||
{
|
||||
isTriggerFirst=false;
|
||||
//受激
|
||||
collision.transform.GetComponent<MonsterControl>().monsterData.charactersHealth.OnHurt(10, CharacterHurtType.none);
|
||||
Destroy(collision.gameObject);
|
||||
Destroy(gameObject);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,7 @@ using UnityEngine;
|
||||
|
||||
public class GameData
|
||||
{
|
||||
public GameType currGameType;
|
||||
public string currUser;
|
||||
public string a;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,48 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
public class GameManager : MonoSingleton<GameManager>
|
||||
{
|
||||
|
||||
public GameData gameData=new GameData();
|
||||
protected override async void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
gameData.currUser="123";
|
||||
//CharacterAnimationType
|
||||
MonsterMoveLine.LoadBezierTxtAsync("MoveLines");
|
||||
}
|
||||
public void StartGame()
|
||||
{
|
||||
UIManager.Instance.ShowAsync(UIPanel.MainGamePanel);
|
||||
switch (gameData.currGameType)
|
||||
{
|
||||
case GameType.JQQD:
|
||||
break;
|
||||
case GameType.defaultPanel:
|
||||
UIManager.Instance.ShowAsync(UIPanel.MainGamePanelDefault);
|
||||
break;
|
||||
case GameType.FXZY:
|
||||
UIManager.Instance.ShowAsync(UIPanel.MainGamePanelDefault);
|
||||
break;
|
||||
case GameType.TGXX:
|
||||
UIManager.Instance.ShowAsync(UIPanel.MainGamePanelDefault);
|
||||
break;
|
||||
case GameType.ZGXQ:
|
||||
UIManager.Instance.ShowAsync(UIPanel.MainGamePanelDefault);
|
||||
break;
|
||||
case GameType.XJMH:
|
||||
UIManager.Instance.ShowAsync(UIPanel.MainGamePanelXJMH);
|
||||
break;
|
||||
case GameType.HHWK:
|
||||
UIManager.Instance.ShowAsync(UIPanel.MainGamePanelDefault);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
@@ -18,5 +54,6 @@ public class GameManager : MonoSingleton<GameManager>
|
||||
void Update()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class BgFit : MonoBehaviour
|
||||
{
|
||||
void Start()
|
||||
{
|
||||
SpriteRenderer sr = GetComponent<SpriteRenderer>();
|
||||
if (sr == null) return;
|
||||
|
||||
float width = sr.bounds.size.x;
|
||||
float height = sr.bounds.size.y;
|
||||
|
||||
float worldHeight = Camera.main.orthographicSize * 2f;
|
||||
float worldWidth = worldHeight * Screen.width / Screen.height;
|
||||
|
||||
transform.localScale = new Vector3(
|
||||
worldWidth / width,
|
||||
worldHeight / height,
|
||||
1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class Test_All : MonoBehaviour
|
||||
{
|
||||
public GameObject monsterPrefab;
|
||||
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (Keyboard.current.aKey.wasPressedThisFrame)
|
||||
{
|
||||
CreateSmallMonster();
|
||||
}
|
||||
|
||||
}
|
||||
public void CreateSmallMonster()
|
||||
{
|
||||
//初始化
|
||||
GameObject obj = Instantiate(monsterPrefab,Vector3.one*999,Quaternion.identity);
|
||||
var v = obj.GetComponent<MonsterControl>();
|
||||
v.dic_AnimKeyAnimName.Add(CharacterAnimationType.move, "stand2");
|
||||
|
||||
v.monsterData.moveLine.Init(MonsterMoveLine.dic_BezierCurveDatas["曲线"+Random.Range(1,4).ToString()], 10);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user