Skip to content

Commit

Permalink
Merge pull request #440 from umasteeringgroup/Feature-13
Browse files Browse the repository at this point in the history
Feature 13
  • Loading branch information
Jaimi authored Jun 12, 2024
2 parents ffee966 + 706f6e9 commit bd94a2d
Show file tree
Hide file tree
Showing 19 changed files with 8,218 additions and 7,037 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Shaderpackager-editor",
"rootNamespace": "",
"references": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,17 @@ public void SetRaceLists(RaceData[] raceDataArray = null)
}
}
}
private void CheckRaceDataLists()

float lastTime = 0.0f;
private void CheckRaceDataLists()
{
float currentTime = Time.realtimeSinceStartup;
if (currentTime - lastTime < 5.0f)
{
lastTime = currentTime;
return;
}

if (UMAContext.Instance == null)
{
var raceDatas = UMAAssetIndexer.Instance.GetAllAssets<RaceData>();
Expand All @@ -66,6 +75,8 @@ private void CheckRaceDataLists()
}
}



public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
CheckRaceDataLists();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UMA;
using System;
using UnityEditor.Build.Reporting;
using UnityEditor;
using System.Linq;
using System.IO;

#if UMA_ADDRESSABLES
public class UMAAddressablesBuildSample
{
public static void Build(string destFolder, bool dev, string appName)
{
// Generate the addressables for UMA, and cleanup after it
GenerateUMAAddressables();
UnityEditor.AddressableAssets.Settings.AddressableAssetSettings.BuildPlayerContent(out var result);
UMAPostBuildMaterialUpdate();
// Addressable bundles are built at this point, so we can build the player


BuildReport buildReport = null;
try
{
// Build the player
buildReport = BuildPlayer(destFolder, dev, appName);
if (buildReport == null)
{
Debug.LogError($"UMABuildScript.BuildPlayer Failed");
return;
}
}
catch (Exception e)
{
Debug.LogError($"UMABuildScript.BuildPlayer Failed: {e.Message}");
return;
}
}

private static BuildReport BuildPlayer(string path, bool dev, string AppName)
{
Debug.Log($"Building player to {path}");
// The default is development build with debugging enabled
var buildOptions = BuildOptions.Development | BuildOptions.AllowDebugging;

// if we don't pass true, wea are building a release build
if (!dev)
{
buildOptions = BuildOptions.None;
}

// Include the scenes speicified in the build settings
// and write output to the path chosen by the user

string pathName = $"{path}/{AppName}";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
var buildPlayerOptions = new BuildPlayerOptions()
{
scenes = EditorBuildSettings.scenes.Select(scene => scene.path.ToString()).ToArray(),
locationPathName = pathName,
target = EditorUserBuildSettings.activeBuildTarget,
options = buildOptions
};

if (!dev)
{
Debug.Log("Building Development Player");
}
else
{
Debug.Log("Building Release Player");
}

return BuildPipeline.BuildPlayer(buildPlayerOptions);
}

public static void UMAPostBuildMaterialUpdate()
{
Debug.Log($"UMAPostProcessBuild - Adding UMA resource references");
try
{
UMAAssetIndexer.Instance.PostBuildMaterialFixup();
}
catch (Exception ex)
{
Debug.Log($"UMAPostProcessBuild - Adding UMA resource references failed with exception {ex.Message}");
}
}

public static void GenerateUMAAddressables()
{
// Clear the index, rebuild the type arrays, and then query to project for the indexed types, and
// add everything to the index. Do not add the text assets (only needed if loading characters from resources)
Debug.Log("UMABuildScript - Rebuilding asset index.");
UMA.UMAAssetIndexer assetIndex = UMAAssetIndexer.Instance;
try
{
assetIndex.PrepareBuild();
}
catch (Exception ex)
{
Debug.LogException(ex);
}

// Generate all UMA addressable labels by recipe. Every recipe gets a unique label, so when that
// recipe needs to be loaded, all bundles that contain that item are demand loaded into memory.
// they are unloaded when there is no active character using any of the assets.
Debug.Log($"UMABuildScript - Generating UMA addressable labels.");
UMAAddressablesSupport.Instance.GenerateAddressables(new SingleGroupGenerator { ClearMaterials = true });

// Make sure that the global library has a reference to every item that is not addressable.
// This ensures that they item is included in resources. (Since the items are built dynamically,
// they must be able to be loaded at runtime either through addressable bundles or resources).
Debug.Log($"UMABuildScript - Adding UMA resource references");
assetIndex.AddReferences();
}
}
#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

