[TASK] Content fixes

This commit is contained in:
2019-08-26 00:51:03 +02:00
parent b4543142de
commit dc140068d6
24 changed files with 433 additions and 15 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Globalization;
using EasyButtons;
using Mapbox.Unity.Utilities;
using Mapbox.Utils;
using Unity.Collections;
@@ -48,4 +49,11 @@ public class CollectableDuckData: ScriptableObject
public GameObject ModelPrefab => _modelPrefab;
public DuckStickerData StickerData => stickerData;
[Button]
public void RegenerateId()
{
_id = Guid.NewGuid().ToString();
}
}

View File

@@ -37,6 +37,7 @@ public class CollectableDuckManager : MonoBehaviour
private void Awake()
{
CheckCollectableDuckIds();
_collectedDucks.Clear();
foreach (var duck in collectableDucks.Where(duck => PlayerPrefs.GetInt("duck." + duck.Id) > 0))
{
@@ -44,6 +45,20 @@ public class CollectableDuckManager : MonoBehaviour
}
}
private void CheckCollectableDuckIds()
{
var duckIds = new HashSet<string>();
foreach (var duck in collectableDucks)
{
if (duckIds.Contains(duck.Id))
{
Debug.LogError("Duplicate duck ID: '" + duck.Id + "' for duck '" + duck.name + "'");
}
duckIds.Add(duck.Id);
}
}
private void Update()
{
var ruler = new CheapRuler(map.CenterLatitudeLongitude.x, CheapRulerUnits.Meters);

View File

@@ -1,6 +1,8 @@
using System;
using EasyButtons;
using Unity.Collections;
using UnityEngine;
using UnityEngine.UIElements;
[CreateAssetMenu(fileName = "sticker", menuName = "Duck/Sticker", order = 10)]
[Serializable]
@@ -21,4 +23,10 @@ public class DuckStickerData: ScriptableObject
public string Label => _label;
public Sprite StickerSprite => _stickerSprite;
[Button]
public void RegenerateId()
{
_id = Guid.NewGuid().ToString();
}
}

View File

@@ -37,11 +37,26 @@ public class DuckStickerManager : MonoBehaviour
private void Awake()
{
CheckDuckStickers();
foreach (var sticker in duckStickers)
{
_collectedStickers.Add(sticker, PlayerPrefs.GetInt("sticker." + sticker.Id));
}
}
private void CheckDuckStickers()
{
var duckIds = new HashSet<string>();
foreach (var duck in duckStickers)
{
if (duckIds.Contains(duck.Id))
{
Debug.LogError("Duplicate duck ID: '" + duck.Id + "' for duck '" + duck.name + "'");
}
duckIds.Add(duck.Id);
}
}
public void OnStickerCollected(DuckStickerData sticker)
{

View File

@@ -12,6 +12,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 7d3768bc9b4537545bf3c5ae5663e033, type: 3}
m_Name: french
m_EditorClassIdentifier:
_id: 75ad3ee9-8249-49fe-95ca-9eff9117708f
_label: De nerd
_id: 50c2d884-e7e7-434b-9d60-6f3e839798b1
_label: De fransman
_stickerSprite: {fileID: 21300000, guid: 6548d657c349d214487c9cb85103ff8b, type: 3}

View File

@@ -12,6 +12,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 7d3768bc9b4537545bf3c5ae5663e033, type: 3}
m_Name: heart
m_EditorClassIdentifier:
_id: 75ad3ee9-8249-49fe-95ca-9eff9117708f
_id: 25686344-8c71-4bea-8aa3-11de2fd12887
_label: Het torteleendje
_stickerSprite: {fileID: 21300000, guid: 6548d657c349d214487c9cb85103ff8b, type: 3}
_stickerSprite: {fileID: 21300000, guid: b0b9923bdf99a4343ae003860ebe7497, type: 3}

