public PlanVertexData(string data) { PlanVertexData Data = JsonUtility.FromJson <PlanVertexData>(data); _NodePoints = Data._NodePoints; _Fineness = Data._Fineness; _Alpha = Data._Alpha; _SpatialPos = Data._SpatialPos; _SpatialDomain = Data._SpatialDomain; _CurvePoints = Curve.CatmulRomCurve(_NodePoints, _Fineness, _Alpha); }
// Use this for initialization void Start() { #region Error if (GetComponent <MeshFilter>() == null) { gameObject.SetActive(false); Debug.LogError("警告" + "游戏物体缺少组件 MeshFilter!"); return; } if (GetComponent <MeshRenderer>() == null) { gameObject.SetActive(false); Debug.LogError("警告" + "游戏物体缺少组件 MeshRenderer!"); return; } //if (transform.localScale != Vector3.one) //{ // transform.localScale = Vector3.one; // Debug.Log("游戏物体的缩放已归为初始值"); //} #endregion _Mesh = GetComponent <MeshFilter>().mesh; m_MeshRenderer = GetComponent <MeshRenderer>(); m_TextMesh = GetComponentInChildren <TextMesh>(); m_PlanVertexData = new PlanVertexData(m_RoadPlanData.text); m_CurvePoints = m_PlanVertexData._CurvePoints; InitCamera(); m_MeshRenderer.material.SetVector("_CameraParams", new Vector4(m_PlanVertexData._SpatialPos.x, m_PlanVertexData._SpatialPos.y, Mathf.Abs(m_PlanVertexData._SpatialDomain.x), Mathf.Abs(m_PlanVertexData._SpatialDomain.x))); Debug.Log(m_MeshRenderer.material.GetVector("_CameraParams")); GenerateVertexNode(); dt = Time.time; }
private void OnGUI() { GUI.backgroundColor = new Color(0.2f, 0.9f, 1f, 0.9f); if (ParentTarget == null) { ParentTarget = new GameObject("PlanVertexEditor", typeof(PlanVertexVisual)); m_PlanVertexVisual = ParentTarget.GetComponent <PlanVertexVisual>(); Selection.activeGameObject = ParentTarget; } scrollVec2Fineness = EditorGUILayout.BeginScrollView(scrollVec2Fineness, GUILayout.Width(position.width), GUILayout.Height(position.height)); //#region 打开网页 //EditorGUILayout.BeginHorizontal("MeTransitionHead"); //if (GUILayout.Button("访问CSDN博客", "toolbarbutton")) //{ // Help.BrowseURL(@"http://blog.csdn.net/qq992817263/article/details/51579913"); //} //if (GUILayout.Button("访问github项目", "toolbarbutton")) //{ // Help.BrowseURL(@"https://github.com/coding2233/MeshEditor"); //} //EditorGUILayout.EndHorizontal(); //#endregion if (m_PlanVertexVisual.Count < 1) { #region Json数据 EditorGUILayout.BeginHorizontal("HelpBox"); GUILayout.Label("Json数据:"); if (ParentTarget != null) { m_RoadPlanData = (TextAsset)EditorGUI.ObjectField(new Rect(2, 5, position.width * 0.5f, 20), m_RoadPlanData, typeof(TextAsset), false); if (m_RoadPlanData != null) { if (GUILayout.Button("解析Json数据", GUILayout.Width(200))) { EditorApplication.delayCall += () => { PlanVertexData data = JsonUtility.FromJson <PlanVertexData>(m_RoadPlanData.text); fineness = data._Fineness; foreach (Vector3 v in data._NodePoints) { CreatNode(v); } Debug.Log("_SpatialDomain : " + data._SpatialDomain + " _SpatialPos : " + data._SpatialPos); m_PlanVertexVisual.Size = new Vector2(data._SpatialDomain.x, data._SpatialDomain.z); m_PlanVertexVisual.Depth = data._SpatialDomain.y; m_PlanVertexVisual.transform.position = new Vector3(data._SpatialPos.x, 0, data._SpatialPos.y); }; } } } else { GUILayout.Label("无", "ErrorLabel"); GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); #endregion } if (m_PlanVertexVisual != null && m_PlanVertexVisual.m_Nodes != null && ParentTarget != null) { if (Selection.activeGameObject != null) { #region 当前编辑目标 EditorGUILayout.BeginHorizontal("HelpBox"); GUILayout.Label("当前编辑节点:"); if (m_PlanVertexVisual.Contains(Selection.activeGameObject.transform)) { curr_Node = Selection.activeGameObject.transform; targetName = curr_Node.name; if (GUILayout.Button(targetName, GUILayout.Width(200))) { EditorApplication.delayCall += () => { Selection.activeGameObject = curr_Node.gameObject; }; } } else { GUILayout.Label("无", "ErrorLabel"); GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); #endregion } #region 精细度 EditorGUILayout.BeginHorizontal("HelpBox"); GUILayout.Label("精细度: " + fineness); if (ParentTarget != null) { fineness = GUILayout.HorizontalSlider(fineness, 10, 100); if (fineness != oldfineness) { m_PlanVertexVisual.fineness = fineness; oldfineness = fineness; } } else { GUILayout.Label("无", "ErrorLabel"); GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); #endregion #region 顶点数量 EditorGUILayout.BeginHorizontal("HelpBox"); GUILayout.Label("当前节点数量:"); if (ParentTarget != null && m_PlanVertexVisual != null) { GUILayout.Label(m_PlanVertexVisual.Count.ToString()); } else { GUILayout.Label("无", "ErrorLabel"); GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); #endregion } GUI.backgroundColor = new Color(0.2f, 0.5f, 1f, 0.9f); #region 创建、删除 EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("创建节点", "LargeButtonLeft")) { EditorApplication.delayCall += CreatNode; } if (GUILayout.Button("删除节点", "LargeButtonRight")) { EditorApplication.delayCall += () => { if (Selection.activeGameObject != null) { if (m_PlanVertexVisual.Contains(Selection.activeGameObject.transform)) { curr_Node = Selection.activeGameObject.transform; targetName = curr_Node.name; Transform obj = m_PlanVertexVisual.Remove(Selection.activeGameObject.transform); if (obj != null) { Selection.activeGameObject = obj.gameObject; } else { Selection.activeGameObject = ParentTarget; } } } }; } EditorGUILayout.EndHorizontal(); #endregion //#region 复制、多个复制 //EditorGUILayout.BeginHorizontal(); //if (GUILayout.Button("复制", "LargeButtonLeft")) //{ // // EditorApplication.delayCall += CollapseOnTwoVertex; //} //if (GUILayout.Button("多个复制", "LargeButtonRight")) //{ // // EditorApplication.delayCall += CollapseOnMoreVertex; //} //EditorGUILayout.EndHorizontal(); //#endregion #region 取消编辑 GUI.color = Color.yellow; GUI.backgroundColor = Color.red; EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("取消编辑", "LargeButton")) { Close(); } EditorGUILayout.EndHorizontal(); #endregion #region 保存数据 GUI.color = Color.green; GUI.backgroundColor = Color.green; EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("保存编辑数据", "LargeButton")) { EditorApplication.delayCall += Finish; } EditorGUILayout.EndHorizontal(); #endregion EditorGUILayout.EndScrollView(); }