コード例 #1
0
        public static string GetComponentName([NotNull] IYamlDocument componentDocument)
        {
            var name = componentDocument.GetUnityObjectPropertyValue(UnityYamlConstants.NameProperty).AsString();

            if (!string.IsNullOrWhiteSpace(name))
            {
                return(name);
            }

            var scriptDocument = componentDocument.GetUnityObjectDocumentFromFileIDProperty(UnityYamlConstants.ScriptProperty);

            name = scriptDocument.GetUnityObjectPropertyValue(UnityYamlConstants.NameProperty).AsString();
            if (!string.IsNullOrWhiteSpace(name))
            {
                return(name);
            }

            var fileID = componentDocument.GetUnityObjectPropertyValue(UnityYamlConstants.ScriptProperty).AsFileID();

            if (fileID != null && fileID.IsExternal && fileID.IsMonoScript)
            {
                var typeElement = GetTypeElementFromScriptAssetGuid(componentDocument.GetSolution(), fileID.guid);
                if (typeElement != null)
                {
                    // TODO: Format like in Unity, by splitting the camel humps
                    return(typeElement.ShortName + " (Script)");
                }
            }

            return(scriptDocument.GetUnityObjectTypeFromRootNode()
                   ?? componentDocument.GetUnityObjectTypeFromRootNode()
                   ?? "Component");
        }
コード例 #2
0
        private FileID GetPrefabInstanceFileId(IYamlDocument document)
        {
            if (myVersion.GetActualVersionForSolution().Major == 2017)
            {
                return(document.GetUnityObjectPropertyValue(UnityYamlConstants.PrefabInstanceProperty2017)?.AsFileID());
            }

            return(document.GetUnityObjectPropertyValue(UnityYamlConstants.PrefabInstanceProperty)?.AsFileID() ??
                   document.GetUnityObjectPropertyValue(UnityYamlConstants.PrefabInstanceProperty2017)?.AsFileID());
        }
コード例 #3
0
        private FileID GetCorrespondingSourceObjectFileId(IYamlDocument document)
        {
            if (myVersion.GetActualVersionForSolution().Major == 2017)
            {
                return(document.GetUnityObjectPropertyValue(UnityYamlConstants.CorrespondingSourceObjectProperty2017)?.AsFileID());
            }

            return(document.GetUnityObjectPropertyValue(UnityYamlConstants.CorrespondingSourceObjectProperty)?.AsFileID() ??
                   document.GetUnityObjectPropertyValue(UnityYamlConstants.CorrespondingSourceObjectProperty2017)?.AsFileID());
        }
コード例 #4
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);
        }
コード例 #5
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));
        }
コード例 #6
0
        public void ConsumeGameObject(IYamlDocument gameObject, IBlockMappingNode modifications)
        {
            string name = null;

            if (modifications != null)
            {
                var documentId = gameObject.GetFileId();
                name = UnityObjectPsiUtil.GetValueFromModifications(modifications, documentId, UnityYamlConstants.NameProperty);
            }
            if (name == null)
            {
                name = gameObject.GetUnityObjectPropertyValue(UnityYamlConstants.NameProperty).AsString();
            }

            if (name?.Equals(string.Empty) == true)
            {
                name = null;
            }
            NameParts.Add(name ?? "Unknown");
        }
コード例 #7
0
 public static IBlockMappingNode GetPrefabModification(IYamlDocument yamlDocument)
 {
     // Prefab instance has a map of modifications, that stores delta of instance and prefab
     return(yamlDocument.GetUnityObjectPropertyValue(UnityYamlConstants.ModificationProperty) as IBlockMappingNode);
 }