コード例 #1
0
        public Dictionary <string, IAssetValue> ToDictionary()
        {
            var dictionary = new Dictionary <string, IAssetValue>();

            dictionary["m_Mode"]            = new AssetSimpleValue(((int)Mode).ToString());
            dictionary["m_MethodName"]      = new AssetSimpleValue(MethodName);
            dictionary["m_MethodNameRange"] = new Int2Value(TextRangeOwnerPsiPersistentIndex.StartOffset, TextRangeOwnerPsiPersistentIndex.EndOffset);
            dictionary["m_Target"]          = new AssetReferenceValue(TargetScriptReference);
            return(dictionary);
        }
コード例 #2
0
        public Dictionary <int, Dictionary <string, IAssetValue> > GetImportedValuesForUnityEvent(LocalReference scriptLocation, JetHashSet <string> allUnityEventNames)
        {
            var result = new Dictionary <int, Dictionary <string, IAssetValue> >();

            foreach (var modification in myPrefabInstanceHierarchy.PrefabModifications)
            {
                if (!(modification.Target is ExternalReference externalReference))
                {
                    continue;
                }

                if (!modification.PropertyPath.Contains("m_PersistentCalls"))
                {
                    continue;
                }

                var location = new LocalReference(Location.OwningPsiPersistentIndex, PrefabsUtil.GetImportedDocumentAnchor(myPrefabInstanceHierarchy.Location.LocalDocumentAnchor, externalReference.LocalDocumentAnchor));
                if (!location.Equals(scriptLocation))
                {
                    continue;
                }

                var parts          = modification.PropertyPath.Split('.');
                var unityEventName = parts[0];
                if (!allUnityEventNames.Contains(unityEventName))
                {
                    continue;
                }

                var dataPart = parts.FirstOrDefault(t => t.StartsWith("data"));
                if (dataPart == null)
                {
                    continue;
                }

                if (!int.TryParse(dataPart.RemoveStart("data[").RemoveEnd("]"), out var index))
                {
                    continue;
                }

                var last = parts.Last();

                if (!result.TryGetValue(index, out var modifications))
                {
                    modifications = new Dictionary <string, IAssetValue>();
                    result[index] = modifications;
                }

                switch (last)
                {
                case "m_Mode" when modification.Value is AssetSimpleValue simpleValue:
                    modifications[last] = simpleValue;
                    break;

                case "m_MethodName" when modification.Value is AssetSimpleValue simpleValue:
                    modifications[last] = simpleValue;
                    modifications["m_MethodNameRange"] = new Int2Value(modification.ValueRange.StartOffset, modification.ValueRange.EndOffset);
                    break;

                case "m_Target" when modification.ObjectReference is IHierarchyReference objectReference:
                    modifications[last] = new AssetReferenceValue(objectReference);
                    break;
                }
            }

            return(result);
        }