// =================================================================================================== // Inspector UI // =================================================================================================== public override void OnInspectorGUI() { if (!viewModel.IsPlaying && wasPreview) { // workaround for stupid "getting control 5" exception wasPreview = false; Repaint(); return; } viewModel.ProcessInvalidations(); NPVoxAnimationEditorSession session = ((NPVoxAnimationEditorSession)target); EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Close Editor") || !session.animation) { NPVoxAnimationEditor.CloseAnimationEditor(session); } if (GUILayout.Button("Debug")) { viewModel.DebugButton(); } if (GUILayout.Button("Invalidate & Reimport All")) { NPipelineUtils.InvalidateAndReimportAll(session.animation); } if (GUILayout.Button("Invalidate & Reimport All Deep")) { NPipelineUtils.InvalidateAndReimportAllDeep(session.animation); } if (GUILayout.Button("Help")) { NPVoxAnimHelpWindow.ShowWindow(); } EditorGUILayout.EndHorizontal(); GUILayout.Label("Preview: ", EditorStyles.boldLabel); DrawPreview(); if (!viewModel.IsPlaying) { GUILayout.Space(10); GUILayout.Label("Frames: ", EditorStyles.boldLabel); DrawFrameSelection(); GUILayout.Space(10); DrawModelSelection(); DrawTransformationSelector(); GUILayout.Space(10); GUILayout.Label("Presentation: ", EditorStyles.boldLabel); DrawModeToolbar(); DrawSocketTools(); } else { // Debug.Log("playing"); DrawFrameList(); } DrawMaterialSelection(); session.groundplateOffset = EditorGUILayout.FloatField("Ground Offset", session.groundplateOffset); EditorGUILayout.EndVertical(); if (meshRefreshRequested) { meshRefreshRequested = false; UpdateMeshes(); SceneView.RepaintAll(); } // unfocus by pressing escape Event e = Event.current; if (e.isKey && e.keyCode == KeyCode.Escape) { unfocus(); } // ground plate if (viewModel.SelectedFrame != null && viewModel.SelectedFrame.Source != null && session.groundFilter) { NPVoxModel model = viewModel.SelectedFrame.Source.GetProduct(); NPVoxToUnity n2u = new NPVoxToUnity(model, viewModel.Animation.MeshFactory.VoxelSize); Vector3 pos = n2u.ToUnityPosition(new Vector3(model.BoundingBox.SaveCenter.x, model.BoundingBox.SaveCenter.y, model.BoundingBox.Forward + 1)); session.groundFilter.transform.position = pos + Vector3.forward * session.groundplateOffset; } KeyboardShortcuts(); }
public override void OnInspectorGUI() { GUIStyle boldStyle = new GUIStyle(); boldStyle.fontStyle = FontStyle.Bold; NPVoxAnimation animation = (NPVoxAnimation)target; GUILayout.Label("NPVox Animation: " + animation.name); GUILayout.Label("Tools:"); GUILayout.BeginHorizontal(); if (GUILayout.Button("Invalidate & Reimport All")) { NPipelineUtils.InvalidateAndReimportAll(animation); } if (GUILayout.Button("Invalidate & Reimport All Deep")) { NPipelineUtils.InvalidateAndReimportAllDeep(animation); } GUILayout.EndHorizontal(); if (GUILayout.Button("Edit Animation")) { OpenAnimationScene(animation); } if (animation.Frames != null && animation.Frames.Length > 0 && animation.Frames[0].Source != null) { NPVoxModel model = animation.Frames[0].Source.GetProduct(); if (model != null && model.SocketNames.Length > 0) { EditorGUILayout.BeginHorizontal(); selectedTargetSocket = NPipeGUILayout.Popup(model.SocketNames, model.SocketNames, selectedTargetSocket, true); selectedModelFactory = NPipelineUtils.DrawSourceSelector <NPVoxIModelFactory>("Input:", selectedModelFactory); if (selectedModelFactory != null && selectedModelFactory.GetProduct()) { selectedInputSocket = NPipeGUILayout.Popup(selectedModelFactory.GetProduct().SocketNames, selectedModelFactory.GetProduct().SocketNames, selectedInputSocket, true); } if (GUILayout.Button("Create Slave Animation") && selectedModelFactory != null) { createSlaveAnimation(animation, selectedTargetSocket, selectedModelFactory, selectedInputSocket); } if (GUILayout.Button("Create Slave Animation From Preview") && selectedModelFactory != null) { createSlaveAnimationFromPreview(animation, selectedModelFactory); } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.Space(); EditorGUILayout.Space(); GUILayout.Label("Animation Default Settings", boldStyle); DrawDefaultInspector(); EditorGUILayout.Space(); EditorGUILayout.Space(); // Mesh Output Settings GUILayout.Label("Mesh Output Settings", boldStyle); if (animation.MeshFactory.DrawInspector(~NPipeEditFlags.TOOLS & ~NPipeEditFlags.INPUT)) { // Cascade to all frames foreach (NPVoxFrame frame in animation.Frames) { frame.Output.BloodColorIndex = animation.MeshFactory.BloodColorIndex; frame.Output.Cutout = animation.MeshFactory.Cutout; frame.Output.Loop = animation.MeshFactory.Loop; frame.Output.NormalMode = animation.MeshFactory.NormalMode; frame.Output.NormalVariance = animation.MeshFactory.NormalVariance; frame.Output.NormalVarianceSeed = animation.MeshFactory.NormalVarianceSeed; frame.Output.VoxelSize = animation.MeshFactory.VoxelSize; frame.Output.StorageMode = animation.MeshFactory.StorageMode; frame.Output.MinVertexGroups = animation.MeshFactory.MinVertexGroups; frame.Output.NormalModePerVoxelGroup = animation.MeshFactory.NormalModePerVoxelGroup; } } // Destroy unconnected things NPipeIImportable[] importables = NPipelineUtils.GetImportables(AssetDatabase.GetAssetPath(animation)); foreach (NPipeIImportable importable in importables) { NPipeIImportable prev = NPipelineUtils.FindPreviousOfType <NPVoxIModelFactory>(importable); if ((importable as NPVoxMeshOutput) != animation.MeshFactory && (prev == null || prev == importable)) { Debug.LogWarning("Destroying orphaning importable: " + importable); if (importable is NPipeIComposite) { ((NPipeIComposite)importable).Input = null; } importable.Destroy(); // destroy the product Undo.DestroyObjectImmediate((UnityEngine.Object)importable); } } }
protected bool DrawPipelineElements() { //================================================================================================================================== // setup colors //================================================================================================================================== normalStyle = new GUIStyle((GUIStyle)"helpbox"); normalStyle.normal.textColor = Color.black; normalStyle.fontStyle = FontStyle.Normal; boldStyle = new GUIStyle((GUIStyle)"helpbox"); boldStyle.normal.textColor = Color.black; boldStyle.fontStyle = FontStyle.Bold; thisContainerColor = new Color(0.8f, 1.0f, 0.6f); thisContainerMultiColor = new Color(0.8f, 0.6f, 1.0f); string assetPath = AssetDatabase.GetAssetPath(target); NPipeIImportable[] allImportables = NPipelineUtils.GetByType <NPipeIImportable>(target); NPipeIImportable[] outputPipes = NPipelineUtils.FindOutputPipes(allImportables); //================================================================================================================================== // Tool Buttons (Select Me, Invalidation) //================================================================================================================================== GUILayout.BeginHorizontal(); if (GUILayout.Button("Select Me")) { Selection.objects = this.targets; } GUILayout.BeginHorizontal(); if (GUILayout.Button("Invalidate & Reimport All")) { NPipelineUtils.InvalidateAndReimportAll(targets); } if (GUILayout.Button("Invalidate & Reimport All Deep")) { NPipelineUtils.InvalidateAndReimportAllDeep(targets); } GUILayout.EndHorizontal(); GUILayout.EndHorizontal(); //================================================================================================================================== // Single Instance Mode Only for Lazyness Tool Buttons (Deleta all Payload, Instantiate) //================================================================================================================================== if (!this.isMultiInstance) { if (GUILayout.Button("Delete all Payload")) { UnityEngine.Object[] allObjects = AssetDatabase.LoadAllAssetsAtPath(assetPath); foreach (UnityEngine.Object obj in allObjects) { if (!(obj is NPipeIImportable) && !(obj is NPipeContainer)) { DestroyImmediate(obj, true); } } EditorUtility.SetDirty(target); } foreach (NPipeIImportable imp in allImportables) { if (imp is NPipeIInstantiable && GUILayout.Button("Instantiate " + imp.GetInstanceName() + " (" + imp.GetTypeName() + ")")) { ((NPipeIInstantiable)imp).Instatiate(); } } } //================================================================================================================================== // Draw Pipelines //================================================================================================================================== { GUILayout.Space(10f); // headline GUILayout.Label(string.Format("Pipelines", allImportables.Length), EditorStyles.boldLabel); // pipelines GUILayout.BeginHorizontal(); HashSet <NPipeIImportable> visited = new HashSet <NPipeIImportable>(); foreach (NPipeIImportable iimp in outputPipes) { DrawPipelineElements(assetPath, iimp, visited, false); } GUI.backgroundColor = isMultiInstance ? thisContainerMultiColor : thisContainerColor; if (!isMultiInstance) { GUILayout.BeginHorizontal(); GUILayout.Label("Add: "); { GUILayout.BeginVertical(); foreach (Type factoryType in NPipeReflectionUtil.GetAllTypesWithAttribute(typeof(NPipeStartingAttribute))) { NPipeStartingAttribute attr = (NPipeStartingAttribute)factoryType.GetCustomAttributes(typeof(NPipeStartingAttribute), true)[0]; if (attr.attached && GUILayout.Button(attr.name)) { NPipelineUtils.CreateAttachedPipe(assetPath, factoryType); } } List <System.Type> allTypes = new List <System.Type>(NPipeReflectionUtil.GetAllTypesWithAttribute(typeof(NPipeAppendableAttribute))); List <string> allLabels = new List <string>(); allLabels.Add("Other ..."); foreach (Type factoryType in allTypes) { NPipeAppendableAttribute attr = (NPipeAppendableAttribute)factoryType.GetCustomAttributes(typeof(NPipeAppendableAttribute), true)[0]; allLabels.Add(attr.name); } int selection = EditorGUILayout.Popup(0, allLabels.ToArray()); if (selection > 0) { NPipelineUtils.CreateAttachedPipe(assetPath, allTypes[selection - 1]); } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); } GUILayout.EndHorizontal(); } drawPipeEditor(assetPath); return(false); }