コード例 #1
0
 // Pass:
 //   randomSeed -
 //     A seed string that helps uniquify the generated material names.
 //     This must be different for each imported model that generates materials.
 public ImportMaterialCollector(string assetLocation, string uniqueSeed)
 {
     m_guidNamespace = GuidUtils.Uuid5(Guid.Empty, uniqueSeed);
     m_AssetLocation = assetLocation;
 }
コード例 #2
0
ファイル: ToolkitUtils.cs プロジェクト: sw0817/open-brush
        // Appends to collectedAssets
        static void ExportToToolkit_Environment(
            Environment environment,
            string targetDirectory,
            HashSet <string> collectedAssets)
        {
            // make an environment
            var name     = environment.name;
            var settings = environment.m_RenderSettings;

            EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single);

            var prefab = AssetDatabase.LoadAssetAtPath <GameObject>(
                "Assets/Resources/" + settings.m_EnvironmentPrefab + ".prefab");

            PrefabUtility.InstantiatePrefab(prefab);

            RenderSettings.ambientSkyColor       = settings.m_AmbientColor;
            RenderSettings.fogColor              = settings.m_FogColor;
            RenderSettings.reflectionIntensity   = settings.m_ReflectionIntensity;
            RenderSettings.defaultReflectionMode = UnityEngine.Rendering.DefaultReflectionMode.Custom;

            RenderSettings.fog              = settings.m_FogEnabled;
            RenderSettings.fogMode          = settings.m_FogMode;
            RenderSettings.fogDensity       = settings.m_FogDensity;
            RenderSettings.fogStartDistance = settings.m_FogStartDistance;
            RenderSettings.fogEndDistance   = settings.m_FogEndDistance;

            // Lights
            Object.DestroyImmediate(Object.FindObjectOfType <Light>());
            for (int li = 0; li < environment.m_Lights.Count; li++)
            {
                var lsettings = environment.m_Lights[li];
                var light     = new GameObject("Light " + li, typeof(Light)).GetComponent <Light>();
                light.transform.position = lsettings.m_Position;
                light.transform.rotation = lsettings.m_Rotation;
                light.color     = lsettings.Color;
                light.type      = lsettings.m_Type;
                light.range     = lsettings.m_Range;
                light.spotAngle = lsettings.m_SpotAngle;
                light.intensity = 1.0f;
                light.shadows   = lsettings.m_ShadowsEnabled ? LightShadows.Hard : LightShadows.None;
            }

            // Camera
            var cam = Object.FindObjectOfType <Camera>();

            cam.transform.position = new Vector3(0, 15, 0);
            cam.nearClipPlane      = 0.5f;
            cam.farClipPlane       = 10000.0f;
            cam.fieldOfView        = 60;
            cam.clearFlags         = CameraClearFlags.Skybox;
            cam.backgroundColor    = settings.m_ClearColor;


            RenderSettings.customReflection = settings.m_ReflectionCubemap;
            if (settings.m_SkyboxCubemap)
            {
                Error("These guid shenanigans don't work yet: {0}", name);
                Material skyboxMaterialTmp  = new Material(Shader.Find("Custom/Skybox"));
                Guid     skyboxMaterialGuid = GuidUtils.Uuid5(environment.m_Guid, "skyboxMaterial");
                Material skyboxMaterial     = CreateAssetWithGuid_Incorrect(
                    skyboxMaterialTmp, name + "_Skybox.mat", skyboxMaterialGuid);
                string sbAssetPath = AssetDatabase.GetAssetPath(skyboxMaterial);

                collectedAssets.UnionWith(GetDependencies(sbAssetPath, includeRoot: false));

                string sbFinalPath = targetDirectory + "/" + sbAssetPath;
                CopyAsset(sbAssetPath, sbFinalPath);

                RenderSettings.skybox = skyboxMaterial;
                RenderSettings.skybox.SetColor("_Tint", settings.m_SkyboxTint);
                RenderSettings.skybox.SetFloat("_Exposure", settings.m_SkyboxExposure);
                RenderSettings.skybox.SetTexture("_Tex", settings.m_SkyboxCubemap);
            }
            else
            {
                RenderSettings.skybox = null;
            }

            Lightmapping.realtimeGI = false;
            Lightmapping.bakedGI    = false;

            // Store scene
            var sceneAssetPath = "Assets/Dynamic/" + name + ".unity";
            var sceneFinalPath = targetDirectory + "/Environments/" + Path.GetFileName(sceneAssetPath);

            EditorSceneManager.SaveScene(SceneManager.GetActiveScene(), sceneAssetPath);
            AssetDatabase.ImportAsset(sceneAssetPath, ImportAssetOptions.ForceSynchronousImport);

            CopyAsset(sceneAssetPath, sceneFinalPath);
            collectedAssets.UnionWith(GetDependencies(sceneAssetPath, includeRoot: false));
            SetFileGuid_Incorrect(sceneFinalPath, environment.m_Guid);

            AssetDatabase.DeleteAsset(sceneAssetPath);

            EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects);
        }
