static void MenuFunc(object t) { Type _t = t as Type; object obj = System.Activator.CreateInstance(_t); Node node = obj as Node; if (node != null) { node.editorPos = pos; node.modifier = CameraForgeWindow.controller; if (!(node is OutputNode)) { CameraForgeWindow.controller.AddNode(node); } } PoseNode posenode = obj as PoseNode; if (posenode != null) { posenode.editorPos = pos; posenode.controller = CameraForgeWindow.controller; if (!(posenode is FinalPose)) { CameraForgeWindow.controller.AddPoseNode(posenode); } } }
public void Read(BinaryReader br) { mHead.Read(br); int nvec = mHead.vecNum; if (nvec > 0) { mVec = new VEC[nvec]; br.BaseStream.Seek(mHead.vecOffs, SeekOrigin.Begin); for (int i = 0; i < nvec; ++i) { mVec[i].Read(br); } } int nnode = mHead.nodeNum; mNode = new PoseNode[nnode]; for (int i = 0; i < nnode; ++i) { br.BaseStream.Seek(mHead.nodeOffs + (i * 0x1C), SeekOrigin.Begin); mNode[i] = new PoseNode(this); mNode[i].Read(br); } int npose = mHead.poseNum; mPoseSize = new uint[npose]; br.BaseStream.Seek(mHead.sizeOffs, SeekOrigin.Begin); for (int i = 0; i < npose; ++i) { mPoseSize[i] = br.ReadUInt32(); } mPoseTop = br.BaseStream.Position; }
static void DrawPoseNode(PoseNode node, int index) { Vector2 nodepos = Node2Content(node.editorPos); Rect rct = new Rect(nodepos.x, nodepos.y, 30, 30); string type_name = node.GetType().Name; string window_name = type_name; if (node is FinalPose) { window_name = "Final Pose"; } else if (node is HistoryPose) { window_name = "History Pose"; } else if (node is Modifier) { window_name = (node as Modifier).Name.value.value_str; } else if (node is PoseBlend) { window_name = (node as PoseBlend).Name.value.value_str; } rct = GUILayout.Window(poseStartID + index, rct, NodeWindowFunc, window_name); if (index >= 0 && index < controller.posenodes.Count) { posenodeRects[index] = rct; } if (!CameraForgeWindow.opening) { node.editorPos = Content2Node(rct.position); } }
public static void PopupDelete(Vector2 position, Node _del_node, PoseNode _del_pose_node) { if (!inited) { Init(); } del_node = _del_node; del_pose_node = _del_pose_node; delete_menu.DropDown(new Rect(position.x, position.y, 0, 0)); }
static Color NodeColor(PoseNode posenode) { if (posenode is Modifier) { return((posenode as Modifier).Col.value.value_c); } else if (posenode is ScriptModifier) { return((posenode as ScriptModifier).Col.value.value_c); } else if (posenode is MediaPoseNode) { return(Color.white); } else if (posenode is PoseBlend) { return(Color.white); } else { return(Color.white); } }
static void Init() { menu = new GenericMenu(); Assembly asm = Assembly.GetAssembly(typeof(Node)); Type[] types = asm.GetTypes(); List <MenuTypeDesc> menu_types = new List <MenuTypeDesc> (); foreach (Type t in types) { object[] attrs = t.GetCustomAttributes(false); if (attrs != null && attrs.Length > 0) { MenuAttribute attr = attrs[0] as MenuAttribute; if (attr != null) { MenuTypeDesc desc = new MenuTypeDesc(); desc.name = attr.Name; desc.order = attr.Order; desc.type = t; menu_types.Add(desc); } } } menu_types.Sort(MenuTypeDesc.Compare); foreach (MenuTypeDesc desc in menu_types) { Type t = desc.type; if (!t.IsSubclassOf(typeof(OutputNode))) { menu.AddItem(new GUIContent("Add Node/" + desc.name), false, MenuFunc, t); } } foreach (Type t in types) { if (t.IsAbstract) { continue; } if (t.IsSubclassOf(typeof(MediaPoseNode))) { menu.AddItem(new GUIContent("Add Pose Node/Variable/" + t.Name), false, MenuFunc, t); } else if (t == typeof(Modifier)) { menu.AddItem(new GUIContent("Add Modifier"), false, MenuFunc, t); } else if (t.IsSubclassOf(typeof(ScriptModifier))) { menu.AddItem(new GUIContent("Add Script Modifier/" + t.Name), false, MenuFunc, t); } else if (t.IsSubclassOf(typeof(PoseNode)) && t != typeof(FinalPose) && t != typeof(Controller)) { menu.AddItem(new GUIContent("Add Pose Node/" + t.Name), false, MenuFunc, t); } } delete_menu = new GenericMenu(); delete_menu.AddItem(new GUIContent("Delete"), false, () => { if (del_node != null) { CameraForgeWindow.controller.DeleteNode(del_node); } else if (del_pose_node != null) { CameraForgeWindow.controller.DeletePoseNode(del_pose_node); } del_node = null; del_pose_node = null; }); inited = true; }
static void PoseNodeWindow(int windowID) { PoseNode posenode = null; if (windowID < controller.posenodes.Count) { posenode = controller.posenodes[windowID]; } else { posenode = controller.final; } if (posenode == null) { GUI.DragWindow(); return; } // Delete this posenode if (draggingSlot == null && editingSlot == null && Event.current != null && Event.current.type == EventType.mouseDown) { if (Event.current.button == 1 && Event.current.mousePosition.y < 16) { ControllerEditorMenu.PopupDelete(Event.current.mousePosition, null, posenode); } } // Multiple-click this posenode if (draggingSlot == null && editingSlot == null && Event.current != null && Event.current.type == EventType.mouseDown) { if (Event.current.button == 0 && Event.current.clickCount == 2 && Event.current.mousePosition.y < 16) { if (posenode is Modifier) { CameraForgeWindow.nextCurrent = posenode; mouseDown = false; } } } GUILayout.BeginHorizontal(GUILayout.MinHeight(10)); if (posenode.slots.Length + posenode.poseslots.Length > 0) { GUILayout.BeginVertical(); GUILayout.Space(1); for (int i = 0; i < posenode.slots.Length; ++i) { //GUILayout.Space(-1); Rect rct = EditorGUILayout.BeginHorizontal(); GUI.color = posenode.slots[i].input == null ? new Color(1, 1, 1, 0.2f) : Color.white; if (posenode.slots[i].name == "Name" || posenode.slots[i].name == "Count") { GUI.color = Color.clear; } GUILayout.Label(posenode.slots[i].input == null ? cfwindow.texInputSlot : cfwindow.texInputSlotActive); GUI.color = Color.white; EditorGUILayout.EndHorizontal(); GUILayout.Space(-3); // Draw "drag slot area" GUIStyle gs = new GUIStyle(); gs.normal.background = cfwindow.texInputSlot; gs.hover.background = cfwindow.texInputSlot; gs.active.background = cfwindow.texInputSlot; rct.x += 2; rct.y += 1; rct.width = 16; rct.height = 16; Color c = NodeColor(posenode); c.a = 0.7f; GUI.color = c; if (posenode.slots[i].name != "Name" && posenode.slots[i].name != "Count") { if (Event.current != null && rct.Contains(Event.current.mousePosition)) { GUI.Label(rct, "", gs); // Begin drag slot if (Event.current.type == EventType.MouseDown) { if (Event.current.button == 0) { draggingSlot = posenode.slots[i]; draggingSlotIndex = i; draggingSlot.input = null; dragSlotExcludeNode = null; dragPoseSlotExcludeNode = posenode; } } } } GUI.color = Color.white; } for (int i = 0; i < posenode.poseslots.Length; ++i) { //GUILayout.Space(-1); Rect rct = EditorGUILayout.BeginHorizontal(); GUI.color = posenode.poseslots[i].input == null ? new Color(1, 1, 1, 0.2f) : Color.white; GUILayout.Label(posenode.poseslots[i].input == null ? cfwindow.texInputSlot : cfwindow.texInputSlotActive); GUI.color = Color.white; EditorGUILayout.EndHorizontal(); GUILayout.Space(-3); // Draw "drag slot area" GUIStyle gs = new GUIStyle(); gs.normal.background = cfwindow.texInputSlot; gs.hover.background = cfwindow.texInputSlot; gs.active.background = cfwindow.texInputSlot; rct.x += 2; rct.y += 1; rct.width = 16; rct.height = 16; Color c = NodeColor(posenode); c.a = 0.7f; GUI.color = c; if (Event.current != null && rct.Contains(Event.current.mousePosition)) { GUI.Label(rct, "", gs); // Begin drag slot if (Event.current.type == EventType.MouseDown) { if (Event.current.button == 0) { draggingPoseSlot = posenode.poseslots[i]; draggingPoseSlotIndex = i; draggingPoseSlot.input = null; dragSlotExcludeNode = null; dragPoseSlotExcludeNode = posenode; } } } GUI.color = Color.white; } GUILayout.Space(3); GUILayout.EndVertical(); Rect nameRect = EditorGUILayout.BeginVertical(GUILayout.MinWidth(30), GUILayout.MaxWidth(200)); GUILayout.Space(2); for (int i = 0; i < posenode.slots.Length; ++i) { if (posenode.slots[i] == editingSlot) { GUI.color = Color.clear; } GUILayout.Label(posenode.slots[i].name); GUI.color = Color.white; } for (int i = 0; i < posenode.poseslots.Length; ++i) { GUILayout.Label(posenode.poseslots[i].name); } EditorGUILayout.EndVertical(); GUILayout.BeginVertical(GUILayout.MinWidth(20), GUILayout.MaxWidth(200)); GUILayout.Space(2); for (int i = 0; i < posenode.slots.Length; ++i) { string value = ""; if (!posenode.slots[i].value.isNull) { value = posenode.slots[i].value.ToEditString(false); } Rect rct = EditorGUILayout.BeginHorizontal(); GUIStyle gs = new GUIStyle(EditorStyles.label); gs.alignment = TextAnchor.MiddleRight; gs.padding = new RectOffset(gs.padding.left, 5, gs.padding.top, gs.padding.bottom); Color c = NodeColor(posenode); c.a = 0.25f; if (posenode.slots[i].input != null) { GUI.color = c; GUILayout.Label(value, gs); GUI.color = Color.white; } else { GUIStyle gbs = new GUIStyle(EditorStyles.miniButton); gbs.hover.background = gbs.normal.background; Rect btn_rct = new Rect(rct.xMin - (nameRect.width + 8), rct.yMin, rct.width + (nameRect.width + 8), rct.height - 1); c.a = 0.5f; GUI.color = c; if (!posenode.slots[i].value.isNull) { gbs.normal.background = null; } if (posenode.slots[i] != editingSlot && GUI.Button(btn_rct, "", gbs)) { if (Event.current != null && Event.current.button == 0) { EndEditingSlot(); editingSlot = posenode.slots[i]; editingSlotValue = posenode.slots[i].value.ToEditString(true); if (posenode is PoseBlend) { editingPoseBlend = posenode as PoseBlend; } else { editingPoseBlend = null; } GUI.FocusControl(""); } } GUI.color = Color.white; if (posenode.slots[i].value.isNull) { value = "?"; } if (posenode.slots[i] == editingSlot) { GUI.color = Color.clear; } GUILayout.Label(value, gs); GUI.color = Color.white; if (posenode.slots[i] == editingSlot) { GUIStyle gfs = new GUIStyle(EditorStyles.textField); gfs.alignment = TextAnchor.MiddleRight; gfs.padding = new RectOffset(gfs.padding.left, 5, gfs.padding.top, gfs.padding.bottom); gfs.fontSize = 10; c.a = 1; //GUI.color = c; GUI.SetNextControlName("EditSlot"); editingSlotValue = GUI.TextField(btn_rct, editingSlotValue, gfs); } } EditorGUILayout.EndHorizontal(); } for (int i = 0; i < posenode.poseslots.Length; ++i) { string value = "Camera Pose"; if (posenode is PoseBlend) { value = "Weight = " + (posenode as PoseBlend).GetWeight(i).ToString("0.000000"); } EditorGUILayout.BeginHorizontal(); GUIStyle gs = new GUIStyle(EditorStyles.label); gs.alignment = TextAnchor.MiddleRight; gs.padding = new RectOffset(gs.padding.left, 5, gs.padding.top, gs.padding.bottom); Color c = NodeColor(posenode); c.a = 0.25f; if (posenode.poseslots[i].input != null) { GUI.color = c; GUILayout.Label(value, gs); GUI.color = Color.white; } else { GUI.color = c; GUILayout.Label("Default Pose", gs); GUI.color = Color.white; } EditorGUILayout.EndHorizontal(); } GUILayout.EndVertical(); } else { GUILayout.BeginVertical(GUILayout.MaxWidth(5)); GUILayout.Space(2); GUILayout.EndVertical(); GUILayout.BeginVertical(GUILayout.MaxWidth(5)); GUILayout.Space(2); GUILayout.EndVertical(); GUILayout.BeginVertical(GUILayout.MinWidth(80)); GUILayout.Space(0); Color c = NodeColor(posenode); c.a = 0.25f; GUI.color = c; GUIStyle gs = new GUIStyle(); gs.normal.textColor = Color.white; gs.alignment = TextAnchor.LowerRight; GUILayout.Label("<Empty>", gs); GUI.color = Color.white; GUILayout.Space(1); GUILayout.EndVertical(); } if (!(posenode is FinalPose)) { GUILayout.Space(-13); GUILayout.BeginVertical(); GUILayout.Space(-21); GUI.color = NodeColor(posenode); if (!posenodeOutputs[windowID]) { GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, 0.2f); } if (posenode == dragPoseSlotExcludeNode) { GUI.color = Color.clear; } GUILayout.Label(posenodeOutputs[windowID] ? cfwindow.texOutputSlotActive : cfwindow.texOutputSlot); GUI.color = Color.white; GUILayout.EndVertical(); GUILayout.Space(-7); } else { GUILayout.BeginVertical(); GUILayout.EndVertical(); } GUILayout.EndHorizontal(); if (dragPoseSlotExcludeNode != posenode) { GUI.DragWindow(); } }
// Drag Pose Slot static void DragPoseSlot() { int stncnt = controller.posenodes.Count; // Drag pose slot if (draggingPoseSlot != null && Event.current != null) { for (int n = 0; n < stncnt; ++n) { PoseNode posenode = controller.posenodes[n]; if (posenode == dragPoseSlotExcludeNode) { continue; } // if (dragPoseSlotExcludeNode.IsDependencyOf(node)) // continue; Rect outputRect = posenodeRects[n]; outputRect.xMin = outputRect.xMax - 20; outputRect.yMin = outputRect.yMin - 3; outputRect.width = 24; outputRect.height = 24; bool inRect = outputRect.Contains(Event.current.mousePosition); if (!mouseDown) { if (inRect) { draggingPoseSlot.input = posenode; draggingPoseSlot.value = Pose.Default; } } Color c = NodeColor(posenode); c.a = inRect ? 1.0f : 0.4f; Color.Lerp(c, Color.white, inRect ? 0f : 0.5f); GUI.color = c; GUI.Label(outputRect, cfwindow.texTargetArea); GUI.color = Color.white; } // Dragging , draw line Vector2 thispos = Node2Content(dragPoseSlotExcludeNode.editorPos); thispos.y += (30 + (draggingPoseSlotIndex + dragPoseSlotExcludeNode.slots.Length) * 18); thispos.x += 8; Vector2 targetpos = Event.current.mousePosition; float tgl = Vector2.Distance(targetpos, thispos) * 0.5f; tgl = Mathf.Min(100, tgl); Vector2 thistg = thispos - Vector2.right * tgl; Vector2 targettg = targetpos + Vector2.right * tgl; if (Vector3.Distance(thispos, targetpos) > 8) { Handles.DrawBezier(thispos, targetpos, thistg, targettg, new Color(1, 1, 1, 0.2f), null, 3f); } if (!mouseDown) { draggingPoseSlot = null; draggingPoseSlotIndex = -1; dragSlotExcludeNode = null; dragPoseSlotExcludeNode = null; } } // End 'Drag pose slot' }
// Draw Connection lines static void DrawConnectionLines() { int ncnt = controller.nodes.Count; int stncnt = controller.posenodes.Count; // Draw node line for (int n = 0; n < ncnt; ++n) { Node node = null; node = controller.nodes[n]; if (node == null) { continue; } for (int i = 0; i < node.slots.Length; ++i) { if (node.slots[i].input != null) { for (int k = 0; k < ncnt; ++k) { if (controller.nodes[k] == node.slots[i].input) { nodeOutputs[k] = true; Vector2 thispos = Node2Content(node.editorPos); thispos.y += (30 + i * 18); thispos.x += 8; Vector2 targetpos = new Vector2(nodeRects[k].xMax - 1, nodeRects[k].yMin + 8); DrawBezierCurve(thispos, targetpos, k); break; } } } } } // End 'Draw node line' // Draw posenode line for (int n = 0; n <= stncnt; ++n) { PoseNode posenode = null; if (n < stncnt) { posenode = controller.posenodes[n]; } else { posenode = controller.final; } if (posenode != null) { for (int i = 0; i < posenode.slots.Length; ++i) { if (posenode.slots[i].input != null) { for (int k = 0; k < ncnt; ++k) { if (controller.nodes[k] == posenode.slots[i].input) { nodeOutputs[k] = true; Vector2 thispos = Node2Content(posenode.editorPos); thispos.y += (30 + i * 18); thispos.x += 8; Vector2 targetpos = new Vector2(nodeRects[k].xMax - 1, nodeRects[k].yMin + 8); DrawBezierCurve(thispos, targetpos, k); break; } } } } for (int i = 0; i < posenode.poseslots.Length; ++i) { if (posenode.poseslots[i].input != null) { for (int k = 0; k < stncnt; ++k) { if (controller.posenodes[k] == posenode.poseslots[i].input) { posenodeOutputs[k] = true; Vector2 thispos = Node2Content(posenode.editorPos); thispos.y += (30 + (i + posenode.slots.Length) * 18); thispos.x += 8; Vector2 targetpos = new Vector2(posenodeRects[k].xMax - 1, posenodeRects[k].yMin + 8); DrawBezierCurve(thispos, targetpos, k + poseStartID); break; } } } } } } // End 'Draw posenode line' }
// Init Temp Arrays static void InitTempArrays() { int ncnt = controller.nodes.Count; int stncnt = controller.posenodes.Count; nodeRects = new Rect[ncnt]; nodeOutputs = new bool[ncnt]; posenodeRects = new Rect[stncnt + 1]; posenodeOutputs = new bool[stncnt + 1]; // Collect nodeOutputs for (int n = 0; n < ncnt; ++n) { Node node = null; node = controller.nodes[n]; if (node != null) { for (int i = 0; i < node.slots.Length; ++i) { if (node.slots[i].input != null) { for (int k = 0; k < ncnt; ++k) { if (controller.nodes[k] == node.slots[i].input) { nodeOutputs[k] = true; break; } } } } } } // Collect posenodeOutputs for (int n = 0; n <= stncnt; ++n) { PoseNode posenode = null; if (n < stncnt) { posenode = controller.posenodes[n]; } else { posenode = controller.final; } if (posenode != null) { for (int i = 0; i < posenode.slots.Length; ++i) { if (posenode.slots[i].input != null) { for (int k = 0; k < ncnt; ++k) { if (controller.nodes[k] == posenode.slots[i].input) { nodeOutputs[k] = true; break; } } } } for (int i = 0; i < posenode.poseslots.Length; ++i) { if (posenode.poseslots[i].input != null) { for (int k = 0; k < stncnt; ++k) { if (controller.posenodes[k] == posenode.poseslots[i].input) { posenodeOutputs[k] = true; break; } } } } } } }