-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSofaBeamAdapterEditor.cs
More file actions
70 lines (59 loc) · 2.67 KB
/
Copy pathSofaBeamAdapterEditor.cs
File metadata and controls
70 lines (59 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using UnityEngine;
using UnityEditor;
using SofaUnity;
using System.Collections.Generic;
namespace SofaUnity
{
[CustomEditor(typeof(SofaBeamAdapterModel), true)]
public class SofaBeamAdapterModelEditor : Editor
{
/// <summary>
/// Add SofaBeamAdapterModel creation to the SofaUnity Menu
/// </summary>
/// <returns>Pointer to the SofaBeamAdapterModel GameObject</returns>
[MenuItem("Tools/SofaUnity/SofaComponent/SofaBeamAdapterModel")]
[MenuItem("GameObject/Tools/SofaUnity/SofaComponent/SofaBeamAdapterModel")]
public static GameObject CreateNew()
{
if (Selection.activeTransform != null)
{
GameObject selectObj = Selection.activeGameObject;
SofaDAGNode dagN = selectObj.GetComponent<SofaDAGNode>();
if (dagN == null)
{
Debug.LogError("Error2 creating SofaBeamAdapterModel object. No SofaDAGNode with a valid SofaMesh selected.");
return null;
}
SofaMesh mesh = dagN.GetSofaMesh();
if (mesh == null)
mesh = dagN.FindSofaMesh();
if (mesh == null)
{
Debug.LogError("Error3 creating SofaBeamAdapterModel object. No SofaDAGNode with a valid SofaMesh selected.");
return null;
}
GameObject go = new GameObject("SofaBeamAdapterModel - " + dagN.UniqueNameId);
SofaBeamAdapterModel bModel = go.AddComponent<SofaBeamAdapterModel>();
go.transform.parent = selectObj.transform;
bModel.m_sofaMesh = mesh;
return go;
}
else
{
Debug.LogError("Error1 creating SofaBeamAdapterModel object. No SofaDAGNode with a valid SofaMesh selected.");
}
return null;
}
/// Method to create parameters GUI
public override void OnInspectorGUI()
{
SofaBeamAdapterModel model = this.target as SofaBeamAdapterModel;
if (model == null)
return;
model.m_sofaMesh = (SofaMesh)EditorGUILayout.ObjectField("Beam SofaMesh", model.m_sofaMesh, typeof(SofaMesh), true);
model.BeamDiscretisation = EditorGUILayout.IntField("Beam Discretisation", model.BeamDiscretisation);
model.BeamRadius = EditorGUILayout.Slider("Beam Radius", model.BeamRadius, 0.001f, 30);
model.m_childCameraScript = (GameObject)EditorGUILayout.ObjectField("Child Tip Camera", model.m_childCameraScript, typeof(GameObject), true);
}
}
}