海淀天下城电子沙盘单机版
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.

126 lines
4.2 KiB

4 years ago
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 空间测距脚本
/// </summary>
public class SpaceRanging : RangingLineType
{
bool ControlRanging = false;//控制重复生成数字显示
private void Start()
{
variableX = 5f;
variableY = 18f;
variableZ = 5f;
}
public override void HandleOther(bool flag)
{
if (ControlRanging)
{
EstimatePosY("Height");
EstimatePosY("Width");
ControlRanging = false;
InstanceMeshText(placementPos, placementPos2);
placementPos = new Vector3(0, 0, 0);
placementPos2 = new Vector3(0, 0, 0);
}
else
{
ControlRanging = true;
}
if (!flag) { RangSpecialTreat(); }
}
/// <summary>
/// 检查第一个碰撞点和第二个碰撞点的高度
/// 从而判断哪个点是基础点
/// </summary>
Vector3 NewLine;
public void EstimatePosY(string Value)
{
//根据新获取的点绘制线段
if (placementPos.y < placementPos2.y)
{
if (Value.Equals("Height"))
{
NewLine = new Vector3(placementPos.x, placementPos2.y, placementPos.z);
}
else
{
NewLine = new Vector3(placementPos2.x, placementPos.y, placementPos2.z);
}
CreateLine(placementPos, NewLine);
InstanceMeshText(placementPos, NewLine);
}
else
{
if (Value.Equals("Height"))
{
NewLine = new Vector3(placementPos2.x, placementPos.y, placementPos2.z);
}
else
{
NewLine = new Vector3(placementPos.x, placementPos2.y, placementPos.z);
}
CreateLine(placementPos2, NewLine);
InstanceMeshText(placementPos2, NewLine);
}
}
/// <summary>
/// 实例化完成后显示米数
/// </summary>
/// <param name="placementPos">第一个碰撞点</param>
/// <param name="placementPos2">第二个碰撞点</param>
/// <param name="flag">标记起点米数</param>
public void InstanceMeshText(Vector3 placementPos_, Vector3 placementPos2_)
{
float dis = Vector3.Distance(placementPos_, placementPos2_);
float level = Vector2.Distance(new Vector2(placementPos_.x, placementPos_.z), new Vector2(placementPos2_.x, placementPos2_.z));
float height = Mathf.Abs(placementPos_.y - placementPos2_.y);
Vector3 vethight = new Vector3();
Vector3 vetLow = new Vector3();
//获取高低点
if (placementPos_.y < placementPos2_.y)
{
vetLow = placementPos_;
vethight = placementPos2_;
}
else
{
if (placementPos_.y == placementPos2_.y)//判断Y水平情况下
{
vetLow = placementPos_;
vethight = placementPos2_;
}
else
{
vetLow = placementPos2_;
vethight = placementPos_;
}
}
if (ControlRanging)
{
//交叉点
GameObject PointMeshText = Instantiate(Resources.Load<GameObject>("Prefab/Lines/Ranging"), vetLow, Quaternion.identity) as GameObject;
PointMeshText.transform.parent = transform;
PointMeshText.transform.localScale = new Vector3(2, 2, 1);
PointMeshText.transform.Find("text").GetComponent<TextMesh>().text = "0";
ControlRanging = false;
RangList.Add(PointMeshText);
}
//顶点
GameObject PointMeshText_ = Instantiate(Resources.Load<GameObject>("Prefab/Lines/Ranging"), vethight, Quaternion.identity) as GameObject;
PointMeshText_.transform.parent = transform;
PointMeshText_.transform.localScale = new Vector3(2, 2, 1);
float distance = Vector3.Distance(vetLow, vethight);
PointMeshText_.transform.Find("text").GetComponent<TextMesh>().text = Math.Round(distance, 2).ToString();
RangList.Add(PointMeshText_);
}
}