123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- using System;
- using System.Collections.Generic;
- using Core.Utility;
- using Fort23.Core;
- using GameLogic.CombatScenesTool;
- using UnityEngine;
- using Random = UnityEngine.Random;
- namespace GameLogic.Combat.CombatTool
- {
- public class CombatSenceController : IDisposable
- {
- private AssetHandle scenesHandle;
- public GameObject scenes1;
- public CombatSencePath currBesselPath;
- public CombatSencePath NextBesselPath;
- private float moveTime;
- private Vector3 lasetPos;
- private float maxD = 100;
- private Vector3 lasetDir;
- public float currTime;
- public Transform moveRoot;
- public async CTask InitScenes()
- {
- GameObject gameObject = new GameObject("mvoeRoot");
- moveRoot = gameObject.transform;
- CTaskAwaitBuffer cTaskAwaitBuffer = new CTaskAwaitBuffer();
- cTaskAwaitBuffer.AddTask(AssetBundleLoadManager.Instance.LoadAssetAsyncTask<GameObject>(
- "shan1.prefab",
- delegate(AssetHandle handle)
- {
- scenesHandle = handle;
- scenes1 = scenesHandle.AssetObject<GameObject>();
- scenes1.SetActive(false);
- }));
- lasetDir = Vector3.forward;
- await cTaskAwaitBuffer.WaitAll();
- currBesselPath = InitBesselPath(lasetPos);
- }
- private CombatSencePath InitBesselPath(Vector3 satrtPos)
- {
- CombatSencePath besselPath = new CombatSencePath();
- Vector3 target = satrtPos + lasetDir.normalized * maxD;
- // if (offx == 0)
- {
- besselPath.SetPos(satrtPos, target);
- }
- Vector3 p = besselPath.GetValue(0.99f);
- lasetDir = (target - p).normalized;
- GameObject gameObject = new GameObject("path");
- gameObject.transform.position = satrtPos;
- CombatPathMono combatPathMono = gameObject.AddComponent<CombatPathMono>();
- combatPathMono.BesselPath = besselPath;
- InitZhuangSHi(besselPath);
- return besselPath;
- }
- private CombatSencePath InitBesselPath(Vector3 satrtPos, float offx)
- {
- CombatSencePath besselPath = new CombatSencePath();
- Vector3 dir = Quaternion.LookRotation(lasetDir) * new Vector3(offx, 0, 1);
- Vector3 target = satrtPos + dir.normalized * maxD;
- Vector3 dir2 = Quaternion.LookRotation(lasetDir) * new Vector3(offx*-1, 0, 1);
- Vector3 centre = satrtPos + dir2.normalized * maxD;
- // if (offx == 0)
- {
- besselPath.SetPos(satrtPos, centre, target);
- }
- Vector3 p = besselPath.GetValue(0.99f);
- lasetDir = (target - p).normalized;
- GameObject gameObject = new GameObject("path");
- gameObject.transform.position = satrtPos;
- CombatPathMono combatPathMono = gameObject.AddComponent<CombatPathMono>();
- combatPathMono.BesselPath = besselPath;
- InitZhuangSHi(besselPath);
- return besselPath;
- }
- private void InitZhuangSHi(CombatSencePath besselPath)
- {
- int count = Random.Range(30, 40);
- for (int i = 0; i < count; i++)
- {
- float md = Random.Range(0.1f, 0.9f);
- Vector3 p = besselPath.GetValue(md);
- Vector3 p2 = besselPath.GetValue(md - 0.01f);
- Vector3 dir = (p - p2);
- Vector3 cross = Vector3.Cross(dir, Vector3.up);
- cross = cross.normalized;
- int odds = Random.Range(0, 100);
- p += cross * Random.Range(8, 25) * (odds < 50 ? 1 : -1);
- GameObject g = GameObject.Instantiate(scenes1);
- g.SetActive(true);
- g.transform.position = p + new Vector3(0, Random.Range(-7, -4), 0);
- g.transform.eulerAngles = new Vector3(-90, 0, Random.Range(0, 360));
- }
- }
- public Vector3 GetTarget(float time)
- {
- if (time > 1)
- {
- if (NextBesselPath == null)
- {
- NextBesselPath = InitBesselPath(currBesselPath.b, 0);
- }
- time = time % 1;
- return NextBesselPath.GetValue(time);
- }
- else
- {
- return currBesselPath.GetValue(time);
- }
- }
- public Vector3 Move(float speedTime)
- {
- currTime += speedTime;
- Vector3 targetPos = Vector3.zero;
- if (currTime > 0.2f)
- {
- if (NextBesselPath == null)
- {
- int odds = Random.Range(0, 100);
- if (odds < 50)
- {
- NextBesselPath = InitBesselPath(currBesselPath.b, -1);
- }
- else
- {
- NextBesselPath = InitBesselPath(currBesselPath.b);
- }
- }
- }
- if (currTime > 1)
- {
- if (NextBesselPath == null)
- {
- NextBesselPath = InitBesselPath(currBesselPath.b, -1);
- }
- currTime = currTime % 1;
- targetPos = NextBesselPath.GetValue(currTime);
- currBesselPath = NextBesselPath;
- NextBesselPath = null;
- }
- else
- {
- targetPos = currBesselPath.GetValue(currTime);
- }
- moveRoot.transform.position = targetPos;
- return targetPos;
- }
- public void Update(float t)
- {
-
- }
- public void Dispose()
- {
- if (scenesHandle != null)
- {
- scenesHandle.Release();
- }
- }
- }
- }
|