AssetBundleGraph.AssetBundleGraphSettings.NodeKindFromString C# (CSharp) Method

NodeKindFromString() public static method

public static NodeKindFromString ( string val ) : NodeKind
val string
return NodeKind
        public static NodeKind NodeKindFromString(string val)
        {
            return (NodeKind)Enum.Parse(typeof(NodeKind), val);
        }

Usage Example

Example #1
0
        /*
         * 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);
        }
All Usage Examples Of AssetBundleGraph.AssetBundleGraphSettings::NodeKindFromString
AssetBundleGraphSettings