Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
tutorial version commit
Browse files Browse the repository at this point in the history
all things from tutorial
  • Loading branch information
Qwekem482 committed Sep 3, 2022
1 parent 3ef70a1 commit 9f2cb52
Show file tree
Hide file tree
Showing 102 changed files with 7,450 additions and 0 deletions.
55 changes: 55 additions & 0 deletions Assets/Ball.cs
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;
}
}
}
11 changes: 11 additions & 0 deletions Assets/Ball.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Components.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Assets/Components/BallMaterial.physicsMaterial2D
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
8 changes: 8 additions & 0 deletions Assets/Components/BallMaterial.physicsMaterial2D.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Assets/MoveRacket.cs
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;
}
}
11 changes: 11 additions & 0 deletions Assets/MoveRacket.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Plugins.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/Plugins/GitHub.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/Plugins/GitHub/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Assets/Plugins/GitHub/Editor/AsyncBridge.Net35.dll
Git LFS file not shown
34 changes: 34 additions & 0 deletions Assets/Plugins/GitHub/Editor/AsyncBridge.Net35.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 93 additions & 0 deletions Assets/Plugins/GitHub/Editor/ExtensionLoader.cs
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();
}
}
}
}
}
34 changes: 34 additions & 0 deletions Assets/Plugins/GitHub/Editor/ExtensionLoader.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Assets/Plugins/GitHub/Editor/GitHub.Api.45.dll
Git LFS file not shown
33 changes: 33 additions & 0 deletions Assets/Plugins/GitHub/Editor/GitHub.Api.45.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Assets/Plugins/GitHub/Editor/GitHub.Api.dll
Git LFS file not shown
34 changes: 34 additions & 0 deletions Assets/Plugins/GitHub/Editor/GitHub.Api.dll.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9f2cb52

Please sign in to comment.