| @@ -0,0 +1,88 @@ | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
| using UnityEngine.EventSystems; | ||
| using UnityEngine.UI; | ||
|
|
||
| [RequireComponent(typeof(Image))] | ||
| public class DragMe : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler | ||
| { | ||
| public bool dragOnSurfaces = true; | ||
|
|
||
| private Dictionary<int,GameObject> m_DraggingIcons = new Dictionary<int, GameObject>(); | ||
| private Dictionary<int, RectTransform> m_DraggingPlanes = new Dictionary<int, RectTransform>(); | ||
|
|
||
| public void OnBeginDrag(PointerEventData eventData) | ||
| { | ||
| var canvas = FindInParents<Canvas>(gameObject); | ||
| if (canvas == null) | ||
| return; | ||
|
|
||
| // We have clicked something that can be dragged. | ||
| // What we want to do is create an icon for this. | ||
| m_DraggingIcons[eventData.pointerId] = new GameObject("icon"); | ||
|
|
||
| m_DraggingIcons[eventData.pointerId].transform.SetParent (canvas.transform, false); | ||
| m_DraggingIcons[eventData.pointerId].transform.SetAsLastSibling(); | ||
|
|
||
| var image = m_DraggingIcons[eventData.pointerId].AddComponent<Image>(); | ||
| // The icon will be under the cursor. | ||
| // We want it to be ignored by the event system. | ||
| var group = m_DraggingIcons[eventData.pointerId].AddComponent<CanvasGroup>(); | ||
| group.blocksRaycasts = false; | ||
|
|
||
| image.sprite = GetComponent<Image>().sprite; | ||
| image.SetNativeSize(); | ||
|
|
||
| if (dragOnSurfaces) | ||
| m_DraggingPlanes[eventData.pointerId] = transform as RectTransform; | ||
| else | ||
| m_DraggingPlanes[eventData.pointerId] = canvas.transform as RectTransform; | ||
|
|
||
| SetDraggedPosition(eventData); | ||
| } | ||
|
|
||
| public void OnDrag(PointerEventData eventData) | ||
| { | ||
| if (m_DraggingIcons[eventData.pointerId] != null) | ||
| SetDraggedPosition(eventData); | ||
| } | ||
|
|
||
| private void SetDraggedPosition(PointerEventData eventData) | ||
| { | ||
| if (dragOnSurfaces && eventData.pointerEnter != null && eventData.pointerEnter.transform as RectTransform != null) | ||
| m_DraggingPlanes[eventData.pointerId] = eventData.pointerEnter.transform as RectTransform; | ||
|
|
||
| var rt = m_DraggingIcons[eventData.pointerId].GetComponent<RectTransform>(); | ||
| Vector3 globalMousePos; | ||
| if (RectTransformUtility.ScreenPointToWorldPointInRectangle(m_DraggingPlanes[eventData.pointerId], eventData.position, eventData.pressEventCamera, out globalMousePos)) | ||
| { | ||
| rt.position = globalMousePos; | ||
| rt.rotation = m_DraggingPlanes[eventData.pointerId].rotation; | ||
| } | ||
| } | ||
|
|
||
| public void OnEndDrag(PointerEventData eventData) | ||
| { | ||
| if (m_DraggingIcons[eventData.pointerId] != null) | ||
| Destroy(m_DraggingIcons[eventData.pointerId]); | ||
|
|
||
| m_DraggingIcons[eventData.pointerId] = null; | ||
| } | ||
|
|
||
| static public T FindInParents<T>(GameObject go) where T : Component | ||
| { | ||
| if (go == null) return null; | ||
| var comp = go.GetComponent<T>(); | ||
|
|
||
| if (comp != null) | ||
| return comp; | ||
|
|
||
| var t = go.transform.parent; | ||
| while (t != null && comp == null) | ||
| { | ||
| comp = t.gameObject.GetComponent<T>(); | ||
| t = t.parent; | ||
| } | ||
| return comp; | ||
| } | ||
| } |
| @@ -0,0 +1,48 @@ | ||
| using UnityEngine; | ||
| using UnityEngine.UI; | ||
| using UnityEngine.EventSystems; | ||
| using System.Collections; | ||
|
|
||
| public class DragPanel : MonoBehaviour, IPointerDownHandler, IDragHandler { | ||
|
|
||
| private Vector2 originalLocalPointerPosition; | ||
| private Vector3 originalPanelLocalPosition; | ||
| private RectTransform panelRectTransform; | ||
| private RectTransform parentRectTransform; | ||
|
|
||
| void Awake () { | ||
| panelRectTransform = transform.parent as RectTransform; | ||
| parentRectTransform = panelRectTransform.parent as RectTransform; | ||
| } | ||
|
|
||
| public void OnPointerDown (PointerEventData data) { | ||
| originalPanelLocalPosition = panelRectTransform.localPosition; | ||
| RectTransformUtility.ScreenPointToLocalPointInRectangle (parentRectTransform, data.position, data.pressEventCamera, out originalLocalPointerPosition); | ||
| } | ||
|
|
||
| public void OnDrag (PointerEventData data) { | ||
| if (panelRectTransform == null || parentRectTransform == null) | ||
| return; | ||
|
|
||
| Vector2 localPointerPosition; | ||
| if (RectTransformUtility.ScreenPointToLocalPointInRectangle (parentRectTransform, data.position, data.pressEventCamera, out localPointerPosition)) { | ||
| Vector3 offsetToOriginal = localPointerPosition - originalLocalPointerPosition; | ||
| panelRectTransform.localPosition = originalPanelLocalPosition + offsetToOriginal; | ||
| } | ||
|
|
||
| ClampToWindow (); | ||
| } | ||
|
|
||
| // Clamp panel to area of parent | ||
| void ClampToWindow () { | ||
| Vector3 pos = panelRectTransform.localPosition; | ||
|
|
||
| Vector3 minPosition = parentRectTransform.rect.min - panelRectTransform.rect.min; | ||
| Vector3 maxPosition = parentRectTransform.rect.max - panelRectTransform.rect.max; | ||
|
|
||
| pos.x = Mathf.Clamp (panelRectTransform.localPosition.x, minPosition.x, maxPosition.x); | ||
| pos.y = Mathf.Clamp (panelRectTransform.localPosition.y, minPosition.y, maxPosition.y); | ||
|
|
||
| panelRectTransform.localPosition = pos; | ||
| } | ||
| } |
| @@ -0,0 +1,65 @@ | ||
| using System.Reflection; | ||
| using UnityEngine; | ||
| using UnityEngine.EventSystems; | ||
| using UnityEngine.UI; | ||
|
|
||
| public class DropMe : MonoBehaviour, IDropHandler, IPointerEnterHandler, IPointerExitHandler | ||
| { | ||
| public Image containerImage; | ||
| public Image receivingImage; | ||
| private Color normalColor; | ||
| public Color highlightColor = Color.yellow; | ||
|
|
||
| public void OnEnable () | ||
| { | ||
| if (containerImage != null) | ||
| normalColor = containerImage.color; | ||
| } | ||
|
|
||
| public void OnDrop(PointerEventData data) | ||
| { | ||
| containerImage.color = normalColor; | ||
|
|
||
| if (receivingImage == null) | ||
| return; | ||
|
|
||
| Sprite dropSprite = GetDropSprite (data); | ||
| if (dropSprite != null) | ||
| receivingImage.overrideSprite = dropSprite; | ||
| } | ||
|
|
||
| public void OnPointerEnter(PointerEventData data) | ||
| { | ||
| if (containerImage == null) | ||
| return; | ||
|
|
||
| Sprite dropSprite = GetDropSprite (data); | ||
| if (dropSprite != null) | ||
| containerImage.color = highlightColor; | ||
| } | ||
|
|
||
| public void OnPointerExit(PointerEventData data) | ||
| { | ||
| if (containerImage == null) | ||
| return; | ||
|
|
||
| containerImage.color = normalColor; | ||
| } | ||
|
|
||
| private Sprite GetDropSprite(PointerEventData data) | ||
| { | ||
| var originalObj = data.pointerDrag; | ||
| if (originalObj == null) | ||
| return null; | ||
|
|
||
| var dragMe = originalObj.GetComponent<DragMe>(); | ||
| if (dragMe == null) | ||
| return null; | ||
|
|
||
| var srcImage = originalObj.GetComponent<Image>(); | ||
| if (srcImage == null) | ||
| return null; | ||
|
|
||
| return srcImage.sprite; | ||
| } | ||
| } |
| @@ -0,0 +1,24 @@ | ||
| using UnityEngine; | ||
|
|
||
| public class EndButton : MonoBehaviour { | ||
|
|
||
| private GameObject winText; | ||
|
|
||
| void Awake() | ||
| { | ||
| winText = GameObject.FindGameObjectWithTag("Win Text"); | ||
| } | ||
|
|
||
| void Start() | ||
| { | ||
| winText.SetActive(false); | ||
| } | ||
|
|
||
| void OnCollisionEnter2D(Collision2D collider) | ||
| { | ||
| if (collider.gameObject.tag == "Block") | ||
| { | ||
| winText.SetActive(true); | ||
| } | ||
| } | ||
| } |
| @@ -0,0 +1,13 @@ | ||
| using UnityEngine; | ||
| using UnityEngine.UI; | ||
| using System.Collections; | ||
|
|
||
| public class GameManager : MonoBehaviour { | ||
|
|
||
| private Button launchBotton; | ||
|
|
||
| void Start () { | ||
|
|
||
| } | ||
|
|
||
| } |
| @@ -0,0 +1,17 @@ | ||
| using UnityEngine; | ||
| using System.Collections; | ||
|
|
||
| public class StartingBlock : MonoBehaviour { | ||
|
|
||
| public float force = 45; | ||
|
|
||
| public Rigidbody2D rBody; | ||
|
|
||
| void Awake() | ||
| { | ||
| rBody = GetComponent<Rigidbody2D>(); | ||
| } | ||
|
|
||
| public void AddTorque(float torque, ForceMode2D mode = ForceMode2D.Force) { } | ||
|
|
||
| } |
| @@ -0,0 +1,10 @@ | ||
| %YAML 1.1 | ||
| %TAG !u! tag:unity3d.com,2011: | ||
| --- !u!62 &6200000 | ||
| PhysicsMaterial2D: | ||
| m_ObjectHideFlags: 0 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 0} | ||
| m_Name: BouncyBox | ||
| friction: .400000006 | ||
| bounciness: .400000006 |
| @@ -0,0 +1,10 @@ | ||
| %YAML 1.1 | ||
| %TAG !u! tag:unity3d.com,2011: | ||
| --- !u!62 &6200000 | ||
| PhysicsMaterial2D: | ||
| m_ObjectHideFlags: 0 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 0} | ||
| m_Name: Slippery | ||
| friction: 0 | ||
| bounciness: 0 |
| @@ -0,0 +1,10 @@ | ||
| %YAML 1.1 | ||
| %TAG !u! tag:unity3d.com,2011: | ||
| --- !u!62 &6200000 | ||
| PhysicsMaterial2D: | ||
| m_ObjectHideFlags: 0 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 0} | ||
| m_Name: Sticky | ||
| friction: 1 | ||
| bounciness: 0 |
| @@ -0,0 +1,100 @@ | ||
| %YAML 1.1 | ||
| %TAG !u! tag:unity3d.com,2011: | ||
| --- !u!1 &100000 | ||
| GameObject: | ||
| m_ObjectHideFlags: 0 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| serializedVersion: 4 | ||
| m_Component: | ||
| - 4: {fileID: 400000} | ||
| - 212: {fileID: 21200000} | ||
| - 61: {fileID: 6100000} | ||
| - 50: {fileID: 5000000} | ||
| m_Layer: 0 | ||
| m_Name: CratePink | ||
| m_TagString: Untagged | ||
| m_Icon: {fileID: 0} | ||
| m_NavMeshLayer: 0 | ||
| m_StaticEditorFlags: 0 | ||
| m_IsActive: 1 | ||
| --- !u!4 &400000 | ||
| Transform: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 100000} | ||
| m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} | ||
| m_LocalPosition: {x: 26.875, y: 3.5, z: 0} | ||
| m_LocalScale: {x: 1, y: 1, z: 1} | ||
| m_Children: [] | ||
| m_Father: {fileID: 0} | ||
| m_RootOrder: 0 | ||
| --- !u!50 &5000000 | ||
| Rigidbody2D: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 100000} | ||
| m_Mass: 1 | ||
| m_LinearDrag: 0 | ||
| m_AngularDrag: .0500000007 | ||
| m_GravityScale: 3 | ||
| m_FixedAngle: 0 | ||
| m_IsKinematic: 0 | ||
| m_Interpolate: 0 | ||
| m_SleepingMode: 1 | ||
| m_CollisionDetection: 0 | ||
| --- !u!61 &6100000 | ||
| BoxCollider2D: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 100000} | ||
| m_Enabled: 1 | ||
| m_Material: {fileID: 6200000, guid: 8be6341e1ce3f4cec9902bc34f72d20a, type: 2} | ||
| m_IsTrigger: 0 | ||
| m_UsedByEffector: 0 | ||
| m_Offset: {x: .625009537, y: .625220299} | ||
| serializedVersion: 2 | ||
| m_Size: {x: 1.23269653, y: 1.23209572} | ||
| --- !u!212 &21200000 | ||
| SpriteRenderer: | ||
| m_ObjectHideFlags: 1 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 100100000} | ||
| m_GameObject: {fileID: 100000} | ||
| m_Enabled: 1 | ||
| m_CastShadows: 0 | ||
| m_ReceiveShadows: 0 | ||
| m_LightmapIndex: 255 | ||
| m_LightmapIndexDynamic: 255 | ||
| m_LightmapTilingOffset: {x: 1, y: 1, z: 0, w: 0} | ||
| m_LightmapTilingOffsetDynamic: {x: 1, y: 1, z: 0, w: 0} | ||
| m_Materials: | ||
| - {fileID: 2100000, guid: 272ba847f100d4251bb8260575189042, type: 2} | ||
| m_SubsetIndices: | ||
| m_StaticBatchRoot: {fileID: 0} | ||
| m_UseLightProbes: 0 | ||
| m_UseReflectionProbes: 1 | ||
| m_ProbeAnchor: {fileID: 0} | ||
| m_ScaleInLightmap: 1 | ||
| m_PreserveUVs: 0 | ||
| m_AutoUVMaxDistance: .5 | ||
| m_AutoUVMaxAngle: 89 | ||
| m_LightmapParameters: {fileID: 0} | ||
| m_SortingLayerID: 1859086223 | ||
| m_SortingOrder: 0 | ||
| m_Sprite: {fileID: 21300000, guid: 12ef7cbdfe0e143fa858a324456c8979, type: 3} | ||
| m_Color: {r: 1, g: 1, b: 1, a: 1} | ||
| --- !u!1001 &100100000 | ||
| Prefab: | ||
| m_ObjectHideFlags: 1 | ||
| serializedVersion: 2 | ||
| m_Modification: | ||
| m_TransformParent: {fileID: 0} | ||
| m_Modifications: [] | ||
| m_RemovedComponents: [] | ||
| m_ParentPrefab: {fileID: 0} | ||
| m_RootGameObject: {fileID: 100000} | ||
| m_IsPrefabParent: 1 |
| @@ -0,0 +1,21 @@ | ||
| %YAML 1.1 | ||
| %TAG !u! tag:unity3d.com,2011: | ||
| --- !u!84 &8400000 | ||
| RenderTexture: | ||
| m_ObjectHideFlags: 0 | ||
| m_PrefabParentObject: {fileID: 0} | ||
| m_PrefabInternal: {fileID: 0} | ||
| m_Name: RenderTexture | ||
| m_Width: 320 | ||
| m_Height: 240 | ||
| m_AntiAliasing: 4 | ||
| m_DepthFormat: 2 | ||
| m_ColorFormat: 0 | ||
| m_MipMap: 0 | ||
| m_GenerateMips: 1 | ||
| m_SRGB: 0 | ||
| m_TextureSettings: | ||
| m_FilterMode: 1 | ||
| m_Aniso: 0 | ||
| m_MipBias: 0 | ||
| m_WrapMode: 1 |
| @@ -0,0 +1 @@ | ||
| The background image is created by NASA and is in the public domain. |