35 changed files with 5435 additions and 56 deletions
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
@ -0,0 +1,44 @@ |
|||
using UnityEngine; |
|||
|
|||
namespace Core.Tools.AspectAdapters |
|||
{ |
|||
[ExecuteInEditMode] |
|||
[RequireComponent(typeof(Camera))] |
|||
public class CameraVerticalStretchingAdapter : MonoBehaviour |
|||
{ |
|||
[SerializeField] private float _standartCameraSize = 11.75f; |
|||
[SerializeField] private float _standartCameraAngle = 60f; |
|||
|
|||
[SerializeField] private Camera _camera = null; |
|||
|
|||
private void Reset() => |
|||
_camera = GetComponent<Camera>(); |
|||
|
|||
private void Awake() => |
|||
SetCameraSize(); |
|||
|
|||
private void Update() |
|||
{ |
|||
if (Application.isEditor) |
|||
SetCameraSize(); |
|||
} |
|||
|
|||
private void SetCameraSize() |
|||
{ |
|||
if (_camera.orthographic) |
|||
{ |
|||
float newSize = _standartCameraSize / _camera.aspect; |
|||
|
|||
if (_camera.orthographicSize != newSize) |
|||
_camera.orthographicSize = newSize; |
|||
} |
|||
else |
|||
{ |
|||
float newAngle = _standartCameraAngle / _camera.aspect; |
|||
|
|||
if (_camera.fieldOfView != newAngle) |
|||
_camera.fieldOfView = newAngle; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
using UnityEngine; |
|||
using UnityEngine.UI; |
|||
using System; |
|||
|
|||
namespace Core.Tools.AspectAdapters |
|||
{ |
|||
[ExecuteInEditMode] |
|||
[RequireComponent(typeof(CanvasScaler))] |
|||
public sealed class CanvasAspectAdapter : MonoBehaviour |
|||
{ |
|||
[SerializeField] private CanvasScaler _canvasScaler = null; |
|||
|
|||
private void Reset() => |
|||
_canvasScaler = GetComponent<CanvasScaler>(); |
|||
|
|||
private void Awake() |
|||
{ |
|||
_canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; |
|||
_canvasScaler.screenMatchMode = CanvasScaler.ScreenMatchMode.MatchWidthOrHeight; |
|||
|
|||
SetCanvasAspect(); |
|||
} |
|||
|
|||
private void Update() |
|||
{ |
|||
if (Application.isEditor) |
|||
SetCanvasAspect(); |
|||
} |
|||
|
|||
private void SetCanvasAspect() |
|||
{ |
|||
if (Camera.main == null) |
|||
throw new ArgumentNullException("MainCamera not found"); |
|||
|
|||
if (Camera.main.aspect < (_canvasScaler.referenceResolution.x / _canvasScaler.referenceResolution.y)) |
|||
_canvasScaler.matchWidthOrHeight = 0f; |
|||
else |
|||
_canvasScaler.matchWidthOrHeight = 1f; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEngine; |
|||
|
|||
namespace Core.Tools.Pool.Particles |
|||
{ |
|||
[Serializable] |
|||
public sealed class Particle |
|||
{ |
|||
[SerializeField] private string _id = "particle"; |
|||
[SerializeField] private ParticleSystem _prefab = null; |
|||
[SerializeField] private int _startCount = 1; |
|||
|
|||
private List<ParticleSystem> _pool = new List<ParticleSystem>(); |
|||
|
|||
private Transform _summonParent = null; |
|||
|
|||
public string ID => _id; |
|||
|
|||
public void Init(Transform summonParent) |
|||
{ |
|||
_summonParent = summonParent; |
|||
|
|||
for (int i = 0; i < _startCount; i++) |
|||
_pool.Add(GameObject.Instantiate(_prefab, _summonParent)); |
|||
} |
|||
|
|||
public ParticleSystem GetParticleFromPool() |
|||
{ |
|||
ParticleSystem particle = _pool.Where(p => p != null && !p.isPlaying).FirstOrDefault(); |
|||
|
|||
if (particle == null) |
|||
{ |
|||
particle = GameObject.Instantiate(_prefab, _summonParent); |
|||
_pool.Add(particle); |
|||
} |
|||
|
|||
return particle; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using UnityEngine; |
|||
|
|||
namespace Core.Tools.Pool.Particles |
|||
{ |
|||
public sealed class ParticleSpawner : MonoBehaviour |
|||
{ |
|||
[SerializeField] private string _particleName = ""; |
|||
[SerializeField] private bool _spawnOnAwake = true; |
|||
|
|||
private void Start() |
|||
{ |
|||
if (_spawnOnAwake) |
|||
Spawn(); |
|||
} |
|||
|
|||
public void Spawn() => |
|||
ParticlesPool.PlayParticle(_particleName, transform.position, transform.rotation, Vector3.one, transform); |
|||
} |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEngine; |
|||
|
|||
namespace Core.Tools.Pool.Particles |
|||
{ |
|||
[ExecuteInEditMode] |
|||
public sealed class ParticlesPool : MonoBehaviour |
|||
{ |
|||
private static ParticlesPool _current = null; |
|||
|
|||
public static string[] GetParticlesName() |
|||
{ |
|||
if (_current == null) |
|||
return new string[0]; |
|||
|
|||
return _current._particles.Select(p => p.ID).ToArray(); |
|||
} |
|||
|
|||
public static void PlayParticle(string id, Vector3 position, Quaternion rotation, Vector3 scale, Transform parent) |
|||
{ |
|||
if (_current == null) |
|||
throw new ArgumentNullException("ParticlesPool not found on scene"); |
|||
|
|||
Particle particle = _current._particles.Where(p => p.ID == id).FirstOrDefault(); |
|||
|
|||
if (particle == null) |
|||
throw new KeyNotFoundException($"particle with id={id} not found!!!"); |
|||
|
|||
ParticleSystem particleSystem = particle.GetParticleFromPool(); |
|||
|
|||
particleSystem.transform.SetParent(parent); |
|||
particleSystem.transform.position = position; |
|||
particleSystem.transform.rotation = rotation; |
|||
particleSystem.transform.localScale = scale; |
|||
|
|||
particleSystem.Play(); |
|||
} |
|||
|
|||
[SerializeField] private Particle[] _particles = new Particle[0]; |
|||
|
|||
private void OnEnable() => |
|||
_current = this; |
|||
|
|||
private void Awake() |
|||
{ |
|||
if (!Application.isPlaying) |
|||
return; |
|||
|
|||
for (int i = 0; i < _particles.Length; i++) |
|||
_particles[i].Init(transform); |
|||
} |
|||
} |
|||
} |
|||
Binary file not shown.
@ -1 +1 @@ |
|||
0ba7e6792316ae7e255beef2c30122219f6f0082 |
|||
d1c5eb68f3ce5b18f962b2e20f3968ce352e152d |
|||
|
|||
Binary file not shown.
@ -0,0 +1,36 @@ |
|||
using Core.Tools.AspectAdapters; |
|||
using UnityEditor; |
|||
using UnityEngine; |
|||
|
|||
namespace CoreEditor.Tools.AspectAdapters |
|||
{ |
|||
[CustomEditor(typeof(CameraVerticalStretchingAdapter))] |
|||
internal sealed class CameraVerticalStretchingAdapterEditor : Editor |
|||
{ |
|||
public override void OnInspectorGUI() |
|||
{ |
|||
CameraVerticalStretchingAdapter script = (CameraVerticalStretchingAdapter)target; |
|||
|
|||
Camera camera = (Camera)serializedObject.FindProperty("_camera").objectReferenceValue; |
|||
|
|||
serializedObject.Update(); |
|||
|
|||
EditorGUILayout.Space(5); |
|||
|
|||
if (camera.orthographic) |
|||
{ |
|||
GUILayout.Label("Camera size for screen 1x1", EditorStyles.helpBox); |
|||
EditorGUILayout.PropertyField(serializedObject.FindProperty("_standartCameraSize")); |
|||
} |
|||
else |
|||
{ |
|||
GUILayout.Label("Camera angle for screen 1x1", EditorStyles.helpBox); |
|||
EditorGUILayout.PropertyField(serializedObject.FindProperty("_standartCameraAngle")); |
|||
} |
|||
|
|||
EditorGUILayout.Space(5); |
|||
|
|||
serializedObject.ApplyModifiedProperties(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
using Core.Tools.AspectAdapters; |
|||
using UnityEditor; |
|||
using UnityEngine; |
|||
using UnityEngine.UI; |
|||
|
|||
namespace CoreEditor.Tools.AspectAdapters |
|||
{ |
|||
[CustomEditor(typeof(CanvasAspectAdapter))] |
|||
internal sealed class CanvasAspectAdapterEditor : Editor |
|||
{ |
|||
public override void OnInspectorGUI() |
|||
{ |
|||
CanvasAspectAdapter script = (CanvasAspectAdapter)target; |
|||
|
|||
CanvasScaler canvasScaler = (CanvasScaler)serializedObject.FindProperty("_canvasScaler").objectReferenceValue; |
|||
|
|||
canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; |
|||
canvasScaler.screenMatchMode = CanvasScaler.ScreenMatchMode.MatchWidthOrHeight; |
|||
|
|||
EditorGUILayout.Space(5); |
|||
|
|||
GUILayout.Label("Made UI for 16:9 screen", EditorStyles.helpBox); |
|||
|
|||
EditorGUILayout.Space(5); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
using Core.Localization; |
|||
using Core.Tools.Pool.Particles; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UnityEditor; |
|||
|
|||
namespace CoreEditor.Localization |
|||
{ |
|||
[CustomEditor(typeof(ParticleSpawner))] |
|||
public class ParticleSpawnerEditor : Editor |
|||
{ |
|||
public override void OnInspectorGUI() |
|||
{ |
|||
serializedObject.Update(); |
|||
|
|||
EditorGUILayout.Space(5); |
|||
|
|||
SerializedProperty particleName = serializedObject.FindProperty("_particleName"); |
|||
|
|||
List<string> particles = ParticlesPool.GetParticlesName().ToList(); |
|||
|
|||
int currentIndex = particles.IndexOf(particleName.stringValue); |
|||
|
|||
if (currentIndex < 0 && !string.IsNullOrWhiteSpace(particleName.stringValue)) |
|||
{ |
|||
particles.Insert(0, particleName.stringValue); |
|||
currentIndex = 0; |
|||
} |
|||
|
|||
if (particles.Count == 0) |
|||
{ |
|||
currentIndex = 0; |
|||
particles = new List<string> { "None" }; |
|||
} |
|||
|
|||
currentIndex = EditorGUILayout.Popup("ParticleID:", currentIndex, particles.ToArray()); |
|||
|
|||
particleName.stringValue = particles[currentIndex]; |
|||
|
|||
EditorGUILayout.Space(5); |
|||
|
|||
SerializedProperty spawnOnAwake = serializedObject.FindProperty("_spawnOnAwake"); |
|||
|
|||
spawnOnAwake.boolValue = EditorGUILayout.Toggle("Spawn on Awake", spawnOnAwake.boolValue); |
|||
|
|||
EditorGUILayout.Space(5); |
|||
|
|||
serializedObject.ApplyModifiedProperties(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,64 @@ |
|||
using Core.Tools.Pool.Particles; |
|||
using UnityEditor; |
|||
using UnityEngine; |
|||
|
|||
namespace CoreEditor.Localization |
|||
{ |
|||
[CustomEditor(typeof(ParticlesPool))] |
|||
public class ParticlesPoolEditor : Editor |
|||
{ |
|||
public override void OnInspectorGUI() |
|||
{ |
|||
serializedObject.Update(); |
|||
|
|||
SerializedProperty particles = serializedObject.FindProperty("_particles"); |
|||
|
|||
EditorGUILayout.Space(5); |
|||
|
|||
EditorGUILayout.BeginHorizontal("BOX"); |
|||
|
|||
GUILayout.Label("ID", EditorStyles.label); |
|||
GUILayout.Label(" Prefab", EditorStyles.label); |
|||
GUILayout.Label("StartCount", EditorStyles.label, GUILayout.MaxWidth(64)); |
|||
GUILayout.Label("", EditorStyles.label, GUILayout.MaxWidth(64)); |
|||
|
|||
EditorGUILayout.EndHorizontal(); |
|||
|
|||
EditorGUILayout.Space(5); |
|||
|
|||
for (int i = 0; i < particles.arraySize; i++) |
|||
{ |
|||
EditorGUILayout.BeginHorizontal("BOX"); |
|||
|
|||
SerializedProperty particle = particles.GetArrayElementAtIndex(i); |
|||
|
|||
SerializedProperty id = particle.FindPropertyRelative("_id"); |
|||
SerializedProperty prefab = particle.FindPropertyRelative("_prefab"); |
|||
SerializedProperty count = particle.FindPropertyRelative("_startCount"); |
|||
|
|||
|
|||
id.stringValue = EditorGUILayout.TextField(id.stringValue); |
|||
|
|||
EditorGUILayout.PropertyField(prefab, GUIContent.none); |
|||
|
|||
count.intValue = EditorGUILayout.IntField(count.intValue, GUILayout.MaxWidth(64)); |
|||
|
|||
if (GUILayout.Button("Remove", GUILayout.MaxWidth(64))) |
|||
particles.DeleteArrayElementAtIndex(i); |
|||
|
|||
EditorGUILayout.EndHorizontal(); |
|||
} |
|||
|
|||
EditorGUILayout.Space(5); |
|||
|
|||
if (GUILayout.Button("Add")) |
|||
{ |
|||
particles.InsertArrayElementAtIndex(particles.arraySize); |
|||
} |
|||
|
|||
EditorGUILayout.Space(5); |
|||
|
|||
serializedObject.ApplyModifiedProperties(); |
|||
} |
|||
} |
|||
} |
|||
Binary file not shown.
@ -1 +1 @@ |
|||
11bcacb5e6198468d31724d89237cbc3f0ee9953 |
|||
303f7c18877e6d0c94d1ea8312a22f962649285d |
|||
|
|||
Binary file not shown.
Loading…
Reference in new issue