贵港路建设路地下商业街网上演练
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

141 lines
6.3 KiB

using System;
using AX.MessageSystem;
using UnityEngine;
using UnityEngine.UI;
public class ThirdPersonView : BaseToggle
{
private Transform topNameParent;
private Transform HealthBars;
private GameObject mP_Character;
private Transform hideNameToggle;
private GameObject mThirdPerson;
private GameObject mDefaultTarget;
private string mTglText = "视角切换";
private string mTglTextB = "第三人称";
private float distance;
private float distanceMin;
private float distanceMax;
private void Awake()
{
hideNameToggle = transform.parent.parent.parent.Find("HideName/HideNameToggle");
topNameParent = GameObject.Find("Canvas").transform.Find("TheHeadName");
HealthBars = GameObject.Find("Canvas").transform.Find("HaemalPanel");
mP_Character = GameObject.Find("P_AllParent/P_Person/P_Character");
mDefaultTarget = GameObject.Find("Target");
distance = GameObject.Find("Main Camera").GetComponent<CameraManager>().distance;
distanceMin = GameObject.Find("Main Camera").GetComponent<CameraManager>().minDistance;
distanceMax = GameObject.Find("Main Camera").GetComponent<CameraManager>().maxDistance;
MessageDispatcher.AddListener("CHANGE_TO_THIRDPERSONVIEW", ChangeToThirdPersonView);
}
void Start()
{
}
public override void OnDestroy()
{
base.OnDestroy();
MessageDispatcher.RemoveListener("CHANGE_TO_THIRDPERSONVIEW", ChangeToThirdPersonView);
}
private void ChangeToThirdPersonView(IMessage obj)
{
transform.parent.parent.Find("ViewSwitchToggle").GetComponent<Toggle>().isOn = true;
transform.GetComponent<Toggle>().isOn = true;
}
public override void RespondFun(bool value)
{
if (value == true)
{
//MessageDispatcher.SendMessage("OBJ_SHOWED", value);
//topNameParent.SetActive(true);
//HealthBars.SetActive(true);
//if (CurrentUserInfo.role != Role.导调组 && CurrentUserInfo.role != Role.总队指挥中心
//&& CurrentUserInfo.role != Role.支队指挥中心 && CurrentUserInfo.role != Role.中队指挥
//&& CurrentUserInfo.role != Role.战斗班长)
//{
// GameObject.Find("Main Camera").GetComponent<CameraManager>().isThirdPerson = true;
// try
// {
// mThirdPerson = mP_Character.transform.Find("Character").gameObject;
// if (mThirdPerson != null && GameObject.Find("Main Camera").GetComponent<CameraManager>().isThirdPerson == true)
// {
// GameObject.Find("ViewSwitchToggle").transform.Find("Label").GetComponent<Text>().text = mTglTextB;
// mThirdPerson = mP_Character.transform.Find("Character").gameObject;
// GameObject.Find("Main Camera").GetComponent<CameraManager>().ChangeTarget(mThirdPerson);
// GameObject.Find("Main Camera").GetComponent<CameraManager>().isThirdPerson = true;
// GameObject.Find("Main Camera").GetComponent<CameraManager>().ChangeCameraView(mThirdPerson.transform.position, 16, 10, 20);
// }
// }
// catch
// {
// GameObject.Find("Main Camera").GetComponent<CameraManager>().isThirdPerson = false;
// GameObject.Find("Main Camera").GetComponent<CameraManager>().ChangeCameraView(mDefaultTarget.transform.position, 40, 5, 100);
// LoadPromptWin.Instance.LoadTextPromptWindow("还没有克隆角色!", 1f);
// return;
// }
//}
if (mP_Character.transform.Find("Character") != null)
mThirdPerson = mP_Character.transform.Find("Character").gameObject;
if (mThirdPerson != null)
{
GameObject.Find("Main Camera").GetComponent<CameraManager>().viewType = CameraViewState.ThirdPersonView;
GameObject.Find("ViewSwitchToggle").transform.Find("Label").GetComponent<Text>().text = mTglTextB;
GameObject.Find("Main Camera").GetComponent<CameraManager>().ChangeTarget(mThirdPerson);
GameObject.Find("Main Camera").GetComponent<CameraManager>().ChangeCameraView(mThirdPerson.transform.position, 16, 10, 20);
MessageDispatcher.SendMessage("OBJ_SHOWED", value);
topNameParent.gameObject.SetActive(true);
HealthBars.gameObject.SetActive(true);
//切换到第三人称视角后,恢复控制角色的选中以便能寻路
SelectedObjs.selectedRolePlay = GameObject.Find("Character");
transform.parent.parent.Find("ViewSwitchToggle").GetComponent<Toggle>().isOn = false;
//直到创建的第三人称角色后才启用隐藏名称功能
if (hideNameToggle.GetComponent<HideTopName>().isPlaneView)
{
hideNameToggle.GetComponent<HideTopName>().isPlaneView = false;
}
}
else
{
LoadPromptWin.Instance.LoadTextPromptWindow("还没有克隆角色!", 1f);
GetComponent<Toggle>().isOn = false;
return;
}
}
else
{
if (CurrentUserInfo.role == Role. && mThirdPerson)
{
GameObject.Find("Main Camera").GetComponent<CameraManager>().viewType = CameraViewState.None;
GameObject.Find("ViewSwitchToggle").transform.Find("Label").GetComponent<Text>().text = mTglText;
GameObject.Find("Main Camera").GetComponent<CameraManager>().ChangeTarget(mDefaultTarget);
GameObject.Find("Main Camera").GetComponent<CameraManager>().ChangeCameraView(mThirdPerson.transform.position, distance, distanceMin, distanceMax);
foreach (Transform t in mP_Character.transform)
{
Destroy(t.gameObject);
}
MessageDispatcher.SendMessage("CloneCharacterShow");
SelectedObjs.selectedRolePlay = null;
mThirdPerson = null;
}
}
}
}