Skip to content

Commit 14e5caa

Browse files
authored
Uni-48541 Fixed warning CA2122 (LinkDemand) (#428)
1 parent d5b6190 commit 14e5caa

File tree

9 files changed

+56
-0
lines changed

9 files changed

+56
-0
lines changed

Packages/com.unity.formats.fbx/Editor/Scripts/ConvertToModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using UnityEngine.Formats.Fbx.Exporter;
66
using System.Runtime.Serialization;
7+
using System.Security.Permissions;
78

89
namespace UnityEditor.Formats.Fbx.Exporter
910
{
@@ -103,6 +104,7 @@ public static ExportSettings ExportSettings {
103104
/// <returns>list of instanced Model Prefabs</returns>
104105
/// <param name="unityGameObjectsToConvert">Unity game objects to convert to Model Prefab instances</param>
105106
/// <param name="path">Path to save Model Prefab; use FbxExportSettings if null</param>
107+
[SecurityPermission(SecurityAction.LinkDemand)]
106108
public static GameObject[] CreateInstantiatedModelPrefab (
107109
GameObject [] unityGameObjectsToConvert)
108110
{
@@ -165,6 +167,7 @@ public static GameObject[] CreateInstantiatedModelPrefab (
165167
/// file under a unique filename. May be null, in which case we use
166168
/// the export settings. Ignored if 'prefabFullPath' is specified.
167169
/// Ignored if 'toConvert' is a prefab asset.</param>
170+
[SecurityPermission(SecurityAction.LinkDemand)]
168171
public static GameObject Convert (
169172
GameObject toConvert,
170173
string fbxDirectoryFullPath = null,
@@ -402,6 +405,7 @@ public static GameObject ApplyOrCreatePrefab(GameObject instance,
402405
/// </summary>
403406
/// <param name="toSetUp">Instance in the scene that we want to link to the fbx asset.</param>
404407
/// <param name="unityMainAsset">Main asset in the FBX.</param>
408+
[SecurityPermission(SecurityAction.LinkDemand)]
405409
public static void SetupFbxPrefab(GameObject toSetUp, GameObject unityMainAsset)
406410
{
407411
if(toSetUp == null)

Packages/com.unity.formats.fbx/Editor/Scripts/ConvertToPrefabEditorWindow.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using UnityEditor.Presets;
55
#endif
66
using System.Linq;
7+
using System.Security.Permissions;
78

89
namespace UnityEditor.Formats.Fbx.Exporter
910
{
@@ -104,6 +105,7 @@ protected bool ExportSetContainsAnimation()
104105
return false;
105106
}
106107

108+
[SecurityPermission(SecurityAction.LinkDemand)]
107109
protected override bool Export()
108110
{
109111
if (string.IsNullOrEmpty(ExportFileName))

Packages/com.unity.formats.fbx/Editor/Scripts/ExportModelEditorWindow.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using UnityEditor.Presets;
55
#endif
66
using System.Linq;
7+
using System.Security.Permissions;
78

89
namespace UnityEditor.Formats.Fbx.Exporter
910
{
@@ -593,6 +594,7 @@ protected virtual void RestoreSettings()
593594
}
594595

595596

597+
[SecurityPermission(SecurityAction.LinkDemand)]
596598
protected override bool Export(){
597599
if (string.IsNullOrEmpty (ExportFileName)) {
598600
Debug.LogError ("FbxExporter: Please specify an fbx filename");

Packages/com.unity.formats.fbx/Editor/Scripts/FbxExportSettings.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class ExportSettingsEditor : UnityEditor.Editor {
3232
const float FieldOffset = 18;
3333
const float BrowseButtonOffset = 5;
3434

35+
[SecurityPermission(SecurityAction.LinkDemand)]
3536
public override void OnInspectorGUI() {
3637
ExportSettings exportSettings = (ExportSettings)target;
3738

@@ -310,6 +311,7 @@ private static string GetMayaLocationFromEnvironmentVariable(string env)
310311
/// <summary>
311312
/// Returns a set of valid vendor folder paths with no trailing '/'
312313
/// </summary>
314+
[SecurityPermission(SecurityAction.LinkDemand)]
313315
private static HashSet<string> GetCustomVendorLocations()
314316
{
315317
HashSet<string> result = null;
@@ -331,6 +333,7 @@ private static HashSet<string> GetCustomVendorLocations()
331333
return result;
332334
}
333335

336+
[SecurityPermission(SecurityAction.LinkDemand)]
334337
private static HashSet<string> GetDefaultVendorLocations()
335338
{
336339
if (Application.platform == RuntimePlatform.WindowsEditor)
@@ -371,6 +374,7 @@ private static HashSet<string> GetDefaultVendorLocations()
371374
/// </summary>
372375
public static List<string> DCCVendorLocations
373376
{
377+
[SecurityPermission(SecurityAction.LinkDemand)]
374378
get
375379
{
376380
HashSet<string> result = GetCustomVendorLocations();
@@ -743,6 +747,7 @@ private static int FindDCCVersion(string AppName)
743747
///
744748
/// If MAYA_LOCATION is set, add this to the list as well.
745749
/// </summary>
750+
[SecurityPermission(SecurityAction.LinkDemand)]
746751
private static void FindDCCInstalls() {
747752
var dccOptionNames = instance.dccOptionNames;
748753
var dccOptionPaths = instance.dccOptionPaths;
@@ -806,6 +811,7 @@ private static void FindDCCInstalls() {
806811
/// <returns>The first valid vendor location</returns>
807812
public static string FirstValidVendorLocation
808813
{
814+
[SecurityPermission(SecurityAction.LinkDemand)]
809815
get
810816
{
811817
List<string> locations = DCCVendorLocations;
@@ -849,6 +855,7 @@ private static string GetMayaExePathFromLocation(string location)
849855
}
850856
}
851857

858+
[SecurityPermission(SecurityAction.LinkDemand)]
852859
public static GUIContent[] GetDCCOptions(){
853860
if (instance.dccOptionNames == null ||
854861
instance.dccOptionNames.Count != instance.dccOptionPaths.Count ||

Packages/com.unity.formats.fbx/Editor/Scripts/FbxExporter.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Runtime.Serialization;
99
using UnityEditor.Formats.Fbx.Exporter.Visitors;
1010
using UnityEditor.Formats.Fbx.Exporter.CustomExtensions;
11+
using System.Security.Permissions;
1112

1213
namespace UnityEditor.Formats.Fbx.Exporter
1314
{
@@ -873,6 +874,7 @@ bool ExportMesh (MeshInfo meshInfo, FbxNode fbxNode)
873874
/// <summary>
874875
/// Export GameObject as a skinned mesh with material, bones, a skin and, a bind pose.
875876
/// </summary>
877+
[SecurityPermission(SecurityAction.LinkDemand)]
876878
protected bool ExportSkinnedMesh (GameObject unityGo, FbxScene fbxScene, FbxNode fbxNode)
877879
{
878880
if(!unityGo || fbxNode == null)
@@ -948,6 +950,7 @@ private Matrix4x4 GetBindPose(
948950
/// Export bones of skinned mesh, if this is a skinned mesh with
949951
/// bones and bind poses.
950952
/// </summary>
953+
[SecurityPermission(SecurityAction.LinkDemand)]
951954
private bool ExportSkeleton (SkinnedMeshRenderer skinnedMesh, FbxScene fbxScene, out Dictionary<SkinnedMeshRenderer, Transform[]> skinnedMeshToBonesMap)
952955
{
953956
skinnedMeshToBonesMap = new Dictionary<SkinnedMeshRenderer, Transform[]> ();
@@ -1285,6 +1288,7 @@ internal bool ExportTransform (UnityEngine.Transform unityTransform, FbxNode fbx
12851288
/// <summary>
12861289
/// if this game object is a model prefab then export with shared components
12871290
/// </summary>
1291+
[SecurityPermission(SecurityAction.LinkDemand)]
12881292
protected bool ExportInstance(GameObject unityGo, FbxNode fbxNode)
12891293
{
12901294
if (!unityGo || fbxNode == null)
@@ -1771,6 +1775,7 @@ protected bool ExportConstraints (GameObject unityGo, FbxScene fbxScene, FbxNode
17711775
/// <summary>
17721776
/// Return set of sample times to cover all keys on animation curves
17731777
/// </summary>
1778+
[SecurityPermission(SecurityAction.LinkDemand)]
17741779
internal static HashSet<float> GetSampleTimes(AnimationCurve[] animCurves, double sampleRate)
17751780
{
17761781
var keyTimes = new HashSet<float>();
@@ -1798,6 +1803,7 @@ internal static HashSet<float> GetSampleTimes(AnimationCurve[] animCurves, doubl
17981803
/// <summary>
17991804
/// Return set of all keys times on animation curves
18001805
/// </summary>
1806+
[SecurityPermission(SecurityAction.LinkDemand)]
18011807
internal static HashSet<float> GetKeyTimes(AnimationCurve[] animCurves)
18021808
{
18031809
var keyTimes = new HashSet<float>();
@@ -1868,6 +1874,7 @@ internal void ExportAnimationKeys (AnimationCurve uniAnimCurve, FbxAnimCurve fbx
18681874
/// <summary>
18691875
/// Export animation curve key samples
18701876
/// </summary>
1877+
[SecurityPermission(SecurityAction.LinkDemand)]
18711878
internal void ExportAnimationSamples (AnimationCurve uniAnimCurve, FbxAnimCurve fbxAnimCurve,
18721879
double sampleRate,
18731880
UnityToMayaConvertSceneHelper convertSceneHelper)
@@ -1964,6 +1971,7 @@ protected FbxProperty GetFbxProperty(FbxNode fbxNode, string fbxPropertyName, Sy
19641971
/// NOTE: This is not used for rotations, because we need to convert from
19651972
/// quaternion to euler and various other stuff.
19661973
/// </summary>
1974+
[SecurityPermission(SecurityAction.LinkDemand)]
19671975
protected void ExportAnimationCurve (FbxNode fbxNode,
19681976
AnimationCurve uniAnimCurve,
19691977
float frameRate,
@@ -2063,6 +2071,7 @@ public float Convert(float value)
20632071
/// <summary>
20642072
/// Export an AnimationClip as a single take
20652073
/// </summary>
2074+
[SecurityPermission(SecurityAction.LinkDemand)]
20662075
protected void ExportAnimationClip (AnimationClip uniAnimClip, GameObject uniRoot, FbxScene fbxScene)
20672076
{
20682077
if (!uniAnimClip || !uniRoot || fbxScene == null) return;
@@ -2229,6 +2238,7 @@ protected void ExportAnimationClip (AnimationClip uniAnimClip, GameObject uniRoo
22292238
/// <param name="dest">Destination, child of the source.</param>
22302239
/// <param name="sampleRate">Sample rate.</param>
22312240
/// <param name="unityCurves">Unity curves.</param>
2241+
[SecurityPermission(SecurityAction.LinkDemand)]
22322242
private void TransferMotion(Transform source, Transform dest, float sampleRate, ref Dictionary<GameObject, List<UnityCurve>> unityCurves){
22332243
// get sample times for curves in dest + source
22342244
// at each sample time, evaluate all 18 transfom anim curves, creating 2 transform matrices
@@ -2457,6 +2467,7 @@ ref Dictionary<GameObject, RotationCurve> rotations
24572467
/// <summary>
24582468
/// Export the Animator component on this game object
24592469
/// </summary>
2470+
[SecurityPermission(SecurityAction.LinkDemand)]
24602471
protected void ExportAnimation (GameObject uniRoot, FbxScene fbxScene)
24612472
{
24622473
if (!uniRoot)
@@ -2641,6 +2652,7 @@ internal int ExportTransformHierarchy(
26412652
/// but components are only exported if explicitly animated. Meshes are not exported.
26422653
/// </summary>
26432654
/// <returns>The number of nodes exported.</returns>
2655+
[SecurityPermission(SecurityAction.LinkDemand)]
26442656
internal int ExportAnimationOnly(
26452657
GameObject unityGO,
26462658
FbxScene fbxScene,
@@ -2942,6 +2954,7 @@ private static int GetObjectToRootDepth(Transform startObject, Transform root){
29422954
/// <returns>The animation only hierarchy count.</returns>
29432955
/// <param name="exportSet">GameObject hierarchies selected for export.</param>
29442956
/// <param name="hierarchyToExportData">Map from GameObject hierarchy to animation export data.</param>
2957+
[SecurityPermission(SecurityAction.LinkDemand)]
29452958
internal int GetAnimOnlyHierarchyCount(Dictionary<GameObject, IExportData> hierarchyToExportData)
29462959
{
29472960
// including any parents of animated objects that are exported
@@ -2960,6 +2973,7 @@ internal int GetAnimOnlyHierarchyCount(Dictionary<GameObject, IExportData> hiera
29602973
return completeExpSet.Count;
29612974
}
29622975

2976+
[SecurityPermission(SecurityAction.LinkDemand)]
29632977
internal static Dictionary<GameObject, IExportData> GetExportData(Object[] objects, IExportOptions exportOptions = null)
29642978
{
29652979
if (exportOptions==null)
@@ -2990,6 +3004,7 @@ internal static Dictionary<GameObject, IExportData> GetExportData(Object[] objec
29903004
return exportData.Count == 0 ? null : exportData;
29913005
}
29923006

3007+
[SecurityPermission(SecurityAction.LinkDemand)]
29933008
internal static IExportData GetExportData(GameObject rootObject, AnimationClip animationClip, IExportOptions exportOptions = null)
29943009
{
29953010
if (exportOptions==null)
@@ -3090,6 +3105,7 @@ internal static IExportData GetExportData(GameObject go, IExportOptions exportOp
30903105
/// Transform components have already been exported.
30913106
/// This function exports the other components and animation.
30923107
/// </summary>
3108+
[SecurityPermission(SecurityAction.LinkDemand)]
30933109
protected bool ExportComponents(FbxScene fbxScene, bool exportAnim = true)
30943110
{
30953111
var animationNodes = new HashSet<GameObject> ();
@@ -3186,6 +3202,7 @@ internal int GetHierarchyCount (HashSet<GameObject> exportSet)
31863202
/// </summary>
31873203
/// <returns>The revised export set</returns>
31883204
/// <param name="unityExportSet">Unity export set.</param>
3205+
[SecurityPermission(SecurityAction.LinkDemand)]
31893206
internal static HashSet<GameObject> RemoveRedundantObjects(IEnumerable<UnityEngine.Object> unityExportSet)
31903207
{
31913208
// basically just remove the descendents from the unity export set
@@ -3296,6 +3313,7 @@ internal enum TransformExportType { Local, Global, Reset };
32963313
///
32973314
/// This refreshes the asset database.
32983315
/// </summary>
3316+
[SecurityPermission(SecurityAction.LinkDemand)]
32993317
internal int ExportAll (
33003318
IEnumerable<UnityEngine.Object> unityExportSet,
33013319
Dictionary<GameObject, IExportData> exportData)
@@ -3927,6 +3945,7 @@ internal static void UnRegisterMeshCallback(GetMeshForObject callback)
39273945
/// This goes through the callback system to find the right mesh and
39283946
/// allow plugins to substitute their own meshes.
39293947
/// </summary>
3948+
[SecurityPermission(SecurityAction.LinkDemand)]
39303949
bool ExportMesh (GameObject gameObject, FbxNode fbxNode)
39313950
{
39323951
// First allow the object-based callbacks to have a hack at it.
@@ -4060,6 +4079,7 @@ private static void OnExport ()
40604079
}
40614080

40624081

4082+
[SecurityPermission(SecurityAction.LinkDemand)]
40634083
public static string ExportObjects(
40644084
string filePath,
40654085
UnityEngine.Object[] objects = null,
@@ -4073,6 +4093,7 @@ public static string ExportObjects(
40734093
/// Export a list of (Game) objects to FBX file.
40744094
/// Use the SaveFile panel to allow user to enter a file name.
40754095
/// <summary>
4096+
[SecurityPermission(SecurityAction.LinkDemand)]
40764097
internal static string ExportObjects (
40774098
string filePath,
40784099
UnityEngine.Object[] objects = null,
@@ -4104,6 +4125,7 @@ internal static string ExportObjects (
41044125
return null;
41054126
}
41064127

4128+
[SecurityPermission(SecurityAction.LinkDemand)]
41074129
public static string ExportObject (
41084130
string filePath,
41094131
UnityEngine.Object root,

Packages/com.unity.formats.fbx/Editor/Scripts/FbxPrefabAutoUpdater.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Runtime.Serialization;
66
using UnityEngine.Formats.Fbx.Exporter;
7+
using System.Security.Permissions;
78

89
namespace UnityEditor.Formats.Fbx.Exporter
910
{
@@ -98,6 +99,7 @@ public static bool IsPrefabAsset(string assetPath) {
9899
///
99100
/// May return a false positive. This is a cheap check.
100101
/// </summary>
102+
[SecurityPermission(SecurityAction.LinkDemand)]
101103
public static bool MayHaveFbxPrefabToFbxAsset(string prefabPath,
102104
string fbxPrefabScriptPath, HashSet<string> fbxImported) {
103105
if(fbxImported == null)
@@ -287,6 +289,7 @@ public static bool OnValidateMenuItem()
287289
/// <summary>
288290
/// Launch the manual update of the linked prefab specified
289291
/// </summary>
292+
[SecurityPermission(SecurityAction.LinkDemand)]
290293
public static void UpdateLinkedPrefab(GameObject prefabOrInstance)
291294
{
292295
// Find the prefab, bail if this is neither a prefab nor an instance.

Packages/com.unity.formats.fbx/Editor/Scripts/FbxPrefabInspector.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using UnityEngine;
22
using UnityEditor;
33
using UnityEngine.Formats.Fbx.Exporter;
4+
using System.Security.Permissions;
45

56
namespace UnityEditor.Formats.Fbx.Exporter {
67

78
[CustomEditor(typeof(FbxPrefab))]
89
public class FbxPrefabInspector : UnityEditor.Editor {
10+
[SecurityPermission(SecurityAction.LinkDemand)]
911
public override void OnInspectorGUI() {
1012

1113
SerializedProperty m_GameObjectProp = serializedObject.FindProperty("m_nameMapping");

0 commit comments

Comments
 (0)