SerializedNodeInfo FillNodeInfos() { var rootNode = new SerializedNodeInfo() { depth = -1, displayName = "", id = 0, children = new List <TreeViewItem>(0) }; if (m_TransformPaths == null || m_TransformPaths.Length < 1) { return(rootNode); } var nodesCount = m_TransformPaths.Length; var nodeInfos = new List <SerializedNodeInfo>(nodesCount - 1); Stack <string> depth = new Stack <string>(nodesCount); string currentPath = String.Empty; // skip the first index as it is the empty root of the gameObject for (int i = 1; i < nodesCount; i++) { var newNode = new SerializedNodeInfo(); newNode.id = i; newNode.path = m_TransformPaths[i]; newNode.getNodeState = GetNodeState; newNode.setNodeState = SetNodeState; var newPath = newNode.path; while (!string.IsNullOrEmpty(currentPath) && !newPath.StartsWith(currentPath + "/", StringComparison.InvariantCulture)) { // we are in a new node, lets unstack until we reach the correct hierarchy var oldParent = depth.Pop(); var index = currentPath.LastIndexOf(oldParent, StringComparison.InvariantCulture); if (index > 0) { index--; } currentPath = currentPath.Remove(index); } var nodeName = newPath; if (!string.IsNullOrEmpty(currentPath)) { nodeName = nodeName.Remove(0, currentPath.Length + 1); } newNode.depth = depth.Count; newNode.displayName = nodeName; depth.Push(nodeName); currentPath = newPath; nodeInfos.Add(newNode); } TreeViewUtility.SetChildParentReferences(nodeInfos.Cast <TreeViewItem>().ToList(), rootNode); return(rootNode); }
bool CheckNodesPaths(SerializedNodeInfo parent) { if (parent.children != null) { foreach (var treeViewItem in parent.children) { var node = (SerializedNodeInfo)treeViewItem; if (!CheckNodesPaths(node)) { return(false); } } } if (parent.m_Path != null) { string path = parent.m_Path.stringValue; return(ArrayUtility.FindIndex(m_TransformPaths, s => s == path) != -1); } return(true); }
SerializedNodeInfo FillNodeInfos() { var rootNode = new SerializedNodeInfo() { depth = -1, displayName = "", id = 0, children = new List <TreeViewItem>(0) }; if (m_TransformPaths == null || m_TransformPaths.Length < 1) { return(rootNode); } var nodesCount = m_TransformPaths.Length; var nodeInfos = new List <SerializedNodeInfo>(nodesCount - 1); // skip the first index as it is the empty root of the gameObject for (int i = 1; i < nodesCount; i++) { var newNode = new SerializedNodeInfo(); newNode.id = i; newNode.path = m_TransformPaths[i]; newNode.getNodeState = GetNodeState; newNode.setNodeState = SetNodeState; newNode.depth = newNode.path.Count(f => f == '/') + 1; int lastIndex = newNode.path.LastIndexOf('/'); lastIndex = lastIndex == -1 ? 0 : lastIndex + 1; newNode.displayName = newNode.path.Substring(lastIndex); nodeInfos.Add(newNode); } TreeViewUtility.SetChildParentReferences(nodeInfos.Cast <TreeViewItem>().ToList(), rootNode); return(rootNode); }
private SerializedNodeInfo FillNodeInfos() { var rootNode = new SerializedNodeInfo() { depth = -1, displayName = "", id = 0, children = new List <TreeViewItem>(0) }; if (m_TransformMask == null || m_TransformMask.arraySize == 0) { return(rootNode); } var nodesCount = m_TransformMask.arraySize; var nodeInfos = new List <SerializedNodeInfo>(nodesCount); string[] paths = new string[nodesCount]; SerializedProperty prop = m_TransformMask.GetArrayElementAtIndex(0); prop.Next(false); for (int i = 1; i < nodesCount; i++) { var newNode = new SerializedNodeInfo(); newNode.id = i; newNode.m_Path = prop.FindPropertyRelative("m_Path"); newNode.m_Weight = prop.FindPropertyRelative("m_Weight"); paths[i] = newNode.m_Path.stringValue; string fullPath = paths[i]; if (m_CanImport) { // in avatar mask inspector UI,everything is enabled. newNode.m_State = SerializedNodeInfo.State.Enabled; } else if (humanTransforms != null) { // Enable only transforms that are not human. Human transforms in this case are handled by muscle curves and cannot be imported. if (ArrayUtility.FindIndex(humanTransforms, s => fullPath == s) == -1) { if (m_TransformPaths != null && ArrayUtility.FindIndex(m_TransformPaths, s => fullPath == s) == -1) { newNode.m_State = SerializedNodeInfo.State.Invalid; } else { newNode.m_State = SerializedNodeInfo.State.Enabled; } } else { newNode.m_State = SerializedNodeInfo.State.Disabled; } } else if (m_TransformPaths != null && ArrayUtility.FindIndex(m_TransformPaths, s => fullPath == s) == -1) { // mask does not map to an existing hierarchy node. It's invalid. newNode.m_State = SerializedNodeInfo.State.Invalid; } else { newNode.m_State = SerializedNodeInfo.State.Enabled; } newNode.depth = fullPath.Count(f => f == '/'); int lastIndex = fullPath.LastIndexOf('/'); lastIndex = lastIndex == -1 ? 0 : lastIndex + 1; newNode.displayName = fullPath.Substring(lastIndex); nodeInfos.Add(newNode); prop.Next(false); } TreeViewUtility.SetChildParentReferences(nodeInfos.Cast <TreeViewItem>().ToList(), rootNode); return(rootNode); }
private SerializedNodeInfo FillNodeInfos() { var rootNode = new SerializedNodeInfo() { depth = -1, displayName = "", id = 0, children = new List <TreeViewItem>(0) }; if (m_TransformMask == null || m_TransformMask.arraySize == 0) { return(rootNode); } var nodesCount = m_TransformMask.arraySize; var nodeInfos = new List <SerializedNodeInfo>(nodesCount); SerializedProperty prop = m_TransformMask.GetArrayElementAtIndex(0); prop.Next(false); Stack <string> depth = new Stack <string>(nodesCount); string currentPath = String.Empty; for (int i = 1; i < nodesCount; i++) { var newNode = new SerializedNodeInfo(); newNode.id = i; newNode.m_Path = prop.FindPropertyRelative("m_Path"); newNode.m_Weight = prop.FindPropertyRelative("m_Weight"); var newPath = newNode.m_Path.stringValue; while (!string.IsNullOrEmpty(currentPath) && !newPath.StartsWith(currentPath + "/")) { // we are in a new node, lets unstack until we reach the correct hierarchy var oldParent = depth.Pop(); var index = currentPath.LastIndexOf(oldParent); if (index > 0) { index--; } currentPath = currentPath.Remove(index); } var nodeName = newPath; if (!string.IsNullOrEmpty(currentPath)) { nodeName = nodeName.Remove(0, currentPath.Length + 1); } if (m_CanImport) { // in avatar mask inspector UI,everything is enabled. newNode.m_State = SerializedNodeInfo.State.Enabled; } else if (humanTransforms != null) { // Enable only transforms that are not human. Human transforms in this case are handled by muscle curves and cannot be imported. if (ArrayUtility.FindIndex(humanTransforms, s => newPath == s) == -1) { if (m_TransformPaths != null && ArrayUtility.FindIndex(m_TransformPaths, s => newPath == s) == -1) { newNode.m_State = SerializedNodeInfo.State.Invalid; } else { newNode.m_State = SerializedNodeInfo.State.Enabled; } } else { newNode.m_State = SerializedNodeInfo.State.Disabled; } } else if (m_TransformPaths != null && ArrayUtility.FindIndex(m_TransformPaths, s => newPath == s) == -1) { // mask does not map to an existing hierarchy node. It's invalid. newNode.m_State = SerializedNodeInfo.State.Invalid; } else { newNode.m_State = SerializedNodeInfo.State.Enabled; } newNode.depth = depth.Count; newNode.displayName = nodeName; depth.Push(nodeName); currentPath = newPath; nodeInfos.Add(newNode); prop.Next(false); } TreeViewUtility.SetChildParentReferences(nodeInfos.Cast <TreeViewItem>().ToList(), rootNode); return(rootNode); }