Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - rakkarage

Pages: [1]
1
Support / Re: Duplicated sprites in Sprite Collection...
« on: July 15, 2014, 05:14:48 am »
is there any way to automatically remove empty sprites from a collection?
some of my sprite sheets have a large percentage of empty space atm

1024x1024 16x16 tilemap


i have tried doing it manually however i noticed a couple problems with that approach
- empty spaces are filled in with sprites from the next sheet you add (so they become mixed in selector)
- cannot re add them later

is there an easier way or i have to
- cut em all out by hand, ya easier with rect select tool but
- limit the collection to a single sheet so the ids are not reused in empty spaces
- name em all
- can i add some back without recutting the whole sheet and losing all my manual trimming and naming work?
- start all over? cutting and naming?

thanks


2
Support / Re: Saving and Loading TileMaps
« on: June 27, 2014, 04:26:55 pm »
that really seems like overkill... delete and recreate everything just to change a few tiles?

i got it working like suggested elsewhere on this board by just saving the tiles to string and loading from string. with the caveat that you have to set size to max and manage size yourself

i can provide a simple example code if want

https://github.com/jacobdufault/fullserializer

4
Contract Work / Re: [paid] Tilemap pathfinding
« on: June 20, 2014, 04:30:52 am »
check out that code & pics i just posted... a simple astar that works with 2dtoolkit
it will need to be reworked a bit for individual games i guess but


5
Support / Re: Sprite animations
« on: June 19, 2014, 03:24:27 pm »
i was just wondering if there was a better then making 15 animations all the same except start point

for example maybe i can:

- replace the sprite collection on an animation and it will play using the new frames
  - meaning i would need to create a new collection for each mob skin

- use some kind of offset to shift the start position of the animation around on the sprite sheet

please excuse my ignorance
thanks

6
Support / Re: CustomPropertyDrawer & sprites & animations
« on: June 19, 2014, 03:17:25 pm »
i am just trying to make something like this to edit mobs and items


it would be nice to have standalone sprite and animation pickers to define sprites and animations in scriptableObject asset file databases?
http://catlikecoding.com/unity/tutorials/editor/custom-data/



i got the animation picker working by just making a CustomPropertyDrawer for a custom class with two ints...
- i should prob use a path or guid for collection instead of an int but it works for now
- my rect math seems kinda wonky(?) too but it works

Code: [Select]
[Serializable]
public struct DataAnimation
{
public int Collection;
public int Index;
}

