-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
all things from tutorial
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class Ball : MonoBehaviour | ||
{ | ||
|
||
public float speed = 30; | ||
// Start is called before the first frame update | ||
void Start() | ||
{ | ||
GetComponent<Rigidbody2D>().velocity = Vector2.right * speed; | ||
} | ||
|
||
float hitFactor(Vector2 ballPos, Vector2 racketPos, float racketHeight) | ||
{ | ||
// ascii art: | ||
// || 1 <- at the top of the racket | ||
// || | ||
// || 0 <- at the middle of the racket | ||
// || | ||
// || -1 <- at the bottom of the racket | ||
return (ballPos.y - racketPos.y) / racketHeight; | ||
} | ||
|
||
void OnCollisionEnter2D(Collision2D col) { | ||
// Note: 'col' holds the collision information. If the | ||
// Ball collided with a racket, then: | ||
// col.gameObject is the racket | ||
// col.transform.position is the racket's position | ||
// col.collider is the racket's collider | ||
|
||
//left | ||
if (col.gameObject.name == "RacketLeft") { | ||
float y = hitFactor(transform.position, col.transform.position, col.collider.bounds.size.y); | ||
// Calculate direction, make length=1 via .normalized | ||
Vector2 dir = new Vector2(1, y).normalized; | ||
|
||
// Set Velocity with dir * speed | ||
GetComponent<Rigidbody2D>().velocity = dir * speed; | ||
} | ||
|
||
//right | ||
if (col.gameObject.name == "RacketRight") { | ||
// Calculate hit Factor | ||
float y = hitFactor(transform.position, col.transform.position, col.collider.bounds.size.y); | ||
|
||
// Calculate direction, make length=1 via .normalized | ||
Vector2 dir = new Vector2(-1, y).normalized; | ||
|
||
// Set Velocity with dir * speed | ||
GetComponent<Rigidbody2D>().velocity = dir * speed; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
%YAML 1.1 | ||
%TAG !u! tag:unity3d.com,2011: | ||
--- !u!62 &6200000 | ||
PhysicsMaterial2D: | ||
m_ObjectHideFlags: 0 | ||
m_CorrespondingSourceObject: {fileID: 0} | ||
m_PrefabInstance: {fileID: 0} | ||
m_PrefabAsset: {fileID: 0} | ||
m_Name: BallMaterial | ||
friction: 0.4 | ||
bounciness: 1 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class MoveRacket : MonoBehaviour | ||
{ | ||
public float speed = 30; | ||
public string axis = "Vertical"; | ||
|
||
void FixedUpdate() | ||
{ | ||
float v = Input.GetAxisRaw(axis); | ||
GetComponent<Rigidbody2D>().velocity = new Vector2(0, v) * speed; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
using System.IO; | ||
using System; | ||
|
||
namespace GitHub.Unity | ||
{ | ||
[InitializeOnLoad] | ||
public class ExtensionLoader : ScriptableSingleton<ExtensionLoader> | ||
{ | ||
[SerializeField] private bool initialized = true; | ||
|
||
public bool Initialized | ||
{ | ||
get | ||
{ | ||
return initialized; | ||
} | ||
set | ||
{ | ||
initialized = value; | ||
Save(true); | ||
} | ||
} | ||
|
||
private static bool inSourceMode = false; | ||
private const string sourceModePath = "Assets/Editor/build/"; | ||
private const string realPath = "Assets/Plugins/GitHub/Editor/"; | ||
|
||
private static string[] assemblies20 = { "System.Threading.dll", "AsyncBridge.Net35.dll", "ReadOnlyCollectionsInterfaces.dll", "GitHub.Api.dll", "GitHub.Unity.dll" }; | ||
private static string[] assemblies45 = { "GitHub.Api.45.dll", "GitHub.Unity.45.dll" }; | ||
|
||
private const string GITHUB_UNITY_DISABLE = "GITHUB_UNITY_DISABLE"; | ||
private static bool IsDisabled { get { return Environment.GetEnvironmentVariable(GITHUB_UNITY_DISABLE) == "1"; } } | ||
|
||
static ExtensionLoader() | ||
{ | ||
if (IsDisabled) | ||
{ | ||
return; | ||
} | ||
EditorApplication.update += Initialize; | ||
} | ||
|
||
private static void Initialize() | ||
{ | ||
EditorApplication.update -= Initialize; | ||
|
||
// we're always doing this right now because if the plugin gets updated all the meta files will be disabled and we need to re-enable them | ||
// we should probably detect if our assets change and re-run this instead of doing it every time | ||
//if (!ExtensionLoader.instance.Initialized) | ||
{ | ||
var scriptPath = Path.Combine(Application.dataPath, "Editor" + Path.DirectorySeparatorChar + "GitHub.Unity" + Path.DirectorySeparatorChar + "EntryPoint.cs"); | ||
inSourceMode = File.Exists(scriptPath); | ||
ToggleAssemblies(); | ||
//ExtensionLoader.instance.Initialized = true; | ||
AssetDatabase.SaveAssets(); | ||
} | ||
|
||
} | ||
|
||
private static void ToggleAssemblies() | ||
{ | ||
var path = inSourceMode ? sourceModePath : realPath; | ||
#if NET_4_6 | ||
ToggleAssemblies(path, assemblies20, false); | ||
ToggleAssemblies(path, assemblies45, true); | ||
#else | ||
ToggleAssemblies(path, assemblies45, false); | ||
ToggleAssemblies(path, assemblies20, true); | ||
#endif | ||
} | ||
|
||
private static void ToggleAssemblies(string path, string[] assemblies, bool enable) | ||
{ | ||
foreach (var file in assemblies) | ||
{ | ||
var filepath = path + file; | ||
PluginImporter importer = AssetImporter.GetAtPath(filepath) as PluginImporter; | ||
if (importer == null) | ||
{ | ||
Debug.LogFormat("GitHub for Unity: Could not find importer for {0}. Some functionality may fail.", filepath); | ||
continue; | ||
} | ||
if (importer.GetCompatibleWithEditor() != enable) | ||
{ | ||
importer.SetCompatibleWithEditor(enable); | ||
importer.SaveAndReimport(); | ||
} | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.