188 lines
5.4 KiB
C#
188 lines
5.4 KiB
C#
|
|
#define _DEBUG_
|
|||
|
|
// #undef _DEBUG_
|
|||
|
|
|
|||
|
|
using System;
|
|||
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using Deconstruction.Element;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
using Deconstruction.Manager;
|
|||
|
|
using Deconstruction.Tool;
|
|||
|
|
using Deconstruction.Type.Area;
|
|||
|
|
using Deconstruction.Type.Serialize;
|
|||
|
|
using Newtonsoft.Json;
|
|||
|
|
using SerializerHelper.Type;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
using XericLibrary.Runtime.Debuger;
|
|||
|
|
using XericLibrary.Runtime.MacroLibrary;
|
|||
|
|
|
|||
|
|
namespace SesothoLine
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// <code>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><D7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </code>
|
|||
|
|
/// </summary>
|
|||
|
|
public sealed class SesothoPeManager : PlaceElementManager
|
|||
|
|
{
|
|||
|
|
#region <EFBFBD><EFBFBD>̬<EFBFBD><EFBFBD>Ա
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>˴<EFBFBD><CBB4>ṩ<EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD>븸<EFBFBD><EFBFBD><E0B5A5><EFBFBD>Ƕ<EFBFBD><C7B6><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public new static SesothoPeManager Inst => _inst;
|
|||
|
|
private static SesothoPeManager _inst;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>·<EFBFBD><C2B7><EFBFBD>ƹ<EFBFBD><C6B9><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public static SesothoArrangementWiresTool WiresTool => _wiresTool;
|
|||
|
|
private static SesothoArrangementWiresTool _wiresTool;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͻ<EFBFBD><CFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public static Vector3 NearestLineTangentPoint => _lineTangentTraceTool.NearsetPoint;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public static PlacementBase NearestLineTangentObject => _lineTangentTraceTool.NearsetObject;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>ԭ<EFBFBD><D4AD>
|
|||
|
|
/// </summary>
|
|||
|
|
public static Vector3 NearestPoint => TrackingTool.TrackingCurrentPosition;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public static PlacementBase NearestObject => TrackingTool.TrackingCurrentTarget;
|
|||
|
|
|
|||
|
|
private static TrajectoryTrackingTool.TrackPersistentCommunicate _lineTangentTraceTool;
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD>Թ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
#if UNITY_EDITOR
|
|||
|
|
|
|||
|
|
public bool EnableGridDebugDraw = false;
|
|||
|
|
|
|||
|
|
|
|||
|
|
public void DebugFunc()
|
|||
|
|
{
|
|||
|
|
if (EnableGridDebugDraw)
|
|||
|
|
{
|
|||
|
|
PlacementNeighbor.DebugDrawGrid();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
protected override void Awake()
|
|||
|
|
{
|
|||
|
|
base.Awake();
|
|||
|
|
_inst = this;
|
|||
|
|
|
|||
|
|
if (LineMaterial == null)
|
|||
|
|
Debug.LogError("<22><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṩһ<E1B9A9><D2BB><EFBFBD>߶β<DFB6><CEB2><EFBFBD>");
|
|||
|
|
if (PointMaterial == null)
|
|||
|
|
Debug.LogError("<22><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṩһ<E1B9A9><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|||
|
|
|
|||
|
|
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>߹<EFBFBD><DFB9><EFBFBD>
|
|||
|
|
_wiresTool = new SesothoArrangementWiresTool();
|
|||
|
|
_wiresTool.InitializeParent(transform);
|
|||
|
|
|
|||
|
|
_lineTangentTraceTool = TrackingTool.InstantiationTrackCaculate(PlaceholdersAreaType.LinearContinuity);
|
|||
|
|
|
|||
|
|
// <20>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
EnableUpdate = true;
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
protected override void Start()
|
|||
|
|
{
|
|||
|
|
base.Start();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private NeighborGrid<PlacementBase>.NeighborGridIndex index;
|
|||
|
|
protected override void Update()
|
|||
|
|
{
|
|||
|
|
base.Update();
|
|||
|
|
#if UNITY_EDITOR
|
|||
|
|
DebugFunc();
|
|||
|
|
#endif
|
|||
|
|
if (Input.GetMouseButtonDown(2))
|
|||
|
|
{
|
|||
|
|
index = PlacementNeighbor.GetNeighborIndex(null);
|
|||
|
|
index.SetDrivenAsWorld(InputHelper.CurrentPosition);
|
|||
|
|
Debug.Log($"{index.GetDrivenAsLinear()} => {index.GetNeighbor().FirstOrDefault()}");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// new SerializeUnion();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private string serializeContext = null;
|
|||
|
|
protected override void LateUpdate()
|
|||
|
|
{
|
|||
|
|
base.LateUpdate();
|
|||
|
|
// if (DecisionMakerToolBase.ActiveDecisionMaker == null ||
|
|||
|
|
// !DecisionMakerToolBase.ActiveDecisionMaker.EnableTool)
|
|||
|
|
#if !UNITY_EDITOR || !_DEBUG_
|
|||
|
|
return;
|
|||
|
|
#endif
|
|||
|
|
// <20><><EFBFBD>߹<EFBFBD><DFB9>ܲ<EFBFBD><DCB2><EFBFBD>
|
|||
|
|
if (Input.GetKeyDown(KeyCode.L))
|
|||
|
|
{
|
|||
|
|
_wiresTool.EnableTool = !_wiresTool.EnableTool;
|
|||
|
|
Debug.Log($"{(_wiresTool.EnableTool ? "<EFBFBD><EFBFBD><EFBFBD>ƹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѽ<EFBFBD><EFBFBD><EFBFBD>" : "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")}");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20>浵<EFBFBD><E6B5B5><EFBFBD>ܲ<EFBFBD><DCB2><EFBFBD>
|
|||
|
|
if (Input.GetKeyDown(KeyCode.S))
|
|||
|
|
{
|
|||
|
|
var obj = _wiresTool.ToolSerializeDispost();
|
|||
|
|
serializeContext = JsonConvert.SerializeObject(obj);
|
|||
|
|
Debug.Log(obj.ToString());
|
|||
|
|
}
|
|||
|
|
if (Input.GetKeyDown(KeyCode.D))
|
|||
|
|
{
|
|||
|
|
if (serializeContext == null)
|
|||
|
|
{
|
|||
|
|
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var obj = JsonConvert.DeserializeObject<SerializeUnion>(serializeContext);
|
|||
|
|
_wiresTool.ToolDiserializDispost(obj);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (Input.GetKeyDown(KeyCode.A))
|
|||
|
|
{
|
|||
|
|
_wiresTool.EnableCompress = !_wiresTool.EnableCompress;
|
|||
|
|
if (_wiresTool.EnableCompress )
|
|||
|
|
Debug.Log("<22><><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9>");
|
|||
|
|
else
|
|||
|
|
Debug.Log("<22>ر<EFBFBD>ѹ<EFBFBD><D1B9>");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>λ<EFBFBD><CEBB>
|
|||
|
|
if (TrackingTool.EnableTool || TrackingTool._enableAuxiliaryTool)
|
|||
|
|
{
|
|||
|
|
MacroDebugDraw.DrawDownArrow(NearestPoint, Color.magenta);
|
|||
|
|
MacroDebugDraw.DrawDownArrow(NearestLineTangentPoint, Color.green);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|