修改字符模块
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MuHua;
|
||||
|
||||
/// <summary>
|
||||
/// 数据采集
|
||||
/// </summary>
|
||||
public class AnalysisCollector : Module<AnalysisCollector> {
|
||||
/// <summary> 接口 :https://api.mairui.club/hszbl/fsjy/股票代码(如000001)/分时级别/licence证书 </summary>
|
||||
public string API => "https://api.mairui.club/hszbl/fsjy/";
|
||||
|
||||
public void GetStock(string code, Action<List<DataAnalysis>> action, bool isCache = true) {
|
||||
string json = SaveTool.LoadText(FileName.Create(code));
|
||||
if (json != null && json != "" && isCache) { StockToAnalysis(json, action); return; }
|
||||
|
||||
//https://api.mairui.club/hszbl/fsjy/000001/60m/b997d4403688d5e66a
|
||||
string url = $"{API}{code}/dn/2E111385-7BF1-473D-9210-8E22AA75375A";
|
||||
Debug.Log($"{code}重新缓存了数据!");
|
||||
|
||||
DataRequestGet request = new DataRequestGet(url);
|
||||
request.OnError = (json) => { Debug.Log(json); };
|
||||
request.OnCallback = (json) => {
|
||||
SaveTool.SaveText(FileName.Create(code), json);
|
||||
StockToAnalysis(json, action);
|
||||
};
|
||||
request.SendAsync();
|
||||
}
|
||||
|
||||
public void StockToAnalysis(string json, Action<List<DataAnalysis>> action = null) {
|
||||
List<DataStock> stocks = JsonTool.FromJson<List<DataStock>>(json);
|
||||
List<DataAnalysis> analyses = new List<DataAnalysis>();
|
||||
for (int i = 0; i < stocks.Count; i++) { analyses.Add(stocks[i].To()); }
|
||||
action?.Invoke(analyses);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class DataAnalysis {
|
||||
/// <summary> 日期 </summary>
|
||||
public string dateTime;
|
||||
/// <summary> 最高价(元) </summary>
|
||||
public float max;
|
||||
/// <summary> 最低价(元) </summary>
|
||||
public float min;
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class DataStock {
|
||||
/// <summary> 日期 </summary>
|
||||
public string d;
|
||||
/// <summary> 开盘价(元) </summary>
|
||||
public string o;
|
||||
/// <summary> 最高价(元) </summary>
|
||||
public string h;
|
||||
/// <summary> 最低价(元) </summary>
|
||||
public string l;
|
||||
/// <summary> 收盘价(元) </summary>
|
||||
public string c;
|
||||
/// <summary> 成交量(手) </summary>
|
||||
public string v;
|
||||
/// <summary> 成交额(元) </summary>
|
||||
public string e;
|
||||
/// <summary> 振幅(%) </summary>
|
||||
public string zf;
|
||||
/// <summary> 换手率(%) </summary>
|
||||
public string hs;
|
||||
/// <summary> 涨跌幅(%) </summary>
|
||||
public string zd;
|
||||
/// <summary> 涨跌额(元) </summary>
|
||||
public string zde;
|
||||
/// <summary> </summary>
|
||||
public string ud;
|
||||
|
||||
public DataAnalysis To() {
|
||||
DataAnalysis analysis = new DataAnalysis();
|
||||
//analysis.dateTime = DateTime.ParseExact(d, "yyyy-MM-dd", CultureInfo.CurrentCulture);
|
||||
analysis.dateTime = d;
|
||||
analysis.max = float.Parse(h);
|
||||
analysis.min = float.Parse(l);
|
||||
return analysis;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MuHua;
|
||||
|
||||
/// <summary>
|
||||
/// 分析模块
|
||||
/// </summary>
|
||||
public class ModuleAnalysis : MonoBehaviour {
|
||||
public List<DataAnalysis> analyses;
|
||||
private void Start() {
|
||||
AnalysisCollector.I.GetStock("601658", (analyses) => { this.analyses = analyses; });
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 交易模块
|
||||
/// </summary>
|
||||
public abstract class ModuleTrading {
|
||||
/// <summary> 执行交易 </summary>
|
||||
public abstract void Execute();
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11336b15ef40f45488427630359ab3ba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ebb2815476f460d48b87b8d80a3c1faa
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4cbc8837586bb7248990d0581e20725f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,32 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MuHua;
|
||||
|
||||
// public class AnimalChasingState<T> : IStateMachine where T : Component {
|
||||
// public T target;
|
||||
// public string ToDefault = "Eating";
|
||||
// public readonly AnimalMachine animal;
|
||||
// public AnimalChasingState(StateMachine machine) : base(machine) => animal = machine as AnimalMachine;
|
||||
|
||||
// public override void Enter() {
|
||||
// bool valid = animal.Find(out target);
|
||||
// if (!valid) { animal.ChangeState("Idle"); }
|
||||
// }
|
||||
|
||||
// public override void Exit() {
|
||||
// animal.movement.StopMoving();
|
||||
// animal.animator.SetFloat("MoveSpeed", 0);
|
||||
// }
|
||||
|
||||
// public override void Trigger() {
|
||||
|
||||
// }
|
||||
|
||||
// public override void Update() {
|
||||
// if (target == null) { animal.ChangeState(ToDefault); return; }
|
||||
// bool complete = animal.movement.UpdateMove(target.transform.position);
|
||||
// animal.animator.SetFloat("MoveSpeed", animal.movement.currentSpeed);
|
||||
// if (complete) { animal.ChangeState(ToDefault); }
|
||||
// }
|
||||
// }
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 246d20af4dd47a14b9151feca52b870d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,39 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MuHua;
|
||||
|
||||
// public class AnimalEatingState : IStateMachine {
|
||||
// public string ToDefault = "Idle";
|
||||
|
||||
// private AnimalFood target;
|
||||
|
||||
// public AnimalMachine animal;
|
||||
// public AnimalEatingState(StateMachine machine) : base(machine) => animal = machine as AnimalMachine;
|
||||
|
||||
// public override void Enter() {
|
||||
// if (!animal.Find(out target)) { Exit(); return; }
|
||||
|
||||
// // 判断target距离是否小于0.3f
|
||||
// float distance = Vector3.Distance(animal.transform.position, target.transform.position);
|
||||
// if (distance >= 0.1f) { Exit(); return; }
|
||||
|
||||
// animal.animator.SetBool("Eating", true);
|
||||
// }
|
||||
|
||||
// public override void Exit() {
|
||||
// animal.animator.SetBool("Eating", false);
|
||||
// }
|
||||
|
||||
// public override void Trigger() {
|
||||
// animal.hunger += target.nutritionValue;
|
||||
// animal.hunger = Mathf.Clamp(animal.hunger, 0, animal.maxHunger);
|
||||
// GameObject.Destroy(target.gameObject);
|
||||
|
||||
// animal.ChangeState(ToDefault);
|
||||
// }
|
||||
|
||||
// public override void Update() {
|
||||
|
||||
// }
|
||||
// }
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d6c47e58145a2b44a20a3535cadc301
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class AnimalFood : MonoBehaviour
|
||||
{
|
||||
public float nutritionValue = 20.0f; // 饱食度增加值
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d83ffa2b763f0214298151e204ea0872
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,30 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MuHua;
|
||||
|
||||
// public class AnimalIdleState : IStateMachine {
|
||||
// public string ToDefault = "Roaming";
|
||||
|
||||
// private float idleTime;
|
||||
|
||||
// public AnimalMachine animal;
|
||||
// public AnimalIdleState(StateMachine machine) : base(machine) => animal = machine as AnimalMachine;
|
||||
|
||||
// public override void Enter() {
|
||||
// idleTime = Random.Range(3.0f, 5.0f);
|
||||
// }
|
||||
|
||||
// public override void Exit() {
|
||||
|
||||
// }
|
||||
|
||||
// public override void Trigger() {
|
||||
|
||||
// }
|
||||
|
||||
// public override void Update() {
|
||||
// idleTime -= Time.deltaTime;
|
||||
// if (idleTime <= 0) { animal.ChangeState(ToDefault); }
|
||||
// }
|
||||
// }
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8defd42d4b3f4a544bbeb381cb525533
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,81 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MuHua;
|
||||
|
||||
// public class AnimalMachine : StateMachine {
|
||||
// [Header("饥饿度参数")]
|
||||
// public float hunger = 100.0f; // 饥饿度,从0到100
|
||||
// public float maxHunger = 100.0f; // 最大饥饿度
|
||||
// public float searchRadius = 10.0f; // 搜索食物的半径
|
||||
|
||||
// [Header("控制组件")]
|
||||
// public Movement movement; // 运动控制器
|
||||
// public Animator animator; // 动画控制器
|
||||
|
||||
// private float hungerTimer = 0.0f; // 计时器
|
||||
// private float chasingCooldownTimer = 0.0f; // 追逐状态冷却计时器
|
||||
// private const float chasingCooldown = 5.0f; // 追逐状态冷却时间
|
||||
|
||||
// protected override void InitializeStates() {
|
||||
// RegisterState("Idle", new AnimalIdleState(this));
|
||||
// RegisterState("Roaming", new AnimalRoamingState(this));
|
||||
// RegisterState("Chasing", new AnimalChasingState<AnimalFood>(this));
|
||||
// RegisterState("Eating", new AnimalEatingState(this));
|
||||
|
||||
// ChangeState("Idle");
|
||||
// }
|
||||
|
||||
// protected override void Update() {
|
||||
// base.Update();
|
||||
|
||||
// // 更新计时器
|
||||
// hungerTimer += Time.deltaTime;
|
||||
// chasingCooldownTimer += Time.deltaTime;
|
||||
|
||||
// if (hungerTimer >= 1.0f) { ConsumeHunger(); }
|
||||
// }
|
||||
|
||||
// public virtual void ConsumeHunger() {
|
||||
// // 重置计时器
|
||||
// hungerTimer = 0.0f;
|
||||
// // 每次消耗1点饥饿度
|
||||
// hunger -= 1.0f;
|
||||
// if (hunger < 0.0f) { hunger = 0.0f; }
|
||||
|
||||
// // 如果饥饿度低于最大饥饿度的70%,有50%的概率触发Chasing状态
|
||||
// // 如果饥饿度低于最大饥饿度的30%,有90%的概率触发Chasing状态
|
||||
// float foraging = hunger < maxHunger * 0.3f ? 0.9f : 0.5f;
|
||||
// bool valid = hunger < maxHunger * 0.7f && Random.value < foraging;
|
||||
|
||||
// // 如果触发Chasing状态,且冷却时间已过,切换到Chasing状态
|
||||
// if (valid && chasingCooldownTimer >= chasingCooldown) {
|
||||
// ChangeState("Chasing");
|
||||
// chasingCooldownTimer = 0.0f; // 重置冷却计时器
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 从指定范围内查找指定类型的组件
|
||||
// public virtual bool Find<T>(out T value) where T : Component {
|
||||
// Collider[] colliders = Physics.OverlapSphere(transform.position, searchRadius);
|
||||
// foreach (Collider collider in colliders) {
|
||||
// T component = collider.GetComponent<T>();
|
||||
// if (component != null) {
|
||||
// value = component;
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// value = null;
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// // public override bool UpdateMove(Vector3 position) {
|
||||
// // return movement.UpdateMove(position);
|
||||
// // }
|
||||
// // public override void AnimationTrigger(string value) {
|
||||
// // throw new System.NotImplementedException();
|
||||
// // }
|
||||
// // public override void AnimationEnd() {
|
||||
// // throw new System.NotImplementedException();
|
||||
// // }
|
||||
// }
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a513572e2996d4748acb2838b4cadc89
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,30 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using MuHua;
|
||||
|
||||
// public class AnimalRoamingState : IStateMachine {
|
||||
// public Vector3 targetPosition;
|
||||
// public string ToDefault = "Idle";
|
||||
// public readonly AnimalMachine animal;
|
||||
// public AnimalRoamingState(StateMachine machine) : base(machine) => animal = machine as AnimalMachine;
|
||||
|
||||
// public override void Enter() {
|
||||
// targetPosition = animal.movement.RandomTargetPosition();
|
||||
// }
|
||||
|
||||
// public override void Exit() {
|
||||
// animal.movement.StopMoving();
|
||||
// animal.animator.SetFloat("MoveSpeed", 0);
|
||||
// }
|
||||
|
||||
// public override void Trigger() {
|
||||
|
||||
// }
|
||||
|
||||
// public override void Update() {
|
||||
// bool complete = animal.movement.UpdateMove(targetPosition);
|
||||
// animal.animator.SetFloat("MoveSpeed", animal.movement.currentSpeed);
|
||||
// if (complete) { animal.ChangeState(ToDefault); }
|
||||
// }
|
||||
// }
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 494833b7d85b90743956831570b1c49e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc54f6ddf4030054f974974bf79889d6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56476dea62b51fc41b2a53b9bdfaa56f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,56 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using MuHua;
|
||||
|
||||
public class TestUI : MonoBehaviour {
|
||||
/// <summary> 绑定文档 </summary>
|
||||
public UIDocument document;
|
||||
/// <summary> 根目录文档 </summary>
|
||||
public VisualElement root => document.rootVisualElement;
|
||||
|
||||
private UIScrollView scrollView;
|
||||
private UIScrollView scrollViewHorizontal;
|
||||
private UIScrollView scrollViewVertical;
|
||||
|
||||
private UISlider slider1;
|
||||
private UISlider slider2;
|
||||
private UISlider slider3;
|
||||
private UISlider slider4;
|
||||
|
||||
private void Awake() {
|
||||
VisualElement ScrollView = root.Q<VisualElement>("ScrollView");
|
||||
scrollView = new UIScrollView(ScrollView, root, UIDirection.HorizontalAndVertical);
|
||||
|
||||
VisualElement ScrollViewHorizontal = root.Q<VisualElement>("ScrollViewHorizontal");
|
||||
scrollViewHorizontal = new UIScrollView(ScrollViewHorizontal, root, UIDirection.Horizontal);
|
||||
|
||||
VisualElement ScrollViewVertical = root.Q<VisualElement>("ScrollViewVertical");
|
||||
scrollViewVertical = new UIScrollView(ScrollViewVertical, root, UIDirection.Vertical);
|
||||
|
||||
VisualElement Slider1 = root.Q<VisualElement>("SliderHorizontal1");
|
||||
slider1 = new UISlider(Slider1, root, UIDirection.FromLeftToRight);
|
||||
|
||||
VisualElement Slider2 = root.Q<VisualElement>("SliderHorizontal2");
|
||||
slider2 = new UISlider(Slider2, root, UIDirection.FromRightToLeft);
|
||||
|
||||
VisualElement Slider3 = root.Q<VisualElement>("SliderVertical1");
|
||||
slider3 = new UISlider(Slider3, root, UIDirection.FromTopToBottom);
|
||||
|
||||
VisualElement Slider4 = root.Q<VisualElement>("SliderVertical2");
|
||||
slider4 = new UISlider(Slider4, root, UIDirection.FromBottomToTop);
|
||||
|
||||
slider4.ValueChanged += (obj) => { Debug.Log(obj); };
|
||||
}
|
||||
private void Update() {
|
||||
scrollView.Update();
|
||||
scrollViewHorizontal.Update();
|
||||
scrollViewVertical.Update();
|
||||
|
||||
slider1.Update();
|
||||
slider2.Update();
|
||||
slider3.Update();
|
||||
slider4.Update();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 48270532e0731284a92ff8556d892c7e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,12 +0,0 @@
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
|
||||
<ui:Template name="ScrollView" src="project://database/Assets/MuHua/UITool/UIScrollView/ScrollView.uxml?fileID=9197481963319205126&guid=e95fad6397f22504eb724a8ea0c8d926&type=3#ScrollView" />
|
||||
<ui:Template name="ScrollViewHorizontal" src="project://database/Assets/MuHua/UITool/UIScrollView/ScrollViewHorizontal.uxml?fileID=9197481963319205126&guid=ac460a2d93de869499c04a4295795595&type=3#ScrollViewHorizontal" />
|
||||
<ui:Template name="ScrollViewVertical" src="project://database/Assets/MuHua/UITool/UIScrollView/ScrollViewVertical.uxml?fileID=9197481963319205126&guid=df824968495905e4db8daa1a4a942d6f&type=3#ScrollViewVertical" />
|
||||
<ui:Template name="UISlider" src="project://database/Assets/MuHua/UITool/UISlider/UISlider.uxml?fileID=9197481963319205126&guid=7360aa427d614894eab01f938a59da18&type=3#UISlider" />
|
||||
<ui:VisualElement style="flex-grow: 1; flex-direction: row;">
|
||||
<ui:Instance template="ScrollView" name="ScrollView" />
|
||||
<ui:Instance template="ScrollViewHorizontal" name="ScrollViewHorizontal" />
|
||||
<ui:Instance template="ScrollViewVertical" name="ScrollViewVertical" />
|
||||
<ui:Instance template="UISlider" name="UISlider" style="width: 300px;" />
|
||||
</ui:VisualElement>
|
||||
</ui:UXML>
|
||||
@@ -1,10 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 337d91fd31b0b764f97868cdacc90f66
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6636b9d6db0317e43a61b41ac2b2297d
|
||||
guid: 5714b692b8275aa4cb37f8f22344174e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 动作动画控制器
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Animator))]
|
||||
public class KinesisAnimator : MonoBehaviour {
|
||||
protected int layerIndex;
|
||||
protected string current;
|
||||
protected Animator animator;
|
||||
protected IKinesis kinesis;
|
||||
|
||||
public virtual void Awake() => animator = GetComponent<Animator>();
|
||||
|
||||
/// <summary> 设置动作 </summary>
|
||||
public virtual void SetKinesis(IKinesis kinesis) => this.kinesis = kinesis;
|
||||
/// <summary> 动画过渡 </summary>
|
||||
public virtual void Transition(int layerIndex, string name, float normalizedTransitionDuration = 0.1f) {
|
||||
animator.SetLayerWeight(this.layerIndex, 0);
|
||||
animator.SetLayerWeight(layerIndex, 1);
|
||||
this.layerIndex = layerIndex;
|
||||
Transition(name, normalizedTransitionDuration);
|
||||
}
|
||||
/// <summary> 动画过渡 </summary>
|
||||
public virtual void Transition(string name, float normalizedTransitionDuration = 0.1f) {
|
||||
if (current == name) { animator.Play(name); }
|
||||
else { animator.CrossFade(name, normalizedTransitionDuration); }
|
||||
current = name;
|
||||
}
|
||||
|
||||
/// <summary> 设置参数 </summary>
|
||||
public virtual void SetBool(string name, bool value) => animator.SetBool(name, value);
|
||||
/// <summary> 设置参数 </summary>
|
||||
public virtual void SetFloat(string name, float value) => animator.SetFloat(name, value);
|
||||
|
||||
/// <summary> 触发动画特效 </summary>
|
||||
public virtual void AnimationEffects() => kinesis?.AnimationEffects();
|
||||
/// <summary> 动画结束(有后摇) </summary>
|
||||
public virtual void AnimationEnd() => kinesis?.AnimationEnd();
|
||||
/// <summary> 动画退出(无后摇) </summary>
|
||||
public virtual void AnimationExit() => kinesis?.AnimationExit();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3ceef7224b9b094aadaa9b3a0238648
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,32 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 动作控制器
|
||||
/// </summary>
|
||||
public class KinesisController : MonoBehaviour {
|
||||
public KinesisAnimator animator;
|
||||
public KinesisMovement movement;
|
||||
|
||||
private IKinesis currentKinesis;
|
||||
|
||||
public virtual void Awake() => TransitionKinesis(new KinesisIdle());
|
||||
|
||||
public virtual void Update() => currentKinesis?.UpdateKinesis();
|
||||
|
||||
/// <summary> 动作过渡 </summary>
|
||||
public virtual void TransitionKinesis(IKinesis kinesis) {
|
||||
//不可以转换
|
||||
if (currentKinesis != null && !currentKinesis.Transition(kinesis)) { return; }
|
||||
//进行转换
|
||||
currentKinesis?.FinishKinesis();
|
||||
currentKinesis = kinesis;
|
||||
currentKinesis?.StartKinesis();
|
||||
|
||||
animator?.SetKinesis(currentKinesis);
|
||||
movement?.SetKinesis(currentKinesis);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c1979e13b26c7b48a7a4690da154535
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,100 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 动作运动控制器
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(CharacterController))]
|
||||
public class KinesisMovement : MonoBehaviour {
|
||||
public float moveSpeed = 5;// 移动速度
|
||||
public float acceleration = 10.0f;// 加速度
|
||||
[Range(0.0f, 0.3f)]
|
||||
public float rotationSmoothTime = 0.12f;// 旋转平滑
|
||||
|
||||
protected float currentSpeed;// 当前速度
|
||||
protected Vector2 moveDirection;// 移动方向
|
||||
protected float animationBlend;// 动画混合速度
|
||||
protected float targetRotation = 0.0f;// 旋转目标
|
||||
protected float rotationVelocity;// 旋转速度
|
||||
protected float verticalVelocity;// 垂直速度
|
||||
protected IKinesis kinesis;// 当前动作
|
||||
protected KinesisAnimator animator;// 动作动画控制器
|
||||
protected CharacterController controller;// 角色控制器
|
||||
|
||||
public virtual bool IsStop => currentSpeed == 0;
|
||||
|
||||
public virtual void Awake() {
|
||||
animator = GetComponent<KinesisAnimator>();
|
||||
controller = GetComponent<CharacterController>();
|
||||
}
|
||||
public virtual void Update() {
|
||||
PlanarMovement();
|
||||
}
|
||||
|
||||
/// <summary> 设置动作 </summary>
|
||||
public virtual void SetKinesis(IKinesis kinesis) => this.kinesis = kinesis;
|
||||
/// <summary> 设置方向 </summary>
|
||||
public virtual void SetDirection(Vector2 moveDirection) => this.moveDirection = moveDirection;
|
||||
/// <summary> 停止移动 </summary>
|
||||
public virtual void StopMovement() {
|
||||
currentSpeed = 0;
|
||||
moveDirection = Vector2.zero;
|
||||
animationBlend = 0;
|
||||
animator?.SetFloat("MoveSpeed", animationBlend);
|
||||
}
|
||||
|
||||
/// <summary> 平面移动 </summary>
|
||||
public virtual void PlanarMovement() {
|
||||
// 设定目标速度
|
||||
float targetSpeed = moveSpeed;
|
||||
|
||||
// 一种简单的加速和减速设计,易于拆卸、更换或迭代
|
||||
|
||||
// 如果没有输入,将目标速度设置为0
|
||||
if (moveDirection == Vector2.zero && currentSpeed == 0) { return; }
|
||||
if (moveDirection == Vector2.zero) targetSpeed = 0.0f;
|
||||
|
||||
// 当前水平速度的参考
|
||||
// float currentHorizontalSpeed = new Vector3(controller.velocity.x, 0.0f, controller.velocity.z).magnitude;
|
||||
|
||||
// float speedOffset = 0.1f;
|
||||
|
||||
// 加速或减速至目标速度
|
||||
// if (currentHorizontalSpeed < targetSpeed - speedOffset || currentHorizontalSpeed > targetSpeed + speedOffset) {
|
||||
// 产生弯曲的结果,而不是线性的结果,从而产生更有机的速度变化
|
||||
// 注意Lerp中的T是夹紧的,所以我们不需要夹紧我们的速度
|
||||
currentSpeed = Mathf.Lerp(currentSpeed, targetSpeed, Time.deltaTime * acceleration);
|
||||
|
||||
// round speed to 3 decimal places
|
||||
currentSpeed = Mathf.Round(currentSpeed * 1000f) / 1000f;
|
||||
// }
|
||||
// else { currentSpeed = targetSpeed; }
|
||||
|
||||
animationBlend = Mathf.Lerp(animationBlend, targetSpeed, Time.deltaTime * acceleration);
|
||||
if (animationBlend < 0.01f) animationBlend = 0f;
|
||||
|
||||
// 使输入方向标准化
|
||||
Vector3 inputDirection = new Vector3(moveDirection.x, 0.0f, moveDirection.y).normalized;
|
||||
|
||||
// 如果有移动输入,则在玩家移动时旋转玩家
|
||||
if (moveDirection != Vector2.zero) {
|
||||
targetRotation = Mathf.Atan2(inputDirection.x, inputDirection.z) * Mathf.Rad2Deg;
|
||||
float rotation = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetRotation, ref rotationVelocity, rotationSmoothTime);
|
||||
|
||||
// 相对于相机位置旋转到面向输入方向
|
||||
transform.rotation = Quaternion.Euler(0.0f, rotation, 0.0f);
|
||||
}
|
||||
|
||||
|
||||
Vector3 targetDirection = Quaternion.Euler(0.0f, targetRotation, 0.0f) * Vector3.forward;
|
||||
|
||||
// 移动
|
||||
controller.Move(targetDirection.normalized * (currentSpeed * Time.deltaTime) + new Vector3(0.0f, verticalVelocity, 0.0f) * Time.deltaTime);
|
||||
|
||||
// 如果使用角色,请更新动画师
|
||||
animator?.SetFloat("MoveSpeed", animationBlend);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61ef13b926e462442920d0ba932e8e27
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 运动器
|
||||
/// </summary>
|
||||
public abstract class Movement {
|
||||
/// <summary> 当前速度 </summary>
|
||||
public abstract float Speed { get; }
|
||||
/// <summary> 是否接地 </summary>
|
||||
public abstract bool Grounded { get; }
|
||||
/// <summary> 移动 </summary>
|
||||
public abstract void Move(Vector2 moveDirection, float moveSpeed, float acceleration, bool isRotation);
|
||||
/// <summary> 跳跃 </summary>
|
||||
public abstract void Jump(float jumpHeight);
|
||||
/// <summary> 更新 </summary>
|
||||
public abstract void Update();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 690f28715cec9bc41a56277db51f79fc
|
||||
guid: c48241a855a542e41b23b017edcab454
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,109 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 碰撞 - 运动器
|
||||
/// </summary>
|
||||
public class MovementCollision : Movement {
|
||||
/// <summary> 地面图层 </summary>
|
||||
public readonly LayerMask groundLayers;
|
||||
/// <summary> 角色控制器 </summary>
|
||||
public readonly CharacterController controller;
|
||||
|
||||
public float moveSpeed;// 移动速度
|
||||
public float currentSpeed;// 当前速度
|
||||
public float acceleration;// 加速度
|
||||
public float animationBlend;// 动画混合速度
|
||||
public Vector2 moveDirection;// 移动方向
|
||||
|
||||
public bool isRotation;// 是否旋转
|
||||
public float targetRotation;// 目标旋转
|
||||
public float rotationVelocity;// 旋转速度
|
||||
public float rotationSmoothTime = 0.12f;// 旋转平滑 Range(0.0f, 0.3f)
|
||||
|
||||
public bool grounded = true;// 是否接地
|
||||
public float verticalVelocity;// 垂直速度
|
||||
public float groundedRadius = 0.14f;// 地面检测半径
|
||||
|
||||
/// <summary> 垂直重力 </summary>
|
||||
public float Gravity => Physics.gravity.y;
|
||||
|
||||
public override float Speed => currentSpeed;
|
||||
|
||||
public override bool Grounded => grounded;
|
||||
|
||||
public MovementCollision(CharacterController controller, LayerMask groundLayers) {
|
||||
this.controller = controller;
|
||||
this.groundLayers = groundLayers;
|
||||
}
|
||||
|
||||
/// <summary> 移动 </summary>
|
||||
public override void Move(Vector2 moveDirection, float moveSpeed, float acceleration, bool isRotation) {
|
||||
this.moveSpeed = moveSpeed;
|
||||
this.acceleration = acceleration;
|
||||
this.moveDirection = moveDirection;
|
||||
this.isRotation = isRotation;
|
||||
}
|
||||
/// <summary> H*-2*G的平方根=达到所需高度所需的速度 </summary>
|
||||
public override void Jump(float jumpHeight) {
|
||||
verticalVelocity = Mathf.Sqrt(jumpHeight * -2f * Gravity);
|
||||
}
|
||||
/// <summary> 更新 </summary>
|
||||
public override void Update() {
|
||||
// 如果没有输入,将目标速度设置为0
|
||||
if (moveDirection == Vector2.zero) moveSpeed = 0.0f;
|
||||
|
||||
// 当前速度
|
||||
currentSpeed = Mathf.Lerp(currentSpeed, moveSpeed, Time.deltaTime * acceleration);
|
||||
|
||||
// 四舍五入到小数点后3位
|
||||
currentSpeed = Mathf.Round(currentSpeed * 1000f) / 1000f;
|
||||
|
||||
animationBlend = Mathf.Lerp(animationBlend, moveSpeed, Time.deltaTime * acceleration);
|
||||
if (animationBlend < 0.01f) animationBlend = 0f;
|
||||
|
||||
// 使输入方向标准化
|
||||
Vector3 inputDirection = new Vector3(moveDirection.x, 0.0f, moveDirection.y).normalized;
|
||||
|
||||
if (isRotation) {
|
||||
// 如果有移动输入,则在玩家移动时旋转玩家
|
||||
if (moveDirection != Vector2.zero) {
|
||||
targetRotation = Mathf.Atan2(inputDirection.x, inputDirection.z) * Mathf.Rad2Deg;
|
||||
float rotation = Mathf.SmoothDampAngle(controller.transform.eulerAngles.y, targetRotation, ref rotationVelocity, rotationSmoothTime);
|
||||
|
||||
// 相对于相机位置旋转到面向输入方向
|
||||
controller.transform.rotation = Quaternion.Euler(0.0f, rotation, 0.0f);
|
||||
}
|
||||
|
||||
// 移动
|
||||
Vector3 targetDirection = Quaternion.Euler(0.0f, targetRotation, 0.0f) * Vector3.forward;
|
||||
Vector3 horizontal = targetDirection.normalized * (currentSpeed * Time.deltaTime);
|
||||
Vector3 vertical = new Vector3(0.0f, verticalVelocity, 0.0f) * Time.deltaTime;
|
||||
controller.Move(horizontal + vertical);
|
||||
}
|
||||
else {
|
||||
// 移动
|
||||
Vector3 horizontal = inputDirection * (currentSpeed * Time.deltaTime);
|
||||
Vector3 vertical = new Vector3(0.0f, verticalVelocity, 0.0f) * Time.deltaTime;
|
||||
controller.Move(horizontal + vertical);
|
||||
}
|
||||
|
||||
// 地面检测
|
||||
Vector3 position = controller.transform.position;
|
||||
Vector3 rayOrigin = new Vector3(position.x, position.y + groundedRadius, position.z);
|
||||
// 射线长度稍微大于检测半径
|
||||
float rayLength = groundedRadius * 2 + 0.1f;
|
||||
// 使用射线检测地面
|
||||
grounded = Physics.Raycast(rayOrigin, Vector3.down, rayLength, groundLayers, QueryTriggerInteraction.Ignore);
|
||||
// 可选:调试显示射线
|
||||
Debug.DrawRay(rayOrigin, Vector3.down * rayLength, grounded ? Color.green : Color.red);
|
||||
|
||||
// 引力
|
||||
verticalVelocity += Gravity * Time.deltaTime;
|
||||
// 站在地面上时,限制最大下落速度
|
||||
if (grounded && verticalVelocity < 0.0f) { verticalVelocity = -2f; }
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4b97a8a3401e2a42903697e2b5acb2f
|
||||
guid: 06f3697338f20ac459ed126fc05a9694
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,101 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 标准 - 运动器
|
||||
/// </summary>
|
||||
public class MovementStandard : Movement {
|
||||
/// <summary> 地面图层 </summary>
|
||||
public readonly LayerMask groundLayers;
|
||||
/// <summary> 变换 </summary>
|
||||
public readonly Transform transform;
|
||||
|
||||
public float moveSpeed;// 移动速度
|
||||
public float currentSpeed;// 当前速度
|
||||
public float acceleration;// 加速度
|
||||
public float animationBlend;// 动画混合速度
|
||||
public Vector2 moveDirection;// 移动方向
|
||||
|
||||
public bool isRotation;// 是否旋转
|
||||
public float targetRotation;// 目标旋转
|
||||
public float rotationVelocity;// 旋转速度
|
||||
public float rotationSmoothTime = 0.12f;// 旋转平滑 Range(0.0f, 0.3f)
|
||||
|
||||
public bool grounded = true;// 是否接地
|
||||
public float verticalVelocity;// 垂直速度
|
||||
public float groundedRadius = 0.14f;// 地面检测半径
|
||||
|
||||
/// <summary> 垂直重力 </summary>
|
||||
public float Gravity => Physics.gravity.y;
|
||||
|
||||
public override float Speed => currentSpeed;
|
||||
|
||||
public override bool Grounded => grounded;
|
||||
|
||||
public MovementStandard(Transform transform, LayerMask groundLayers) {
|
||||
this.transform = transform;
|
||||
this.groundLayers = groundLayers;
|
||||
}
|
||||
|
||||
/// <summary> 移动 </summary>
|
||||
public override void Move(Vector2 moveDirection, float moveSpeed, float acceleration, bool isRotation) {
|
||||
this.moveSpeed = moveSpeed;
|
||||
this.acceleration = acceleration;
|
||||
this.moveDirection = moveDirection;
|
||||
this.isRotation = isRotation;
|
||||
}
|
||||
/// <summary> 跳跃 </summary>
|
||||
public override void Jump(float jumpHeight) {
|
||||
verticalVelocity = Mathf.Sqrt(jumpHeight * -2f * Gravity);
|
||||
}
|
||||
/// <summary> 更新 </summary>
|
||||
public override void Update() {
|
||||
// 如果没有输入,将目标速度设置为0
|
||||
if (moveDirection == Vector2.zero) moveSpeed = 0.0f;
|
||||
|
||||
// 当前速度
|
||||
currentSpeed = Mathf.Lerp(currentSpeed, moveSpeed, Time.deltaTime * acceleration);
|
||||
|
||||
// 四舍五入到小数点后3位
|
||||
currentSpeed = Mathf.Round(currentSpeed * 1000f) / 1000f;
|
||||
|
||||
animationBlend = Mathf.Lerp(animationBlend, moveSpeed, Time.deltaTime * acceleration);
|
||||
if (animationBlend < 0.01f) animationBlend = 0f;
|
||||
|
||||
// 使输入方向标准化
|
||||
Vector3 inputDirection = new Vector3(moveDirection.x, 0.0f, moveDirection.y).normalized;
|
||||
|
||||
// 如果有移动输入,则在玩家移动时旋转玩家
|
||||
if (moveDirection != Vector2.zero && isRotation) {
|
||||
targetRotation = Mathf.Atan2(inputDirection.x, inputDirection.z) * Mathf.Rad2Deg;
|
||||
float rotation = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetRotation, ref rotationVelocity, rotationSmoothTime);
|
||||
|
||||
// 相对于相机位置旋转到面向输入方向
|
||||
transform.rotation = Quaternion.Euler(0.0f, rotation, 0.0f);
|
||||
}
|
||||
|
||||
// 移动
|
||||
Vector3 targetDirection = Quaternion.Euler(0.0f, targetRotation, 0.0f) * Vector3.forward;
|
||||
Vector3 horizontal = targetDirection.normalized * (currentSpeed * Time.deltaTime);
|
||||
Vector3 vertical = new Vector3(0.0f, verticalVelocity, 0.0f) * Time.deltaTime;
|
||||
transform.position += horizontal + vertical;
|
||||
|
||||
// 地面检测
|
||||
Vector3 position = transform.position;
|
||||
Vector3 rayOrigin = new Vector3(position.x, position.y + groundedRadius, position.z);
|
||||
// 射线长度稍微大于检测半径
|
||||
float rayLength = groundedRadius * 2 + 0.1f;
|
||||
// 使用射线检测地面
|
||||
grounded = Physics.Raycast(rayOrigin, Vector3.down, rayLength, groundLayers, QueryTriggerInteraction.Ignore);
|
||||
// 可选:调试显示射线
|
||||
Debug.DrawRay(rayOrigin, Vector3.down * rayLength, grounded ? Color.green : Color.red);
|
||||
|
||||
// 引力
|
||||
verticalVelocity += Gravity * Time.deltaTime;
|
||||
// 站在地面上时,限制最大下落速度
|
||||
if (grounded && verticalVelocity < 0.0f) { verticalVelocity = -2f; }
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 06f3d6e55c2a1584ba20c9262c06704d
|
||||
guid: cf671b0b45929dc4c970eadb97df3ec8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a373c751fa5625249af75654ab69aec4
|
||||
guid: 197992f6020004c44a74153f43c5f7d1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
|
||||
@@ -4,23 +4,18 @@ using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 角色动作
|
||||
/// 运动
|
||||
/// </summary>
|
||||
public interface IKinesis {
|
||||
public abstract class IKinesis {
|
||||
/// <summary> 动作过渡 </summary>
|
||||
public bool Transition(IKinesis kinesis);
|
||||
public abstract bool Transition(IKinesis kinesis);
|
||||
/// <summary> 开始动作 </summary>
|
||||
public void StartKinesis();
|
||||
public abstract void StartKinesis();
|
||||
/// <summary> 更新动作 </summary>
|
||||
public void UpdateKinesis();
|
||||
public abstract void UpdateKinesis();
|
||||
/// <summary> 完成动作 </summary>
|
||||
public void FinishKinesis();
|
||||
|
||||
/// <summary> 触发动画特效 </summary>
|
||||
public void AnimationEffects();
|
||||
/// <summary> 动画结束(有后摇) </summary>
|
||||
public void AnimationEnd();
|
||||
/// <summary> 动画退出(无后摇) </summary>
|
||||
public void AnimationExit();
|
||||
public abstract void FinishKinesis();
|
||||
/// <summary> 动画结束 </summary>
|
||||
public abstract void AnimationExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e096ab8673cda9e42be867d97aae83eb
|
||||
guid: 1490d224da1fe674cb366599e7603d66
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bae5611456f58c64eaa6b106bc0b75cc
|
||||
guid: 338d1e647d487fe43aee258fbf63dfd4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 空闲 - 运动
|
||||
/// </summary>
|
||||
public class KIdle : IKinesis {
|
||||
public override bool Transition(IKinesis kinesis) {
|
||||
return true;
|
||||
}
|
||||
public override void StartKinesis() {
|
||||
// throw new System.NotImplementedException();
|
||||
}
|
||||
public override void UpdateKinesis() {
|
||||
// throw new System.NotImplementedException();
|
||||
}
|
||||
public override void FinishKinesis() {
|
||||
// throw new System.NotImplementedException();
|
||||
}
|
||||
public override void AnimationExit() {
|
||||
// throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4965f5d3a8eb6ef4ca7837688badb4e6
|
||||
guid: 29150243edc07d0429fea37464e830a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,102 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 跳跃 - 运动
|
||||
/// </summary>
|
||||
public class KJump : IKinesis {
|
||||
/// <summary> 基础角色 </summary>
|
||||
public readonly MCharacter character;
|
||||
|
||||
/// <summary> 结束跳跃 </summary>
|
||||
public bool isEndJump;
|
||||
/// <summary> 是否接地 </summary>
|
||||
public bool isGrounded;
|
||||
/// <summary> 允许转换 </summary>
|
||||
public bool isTransition;
|
||||
/// <summary> 跳跃高度 </summary>
|
||||
public float jumpHeight;
|
||||
/// <summary> 衰退速度 </summary>
|
||||
public float decaySpeed;
|
||||
/// <summary> 移动速度 </summary>
|
||||
public float moveSpeed = 2;
|
||||
/// <summary> 加速度 </summary>
|
||||
public float acceleration = 15;
|
||||
/// <summary> 移动方向 </summary>
|
||||
public Vector2 moveDirection;
|
||||
/// <summary> 初始位置 </summary>
|
||||
public Vector3 position;
|
||||
/// <summary> 初始角度 </summary>
|
||||
public Vector3 eulerAngles;
|
||||
/// <summary> 是否旋转 </summary>
|
||||
public bool isRotation;
|
||||
/// <summary> 初始设置 </summary>
|
||||
public bool isInitial = false;
|
||||
|
||||
/// <summary> 变换器 </summary>
|
||||
public Transform transform => character.transform;
|
||||
/// <summary> 动画器 </summary>
|
||||
public Animator animator => character.animator;
|
||||
/// <summary> 运动器 </summary>
|
||||
public Movement movement => character.movement;
|
||||
|
||||
public KJump(MCharacter character, Vector2 moveDirection, float jumpHeight, bool isRotation) {
|
||||
this.character = character;
|
||||
this.moveDirection = moveDirection;
|
||||
this.jumpHeight = jumpHeight;
|
||||
}
|
||||
|
||||
public void Settings(float moveSpeed, float acceleration) {
|
||||
this.moveSpeed = moveSpeed;
|
||||
this.acceleration = acceleration;
|
||||
}
|
||||
public void Settings(Vector3 position, Vector3 eulerAngles) {
|
||||
this.position = position;
|
||||
this.eulerAngles = eulerAngles;
|
||||
isInitial = true;
|
||||
}
|
||||
|
||||
public override bool Transition(IKinesis kinesis) {
|
||||
return isTransition;
|
||||
}
|
||||
public override void StartKinesis() {
|
||||
if (isInitial) {
|
||||
character.transform.position = position;
|
||||
character.transform.eulerAngles = eulerAngles;
|
||||
}
|
||||
isEndJump = false;
|
||||
isTransition = false;
|
||||
isGrounded = movement.Grounded;
|
||||
decaySpeed = movement.Speed;
|
||||
movement.Jump(jumpHeight);
|
||||
animator.SetTrigger("JumpStart");
|
||||
}
|
||||
public override void UpdateKinesis() {
|
||||
if (isEndJump) { return; }
|
||||
// 衰退速度
|
||||
decaySpeed = Mathf.Lerp(decaySpeed, 0, Time.deltaTime * 0.8f);
|
||||
movement.Move(moveDirection, decaySpeed, acceleration, isRotation);
|
||||
// 跳跃状态判断
|
||||
if (isGrounded == movement.Grounded) { return; }
|
||||
isGrounded = movement.Grounded;
|
||||
// 起跳
|
||||
if (!isGrounded) { return; }
|
||||
// 落地
|
||||
isEndJump = true;
|
||||
animator.SetTrigger("JumpLand");
|
||||
movement.Move(Vector2.zero, decaySpeed, acceleration, isRotation);
|
||||
}
|
||||
public override void FinishKinesis() {
|
||||
// throw new System.NotImplementedException();
|
||||
}
|
||||
public override void AnimationExit() {
|
||||
isTransition = true;
|
||||
// 转换到移动
|
||||
KMove kMove = new KMove(character, moveDirection, isRotation);
|
||||
kMove.Settings(moveSpeed, acceleration);
|
||||
character.Transition(kMove);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d61c404e3dc615b4eb590448b876863c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,73 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 移动 - 运动
|
||||
/// </summary>
|
||||
public class KMove : IKinesis {
|
||||
/// <summary> 基础角色 </summary>
|
||||
public readonly MCharacter character;
|
||||
|
||||
/// <summary> 移动速度 </summary>
|
||||
public float moveSpeed = 2;
|
||||
/// <summary> 加速度 </summary>
|
||||
public float acceleration = 15;
|
||||
/// <summary> 移动方向 </summary>
|
||||
public Vector2 moveDirection;
|
||||
/// <summary> 初始位置 </summary>
|
||||
public Vector3 position;
|
||||
/// <summary> 初始角度 </summary>
|
||||
public Vector3 eulerAngles;
|
||||
/// <summary> 是否旋转 </summary>
|
||||
public bool isRotation;
|
||||
/// <summary> 初始设置 </summary>
|
||||
public bool isInitial = false;
|
||||
|
||||
/// <summary> 变换器 </summary>
|
||||
public Transform transform => character.transform;
|
||||
/// <summary> 动画器 </summary>
|
||||
public Animator animator => character.animator;
|
||||
/// <summary> 运动器 </summary>
|
||||
public Movement movement => character.movement;
|
||||
|
||||
public KMove(MCharacter character, Vector2 moveDirection, bool isRotation) {
|
||||
this.character = character;
|
||||
this.moveDirection = moveDirection;
|
||||
this.isRotation = isRotation;
|
||||
}
|
||||
|
||||
public void Settings(float moveSpeed, float acceleration) {
|
||||
this.moveSpeed = moveSpeed;
|
||||
this.acceleration = acceleration;
|
||||
}
|
||||
public void Settings(Vector3 position, Vector3 eulerAngles) {
|
||||
this.position = position;
|
||||
this.eulerAngles = eulerAngles;
|
||||
isInitial = true;
|
||||
}
|
||||
|
||||
public override bool Transition(IKinesis kinesis) {
|
||||
return true;
|
||||
}
|
||||
public override void StartKinesis() {
|
||||
movement.Move(moveDirection, moveSpeed, acceleration, isRotation);
|
||||
if (!isInitial) { return; }
|
||||
transform.position = position;
|
||||
transform.eulerAngles = eulerAngles;
|
||||
}
|
||||
public override void UpdateKinesis() {
|
||||
// 更新动画器
|
||||
animator.SetFloat("MoveSpeed", movement.Speed);
|
||||
// 移动结束
|
||||
if (movement.Speed == 0) { character.Transition(new KIdle()); }
|
||||
}
|
||||
public override void FinishKinesis() {
|
||||
// throw new System.NotImplementedException();
|
||||
}
|
||||
public override void AnimationExit() {
|
||||
// throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2b41872ba018e447a649cb6bb35059f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 角色 - 模块
|
||||
/// </summary>
|
||||
public abstract class MCharacter {
|
||||
|
||||
/// <summary> 变换器 </summary>
|
||||
public Transform transform;
|
||||
/// <summary> 动画器 </summary>
|
||||
public Animator animator;
|
||||
/// <summary> 运动器 </summary>
|
||||
public Movement movement;
|
||||
|
||||
public MCharacter(Animator animator) => this.animator = animator;
|
||||
|
||||
/// <summary> 更新 </summary>
|
||||
public abstract void Update();
|
||||
/// <summary> 动作过渡 </summary>
|
||||
public abstract bool Transition(IKinesis kinesis);
|
||||
/// <summary> 动画结束 </summary>
|
||||
public abstract void AnimationExit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f75543aff254f1c4899eb3d332ba5de9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 碰撞角色 - 模块
|
||||
/// </summary>
|
||||
public class MCharacterCollision : MCharacter {
|
||||
|
||||
/// <summary> 当前动作 </summary>
|
||||
public IKinesis currentKinesis;
|
||||
|
||||
public MCharacterCollision(Animator animator, CharacterController controller, LayerMask ground) : base(animator) {
|
||||
movement = new MovementCollision(controller, ground);
|
||||
|
||||
Transition(new KIdle());
|
||||
}
|
||||
|
||||
public override void Update() {
|
||||
movement.Update();
|
||||
currentKinesis.UpdateKinesis();
|
||||
}
|
||||
public override bool Transition(IKinesis kinesis) {
|
||||
// 不可以转换
|
||||
if (currentKinesis != null && !currentKinesis.Transition(kinesis)) { return false; }
|
||||
// 进行转换
|
||||
currentKinesis?.FinishKinesis();
|
||||
currentKinesis = kinesis;
|
||||
currentKinesis?.StartKinesis();
|
||||
return true;
|
||||
}
|
||||
public override void AnimationExit() {
|
||||
currentKinesis.AnimationExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa752d6843dd06146b699b3588a59ea1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MCharacterRigidbody : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c073d7ddd6e118746b2709e22bcf7ea6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 标准角色 - 模块
|
||||
/// </summary>
|
||||
public class MCharacterStandard : MCharacter {
|
||||
|
||||
/// <summary> 当前动作 </summary>
|
||||
public IKinesis currentKinesis;
|
||||
|
||||
public MCharacterStandard(Animator animator, LayerMask ground) : base(animator) {
|
||||
movement = new MovementStandard(transform, ground);
|
||||
|
||||
Transition(new KIdle());
|
||||
}
|
||||
|
||||
public override void Update() {
|
||||
movement.Update();
|
||||
currentKinesis.UpdateKinesis();
|
||||
}
|
||||
public override bool Transition(IKinesis kinesis) {
|
||||
// 不可以转换
|
||||
if (currentKinesis != null && !currentKinesis.Transition(kinesis)) { return false; }
|
||||
// 进行转换
|
||||
currentKinesis?.FinishKinesis();
|
||||
currentKinesis = kinesis;
|
||||
currentKinesis?.StartKinesis();
|
||||
return true;
|
||||
}
|
||||
public override void AnimationExit() {
|
||||
currentKinesis.AnimationExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7eb8fc105ff36704499c0a954daa9c5c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c36f49b360d4c048aef47715ebb0616
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,20 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 空闲动作
|
||||
/// </summary>
|
||||
public class KinesisIdle : IKinesis {
|
||||
|
||||
public bool Transition(IKinesis kinesis) => true;
|
||||
public void StartKinesis() { }
|
||||
public void UpdateKinesis() { }
|
||||
public void FinishKinesis() { }
|
||||
|
||||
public void AnimationEffects() { }
|
||||
public void AnimationEnd() { }
|
||||
public void AnimationExit() { }
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99fdb0fe5f05b3b44bf010af88ab1f8f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,61 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 移动动作
|
||||
/// </summary>
|
||||
public class KinesisMove : IKinesis {
|
||||
|
||||
public Vector3 position;
|
||||
public Vector3 eulerAngles;
|
||||
public Vector2 moveDirection;// 移动方向
|
||||
public KinesisMovement movement;
|
||||
public KinesisController controller;
|
||||
|
||||
public KinesisMove(KinesisController controller, Vector2 moveDirection) {
|
||||
this.controller = controller;
|
||||
this.moveDirection = moveDirection;
|
||||
movement = controller.movement;
|
||||
position = movement.transform.position;
|
||||
eulerAngles = movement.transform.eulerAngles;
|
||||
}
|
||||
public KinesisMove(KinesisController controller, Vector2 moveDirection, Vector3 position, Vector3 eulerAngles) {
|
||||
this.position = position;
|
||||
this.eulerAngles = eulerAngles;
|
||||
this.controller = controller;
|
||||
this.moveDirection = moveDirection;
|
||||
movement = controller.movement;
|
||||
}
|
||||
|
||||
public bool Transition(IKinesis kinesis) {
|
||||
KinesisMove move = kinesis as KinesisMove;
|
||||
if (move == null) { return true; }
|
||||
position = move.position;
|
||||
eulerAngles = move.eulerAngles;
|
||||
moveDirection = move.moveDirection;
|
||||
movement.transform.position = position;
|
||||
movement.transform.eulerAngles = eulerAngles;
|
||||
movement.SetDirection(moveDirection);
|
||||
return false;
|
||||
}
|
||||
public void StartKinesis() {
|
||||
movement.transform.position = position;
|
||||
movement.transform.eulerAngles = eulerAngles;
|
||||
movement.SetDirection(moveDirection);
|
||||
}
|
||||
public void UpdateKinesis() {
|
||||
if (!movement.IsStop) { return; }
|
||||
controller.TransitionKinesis(new KinesisIdle());
|
||||
}
|
||||
public void FinishKinesis() {
|
||||
movement.StopMovement();
|
||||
}
|
||||
|
||||
public void AnimationEffects() { }
|
||||
public void AnimationEnd() { }
|
||||
public void AnimationExit() { }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c1bd98cf0e078140ab99d637e398ed1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -14,8 +14,5 @@
|
||||
"description": "",
|
||||
"path": "Samples"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"com.unity.inputsystem": "1.7.0"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -283,9 +283,7 @@
|
||||
"version": "file:Character",
|
||||
"depth": 0,
|
||||
"source": "embedded",
|
||||
"dependencies": {
|
||||
"com.unity.inputsystem": "1.7.0"
|
||||
}
|
||||
"dependencies": {}
|
||||
},
|
||||
"muhua-follow-tag": {
|
||||
"version": "file:FollowTag",
|
||||
|
||||
Reference in New Issue
Block a user