mirror of
https://github.com/soarqin/DSP_Mods_TO.git
synced 2026-02-04 22:22:22 +08:00
add XianTu
This commit is contained in:
50
XianTu/AssetsLoader/ABEmbeddedAssetsLoad.cs
Normal file
50
XianTu/AssetsLoader/ABEmbeddedAssetsLoad.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
namespace AssetsLoader
|
||||
{
|
||||
internal class ABEmbeddedAssetsLoad : ABLoad
|
||||
{
|
||||
public ABEmbeddedAssetsLoad(string filename, string assetsNamespace = null)
|
||||
{
|
||||
var stackTrace = new StackTrace();
|
||||
var frame = stackTrace.GetFrame(1);
|
||||
var assembly = frame.GetMethod().DeclaringType.Assembly;
|
||||
var flag = assetsNamespace == null;
|
||||
if (flag)
|
||||
{
|
||||
assetsNamespace = assembly.FullName.Split([','])[0];
|
||||
}
|
||||
LoadAssetsFromEmbedded(filename, assetsNamespace, assembly);
|
||||
}
|
||||
|
||||
private void LoadAssetsFromEmbedded(string filename, string assetsNamespace, Assembly assembly)
|
||||
{
|
||||
var text = assetsNamespace + "." + filename;
|
||||
var manifestResourceStream = assembly.GetManifestResourceStream(text);
|
||||
var flag = manifestResourceStream == null;
|
||||
if (flag)
|
||||
{
|
||||
Debug.Log(string.Concat(["在", assembly.FullName, "找不到内嵌的资源", text, ",请检查内嵌资源中是否有它:"]));
|
||||
foreach (var text2 in assembly.GetManifestResourceNames())
|
||||
{
|
||||
Debug.Log(text2);
|
||||
}
|
||||
Debug.Log("------------------------");
|
||||
}
|
||||
else
|
||||
{
|
||||
Ab = AssetBundle.LoadFromStream(manifestResourceStream);
|
||||
Init();
|
||||
}
|
||||
}
|
||||
|
||||
public ABEmbeddedAssetsLoad(string filename, string dllFilepath, string dllNamespace)
|
||||
{
|
||||
var assembly = Assembly.LoadFrom(dllFilepath);
|
||||
LoadAssetsFromEmbedded(filename, dllNamespace, assembly);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
XianTu/AssetsLoader/ABFileLoad.cs
Normal file
13
XianTu/AssetsLoader/ABFileLoad.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetsLoader
|
||||
{
|
||||
internal class ABFileLoad : ABLoad
|
||||
{
|
||||
public ABFileLoad(string filepath)
|
||||
{
|
||||
Ab = AssetBundle.LoadFromFile(filepath);
|
||||
Init();
|
||||
}
|
||||
}
|
||||
}
|
||||
80
XianTu/AssetsLoader/ABLoad.cs
Normal file
80
XianTu/AssetsLoader/ABLoad.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetsLoader
|
||||
{
|
||||
public abstract class ABLoad : ILoad
|
||||
{
|
||||
protected void Init()
|
||||
{
|
||||
foreach (var text in Ab.GetAllAssetNames())
|
||||
{
|
||||
var flag = text.Contains("prefabs");
|
||||
if (flag)
|
||||
{
|
||||
PrefabPath = text.Substring(0, text.IndexOf("prefabs", StringComparison.OrdinalIgnoreCase));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public GameObject LoadPrefab(string path)
|
||||
{
|
||||
var flag = Ab == null;
|
||||
GameObject gameObject;
|
||||
if (flag)
|
||||
{
|
||||
Debug.Log("内嵌的AB包没有找到");
|
||||
gameObject = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var flag2 = path.Contains("/");
|
||||
if (flag2)
|
||||
{
|
||||
path = Path.Combine(PrefabPath, path);
|
||||
var flag3 = !path.EndsWith(".prefab", StringComparison.OrdinalIgnoreCase);
|
||||
if (flag3)
|
||||
{
|
||||
path += ".prefab";
|
||||
}
|
||||
}
|
||||
gameObject = Ab.LoadAsset<GameObject>(path);
|
||||
}
|
||||
return gameObject;
|
||||
}
|
||||
|
||||
public string LoadText(string path)
|
||||
{
|
||||
var flag = Ab == null;
|
||||
string text;
|
||||
if (flag)
|
||||
{
|
||||
Debug.Log("内嵌的AB包没有找到");
|
||||
text = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var flag2 = path.Contains("/");
|
||||
if (flag2)
|
||||
{
|
||||
path = Path.Combine(_txtPath, path);
|
||||
var flag3 = !path.EndsWith(".prefab", StringComparison.OrdinalIgnoreCase);
|
||||
if (flag3)
|
||||
{
|
||||
path += ".prefab";
|
||||
}
|
||||
}
|
||||
text = Ab.LoadAsset<TextAsset>(path).text;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
protected string PrefabPath;
|
||||
|
||||
protected AssetBundle Ab;
|
||||
|
||||
private string _txtPath;
|
||||
}
|
||||
}
|
||||
28
XianTu/AssetsLoader/ABLoader.cs
Normal file
28
XianTu/AssetsLoader/ABLoader.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.IO;
|
||||
|
||||
namespace AssetsLoader
|
||||
{
|
||||
public static class ABLoader
|
||||
{
|
||||
public static ABLoad LoadFromFile(string abFilename, string dir)
|
||||
{
|
||||
var text = Path.Combine(dir, abFilename);
|
||||
return new ABFileLoad(text);
|
||||
}
|
||||
|
||||
public static ABLoad LoadFromFile(string filepath)
|
||||
{
|
||||
return new ABFileLoad(filepath);
|
||||
}
|
||||
|
||||
public static ABLoad LoadFromEmbeddedAssets(string abFilename, string defaultNamespace = null)
|
||||
{
|
||||
return new ABEmbeddedAssetsLoad(abFilename, defaultNamespace);
|
||||
}
|
||||
|
||||
public static ABLoad LoadFromDll(string abFilename, string dllFilepath, string dllDefaultNameSpace)
|
||||
{
|
||||
return new ABEmbeddedAssetsLoad(abFilename, dllFilepath, dllDefaultNameSpace);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
XianTu/AssetsLoader/ILoad.cs
Normal file
11
XianTu/AssetsLoader/ILoad.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetsLoader
|
||||
{
|
||||
public interface ILoad
|
||||
{
|
||||
GameObject LoadPrefab(string path);
|
||||
|
||||
string LoadText(string path);
|
||||
}
|
||||
}
|
||||
17
XianTu/AssetsLoader/ResourceLoad.cs
Normal file
17
XianTu/AssetsLoader/ResourceLoad.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AssetsLoader
|
||||
{
|
||||
public class ResourceLoad : ILoad
|
||||
{
|
||||
public GameObject LoadPrefab(string path)
|
||||
{
|
||||
return Resources.Load<GameObject>(path);
|
||||
}
|
||||
|
||||
public string LoadText(string path)
|
||||
{
|
||||
return Resources.Load<TextAsset>(path).text;
|
||||
}
|
||||
}
|
||||
}
|
||||
156
XianTu/BlueTuUIData.cs
Normal file
156
XianTu/BlueTuUIData.cs
Normal file
@@ -0,0 +1,156 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XianTu
|
||||
{
|
||||
public class BlueTuUIData
|
||||
{
|
||||
[field: DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||
public event Action OnValueChange;
|
||||
|
||||
public static BlueTuUIData Instance { get; } = new();
|
||||
|
||||
public Vector3 Bias
|
||||
{
|
||||
get => _bias;
|
||||
set
|
||||
{
|
||||
_bias = value;
|
||||
var onValueChange = OnValueChange;
|
||||
if (onValueChange != null)
|
||||
{
|
||||
onValueChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 Scale
|
||||
{
|
||||
get => _scale;
|
||||
set
|
||||
{
|
||||
_scale = value;
|
||||
var onValueChange = OnValueChange;
|
||||
if (onValueChange != null)
|
||||
{
|
||||
onValueChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 Pivot
|
||||
{
|
||||
get => _pivot;
|
||||
set
|
||||
{
|
||||
_pivot = value;
|
||||
var onValueChange = OnValueChange;
|
||||
if (onValueChange != null)
|
||||
{
|
||||
onValueChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float LayerHeight
|
||||
{
|
||||
get => _layerHeight;
|
||||
set
|
||||
{
|
||||
_layerHeight = value;
|
||||
var onValueChange = OnValueChange;
|
||||
if (onValueChange != null)
|
||||
{
|
||||
onValueChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float Rotate
|
||||
{
|
||||
get => _rotate;
|
||||
set
|
||||
{
|
||||
_rotate = value;
|
||||
var onValueChange = OnValueChange;
|
||||
if (onValueChange != null)
|
||||
{
|
||||
onValueChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int LayerNumber
|
||||
{
|
||||
get => _layerNumber;
|
||||
set
|
||||
{
|
||||
var flag = LayerNumber < 1;
|
||||
if (!flag)
|
||||
{
|
||||
_layerNumber = value;
|
||||
var onValueChange = OnValueChange;
|
||||
if (onValueChange != null)
|
||||
{
|
||||
onValueChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Enable
|
||||
{
|
||||
get => _enable;
|
||||
set
|
||||
{
|
||||
_enable = value;
|
||||
var onValueChange = OnValueChange;
|
||||
if (onValueChange != null)
|
||||
{
|
||||
onValueChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BlueTuUIData Clone()
|
||||
{
|
||||
var blueTuUIData = (BlueTuUIData)MemberwiseClone();
|
||||
blueTuUIData.OnValueChange = null;
|
||||
return blueTuUIData;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
var blueTuUIData = new BlueTuUIData();
|
||||
_bias = blueTuUIData._bias;
|
||||
_scale = blueTuUIData._scale;
|
||||
_pivot = blueTuUIData._pivot;
|
||||
_layerHeight = blueTuUIData._layerHeight;
|
||||
_layerNumber = blueTuUIData._layerNumber;
|
||||
_rotate = blueTuUIData._rotate;
|
||||
_enable = true;
|
||||
}
|
||||
|
||||
|
||||
private Vector3 _bias = new(0f, 0f, 0f);
|
||||
|
||||
private Vector3 _scale = new(1f, 1f, 1f);
|
||||
|
||||
private Vector3 _pivot = new(0f, 0f, 0f);
|
||||
|
||||
private float _layerHeight = 5f;
|
||||
|
||||
private int _layerNumber = 1;
|
||||
|
||||
private float _rotate;
|
||||
|
||||
private bool _enable = true;
|
||||
|
||||
public Action OnBuildBtn;
|
||||
|
||||
public Action OnResetBtn;
|
||||
|
||||
public Action OnCopyBtn;
|
||||
}
|
||||
}
|
||||
41
XianTu/EmbeddedFileLoad.cs
Normal file
41
XianTu/EmbeddedFileLoad.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using AssetsLoader;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XianTu
|
||||
{
|
||||
internal class EmbeddedFileLoad : ILoad
|
||||
{
|
||||
public EmbeddedFileLoad(string assetsNamespace = null)
|
||||
{
|
||||
var stackTrace = new StackTrace();
|
||||
var frame = stackTrace.GetFrame(1);
|
||||
var assembly = frame.GetMethod().DeclaringType.Assembly;
|
||||
var flag = assetsNamespace == null;
|
||||
if (flag)
|
||||
{
|
||||
assetsNamespace = assembly.FullName.Split([','])[0];
|
||||
}
|
||||
this._assetsNamespace = assetsNamespace;
|
||||
this._assembly = assembly;
|
||||
}
|
||||
|
||||
public GameObject LoadPrefab(string path)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public string LoadText(string path)
|
||||
{
|
||||
using var manifestResourceStream = _assembly.GetManifestResourceStream(_assetsNamespace + "." + path.Replace('/', '.'));
|
||||
using var streamReader = new StreamReader(manifestResourceStream);
|
||||
return streamReader.ReadToEnd();
|
||||
}
|
||||
|
||||
private readonly string _assetsNamespace;
|
||||
|
||||
private readonly Assembly _assembly;
|
||||
}
|
||||
}
|
||||
22
XianTu/FileLoad.cs
Normal file
22
XianTu/FileLoad.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.IO;
|
||||
using AssetsLoader;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XianTu
|
||||
{
|
||||
internal class FileLoad(string dirPath) : ILoad
|
||||
{
|
||||
|
||||
public GameObject LoadPrefab(string path)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public string LoadText(string path)
|
||||
{
|
||||
return File.ReadAllText(Path.Combine(_dirPath, path));
|
||||
}
|
||||
|
||||
private readonly string _dirPath = dirPath ?? "";
|
||||
}
|
||||
}
|
||||
1
XianTu/FoundationBlueTu.txt
Normal file
1
XianTu/FoundationBlueTu.txt
Normal file
@@ -0,0 +1 @@
|
||||
BLUEPRINT:0,10,0,0,0,0,0,0,637975354775775693,0.9.26.13034,OnBelt,"H4sIAAAAAAAAC2NkQAWMUAxh/2dgWABlMsKFEWoPSG5DZZs4g/BFdmWG/1CAZBwDAHYxJApsAAAA"DEB2D60B60B70FA664332C993B2453B2
|
||||
64
XianTu/LoadManager.cs
Normal file
64
XianTu/LoadManager.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System.Collections.Generic;
|
||||
using AssetsLoader;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace XianTu;
|
||||
|
||||
public class LoadManager : Singleton<LoadManager>
|
||||
{
|
||||
public void SetLoader(ILoad loader)
|
||||
{
|
||||
_loaders = [loader];
|
||||
}
|
||||
|
||||
public void AddLoader(ILoad loader)
|
||||
{
|
||||
_loaders.Insert(0, loader);
|
||||
}
|
||||
|
||||
|
||||
public GameObject LoadPrefab(string path)
|
||||
{
|
||||
foreach (var load in _loaders)
|
||||
{
|
||||
var gameObject = load.LoadPrefab(path);
|
||||
var flag = gameObject != null;
|
||||
if (flag)
|
||||
{
|
||||
return gameObject;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public GameObject LoadPrefab(string path, Transform parent)
|
||||
{
|
||||
foreach (var load in _loaders)
|
||||
{
|
||||
var gameObject = load.LoadPrefab(path);
|
||||
var flag = gameObject != null;
|
||||
if (flag)
|
||||
{
|
||||
return Object.Instantiate(gameObject, parent);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public string LoadText(string path)
|
||||
{
|
||||
foreach (var load in _loaders)
|
||||
{
|
||||
var text = load.LoadText(path);
|
||||
var flag = text != "";
|
||||
if (flag)
|
||||
{
|
||||
return text;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private List<ILoad> _loaders = [new ResourceLoad()];
|
||||
}
|
||||
6
XianTu/Properties/AssemblyInfo.cs
Normal file
6
XianTu/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyCopyright("Copyright © 2022")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: ComVisible(false)]
|
||||
413
XianTu/Scripts/DataController/BlueTuController.cs
Normal file
413
XianTu/Scripts/DataController/BlueTuController.cs
Normal file
@@ -0,0 +1,413 @@
|
||||
using System;
|
||||
using ToolScripts;
|
||||
using UnityEngine;
|
||||
using XianTu.UI;
|
||||
|
||||
namespace XianTu.Scripts.DataController
|
||||
{
|
||||
internal class BlueTuController
|
||||
{
|
||||
public BlueTuController()
|
||||
{
|
||||
_oldData = BlueTuUIData.Instance.Clone();
|
||||
_data = BlueTuUIData.Instance;
|
||||
Init_OnUIOpen();
|
||||
_data.OnValueChange += OnUserChangeData;
|
||||
var blueTuUIData = _data;
|
||||
blueTuUIData.OnBuildBtn = (Action)Delegate.Combine(blueTuUIData.OnBuildBtn, new Action(OnUserBuildDetermine));
|
||||
var blueTuUIData2 = _data;
|
||||
blueTuUIData2.OnCopyBtn = (Action)Delegate.Combine(blueTuUIData2.OnCopyBtn, new Action(OnUserCopy));
|
||||
var blueTuUIData3 = _data;
|
||||
blueTuUIData3.OnResetBtn = (Action)Delegate.Combine(blueTuUIData3.OnResetBtn, new Action(OnReset));
|
||||
var blueprintData = BlueTuDatabase.Load("FoundationBlueTu");
|
||||
_foundation = blueprintData.buildings[0];
|
||||
}
|
||||
|
||||
private void OnUserCopy()
|
||||
{
|
||||
_actionBuild.blueprintClipboard = _bPaste.blueprint;
|
||||
ResetBuildDuiDie();
|
||||
_bPaste.RefreshBlueprintUI();
|
||||
}
|
||||
|
||||
private void Init_OnUIOpen()
|
||||
{
|
||||
UIManager.Instance.CanvasMonoEvent.onEnableEvent.AddListener(OnReset);
|
||||
}
|
||||
|
||||
private void OnReset()
|
||||
{
|
||||
Player = GameMain.mainPlayer;
|
||||
var flag = Player == null;
|
||||
if (flag)
|
||||
{
|
||||
_data.Enable = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_playerController = Player.controller;
|
||||
_actionBuild = PlayerController.actionBuild;
|
||||
var flag2 = _actionBuild != null;
|
||||
if (flag2)
|
||||
{
|
||||
_activeTool = _actionBuild.activeTool;
|
||||
var buildToolBlueprintPaste = _activeTool as BuildTool_BlueprintPaste;
|
||||
var flag3 = buildToolBlueprintPaste != null;
|
||||
if (flag3)
|
||||
{
|
||||
_bPaste = buildToolBlueprintPaste;
|
||||
var mouseRay = _actionBuild.activeTool.mouseRay;
|
||||
_defaultMouseRay = new Ray(mouseRay.origin, mouseRay.direction);
|
||||
var flag4 = buildToolBlueprintPaste.blueprint != _blueprint;
|
||||
if (flag4)
|
||||
{
|
||||
_templateBlueTu = buildToolBlueprintPaste.blueprint.Clone();
|
||||
_blueprint = buildToolBlueprintPaste.blueprint;
|
||||
}
|
||||
_oldData = new BlueTuUIData();
|
||||
_data.Reset();
|
||||
_data.Enable = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
_data.Enable = false;
|
||||
}
|
||||
}
|
||||
|
||||
private Player Player { get; set; }
|
||||
|
||||
private void OnUserBuildDetermine()
|
||||
{
|
||||
var flag = _actionBuild.activeTool != null;
|
||||
if (flag)
|
||||
{
|
||||
var buildToolBlueprintPaste = _actionBuild.activeTool as BuildTool_BlueprintPaste;
|
||||
var flag2 = buildToolBlueprintPaste != null;
|
||||
if (flag2)
|
||||
{
|
||||
var flag3 = buildToolBlueprintPaste.CheckBuildConditionsPrestage();
|
||||
if (flag3)
|
||||
{
|
||||
ResetBuildDuiDie();
|
||||
Build(buildToolBlueprintPaste);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetBuildDuiDie()
|
||||
{
|
||||
var buildToolBlueprintPaste = _bPaste;
|
||||
BlueprintBuilding blueprintBuilding = null;
|
||||
foreach (var blueprintBuilding2 in buildToolBlueprintPaste.blueprint.buildings)
|
||||
{
|
||||
var flag = Math.Abs(blueprintBuilding2.localOffset_z) < 1.5f;
|
||||
if (flag)
|
||||
{
|
||||
var itemProto = LDB.items.Select(blueprintBuilding2.itemId);
|
||||
Debug.Log($"基底查验:{itemProto.name}.{itemProto.ID}:{blueprintBuilding2.localOffset_x:2f}, {blueprintBuilding2.localOffset_y:2f}, {blueprintBuilding2.localOffset_z:2f}");
|
||||
blueprintBuilding = blueprintBuilding2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
var flag2 = blueprintBuilding == null;
|
||||
if (flag2)
|
||||
{
|
||||
Debug.Log("没有基底");
|
||||
}
|
||||
var flag3 = blueprintBuilding == null;
|
||||
if (flag3)
|
||||
{
|
||||
var buildings2 = _bPaste.blueprint.buildings;
|
||||
var array = new BlueprintBuilding[_bPaste.blueprint.buildings.Length + 1];
|
||||
_bPaste.blueprint.buildings = array;
|
||||
buildings2.CopyTo(array, 0);
|
||||
blueprintBuilding = _foundation;
|
||||
blueprintBuilding.index = buildings2.Length;
|
||||
blueprintBuilding.localOffset_z = -0.5f;
|
||||
array[buildings2.Length] = blueprintBuilding;
|
||||
}
|
||||
foreach (var blueprintBuilding3 in _bPaste.blueprint.buildings)
|
||||
{
|
||||
var flag4 = blueprintBuilding3.IsBelt();
|
||||
if (!flag4)
|
||||
{
|
||||
var flag5 = blueprintBuilding3.IsSlot();
|
||||
if (!flag5)
|
||||
{
|
||||
var flag6 = blueprintBuilding3 == blueprintBuilding;
|
||||
if (!flag6)
|
||||
{
|
||||
blueprintBuilding3.inputToSlot = 14;
|
||||
blueprintBuilding3.outputFromSlot = 15;
|
||||
blueprintBuilding3.inputFromSlot = 15;
|
||||
blueprintBuilding3.outputToSlot = 14;
|
||||
blueprintBuilding3.inputObj = blueprintBuilding;
|
||||
blueprintBuilding3.inputFromSlot = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_bPaste.bpCursor = _bPaste.blueprint.buildings.Length;
|
||||
_bPaste.buildPreviews.Clear();
|
||||
_bPaste.ResetStates();
|
||||
_BuildTool_BluePrint_OnTick();
|
||||
}
|
||||
|
||||
private void Build(BuildTool_BlueprintPaste bp)
|
||||
{
|
||||
PlayerController.cmd.stage = 1;
|
||||
bp.GenerateBlueprintGratBoxes();
|
||||
bp.DeterminePreviewsPrestage(true);
|
||||
bp.ActiveColliders(_actionBuild.model);
|
||||
bp.buildCondition = bp.CheckBuildConditions();
|
||||
bp.DeterminePreviews();
|
||||
bp.DeactiveColliders(_actionBuild.model);
|
||||
var buildCondition = bp.buildCondition;
|
||||
if (buildCondition)
|
||||
{
|
||||
bp.CreatePrebuilds();
|
||||
bp.ResetStates();
|
||||
}
|
||||
else
|
||||
{
|
||||
bp.isDragging = false;
|
||||
bp.startGroundPosSnapped = bp.castGroundPosSnapped;
|
||||
_BuildTool_BluePrint_OnTick();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUserChangeData()
|
||||
{
|
||||
var flag = !_data.Enable;
|
||||
if (!flag)
|
||||
{
|
||||
var flag2 = PlayerController == null;
|
||||
if (!flag2)
|
||||
{
|
||||
var flag3 = _actionBuild == null;
|
||||
if (!flag3)
|
||||
{
|
||||
var flag4 = _bPaste == null;
|
||||
if (!flag4)
|
||||
{
|
||||
var vector = _data.Bias - _oldData.Bias;
|
||||
var num = _data.LayerHeight - _oldData.LayerHeight;
|
||||
var num2 = _data.LayerNumber - _oldData.LayerNumber;
|
||||
var num3 = _data.Rotate - _oldData.Rotate;
|
||||
var flag5 = _actionBuild != null;
|
||||
if (flag5)
|
||||
{
|
||||
CtrlLayerNumber(num2);
|
||||
CtrlLayerHeight(num);
|
||||
CtrlRotate(num3);
|
||||
CtrlBiasData(vector);
|
||||
CtrlScale();
|
||||
_BuildTool_BluePrint_OnTick();
|
||||
}
|
||||
_oldData.Scale = _data.Scale;
|
||||
_oldData.Pivot = _data.Pivot;
|
||||
_oldData.LayerHeight = _data.LayerHeight;
|
||||
_oldData.LayerNumber = _data.LayerNumber;
|
||||
_oldData.Rotate = _data.Rotate;
|
||||
_oldData.Bias = _data.Bias;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CtrlLayerNumber(int bLayerNumber)
|
||||
{
|
||||
var flag = bLayerNumber == 0;
|
||||
if (!flag)
|
||||
{
|
||||
var num = _data.LayerNumber * _templateBlueTu.buildings.Length;
|
||||
var buildings = _bPaste.blueprint.buildings;
|
||||
var array = new BlueprintBuilding[num];
|
||||
var flag2 = buildings.Length > num;
|
||||
if (flag2)
|
||||
{
|
||||
Array.Copy(buildings, array, num);
|
||||
}
|
||||
else
|
||||
{
|
||||
buildings.CopyTo(array, 0);
|
||||
var num2 = _templateBlueTu.buildings.Length;
|
||||
for (var i = _bPaste.bpCursor; i < array.Length; i += num2)
|
||||
{
|
||||
_templateBlueTu.Clone().buildings.CopyTo(array, i);
|
||||
}
|
||||
for (var j = _bPaste.bpCursor; j < array.Length; j++)
|
||||
{
|
||||
array[j].localOffset_z = array[j - num2].localOffset_z + _data.LayerHeight;
|
||||
array[j].localOffset_z2 = array[j - num2].localOffset_z2 + _data.LayerHeight;
|
||||
}
|
||||
for (var k = _bPaste.bpCursor; k < array.Length; k++)
|
||||
{
|
||||
array[k].index = k;
|
||||
}
|
||||
}
|
||||
_bPaste.blueprint.buildings = array;
|
||||
_bPaste.bpCursor = _bPaste.blueprint.buildings.Length;
|
||||
_bPaste.buildPreviews.Clear();
|
||||
_bPaste.ResetStates();
|
||||
}
|
||||
}
|
||||
|
||||
private void CtrlLayerHeight(float bLayerHeight)
|
||||
{
|
||||
var flag = bLayerHeight == 0f;
|
||||
if (!flag)
|
||||
{
|
||||
var num = _templateBlueTu.buildings.Length;
|
||||
var num2 = 0;
|
||||
var buildings = _bPaste.blueprint.buildings;
|
||||
for (var i = 0; i < _bPaste.bpCursor; i++)
|
||||
{
|
||||
var flag2 = i == num * (num2 + 1);
|
||||
if (flag2)
|
||||
{
|
||||
num2++;
|
||||
}
|
||||
buildings[i].localOffset_z += bLayerHeight * num2;
|
||||
buildings[i].localOffset_z2 += bLayerHeight * num2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CtrlScale()
|
||||
{
|
||||
var flag = _oldData.Scale == _data.Scale;
|
||||
if (!flag)
|
||||
{
|
||||
var buildings = _templateBlueTu.buildings;
|
||||
var vector = _data.Scale - _oldData.Scale;
|
||||
var pivot = _data.Pivot;
|
||||
var num = 0;
|
||||
for (var i = 0; i < _bPaste.bpCursor; i++)
|
||||
{
|
||||
var flag2 = num == buildings.Length;
|
||||
if (flag2)
|
||||
{
|
||||
num = 0;
|
||||
}
|
||||
var blueprintBuilding = buildings[num];
|
||||
var blueprintBuilding2 = _bPaste.blueprint.buildings[i];
|
||||
blueprintBuilding2.localOffset_x += (blueprintBuilding.localOffset_x - pivot.x) * vector.x + pivot.x;
|
||||
blueprintBuilding2.localOffset_y += (blueprintBuilding.localOffset_y - pivot.y) * vector.y + pivot.y;
|
||||
blueprintBuilding2.localOffset_z += blueprintBuilding.localOffset_z * vector.z;
|
||||
blueprintBuilding2.localOffset_x2 += (blueprintBuilding.localOffset_x2 - pivot.x) * vector.x + pivot.x;
|
||||
blueprintBuilding2.localOffset_y2 += (blueprintBuilding.localOffset_y2 - pivot.y) * vector.y + pivot.y;
|
||||
blueprintBuilding2.localOffset_z2 += blueprintBuilding.localOffset_z2 * vector.z;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CtrlRotate(float bRotate)
|
||||
{
|
||||
var flag = Math.Abs(bRotate) < 0.001f;
|
||||
if (!flag)
|
||||
{
|
||||
var buildToolBlueprintPaste = _actionBuild.activeTool as BuildTool_BlueprintPaste;
|
||||
var flag2 = buildToolBlueprintPaste != null;
|
||||
if (flag2)
|
||||
{
|
||||
var pivot = _data.Pivot;
|
||||
var buildings = buildToolBlueprintPaste.blueprint.buildings;
|
||||
var quaternion = Quaternion.AngleAxis(bRotate, Vector3.forward);
|
||||
for (var i = 0; i < _bPaste.bpCursor; i++)
|
||||
{
|
||||
var blueprintBuilding = buildings[i];
|
||||
var vector = new Vector3(blueprintBuilding.localOffset_x - pivot.x, blueprintBuilding.localOffset_y - pivot.y, 0f);
|
||||
vector = quaternion * vector;
|
||||
blueprintBuilding.localOffset_x = vector.x + pivot.x;
|
||||
blueprintBuilding.localOffset_y = vector.y + pivot.y;
|
||||
blueprintBuilding.yaw -= bRotate;
|
||||
vector = new Vector3(blueprintBuilding.localOffset_x2 - pivot.x, blueprintBuilding.localOffset_y2 - pivot.y, 0f);
|
||||
vector = quaternion * vector;
|
||||
blueprintBuilding.localOffset_x2 = vector.x + pivot.x;
|
||||
blueprintBuilding.localOffset_y2 = vector.y + pivot.y;
|
||||
blueprintBuilding.yaw2 -= bRotate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PlayerController PlayerController => _playerController;
|
||||
|
||||
private void CtrlBiasData(Vector3 bBias)
|
||||
{
|
||||
var flag = bBias == Vector3.zero;
|
||||
if (!flag)
|
||||
{
|
||||
var playerActionBuild = _actionBuild;
|
||||
var buildTool = playerActionBuild.activeTool;
|
||||
var buildToolBlueprintPaste = buildTool as BuildTool_BlueprintPaste;
|
||||
var flag2 = buildToolBlueprintPaste != null;
|
||||
if (flag2)
|
||||
{
|
||||
for (var i = 0; i < buildToolBlueprintPaste.bpCursor; i++)
|
||||
{
|
||||
var blueprintBuilding = buildToolBlueprintPaste.blueprint.buildings[i];
|
||||
blueprintBuilding.localOffset_x += bBias.x;
|
||||
blueprintBuilding.localOffset_x2 += bBias.x;
|
||||
blueprintBuilding.localOffset_y += bBias.y;
|
||||
blueprintBuilding.localOffset_y2 += bBias.y;
|
||||
blueprintBuilding.localOffset_z += bBias.z;
|
||||
blueprintBuilding.localOffset_z2 += bBias.z;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void _BuildTool_BluePrint_OnTick()
|
||||
{
|
||||
VFInput.onGUI = false;
|
||||
_bPaste.mouseRay = _defaultMouseRay;
|
||||
var buildToolBlueprintPaste = _activeTool as BuildTool_BlueprintPaste;
|
||||
var flag = buildToolBlueprintPaste != null;
|
||||
if (flag)
|
||||
{
|
||||
buildToolBlueprintPaste.ClearErrorMessage();
|
||||
buildToolBlueprintPaste.UpdateRaycast();
|
||||
var flag2 = PlayerController.cmd.stage == 0;
|
||||
if (flag2)
|
||||
{
|
||||
buildToolBlueprintPaste.OperatingPrestage();
|
||||
}
|
||||
else
|
||||
{
|
||||
var flag3 = PlayerController.cmd.stage == 1;
|
||||
if (flag3)
|
||||
{
|
||||
buildToolBlueprintPaste.Operating();
|
||||
}
|
||||
}
|
||||
buildToolBlueprintPaste.UpdatePreviewModels(_actionBuild.model);
|
||||
buildToolBlueprintPaste.ShowCursorText();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly BlueTuUIData _data;
|
||||
|
||||
private BlueTuUIData _oldData;
|
||||
|
||||
private PlayerController _playerController;
|
||||
|
||||
private Ray _defaultMouseRay;
|
||||
|
||||
private BlueprintData _templateBlueTu;
|
||||
|
||||
private PlayerAction_Build _actionBuild;
|
||||
|
||||
private BuildTool _activeTool;
|
||||
|
||||
private BuildTool_BlueprintPaste _bPaste;
|
||||
|
||||
private readonly BlueprintBuilding _foundation;
|
||||
|
||||
private BlueprintData _blueprint;
|
||||
}
|
||||
}
|
||||
35
XianTu/Scripts/DataController/BlueTuDatabase.cs
Normal file
35
XianTu/Scripts/DataController/BlueTuDatabase.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XianTu.Scripts.DataController
|
||||
{
|
||||
internal static class BlueTuDatabase
|
||||
{
|
||||
public static BlueprintData Load(string path)
|
||||
{
|
||||
var flag = !path.EndsWith(".txt");
|
||||
if (flag)
|
||||
{
|
||||
path += ".txt";
|
||||
}
|
||||
var text = Singleton<LoadManager>.Instance.LoadText(path);
|
||||
var flag2 = text == "";
|
||||
BlueprintData blueprintData;
|
||||
if (flag2)
|
||||
{
|
||||
Debug.Log("没有找到蓝图文件");
|
||||
blueprintData = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var blueprintData2 = BlueprintData.CreateNew(text);
|
||||
var flag3 = blueprintData2 == null;
|
||||
if (flag3)
|
||||
{
|
||||
Debug.Log("蓝图文件加载失败");
|
||||
}
|
||||
blueprintData = blueprintData2;
|
||||
}
|
||||
return blueprintData;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
XianTu/Singleton.cs
Normal file
21
XianTu/Singleton.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
|
||||
namespace XianTu;
|
||||
|
||||
public class Singleton<T> where T : new()
|
||||
{
|
||||
public static T Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
var flag = _msInstance == null;
|
||||
if (flag)
|
||||
{
|
||||
_msInstance = new T();
|
||||
}
|
||||
return _msInstance;
|
||||
}
|
||||
}
|
||||
|
||||
private static T _msInstance;
|
||||
}
|
||||
21
XianTu/ToolScripts/EventTriggerExpand.cs
Normal file
21
XianTu/ToolScripts/EventTriggerExpand.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace ToolScripts
|
||||
{
|
||||
internal static class EventTriggerExpand
|
||||
{
|
||||
public static void Add(this EventTrigger trigger, EventTriggerType eventID, UnityAction<BaseEventData> callback)
|
||||
{
|
||||
var flag = trigger.triggers == null;
|
||||
if (flag)
|
||||
{
|
||||
trigger.triggers = [];
|
||||
}
|
||||
var entry = new EventTrigger.Entry();
|
||||
entry.eventID = eventID;
|
||||
entry.callback.AddListener(callback);
|
||||
trigger.triggers.Add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
75
XianTu/ToolScripts/GameObjectExpand.cs
Normal file
75
XianTu/ToolScripts/GameObjectExpand.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace ToolScripts
|
||||
{
|
||||
public static class GameObjectExpand
|
||||
{
|
||||
public static T Find<T>(this GameObject obj, string name) where T : class
|
||||
{
|
||||
var gameObject = GameObject.Find(name);
|
||||
bool flag = gameObject;
|
||||
T t;
|
||||
if (flag)
|
||||
{
|
||||
t = gameObject.GetComponent<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
t = default(T);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
public static T Find<T>(this Transform obj, string name) where T : class
|
||||
{
|
||||
var transform = obj.Find(name);
|
||||
bool flag = transform;
|
||||
T t;
|
||||
if (flag)
|
||||
{
|
||||
t = transform.GetComponent<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
t = default(T);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
public static bool TryFind<T>(this GameObject obj, string name, out T result) where T : class
|
||||
{
|
||||
var gameObject = GameObject.Find(name);
|
||||
bool flag = gameObject;
|
||||
bool flag2;
|
||||
if (flag)
|
||||
{
|
||||
result = gameObject.GetComponent<T>();
|
||||
flag2 = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = default(T);
|
||||
flag2 = false;
|
||||
}
|
||||
return flag2;
|
||||
}
|
||||
|
||||
public static bool TryFind<T>(this Transform obj, string name, out T result) where T : class
|
||||
{
|
||||
var transform = obj.Find(name);
|
||||
bool flag = transform;
|
||||
bool flag2;
|
||||
if (flag)
|
||||
{
|
||||
result = transform.GetComponent<T>();
|
||||
flag2 = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = default(T);
|
||||
flag2 = false;
|
||||
}
|
||||
return flag2;
|
||||
}
|
||||
}
|
||||
}
|
||||
32
XianTu/ToolScripts/_BlueprintBuildingExpands.cs
Normal file
32
XianTu/ToolScripts/_BlueprintBuildingExpands.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ToolScripts
|
||||
{
|
||||
public static class _BlueprintBuildingExpands
|
||||
{
|
||||
static _BlueprintBuildingExpands()
|
||||
{
|
||||
BeltProtoDict.Add(2001, null);
|
||||
BeltProtoDict.Add(2002, null);
|
||||
BeltProtoDict.Add(2003, null);
|
||||
SoltProtoDict.Add(2011, null);
|
||||
SoltProtoDict.Add(2012, null);
|
||||
SoltProtoDict.Add(2013, null);
|
||||
SoltProtoDict.Add(2014, null);
|
||||
}
|
||||
|
||||
public static bool IsBelt(this BlueprintBuilding bb)
|
||||
{
|
||||
return BeltProtoDict.ContainsKey(bb.itemId);
|
||||
}
|
||||
|
||||
public static bool IsSlot(this BlueprintBuilding bb)
|
||||
{
|
||||
return SoltProtoDict.ContainsKey(bb.itemId);
|
||||
}
|
||||
|
||||
private static readonly Dictionary<int, ItemProto> BeltProtoDict = new();
|
||||
|
||||
private static readonly Dictionary<int, ItemProto> SoltProtoDict = new();
|
||||
}
|
||||
}
|
||||
40
XianTu/UI/BasePanel.cs
Normal file
40
XianTu/UI/BasePanel.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace XianTu.UI
|
||||
{
|
||||
internal class BasePanel : MonoBehaviour
|
||||
{
|
||||
public virtual void OnEnter()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void OnPause()
|
||||
{
|
||||
UITool.GameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public virtual void OnResume()
|
||||
{
|
||||
UITool.GameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public virtual void OnExit()
|
||||
{
|
||||
Destroy(UITool.GameObject);
|
||||
}
|
||||
|
||||
public void Init(PanelManager panelManager)
|
||||
{
|
||||
PanelManager = panelManager;
|
||||
}
|
||||
|
||||
public PanelManager PanelManager { get; private set; }
|
||||
|
||||
public void Init(UITool uiTool)
|
||||
{
|
||||
UITool = uiTool;
|
||||
}
|
||||
|
||||
public UITool UITool { get; private set; }
|
||||
}
|
||||
}
|
||||
344
XianTu/UI/BlueTuPatchUI.cs
Normal file
344
XianTu/UI/BlueTuPatchUI.cs
Normal file
@@ -0,0 +1,344 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
namespace XianTu.UI
|
||||
{
|
||||
internal class BlueTuPatchUI : XianTuBasePanel
|
||||
{
|
||||
public BlueTuUIData Data { get; private set; }
|
||||
|
||||
public static BlueTuPatchUI Instance { get; private set; }
|
||||
|
||||
public override void OnEnter()
|
||||
{
|
||||
base.OnEnter();
|
||||
Data = BlueTuUIData.Instance;
|
||||
enableToggle = UITool.GetComponentInChild<Toggle>("XianTuEnableTg");
|
||||
enableToggle.isOn = Data.Enable;
|
||||
enableToggle.onValueChanged.AddListener(delegate(bool value)
|
||||
{
|
||||
Data.Enable = value;
|
||||
});
|
||||
_tipText = UITool.GetComponentInChild<Button>("Tx_Tip");
|
||||
_buildButton = UITool.GetComponentInChild<Button>("Btn_Build");
|
||||
_buildButton.onClick.AddListener(delegate
|
||||
{
|
||||
var onBuildBtn = Data.OnBuildBtn;
|
||||
if (onBuildBtn != null)
|
||||
{
|
||||
onBuildBtn();
|
||||
}
|
||||
});
|
||||
_resetButton = UITool.GetComponentInChild<Button>("Btn_Reset");
|
||||
_resetButton.onClick.AddListener(delegate
|
||||
{
|
||||
var onResetBtn = Data.OnResetBtn;
|
||||
if (onResetBtn != null)
|
||||
{
|
||||
onResetBtn();
|
||||
}
|
||||
ResetValue();
|
||||
});
|
||||
_copyButton = UITool.GetComponentInChild<Button>("Btn_Copy");
|
||||
_copyButton.onClick.AddListener(delegate
|
||||
{
|
||||
var onCopyBtn = Data.OnCopyBtn;
|
||||
if (onCopyBtn != null)
|
||||
{
|
||||
onCopyBtn();
|
||||
}
|
||||
});
|
||||
LayerNumber = CreateUIValue(Data.LayerNumber, "LayerNumber");
|
||||
LayerHeight = CreateUIValue(Data.LayerHeight, "LayerHeight", 20f);
|
||||
var text = "ScaleGroup/Group/ScaleX";
|
||||
var text2 = "ScaleGroup/Group/ScaleY";
|
||||
ScaleX = CreateUIValue(Data.Scale.x, text);
|
||||
ScaleY = CreateUIValue(Data.Scale.y, text2);
|
||||
var text3 = "ScaleGroup/Group/ScaleZ";
|
||||
ScaleZ = CreateUIValue(Data.Scale.z, text3);
|
||||
var text4 = "BiasGroup/Group/BiasX";
|
||||
var text5 = "BiasGroup/Group/BiasY";
|
||||
var text6 = "BiasGroup/Group/BiasZ";
|
||||
_biasX = CreateUIValue(Data.Bias.x, text4, 20f);
|
||||
_biasY = CreateUIValue(Data.Bias.y, text5, 20f);
|
||||
BiasZ = CreateUIValue(Data.Bias.z, text6, 20f);
|
||||
Rotate = CreateUIValue(Data.Rotate, "Rotate", 180f);
|
||||
_pivotX = CreateUIValue(Data.Pivot.x, "PivotX");
|
||||
_pivotY = CreateUIValue(Data.Pivot.y, "PivotY");
|
||||
AddDragControl(Rotate, "Name");
|
||||
AddDragControl(LayerNumber, "Name");
|
||||
AddDragControl(LayerHeight, "Name");
|
||||
AddDragControl(ScaleX, "Name");
|
||||
AddDragControl(ScaleY, "Name");
|
||||
AddDragControl(ScaleZ, "Name");
|
||||
AddDragControl(_pivotX, _pivotY, "Name");
|
||||
AddDragControl(_biasX, "Name");
|
||||
AddDragControl(_biasY, "Name");
|
||||
AddDragControl(BiasZ, "Name");
|
||||
BindScaleData();
|
||||
BindBiasData();
|
||||
BindPivot();
|
||||
BindLayerNumber();
|
||||
BindLayerHeight();
|
||||
BindRotate();
|
||||
Instance = this;
|
||||
var initFinish = InitFinish;
|
||||
if (initFinish != null)
|
||||
{
|
||||
initFinish(this);
|
||||
}
|
||||
BindOnEnable_MoveCenter();
|
||||
}
|
||||
|
||||
private void ResetValue()
|
||||
{
|
||||
_biasX.Value = Data.Bias.x;
|
||||
_biasY.Value = Data.Bias.y;
|
||||
BiasZ.Value = Data.Bias.z;
|
||||
ScaleX.Value = Data.Scale.x;
|
||||
ScaleY.Value = Data.Scale.y;
|
||||
ScaleZ.Value = Data.Scale.z;
|
||||
_pivotX.Value = Data.Pivot.x;
|
||||
_pivotY.Value = Data.Pivot.y;
|
||||
Rotate.Value = Data.Rotate;
|
||||
enableToggle.isOn = Data.Enable;
|
||||
LayerHeight.Value = Data.LayerHeight;
|
||||
LayerNumber.Value = Data.LayerNumber;
|
||||
}
|
||||
|
||||
private void BindOnEnable_MoveCenter()
|
||||
{
|
||||
var canvasMonoEvent = UIManager.CanvasMonoEvent;
|
||||
var rectTransform = (RectTransform)transform;
|
||||
var centerBias = new Vector3(-rectTransform.rect.width / 2f, rectTransform.rect.height / 2f);
|
||||
canvasMonoEvent.onEnableEvent.AddListener(delegate
|
||||
{
|
||||
var isOn = enableToggle.isOn;
|
||||
if (isOn)
|
||||
{
|
||||
UITool.GameObject.transform.position = Input.mousePosition + centerBias;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void BindRotate()
|
||||
{
|
||||
Rotate.OnValueChange += delegate(float f)
|
||||
{
|
||||
Data.Rotate = f;
|
||||
};
|
||||
}
|
||||
|
||||
private void BindLayerHeight()
|
||||
{
|
||||
LayerHeight.OnValueChange += delegate(float f)
|
||||
{
|
||||
Data.LayerHeight = f;
|
||||
};
|
||||
}
|
||||
|
||||
private void BindLayerNumber()
|
||||
{
|
||||
LayerNumber.OnValueChange += delegate(int i)
|
||||
{
|
||||
Data.LayerNumber = i;
|
||||
};
|
||||
}
|
||||
|
||||
private void BindPivot()
|
||||
{
|
||||
var tempPivot = Data.Pivot;
|
||||
var cd = Time.time;
|
||||
_pivotX.OnValueChange += delegate(float f)
|
||||
{
|
||||
var flag = Time.time - cd < Time.fixedDeltaTime;
|
||||
if (!flag)
|
||||
{
|
||||
cd = Time.time;
|
||||
tempPivot.x = f;
|
||||
Data.Pivot = tempPivot;
|
||||
}
|
||||
};
|
||||
_pivotY.OnValueChange += delegate(float f)
|
||||
{
|
||||
var flag2 = Time.time - cd < Time.fixedDeltaTime;
|
||||
if (!flag2)
|
||||
{
|
||||
cd = Time.time;
|
||||
tempPivot.y = f;
|
||||
Data.Pivot = tempPivot;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void BindBiasData()
|
||||
{
|
||||
var tempBias = Data.Bias;
|
||||
_biasX.OnValueChange += delegate(float f)
|
||||
{
|
||||
tempBias.x = f;
|
||||
Data.Bias = tempBias;
|
||||
};
|
||||
_biasY.OnValueChange += delegate(float f)
|
||||
{
|
||||
tempBias.y = f;
|
||||
Data.Bias = tempBias;
|
||||
};
|
||||
BiasZ.OnValueChange += delegate(float f)
|
||||
{
|
||||
tempBias.z = f;
|
||||
Data.Bias = tempBias;
|
||||
};
|
||||
}
|
||||
|
||||
private void BindScaleData()
|
||||
{
|
||||
var tempScale = Data.Scale;
|
||||
ScaleX.OnValueChange += delegate(float f)
|
||||
{
|
||||
tempScale.x = f;
|
||||
Data.Scale = tempScale;
|
||||
};
|
||||
ScaleY.OnValueChange += delegate(float f)
|
||||
{
|
||||
tempScale.y = f;
|
||||
Data.Scale = tempScale;
|
||||
};
|
||||
ScaleZ.OnValueChange += delegate(float f)
|
||||
{
|
||||
tempScale.z = f;
|
||||
Data.Scale = tempScale;
|
||||
};
|
||||
}
|
||||
|
||||
[field: DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||
private static event Action<BlueTuPatchUI> InitFinish;
|
||||
|
||||
public static event Action<BlueTuPatchUI> OnInitFinish
|
||||
{
|
||||
add
|
||||
{
|
||||
InitFinish += value;
|
||||
var flag = Instance != null;
|
||||
if (flag)
|
||||
{
|
||||
value(Instance);
|
||||
}
|
||||
}
|
||||
remove => InitFinish -= value;
|
||||
}
|
||||
|
||||
private void AddDragControl<T>(UIValue<T> uiValue, string childrenName) where T : IComparable
|
||||
{
|
||||
var flag = uiValue.Components.Length != 0;
|
||||
if (flag)
|
||||
{
|
||||
var parent = uiValue.Components[0].gameObject.transform.parent;
|
||||
var transform = parent.Find(childrenName);
|
||||
bool flag2 = transform;
|
||||
if (flag2)
|
||||
{
|
||||
uiValue.BindDragControl(transform.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AddDragControl<T>(UIValue<T> uiValueX, UIValue<T> uiValueY, string childrenName) where T : IComparable
|
||||
{
|
||||
var flag = uiValueX.Components.Length != 0;
|
||||
if (flag)
|
||||
{
|
||||
var parent = uiValueX.Components[0].gameObject.transform.parent;
|
||||
var transform = parent.Find(childrenName);
|
||||
bool flag2 = transform;
|
||||
if (flag2)
|
||||
{
|
||||
uiValueX.BindDragControl(transform.gameObject);
|
||||
uiValueY.BindDragControl(transform.gameObject);
|
||||
UIValue<T>.BindDragControl(transform.gameObject, uiValueX, uiValueY);
|
||||
}
|
||||
}
|
||||
var flag3 = uiValueY.Components.Length != 0;
|
||||
if (flag3)
|
||||
{
|
||||
var parent2 = uiValueY.Components[0].gameObject.transform.parent;
|
||||
var transform2 = parent2.Find(childrenName);
|
||||
bool flag4 = transform2;
|
||||
if (flag4)
|
||||
{
|
||||
uiValueX.BindDragControl(transform2.gameObject);
|
||||
uiValueY.BindDragControl(transform2.gameObject);
|
||||
UIValue<T>.BindDragControl(transform2.gameObject, uiValueX, uiValueY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private UIValue<T> CreateUIValue<T>(T defaultValue, string groupPath, float maxValue = 10f) where T : IComparable
|
||||
{
|
||||
var uivalue = new UIValue<T>(defaultValue, Array.Empty<Component>());
|
||||
var gameObject = UITool.FindChildGameObject(groupPath);
|
||||
var flag = gameObject == null;
|
||||
UIValue<T> uivalue2;
|
||||
if (flag)
|
||||
{
|
||||
Debug.LogError("没有找到" + groupPath);
|
||||
uivalue2 = uivalue;
|
||||
}
|
||||
else
|
||||
{
|
||||
uivalue.Bind(gameObject.GetComponentInChildren<Toggle>());
|
||||
uivalue.Bind(gameObject.GetComponentInChildren<Slider>());
|
||||
uivalue.Bind(gameObject.GetComponentInChildren<Scrollbar>());
|
||||
var componentsInChildren = gameObject.GetComponentsInChildren<Text>();
|
||||
for (var i = 0; i < componentsInChildren.Length; i++)
|
||||
{
|
||||
var flag2 = componentsInChildren[i].name == "ValueText";
|
||||
if (flag2)
|
||||
{
|
||||
uivalue.Bind(componentsInChildren[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
uivalue.Bind(gameObject.GetComponentInChildren<InputField>());
|
||||
uivalue.MaxValue = maxValue;
|
||||
uivalue2 = uivalue;
|
||||
}
|
||||
return uivalue2;
|
||||
}
|
||||
|
||||
public Toggle enableToggle;
|
||||
|
||||
private Button _tipText;
|
||||
|
||||
private Button _buildButton;
|
||||
|
||||
private Button _resetButton;
|
||||
|
||||
public UIValue<int> LayerNumber;
|
||||
|
||||
public UIValue<float> LayerHeight;
|
||||
|
||||
public UIValue<float> ScaleX;
|
||||
|
||||
public UIValue<float> ScaleY;
|
||||
|
||||
public UIValue<float> ScaleZ;
|
||||
|
||||
public UIValue<float> BiasZ;
|
||||
|
||||
public UIValue<float> Rotate;
|
||||
|
||||
private UIValue<float> _pivotX;
|
||||
|
||||
private UIValue<float> _pivotY;
|
||||
|
||||
private UIValue<float> _biasX;
|
||||
|
||||
private UIValue<float> _biasY;
|
||||
|
||||
private Button _copyButton;
|
||||
}
|
||||
}
|
||||
25
XianTu/UI/CanvasMonoEvent.cs
Normal file
25
XianTu/UI/CanvasMonoEvent.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace XianTu.UI
|
||||
{
|
||||
public class CanvasMonoEvent : MonoBehaviour
|
||||
{
|
||||
private void Awake()
|
||||
{
|
||||
onEnableEvent = new UnityEvent();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
var onEnableEvent = this.onEnableEvent;
|
||||
if (onEnableEvent != null)
|
||||
{
|
||||
onEnableEvent.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
[FormerlySerializedAs("OnEnableEvent")] public UnityEvent onEnableEvent;
|
||||
}
|
||||
}
|
||||
99
XianTu/UI/PanelManager.cs
Normal file
99
XianTu/UI/PanelManager.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace XianTu.UI
|
||||
{
|
||||
public class PanelManager
|
||||
{
|
||||
public LoadManager Loader { get; private set; }
|
||||
|
||||
public PanelManager(GameObject rootCanvas)
|
||||
{
|
||||
_panelStack = new Stack<BasePanel>();
|
||||
_panelDict = new Dictionary<string, BasePanel>();
|
||||
this._rootCanvas = rootCanvas;
|
||||
Loader = Singleton<LoadManager>.Instance;
|
||||
_uiAssembly = GetType().Assembly;
|
||||
}
|
||||
|
||||
public void Push(string nextPanelName)
|
||||
{
|
||||
var flag = _panelStack.Count > 0;
|
||||
if (flag)
|
||||
{
|
||||
_panelStack.Peek().OnPause();
|
||||
}
|
||||
var flag2 = _panelDict.ContainsKey(nextPanelName);
|
||||
BasePanel basePanel;
|
||||
if (flag2)
|
||||
{
|
||||
basePanel = _panelDict[nextPanelName];
|
||||
basePanel.OnResume();
|
||||
}
|
||||
else
|
||||
{
|
||||
var text = Path.Combine(UIPrefabDir, nextPanelName);
|
||||
var gameObject = Loader.LoadPrefab(text);
|
||||
var flag3 = gameObject == null;
|
||||
if (flag3)
|
||||
{
|
||||
Debug.LogError("没有找到" + text);
|
||||
var flag4 = _panelStack.Count > 0;
|
||||
if (flag4)
|
||||
{
|
||||
_panelStack.Peek().OnResume();
|
||||
}
|
||||
return;
|
||||
}
|
||||
gameObject = Object.Instantiate(gameObject, _rootCanvas.transform);
|
||||
var type = _uiAssembly.GetType(_panelNameSapce + "." + nextPanelName);
|
||||
basePanel = (BasePanel)gameObject.AddComponent(type);
|
||||
var uitool = new UITool(gameObject);
|
||||
basePanel.Init(this);
|
||||
basePanel.Init(uitool);
|
||||
_panelDict.Add(nextPanelName, basePanel);
|
||||
basePanel.OnEnter();
|
||||
}
|
||||
_panelStack.Push(basePanel);
|
||||
}
|
||||
|
||||
public void Pop()
|
||||
{
|
||||
var flag = _panelStack.Count > 0;
|
||||
if (flag)
|
||||
{
|
||||
var basePanel = _panelStack.Pop();
|
||||
basePanel.OnPause();
|
||||
}
|
||||
var flag2 = _panelStack.Count > 0;
|
||||
if (flag2)
|
||||
{
|
||||
_panelStack.Peek().OnResume();
|
||||
}
|
||||
}
|
||||
|
||||
public void Exit()
|
||||
{
|
||||
for (var i = 0; i < _panelDict.Count; i++)
|
||||
{
|
||||
_panelDict.ElementAt(i).Value.OnExit();
|
||||
}
|
||||
}
|
||||
|
||||
private Stack<BasePanel> _panelStack;
|
||||
|
||||
private Dictionary<string, BasePanel> _panelDict;
|
||||
|
||||
private GameObject _rootCanvas;
|
||||
|
||||
private Assembly _uiAssembly;
|
||||
|
||||
private string _panelNameSapce = "XianTu.UI";
|
||||
|
||||
public readonly string UIPrefabDir = "Prefabs/UI";
|
||||
}
|
||||
}
|
||||
72
XianTu/UI/UIManager.cs
Normal file
72
XianTu/UI/UIManager.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace XianTu.UI
|
||||
{
|
||||
public class UIManager
|
||||
{
|
||||
public GameObject CanvasObj { get; private set; }
|
||||
|
||||
public bool ActiveSelf => CanvasObj.activeSelf;
|
||||
|
||||
public void SetActive(bool value)
|
||||
{
|
||||
CanvasObj.SetActive(value);
|
||||
}
|
||||
|
||||
public void SwitchDisplay()
|
||||
{
|
||||
CanvasObj.SetActive(CanvasObj.activeSelf);
|
||||
}
|
||||
|
||||
public UIManager(Action<object> debugLog = null)
|
||||
{
|
||||
Instance = this;
|
||||
var flag = debugLog == null;
|
||||
if (flag)
|
||||
{
|
||||
DebugLog = new Action<object>(Debug.Log);
|
||||
}
|
||||
var flag2 = !LoadCanvas();
|
||||
if (flag2)
|
||||
{
|
||||
DebugLog("UI管理器加载失败");
|
||||
}
|
||||
else
|
||||
{
|
||||
PanelManager = new PanelManager(CanvasObj);
|
||||
}
|
||||
}
|
||||
|
||||
public PanelManager PanelManager { get; private set; }
|
||||
|
||||
public static UIManager Instance { get; private set; }
|
||||
|
||||
public CanvasMonoEvent CanvasMonoEvent { get; private set; }
|
||||
|
||||
private bool LoadCanvas()
|
||||
{
|
||||
var gameObject = Singleton<LoadManager>.Instance.LoadPrefab("Prefabs/XianTuCanvas");
|
||||
var flag = gameObject != null;
|
||||
bool flag2;
|
||||
if (flag)
|
||||
{
|
||||
var gameObject2 = Object.Instantiate(gameObject);
|
||||
CanvasObj = gameObject2;
|
||||
CanvasMonoEvent = gameObject2.AddComponent<CanvasMonoEvent>();
|
||||
gameObject2.SetActive(false);
|
||||
flag2 = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
flag2 = false;
|
||||
}
|
||||
return flag2;
|
||||
}
|
||||
|
||||
private const string CanvasPrefabPath = "Prefabs/XianTuCanvas";
|
||||
|
||||
public readonly Action<object> DebugLog;
|
||||
}
|
||||
}
|
||||
148
XianTu/UI/UITool.cs
Normal file
148
XianTu/UI/UITool.cs
Normal file
@@ -0,0 +1,148 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XianTu.UI
|
||||
{
|
||||
internal class UITool
|
||||
{
|
||||
public UITool(GameObject uiGameObject)
|
||||
{
|
||||
GameObject = uiGameObject;
|
||||
Transform = GameObject.transform;
|
||||
}
|
||||
|
||||
public T GetComponentInChild<T>(string path) where T : class
|
||||
{
|
||||
var gameObject = FindChildGameObject(path);
|
||||
bool flag = gameObject;
|
||||
T t;
|
||||
if (flag)
|
||||
{
|
||||
t = gameObject.GetComponent<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
t = default(T);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
public GameObject FindChildGameObject(string path)
|
||||
{
|
||||
var array = path.Split(['/']);
|
||||
var flag = array.Length == 0;
|
||||
GameObject gameObject;
|
||||
if (flag)
|
||||
{
|
||||
Debug.LogError("空路径");
|
||||
gameObject = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var flag2 = array[0] == "";
|
||||
GameObject gameObject2;
|
||||
if (flag2)
|
||||
{
|
||||
gameObject2 = StepByStepFindChild(Transform, array.Skip(1).ToArray());
|
||||
var flag3 = gameObject2 != null;
|
||||
if (flag3)
|
||||
{
|
||||
return gameObject2.gameObject;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gameObject2 = BreadthFindChild(Transform, array[0]);
|
||||
var flag4 = gameObject2 != null && array.Length > 1;
|
||||
if (flag4)
|
||||
{
|
||||
gameObject2 = StepByStepFindChild(gameObject2.transform, array.Skip(1).ToArray());
|
||||
}
|
||||
}
|
||||
var flag5 = gameObject2 == null;
|
||||
if (flag5)
|
||||
{
|
||||
Debug.LogError("找不到" + path);
|
||||
}
|
||||
gameObject = gameObject2;
|
||||
}
|
||||
return gameObject;
|
||||
}
|
||||
|
||||
private static GameObject BreadthFindChild(Transform parent, string name)
|
||||
{
|
||||
var flag = parent == null;
|
||||
GameObject gameObject;
|
||||
if (flag)
|
||||
{
|
||||
Debug.LogError("不要传个空的过来!");
|
||||
gameObject = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var queue = new Queue<Transform>();
|
||||
queue.Enqueue(parent);
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
var transform = queue.Dequeue();
|
||||
var transform2 = transform.Find(name);
|
||||
var flag2 = transform2 != null;
|
||||
if (flag2)
|
||||
{
|
||||
return transform2.gameObject;
|
||||
}
|
||||
for (var i = 0; i < transform.childCount; i++)
|
||||
{
|
||||
queue.Enqueue(transform.GetChild(i));
|
||||
}
|
||||
}
|
||||
gameObject = null;
|
||||
}
|
||||
return gameObject;
|
||||
}
|
||||
|
||||
public T GetOrAddComponentInChildren<T>(string name) where T : Component
|
||||
{
|
||||
var gameObject = FindChildGameObject(name);
|
||||
var flag = gameObject != null;
|
||||
T t2;
|
||||
if (flag)
|
||||
{
|
||||
var t = gameObject.GetComponent<T>();
|
||||
var flag2 = t == null;
|
||||
if (flag2)
|
||||
{
|
||||
t = gameObject.AddComponent<T>();
|
||||
}
|
||||
t2 = t;
|
||||
}
|
||||
else
|
||||
{
|
||||
t2 = default(T);
|
||||
}
|
||||
return t2;
|
||||
}
|
||||
|
||||
[CompilerGenerated]
|
||||
internal static GameObject StepByStepFindChild(Transform parent, string[] filepaths)
|
||||
{
|
||||
var transform = parent;
|
||||
for (var i = 0; i < filepaths.Length; i++)
|
||||
{
|
||||
transform = transform.Find(filepaths[i]);
|
||||
var flag = transform == null;
|
||||
if (flag)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return transform.gameObject;
|
||||
}
|
||||
|
||||
public readonly GameObject GameObject;
|
||||
|
||||
public readonly Transform Transform;
|
||||
}
|
||||
}
|
||||
15
XianTu/UI/UIType.cs
Normal file
15
XianTu/UI/UIType.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace XianTu.UI
|
||||
{
|
||||
internal class UIType
|
||||
{
|
||||
public UIType(string prefabPath)
|
||||
{
|
||||
this.PrefabPath = prefabPath;
|
||||
Name = prefabPath.Substring(prefabPath.LastIndexOf('/') + 1);
|
||||
}
|
||||
|
||||
public string PrefabPath;
|
||||
|
||||
public string Name;
|
||||
}
|
||||
}
|
||||
421
XianTu/UI/UIValue.cs
Normal file
421
XianTu/UI/UIValue.cs
Normal file
@@ -0,0 +1,421 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using ToolScripts;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XianTu.UI
|
||||
{
|
||||
internal class UIValue<T> where T : IComparable
|
||||
{
|
||||
[field: DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||
private event Action<object> ValueUpdate;
|
||||
|
||||
[field: DebuggerBrowsable(DebuggerBrowsableState.Never)]
|
||||
public event Action<T> OnValueChange;
|
||||
|
||||
public T Value
|
||||
{
|
||||
get => _value;
|
||||
set
|
||||
{
|
||||
var publicValueLock = _publicValueLock;
|
||||
if (!publicValueLock)
|
||||
{
|
||||
_publicValueLock = true;
|
||||
ValueUpdate(value);
|
||||
_publicValueLock = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public float MaxValue
|
||||
{
|
||||
get => _maxValue;
|
||||
set
|
||||
{
|
||||
_maxValue = value;
|
||||
for (var i = 0; i < Components.Length; i++)
|
||||
{
|
||||
var component = Components[i];
|
||||
var component2 = component;
|
||||
var slider = component2 as Slider;
|
||||
if (slider != null)
|
||||
{
|
||||
slider.maxValue = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public UIValue(T defaultValue, params Component[] components)
|
||||
{
|
||||
var flag = typeof(T) == typeof(bool);
|
||||
if (flag)
|
||||
{
|
||||
_valueType = EValueType.Bool;
|
||||
}
|
||||
else
|
||||
{
|
||||
var flag2 = typeof(T) == typeof(int);
|
||||
if (flag2)
|
||||
{
|
||||
_valueType = EValueType.Int;
|
||||
}
|
||||
else
|
||||
{
|
||||
var flag3 = typeof(T) == typeof(float);
|
||||
if (flag3)
|
||||
{
|
||||
_valueType = EValueType.Float;
|
||||
}
|
||||
else
|
||||
{
|
||||
var flag4 = typeof(T) == typeof(string);
|
||||
if (flag4)
|
||||
{
|
||||
_valueType = EValueType.String;
|
||||
}
|
||||
else
|
||||
{
|
||||
var flag5 = typeof(T) == typeof(double);
|
||||
if (flag5)
|
||||
{
|
||||
_valueType = EValueType.Double;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ValueUpdate = delegate(object v)
|
||||
{
|
||||
switch (_valueType)
|
||||
{
|
||||
case EValueType.Bool:
|
||||
_value = (T)((object)Convert.ToBoolean(v));
|
||||
break;
|
||||
case EValueType.Int:
|
||||
_value = (T)((object)Convert.ToInt32(v));
|
||||
break;
|
||||
case EValueType.Float:
|
||||
_value = (T)((object)Convert.ToSingle(v));
|
||||
break;
|
||||
case EValueType.Double:
|
||||
_value = (T)((object)Convert.ToDouble(v));
|
||||
break;
|
||||
case EValueType.String:
|
||||
_value = (T)((object)_valueType.ToString());
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
var onValueChange = OnValueChange;
|
||||
if (onValueChange != null)
|
||||
{
|
||||
onValueChange(_value);
|
||||
}
|
||||
};
|
||||
foreach (var component in components)
|
||||
{
|
||||
var component2 = component;
|
||||
var component3 = component2;
|
||||
var inputField = component3 as InputField;
|
||||
if (inputField == null)
|
||||
{
|
||||
var toggle = component3 as Toggle;
|
||||
if (toggle == null)
|
||||
{
|
||||
var slider = component3 as Slider;
|
||||
if (slider == null)
|
||||
{
|
||||
var text = component3 as Text;
|
||||
if (text == null)
|
||||
{
|
||||
var scrollbar = component3 as Scrollbar;
|
||||
if (scrollbar != null)
|
||||
{
|
||||
Bind(scrollbar);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Bind(text);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Bind(slider);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Bind(toggle);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Bind(inputField);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Bind(Scrollbar scrollBar)
|
||||
{
|
||||
var flag = scrollBar == null;
|
||||
if (!flag)
|
||||
{
|
||||
Components = Components.Append(scrollBar).ToArray();
|
||||
var hasSet = false;
|
||||
var justUpdate = false;
|
||||
ValueUpdate += delegate(object value)
|
||||
{
|
||||
var hasSet2 = hasSet;
|
||||
if (!hasSet2)
|
||||
{
|
||||
justUpdate = true;
|
||||
scrollBar.value = Convert.ToSingle(value);
|
||||
justUpdate = false;
|
||||
}
|
||||
};
|
||||
scrollBar.onValueChanged.AddListener(delegate(float value)
|
||||
{
|
||||
var justUpdate2 = justUpdate;
|
||||
if (!justUpdate2)
|
||||
{
|
||||
hasSet = true;
|
||||
ValueUpdate(value);
|
||||
hasSet = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void Bind(Text text)
|
||||
{
|
||||
var flag = text == null;
|
||||
if (!flag)
|
||||
{
|
||||
Components = Components.Append(text).ToArray();
|
||||
var justUpdate = false;
|
||||
ValueUpdate += delegate(object value)
|
||||
{
|
||||
var justUpdate2 = justUpdate;
|
||||
if (!justUpdate2)
|
||||
{
|
||||
justUpdate = true;
|
||||
text.text = string.Format("{0:f2}", value);
|
||||
justUpdate = false;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void Bind(Slider slider)
|
||||
{
|
||||
var flag = slider == null;
|
||||
if (!flag)
|
||||
{
|
||||
Components = Components.Append(slider).ToArray();
|
||||
var hasSet = false;
|
||||
var justUpdate = false;
|
||||
ValueUpdate += delegate(object value)
|
||||
{
|
||||
var hasSet2 = hasSet;
|
||||
if (!hasSet2)
|
||||
{
|
||||
justUpdate = true;
|
||||
slider.value = Convert.ToSingle(value);
|
||||
justUpdate = false;
|
||||
}
|
||||
};
|
||||
slider.onValueChanged.AddListener(delegate(float value)
|
||||
{
|
||||
var justUpdate2 = justUpdate;
|
||||
if (!justUpdate2)
|
||||
{
|
||||
hasSet = true;
|
||||
ValueUpdate(value);
|
||||
hasSet = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void Bind(Toggle toggle)
|
||||
{
|
||||
var flag = toggle == null;
|
||||
if (!flag)
|
||||
{
|
||||
Components = Components.Append(toggle).ToArray();
|
||||
var hasSet = false;
|
||||
var justUpdate = false;
|
||||
ValueUpdate += delegate(object value)
|
||||
{
|
||||
var hasSet2 = hasSet;
|
||||
if (!hasSet2)
|
||||
{
|
||||
justUpdate = true;
|
||||
toggle.isOn = Convert.ToBoolean(value);
|
||||
justUpdate = false;
|
||||
}
|
||||
};
|
||||
toggle.onValueChanged.AddListener(delegate(bool value)
|
||||
{
|
||||
var justUpdate2 = justUpdate;
|
||||
if (!justUpdate2)
|
||||
{
|
||||
hasSet = true;
|
||||
ValueUpdate(value);
|
||||
hasSet = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void Bind(InputField inputField)
|
||||
{
|
||||
var flag = inputField == null;
|
||||
if (!flag)
|
||||
{
|
||||
Components = Components.Append(inputField).ToArray();
|
||||
var hasSet = false;
|
||||
var justUpdate = false;
|
||||
ValueUpdate += delegate(object value)
|
||||
{
|
||||
var hasSet2 = hasSet;
|
||||
if (!hasSet2)
|
||||
{
|
||||
justUpdate = true;
|
||||
inputField.text = string.Format("{0:f2}", value);
|
||||
justUpdate = false;
|
||||
}
|
||||
};
|
||||
inputField.onValueChanged.AddListener(delegate(string value)
|
||||
{
|
||||
var justUpdate2 = justUpdate;
|
||||
if (!justUpdate2)
|
||||
{
|
||||
var flag2 = value == "-" || value == "";
|
||||
if (!flag2)
|
||||
{
|
||||
hasSet = true;
|
||||
switch (_valueType)
|
||||
{
|
||||
case EValueType.Bool:
|
||||
ValueUpdate(Convert.ToBoolean(value));
|
||||
break;
|
||||
case EValueType.Int:
|
||||
ValueUpdate(Convert.ToInt32(value));
|
||||
break;
|
||||
case EValueType.Float:
|
||||
ValueUpdate(Convert.ToSingle(value));
|
||||
break;
|
||||
case EValueType.Double:
|
||||
ValueUpdate(Convert.ToDouble(value));
|
||||
break;
|
||||
case EValueType.String:
|
||||
ValueUpdate(value);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
hasSet = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void BindDragControl(GameObject gameObject)
|
||||
{
|
||||
var startPosition = default(Vector2);
|
||||
var defaultValue = 0f;
|
||||
var eventTrigger = gameObject.GetComponent<EventTrigger>();
|
||||
var flag = eventTrigger == null;
|
||||
if (flag)
|
||||
{
|
||||
eventTrigger = gameObject.AddComponent<EventTrigger>();
|
||||
}
|
||||
var speed = 0f;
|
||||
eventTrigger.Add(EventTriggerType.BeginDrag, delegate(BaseEventData edata)
|
||||
{
|
||||
var pointerEventData = edata as PointerEventData;
|
||||
var flag2 = pointerEventData != null;
|
||||
if (flag2)
|
||||
{
|
||||
startPosition = pointerEventData.position;
|
||||
defaultValue = Convert.ToSingle(Value);
|
||||
speed = _maxValue / Screen.width * 4f;
|
||||
}
|
||||
});
|
||||
eventTrigger.Add(EventTriggerType.Drag, delegate(BaseEventData edata)
|
||||
{
|
||||
var pointerEventData2 = edata as PointerEventData;
|
||||
var flag3 = pointerEventData2 != null;
|
||||
if (flag3)
|
||||
{
|
||||
var num = (pointerEventData2.position.x - startPosition.x) * speed;
|
||||
ValueUpdate(defaultValue + num);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void BindDragControl(GameObject controller, UIValue<T> uiValueX, UIValue<T> uiValueY)
|
||||
{
|
||||
var startPosition = default(Vector2);
|
||||
var defaultValue1 = 0f;
|
||||
var defaultValue2 = 0f;
|
||||
var eventTrigger = controller.GetComponent<EventTrigger>();
|
||||
var flag = eventTrigger == null;
|
||||
if (flag)
|
||||
{
|
||||
eventTrigger = controller.AddComponent<EventTrigger>();
|
||||
}
|
||||
var speed = 0f;
|
||||
eventTrigger.Add(EventTriggerType.BeginDrag, delegate(BaseEventData edata)
|
||||
{
|
||||
var pointerEventData = edata as PointerEventData;
|
||||
var flag2 = pointerEventData != null;
|
||||
if (flag2)
|
||||
{
|
||||
startPosition = pointerEventData.position;
|
||||
defaultValue1 = Convert.ToSingle(uiValueX.Value);
|
||||
defaultValue2 = Convert.ToSingle(uiValueY.Value);
|
||||
speed = uiValueX._maxValue / Screen.width * 4f;
|
||||
}
|
||||
});
|
||||
eventTrigger.Add(EventTriggerType.Drag, delegate(BaseEventData edata)
|
||||
{
|
||||
var pointerEventData2 = edata as PointerEventData;
|
||||
var flag3 = pointerEventData2 != null;
|
||||
if (flag3)
|
||||
{
|
||||
var vector = (pointerEventData2.position - startPosition) * speed;
|
||||
uiValueX.ValueUpdate(defaultValue1 + vector.x);
|
||||
uiValueY.ValueUpdate(defaultValue2 + vector.y);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private T _value;
|
||||
|
||||
private float _maxValue = 1f;
|
||||
|
||||
private readonly EValueType _valueType;
|
||||
|
||||
public Component[] Components = new Component[0];
|
||||
|
||||
private bool _publicValueLock = false;
|
||||
|
||||
private enum EValueType
|
||||
{
|
||||
Bool,
|
||||
Int,
|
||||
Float,
|
||||
Double,
|
||||
String
|
||||
}
|
||||
}
|
||||
}
|
||||
149
XianTu/UI/XianTuBasePanel.cs
Normal file
149
XianTu/UI/XianTuBasePanel.cs
Normal file
@@ -0,0 +1,149 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace XianTu.UI
|
||||
{
|
||||
internal class XianTuBasePanel : BasePanel
|
||||
{
|
||||
public override void OnEnter()
|
||||
{
|
||||
base.OnEnter();
|
||||
UIManager = UIManager.Instance;
|
||||
BindBaseEvent();
|
||||
_uRect = UITool.GameObject.GetComponent<RectTransform>();
|
||||
_defaultRect = _uRect.rect;
|
||||
}
|
||||
|
||||
public UIManager UIManager { get; set; }
|
||||
|
||||
private void BindBaseEvent()
|
||||
{
|
||||
BindCloseWindowBtn();
|
||||
var eventTrigger = UITool.GameObject.AddComponent<EventTrigger>();
|
||||
eventTrigger.triggers = [];
|
||||
var transform = UITool.Transform;
|
||||
TriggerAdd(eventTrigger, EventTriggerType.Drag, delegate(BaseEventData x)
|
||||
{
|
||||
var pointerEventData = x as PointerEventData;
|
||||
var flag = pointerEventData != null;
|
||||
if (flag)
|
||||
{
|
||||
var vector = pointerEventData.position - _dragBias;
|
||||
var width = _defaultRect.width;
|
||||
var height = _defaultRect.height;
|
||||
switch (_dragMode)
|
||||
{
|
||||
case EDragMode.Drag:
|
||||
transform.position = _sourceDragPoint + vector;
|
||||
break;
|
||||
case EDragMode.ScaleX:
|
||||
_uRect.sizeDelta = new Vector2(width + vector.x, height);
|
||||
break;
|
||||
case EDragMode.ScaleY:
|
||||
_uRect.sizeDelta = new Vector2(width, height - vector.y);
|
||||
break;
|
||||
case EDragMode.ScaleXY:
|
||||
_uRect.sizeDelta = new Vector2(width + vector.x, height - vector.y);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
});
|
||||
TriggerAdd(eventTrigger, EventTriggerType.PointerDown, delegate(BaseEventData x)
|
||||
{
|
||||
var pointerEventData2 = x as PointerEventData;
|
||||
_sourceDragPoint = transform.position;
|
||||
_dragBias = pointerEventData2.position;
|
||||
var position = pointerEventData2.position;
|
||||
var position2 = transform.position;
|
||||
var num = position.x - position2.x;
|
||||
var num2 = position.y - position2.y;
|
||||
var rect = _uRect.rect;
|
||||
var flag2 = rect.height - 20f < num2;
|
||||
var flag3 = flag2;
|
||||
if (flag3)
|
||||
{
|
||||
_dragMode = EDragMode.Drag;
|
||||
}
|
||||
else
|
||||
{
|
||||
var flag4 = num > rect.width - 20f;
|
||||
var flag5 = -num2 > rect.height - 20f;
|
||||
var flag6 = flag4 && flag5;
|
||||
if (flag6)
|
||||
{
|
||||
_dragMode = EDragMode.ScaleXY;
|
||||
}
|
||||
else
|
||||
{
|
||||
var flag7 = flag4;
|
||||
if (flag7)
|
||||
{
|
||||
_dragMode = EDragMode.ScaleX;
|
||||
}
|
||||
else
|
||||
{
|
||||
var flag8 = flag5;
|
||||
if (flag8)
|
||||
{
|
||||
_dragMode = EDragMode.ScaleY;
|
||||
}
|
||||
else
|
||||
{
|
||||
_dragMode = EDragMode.Drag;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void BindCloseWindowBtn()
|
||||
{
|
||||
var orAddComponentInChildren = UITool.GetOrAddComponentInChildren<Button>("Btn_Close");
|
||||
var flag = orAddComponentInChildren != null;
|
||||
if (flag)
|
||||
{
|
||||
var component = orAddComponentInChildren.gameObject.GetComponent<Button>();
|
||||
component.onClick.AddListener(delegate
|
||||
{
|
||||
UIManager.SetActive(false);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("没有找到关闭按钮");
|
||||
}
|
||||
}
|
||||
|
||||
private static void TriggerAdd(EventTrigger trigger, EventTriggerType eventID, UnityAction<BaseEventData> callback)
|
||||
{
|
||||
var entry = new EventTrigger.Entry();
|
||||
entry.eventID = eventID;
|
||||
entry.callback.AddListener(callback);
|
||||
trigger.triggers.Add(entry);
|
||||
}
|
||||
|
||||
private Vector2 _dragBias;
|
||||
|
||||
private Vector2 _sourceDragPoint;
|
||||
|
||||
private RectTransform _uRect;
|
||||
|
||||
private EDragMode _dragMode = EDragMode.Drag;
|
||||
|
||||
private Rect _defaultRect;
|
||||
|
||||
private enum EDragMode
|
||||
{
|
||||
Drag,
|
||||
ScaleX,
|
||||
ScaleY,
|
||||
ScaleXY
|
||||
}
|
||||
}
|
||||
}
|
||||
30
XianTu/XianTu.csproj
Normal file
30
XianTu/XianTu.csproj
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<AssemblyName>XianTu</AssemblyName>
|
||||
<BepInExPluginGuid>me.GammaChineYov.plugin.Dyson.XianTu</BepInExPluginGuid>
|
||||
<Description>DSP MOD - CompressSave</Description>
|
||||
<Version>1.0.5</Version>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<RestoreAdditionalProjectSources>https://nuget.bepinex.dev/v3/index.json</RestoreAdditionalProjectSources>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BepInEx.Core" Version="5.*" />
|
||||
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
|
||||
<PackageReference Include="DysonSphereProgram.GameLibs" Version="*-r.*" />
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.*" />
|
||||
<PackageReference Include="UnityEngine.Modules" Version="2018.4.12" IncludeAssets="compile" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
|
||||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="FoundationBlueTu.txt" />
|
||||
<EmbeddedResource Include="xiantu" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
47
XianTu/XianTuPlugin.cs
Normal file
47
XianTu/XianTuPlugin.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using AssetsLoader;
|
||||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using BepInEx.Logging;
|
||||
using UnityEngine;
|
||||
using XianTu.Scripts.DataController;
|
||||
using XianTu.UI;
|
||||
|
||||
namespace XianTu
|
||||
{
|
||||
[BepInPlugin("me.GammaChineYov.plugin.Dyson.XianTu", "XianTu", "1.0.5")]
|
||||
internal class XianTuPlugin : BaseUnityPlugin
|
||||
{
|
||||
private static KeyCode HotKey => _hotKey.Value;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_logger = Logger;
|
||||
_hotKey = Config.Bind("config", "HotKey", KeyCode.F2, "显示UI的快捷键");
|
||||
var abload = ABLoader.LoadFromEmbeddedAssets("xiantu");
|
||||
Singleton<LoadManager>.Instance.SetLoader(abload);
|
||||
Singleton<LoadManager>.Instance.AddLoader(new EmbeddedFileLoad());
|
||||
UIManager = new UIManager();
|
||||
UIManager.SetActive(false);
|
||||
UIManager.PanelManager.Push("BlueTuPatchUI");
|
||||
new BlueTuController();
|
||||
_logger.LogInfo("仙图加载完毕");
|
||||
}
|
||||
|
||||
public UIManager UIManager { get; set; }
|
||||
|
||||
private void Update()
|
||||
{
|
||||
var keyDown = Input.GetKeyDown(HotKey);
|
||||
if (keyDown)
|
||||
{
|
||||
UIManager.SetActive(!UIManager.ActiveSelf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static ManualLogSource _logger;
|
||||
|
||||
private static ConfigEntry<KeyCode> _hotKey;
|
||||
|
||||
}
|
||||
}
|
||||
68
XianTu/XianTuTest.cs
Normal file
68
XianTu/XianTuTest.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System.IO;
|
||||
using AssetsLoader;
|
||||
using UnityEngine;
|
||||
using XianTu.UI;
|
||||
|
||||
namespace XianTu
|
||||
{
|
||||
internal class XianTuTest : MonoBehaviour
|
||||
{
|
||||
private void Awake()
|
||||
{
|
||||
var abload = ABLoader.LoadFromFile("xiantu", "Assets/AB");
|
||||
Singleton<LoadManager>.Instance.SetLoader(abload);
|
||||
_canvas = new UIManager();
|
||||
cube = GameObject.Find("Cube");
|
||||
_canvas.PanelManager.Push("BlueTuPatchUI");
|
||||
var data = BlueTuUIData.Instance;
|
||||
var trans = cube.transform;
|
||||
BlueTuUIData.Instance.OnValueChange += delegate
|
||||
{
|
||||
trans.localScale = data.Scale;
|
||||
trans.position = data.Bias;
|
||||
trans.eulerAngles = new Vector3(0f, data.Rotate, 0f);
|
||||
};
|
||||
}
|
||||
|
||||
private static void LoadTest()
|
||||
{
|
||||
var text = Path.Combine("Assets/XianTu/AB", "xiantu");
|
||||
var assetBundle = AssetBundle.LoadFromFile(text);
|
||||
var allAssetNames = assetBundle.GetAllAssetNames();
|
||||
foreach (var text2 in allAssetNames)
|
||||
{
|
||||
Debug.Log("全路径: " + text2);
|
||||
var text3 = text2.Substring(0, text2.IndexOf("prefabs"));
|
||||
Debug.Log("测试切割" + text3);
|
||||
var text4 = text2.Substring(text2.LastIndexOf('/') + 1);
|
||||
text4 = text4.Split(['.'])[0];
|
||||
Debug.Log("名字: " + text4);
|
||||
var gameObject = assetBundle.LoadAsset<GameObject>(text4);
|
||||
bool flag = gameObject;
|
||||
if (flag)
|
||||
{
|
||||
var gameObject2 = Instantiate(gameObject);
|
||||
gameObject2.name = "路径: " + text4;
|
||||
}
|
||||
}
|
||||
Debug.Log("路径streamingAssetsPath:" + Application.streamingAssetsPath);
|
||||
Debug.Log("dataPath:" + Application.dataPath);
|
||||
Debug.Log("persistentDataPath:" + Application.persistentDataPath);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
var keyDown = Input.GetKeyDown(hotKey);
|
||||
if (keyDown)
|
||||
{
|
||||
_canvas.SetActive(!_canvas.ActiveSelf);
|
||||
}
|
||||
}
|
||||
|
||||
private UIManager _canvas;
|
||||
|
||||
public KeyCode hotKey = KeyCode.F2;
|
||||
|
||||
public GameObject cube;
|
||||
}
|
||||
}
|
||||
BIN
XianTu/xiantu
Normal file
BIN
XianTu/xiantu
Normal file
Binary file not shown.
Reference in New Issue
Block a user