Beispiel #1
0
        internal static void ConversionIndexer(CustomObjectIndexerTarget context, ObjectIndexer indexer)
        {
            //Custom finding of all default Material properties on every single object type including custom types
            if (MaterialReferenceBuilder.MaterialReferenceLookup.TryGetValue(context.targetType, out var methods))
            {
                foreach (var method in methods)
                {
                    if (method == null)
                    {
                        continue;
                    }

                    var result = method.GetMaterialFromMethod(context.target, (methodName, objectName) =>
                                                              $"The method {methodName} was not found on {objectName}. This property will not be indexed.");

                    if (result is Material materialResult)
                    {
                        if (materialResult != null && MaterialReferenceBuilder.GetIsReadonlyMaterial(materialResult))
                        {
                            indexer.AddProperty("urp", "convert-readonly", context.documentIndex);
                        }
                    }
                    else if (result is Material[] materialArrayResult)
                    {
                        foreach (var material in materialArrayResult)
                        {
                            if (material != null && MaterialReferenceBuilder.GetIsReadonlyMaterial(material))
                            {
                                indexer.AddProperty("urp", "convert-readonly", context.documentIndex);
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public override void OnRun(ref RunItemContext ctx)
        {
            var obj         = LoadObject(ref ctx);
            var result      = true;
            var errorString = new StringBuilder();

            if (obj != null)
            {
                var materials = MaterialReferenceBuilder.GetMaterialsFromObject(obj);

                foreach (var material in materials)
                {
                    if (material == null)
                    {
                        continue;
                    }
                    // there might be multiple materials on this object, we only care about the ones we explicitly try to remap that fail
                    if (!MaterialReferenceBuilder.GetIsReadonlyMaterial(material))
                    {
                        continue;
                    }
                    if (!ReadonlyMaterialMap.Map.ContainsKey(material.name))
                    {
                        continue;
                    }
                    if (!ReassignMaterial(obj, material.name, ReadonlyMaterialMap.Map[material.name]))
                    {
                        result = false;
                        errorString.AppendLine($"Material {material.name} failed to be reassigned");
                    }
                }
            }
            else
            {
                result = false;
                errorString.AppendLine($"Object {ctx.item.descriptor.name} could not be loaded");
            }

            if (!result)
            {
                ctx.didFail = true;
                ctx.info    = errorString.ToString();
            }
            else
            {
                // make sure the changes get saved
                EditorUtility.SetDirty(obj);
                var currentScene = SceneManager.GetActiveScene();
                EditorSceneManager.SaveScene(currentScene);
            }
        }