-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSofaParticlesModelEditor.cs
More file actions
61 lines (52 loc) · 2.09 KB
/
Copy pathSofaParticlesModelEditor.cs
File metadata and controls
61 lines (52 loc) · 2.09 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
using UnityEngine;
using UnityEditor;
using SofaUnity;
using System.Collections.Generic;
namespace SofaUnity
{
/// <summary>
/// Editor class corresponding to @sa SofaParticlesModel
/// Provide only a create method to create SofaParticlesModel from Unity Menu
/// </summary>
[CustomEditor(typeof(SofaParticlesModel), true)]
public class SofaParticlesModelEditor : Editor
{
/// <summary>
/// Add SofaParticlesModel creation to the SofaUnity Menu
/// </summary>
/// <returns>Pointer to the SofaParticlesModel GameObject</returns>
[MenuItem("Tools/SofaUnity/SofaComponent/SofaParticlesModel")]
[MenuItem("GameObject/Tools/SofaUnity/SofaComponent/SofaParticlesModel")]
public static GameObject CreateNew()
{
if (Selection.activeTransform != null)
{
GameObject selectObj = Selection.activeGameObject;
SofaDAGNode dagN = selectObj.GetComponent<SofaDAGNode>();
if (dagN == null)
{
Debug.LogError("Error2 creating SofaParticlesModel 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 SofaParticlesModel object. No SofaDAGNode with a valid SofaMesh selected.");
return null;
}
GameObject go = new GameObject("SofaParticlesModel - " + dagN.UniqueNameId);
SofaParticlesModel pModel = go.AddComponent<SofaParticlesModel>();
go.transform.parent = selectObj.transform;
pModel.m_sofaMesh = mesh;
return go;
}
else
{
Debug.LogError("Error1 creating SofaBeamModel object. No SofaDAGNode with a valid SofaMesh selected.");
}
return null;
}
}
}