Пример #1
0
        public void Select(tk2dSpriteSheetSource spriteSheet, int[] ids)
        {
            selectedSprites.Clear();
            activeSelectedSprites.Clear();
            rectSelectX             = rectSelectY = -1;
            textureViewScrollBar    = Vector2.zero;
            inspectorScrollBar      = Vector2.zero;
            activeSpriteSheetSource = spriteSheet;
            selectedMode            = EditMode.Edit;

            foreach (int id in ids)
            {
                var v = new SpriteCollectionEditorEntry();
                v.index = id;
                selectedSprites.Add(v);
            }
        }
Пример #2
0
        void ProcessSpriteSelectionUI(tk2dSpriteSheetSource spriteSheet, Rect rect)
        {
            int spriteSheetId = SpriteCollection.GetSpriteSheetId(spriteSheet);

            if (rect.Contains(Event.current.mousePosition))
            {
                Vector2 localMousePos = (Event.current.mousePosition - new Vector2(rect.x, rect.y)) / zoomAmount;
                int     tileX = ((int)localMousePos.x - spriteSheet.tileMarginX) / (spriteSheet.tileSpacingX + spriteSheet.tileWidth);
                int     tileY = ((int)localMousePos.y - spriteSheet.tileMarginY) / (spriteSheet.tileSpacingY + spriteSheet.tileHeight);
                int     numTilesX, numTilesY;
                GetNumTilesForSpriteSheet(spriteSheet, out numTilesX, out numTilesY);

                if (Event.current.type == EventType.MouseDown)
                {
                    bool multiSelectKey = (Application.platform == RuntimePlatform.OSXEditor)?Event.current.command:Event.current.control;
                    if (tileX >= 0 && tileX < numTilesX && tileY >= 0 && tileY < numTilesY)
                    {
                        if (!multiSelectKey)
                        {
                            selectedSprites.Clear();
                        }

                        int id = FindSpriteSlotForSpriteSheetCell(SpriteCollection.GetSpriteSheetId(spriteSheet), tileX, tileY);
                        if (id != -1)
                        {
                            if (!multiSelectKey)
                            {
                                rectSelectX = tileX;
                                rectSelectY = tileY;
                            }

                            bool found = false;
                            foreach (var sel in selectedSprites)
                            {
                                if (sel.index == id)
                                {
                                    found = true;
                                    selectedSprites.Remove(sel);
                                    break;
                                }
                            }
                            if (!found)
                            {
                                var entry = new SpriteCollectionEditorEntry();
                                entry.index = id;
                                selectedSprites.Add(entry);
                            }
                            HandleUtility.Repaint();
                        }
                    }
                }
                else if (Event.current.type == EventType.MouseDrag)
                {
                    if (rectSelectX != -1 && rectSelectY != -1)
                    {
                        int x0 = Mathf.Min(tileX, rectSelectX);
                        int x1 = Mathf.Max(tileX, rectSelectX);
                        int y0 = Mathf.Min(tileY, rectSelectY);
                        int y1 = Mathf.Max(tileY, rectSelectY);
                        selectedSprites.Clear();
                        for (int y = y0; y <= y1; ++y)
                        {
                            for (int x = x0; x <= x1; ++x)
                            {
                                int id = FindSpriteSlotForSpriteSheetCell(spriteSheetId, x, y);
                                if (id != -1)
                                {
                                    var entry = new SpriteCollectionEditorEntry();
                                    entry.index = id;
                                    selectedSprites.Add(entry);
                                }
                            }
                        }
                        HandleUtility.Repaint();
                    }
                }
                else if (Event.current.type == EventType.MouseUp)
                {
                    rectSelectX = -1;
                    rectSelectY = -1;
                }
            }
        }
	string GetEntryTypeString(SpriteCollectionEditorEntry.Type kind)
	{
		switch (kind)
		{
			case SpriteCollectionEditorEntry.Type.Sprite: return "Sprites";
			case SpriteCollectionEditorEntry.Type.SpriteSheet: return "Sprite Sheets";
			case SpriteCollectionEditorEntry.Type.Font: return "Fonts";
		}
		
		Debug.LogError("Unhandled type");
		return "";
	}
	// populate the entries struct for display in the listbox
	void PopulateEntries()
	{
		entries = new List<SpriteCollectionEditorEntry>();
		selectedEntries = new List<SpriteCollectionEditorEntry>();
		if (spriteCollectionProxy == null)
			return;

		for (int spriteIndex = 0; spriteIndex < spriteCollectionProxy.textureParams.Count; ++spriteIndex)
		{
			var sprite = spriteCollectionProxy.textureParams[spriteIndex];
			var spriteSourceTexture = sprite.texture;
			if (spriteSourceTexture == null && sprite.name.Length == 0) continue;
			
			var newEntry = new SpriteCollectionEditorEntry();
			newEntry.name = sprite.name;

			if (sprite.texture == null) {
				newEntry.name += " (missing)";
			}

			newEntry.index = spriteIndex;
			newEntry.type = SpriteCollectionEditorEntry.Type.Sprite;
			entries.Add(newEntry);
		}
		
		for (int i = 0; i < spriteCollectionProxy.spriteSheets.Count; ++i)
		{
			var spriteSheet = spriteCollectionProxy.spriteSheets[i];
			if (!spriteSheet.active) continue;
			
			var newEntry = new SpriteCollectionEditorEntry();
			newEntry.name = spriteSheet.Name;
			newEntry.index = i;
			newEntry.type = SpriteCollectionEditorEntry.Type.SpriteSheet;
			entries.Add(newEntry);
		}
		
		for (int i = 0; i < spriteCollectionProxy.fonts.Count; ++i)
		{
			var font = spriteCollectionProxy.fonts[i];
			if (!font.active) continue;
			
			var newEntry = new SpriteCollectionEditorEntry();
			newEntry.name = font.Name;
			newEntry.index = i;
			newEntry.type = SpriteCollectionEditorEntry.Type.Font;
			entries.Add(newEntry);
		}
		
		OnSpriteCollectionSortChanged();
		selectedEntries = new List<SpriteCollectionEditorEntry>();
	}
		public void Select(tk2dSpriteSheetSource spriteSheet, int[] ids)
		{
			selectedSprites.Clear();
			activeSelectedSprites.Clear();
			rectSelectX = rectSelectY = -1;
			textureViewScrollBar = Vector2.zero;
			inspectorScrollBar = Vector2.zero;
			activeSpriteSheetSource = spriteSheet;
			selectedMode = EditMode.Edit;	
			
			foreach (int id in ids)
			{
				var v = new SpriteCollectionEditorEntry();
				v.index = id;
				selectedSprites.Add(v);
			}
		}
		void ProcessSpriteSelectionUI(tk2dSpriteSheetSource spriteSheet, Rect rect)
		{
			int spriteSheetId = SpriteCollection.GetSpriteSheetId(spriteSheet);
			if (rect.Contains(Event.current.mousePosition))
			{
				Vector2 localMousePos = (Event.current.mousePosition - new Vector2(rect.x, rect.y)) / zoomAmount;
				int tileX = ((int)localMousePos.x - spriteSheet.tileMarginX) / (spriteSheet.tileSpacingX + spriteSheet.tileWidth);
				int tileY = ((int)localMousePos.y - spriteSheet.tileMarginY) / (spriteSheet.tileSpacingY + spriteSheet.tileHeight);
				int numTilesX, numTilesY;
				GetNumTilesForSpriteSheet(spriteSheet, out numTilesX, out numTilesY);
				
				if (Event.current.type == EventType.MouseDown)
				{
					bool multiSelectKey = (Application.platform == RuntimePlatform.OSXEditor)?Event.current.command:Event.current.control;
					if (tileX >= 0 && tileX < numTilesX && tileY >= 0 && tileY < numTilesY)
					{
						if (!multiSelectKey)
							selectedSprites.Clear();
						
						int id = FindSpriteSlotForSpriteSheetCell(SpriteCollection.GetSpriteSheetId(spriteSheet), tileX, tileY);
						if (id != -1)
						{
							if (!multiSelectKey)
							{
								rectSelectX = tileX;
								rectSelectY = tileY;
							}
							
							bool found = false;
							foreach (var sel in selectedSprites)
							{
								if (sel.index == id)
								{
									found = true;
									selectedSprites.Remove(sel);
									break;
								}
							}
							if (!found)
							{
								var entry = new SpriteCollectionEditorEntry();
								entry.index = id;
								selectedSprites.Add(entry);
							}
							HandleUtility.Repaint();
						}
					}
				}
				else if (Event.current.type == EventType.MouseDrag)
				{
					if (rectSelectX != -1 && rectSelectY != -1)
					{
						int x0 = Mathf.Min(tileX, rectSelectX);
						int x1 = Mathf.Max(tileX, rectSelectX);
						int y0 = Mathf.Min(tileY, rectSelectY);
						int y1 = Mathf.Max(tileY, rectSelectY);
						selectedSprites.Clear();
						for (int y = y0; y <= y1; ++y)
						{
							for (int x = x0; x <= x1; ++x)
							{
								int id = FindSpriteSlotForSpriteSheetCell(spriteSheetId, x, y);
								if (id != -1)
								{
									var entry = new SpriteCollectionEditorEntry();
									entry.index = id;
									selectedSprites.Add(entry);
								}
							}
						}
						HandleUtility.Repaint();
					}
				}
				else if (Event.current.type == EventType.MouseUp)
				{
					rectSelectX = -1;
					rectSelectY = -1;
				}
			}			
		}