Skip to content

Instantly share code, notes, and snippets.

@dnkm
dnkm / MainCameraBorder
Last active August 29, 2015 14:17
Gizmo Exampls
using UnityEngine;
using System.Collections;
public class Gizmo : MonoBehaviour {
public bool ShowMainCameraBorder;
void OnDrawGizmos() {
if (ShowMainCameraBorder) {
float z = GetComponent<Camera>().nearClipPlane;
Vector3 max = GetComponent<Camera>().ViewportToWorldPoint(new Vector3(1, 1, z));
@dnkm
dnkm / SnapToGrid
Created March 24, 2015 19:09
Grid Snapping
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class SnapToGrid : MonoBehaviour {
public float cell_size = 1f; // = larghezza/altezza delle celle
private float x, y, z;
void Start() {
@dnkm
dnkm / Constant
Created March 31, 2015 19:26
Unity Mathf.lerp
// constant movement
void Update() {
transform.position = Vector3.Lerp(pos1.position, pos2.position, speed * timer);
if (destination == pos1) {
timer = Mathf.Clamp(timer = Time.deltaTime, 0.0f, 1.0f/speed);
} else {
timer = Mathf.Clamp(timer + Time.deltaTime, 0.0f, 1.0f/speed);
}
}
@dnkm
dnkm / ActivityMethods.java
Last active August 29, 2015 14:18
Android Tutorial Chapter 1 - Getting Started
protected void onCreate(...) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setTextSize(40);
tv.setText("blah");
setContentView(tv); // adds tv as the root view of the activity's layout
}
@dnkm
dnkm / EnableUpButton.java
Last active August 29, 2015 14:18
Android Tutorial Chapter 2 - Action Bar
// enables the "app icon" as the up button
// make sure to declare parent activity in the manifest
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// if minSdkVersion >= 11, use this instead:
// getActionBar().setDisplayHomeAsUpEnabled(true);
@dnkm
dnkm / P1_AndroidManifest.xml
Last active August 29, 2015 14:18
Android Tutorial - Chapter 3 Activity
<!-- Declaring the main "launcher" activity -->
<activity android:name=".MainActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
@dnkm
dnkm / P1_CreateFragment.java
Last active August 29, 2015 14:18
Android Tutorial - Chapter 4 Fragments! (using support library)
// fragment = nested sub-activity w/ its own layout and lifecycle. (modular section of an activity)
// fragment receives the same lifecycle callbacks as its parent activity does
public class ArticleFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.article_view, container, false);
}
}
@dnkm
dnkm / P1_KeyValue.java
Created April 13, 2015 20:18
Android Tutorial - Chapter 5 Saving Data
// use SharedPreferences APIs for small collection of data
// 1. using key
SharedPreferences pref = anyContext.getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
// 2. activity's default
SharedPreferences pref = getAcitivy().getPreferences(Copntext.MODE_PRIVATE);
// Write
SharedPreferences.Editor editor = pref.edit();
@dnkm
dnkm / Homework1.java
Last active April 6, 2016 05:33
homework1
import java.lang.*;
class Homework1 {
public static void main(String args[]) {
int[] testArray = new int[10];
// exercise 1
fillWithRandomIntegers(testArray, 0, 100);
printArray(testArray);
console.log("Hello World");