#if UMA_ADDRESSABLES
public class UMAAddressablesBuildWindow : EditorWindow
{
[MenuItem("UMA/Sample Addressables Build")]
public static void OpenWindow()
{
CreateWindow<UMAAddressablesBuildWindow>()
.Init()
.Show();
}

private static bool dev = true;
private static string appName = "UMASample.exe";

private static string DestinationFolder
{
get => EditorPrefs.GetString("UMABuildPath", $"{Application.dataPath.TrimEnd("/Assets".ToCharArray())}/UMATestBuild");
set => EditorPrefs.SetString("UMABuildPath", value);
}

private static string AppName
{
get => EditorPrefs.GetString("UMAAppName", appName);
set => EditorPrefs.SetString("UMAAppName", value);
}

private UMAAddressablesBuildWindow Init()
{
titleContent = new GUIContent("UMA Build Sample");
return this;
}

private void OnGUI()
{
EditorGUILayout.LabelField("UMA Addressables Build Sample");
EditorGUILayout.Space(20);
dev = EditorGUILayout.Toggle("Development Build", dev);
AppName = EditorGUILayout.TextField("App Name", AppName);
EditorGUILayout.BeginHorizontal();

DestinationFolder = EditorGUILayout.TextField("Build Path", DestinationFolder);
if (GUILayout.Button("Browse"))
{
DestinationFolder = EditorUtility.OpenFolderPanel("Output Folder", DestinationFolder, "");
}
EditorGUILayout.EndHorizontal();

EditorGUILayout.Space(20);
if (GUILayout.Button("Build Addressables"))
{
UMAAddressablesBuildSample.Build(DestinationFolder,dev, AppName);
}
}
}



#endif

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions UMAProject/Assets/UMA/Core/Editor/Scripts/UMAMaterialInspector.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using Unity.Collections.LowLevel.Unsafe;

namespace UMA.Editors
{
Expand Down Expand Up @@ -307,10 +308,16 @@ private void DrawChannelList(SerializedProperty list, UMAMaterial.MaterialType m
EditorGUILayout.PropertyField( materialPropertyName, new GUIContent("Material Property Name", "The name of the property this texture corresponds to in the shader used by this material."), GUILayout.MinWidth(300));
if (_shaderProperties != null)
{
string oldValue = materialPropertyName.stringValue;
int selection = EditorGUILayout.Popup(0, _shaderProperties, GUILayout.MinWidth(100), GUILayout.MaxWidth(200));
if (oldValue != materialPropertyName.stringValue)
{
UpdateCurrentSRP(i, materialPropertyName.stringValue, serializedObject);
}
if (selection > 0)
{
materialPropertyName.stringValue = _shaderProperties[selection];
UpdateCurrentSRP(i, _shaderProperties[selection],serializedObject);
}
}
EditorGUILayout.EndHorizontal();
Expand Down Expand Up @@ -353,6 +360,23 @@ private void DrawChannelList(SerializedProperty list, UMAMaterial.MaterialType m
}
}

private void UpdateCurrentSRP(int i, string v, SerializedObject sobj)
{
// Update the current SRP property name from the array
UMAMaterial source = target as UMAMaterial;
if (source.srpMaterials != null)
{
foreach (UMAMaterial.SRPMaterial srpMaterial in source.srpMaterials)
{
if (srpMaterial.SRP == UMAUtils.CurrentPipeline)
{
srpMaterial.alternateKeywords[i] = v;
sobj.Update();
}
}
}
}

private static string[] FindTexProperties( Shader shader)
{
int count = ShaderUtil.GetPropertyCount(shader);
Expand Down
Loading

0 comments on commit bd94a2d

Please sign in to comment.