Code: [Select]
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace ca.HenrySoftware.Deko
{
[CustomPropertyDrawer(typeof(DataAnimation))]
public class DataAnimationEditor : PropertyDrawer
{
private static float _offset = EditorGUIUtility.singleLineHeight;
private tk2dGenericIndexItem[] _indexes = null;
private string[] _names = null;
private bool _initialized = false;
private void Init()
{
if (!_initialized)
{
_indexes = tk2dEditorUtility.GetOrCreateIndex().GetSpriteAnimations();
if (_indexes != null)
{
_names = new string[_indexes.Length];
for (int i = 0; i < _indexes.Length; i++)
{
_names[i] = _indexes[i].AssetName;
}
}
_initialized = true;
}
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
Init();
if ((_indexes == null) || (_indexes.Length == 0))
{
if (GUI.Button(position, "None! Refresh?"))
{
_initialized = false;
Init();
}
}
else
{
var collectionProperty = property.FindPropertyRelative("Collection");
if (collectionProperty == null) return;
int selectedCollection = collectionProperty.intValue;
float indent = _offset * EditorGUI.indentLevel;
Rect region0 = position;
region0.width = ((position.width - _offset) * .5f) + (indent * .5f);
region0.height = _offset;
collectionProperty.intValue = EditorGUI.Popup(region0, string.Empty, selectedCollection, _names);
if (collectionProperty.intValue != selectedCollection)
{
GUI.changed = true;
}
tk2dSpriteAnimation animation = _indexes[selectedCollection].GetAsset<tk2dSpriteAnimation>();
if ((animation != null) && (animation.clips.Length > 0))
{
List<string> clipNames = new List<string>(animation.clips.Length);
List<int> clipIds = new List<int>(animation.clips.Length);
for (int i = 0; i < animation.clips.Length; i++)
{
if (animation.clips[i].name != null && animation.clips[i].name.Length > 0)
{
string name = animation.clips[i].name;
if (tk2dPreferences.inst.showIds)
{
name += "\t[" + i.ToString() + "]";
}
clipNames.Add(name);
clipIds.Add(i);
}
}
var indexProperty = property.FindPropertyRelative("Index");
if (indexProperty == null) return;
int selectedIndex = ((indexProperty == null) ? 0 : indexProperty.intValue);
region0.x += region0.width - indent;
indexProperty.intValue = EditorGUI.IntPopup(region0, string.Empty, selectedIndex, clipNames.ToArray(), clipIds.ToArray());
if (indexProperty.intValue != selectedIndex)
{
GUI.changed = true;
}
if (Event.current.type == EventType.Repaint)
{
Rect background = position;
background.x = _offset + indent;
background.y += _offset;
background.height = _offset * 2;
background.width = position.width - indent;
tk2dGrid.Draw(background);
Rect region1 = position;
region1.x = _offset + indent;
region1.y += _offset;
region1.width = _offset * 2;
region1.height = region1.width;
if (animation != null)
{
tk2dSpriteAnimationClip clip = animation.clips[indexProperty.intValue];
if (clip != null)
{
foreach (var frame in clip.frames)
{
int spriteId = frame.spriteId;
int first = frame.spriteCollection.FirstValidDefinitionIndex;
tk2dSpriteDefinition def = frame.spriteCollection.spriteDefinitions[first + spriteId];
tk2dSpriteThumbnailCache.DrawSpriteTextureInRect(region1, def, Color.white);
region1.x += region1.width;
}
}
}
}
Rect region2 = position;
region2.x = position.width;
region2.width = _offset;
region2.height = _offset;
if (GUI.Button(region2, GUIContent.none))
{
tk2dSpriteAnimationEditorPopup v = EditorWindow.GetWindow(typeof(tk2dSpriteAnimationEditorPopup), false, "Sprite Animation Editor") as tk2dSpriteAnimationEditorPopup;
v.SetSpriteAnimation(animation);
v.Show();
}
}
property.serializedObject.ApplyModifiedProperties();
}
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return _offset * 3;
}
}
}



but i had more trouble with sprite
i got it working but not without modifying the tk2d source code to remake some methods to not use layout
sure i could have rewritten the cache and buildkeys and Lut and indices and sorting and cache and... but argh... 0 lines of code for a unity3d sprite

if you could add dupes of these two functions that don't use layout and take a rect we could call it from CustomPropertyDrawers without having to edit or recreate the tk2d code

public static tk2dSpriteCollectionData SpriteCollectionList(tk2dSpriteCollectionData currentValue)
public static int SpriteList(string label, int spriteId, tk2dSpriteCollectionData rootSpriteCollection)

thanks a lot

Code: [Select]
[Serializable]
public struct DataSprite
{
public tk2dSpriteCollectionData Collection;
public int Index;
}


