/* * Checks deserialized Json Data, and make some changes if necessary * Returns original Json Data if there is no change necessary, and returns modified Json Data if there is some changes. */ public static Dictionary <string, object> CreateSafeDecerializedJsonData(Dictionary <string, object> deserializedJsonData) { var changed = false; var allNodesJson = deserializedJsonData[AssetBundleGraphSettings.ASSETBUNDLEGRAPH_DATA_NODES] as List <object>; var sanitizedAllNodesJson = new List <Dictionary <string, object> >(); /* * delete undetectable node. */ foreach (var n in allNodesJson) { var nodeJson = n as Dictionary <string, object>; // copy all key and value to new Node data dictionary. var sanitizedNodeJson = new Dictionary <string, object>(); foreach (var key in nodeJson.Keys) { sanitizedNodeJson[key] = nodeJson[key]; } var kind = AssetBundleGraphSettings.NodeKindFromString(nodeJson[AssetBundleGraphSettings.NODE_KIND] as string); switch (kind) { case AssetBundleGraphSettings.NodeKind.PREFABRICATOR_GUI: break; case AssetBundleGraphSettings.NodeKind.BUNDLIZER_GUI: if (!ValidateNodeJsonDataForBundlizer(ref nodeJson)) { changed = true; continue; } break; case AssetBundleGraphSettings.NodeKind.LOADER_GUI: case AssetBundleGraphSettings.NodeKind.FILTER_GUI: case AssetBundleGraphSettings.NodeKind.IMPORTSETTING_GUI: case AssetBundleGraphSettings.NodeKind.MODIFIER_GUI: case AssetBundleGraphSettings.NodeKind.GROUPING_GUI: case AssetBundleGraphSettings.NodeKind.EXPORTER_GUI: case AssetBundleGraphSettings.NodeKind.BUNDLEBUILDER_GUI: break; default: { var nodeName = nodeJson[AssetBundleGraphSettings.NODE_NAME] as string; Debug.LogError(nodeName + " is defined as unknown kind of node. value:" + kind); break; } } sanitizedAllNodesJson.Add(sanitizedNodeJson); } /* * delete undetectable connection. * erase no start node connection. * erase no end node connection. * erase connection which label does exists in the start node. */ var allConnectionsJson = deserializedJsonData[AssetBundleGraphSettings.ASSETBUNDLEGRAPH_DATA_CONNECTIONS] as List <object>; var sanitizedAllConnectionsJson = new List <Dictionary <string, object> >(); foreach (var c in allConnectionsJson) { var connectionJson = c as Dictionary <string, object>; var connectionLabel = connectionJson[AssetBundleGraphSettings.CONNECTION_LABEL] as string; var fromNodeId = connectionJson[AssetBundleGraphSettings.CONNECTION_FROMNODE] as string; var fromNodePointId = connectionJson[AssetBundleGraphSettings.CONNECTION_FROMNODE_CONPOINT_ID] as string; var toNodeId = connectionJson[AssetBundleGraphSettings.CONNECTION_TONODE] as string; // var toNodePointId = connectionJson[AssetBundleGraphSettings.CONNECTION_TONODE_CONPOINT_ID] as string; // detect start node. var fromNodeCandidates = sanitizedAllNodesJson.Where( node => { var nodeId = node[AssetBundleGraphSettings.NODE_ID] as string; return(nodeId == fromNodeId); } ).ToList(); if (!fromNodeCandidates.Any()) { changed = true; continue; } // start node should contain specific connection point. var candidateNode = fromNodeCandidates[0]; var candidateOutputPointIdsSources = candidateNode[AssetBundleGraphSettings.NODE_OUTPUTPOINT_IDS] as List <object>; var candidateOutputPointIds = new List <string>(); foreach (var candidateOutputPointIdsSource in candidateOutputPointIdsSources) { candidateOutputPointIds.Add(candidateOutputPointIdsSource as string); } if (!candidateOutputPointIdsSources.Contains(fromNodePointId)) { changed = true; continue; } // detect end node. var toNodeCandidates = sanitizedAllNodesJson.Where( node => { var nodeId = node[AssetBundleGraphSettings.NODE_ID] as string; return(nodeId == toNodeId); } ).ToList(); if (!toNodeCandidates.Any()) { changed = true; continue; } // this connection has start node & end node. // detect connectionLabel. var fromNode = fromNodeCandidates[0]; var connectionLabelsSource = fromNode[AssetBundleGraphSettings.NODE_OUTPUTPOINT_LABELS] as List <object>; var connectionLabels = new List <string>(); foreach (var connectionLabelSource in connectionLabelsSource) { connectionLabels.Add(connectionLabelSource as string); } if (!connectionLabels.Contains(connectionLabel)) { changed = true; continue; } sanitizedAllConnectionsJson.Add(connectionJson); } if (changed) { var validatedResultDict = new Dictionary <string, object> { { AssetBundleGraphSettings.ASSETBUNDLEGRAPH_DATA_LASTMODIFIED, DateTime.Now }, { AssetBundleGraphSettings.ASSETBUNDLEGRAPH_DATA_NODES, sanitizedAllNodesJson }, { AssetBundleGraphSettings.ASSETBUNDLEGRAPH_DATA_CONNECTIONS, sanitizedAllConnectionsJson } }; return(validatedResultDict); } return(deserializedJsonData); }
public void FromJsonDictionary(Dictionary <string, object> jsonData) { m_name = jsonData[NODE_NAME] as string; m_id = jsonData[NODE_ID] as string; m_kind = AssetBundleGraphSettings.NodeKindFromString(jsonData[NODE_KIND] as string); m_scriptClassName = string.Empty; m_nodeNeedsRevisit = false; if (jsonData.ContainsKey(NODE_SCRIPT_CLASSNAME)) { m_scriptClassName = jsonData[NODE_SCRIPT_CLASSNAME] as string; } var pos = jsonData[NODE_POS] as Dictionary <string, object>; m_x = (float)Convert.ToDouble(pos[NODE_POS_X]); m_y = (float)Convert.ToDouble(pos[NODE_POS_Y]); var inputs = jsonData[NODE_INPUTPOINTS] as List <object>; var outputs = jsonData[NODE_OUTPUTPOINTS] as List <object>; m_inputPoints = new List <ConnectionPointData>(); m_outputPoints = new List <ConnectionPointData>(); foreach (var obj in inputs) { var pDic = obj as Dictionary <string, object>; m_inputPoints.Add(new ConnectionPointData(pDic, this, true)); } foreach (var obj in outputs) { var pDic = obj as Dictionary <string, object>; m_outputPoints.Add(new ConnectionPointData(pDic, this, false)); } switch (m_kind) { case NodeKind.IMPORTSETTING_GUI: // nothing to do break; case NodeKind.PREFABBUILDER_GUI: { if (jsonData.ContainsKey(NODE_PREFABBUILDER_REPLACEPREFABOPTIONS)) { m_prefabBuilderReplacePrefabOptions = Convert.ToInt32(jsonData[NODE_PREFABBUILDER_REPLACEPREFABOPTIONS]); } if (jsonData.ContainsKey(NODE_SCRIPT_INSTANCE_DATA)) { m_scriptInstanceData = new SerializableMultiTargetString(_SafeGet(jsonData, NODE_SCRIPT_INSTANCE_DATA)); } } break; case NodeKind.MODIFIER_GUI: { if (jsonData.ContainsKey(NODE_SCRIPT_INSTANCE_DATA)) { m_scriptInstanceData = new SerializableMultiTargetString(_SafeGet(jsonData, NODE_SCRIPT_INSTANCE_DATA)); } } break; case NodeKind.LOADER_GUI: { m_loaderLoadPath = new SerializableMultiTargetString(_SafeGet(jsonData, NODE_LOADER_LOAD_PATH)); } break; case NodeKind.FILTER_GUI: { var filters = jsonData[NODE_FILTER] as List <object>; m_filter = new List <FilterEntry>(); for (int i = 0; i < filters.Count; ++i) { var f = filters[i] as Dictionary <string, object>; var keyword = f[NODE_FILTER_KEYWORD] as string; var keytype = f[NODE_FILTER_KEYTYPE] as string; var pointId = f[NODE_FILTER_POINTID] as string; var point = m_outputPoints.Find(p => p.Id == pointId); UnityEngine.Assertions.Assert.IsNotNull(point, "Output point not found for " + keyword); m_filter.Add(new FilterEntry(keyword, keytype, point)); } } break; case NodeKind.GROUPING_GUI: { m_groupingKeyword = new SerializableMultiTargetString(_SafeGet(jsonData, NODE_GROUPING_KEYWORD)); } break; case NodeKind.BUNDLECONFIG_GUI: { m_bundleConfigBundleNameTemplate = new SerializableMultiTargetString(_SafeGet(jsonData, NODE_BUNDLECONFIG_BUNDLENAME_TEMPLATE)); if (jsonData.ContainsKey(NODE_BUNDLECONFIG_USE_GROUPASVARIANTS)) { m_bundleConfigUseGroupAsVariants = Convert.ToBoolean(jsonData[NODE_BUNDLECONFIG_USE_GROUPASVARIANTS]); } m_variants = new List <Variant>(); if (jsonData.ContainsKey(NODE_BUNDLECONFIG_VARIANTS)) { var variants = jsonData[NODE_BUNDLECONFIG_VARIANTS] as List <object>; for (int i = 0; i < variants.Count; ++i) { var v = variants[i] as Dictionary <string, object>; var name = v[NODE_BUNDLECONFIG_VARIANTS_NAME] as string; var pointId = v[NODE_BUNDLECONFIG_VARIANTS_POINTID] as string; var point = m_inputPoints.Find(p => p.Id == pointId); UnityEngine.Assertions.Assert.IsNotNull(point, "Input point not found for " + name); m_variants.Add(new Variant(name, point)); } } } break; case NodeKind.BUNDLEBUILDER_GUI: { m_bundleBuilderEnabledBundleOptions = new SerializableMultiTargetInt(_SafeGet(jsonData, NODE_BUNDLEBUILDER_ENABLEDBUNDLEOPTIONS)); } break; case NodeKind.EXPORTER_GUI: { m_exporterExportPath = new SerializableMultiTargetString(_SafeGet(jsonData, NODE_EXPORTER_EXPORT_PATH)); m_exporterExportOption = new SerializableMultiTargetInt(_SafeGet(jsonData, NODE_EXPORTER_EXPORT_OPTION)); } break; default: throw new ArgumentOutOfRangeException(); } }
public static GraphDescription BuildGraphDescriptionFromJson(Dictionary <string, object> deserializedJsonData) { var nodeIds = new List <string>(); var nodesSource = deserializedJsonData[AssetBundleGraphSettings.ASSETBUNDLEGRAPH_DATA_NODES] as List <object>; var connectionsSource = deserializedJsonData[AssetBundleGraphSettings.ASSETBUNDLEGRAPH_DATA_CONNECTIONS] as List <object>; var allConnections = new List <ConnectionData>(); foreach (var connectionSource in connectionsSource) { var connectionDict = connectionSource as Dictionary <string, object>; var connectionId = connectionDict[AssetBundleGraphSettings.CONNECTION_ID] as string; var connectionLabel = connectionDict[AssetBundleGraphSettings.CONNECTION_LABEL] as string; var fromNodeId = connectionDict[AssetBundleGraphSettings.CONNECTION_FROMNODE] as string; var fromNodeOutputPointId = connectionDict[AssetBundleGraphSettings.CONNECTION_FROMNODE_CONPOINT_ID] as string; var toNodeId = connectionDict[AssetBundleGraphSettings.CONNECTION_TONODE] as string; var toNodeInputPointId = connectionDict[AssetBundleGraphSettings.CONNECTION_TONODE_CONPOINT_ID] as string; allConnections.Add(new ConnectionData(connectionId, connectionLabel, fromNodeId, fromNodeOutputPointId, toNodeId, toNodeInputPointId)); } var allNodes = new List <NodeData>(); foreach (var nodeSource in nodesSource) { var nodeDict = nodeSource as Dictionary <string, object>; var nodeId = nodeDict[AssetBundleGraphSettings.NODE_ID] as string; nodeIds.Add(nodeId); var kindSource = nodeDict[AssetBundleGraphSettings.NODE_KIND] as string; var nodeKind = AssetBundleGraphSettings.NodeKindFromString(kindSource); var nodeName = nodeDict[AssetBundleGraphSettings.NODE_NAME] as string; var nodeOutputPointIdsSources = nodeDict[AssetBundleGraphSettings.NODE_OUTPUTPOINT_IDS] as List <object>; var outputPointIds = new List <string>(); foreach (var nodeOutputPointIdsSource in nodeOutputPointIdsSources) { outputPointIds.Add(nodeOutputPointIdsSource as string); } switch (nodeKind) { case AssetBundleGraphSettings.NodeKind.LOADER_GUI: { var loadPathSource = nodeDict[AssetBundleGraphSettings.NODE_LOADER_LOAD_PATH] as Dictionary <string, object>; var loadPath = new Dictionary <string, string>(); if (loadPathSource == null) { loadPathSource = new Dictionary <string, object>(); } foreach (var platform_package_key in loadPathSource.Keys) { loadPath[platform_package_key] = loadPathSource[platform_package_key] as string; } allNodes.Add( new NodeData( nodeId: nodeId, nodeKind: nodeKind, nodeName: nodeName, outputPointIds: outputPointIds, loadPath: loadPath ) ); break; } case AssetBundleGraphSettings.NodeKind.EXPORTER_GUI: { var exportPathSource = nodeDict[AssetBundleGraphSettings.NODE_EXPORTER_EXPORT_PATH] as Dictionary <string, object>; var exportTo = new Dictionary <string, string>(); if (exportPathSource == null) { exportPathSource = new Dictionary <string, object>(); } foreach (var platform_package_key in exportPathSource.Keys) { exportTo[platform_package_key] = exportPathSource[platform_package_key] as string; } allNodes.Add( new NodeData( nodeId: nodeId, nodeKind: nodeKind, nodeName: nodeName, outputPointIds: outputPointIds, exportTo: exportTo ) ); break; } case AssetBundleGraphSettings.NodeKind.MODIFIER_GUI: case AssetBundleGraphSettings.NodeKind.PREFABRICATOR_GUI: { var scriptClassName = nodeDict[AssetBundleGraphSettings.NODE_SCRIPT_CLASSNAME] as string; allNodes.Add( new NodeData( nodeId: nodeId, nodeKind: nodeKind, nodeName: nodeName, outputPointIds: outputPointIds, scriptClassName: scriptClassName ) ); break; } case AssetBundleGraphSettings.NodeKind.FILTER_GUI: { var containsKeywordsSource = nodeDict[AssetBundleGraphSettings.NODE_FILTER_CONTAINS_KEYWORDS] as List <object>; var filterContainsKeywords = new List <string>(); foreach (var containsKeywordSource in containsKeywordsSource) { filterContainsKeywords.Add(containsKeywordSource.ToString()); } var containsKeytypesSource = nodeDict[AssetBundleGraphSettings.NODE_FILTER_CONTAINS_KEYTYPES] as List <object>; var filterContainsKeytypes = new List <string>(); foreach (var containsKeytypeSource in containsKeytypesSource) { filterContainsKeytypes.Add(containsKeytypeSource.ToString()); } allNodes.Add( new NodeData( nodeId: nodeId, nodeKind: nodeKind, nodeName: nodeName, outputPointIds: outputPointIds, filterContainsKeywords: filterContainsKeywords, filterContainsKeytypes: filterContainsKeytypes ) ); break; } case AssetBundleGraphSettings.NodeKind.IMPORTSETTING_GUI: { var importerPackagesSource = nodeDict[AssetBundleGraphSettings.NODE_IMPORTER_PACKAGES] as Dictionary <string, object>; var importerPackages = new Dictionary <string, string>(); if (importerPackagesSource == null) { importerPackagesSource = new Dictionary <string, object>(); } foreach (var platform_package_key in importerPackagesSource.Keys) { importerPackages[platform_package_key] = string.Empty; } allNodes.Add( new NodeData( nodeId: nodeId, nodeKind: nodeKind, nodeName: nodeName, outputPointIds: outputPointIds, importerPackages: importerPackages ) ); break; } { allNodes.Add( new NodeData( nodeId: nodeId, nodeKind: nodeKind, nodeName: nodeName, outputPointIds: outputPointIds ) ); break; } case AssetBundleGraphSettings.NodeKind.GROUPING_GUI: { var groupingKeywordSource = nodeDict[AssetBundleGraphSettings.NODE_GROUPING_KEYWORD] as Dictionary <string, object>; var groupingKeyword = new Dictionary <string, string>(); if (groupingKeywordSource == null) { groupingKeywordSource = new Dictionary <string, object>(); } foreach (var platform_package_key in groupingKeywordSource.Keys) { groupingKeyword[platform_package_key] = groupingKeywordSource[platform_package_key] as string; } allNodes.Add( new NodeData( nodeId: nodeId, nodeKind: nodeKind, nodeName: nodeName, outputPointIds: outputPointIds, groupingKeyword: groupingKeyword ) ); break; } case AssetBundleGraphSettings.NodeKind.BUNDLIZER_GUI: { var bundleNameTemplateSource = nodeDict[AssetBundleGraphSettings.NODE_BUNDLIZER_BUNDLENAME_TEMPLATE] as Dictionary <string, object>; var bundleNameTemplate = new Dictionary <string, string>(); if (bundleNameTemplateSource == null) { bundleNameTemplateSource = new Dictionary <string, object>(); } foreach (var platform_package_key in bundleNameTemplateSource.Keys) { bundleNameTemplate[platform_package_key] = bundleNameTemplateSource[platform_package_key] as string; } var variantsSource = nodeDict[AssetBundleGraphSettings.NODE_BUNDLIZER_VARIANTS] as Dictionary <string, object>; var variants = new Dictionary <string, string>(); if (variantsSource == null) { variantsSource = new Dictionary <string, object>(); } foreach (var inputPointId in variantsSource.Keys) { variants[inputPointId] = variantsSource[inputPointId] as string; } allNodes.Add( new NodeData( nodeId: nodeId, nodeKind: nodeKind, nodeName: nodeName, outputPointIds: outputPointIds, bundleNameTemplate: bundleNameTemplate, variants: variants ) ); break; } case AssetBundleGraphSettings.NodeKind.BUNDLEBUILDER_GUI: { var enabledBundleOptionsSource = nodeDict[AssetBundleGraphSettings.NODE_BUNDLEBUILDER_ENABLEDBUNDLEOPTIONS] as Dictionary <string, object>; // default is empty. all settings are disabled. var enabledBundleOptions = new Dictionary <string, List <string> >(); if (enabledBundleOptionsSource == null) { enabledBundleOptionsSource = new Dictionary <string, object>(); } foreach (var platform_package_key in enabledBundleOptionsSource.Keys) { enabledBundleOptions[platform_package_key] = new List <string>(); var enabledBundleOptionsListSource = enabledBundleOptionsSource[platform_package_key] as List <object>; // adopt enabled option. foreach (var enabledBundleOption in enabledBundleOptionsListSource) { enabledBundleOptions[platform_package_key].Add(enabledBundleOption as string); } } allNodes.Add( new NodeData( nodeId: nodeId, nodeKind: nodeKind, nodeName: nodeName, outputPointIds: outputPointIds, enabledBundleOptions: enabledBundleOptions ) ); break; } default: { Debug.LogError(nodeName + " is defined as unknown kind of node. value:" + nodeKind); break; } } } /* * collect node's child. for detecting endpoint of relationship. */ var nodeIdListWhichHasChild = new List <string>(); foreach (var connection in allConnections) { nodeIdListWhichHasChild.Add(connection.fromNodeId); } var noChildNodeIds = nodeIds.Except(nodeIdListWhichHasChild).ToList(); /* * adding parentNode id x n into childNode for run up relationship from childNode. */ foreach (var connection in allConnections) { var targetNodes = allNodes.Where(nodeData => nodeData.nodeId == connection.toNodeId).ToList(); foreach (var targetNode in targetNodes) { targetNode.AddConnectionToParent(connection); } } return(new GraphDescription(noChildNodeIds, allNodes, allConnections)); }