Skip to content

Instantly share code, notes, and snippets.

@dskjal
dskjal / canvas_newline.js
Last active September 5, 2016 04:33
HTML5 の Canvas でテキストの折り返し
var canvasWidthPx = 640;
var text = "sample text sample text sample text sample text";
var textWidthPx = context.measureText(text).width;
var charWidthPx = Math.ceil(textWidthPx / text.length);
var nWordInLine = Math.floor(canvasWidthPx / charWidthPx);
var nLine = Math.ceil(text.length / nWordInLine);
var wordHeightPx = 60;
for (var i = 0; i < nLine; ++i) {
var render_text = text.substr(i*nWordInLine, (i+1)*nWordInLine);
context.fillText(render_text, 0, 200+(wordHeightPx*i));
@dskjal
dskjal / ugui_break_pos.cs
Last active October 3, 2017 13:50
uGUI で改行位置を取得する
// uGUI Text の Text スクリプトを取得
var t = GameObject.Find("textbox").gameObject.GetComponent<Text>();
// レンダリングするテキスト
t.text = "abcdefghijklmnopqrstuvwxyz01234567890";
// 改行位置等を計算
var generator = new TextGenerator();
var rt = t.GetComponent<RectTransform>();
var size = new Vector2(rt.rect.width, rt.rect.height);
@dskjal
dskjal / ugui_warp.cs
Last active September 22, 2016 21:07
uGUI で禁則処理
// BEGIN MIT LICENSE BLOCK //
//
// Copyright (c) 2016 dskjal
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
//
// END MIT LICENSE BLOCK //
var warps = ",)]}、〕〉》」』】〙〗〟’”⦆»‐゠–〜~?!‼⁇⁈⁉・:;/。.";
var hasWarp = true;
@dskjal
dskjal / CarChaseCamera
Last active November 21, 2016 00:49
Unity でカメラがプレイヤーを追跡する
// BEGIN MIT LICENSE BLOCK //
//
// Copyright (c) 2016 dskjal
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
//
// END MIT LICENSE BLOCK //
using UnityEngine;
[RequireComponent(typeof(Camera))]
@dskjal
dskjal / unity_font_height_in_px.cs
Created September 5, 2016 04:43
Unity でフォントの高さをピクセルで取得する
private int getFontHeight(GUIStyle style) {
var labelSize = style.CalcSize(new GUIContent("ABC"));
return (int)labelSize.y;
}
@dskjal
dskjal / unity_calc_font_size.cs
Last active September 22, 2016 21:06
Unity で適切なフォントサイズを計算
// BEGIN MIT LICENSE BLOCK //
//
// Copyright (c) 2016 dskjal
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
//
// END MIT LICENSE BLOCK //
private void getProperFontSize(GUIStyle style, int nLines, int textAreaHeight) {
int maxHeight = textAreaHeight / nLines;
int curHeight = getFontHeight(style);
@dskjal
dskjal / FpvCamera_bullet_hole.cs
Last active September 22, 2016 21:05
Unity で弾痕を表示する
// BEGIN MIT LICENSE BLOCK //
//
// Copyright (c) 2016 dskjal
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
//
// END MIT LICENSE BLOCK //
using UnityEngine;
public class FpvCamera : MonoBehaviour {
@dskjal
dskjal / TPVCamera.cs
Last active September 22, 2016 21:03
Unity で3人称視点のカメラを制御するスクリプト
// BEGIN MIT LICENSE BLOCK //
//
// Copyright (c) 2016 dskjal
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
//
// END MIT LICENSE BLOCK //
using UnityEngine;
[RequireComponent(typeof(Camera))]
@dskjal
dskjal / snap_ik_fk.py
Last active July 7, 2019 20:57
Blender で IK/FK を一致させる
// BEGIN MIT LICENSE BLOCK //
//
// Copyright (c) 2019 dskjal
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
//
// END MIT LICENSE BLOCK //
import bpy
from bpy.props import *
import mathutils
@dskjal
dskjal / load_external_texture.cs
Last active September 22, 2016 21:05
Unity で Mod をサポートする(外部リソースをロードする)
// BEGIN MIT LICENSE BLOCK //
//
// Copyright (c) 2016 dskjal
// This software is released under the MIT License.
// http://opensource.org/licenses/mit-license.php
//
// END MIT LICENSE BLOCK //
using UnityEngine;
using System.Collections;
using UnityEngine.UI;