202 lines
6.3 KiB
C#
202 lines
6.3 KiB
C#
using LitJson;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using ZXKFramework;
|
||
[RequireComponent(typeof(OutLineRender))]
|
||
public class HighLightManager : MonoBehaviour
|
||
{
|
||
OutLineRender outLine;
|
||
Outline outLine_;
|
||
private Dictionary<string, OutLineRender> allOutLineDict = new Dictionary<string, OutLineRender>();
|
||
private Dictionary<string, Outline> allOutLineDict_ = new Dictionary<string, Outline>();
|
||
Transform root;
|
||
public void Init()
|
||
{
|
||
outLine = GetComponent<OutLineRender>();
|
||
outLine_ = GetComponent<Outline>();
|
||
root = GameObject.Find("Root").transform;
|
||
Game.Instance.res.Load<TextAsset>(MVC.GetModel<YiLiao.Main.GameModel>().mainData.folder + "/ExcelData/ExcelToJson/BaseData.json", args => {
|
||
string interactionObjs = "";
|
||
List<JsonData> data = JsonMapper.ToObject<List<JsonData>>(args.text);
|
||
for (int i = 0; i < data.Count; i++)
|
||
{
|
||
interactionObjs += data[i]["obj"].ToString() + "|";
|
||
}
|
||
string[] strs = interactionObjs.Split('|');
|
||
for (int i = 0; i < strs.Length; i++)
|
||
{
|
||
if (!allOutLineDict.ContainsKey(strs[i]) && !string.IsNullOrEmpty(strs[i]))
|
||
{
|
||
GameObject go = root.FindFirst(strs[i]);
|
||
if (go != null && go.TryGetComponent(out Collider col))
|
||
{
|
||
if (go.TryGetComponent(out OutLineRender light))
|
||
{
|
||
allOutLineDict.Add(strs[i], SetOutLine(light));
|
||
}
|
||
else
|
||
{
|
||
OutLineRender outli = go.AddComponent<OutLineRender>();
|
||
outli.enabled = false;
|
||
allOutLineDict.Add(strs[i], SetOutLine(outli));
|
||
}
|
||
if (go.TryGetComponent(out Outline light_))
|
||
{
|
||
allOutLineDict_.Add(strs[i], SetOutline_(light_));
|
||
}
|
||
else
|
||
{
|
||
Outline outli = go.AddComponent<Outline>();
|
||
outli.enabled = false;
|
||
allOutLineDict_.Add(strs[i], SetOutline_(outli));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
});
|
||
Game.Instance.eventManager.AddListener<HighLightEvent>(VisiableLight);
|
||
}
|
||
private void VisiableLight(HighLightEvent e)
|
||
{
|
||
if (e.visiable)
|
||
{
|
||
ShowHighLight(e.name);
|
||
}
|
||
else
|
||
{
|
||
HideHighLight(e.name);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// <20><><EFBFBD>ø<EFBFBD><C3B8><EFBFBD>
|
||
/// </summary>
|
||
OutLineRender SetOutLine(OutLineRender outli)
|
||
{
|
||
if (outLine != null)
|
||
{
|
||
//outli.OutlineMode = outLine.OutlineMode;
|
||
outli.OutLineColor = outLine.OutLineColor;
|
||
outli.OutLineStrength = outLine.OutLineStrength;
|
||
}
|
||
return outli;
|
||
}
|
||
Outline SetOutline_(Outline outli)
|
||
{
|
||
if (outLine != null)
|
||
{
|
||
outli.OutlineMode = outLine_.OutlineMode;
|
||
outli.OutlineColor = outLine_.OutlineColor;
|
||
outli.OutlineWidth = outLine_.OutlineWidth;
|
||
}
|
||
return outli;
|
||
}
|
||
/// <summary>
|
||
/// <20><EFBFBD><F2BFAAB8><EFBFBD>
|
||
/// </summary>
|
||
public void ShowHighLight(string name, Action callBack = null)
|
||
{
|
||
if (allOutLineDict.ContainsKey(name) && allOutLineDict_.ContainsKey(name))
|
||
{
|
||
allOutLineDict[name].enabled = true;
|
||
allOutLineDict_[name].enabled = true;
|
||
callBack?.Invoke();
|
||
}
|
||
else
|
||
{
|
||
GameObject go = GameObject.Find("Root").FindFirst(name);
|
||
if (go != null)
|
||
{
|
||
allOutLineDict.Add(go.name, SetOutLine(go.GetOrAddComponent<OutLineRender>()));
|
||
allOutLineDict_.Add(go.name, SetOutline_(go.GetOrAddComponent<Outline>()));
|
||
}
|
||
allOutLineDict[name].enabled = true;
|
||
allOutLineDict_[name].enabled = true;
|
||
callBack?.Invoke();
|
||
}
|
||
}
|
||
public bool IsHighLight(string name)
|
||
{
|
||
if (allOutLineDict.ContainsKey(name) && allOutLineDict_.ContainsKey(name))
|
||
{
|
||
if (allOutLineDict[name].enabled && allOutLineDict_[name].enabled)
|
||
{
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
/// <summary>
|
||
/// <20>رո<D8B1><D5B8><EFBFBD>
|
||
/// </summary>
|
||
/// <param name="name"></param>
|
||
public void HideHighLight(string name, Action callBack = null)
|
||
{
|
||
if (allOutLineDict.TryGetValue(name, out OutLineRender outli))
|
||
{
|
||
if (outli != null && outli.enabled)
|
||
{
|
||
outli.enabled = false;
|
||
}
|
||
}
|
||
if (allOutLineDict_.TryGetValue(name, out Outline outli_))
|
||
{
|
||
if (outli_ != null && outli_.enabled)
|
||
{
|
||
outli_.enabled = false;
|
||
}
|
||
}
|
||
callBack?.Invoke();
|
||
}
|
||
|
||
/// <summary>
|
||
/// <20>ر<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
/// </summary>
|
||
public void HideAllHighLight()
|
||
{
|
||
foreach (var item in allOutLineDict)
|
||
{
|
||
if (item.Value.enabled) item.Value.enabled = false;
|
||
}
|
||
foreach (var item in allOutLineDict_)
|
||
{
|
||
if (item.Value.enabled) item.Value.enabled = false;
|
||
}
|
||
}
|
||
public void RemoveHighLight(string name)
|
||
{
|
||
if (allOutLineDict.ContainsKey(name))
|
||
{
|
||
Destroy(allOutLineDict[name]);
|
||
allOutLineDict.Remove(name);
|
||
}
|
||
if (allOutLineDict_.ContainsKey(name))
|
||
{
|
||
Destroy(allOutLineDict_[name]);
|
||
allOutLineDict_.Remove(name);
|
||
}
|
||
}
|
||
public void RemoveAllHighLight()
|
||
{
|
||
foreach (var item in allOutLineDict)
|
||
{
|
||
Destroy(item.Value);
|
||
}
|
||
allOutLineDict.Clear();
|
||
|
||
foreach (var item in allOutLineDict_)
|
||
{
|
||
Destroy(item.Value);
|
||
}
|
||
allOutLineDict_.Clear();
|
||
}
|
||
private void OnDestroy()
|
||
{
|
||
Game.Instance.eventManager.RemoveListener<HighLightEvent>(VisiableLight);
|
||
}
|
||
}
|