Skip to content

Instantly share code, notes, and snippets.

@GeorgiyRyaposov
GeorgiyRyaposov / DataManager.cs
Last active August 5, 2017 10:42
Save\load data with BinaryFormatter\json in Unity3d for builded game or in the editor
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;
//to make BinarySerializer work at iOS devices add somewhere in awake:
//System.Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes");
namespace Assets.Scripts.Tools
{
@GeorgiyRyaposov
GeorgiyRyaposov / ShakeRoutine.cs
Last active March 25, 2017 10:35
Shake routine
public Vector3 shakePower = new Vector3(0.03f, 0.03f, 0.03f);
public float shakeDuration = 1f;
private IEnumerator ShakeRoutine()
{
for (var t = 0f; t < shakeDuration; t += Time.unscaledDeltaTime)
{
var offset = transform.rotation * Vector3.Scale(Random.onUnitSphere, shakePower);
transform.position += offset;
@GeorgiyRyaposov
GeorgiyRyaposov / CloudBuildHelper.cs
Last active December 4, 2022 07:33
Put into 'Editor' folder and add 'CloudBuildHelper.PreExport' class name in unity cloud build to pre export setting
public class CloudBuildHelper
{
#if UNITY_CLOUD_BUILD
public static void PreExport(UnityEngine.CloudBuild.BuildManifestObject manifest)
{
var buildNumber = "unknown";
manifest.TryGetValue("buildNumber", out buildNumber);
UnityEditor.PlayerSettings.bundleVersion = string.Format("1.0.{0}", buildNumber);
@GeorgiyRyaposov
GeorgiyRyaposov / ObjectPool.cs
Last active April 27, 2017 08:04
Unity ObjectPool, pul to scene and set objects, or init from code: Prefab.CreatePool(..); Prefab.Spawn() - spawn object, gameObject.Recycle() - return to pool
using UnityEngine;
using System.Collections.Generic;
namespace Scripts.Common
{
public sealed class ObjectPool : MonoBehaviour
{
public enum StartupPoolMode { Awake, Start, CallManually };
[System.Serializable]
using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scripts.Tools
{
[RequireComponent(typeof(Text))]
public class FPSCounter : MonoBehaviour
{
const float fpsMeasurePeriod = 0.5f;
private int m_FpsAccumulator = 0;
@GeorgiyRyaposov
GeorgiyRyaposov / ModelsImporter.cs
Last active April 15, 2021 09:54
Unity models imported with animation import
namespace Assets.Editor
{
public class ModelsImporter : AssetPostprocessor
{
private void OnPreprocessModel()
{
var modelImporter = assetImporter as ModelImporter;
if (modelImporter == null)
{
Debug.LogError("Error during import of models: ModelImporter is null");
using UnityEngine;
using System;
using System.Collections;
/// <summary>
/// Since unity doesn't flag the Vector3 as serializable, we
/// need to create our own version. This one will automatically convert
/// between Vector3 and SerializableVector3
/// </summary>
[System.Serializable]
using UnityEngine;
using System;
using System.Collections;
/// <summary>
/// Since unity doesn't flag the Quaternion as serializable, we
/// need to create our own version. This one will automatically convert
/// between Quaternion and SerializableQuaternion
/// </summary>
[System.Serializable]
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
namespace Scripts.Utilities
{
public class EmbedText : MonoBehaviour
{
[SerializeField]
private Text textLabel;
#if UNITY_EDITOR
[UnityEditor.CustomEditor(typeof(YourScriptName))]
public class YourScriptNameEditor : UnityEditor.Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
var yourScriptNameInstance = (YourScriptName)target;
if (GUILayout.Button("Button"))