Skip to content

Commit d3aaa4d

Browse files
author
Unity Technologies
committed
Unity 2023.1.0a16 C# reference source code
1 parent bf25390 commit d3aaa4d

File tree

657 files changed

+66778
-2859
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

657 files changed

+66778
-2859
lines changed

Editor/Mono/2D/SpriteAtlas/EditorSpriteAtlas.bindings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public struct SpriteAtlasTextureSettings
5959
[NativeName("sRGB")]
6060
private bool m_sRGB;
6161

62+
public int maxTextureSize { get { return m_MaxTextureSize; } }
6263
public int anisoLevel { get { return m_AnisoLevel; } set { m_AnisoLevel = value; } }
6364
public FilterMode filterMode { get { return (FilterMode)m_FilterMode; } set { m_FilterMode = (int)value; } }
6465
public bool generateMipMaps { get { return m_GenerateMipMaps; } set { m_GenerateMipMaps = value; } }

Editor/Mono/2D/SpriteAtlas/SpriteAtlasAsset.bindings.cs

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,115 @@
44

55
using System;
66
using System.Collections.Generic;
7-
using System.ComponentModel;
8-
using UnityEditor.Build;
9-
using UnityEditor.AssetImporters;
7+
using System.Runtime.InteropServices;
108
using UnityEngine;
119
using UnityEngine.Bindings;
1210
using UnityEngine.Scripting;
1311
using UnityEngine.U2D;
12+
using Unity.Collections.LowLevel.Unsafe;
13+
using Unity.Collections;
1414

1515
namespace UnityEditor.U2D
1616
{
17+
18+
[UsedByNativeCode]
19+
public abstract class ScriptablePacker : ScriptableObject
20+
{
21+
22+
public enum PackTransform
23+
{
24+
None = 0,
25+
FlipHorizontal = 1,
26+
FlipVertical = 2,
27+
Rotate180 = 3,
28+
}
29+
30+
[RequiredByNativeCode]
31+
[StructLayout(LayoutKind.Sequential)]
32+
public struct SpritePack
33+
{
34+
public int x;
35+
public int y;
36+
public int page;
37+
public PackTransform rot;
38+
};
39+
40+
[RequiredByNativeCode]
41+
[StructLayout(LayoutKind.Sequential)]
42+
public struct SpriteData
43+
{
44+
public int guid;
45+
public int texIndex;
46+
public int indexCount;
47+
public int vertexCount;
48+
public int indexOffset;
49+
public int vertexOffset;
50+
public RectInt rect;
51+
public SpritePack output;
52+
};
53+
54+
[RequiredByNativeCode]
55+
[StructLayout(LayoutKind.Sequential)]
56+
public struct TextureData
57+
{
58+
public int width;
59+
public int height;
60+
public int bufferOffset;
61+
};
62+
63+
[RequiredByNativeCode]
64+
[StructLayout(LayoutKind.Sequential)]
65+
internal struct PackerDataInternal
66+
{
67+
public int colorCount;
68+
public IntPtr colorData;
69+
public int spriteCount;
70+
public IntPtr spriteData;
71+
public int textureCount;
72+
public IntPtr textureData;
73+
public int indexCount;
74+
public IntPtr indexData;
75+
public int vertexCount;
76+
public IntPtr vertexData;
77+
};
78+
79+
[StructLayout(LayoutKind.Sequential)]
80+
public struct PackerData
81+
{
82+
public NativeArray<Color32> colorData;
83+
public NativeArray<SpriteData> spriteData;
84+
public NativeArray<TextureData> textureData;
85+
public NativeArray<int> indexData;
86+
public NativeArray<Vector2> vertexData;
87+
};
88+
89+
// Public function to pack.
90+
public abstract bool Pack(SpriteAtlasPackingSettings config, SpriteAtlasTextureSettings setting, PackerData input);
91+
92+
// Internal Glue function.
93+
[RequiredByNativeCode]
94+
internal bool PackInternal(SpriteAtlasPackingSettings config, SpriteAtlasTextureSettings setting, PackerDataInternal packerData)
95+
{
96+
var input = new PackerData();
97+
unsafe
98+
{
99+
input.colorData = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<Color32>((void*)packerData.colorData, packerData.colorCount, Allocator.None);
100+
input.spriteData = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<SpriteData>((void*)packerData.spriteData, packerData.spriteCount, Allocator.None);
101+
input.textureData = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<TextureData>((void*)packerData.textureData, packerData.textureCount, Allocator.None);
102+
input.indexData = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<int>((void*)packerData.indexData, packerData.indexCount, Allocator.None);
103+
input.vertexData = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray<Vector2>((void*)packerData.vertexData, packerData.vertexCount, Allocator.None);
104+
105+
NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref input.colorData, AtomicSafetyHandle.GetTempMemoryHandle());
106+
NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref input.spriteData, AtomicSafetyHandle.GetTempMemoryHandle());
107+
NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref input.textureData, AtomicSafetyHandle.GetTempMemoryHandle());
108+
NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref input.indexData, AtomicSafetyHandle.GetTempMemoryHandle());
109+
NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref input.vertexData, AtomicSafetyHandle.GetTempMemoryHandle());
110+
}
111+
return Pack(config, setting, input);
112+
}
113+
114+
};
115+
17116
// SpriteAtlas Importer lets you modify [[SpriteAtlas]]
18117
[NativeHeader("Editor/Src/2D/SpriteAtlas/SpriteAtlasAsset.h")]
19118
[NativeType(Header = "Editor/Src/2D/SpriteAtlas/SpriteAtlasAsset.h")]
@@ -26,8 +125,15 @@ public class SpriteAtlasAsset : UnityEngine.Object
26125
extern public void SetIsVariant(bool value);
27126
extern public void SetMasterAtlas(SpriteAtlas atlas);
28127
extern public SpriteAtlas GetMasterAtlas();
128+
extern internal UnityEngine.Object GetPacker();
129+
extern internal void SetPacker(UnityEngine.Object obj);
29130
extern public void Add(UnityEngine.Object[] objects);
30131
extern public void Remove(UnityEngine.Object[] objects);
132+
133+
public void SetScriptablePacker(ScriptablePacker obj)
134+
{
135+
SetPacker(obj);
136+
}
31137
extern internal void RemoveAt(int index);
32138

