コード例 #1
0
        public static IYamlDocument FindTransformComponentForGameObject([CanBeNull] IYamlDocument gameObjectDocument)
        {
            // GameObject:
            //   m_Component:
            //   - component: {fileID: 1234567890}
            //   - component: {fileID: 1234567890}
            //   - component: {fileID: 1234567890}
            // One of these components is the RectTransform(GUI, 2D) or Transform(3D). Most likely the first, but we can't rely on order
            if (gameObjectDocument?.GetUnityObjectPropertyValue("m_Component") is IBlockSequenceNode components)
            {
                var file = (IYamlFile)gameObjectDocument.GetContainingFile();

                foreach (var componentEntry in components.EntriesEnumerable)
                {
                    // - component: {fileID: 1234567890}
                    var componentNode   = componentEntry.Value as IBlockMappingNode;
                    var componentFileID = componentNode?.EntriesEnumerable.FirstOrDefault()?.Content.Value.AsFileID();
                    if (componentFileID != null && !componentFileID.IsNullReference && !componentFileID.IsExternal)
                    {
                        var component     = file.FindDocumentByAnchor(componentFileID.fileID);
                        var componentName = component.GetUnityObjectTypeFromRootNode();
                        if (componentName != null && (componentName.Equals(UnityYamlConstants.RectTransformComponent) || componentName.Equals(UnityYamlConstants.TransformComponent)))
                        {
                            return(component);
                        }
                    }
                }
            }

            return(null);
        }
コード例 #2
0
        public static IYamlDocument GetUnityObjectDocumentFromFileIDProperty([CanBeNull] this IYamlDocument document, string key)
        {
            var fileID = document.GetUnityObjectPropertyValue(key).AsFileID();

            if (fileID == null || fileID.IsNullReference || fileID.IsExternal)
            {
                return(null);
            }

            Assertion.AssertNotNull(document, "document != null");
            var file = (IYamlFile)document.GetContainingFile();

            return(file.FindDocumentByAnchor(fileID.fileID));
        }
コード例 #3
0
        public static IYamlDocument GetTransformFromPrefabInstance(IYamlDocument prefabInstanceDocument)
        {
            // Prefab instance stores it's father in modification map
            var prefabModification = GetPrefabModification(prefabInstanceDocument);

            var fileID = prefabModification?.FindMapEntryBySimpleKey(UnityYamlConstants.TransformParentProperty)?.Content.Value.AsFileID();

            if (fileID == null)
            {
                return(null);
            }

            var file = (IYamlFile)prefabInstanceDocument.GetContainingFile();

            return(file.FindDocumentByAnchor(fileID.fileID));
        }