Showing posts with label Reflection. Show all posts
Showing posts with label Reflection. Show all posts

Tuesday, July 28, 2015

Custom TimeArea Ruller Unity3d

How to create TimeArea the same as seen in Animation Window? Few reflections and voila.



  
    if (__timeAreaW == null) {
                                __timeAreaW = new TimeAreaW (false);

                                
                                __timeAreaW.hSlider = true;
                                __timeAreaW.vSlider = false;
                                __timeAreaW.vRangeLocked = true;
                                __timeAreaW.hRangeMin = 0f;
                                //__timeAreaW.hRangeMax=3f;

                                __timeAreaW.margin = 0f;
                                
                                __timeAreaW.scaleWithWindow = true;
                            
                                //__timeAreaW.ignoreScrollWheelUntilClicked = false;
                                if(__sequence!=null)
                                    __timeAreaW.hTicks.SetTickModulosForFrameRate (__sequence.frameRate);
                                else
                                    __timeAreaW.hTicks.SetTickModulosForFrameRate (30);

                                this.Repaint ();
            
                                
            
                        }
Source:

Sunday, April 12, 2015

Unity3d Hybird Serialization UnityVariable


Serialization/Deserialization is hidden Diablo inside Unity. 
You can fight it( remember you are on their ground!!!) and create your own custom system based on Protobuf, JSON (I dislike it)... or some other, or you can bend the knee. I choose to make hybrid. 
I left Unity to take care of everything that subclass UnityObject + UnityEvent and create custom serialization for the rest thru C# built in BinaryFormatter. BinaryFormatter know how to serialize .NET types, but for Unity primitive types( Vector3, Rect, AnimationCurve,...) you need to create Surrogates. Which is more boring then some complex task.



Part of custom serialized data should be saved somewhere, so can be deserialized. Some solutions are using binary files (ex .dat,.bin) which is ok. But I disapprove solutions that put binary data, previous convert into Base64, into PlayerPref as string. As I found out that Unity know how to serialize ByteArray, I implemented new ISerializationCallbackReceiver and return the ball back to Unity letting Unity ser/des ByteArray of custom serialized data.





Where to use it?
You can create Blackboard with list of variables that can be add/change/removed without code having visual programming in hand.



You can create your variable inside your inspectors/editors:

[UnityVariablePropertyAttribute(typeof(float))]
    public UnityVariable variable6;


[UnityVariablePropertyAttribute(typeof(AnimationClip))]
    public UnityVariable variable7;


Then you can use Raw value ex. 5.6f or Bind to some other GameObject/Component float property or reference variable from Blackboard making your tools more flexible.



Source: GITHUB

Unity3d Curve Editor


No Curves No Sex. Seem that curves are one of most important things in Unity. Why Unity not opensource the editor components, similar like Unity UI 5.0 model, or at least to remove those internal modifiers to component's classes is MYSTERY. Here it is Unity Curve Editor exposed so you can used it Editors or Inspectors. Curve editor inside Inspector where you can add/edit/remove multiply curves. https://youtu.be/CAV_faETDvA?t=364
Usage:
Source code: