| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityCommon;
- using UnityEngine;
- using Sirenix.OdinInspector;
- namespace DTYJ
- {
- public class ZhaJiCtrl : SerializedMonoBehaviour
- {
- public static ZhaJiCtrl Instance;
- private Dictionary<MeshRenderer, Material> dicMatOld;
- private void Awake()
- {
- Instance = this;
- }
- private void Start()
- {
- dicMatOld = new Dictionary<MeshRenderer, Material>();
- foreach (var item in dic)
- {
- dicMatOld[item.Value.mrJin] = item.Value.mrJin.material;
- dicMatOld[item.Value.mrChu] = item.Value.mrChu.material;
- }
- }
- public Material mKai, mGuan;
- public Dictionary<string, ZhaJiModelItem> dic = new Dictionary<string, ZhaJiModelItem>();
- [Serializable]
- public class ZhaJiModelItem
- {
- public Animation anim;
- public MeshRenderer mrJin, mrChu;
- }
- public void SetGateState(string id, int state, int dir)
- {
- if (dic.ContainsKey(id))
- {
- var item = dic[id];
- var anim = item.anim;
- var animationName = dic[id].anim.clip.name;
- anim[animationName].time = state == 1 ? 0 : anim[animationName].length;
- anim[animationName].speed = state == 1 ? 1 : -1;
- anim[animationName].wrapMode = WrapMode.Once;
- anim.CrossFade(animationName);
- if (state == 2 || state == 3)
- {
- item.mrJin.material = mGuan;
- item.mrChu.material = mGuan;
- }
- else
- {
- item.mrJin.material = dicMatOld[item.mrJin];
- item.mrChu.material = dicMatOld[item.mrChu];
- if (dir == 0 || dir == 1)
- {//TODO 乘客导航方向需要变更
- Debug.LogWarning("变更闸机方向");
- return;//张海军接口方向控制错误,直接返回,不受他direction字段控制闸机方向
- item.mrJin.material = dir == 0 ? mKai : mGuan;
- item.mrChu.material = dir == 1 ? mKai : mGuan;
- }
- }
- }
- }
- [ContextMenu("处理")]
- public void HandleTemp()
- {
- Dictionary<string, ZhaJiModelItem> dicNew = new Dictionary<string, ZhaJiModelItem>();
- foreach (var kvp in dic)
- {
- var animPath = Utility.GetPathInHierichy(kvp.Value.anim.transform, null);
- var mrChuPath = Utility.GetPathInHierichy(kvp.Value.mrChu.transform, null);
- var mrJinPath = Utility.GetPathInHierichy(kvp.Value.mrJin.transform, null);
- ZhaJiModelItem zhaJiModelItem = new ZhaJiModelItem();
- zhaJiModelItem.anim = GameObject.Find("StationOthers/1/" + animPath).GetComponent<Animation>();
- zhaJiModelItem.mrChu = GameObject.Find("StationOthers/1/" + mrChuPath).GetComponent<MeshRenderer>();
- zhaJiModelItem.mrJin = GameObject.Find("StationOthers/1/" + mrJinPath).GetComponent<MeshRenderer>();
- dicNew["1_" + kvp.Key] = zhaJiModelItem;
- zhaJiModelItem = new ZhaJiModelItem();
- zhaJiModelItem.anim = GameObject.Find("StationOthers/2/" + animPath).GetComponent<Animation>();
- zhaJiModelItem.mrChu = GameObject.Find("StationOthers/2/" + mrChuPath).GetComponent<MeshRenderer>();
- zhaJiModelItem.mrJin = GameObject.Find("StationOthers/2/" + mrJinPath).GetComponent<MeshRenderer>();
- dicNew["2_" + kvp.Key] = zhaJiModelItem;
- }
- foreach (var kvp in dicNew)
- {
- dic[kvp.Key] = kvp.Value;
- }
- }
- //public List<MeshRenderer> list = new List<MeshRenderer>();
- //[ContextMenu("处理2")]
- //public void HandleTemp2()
- //{
- // foreach(var item in dic)
- // {
- // list.Add(item.Value.mrChu);
- // list.Add(item.Value.mrJin);
- // }
- //}
- }
- }
|