You've already forked ParticleEffectForUGUI
mirror of
https://github.com/mob-sakai/ParticleEffectForUGUI.git
synced 2026-05-16 13:10:07 +00:00
# [3.0.0-preview.18](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v3.0.0-preview.17...v3.0.0-preview.18) (2020-08-19) ### Bug Fixes * AsmdefEx is no longer required ([50e749c](50e749c183)) * fix camera for baking mesh ([6395a4f](6395a4fa74)) * support .Net Framework 3.5 (again) ([23fcb06](23fcb06bf9)) ### Features * 3.0.0 updater ([f99292b](f99292b9a1)) * add menu to create UIParticle ([14f1c78](14f1c782ff)) * Combine baked meshes to improve performance ([633d058](633d058756)) * improve performance ([77c056a](77c056ad5f)) * optimization for vertices transforms and adding node for trails ([e070e8d](e070e8d5ee)), closes [#75](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/75) * option to ignoring canvas scaling ([fe85fed](fe85fed3c0)) * support 3d scaling ([42a84bc](42a84bc5e1)) * support custom simulation space ([a83e647](a83e64761c)), closes [#78](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/78) * support for particle systems including trail only ([f389d39](f389d39953)), closes [#61](https://github.com/mob-sakai/ParticleEffectForUGUI/issues/61) ### BREAKING CHANGES * The bake-task has changed significantly. It may look different from previous versions.
120 lines
3.9 KiB
C#
120 lines
3.9 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace Coffee.UIExtensions
|
|
{
|
|
internal class BakingCamera : MonoBehaviour
|
|
{
|
|
static BakingCamera s_Instance;
|
|
|
|
#if UNITY_2018_3_OR_NEWER && UNITY_EDITOR
|
|
static BakingCamera s_InstanceForPrefab;
|
|
|
|
private static BakingCamera InstanceForPrefab
|
|
{
|
|
get
|
|
{
|
|
// If current scene is prefab mode, create OverlayCamera for editor.
|
|
var prefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
|
|
if (prefabStage == null || !prefabStage.scene.isLoaded) return null;
|
|
if (s_InstanceForPrefab) return s_InstanceForPrefab;
|
|
|
|
s_InstanceForPrefab = Create();
|
|
s_InstanceForPrefab.name += " (For Prefab Stage)";
|
|
UnityEngine.SceneManagement.SceneManager.MoveGameObjectToScene(s_InstanceForPrefab.gameObject, prefabStage.scene);
|
|
|
|
return s_InstanceForPrefab;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
private static BakingCamera Instance
|
|
{
|
|
get
|
|
{
|
|
#if UNITY_2018_3_OR_NEWER && UNITY_EDITOR
|
|
var inst = InstanceForPrefab;
|
|
if (inst) return inst;
|
|
#endif
|
|
// Find instance in scene, or create new one.
|
|
return s_Instance
|
|
? s_Instance
|
|
: (s_Instance = FindObjectOfType<BakingCamera>() ?? Create());
|
|
}
|
|
}
|
|
|
|
private Camera _camera;
|
|
private int _refCount;
|
|
|
|
private static BakingCamera Create()
|
|
{
|
|
var gameObject = new GameObject(typeof(BakingCamera).Name);
|
|
|
|
// This camera object is just for internal use
|
|
gameObject.hideFlags = HideFlags.HideAndDontSave;
|
|
gameObject.hideFlags = HideFlags.DontSave;
|
|
|
|
var inst = gameObject.AddComponent<BakingCamera>();
|
|
inst._camera = gameObject.AddComponent<Camera>();
|
|
inst._camera.orthographic = true;
|
|
|
|
// Turn camera off because particle mesh baker will use only camera matrix
|
|
gameObject.SetActive(false);
|
|
|
|
return inst;
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
if (this == s_Instance)
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
|
|
public static void Register()
|
|
{
|
|
Instance._refCount++;
|
|
}
|
|
|
|
public static void Unregister()
|
|
{
|
|
if (s_Instance == null) return;
|
|
|
|
Instance._refCount--;
|
|
if (0 < Instance._refCount) return;
|
|
|
|
if (Application.isPlaying)
|
|
Destroy(Instance.gameObject);
|
|
else
|
|
DestroyImmediate(Instance.gameObject);
|
|
|
|
s_Instance = null;
|
|
}
|
|
|
|
public static Camera GetCamera(Canvas canvas)
|
|
{
|
|
if (!canvas) return Camera.main;
|
|
|
|
canvas = canvas.rootCanvas;
|
|
// Adjust camera orthographic size to canvas size
|
|
// for canvas-based coordinates of particles' size and speed.
|
|
var size = ((RectTransform) canvas.transform).rect.size;
|
|
Instance._camera.orthographicSize = Mathf.Max(size.x, size.y) * canvas.scaleFactor;
|
|
|
|
var camera = canvas.worldCamera;
|
|
var transform = Instance.transform;
|
|
if (canvas.renderMode != RenderMode.ScreenSpaceOverlay && camera)
|
|
{
|
|
var cameraTr = camera.transform;
|
|
transform.SetPositionAndRotation(cameraTr.position, cameraTr.rotation);
|
|
}
|
|
else
|
|
{
|
|
Instance._camera.orthographic = true;
|
|
transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity);
|
|
}
|
|
|
|
return Instance._camera;
|
|
}
|
|
}
|
|
}
|