大连中石油电子沙盘
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.
 
 
 
 

156 lines
4.6 KiB

using AX.MessageSystem;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
//Author:ZCG
//CreatTime:12/2/2017
/// <summary>
///µØÃæÎı¾¿ØÖÆ
/// </summary>
public class TextControl : MonoBehaviour
{
TextMesh text;
//private Vector3 initScale;
public float Scale { get;private set; }
public Color Color { get; private set; }
public string InputField { get; private set; }
public float initScale;
public Color initColor;
public string initInputField;
void Awake()
{
Color = Color.white;
Scale = 1;
text = transform.Find("InstanceText").GetComponent<TextMesh>();
InputField = text.text;
MessageDispatcher.AddListener("ReplayEvent", ExecuteEvent);
}
private void ExecuteEvent(IMessage obj)
{
var eventData = (EventData)obj.Data;
if (eventData.eventType == RecordEventType.ToolTask && eventData.cloneObjType == CloneObjType.InstanceText)
{
var arg = JsonUtility.FromJson<RecordInstanceText>(eventData.json);
if (arg.objectName == gameObject.name)
{
SetScale(arg.Scale);
SetText(arg.InputField);
SetColor(arg.Color);
}
}
}
void OnDestroy()
{
MessageDispatcher.RemoveListener("ReplayEvent", ExecuteEvent);
}
private DateTime t1, t2;
private void OnMouseDown()
{
//Ë«»÷
if (!EventSystem.current.IsPointerOverGameObject())
{
t2 = DateTime.Now;
if (t2 - t1 < new TimeSpan(0, 0, 0, 0, 500))
{
if (SelectedObjs.selectedObj == gameObject)
{
initColor = Color;
initInputField = InputField;
initScale = Scale;
UIPlanInstanceText.Instance.LoadObjData(gameObject);
}
}
t1 = t2;
}
}
/// <summary>
/// ÉèÖôóС
/// </summary>
public void SetScale(float value)
{
transform.localScale = new Vector3(value, value, 1);
Scale = value;
//AddRecordEventChange(transform);
}
/// <summary>
/// ÉèÖÃÎı¾
/// </summary>
public void SetText(string str)
{
text.text = str;
InputField = str;
// AddRecordEventChange(transform);
}
/// <summary>
/// ÉèÖÃÑÕÉ«
/// </summary>
public void SetColor(Color value)
{
text.color = value;
Color = value;
}
private void LateUpdate()
{
transform.LookAt(Camera.main.transform);
}
/// <summary>
/// È·ÈÏ
/// </summary>
public void Confirm()
{
AddRecordEventChange(transform);
}
/// <summary>
/// ³·»Ø
/// </summary>
public void Revocation()
{
SetColor(initColor);
SetText(initInputField);
SetScale(initScale);
}
/// <summary>
/// Ìí¼Ó¼Ç¼(¿Ë¡)
/// </summary>
public void AddRecordEventChange(Transform obj)
{
if (ReplaySetting.PlayStatus == PlayStatus.isEditor && RecordManager.Instance.recordStatus == RecordStatus.normal)
{
var eventData = new EventData();
eventData.time = RecordManager.Instance.RecordTimer;
eventData.cloneObjType = CloneObjType.InstanceText;
eventData.eventType = RecordEventType.ToolTask;
var data = new RecordInstanceText();
SetBaseData(data, obj);
SetInstanceText(data, obj);
string json = JsonUtility.ToJson(data);
eventData.json = json;
RecordManager.Instance.jsonData.eventDataList.Add(eventData);
}
}
private void SetBaseData(RecordObjectBase data, Transform obj)
{
var msg = obj.GetComponent<CloneGameObjInfo>();
data.gameObjType = msg.gameObjType;
data.objectName = obj.gameObject.name;
data.buildNum = msg.buildNum;
data.floorNum = msg.floorNum;
data.interlayerNum = msg.interlayerNum;
data.myTransform.setMyPosition(obj.localPosition);
data.myTransform.setMyRotation(obj.localRotation);
data.myTransform.setMyScale(obj.localScale);
data.isActive = obj.gameObject.activeSelf;
}
private void SetInstanceText(RecordInstanceText data, Transform child)
{
var textControl = child.GetComponent<TextControl>();
data.Color = Color;
data.Scale = Scale;
data.InputField = InputField;
}
}