private void OnEnable() { TubeMesh = (TubeMesh)target; TubeMesh.SPData = TubeMesh.gameObject.transform.GetComponent <SplinePlus>().sPData; if (TubeMesh.MeshHolder == null) { var meshHolder = SplinePlusAPI.AddMeshHolder(TubeMesh.SPData, "TubeMesh"); TubeMesh.MeshHolder = meshHolder; TubeMesh.MeshRenderer = meshHolder.GetComponent <MeshRenderer>(); TubeMesh.Mesh = meshHolder.GetComponent <MeshFilter>(); } if (Delete == null) { Delete = new GUIContent((Texture2D)EditorGUIUtility.Load(SplinePlusEditor.FindAssetPath("Delete.png"))); } if (TubeMesh.Material == null) { TubeMesh.Material = (Material)EditorGUIUtility.Load(SplinePlusEditor.FindAssetPath("Base.mat")); if (TubeMesh.Material == null) { Debug.Log("mat null"); } } TubeMesh.SPData.MeshModifier = TubeMesh; TubeMesh.DrawMesh(); SplineCreationClass.Update_Spline += Update_Spline; }
public void Draw(SPData SPData, SplinePlusEditor SplinePlusEditor) { if (SPData.IsEditingPivot) { PivotEdit(SPData); } SceneViewGUI(SPData, SplinePlusEditor); }
public void Follower(SPData SPData, SplinePlusEditor SPEditor) { if (SPEditor.FollowersList == null) { Simple(SPData, SPEditor); } var followersRect = EditorGUILayout.BeginHorizontal(); SPEditor.FollowersList.DoList(new Rect(followersRect.x + 5, followersRect.y + 10, followersRect.width - 5, followersRect.height)); EditorGUILayout.EndHorizontal(); GUILayout.Space(SPEditor.FollowersList.GetHeight()); }
void MessageBox(SPData SPData, SplinePlusEditor SplinePlusEditor) { GUI.BeginGroup(new Rect(240, 20, 200, 100)); GUI.Label(new Rect(0, 0, 200, 100), SplinePlusEditor.SceneViewMenu); GUI.Label(new Rect(10, 5, 50, 20), "Radius:"); var radius = GUI.HorizontalSlider(new Rect(60, 5, 130, 20), SPData.SmoothRadius, 0, 1); if (SPData.SmoothRadius != radius) { Undo.RecordObject(SPData.SplinePlus, "Smooth node radius changed"); if (SPData.SmoothData.IsShared) { SplinePlusEditor.SmoothNodeClass.EditSmoothNodePoint(SPData, radius); } else { SplinePlusEditor.SmoothNodeClass.EditSmoothNode(SPData, radius); } EditorUtility.SetDirty(SPData.SplinePlus); } if (GUI.Button(new Rect(5, 25, 95, 20), "Cancel ")) { Undo.RecordObject(SPData.SplinePlus, "Smooth node canceled "); if (SPData.SmoothData.IsShared) { SplinePlusEditor.SmoothNodeClass.ResetSmoothSharedPathPoint(SPData); } else { SplinePlusEditor.SmoothNodeClass.ResetSmoothPathPoint(SPData); } EditorUtility.SetDirty(SPData.SplinePlus); } if (GUI.Button(new Rect(100, 25, 95, 20), "Apply ")) { Undo.RecordObject(SPData.SplinePlus, "Smooth node "); SPData.SmoothData.SmoothNode = false; SPData.SmoothData.Nodes = new Node[0]; if (SPData.Selections._SharedPathPointIndex != -1) { SPData.SharedNodes.RemoveAt(SPData.Selections._SharedPathPointIndex); } EditorUtility.SetDirty(SPData.SplinePlus); } GUI.EndGroup(); }
public void OnEnable() { var SplinePlus = (SplinePlus)target; SPData = SplinePlus.sPData; if (Banner == null) { Banner = new GUIContent((Texture2D)EditorGUIUtility.Load(SplinePlusEditor.FindAssetPath("Banner.png"))); } if (Plus == null) { Plus = new GUIContent((Texture2D)EditorGUIUtility.Load(SplinePlusEditor.FindAssetPath("Plus.png"))); } if (Minus == null) { Minus = new GUIContent((Texture2D)EditorGUIUtility.Load(SplinePlusEditor.FindAssetPath("Minus.png"))); } if (Delete == null) { Delete = new GUIContent((Texture2D)EditorGUIUtility.Load(SplinePlusEditor.FindAssetPath("Delete.png"))); } if (Return == null) { Return = new GUIContent((Texture2D)EditorGUIUtility.Load(SplinePlusEditor.FindAssetPath("Return.png"))); } if (Ok == null) { Ok = new GUIContent((Texture2D)EditorGUIUtility.Load(SplinePlusEditor.FindAssetPath("Ok.png"))); } System.Reflection.FieldInfo info = typeof(EditorApplication).GetField("globalEventHandler", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); value = (EditorApplication.CallbackFunction)info.GetValue(null); value += Shortcuts; info.SetValue(null, value); EditorUtility.SetDirty(SPData.SplinePlus); }
public void Simple(SPData SPData, SplinePlusEditor SPEditor) { SerializedObject serializedObject = new SerializedObject(SPData.SplinePlus); SerializedProperty FollowersSP = serializedObject.FindProperty("SPData").FindPropertyRelative("Followers"); SPEditor.FollowersList = new ReorderableList(serializedObject, FollowersSP, true, false, true, true); SPEditor.FollowersList.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(new Rect(rect.x, rect.y, rect.width, SplinePlusEditor.ElementHeight), "Simple followers", EditorStyles.boldLabel); }; SPEditor.FollowersList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { serializedObject.Update(); SerializedProperty follower = FollowersSP.GetArrayElementAtIndex(index); DrawFollower(SPData, follower, rect); serializedObject.ApplyModifiedProperties(); }; SPEditor.FollowersList.onAddCallback = (ReorderableList list) => { FollowersSP.serializedObject.Update(); var t = FollowersSP.arraySize; FollowersSP.InsertArrayElementAtIndex(t); FollowersSP.GetArrayElementAtIndex(t).FindPropertyRelative("Show").boolValue = false; FollowersSP.GetArrayElementAtIndex(t).FindPropertyRelative("AnimationEvents").boolValue = true; FollowersSP.GetArrayElementAtIndex(t).FindPropertyRelative("IsActive").boolValue = true; FollowersSP.GetArrayElementAtIndex(t).FindPropertyRelative("FlipDirection").boolValue = false; FollowersSP.GetArrayElementAtIndex(t).FindPropertyRelative("IsForward").boolValue = true; FollowersSP.GetArrayElementAtIndex(t).FindPropertyRelative("_BranchKey").intValue = SPData.DictBranches.Keys.LastOrDefault(); FollowersSP.GetArrayElementAtIndex(t).FindPropertyRelative("Progress").floatValue = 0; FollowersSP.GetArrayElementAtIndex(t).FindPropertyRelative("Speed").floatValue = 2.5f; FollowersSP.GetArrayElementAtIndex(t).FindPropertyRelative("Acceleration").floatValue = 0; FollowersSP.GetArrayElementAtIndex(t).FindPropertyRelative("BrakesForce").floatValue = 2; FollowersSP.GetArrayElementAtIndex(t).FindPropertyRelative("_FollowerAnimation").enumValueIndex = 0; FollowersSP.GetArrayElementAtIndex(t).FindPropertyRelative("Rot").boolValue = true; FollowersSP.GetArrayElementAtIndex(t).FindPropertyRelative("Position").vector3Value = Vector3.zero; FollowersSP.GetArrayElementAtIndex(t).FindPropertyRelative("Rotation").vector3Value = Vector3.zero; FollowersSP.serializedObject.ApplyModifiedProperties(); }; SPEditor.FollowersList.elementHeightCallback = (int index) => { SerializedProperty follower = FollowersSP.GetArrayElementAtIndex(index); if (!follower.FindPropertyRelative("Show").boolValue) { return(SplinePlusEditor.ElementHeight + 2); } var height = (SplinePlusEditor.ElementHeight + SplinePlusEditor.ElementHeightSpace) * 7; return(height); }; SPEditor.FollowersList.onRemoveCallback = (ReorderableList list) => { FollowersSP.DeleteArrayElementAtIndex(list.index); if (FollowerSettingsWind.oldWindw != null) { FollowerSettingsWind.oldWindw.Close(); } FollowersSP.serializedObject.ApplyModifiedProperties(); return; }; }
public void Train(SPData SPData, SplinePlusEditor SPEditor) { SerializedObject serializedObject = new SerializedObject(SPData.SplinePlus); SerializedProperty trainsSP = serializedObject.FindProperty("SPData").FindPropertyRelative("Trains"); SPEditor.TrainsList = new ReorderableList(serializedObject, trainsSP, true, false, true, true); SPEditor.TrainsList.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(new Rect(rect.x, rect.y, rect.width, SplinePlusEditor.ElementHeight), "Trains", EditorStyles.boldLabel); }; SPEditor.TrainsList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { SerializedProperty train = trainsSP.GetArrayElementAtIndex(index); SerializedProperty WagonsSP = train.FindPropertyRelative("Wagons"); //wagons ReorderableList setup // add new wagons ReorderableList to the WagonsList whenever new train is added if (SPEditor.WagonsList.Count <= index) { SPEditor.WagonsList.Add(new ReorderableList(train.serializedObject, WagonsSP, true, false, true, true)); WagonsDraw(SPData, SPEditor, train, index); } var trainExpandContent = (train.FindPropertyRelative("Show").boolValue) ? SplinePlusEditor.Plus : SplinePlusEditor.Minus; if (GUI.Button(new Rect(rect.x, rect.y, 20, SplinePlusEditor.ElementHeight), trainExpandContent, GUIStyle.none)) { train.FindPropertyRelative("Show").boolValue = !train.FindPropertyRelative("Show").boolValue; trainsSP.serializedObject.ApplyModifiedProperties(); } train.FindPropertyRelative("Name").stringValue = EditorGUI.TextField(new Rect(rect.x + 40, rect.y, rect.width - 120, SplinePlusEditor.ElementHeight), train.FindPropertyRelative("Name").stringValue, EditorStyles.boldLabel); if (GUI.Button(new Rect(rect.x + 20, rect.y, 20, SplinePlusEditor.ElementHeight), new GUIContent(SplinePlusEditor.Settings.image, "Follower settings"), GUIStyle.none)) { FollowerSettingsWind wind = (FollowerSettingsWind)EditorWindow.GetWindow(typeof(FollowerSettingsWind), true, "Follower settings", true); wind.Show(); wind.ShowWindow(SPData, train, FollowerSettingsType.Train); } var trainIsActiveContent = (train.FindPropertyRelative("IsActive").boolValue) ? SplinePlusEditor.On : SplinePlusEditor.Off; if (GUI.Button(new Rect(rect.width, rect.y, 40, SplinePlusEditor.ElementHeight), new GUIContent(trainIsActiveContent.image, "Enable/disable train animation"), GUIStyle.none)) { train.FindPropertyRelative("IsActive").boolValue = !train.FindPropertyRelative("IsActive").boolValue; trainsSP.serializedObject.ApplyModifiedProperties(); } if (train.FindPropertyRelative("Show").boolValue) { rect.y = rect.y + SplinePlusEditor.ElementHeight + SplinePlusEditor.ElementHeightSpace; EditorGUI.BeginChangeCheck(); var progress = EditorGUI.FloatField(new Rect(rect.x, rect.y, rect.width - 38, SplinePlusEditor.ElementHeight), "Progress", train.FindPropertyRelative("Progress").floatValue); if (EditorGUI.EndChangeCheck()) { if (progress > SPData.DictBranches[train.FindPropertyRelative("_BranchKey").intValue].BranchDistance) { train.FindPropertyRelative("Progress").floatValue = SPData.DictBranches[train.FindPropertyRelative("_BranchKey").intValue].BranchDistance; trainsSP.serializedObject.ApplyModifiedProperties(); return; } train.FindPropertyRelative("Progress").floatValue = progress; UpdateAllWagons(SPData, train); } rect.y = rect.y + SplinePlusEditor.ElementHeight + SplinePlusEditor.ElementHeightSpace; EditorGUI.BeginChangeCheck(); var speed = EditorGUI.FloatField(new Rect(rect.x, rect.y, rect.width - 38, SplinePlusEditor.ElementHeight), "Speed", train.FindPropertyRelative("Speed").floatValue); if (EditorGUI.EndChangeCheck()) { train.FindPropertyRelative("Speed").floatValue = speed; trainsSP.serializedObject.ApplyModifiedProperties(); } rect.y = rect.y + SplinePlusEditor.ElementHeight + SplinePlusEditor.ElementHeightSpace; EditorGUI.IntField(new Rect(rect.x, rect.y, rect.width - 38, SplinePlusEditor.ElementHeight), "Branch key", train.FindPropertyRelative("_BranchKey").intValue); if (GUI.Button(new Rect(rect.width, rect.y, 20, SplinePlusEditor.ElementHeight), new GUIContent(SplinePlusEditor.Return.image, "Add branch index"), GUIStyle.none)) { serializedObject.Update(); train.FindPropertyRelative("_BranchKey").intValue = SPData.Selections._BranchKey; UpdateAllWagons(SPData, train); } rect.y = rect.y + SplinePlusEditor.ElementHeight + SplinePlusEditor.ElementHeightSpace; SPEditor.WagonsList[index].DoList(new Rect(rect.x, rect.y, rect.width, rect.height)); } }; SPEditor.TrainsList.elementHeightCallback = (int index) => { SerializedProperty train = trainsSP.GetArrayElementAtIndex(index); if (!train.FindPropertyRelative("Show").boolValue) { return(SplinePlusEditor.ElementHeight + 2); } var d = 7; if (train.FindPropertyRelative("Wagons").arraySize == 0) { return((SplinePlusEditor.ElementHeight + SplinePlusEditor.ElementHeightSpace) * (d + 1)); } for (int i = 0; i < train.FindPropertyRelative("Wagons").arraySize; i++) { d += (train.FindPropertyRelative("Wagons").GetArrayElementAtIndex(i).FindPropertyRelative("Show").boolValue) ? 5 : 1; } var height = (SplinePlusEditor.ElementHeight + SplinePlusEditor.ElementHeightSpace) * d; return(height); }; SPEditor.TrainsList.onAddCallback = (ReorderableList list) => { var t = trainsSP.arraySize; trainsSP.InsertArrayElementAtIndex(t); trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("AnimationEvents").boolValue = true; trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("IsForward").boolValue = true; trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("Name").stringValue = "Train name"; trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("Wagons").arraySize = 0; trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("Show").boolValue = true; trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("IsActive").boolValue = true; trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("_BranchKey").intValue = 0; trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("Progress").floatValue = 0; trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("Speed").floatValue = 2.5f; trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("Acceleration").floatValue = 0; trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("BrakesForce").floatValue = 2; trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("_FollowerAnimation").enumValueIndex = 0; trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("Position").vector3Value = Vector3.zero; trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("Rotation").vector3Value = Vector3.zero; trainsSP.serializedObject.ApplyModifiedProperties(); }; SPEditor.TrainsList.onRemoveCallback = (ReorderableList list) => { trainsSP.DeleteArrayElementAtIndex(SPEditor.TrainsList.index); if (FollowerSettingsWind.oldWindw != null) { FollowerSettingsWind.oldWindw.Close(); } trainsSP.serializedObject.ApplyModifiedProperties(); return; }; }
void WagonsDraw(SPData SPData, SplinePlusEditor SPEditor, SerializedProperty train, int i) { var progressList = new List <float>(); SerializedProperty WagonsSP = train.FindPropertyRelative("Wagons"); SPEditor.WagonsList[i].drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { if (index == 0) { progressList = new List <float>(); } SerializedProperty wagon = WagonsSP.GetArrayElementAtIndex(index); progressList.Add(wagon.FindPropertyRelative("Progress").floatValue); DrawWagon(SPData, wagon, rect); }; SPEditor.WagonsList[i].elementHeightCallback = (int index) => { SerializedProperty wagon = WagonsSP.GetArrayElementAtIndex(index); if (!wagon.FindPropertyRelative("Show").boolValue) { return(SplinePlusEditor.ElementHeight + 2); } var height = ((SplinePlusEditor.ElementHeight + SplinePlusEditor.ElementHeightSpace) * 5); return(height); }; SPEditor.WagonsList[i].onAddCallback = (ReorderableList list) => { var t = train.FindPropertyRelative("Wagons").arraySize; train.FindPropertyRelative("Wagons").InsertArrayElementAtIndex(t); train.FindPropertyRelative("Wagons").GetArrayElementAtIndex(t).FindPropertyRelative("IsForward").boolValue = true; train.FindPropertyRelative("Wagons").GetArrayElementAtIndex(t).FindPropertyRelative("Reverse").boolValue = false; train.FindPropertyRelative("Wagons").GetArrayElementAtIndex(t).FindPropertyRelative("Rot").boolValue = true; train.FindPropertyRelative("Wagons").GetArrayElementAtIndex(t).FindPropertyRelative("FlipDirection").boolValue = false; train.FindPropertyRelative("Wagons").GetArrayElementAtIndex(t).FindPropertyRelative("IsActive").boolValue = true; train.FindPropertyRelative("Wagons").GetArrayElementAtIndex(t).FindPropertyRelative("Rot").boolValue = true; WagonsSP.serializedObject.ApplyModifiedProperties(); }; SPEditor.WagonsList[i].onRemoveCallback = (ReorderableList list) => { WagonsSP.DeleteArrayElementAtIndex(list.index); WagonsSP.serializedObject.ApplyModifiedProperties(); return; }; SPEditor.WagonsList[i].onReorderCallback = (ReorderableList list) => { UpdateAllWagons(SPData, train); //progress auto setting when auto spacing is off for (int n = 0; n < train.FindPropertyRelative("Wagons").arraySize; n++) { var wagon = train.FindPropertyRelative("Wagons").GetArrayElementAtIndex(n); wagon.FindPropertyRelative("Progress").floatValue = progressList.Min(); progressList.Remove(progressList.Min()); } }; }
void SceneViewGUI(SPData SPData, SplinePlusEditor splinePlusEditor) { Handles.BeginGUI(); Event e = Event.current; if (e == null) { return; } if (SPData.DictBranches.Count == 0 || SPData.DictBranches.Count == 1 && SPData.DictBranches.FirstOrDefault().Value.Nodes.Count <= 1) { style.fontSize = 15; style.normal.textColor = Color.green; var sceneViewRect = SceneView.currentDrawingSceneView.position; GUI.Label(new Rect((sceneViewRect.width / 2) - 250, (sceneViewRect.height / 2) - 10, 500, 20), "Please press 'shift' on keyboard to start adding nodes", style); } if (GUI.Button(new Rect(10, 30, 30, 30), new GUIContent(SplinePlusEditor.Snap.image, "Snap all nodes and their handles to Unity grid"), GUIStyle.none))//snap { foreach (var branch in SPData.DictBranches) { for (int n = 0; n < branch.Value.Nodes.Count; n++) { if (Camera.current.transform.eulerAngles == new Vector3(0, 0, 0) || Camera.current.transform.eulerAngles == new Vector3(0, 180, 0)) { branch.Value.Nodes[n].Point.position = new Vector3(branch.Value.Nodes[n].Point.position.x, branch.Value.Nodes[n].Point.position.y, SPData.DataParent.transform.position.z); branch.Value.Nodes[n].Point1.position = new Vector3(branch.Value.Nodes[n].Point1.position.x, branch.Value.Nodes[n].Point1.position.y, SPData.DataParent.transform.position.z); } else if (Camera.current.transform.eulerAngles == new Vector3(90, 0, 0) || Camera.current.transform.eulerAngles == new Vector3(270, 0, 0)) { branch.Value.Nodes[n].Point.position = new Vector3(branch.Value.Nodes[n].Point.position.x, SPData.DataParent.transform.position.y, branch.Value.Nodes[n].Point.position.z); branch.Value.Nodes[n].Point1.position = new Vector3(branch.Value.Nodes[n].Point1.position.x, SPData.DataParent.transform.position.y, branch.Value.Nodes[n].Point1.position.z); } else if (Camera.current.transform.eulerAngles == new Vector3(0, 90, 0) || Camera.current.transform.eulerAngles == new Vector3(0, 270, 0)) { branch.Value.Nodes[n].Point.position = new Vector3(SPData.DataParent.transform.position.x, branch.Value.Nodes[n].Point.position.y, branch.Value.Nodes[n].Point.position.z); branch.Value.Nodes[n].Point1.position = new Vector3(SPData.DataParent.transform.position.x, branch.Value.Nodes[n].Point1.position.y, branch.Value.Nodes[n].Point1.position.z); } else { branch.Value.Nodes[n].Point.position = new Vector3(branch.Value.Nodes[n].Point.position.x, SPData.DataParent.transform.position.y, branch.Value.Nodes[n].Point.position.z); branch.Value.Nodes[n].Point1.position = new Vector3(branch.Value.Nodes[n].Point1.position.x, SPData.DataParent.transform.position.y, branch.Value.Nodes[n].Point1.position.z); } branch.Value.Nodes[n].Point2.localPosition = -branch.Value.Nodes[n].Point1.localPosition; } } SPData.SplinePlus.SplineCreationClass.UpdateAllBranches(SPData); } var pivotEditingContent = SPData.IsEditingPivot ? SplinePlusEditor.PivotEditOn : SplinePlusEditor.PivotEditOff; if (GUI.Button(new Rect(42, 30, 30, 30), new GUIContent(pivotEditingContent.image, "Pivot editing"), GUIStyle.none))//Edit { SPData.IsEditingPivot = !SPData.IsEditingPivot; Tools.hidden = SPData.IsEditingPivot ? true : false; } style.fontSize = 10; style.normal.textColor = Color.black; GUI.Label(new Rect(10, 5, 30, 20), "Branch :", style); style.normal.textColor = Color.green; GUI.Label(new Rect(50, 5, 40, 20), ((SPData.DictBranches.Count == 0 || SPData.DictBranches[SPData.Selections._BranchKey].Nodes.Count == 0) || SPData.DictBranches.Count == 0) ? "null" : SPData.Selections._BranchKey.ToString(), style); if (SPData.DictBranches.Count > 0) { if (GUI.Button(new Rect(10, 15, 12, 12), new GUIContent(SplinePlusEditor.Next.image, "Next branch"), GUIStyle.none)) { int nextBranchKey = SPData.DictBranches.FirstOrDefault().Key; foreach (var branch in SPData.DictBranches.Reverse()) { if (SPData.Selections._BranchKey == branch.Key) { SPData.Selections._BranchKey = nextBranchKey; break; } nextBranchKey = branch.Key; } SPData.Selections._BranchKey = nextBranchKey; } if (GUI.Button(new Rect(25, 15, 12, 12), new GUIContent(SplinePlusEditor.Previous.image, "Previous branch"), GUIStyle.none)) { int previousBranchKey = SPData.DictBranches.FirstOrDefault().Key; foreach (var branch in SPData.DictBranches) { if (SPData.Selections._BranchKey == branch.Key) { SPData.Selections._BranchKey = previousBranchKey; break; } previousBranchKey = branch.Key; } SPData.Selections._BranchKey = previousBranchKey; } } style.normal.textColor = Color.black; GUI.Label(new Rect(85, 5, 40, 20), "Node :", style); style.normal.textColor = Color.green; GUI.Label(new Rect(140, 5, 40, 20), ((SPData.DictBranches.Count == 0 || SPData.DictBranches[SPData.Selections._BranchKey].Nodes.Count == 0) || SPData.Selections._PathPoint.Equals(null)) ? "null" : SPData.Selections._LocalNodeIndex.ToString(), style); style.normal.textColor = Color.black; GUI.Label(new Rect(180, 5, 40, 20), "Shared :", style); style.normal.textColor = Color.green; GUI.Label(new Rect(225, 5, 40, 20), ((SPData.DictBranches.Count == 0 || SPData.DictBranches[SPData.Selections._BranchKey].Nodes.Count == 0) || SPData.Selections._PathPoint.Equals(null) || SPData.Selections._SharedPathPointIndex == -1) ? "null" : SPData.Selections._SharedPathPointIndex.ToString(), style); style.normal.textColor = Color.black; GUI.Label(new Rect(270, 5, 50, 20), "Connected branches :", style); style.normal.textColor = Color.green; if ((SPData.Selections._SharedPathPointIndex == -1 || SPData.DictBranches.Count == 0 || SPData.DictBranches[SPData.Selections._BranchKey].Nodes.Count == 0) || SPData.Selections._PathPoint.Equals(null)) { GUI.Label(new Rect(380, 5, 50, 20), "null", style); } else { var array = SPData.SharedNodes[SPData.Selections._SharedPathPointIndex].ConnectedBranches; GUI.Label(new Rect(380, 5, 50, 20), string.Join(" - ", array.Select(i => i.ToString()).ToArray()), style); } if (!SPData.SmoothData.SmoothNode) { BranchEdit(SPData); } if (!SPData.Selections._PathPoint.Equals(null)) { SelectedPathPointGUI(SPData, splinePlusEditor); } Handles.EndGUI(); }
void SelectedPathPointGUI(SPData SPData, SplinePlusEditor splinePlusEditor) { if (GUI.Button(new Rect(76, 30, 30, 30), new GUIContent(SplinePlusEditor.SM.image, "Smooth selected regular-shared node"), GUIStyle.none))//smooth { var branch = SPData.DictBranches[SPData.Selections._BranchKey]; SPData.SmoothData.IsShared = (SPData.Selections._SharedPathPointIndex != -1) ? true : false; if (SPData.SmoothData.IsShared) { SPData.SmoothData.SmoothNode = true; splinePlusEditor.SmoothNodeClass.SmoothSharedPathPoint(SPData); } else { if (branch.Nodes.Count > 2 && SPData.Selections._LocalNodeIndex != 0 && SPData.Selections._LocalNodeIndex != branch.Nodes.Count - 1) { SPData.SmoothData.SmoothNode = true; splinePlusEditor.SmoothNodeClass.SmoothNode(SPData); } } } if (SPData.SmoothData.SmoothNode) { MessageBox(SPData, splinePlusEditor); } if (!SPData.Selections._PathPoint.Equals(null)) { var normalFactor = SPData.Selections._PathPoint.NormalFactor; var speedFactor = SPData.Selections._PathPoint.SpeedFactor; GUIStyle style = new GUIStyle { fontStyle = FontStyle.Italic, fontSize = 10 }; style.normal.textColor = Color.black; EditorGUI.LabelField(new Rect(10, 70, 50, 20), "Type", style); EditorGUI.BeginChangeCheck(); var pathPointType = (NodeType)EditorGUI.EnumPopup(new Rect(60, 70, 160, 20), SPData.Selections._PathPoint._Type); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(SPData.SplinePlus, "Path point type changed"); if (SPData.Selections._SharedPathPointIndex != -1) { var sharedNode = SPData.SharedNodes[SPData.Selections._SharedPathPointIndex]; for (int i = 0; i < sharedNode.ConnectedBranches.Count; i++) { var bInd = sharedNode.ConnectedBranches[i]; var n = SPData.Selections._PathPoint.LocalIndex(SPData, bInd); if (n != -1) { SPData.DictBranches[bInd].Nodes[n]._Type = pathPointType; } } } else { SPData.Selections._PathPoint._Type = pathPointType; } EditorUtility.SetDirty(SPData.SplinePlus); SPData.SplinePlus.SplineCreationClass.UpdateAllBranches(SPData); } GUI.Label(new Rect(10, 90, 50, 20), "Normal", style); normalFactor = (int)GUI.HorizontalSlider(new Rect(60, 90, 115, 20), normalFactor, -180, 180); var normalFactorStr = GUI.TextField(new Rect(180, 90, 40, 15), normalFactor.ToString()); System.Int32.TryParse(normalFactorStr, out normalFactor); if (normalFactor != SPData.Selections._PathPoint.NormalFactor) { SPData.Selections._PathPoint.NormalFactor = normalFactor; if (SPData.Selections._SharedPathPointIndex != -1) { var sharedNode = SPData.SharedNodes[SPData.Selections._SharedPathPointIndex]; for (int i = 0; i < sharedNode.ConnectedBranches.Count; i++) { var branchKey = sharedNode.ConnectedBranches[i]; var localIndex = SPData.Selections._PathPoint.LocalIndex(SPData, branchKey); if (localIndex == -1) { continue; //path point not found on the branch } var node = SPData.DictBranches[branchKey].Nodes[localIndex]; var tangent = (node.Point2.position - node.Point.position).normalized; var t = Vector3.Dot(tangent, SPData.Selections._PathPoint.Tangent); if (t > 0) { node.NormalFactor = normalFactor; } else { node.NormalFactor = -normalFactor; } } } else { SPData.Selections._PathPoint.NormalFactor = normalFactor; } SPData.SplinePlus.SplineCreationClass.UpdateAllBranches(SPData); } if (!SPData.ConstantSpeed) { GUI.Label(new Rect(10, 110, 50, 20), "Speed", style); speedFactor = (int)GUI.HorizontalSlider(new Rect(60, 110, 115, 20), speedFactor, 0, 100); var speedFactorStr = GUI.TextField(new Rect(180, 110, 40, 15), speedFactor.ToString()); System.Int32.TryParse(speedFactorStr, out speedFactor); if (speedFactor != SPData.Selections._PathPoint.SpeedFactor) { speedFactor = Mathf.Clamp(speedFactor, 0, 100); if (SPData.Selections._SharedPathPointIndex != -1) { var sharedNode = SPData.SharedNodes[SPData.Selections._SharedPathPointIndex]; for (int i = 0; i < sharedNode.ConnectedBranches.Count; i++) { var branchKey = sharedNode.ConnectedBranches[i]; var localIndex = SPData.Selections._PathPoint.LocalIndex(SPData, branchKey); if (localIndex == -1) { continue; //path point not found on the branch } SPData.DictBranches[branchKey].Nodes[localIndex].SpeedFactor = speedFactor; } } else { SPData.DictBranches[SPData.Selections._BranchKey].Nodes[SPData.Selections._LocalNodeIndex].SpeedFactor = speedFactor; } SPData.SplinePlus.SplineCreationClass.UpdateAllBranches(SPData); } } } SharedPathPointGUI(SPData); }