Skip to content

Commit

Permalink
Fix RewardAssetInfo reference not saving
Browse files Browse the repository at this point in the history
  • Loading branch information
Guerra24 committed May 28, 2024
1 parent 8db2a6d commit e21d978
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 36 deletions.
5 changes: 4 additions & 1 deletion Assets/Editor/Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ public static void BuildRewards()
foreach (var asset in AssetDatabase.GetAssetPathsFromAssetBundle("builtin-rewards"))
{
var rewardAssetInfo = AssetDatabase.LoadAssetAtPath<RewardAssetInfo>(asset);
rewardAssetInfo.Prefab.GetComponent<RewardAsset>().Info = rewardAssetInfo;
var rewardAsset = rewardAssetInfo.Prefab.GetComponent<RewardAsset>();
rewardAsset.Info = rewardAssetInfo;
EditorUtility.SetDirty(rewardAsset);
}
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();

BuildPipeline.BuildAssetBundles("Assets/StreamingAssets", BuildAssetBundleOptions.StrictMode | BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget);
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Rewards/Objects/Box/Box.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,4 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 19d64d4e41648a147ad98e67f6d7d0c4, type: 3}
m_Name:
m_EditorClassIdentifier:
Info: {fileID: 0}
Info: {fileID: 11400000, guid: 84086667b95955b47b82d904da7e06a8, type: 2}
2 changes: 1 addition & 1 deletion Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"com.unity.nuget.newtonsoft-json": "3.2.1",
"com.unity.postprocessing": "3.4.0",
"com.unity.test-framework": "1.4.4",
"com.unity.timeline": "1.8.6",
"com.unity.timeline": "1.8.7",
"com.unity.ugui": "2.0.0",
"com.vrmc.gltf": "https://github.com/vrm-c/UniVRM.git?path=/Assets/UniGLTF#v0.122.0",
"com.vrmc.univrm": "https://github.com/vrm-c/UniVRM.git?path=/Assets/VRM#v0.122.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,47 +38,57 @@ private void OnGUI()
var assets = AssetDatabase.GetAssetPathsFromAssetBundle(bundle);

GUILayout.Label("Assets", EditorStyles.boldLabel);
bool valid = true;
bool valid = true, updatedAssets = false;
foreach (var asset in assets)
{
var rewardAssetInfo = AssetDatabase.LoadAssetAtPath<RewardAssetInfo>(asset);
if (EditorGUILayout.Foldout(true, rewardAssetInfo.AssetName))
if (rewardAssetInfo != null)
{
EditorGUILayout.BeginHorizontal();
GUILayout.Space(16f);
EditorGUILayout.BeginVertical();
if (rewardAssetInfo.Prefab != null)
if (EditorGUILayout.Foldout(true, rewardAssetInfo.AssetName))
{
var hasRewardAsset = rewardAssetInfo.Prefab.TryGetComponent<RewardAsset>(out var rewardAsset);
var hasRigidBody = rewardAssetInfo.Prefab.TryGetComponent<Rigidbody>(out var rigidbody);
var hasComponents = hasRewardAsset && hasRigidBody;
if (!hasComponents)
valid = false;

if (rewardAsset.Info != rewardAssetInfo)
EditorGUILayout.BeginHorizontal();
GUILayout.Space(16f);
EditorGUILayout.BeginVertical();
if (rewardAssetInfo.Prefab != null)
{
rewardAsset.Info = rewardAssetInfo;
AssetDatabase.SaveAssets();
var hasRewardAsset = rewardAssetInfo.Prefab.TryGetComponent<RewardAsset>(out var rewardAsset);
var hasRigidBody = rewardAssetInfo.Prefab.TryGetComponent<Rigidbody>(out var rigidbody);
var hasComponents = hasRewardAsset && hasRigidBody;
if (!hasComponents)
valid = false;

if (rewardAsset.Info != rewardAssetInfo)
{
rewardAsset.Info = rewardAssetInfo;
EditorUtility.SetDirty(rewardAsset);
updatedAssets = true;
}

UnityEditor.Editor.CreateEditor(rewardAssetInfo).OnInspectorGUI();
if (!hasRewardAsset)
GUILayout.Label("Missing RewardAsset component");
if (!hasRigidBody)
GUILayout.Label("Missing RigidBody component");
if (hasComponents)
GUILayout.Label("Reward valid");
}

UnityEditor.Editor.CreateEditor(rewardAssetInfo).OnInspectorGUI();
if (!hasRewardAsset)
GUILayout.Label("Missing RewardAsset component");
if (!hasRigidBody)
GUILayout.Label("Missing RigidBody component");
if (hasComponents)
GUILayout.Label("Reward valid");
}
else
{
valid = false;
GUILayout.Label("Missing Prefab");
else
{
valid = false;
GUILayout.Label("Missing Prefab");
}
EditorGUILayout.EndVertical();
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndVertical();
EditorGUILayout.EndHorizontal();
}
}

if (updatedAssets)
{
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}

GUILayout.Label("Export", EditorStyles.boldLabel);
if (valid)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ namespace AvatarViewer.SDK
{
public class RewardAsset : MonoBehaviour
{
[HideInInspector]
public RewardAssetInfo Info;
[HideInInspector] public RewardAssetInfo Info;

private Rigidbody Rigidbody;
private AudioSource AudioSource;
Expand Down
2 changes: 1 addition & 1 deletion Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
"url": "https://packages.unity.com"
},
"com.unity.timeline": {
"version": "1.8.6",
"version": "1.8.7",
"depth": 0,
"source": "registry",
"dependencies": {
Expand Down

0 comments on commit e21d978

Please sign in to comment.