コード例 #3
0
 public Guid MakeDeterministicUniqueName(int data, string data2)
 {
     return(GuidUtils.Uuid5(m_guidNamespace, string.Format("{0}_{1}", data, data2)));
 }
コード例 #4
0
ファイル: ToolkitUtils.cs プロジェクト: sw0817/open-brush
        // Directly creates some assets in the target tree, and appends other assets
        // to collectedAssets for later copying.
        //
        // Assets which are directly created in the target:
        //               --- asset ---                            --- .meta guid ---
        //   <target>/Assets/Brushes/Basic/<name>/<name>.mat      desc.m_Guid.ToString("N")
        //   <target>/Assets/Brushes/Basic/<name>/<name>.asset    Uuid5(desc.m_Guid, 'tbt-asset'), unity-style
        //
        // - .mat guids are serialized as .ToString("N")
        // - Pre-M14 .asset guids are random and generated by Unity (RFC 4122 type 4)
        // - M14+ .asset guids are generated deterministically (RFC 4122 type 5), and
        //   we copy Unity's wacky serialization format so it's more-feasible to determine
        //   which is which, should we ever need to.  But maybe we should bite the bullet
        //   and make them all type 5? (which may annoy a small number of people trying
        //   to upgrade TBT in a pre-existing project because of the .meta change)
        static void ExportToToolkit_Brush(
            BrushDescriptor descriptor,
            string targetDirectory,
            HashSet <string> collectedAssets)
        {
            if (descriptor.name.StartsWith("Pbr"))
            {
                Debug.LogFormat("Skipping {0}: we don't know how to handle pbr in TBT yet", descriptor.name);
                return;
            }
            if (descriptor.name.StartsWith("EnvironmentDiffuse"))
            {
                Debug.LogFormat("Skipping {0}: we don't need these EnvironmentDiffuse things in TBT", descriptor.name);
                return;
            }

            string containerDirectory = Path.Combine(targetDirectory, GetSubdirForBrush(descriptor));
            string assetName          = GetCreatedAssetNameForBrush(descriptor);

            // Create material and store its dependencies
            string desiredFilename   = assetName + ".mat";
            string materialFinalPath = containerDirectory + "/" + desiredFilename;

            string materialAssetPath = AssetDatabase.GetAssetPath(descriptor.Material);

            collectedAssets.UnionWith(GetDependencies(materialAssetPath, includeRoot: false));

            // Steal the brush's TB guid to use as a Unity guid.
            Guid materialGuid = descriptor.m_Guid;

            CopyAsset(materialAssetPath, materialFinalPath, adjustName: true);
            SetFileGuid_Incorrect(materialFinalPath, descriptor.m_Guid);

            // Create a brush descriptor
            string targetPath = Path.Combine(containerDirectory, assetName + ".asset");
            string meta;
            string yaml = ToolkitBrushDescriptor.CreateAndSerialize(
                descriptor, materialGuid, assetName, out meta);

            File.WriteAllText(targetPath, yaml);

            string targetMetaPath = targetPath + ".meta";

            if (!File.Exists(targetMetaPath))
            {
                Warning("New brush {0}: Uncomment and run BrushManifest.MenuItem_UpdateManifest() in TBT",
                        descriptor.m_DurableName);
            }
            else
            {
                // Revert spurious timestamp changes
                var match = Regex.Match(File.ReadAllText(targetMetaPath), @"timeCreated: \d+");
                if (match.Success)
                {
                    meta = Regex.Replace(meta, @"timeCreated: \d+", match.Groups[0].Value);
                }
            }

            File.WriteAllText(targetMetaPath, meta);
            if (kLegacyBrushGuidToTbtAssetGuidMapping.ContainsKey(descriptor.m_Guid))
            {
                // Legacy: for pre-M14 brushes that were created with random .meta guids
                SetFileGuid_String(targetPath, kLegacyBrushGuidToTbtAssetGuidMapping[descriptor.m_Guid]);
            }
            else
            {
                Guid brushAssetGuid = GuidUtils.Uuid5(descriptor.m_Guid, "tbt-asset");
                SetFileGuid_Correct(targetPath, brushAssetGuid);
            }
        }