8
Assets/EasyButtons.meta Normal file
View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6d787c0dbf4c14c41a5f64f5f24e3f71
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,81 @@
using System;
namespace EasyButtons
{
public enum ButtonMode
{
AlwaysEnabled,
EnabledInPlayMode,
DisabledInPlayMode
}
[Flags]
public enum ButtonSpacing
{
None = 0,
Before = 1,
After = 2
}
/// <summary>
/// Attribute to create a button in the inspector for calling the method it is attached to.
/// The method must have no arguments.
/// </summary>
/// <example>
/// [Button]
/// public void MyMethod()
/// {
/// Debug.Log("Clicked!");
/// }
/// </example>
[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public sealed class ButtonAttribute : Attribute
{
private string name = null;
private ButtonMode mode = ButtonMode.AlwaysEnabled;
private ButtonSpacing spacing = ButtonSpacing.None;
public string Name { get { return name; } }
public ButtonMode Mode { get { return mode; } }
public ButtonSpacing Spacing { get { return spacing; } }
public ButtonAttribute()
{
}
public ButtonAttribute(string name)
{
this.name = name;
}
public ButtonAttribute(ButtonMode mode)
{
this.mode = mode;
}
public ButtonAttribute(ButtonSpacing spacing)
{
this.spacing = spacing;
}
public ButtonAttribute(string name, ButtonMode mode)
{
this.name = name;
this.mode = mode;
}
public ButtonAttribute(string name, ButtonSpacing spacing)
{
this.name = name;
this.spacing = spacing;
}
public ButtonAttribute(string name, ButtonMode mode, ButtonSpacing spacing)
{
this.name = name;
this.mode = mode;
this.spacing = spacing;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 36f9f413a12a9074ead2027c1aa7b6ab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,61 @@
using UnityEngine;
namespace EasyButtons
{
public class ButtonsExample : MonoBehaviour
{
// Example use of the ButtonAttribute
[Button]
public void SayMyName()
{
Debug.Log(name);
}
// Example use of the ButtonAttribute that is not shown in play mode
[Button(ButtonMode.DisabledInPlayMode)]
protected void SayHelloEditor()
{
Debug.Log("Hello from edit mode");
}
// Example use of the ButtonAttribute that is only shown in play mode
[Button(ButtonMode.EnabledInPlayMode)]
private void SayHelloInRuntime()
{
Debug.Log("Hello from play mode");
}
// Example use of the ButtonAttribute with custom name
[Button("Special Name", ButtonSpacing.Before)]
private void TestButtonName()
{
Debug.Log("Hello from special name button");
}
// Example use of the ButtonAttribute with custom name and button mode
[Button("Special Name Editor Only", ButtonMode.DisabledInPlayMode)]
private void TestButtonNameEditorOnly()
{
Debug.Log("Hello from special name button for editor only");
}
// Example use of the ButtonAttribute with static method
[Button]
private static void TestStaticMethod()
{
Debug.Log("Hello from static method");
}
// Example use of the ButtonAttribute with ButtonSpacing, and mix two spacing together.
[Button("Space Before and After", ButtonSpacing.Before | ButtonSpacing.After)]
private void TestButtonSpaceBoth() {
Debug.Log("Hello from a button surround by spaces");
}
// Placeholder to show the last button have space after it.
[Button("Another Button")]
private void TestButtonEndSpace() {
Debug.Log("Hello I am here to show some spacing.");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 803cb9aa6c767b14ab0c93f41cd7aeef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
using UnityEngine;
namespace EasyButtons
{
public class CustomEditorButtonsExample : MonoBehaviour
{
[Button("Custom Editor Example")]
private void SayHello()
{
Debug.Log("Hello from custom editor");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5d318038542ab134cb5b81aa46a97e6b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 61aca73fced8c3d4eb17aa81e23af020
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
using UnityEditor;
namespace EasyButtons
{
/// <summary>
/// Custom inspector for Object including derived classes.
/// </summary>
[CanEditMultipleObjects]
[CustomEditor(typeof(UnityEngine.Object), true)]
public class ObjectEditor : Editor
{
public override void OnInspectorGUI()
{
this.DrawEasyButtons();
// Draw the rest of the inspector as usual
DrawDefaultInspector();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a7a3384be8a368e4c8e870e5feedb31d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
using UnityEditor;
namespace EasyButtons
{
[CustomEditor(typeof(CustomEditorButtonsExample))]
public class CustomEditorButtonsExampleEditor : Editor
{
public override void OnInspectorGUI()
{
this.DrawEasyButtons();
base.OnInspectorGUI();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f42477c48fa930844bbbf0ba8cf55828
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,49 @@
using System;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace EasyButtons
{
public static class EasyButtonsEditorExtensions
{
public static void DrawEasyButtons(this Editor editor)
{
// Loop through all methods with no parameters
var methods = editor.target.GetType()
.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
.Where(m => m.GetParameters().Length == 0);
foreach (var method in methods)
{
// Get the ButtonAttribute on the method (if any)
var ba = (ButtonAttribute)Attribute.GetCustomAttribute(method, typeof(ButtonAttribute));
if (ba != null)
{
// Determine whether the button should be enabled based on its mode
var wasEnabled = GUI.enabled;
GUI.enabled = ba.Mode == ButtonMode.AlwaysEnabled
|| (EditorApplication.isPlaying ? ba.Mode == ButtonMode.EnabledInPlayMode : ba.Mode == ButtonMode.DisabledInPlayMode);
if (((int)ba.Spacing & (int)ButtonSpacing.Before) != 0) GUILayout.Space(10);
// Draw a button which invokes the method
var buttonName = String.IsNullOrEmpty(ba.Name) ? ObjectNames.NicifyVariableName(method.Name) : ba.Name;
if (GUILayout.Button(buttonName))
{
foreach (var t in editor.targets)
{
method.Invoke(t, null);
}
}
if (((int)ba.Spacing & (int)ButtonSpacing.After) != 0) GUILayout.Space(10);
GUI.enabled = wasEnabled;
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4f80fb24d5fa6b441bd6c9d7b25f04cb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
using UnityEngine;
namespace EasyButtons
{
[CreateAssetMenu(fileName = "ScriptableObjectExample.asset", menuName = "EasyButtons/ScriptableObjectExample")]
public class ScriptableObjectExample : ScriptableObject
{
[Button]
public void SayHello()
{
Debug.Log("Hello");
}
[Button(ButtonMode.DisabledInPlayMode)]
public void SayHelloEditor()
{
Debug.Log("Hello from edit mode");
}
[Button(ButtonMode.EnabledInPlayMode)]
public void SayHelloPlayMode()
{
Debug.Log("Hello from play mode");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ac23267699d149848936a2a4e614be65
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -7,7 +7,7 @@ public class PlayerCameraController : MonoBehaviour
public float xSpeed = 1.0f;
public float ySpeed = 20.0f;
public float yMinLimit = 5;
public float yMaxLimit = 1300f;
public float yMaxLimit = 130f;
public float zoomSpeedDesktop = 20f;
public float zoomSpeedMobile = 20f;
public float distanceMin = 10f;
@@ -34,11 +34,26 @@ public class PlayerCameraController : MonoBehaviour
{
if (target)
{
if (Input.GetMouseButton(0))
Vector2 movementInputDelta = Vector2.zero;
if (SystemInfo.deviceType == DeviceType.Handheld)
{
velocityX = xSpeed * Input.GetAxis("Mouse X") * distance * 0.02f;
velocityY = ySpeed * Input.GetAxis("Mouse Y") * 0.02f;
if (Input.touchCount == 1)
{
movementInputDelta = Input.touches[0].deltaPosition * 0.02f;
}
}
else
{
if (Input.GetMouseButton(0))
{
movementInputDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
}
}
movementInputDelta *= 0.2f;
velocityX = xSpeed * movementInputDelta.x * distance;
velocityY = ySpeed * movementInputDelta.y;
rotationYAxis += velocityX;
rotationXAxis -= velocityY;
rotationXAxis = ClampAngle(rotationXAxis, yMinLimit, yMaxLimit);
@@ -84,7 +99,7 @@ public class PlayerCameraController : MonoBehaviour
float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;
// Find the difference in the distances between each frame.
return (prevTouchDeltaMag - touchDeltaMag) * zoomSpeedMobile;
return - (prevTouchDeltaMag - touchDeltaMag) * zoomSpeedMobile;
}
else
{

View File

@@ -1094,7 +1094,7 @@ Canvas:
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_AdditionalShaderChannelsFlag: 25
m_AdditionalShaderChannelsFlag: 0
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
@@ -2034,12 +2034,12 @@ MonoBehaviour:
m_EditorClassIdentifier:
target: {fileID: 100802250}
distance: 50
xSpeed: 15
ySpeed: 150
xSpeed: 3
ySpeed: 30
yMinLimit: 5
yMaxLimit: 1300
yMaxLimit: 130
zoomSpeedDesktop: 20
zoomSpeedMobile: 20
zoomSpeedMobile: 0.2
distanceMin: 10
distanceMax: 150
smoothTime: 2
@@ -2873,7 +2873,7 @@ MonoBehaviour:
Id: mapbox.terrain-rgb
Modified:
UserName:
elevationLayerType: 1
elevationLayerType: 0
requiredOptions:
exaggerationFactor: 1
colliderOptions: