페이지

2017년 5월 30일 화요일

Unity PropertyDrawer ( Custom instpector)






[System.Serializable]
public struct FloatRange{

    //getter,setter방식은 FindPropertyRelative에서 못찾아내서 사용안함.
    public float value,min,max;

    public FloatRange(float pValue, float pMin, float pMax ){
        value = pValue;
        min = pMin;
        max = pMax;
    }
}


[CustomPropertyDrawer(typeof(FloatRange))]
public class FloatRangeDrawer : PropertyDrawer {
 
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label){
        label = EditorGUI.BeginProperty(position, label, property);
        Rect contentPosition = EditorGUI.PrefixLabel(position, label);
        contentPosition.width *= 0.33f;
        EditorGUI.indentLevel = 0;
        EditorGUIUtility.labelWidth = 14f;
        //value
        EditorGUI.PropertyField(contentPosition, property.FindPropertyRelative("value"), GUIContent.none);

        //min
        contentPosition.x += contentPosition.width;
        EditorGUI.PropertyField(contentPosition, property.FindPropertyRelative("min"), new GUIContent(","));
     
        //max
        contentPosition.x += contentPosition.width;
        EditorGUI.PropertyField(contentPosition, property.FindPropertyRelative("max"), new GUIContent("~"));

        EditorGUI.EndProperty();
    }
}

2017년 5월 17일 수요일

cocoapods install and delete

install pods

$ pod init
//make Podfile
$ sudo nano Podfile
$ pod install


delete pods
$ sudo gem install cocoapods-deintegrate cocoapods-clean
$ pod deintegrate
$ pod clean
$ rm Podfile

2017년 5월 15일 월요일

Subclass UIGestureRecognizer

#import <UIKit/UIKit.h>
#import <UIKit/UIGestureRecognizerSubclass.h> // required!!

@interface TouchGestureRecognizer : UIGestureRecognizer
@end


#import "TouchGestureRecognizer.h"
@implementation TouchGestureRecognizer
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    self.state = UIGestureRecognizerStateBegan;
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesEnded:touches withEvent:event];
    self.state = UIGestureRecognizerStateEnded;
}

- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent *)event{
    [super touchesMoved:touches withEvent:event];
    self.state = UIGestureRecognizerStateChanged;
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesCancelled:touches withEvent:event];
    self.state = UIGestureRecognizerStateCancelled;
}


@end