void AttachPointSpriteHandler(tk2dSpriteCollectionData newSpriteCollection, int newSpriteId, object callbackData)
        {
            string attachPointName = (string)callbackData;

            tk2dSpriteCollection.AttachPointTestSprite proxy = null;
            if (SpriteCollection.attachPointTestSprites.TryGetValue(attachPointName, out proxy))
            {
                proxy.spriteCollection = newSpriteCollection;
                proxy.spriteId         = newSpriteId;
                HandleUtility.Repaint();
            }
        }
        public void DrawAttachPointInspector(tk2dSpriteCollectionDefinition param, Texture2D texture)
        {
            // catalog all names
            HashSet <string> apHashSet = new HashSet <string>();

            foreach (tk2dSpriteCollectionDefinition def in SpriteCollection.textureParams)
            {
                foreach (tk2dSpriteDefinition.AttachPoint currAp in def.attachPoints)
                {
                    apHashSet.Add(currAp.name);
                }
            }
            Dictionary <string, int> apNameLookup = new Dictionary <string, int>();
            List <string>            apNames      = new List <string>(apHashSet);

            for (int i = 0; i < apNames.Count; ++i)
            {
                apNameLookup.Add(apNames[i], i);
            }
            apNames.Add("Create...");

            int toDelete = -1;

            tk2dSpriteGuiUtility.showOpenEditShortcuts = false;
            tk2dSpriteDefinition.AttachPoint newEditingAttachPointName = editingAttachPointName;
            int apIdx = 0;

            foreach (var ap in param.attachPoints)
            {
                GUILayout.BeginHorizontal();

                if (editingAttachPointName == ap)
                {
                    if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return)
                    {
                        newEditingAttachPointName = null;
                        HandleUtility.Repaint();
                        GUIUtility.keyboardControl = 0;
                    }
                    ap.name = GUILayout.TextField(ap.name);
                }
                else
                {
                    int sel = EditorGUILayout.Popup(apNameLookup[ap.name], apNames.ToArray());
                    if (sel == apNames.Count - 1)
                    {
                        newEditingAttachPointName = ap;
                        HandleUtility.Repaint();
                    }
                    else
                    {
                        ap.name = apNames[sel];
                    }
                }

                ap.angle = EditorGUILayout.FloatField(ap.angle, GUILayout.Width(45));

                if (GUILayout.Button("x", GUILayout.Width(22)))
                {
                    toDelete = apIdx;
                }
                GUILayout.EndHorizontal();

                if (showAttachPointSprites)
                {
                    bool pushGUIEnabled = GUI.enabled;

                    string tmpName;
                    if (editingAttachPointName != ap)
                    {
                        tmpName = ap.name;
                    }
                    else
                    {
                        tmpName     = "";
                        GUI.enabled = false;
                    }

                    tk2dSpriteCollection.AttachPointTestSprite spriteProxy = null;
                    if (!SpriteCollection.attachPointTestSprites.TryGetValue(tmpName, out spriteProxy))
                    {
                        spriteProxy = new tk2dSpriteCollection.AttachPointTestSprite();
                        SpriteCollection.attachPointTestSprites.Add(tmpName, spriteProxy);
                    }

                    tk2dSpriteGuiUtility.SpriteSelector(spriteProxy.spriteCollection, spriteProxy.spriteId, AttachPointSpriteHandler, tmpName);

                    GUI.enabled = pushGUIEnabled;
                }

                editingAttachPointName = newEditingAttachPointName;
                ++apIdx;
            }

            if (GUILayout.Button("Add AttachPoint"))
            {
                // Find an unused attach point name
                string unused = "";
                foreach (string n in apHashSet)
                {
                    bool used = false;
                    for (int i = 0; i < param.attachPoints.Count; ++i)
                    {
                        if (n == param.attachPoints[i].name)
                        {
                            used = true;
                            break;
                        }
                    }
                    if (!used)
                    {
                        unused = n;
                        break;
                    }
                }
                tk2dSpriteDefinition.AttachPoint ap = new tk2dSpriteDefinition.AttachPoint();
                ap.name     = unused;
                ap.position = Vector3.zero;
                param.attachPoints.Add(ap);

                if (unused == "")
                {
                    editingAttachPointName = ap;
                }
            }

            if (toDelete != -1)
            {
                param.attachPoints.RemoveAt(toDelete);
                HandleUtility.Repaint();
            }

            showAttachPointSprites = GUILayout.Toggle(showAttachPointSprites, "Preview", "button");
            tk2dSpriteGuiUtility.showOpenEditShortcuts = true;
        }
        public void DrawTextureView(tk2dSpriteCollectionDefinition param, Texture2D texture)
        {
            HandleKeys();

            if (mode == Mode.None)
            {
                mode = Mode.Texture;
            }

            // sanity check
            if (editorDisplayScale <= 1.0f)
            {
                editorDisplayScale = 1.0f;
            }

            // mirror data
            currentColliderColor = param.colliderColor;

            GUILayout.BeginVertical(tk2dEditorSkin.SC_BodyBackground, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));

            if (texture == null)
            {
                // Get somewhere to put the texture...
                GUILayoutUtility.GetRect(128.0f, 128.0f, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
            }
            else
            {
                bool allowAnchor   = param.anchor == tk2dSpriteCollectionDefinition.Anchor.Custom;
                bool allowCollider = (param.colliderType == tk2dSpriteCollectionDefinition.ColliderType.Polygon ||
                                      param.colliderType == tk2dSpriteCollectionDefinition.ColliderType.BoxCustom);
                if (mode == Mode.Anchor && !allowAnchor)
                {
                    mode = Mode.Texture;
                }
                if (mode == Mode.Collider && !allowCollider)
                {
                    mode = Mode.Texture;
                }

                Rect rect = GUILayoutUtility.GetRect(128.0f, 128.0f, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                tk2dGrid.Draw(rect);

                // middle mouse drag and scroll zoom
                if (rect.Contains(Event.current.mousePosition))
                {
                    if (Event.current.type == EventType.MouseDrag && Event.current.button == 2)
                    {
                        textureScrollPos -= Event.current.delta * editorDisplayScale;
                        Event.current.Use();
                        HandleUtility.Repaint();
                    }
                    if (Event.current.type == EventType.ScrollWheel)
                    {
                        editorDisplayScale -= Event.current.delta.y * 0.03f;
                        Event.current.Use();
                        HandleUtility.Repaint();
                    }
                }

                bool alphaBlend = true;
                textureScrollPos = GUI.BeginScrollView(rect, textureScrollPos,
                                                       new Rect(0, 0, textureBorderPixels * 2 + (texture.width) * editorDisplayScale, textureBorderPixels * 2 + (texture.height) * editorDisplayScale));
                Rect textureRect = new Rect(textureBorderPixels, textureBorderPixels, texture.width * editorDisplayScale, texture.height * editorDisplayScale);
                texture.filterMode = FilterMode.Point;
                GUI.DrawTexture(textureRect, texture, ScaleMode.ScaleAndCrop, alphaBlend);

                if (mode == Mode.Collider)
                {
                    if (param.colliderType == tk2dSpriteCollectionDefinition.ColliderType.BoxCustom)
                    {
                        DrawCustomBoxColliderEditor(textureRect, param, texture);
                    }
                    if (param.colliderType == tk2dSpriteCollectionDefinition.ColliderType.Polygon)
                    {
                        DrawPolygonColliderEditor(textureRect, ref param.polyColliderIslands, texture, false);
                    }
                }

                if (mode == Mode.Texture && param.customSpriteGeometry)
                {
                    DrawPolygonColliderEditor(textureRect, ref param.geometryIslands, texture, true);
                }

                // Anchor
                if (mode == Mode.Anchor)
                {
                    Color   lineColor = Color.white;
                    Vector2 anchor    = new Vector2(param.anchorX, param.anchorY);
                    Vector2 origin    = new Vector2(textureRect.x, textureRect.y);

                    int id = 99999;
                    anchor = (tk2dGuiUtility.PositionHandle(id, anchor * editorDisplayScale + origin) - origin) / editorDisplayScale;

                    Color oldColor = Handles.color;
                    Handles.color = lineColor;
                    float w = Mathf.Max(rect.width, texture.width * editorDisplayScale);
                    float h = Mathf.Max(rect.height, texture.height * editorDisplayScale);

                    Handles.DrawLine(new Vector3(textureRect.x, textureRect.y + anchor.y * editorDisplayScale, 0), new Vector3(textureRect.x + w, textureRect.y + anchor.y * editorDisplayScale, 0));
                    Handles.DrawLine(new Vector3(textureRect.x + anchor.x * editorDisplayScale, textureRect.y + 0, 0), new Vector3(textureRect.x + anchor.x * editorDisplayScale, textureRect.y + h, 0));
                    Handles.color = oldColor;

                    // constrain
                    param.anchorX = Mathf.Clamp(Mathf.Round(anchor.x), 0.0f, texture.width);
                    param.anchorY = Mathf.Clamp(Mathf.Round(anchor.y), 0.0f, texture.height);

                    tk2dGuiUtility.SetPositionHandleValue(id, new Vector2(param.anchorX, param.anchorY));

                    HandleUtility.Repaint();
                }

                if (mode == Mode.AttachPoint)
                {
                    Vector2 origin = new Vector2(textureRect.x, textureRect.y);
                    int     id     = "Mode.AttachPoint".GetHashCode();
                    foreach (tk2dSpriteDefinition.AttachPoint ap in param.attachPoints)
                    {
                        Vector2 apPosition = new Vector2(ap.position.x, ap.position.y);

                        if (showAttachPointSprites)
                        {
                            tk2dSpriteCollection.AttachPointTestSprite spriteProxy = null;
                            if (SpriteCollection.attachPointTestSprites.TryGetValue(ap.name, out spriteProxy) && spriteProxy.spriteCollection != null &&
                                spriteProxy.spriteCollection.IsValidSpriteId(spriteProxy.spriteId))
                            {
                                tk2dSpriteDefinition def = spriteProxy.spriteCollection.inst.spriteDefinitions[spriteProxy.spriteId];
                                tk2dSpriteThumbnailCache.DrawSpriteTextureInRect(textureRect, def, Color.white, ap.position, ap.angle, new Vector2(editorDisplayScale, editorDisplayScale));
                            }
                        }

                        Vector2 pos = apPosition * editorDisplayScale + origin;
                        GUI.color  = Color.clear;                        // don't actually draw the move handle center
                        apPosition = (tk2dGuiUtility.PositionHandle(id, pos) - origin) / editorDisplayScale;
                        GUI.color  = Color.white;

                        float handleSize = 30;

                        Handles.color = Color.green; Handles.DrawLine(pos, pos - Rotate(Vector2.up, ap.angle) * handleSize);
                        Handles.color = Color.red; Handles.DrawLine(pos, pos + Rotate(Vector2.right, ap.angle) * handleSize);

                        Handles.color = Color.white;
                        Handles.DrawWireDisc(pos, Vector3.forward, handleSize);

                        // rotation handle
                        Vector2 rotHandlePos    = pos + Rotate(Vector2.right, ap.angle) * handleSize;
                        Vector2 newRotHandlePos = tk2dGuiUtility.Handle(tk2dEditorSkin.RotateHandle, id + 1, rotHandlePos, false);
                        if (newRotHandlePos != rotHandlePos)
                        {
                            Vector2 deltaRot = newRotHandlePos - pos;
                            float   angle    = -Mathf.Atan2(deltaRot.y, deltaRot.x) * Mathf.Rad2Deg;
                            if (Event.current.control)
                            {
                                float snapAmount = Event.current.shift ? 15 : 5;
                                angle = Mathf.Floor(angle / snapAmount) * snapAmount;
                            }
                            else if (!Event.current.shift)
                            {
                                angle = Mathf.Floor(angle);
                            }
                            ap.angle = angle;
                        }

                        Rect r = new Rect(pos.x + 8, pos.y + 6, 1000, 50);
                        GUI.Label(r, ap.name, EditorStyles.whiteMiniLabel);

                        ap.position.x = Mathf.Round(apPosition.x);
                        ap.position.y = Mathf.Round(apPosition.y);
                        tk2dGuiUtility.SetPositionHandleValue(id, new Vector2(ap.position.x, ap.position.y));

                        id += 2;
                    }
                    Handles.color = Color.white;
                }

                if (mode == Mode.Texture)
                {
                    if (param.dice)
                    {
                        Handles.color = Color.red;
                        Vector3 p1, p2;
                        int     q, dq;

                        p1 = new Vector3(textureRect.x, textureRect.y, 0);
                        p2 = new Vector3(textureRect.x, textureRect.y + textureRect.height, 0);
                        q  = 0;
                        dq = param.diceUnitX;
                        if (dq > 0)
                        {
                            while (q <= texture.width)
                            {
                                Handles.DrawLine(p1, p2);
                                int q0 = q;
                                if (q < texture.width && (q + dq) > texture.width)
                                {
                                    q = texture.width;
                                }
                                else
                                {
                                    q += dq;
                                }
                                p1.x += (float)(q - q0) * editorDisplayScale;
                                p2.x += (float)(q - q0) * editorDisplayScale;
                            }
                        }
                        p1 = new Vector3(textureRect.x, textureRect.y + textureRect.height, 0);
                        p2 = new Vector3(textureRect.x + textureRect.width, textureRect.y + textureRect.height, 0);
                        q  = 0;
                        dq = param.diceUnitY;
                        if (dq > 0)
                        {
                            while (q <= texture.height)
                            {
                                Handles.DrawLine(p1, p2);
                                int q0 = q;
                                if (q < texture.height && (q + dq) > texture.height)
                                {
                                    q = texture.height;
                                }
                                else
                                {
                                    q += dq;
                                }
                                p1.y -= (float)(q - q0) * editorDisplayScale;
                                p2.y -= (float)(q - q0) * editorDisplayScale;
                            }
                        }

                        Handles.color = Color.white;
                    }
                }

                GUI.EndScrollView();
            }

            // Draw toolbar
            DrawToolbar(param, texture);

            GUILayout.EndVertical();
        }
		public void DrawAttachPointInspector(tk2dSpriteCollectionDefinition param, Texture2D texture) {
			// catalog all names
			HashSet<string> apHashSet = new HashSet<string>();
			foreach (tk2dSpriteCollectionDefinition def in SpriteCollection.textureParams) {
				foreach (tk2dSpriteDefinition.AttachPoint currAp in def.attachPoints) {
					apHashSet.Add( currAp.name );
				}
			}
			Dictionary<string, int> apNameLookup = new Dictionary<string, int>();
			List<string> apNames = new List<string>( apHashSet );
			for (int i = 0; i < apNames.Count; ++i) {
				apNameLookup.Add( apNames[i], i );
			}
			apNames.Add( "Create..." );

			attachPointScroll = EditorGUILayout.BeginScrollView(attachPointScroll);

			int toDelete = -1;
			tk2dSpriteGuiUtility.showOpenEditShortcuts = false;
			tk2dSpriteDefinition.AttachPoint newEditingAttachPointName = editingAttachPointName;
			int apIdx = 0;
			foreach (var ap in param.attachPoints) {
				GUILayout.BeginHorizontal();

				if (editingAttachPointName == ap) {
					if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return) {
						newEditingAttachPointName = null;
						HandleUtility.Repaint();
						GUIUtility.keyboardControl = 0;
					}
					ap.name = GUILayout.TextField(ap.name);
				}
				else {
					int sel = EditorGUILayout.Popup(apNameLookup[ap.name], apNames.ToArray());
					if (sel == apNames.Count - 1) {
						newEditingAttachPointName = ap;
						HandleUtility.Repaint();
					}
					else {
						ap.name = apNames[sel];
					}
				}

				ap.angle = EditorGUILayout.FloatField(ap.angle, GUILayout.Width(45));

				if (GUILayout.Button("x", GUILayout.Width(22))) {
					toDelete = apIdx;
				}
				GUILayout.EndHorizontal();

				if (showAttachPointSprites) {
					bool pushGUIEnabled = GUI.enabled;
					
					string tmpName;
					if (editingAttachPointName != ap) {
						tmpName = ap.name;
					} else {
						tmpName = "";
						GUI.enabled = false;
					}

					tk2dSpriteCollection.AttachPointTestSprite spriteProxy = null;
					if (!SpriteCollection.attachPointTestSprites.TryGetValue(tmpName, out spriteProxy)) {
						spriteProxy = new tk2dSpriteCollection.AttachPointTestSprite();
						SpriteCollection.attachPointTestSprites.Add( tmpName, spriteProxy );
					}

					tk2dSpriteGuiUtility.SpriteSelector( spriteProxy.spriteCollection, spriteProxy.spriteId, AttachPointSpriteHandler, tmpName );
					
					GUI.enabled = pushGUIEnabled;
				}

				editingAttachPointName = newEditingAttachPointName;
				++apIdx;
			}
			
			EditorGUILayout.EndScrollView();

			if (GUILayout.Button("Add AttachPoint")) {
				// Find an unused attach point name
				string unused = "";
				foreach (string n in apHashSet) {
					bool used = false;
					for (int i = 0; i < param.attachPoints.Count; ++i) {
						if (n == param.attachPoints[i].name) {
							used = true;
							break;
						}
					}
					if (!used) {
						unused = n;
						break;
					}
				}
				tk2dSpriteDefinition.AttachPoint ap = new tk2dSpriteDefinition.AttachPoint();
				ap.name = unused;
				ap.position = Vector3.zero;
				param.attachPoints.Add(ap);

				if (unused == "") {
					editingAttachPointName = ap;
				}
			}

			if (toDelete != -1) {
				param.attachPoints.RemoveAt(toDelete);
				HandleUtility.Repaint();
			}

			showAttachPointSprites = GUILayout.Toggle(showAttachPointSprites, "Preview", "button");
			tk2dSpriteGuiUtility.showOpenEditShortcuts = true;
		}
        public void CopyFromSource(bool copyBuilt)
        {
            this.obj.Upgrade();             // make sure its up to date

            textureParams = new List <tk2dSpriteCollectionDefinition>(obj.textureParams.Length);
            foreach (var v in obj.textureParams)
            {
                if (v == null)
                {
                    textureParams.Add(null);
                }
                else
                {
                    var t = new tk2dSpriteCollectionDefinition();
                    t.CopyFrom(v);
                    textureParams.Add(t);
                }
            }

            spriteSheets = new List <tk2dSpriteSheetSource>();
            if (obj.spriteSheets != null)
            {
                foreach (var v in obj.spriteSheets)
                {
                    if (v == null)
                    {
                        spriteSheets.Add(null);
                    }
                    else
                    {
                        var t = new tk2dSpriteSheetSource();
                        t.CopyFrom(v);
                        spriteSheets.Add(t);
                    }
                }
            }

            fonts = new List <tk2dSpriteCollectionFont>();
            if (obj.fonts != null)
            {
                foreach (var v in obj.fonts)
                {
                    if (v == null)
                    {
                        fonts.Add(null);
                    }
                    else
                    {
                        var t = new tk2dSpriteCollectionFont();
                        t.CopyFrom(v);
                        fonts.Add(t);
                    }
                }
            }

            attachPointTestSprites.Clear();
            foreach (var v in obj.attachPointTestSprites)
            {
                if (v.spriteCollection != null && v.spriteCollection.IsValidSpriteId(v.spriteId))
                {
                    tk2dSpriteCollection.AttachPointTestSprite ap = new tk2dSpriteCollection.AttachPointTestSprite();
                    ap.CopyFrom(v);
                    attachPointTestSprites[v.attachPointName] = v;
                }
            }

            UpgradeLegacySpriteSheets();

            var target = this;
            var source = obj;

            target.platforms = new List <tk2dSpriteCollectionPlatform>();
            foreach (tk2dSpriteCollectionPlatform plat in source.platforms)
            {
                tk2dSpriteCollectionPlatform p = new tk2dSpriteCollectionPlatform();
                p.CopyFrom(plat);
                target.platforms.Add(p);
            }
            if (target.platforms.Count == 0)
            {
                tk2dSpriteCollectionPlatform plat = new tk2dSpriteCollectionPlatform();                 // add a null platform
                target.platforms.Add(plat);
            }

            target.assetName   = source.assetName;
            target.loadable    = source.loadable;
            target.atlasFormat = source.atlasFormat;

            target.maxTextureSize      = source.maxTextureSize;
            target.forceTextureSize    = source.forceTextureSize;
            target.forcedTextureWidth  = source.forcedTextureWidth;
            target.forcedTextureHeight = source.forcedTextureHeight;

            target.textureCompression   = source.textureCompression;
            target.atlasWidth           = source.atlasWidth;
            target.atlasHeight          = source.atlasHeight;
            target.forceSquareAtlas     = source.forceSquareAtlas;
            target.atlasWastage         = source.atlasWastage;
            target.allowMultipleAtlases = source.allowMultipleAtlases;
            target.disableRotation      = source.disableRotation;
            target.removeDuplicates     = source.removeDuplicates;
            target.allowSpannedDicing   = source.allowSpannedDicing;

            target.premultipliedAlpha = source.premultipliedAlpha;

            target.sizeDef.CopyFrom(source.sizeDef);
            target.globalScale          = source.globalScale;
            target.globalTextureRescale = source.globalTextureRescale;
            target.physicsDepth         = source.physicsDepth;
            target.physicsEngine        = source.physicsEngine;
            target.disableTrimming      = source.disableTrimming;
            target.normalGenerationMode = source.normalGenerationMode;
            target.padAmount            = source.padAmount;
            target.autoUpdate           = source.autoUpdate;
            target.editorDisplayScale   = source.editorDisplayScale;

            // Texture settings
            target.filterMode = source.filterMode;
            target.wrapMode   = source.wrapMode;
            target.userDefinedTextureSettings = source.userDefinedTextureSettings;
            target.mipmapEnabled = source.mipmapEnabled;
            target.anisoLevel    = source.anisoLevel;

            target.linkedSpriteCollections.Clear();
            for (int i = 0; i < source.linkedSpriteCollections.Count; ++i)
            {
                tk2dLinkedSpriteCollection t = new tk2dLinkedSpriteCollection();
                t.name             = source.linkedSpriteCollections[i].name;
                t.spriteCollection = source.linkedSpriteCollections[i].spriteCollection;
                target.linkedSpriteCollections.Add(t);
            }

            if (copyBuilt)
            {
                CopyBuiltFromSource(source);
            }
        }
        public void CopyToTarget(tk2dSpriteCollection target)
        {
            target.textureParams = textureParams.ToArray();
            target.spriteSheets  = spriteSheets.ToArray();
            target.fonts         = fonts.ToArray();

            var source = this;

            target.platforms = new List <tk2dSpriteCollectionPlatform>();
            foreach (tk2dSpriteCollectionPlatform plat in source.platforms)
            {
                tk2dSpriteCollectionPlatform p = new tk2dSpriteCollectionPlatform();
                p.CopyFrom(plat);
                target.platforms.Add(p);
            }
            target.assetName   = source.assetName;
            target.loadable    = source.loadable;
            target.atlasFormat = source.atlasFormat;

            target.maxTextureSize      = source.maxTextureSize;
            target.forceTextureSize    = source.forceTextureSize;
            target.forcedTextureWidth  = source.forcedTextureWidth;
            target.forcedTextureHeight = source.forcedTextureHeight;

            target.textureCompression   = source.textureCompression;
            target.atlasWidth           = source.atlasWidth;
            target.atlasHeight          = source.atlasHeight;
            target.forceSquareAtlas     = source.forceSquareAtlas;
            target.atlasWastage         = source.atlasWastage;
            target.allowMultipleAtlases = source.allowMultipleAtlases;
            target.disableRotation      = source.disableRotation;
            target.removeDuplicates     = source.removeDuplicates;
            target.allowSpannedDicing   = source.allowSpannedDicing;

            target.spriteCollection   = source.spriteCollection;
            target.premultipliedAlpha = source.premultipliedAlpha;

            CopyArray(ref target.altMaterials, source.altMaterials);
            CopyArray(ref target.atlasMaterials, source.atlasMaterials);
            CopyArray(ref target.atlasTextures, source.atlasTextures);
            CopyArray(ref target.atlasTextureFiles, source.atlasTextureFiles);

            target.sizeDef.CopyFrom(source.sizeDef);
            target.globalScale          = source.globalScale;
            target.globalTextureRescale = source.globalTextureRescale;
            target.physicsDepth         = source.physicsDepth;
            target.physicsEngine        = source.physicsEngine;
            target.disableTrimming      = source.disableTrimming;
            target.normalGenerationMode = source.normalGenerationMode;
            target.padAmount            = source.padAmount;
            target.autoUpdate           = source.autoUpdate;
            target.editorDisplayScale   = source.editorDisplayScale;

            // Texture settings
            target.filterMode = source.filterMode;
            target.wrapMode   = source.wrapMode;
            target.userDefinedTextureSettings = source.userDefinedTextureSettings;
            target.mipmapEnabled = source.mipmapEnabled;
            target.anisoLevel    = source.anisoLevel;

            // Attach point test data
            // Make sure we only store relevant data
            HashSet <string> attachPointNames = new HashSet <string>();

            foreach (tk2dSpriteCollectionDefinition def in textureParams)
            {
                foreach (tk2dSpriteDefinition.AttachPoint ap in def.attachPoints)
                {
                    attachPointNames.Add(ap.name);
                }
            }
            target.attachPointTestSprites.Clear();
            foreach (string name in attachPointTestSprites.Keys)
            {
                if (attachPointNames.Contains(name))
                {
                    tk2dSpriteCollection.AttachPointTestSprite lut = new tk2dSpriteCollection.AttachPointTestSprite();
                    lut.CopyFrom(attachPointTestSprites[name]);
                    lut.attachPointName = name;
                    target.attachPointTestSprites.Add(lut);
                }
            }

            target.linkedSpriteCollections.Clear();
            for (int i = 0; i < source.linkedSpriteCollections.Count; ++i)
            {
                tk2dLinkedSpriteCollection t = new tk2dLinkedSpriteCollection();
                t.name             = source.linkedSpriteCollections[i].name;
                t.spriteCollection = source.linkedSpriteCollections[i].spriteCollection;
                target.linkedSpriteCollections.Add(t);
            }
        }
示例#7
0
        public void CopyFromSource()
        {
            this.obj.Upgrade();             // make sure its up to date

            textureParams = new List <tk2dSpriteCollectionDefinition>(obj.textureParams.Length);
            foreach (var v in obj.textureParams)
            {
                if (v == null)
                {
                    textureParams.Add(null);
                }
                else
                {
                    var t = new tk2dSpriteCollectionDefinition();
                    t.CopyFrom(v);
                    textureParams.Add(t);
                }
            }

            spriteSheets = new List <tk2dSpriteSheetSource>();
            if (obj.spriteSheets != null)
            {
                foreach (var v in obj.spriteSheets)
                {
                    if (v == null)
                    {
                        spriteSheets.Add(null);
                    }
                    else
                    {
                        var t = new tk2dSpriteSheetSource();
                        t.CopyFrom(v);
                        spriteSheets.Add(t);
                    }
                }
            }

            fonts = new List <tk2dSpriteCollectionFont>();
            if (obj.fonts != null)
            {
                foreach (var v in obj.fonts)
                {
                    if (v == null)
                    {
                        fonts.Add(null);
                    }
                    else
                    {
                        var t = new tk2dSpriteCollectionFont();
                        t.CopyFrom(v);
                        fonts.Add(t);
                    }
                }
            }

            attachPointTestSprites.Clear();
            foreach (var v in obj.attachPointTestSprites)
            {
                if (v.spriteCollection != null && v.spriteCollection.IsValidSpriteId(v.spriteId))
                {
                    tk2dSpriteCollection.AttachPointTestSprite ap = new tk2dSpriteCollection.AttachPointTestSprite();
                    ap.CopyFrom(v);
                    attachPointTestSprites[v.attachPointName] = v;
                }
            }

            UpgradeLegacySpriteSheets();

            var target = this;
            var source = obj;

            target.platforms = new List <tk2dSpriteCollectionPlatform>();
            foreach (tk2dSpriteCollectionPlatform plat in source.platforms)
            {
                tk2dSpriteCollectionPlatform p = new tk2dSpriteCollectionPlatform();
                p.CopyFrom(plat);
                target.platforms.Add(p);
            }
            if (target.platforms.Count == 0)
            {
                tk2dSpriteCollectionPlatform plat = new tk2dSpriteCollectionPlatform();                 // add a null platform
                target.platforms.Add(plat);
            }
            target.enablePlatformScaleVertex = source.enablePlatformScaleVertex;

            target.assetName   = source.assetName;
            target.loadable    = source.loadable;
            target.atlasFormat = source.atlasFormat;

            target.maxTextureSize                 = source.maxTextureSize;
            target.forceTextureSize               = source.forceTextureSize;
            target.forcedTextureWidth             = source.forcedTextureWidth;
            target.forcedTextureHeight            = source.forcedTextureHeight;
            target.freeSizeAtlas                  = source.freeSizeAtlas;
            target.amountOfPixelsToExtendFreeSize = source.amountOfPixelsToExtendFreeSize;

            target.forceA8     = source.forceA8;
            target.forceShader = source.forceShader;

            target.textureCompression   = source.textureCompression;
            target.atlasWidth           = source.atlasWidth;
            target.atlasHeight          = source.atlasHeight;
            target.forceSquareAtlas     = source.forceSquareAtlas;
            target.atlasWastage         = source.atlasWastage;
            target.allowMultipleAtlases = source.allowMultipleAtlases;
            target.disableRotation      = source.disableRotation;
            target.removeDuplicates     = source.removeDuplicates;
            target.usePosterize         = source.usePosterize;
            target.posterizeValue       = source.posterizeValue;

            target.spriteCollection   = source.spriteCollection;
            target.premultipliedAlpha = source.premultipliedAlpha;

            CopyArray(ref target.altMaterials, source.altMaterials);
            CopyArray(ref target.atlasMaterials, source.atlasMaterials);
            CopyArray(ref target.atlasTextures, source.atlasTextures);
            CopyArray(ref target.atlasTextureFiles, source.atlasTextureFiles);
            CopyArray(ref target.atlasTexturePaths, source.atlasTexturePaths);

            CopyArray(ref target.atlasWidthTexture, source.atlasWidthTexture);
            CopyArray(ref target.atlasHeightTexture, source.atlasHeightTexture);

            target.sizeDef.CopyFrom(source.sizeDef);
            target.globalScale          = source.globalScale;
            target.globalTextureRescale = source.globalTextureRescale;
            target.physicsDepth         = source.physicsDepth;
            target.physicsEngine        = source.physicsEngine;
            target.disableTrimming      = source.disableTrimming;
            target.normalGenerationMode = source.normalGenerationMode;
            target.padAmount            = source.padAmount;
            target.innerPadAmount       = source.innerPadAmount;
            target.autoUpdate           = source.autoUpdate;
            target.editorDisplayScale   = source.editorDisplayScale;

            // Texture settings
            target.filterMode = source.filterMode;
            target.wrapMode   = source.wrapMode;
            target.userDefinedTextureSettings = source.userDefinedTextureSettings;
            target.mipmapEnabled    = source.mipmapEnabled;
            target.asyncLoadEnabled = source.asyncLoadEnabled;
            target.anisoLevel       = source.anisoLevel;
            target.forceA8          = source.forceA8;
        }