Example #1
0
        private IEnumerable <(LocalReference owningScriptLocation, AssetMethodUsages methodData)> GetImportedAssetMethodDataFor(IPsiSourceFile psiSourceFile)
        {
            if (myImportedUnityEventDatas.TryGetValue(psiSourceFile, out var importedUnityEventData))
            {
                foreach (var((location, unityEventName), modifiedEvents) in importedUnityEventData.UnityEventToModifiedIndex)
                {
                    var script = myAssetDocumentHierarchyElementContainer.GetHierarchyElement(location, true) as IScriptComponentHierarchy;
                    Assertion.Assert(script != null, "script != null");
                    var scriptType = AssetUtils.GetTypeElementFromScriptAssetGuid(mySolution, script.ScriptReference.ExternalAssetGuid);
                    var field      = scriptType?.GetMembers().FirstOrDefault(t => t is IField f && AssetUtils.GetAllNamesFor(f).Contains(unityEventName)) as IField;
                    if (field == null)
                    {
                        continue;
                    }

                    var names         = AssetUtils.GetAllNamesFor(field).ToJetHashSet();
                    var modifications = script.ImportUnityEventData(this, names);

                    foreach (var index in modifiedEvents)
                    {
                        Assertion.Assert(index < modifications.Count, "index < modifications.Count");
                        var result = AssetMethodUsages.TryCreateAssetMethodFromModifications(location, unityEventName, modifications[index]);
                        if (result != null)
                        {
                            yield return(location, result);
                        }
                    }
                }
            }
        }
 protected bool Equals(AssetMethodUsages other)
 {
     return(OwnerName == other.OwnerName &&
            MethodName == other.MethodName && Mode == other.Mode && Type == other.Type &&
            Equals(TargetScriptReference, other.TargetScriptReference) && TextRangeOwnerPsiPersistentIndex.Equals(other.TextRangeOwnerPsiPersistentIndex) &&
            TextRangeOwner == other.TextRangeOwner);
 }
Example #3
0
        public static UnityEventData ReadFrom(UnsafeReader reader)
        {
            var name            = reader.ReadString();
            var location        = HierarchyReferenceUtil.ReadLocalReferenceFrom(reader);
            var scriptReference = HierarchyReferenceUtil.ReadExternalReferenceFrom(reader);
            var count           = reader.ReadInt();
            var calls           = new List <AssetMethodUsages>();

            for (int i = 0; i < count; i++)
            {
                calls.Add(AssetMethodUsages.ReadFrom(reader));
            }

            return(new UnityEventData(name, location, scriptReference, calls));
        }
        public static AssetMethodUsages TryCreateAssetMethodFromModifications(LocalReference location, string unityEventName, Dictionary <string, IAssetValue> modifications, AssetMethodUsages source = null)
        {
            string    name;
            TextRange textRange;
            OWORD     textRangeOwner;

            if (!modifications.TryGetValue("m_MethodName", out var nameValue))
            {
                if (source == null)
                {
                    return(null);
                }
                name           = source.MethodName;
                textRange      = source.TextRangeOwnerPsiPersistentIndex;
                textRangeOwner = source.TextRangeOwner;
            }
            else
            {
                name = (nameValue as AssetSimpleValue).NotNull("name != null").SimpleValue;

                var range = (modifications["m_MethodNameRange"] as Int2Value).NotNull("range != null");
                textRange      = new TextRange(range.X, range.Y);
                textRangeOwner = location.OwningPsiPersistentIndex;
            }

            EventHandlerArgumentMode mode;

            if (!modifications.TryGetValue("m_Mode", out var modeValue))
            {
                if (source == null)
                {
                    return(null);
                }
                mode = source.Mode;
            }
            else
            {
                if (!int.TryParse((modeValue as AssetSimpleValue).NotNull("modeValue as AssetSimpleValue != null").SimpleValue, out var modeV))
                {
                    return(null);
                }

                mode = (EventHandlerArgumentMode)modeV;
            }

            IHierarchyReference target;

            if (!modifications.TryGetValue("m_Target", out var referenceValue))
            {
                if (source == null)
                {
                    return(null);
                }
                target = source.TargetScriptReference;
            }
            else
            {
                target = (referenceValue as AssetReferenceValue).NotNull("referenceValue as AssetReferenceValue != null").Reference;
            }

            return(new AssetMethodUsages(unityEventName, name, textRange, textRangeOwner, mode, null, target));
        }