Code: [Select]
using UnityEditor;
using UnityEngine;
namespace ca.HenrySoftware.Deko
{
[CustomPropertyDrawer(typeof(DataSprite))]
public class DataSpriteDrawer : PropertyDrawer
{
private static float _offset = EditorGUIUtility.singleLineHeight;
private const string _collectionString = "Collection";
private const string _indexString = "Index";
private tk2dSpriteGuiUtility.SpriteChangedCallback _spriteChangedCallbackInstance = null;
private tk2dSpriteGuiUtility.SpriteChangedCallback spriteChangedCallbackInstance
{
get
{
if (_spriteChangedCallbackInstance == null)
{
_spriteChangedCallbackInstance = new tk2dSpriteGuiUtility.SpriteChangedCallback(SpriteChangedCallbackImpl);
}
return _spriteChangedCallbackInstance;
}
}
private void SpriteChangedCallbackImpl(tk2dSpriteCollectionData spriteCollectionData, int spriteId, object data)
{
SerializedProperty property = data as SerializedProperty;
var collectionProperty = property.FindPropertyRelative(_collectionString);
collectionProperty.objectReferenceValue = spriteCollectionData;
var indexProperty = property.FindPropertyRelative(_indexString);
indexProperty.intValue = spriteId;
property.serializedObject.ApplyModifiedProperties();
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var collectionProperty = property.FindPropertyRelative("Collection");
if (collectionProperty == null) return;
var spriteCollectionData = collectionProperty.objectReferenceValue as tk2dSpriteCollectionData;
var indexProperty = property.FindPropertyRelative("Index");
if (indexProperty == null) return;
var spriteId = indexProperty.intValue;
position.height = _offset;
tk2dSpriteGuiUtility.SpriteSelectorNew(position, spriteCollectionData, spriteId, spriteChangedCallbackInstance, property);
if (spriteCollectionData != null)
{
position.x = _offset + _offset * EditorGUI.indentLevel;
position.y += _offset;
position.width = _offset * 2;
position.height = position.width;
tk2dGrid.Draw(position);
tk2dSpriteDefinition def = spriteCollectionData.spriteDefinitions[spriteId];
tk2dSpriteThumbnailCache.DrawSpriteTextureInRect(position, def, Color.white);
Event ev = Event.current;
if (ev.type == EventType.MouseDown && ev.button == 0 && position.Contains(ev.mousePosition))
{
tk2dSpriteGuiUtility.SpriteSelectorPopup(spriteCollectionData, spriteId, spriteChangedCallbackInstance, property);
}
}
property.serializedObject.ApplyModifiedProperties();
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return _offset * 3;
}
}
}

https://gist.github.com/rakkarage/2e3c01314d276c97f569

7
Support / Re: Rotating Sprite on Touch and Drag
« on: June 18, 2014, 01:33:56 pm »
here is some touchScript (http://interactivelab.github.io/TouchScript/) code for panning
you could do something similar but change rotation instead of position maybe
Code: [Select]
private void HandlePanStateChanged(object s, TouchScript.Events.GestureStateChangeEventArgs e)
{
if (Utility.Paused) return;
Menu.Instance.Close();
switch (e.State)
{
case Gesture.GestureState.Began:
case Gesture.GestureState.Changed:
SimplePanGesture g = (SimplePanGesture)s;
if (g.LocalDeltaPosition != Vector3.zero)
{
GameCamera.transform.localPosition -= g.LocalDeltaPosition / GameCamera.ZoomFactor;
}
break;
case Gesture.GestureState.Ended:
Spring();
break;
}
}

8
Support / Re: Sprite animations
« on: June 17, 2014, 07:59:23 pm »
what about changing sprites in other animations?
if i have one mob with 15 'skins'?
i can and did make 15 'duplicate' (except initial offset) animations but maybe there is a better way?
thanks

9
Support / Re: tk2dGrid in PropertyDrawer
« on: June 16, 2014, 10:37:20 pm »
"Unity has confirmed this is a bug and is working on a fix"
http://answers.unity3d.com/questions/377207/drawing-a-texture-in-a-custom-propertydrawer.html

or wrap the 'propertyDrawer' in an (even empty) 'editor'

10
Support / tk2dGrid in PropertyDrawer
« on: June 16, 2014, 07:26:17 pm »
why does the grid disappear after 1 second? thanks

TestGrid.cs

Code: [Select]
[Serializable]
public struct TestGrid
{
public int Unused;
}
Editor/TestGridEditor.cs

Code: [Select]
[CustomPropertyDrawer(typeof(DataGrid))]
public class TestGridEditor : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
tk2dGrid.Draw(position);
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUIUtility.singleLineHeight;
}
}

11
Support / CustomPropertyDrawer & sprites & animations
« on: June 15, 2014, 02:58:17 pm »
has anyone made tk2dSpriteGuiUtility.SpriteList & SpriteCollectionList
work with CustomPropertyDrawer instead of CustomEditor which means
cannot use GUILayout or EditorGUILayout?

i got the animation drawer working by converting EditorGUILayour.Popup
to EditorGUI.Popup.
but the sprite drawer is more complicated...

thanks

Pages: [1]