33139
[Obsolete("SetVariantScale is no longer supported and will be removed. Use SpriteAtlasImporter.SetVariantScale instead.")]

Editor/Mono/2D/SpriteAtlas/SpriteAtlasImporterInspector.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Styles
5151
public readonly GUIContent atlasTypeLabel = EditorGUIUtility.TrTextContent("Type");
5252
public readonly GUIContent defaultPlatformLabel = EditorGUIUtility.TrTextContent("Default");
5353
public readonly GUIContent masterAtlasLabel = EditorGUIUtility.TrTextContent("Master Atlas", "Assigning another Sprite Atlas asset will make this atlas a variant of it.");
54+
public readonly GUIContent packerLabel = EditorGUIUtility.TrTextContent("Scriptable Packer", "Scriptable Object that implements custom packing for Sprite-Atlas.");
5455
public readonly GUIContent bindAsDefaultLabel = EditorGUIUtility.TrTextContent("Include in Build", "Packed textures will be included in the build by default.");
5556
public readonly GUIContent enableRotationLabel = EditorGUIUtility.TrTextContent("Allow Rotation", "Try rotating the sprite to fit better during packing.");
5657
public readonly GUIContent enableTightPackingLabel = EditorGUIUtility.TrTextContent("Tight Packing", "Use the mesh outline to fit instead of the whole texture rect during packing.");
@@ -137,6 +138,7 @@ private enum AtlasType { Undefined = -1, Master = 0, Variant = 1 }
137138

138139
private SerializedProperty m_MasterAtlas;
139140
private SerializedProperty m_VariantScale;
141+
private SerializedProperty m_ScriptablePacker;
140142

141143
private string m_Hash;
142144
private int m_PreviewPage = 0;
@@ -231,6 +233,7 @@ internal static int SpriteAtlasAssetHash(SerializedObject obj)
231233
hashCode = (int)2166136261 ^ (int) obj.FindProperty("m_MasterAtlas").contentHash;
232234
hashCode = hashCode * 16777619 ^ (int) obj.FindProperty("m_ImporterData").contentHash;
233235
hashCode = hashCode * 16777619 ^ (int) obj.FindProperty("m_IsVariant").contentHash;
236+
hashCode = hashCode * 16777619 ^ (int)obj.FindProperty("m_ScriptablePacker").contentHash;
234237
}
235238
return hashCode;
236239
}
@@ -310,6 +313,7 @@ public override void OnEnable()
310313
return;
311314

312315
m_MasterAtlas = serializedAssetObject.FindProperty("m_MasterAtlas");
316+
m_ScriptablePacker = serializedAssetObject.FindProperty("m_ScriptablePacker");
313317
m_Packables = serializedAssetObject.FindProperty("m_ImporterData.packables");
314318
m_PackableList = new ReorderableList(serializedAssetObject, m_Packables, true, true, true, true);
315319
m_PackableList.onAddCallback = AddPackable;
@@ -541,7 +545,7 @@ private void HandleCommonSettingUI()
541545
// Reinit the platform setting view
542546
m_TexturePlatformSettingsView = new SpriteAtlasInspectorPlatformSettingView(IsTargetMaster());
543547
}
544-
548+
m_ScriptablePacker.objectReferenceValue = EditorGUILayout.ObjectField(styles.packerLabel, m_ScriptablePacker.objectReferenceValue, typeof(UnityEditor.U2D.ScriptablePacker), false);
545549
if (atlasType == AtlasType.Variant)
546550
{
547551
EditorGUI.BeginChangeCheck();

Editor/Mono/Animation/AnimationUtility.bindings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using UnityEngine.Internal;
1212

1313
using Object = UnityEngine.Object;
14+
using UnityEngine.Animations;
1415

1516
namespace UnityEditor
1617
{
@@ -52,6 +53,7 @@ public AnimationClipCurveData(EditorCurveBinding binding)
5253
}
5354

5455
[NativeHeader("Editor/Src/Animation/AnimationUtility.bindings.h")]
56+
[NativeHeader("Modules/Animation/ScriptBindings/GenericBinding.bindings.h")]
5557
public partial class AnimationUtility
5658
{
5759
public enum CurveModifiedType
@@ -454,5 +456,8 @@ public static void StopAnimationMode()
454456

455457
[Obsolete("SetAnimationType is no longer supported.")]
456458
public static void SetAnimationType(AnimationClip clip, ModelImporterAnimationType type) {}
459+
460+
461+
extern public static GenericBinding[] EditorCurveBindingsToGenericBindings(EditorCurveBinding[] editorCurveBindings);
457462
}
458463
}

0 commit comments

Comments
 (0)