103 lines
2.7 KiB
C#
103 lines
2.7 KiB
C#
// ***********************************************************************
|
|
// Assembly : Unity
|
|
// Author : Kimch
|
|
// Created : 2018-04-28
|
|
//
|
|
// Last Modified By : Kimch
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "KUIFxNode" company="ddl"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class KUIFxNode : MonoBehaviour
|
|
{
|
|
public bool addRaycaster;
|
|
|
|
public int relativeOrder = 1;
|
|
public bool scale;
|
|
|
|
// Use this for initialization
|
|
private void Start()
|
|
{
|
|
var canvas = GetComponentInParent<Canvas>();
|
|
if (!canvas)
|
|
{
|
|
//Debug.Log(this.name);
|
|
return;
|
|
}
|
|
var sortingLayerID = canvas.sortingLayerID;
|
|
var sortingOrder = canvas.sortingOrder;
|
|
|
|
//
|
|
if (GetComponent<Graphic>())
|
|
{
|
|
var addCanvas = GetComponent<Canvas>();
|
|
if (!addCanvas)
|
|
{
|
|
addCanvas = this.gameObject.AddComponent<Canvas>();
|
|
if (addRaycaster)
|
|
this.gameObject.AddComponent<GraphicRaycaster>();
|
|
}
|
|
|
|
SetSorting(addCanvas, sortingLayerID, sortingOrder);
|
|
}
|
|
else
|
|
{
|
|
var prList = F.ListPool<Renderer>.Get();
|
|
GetComponentsInChildren(true, prList);
|
|
SetSorting(prList, sortingLayerID, sortingOrder);
|
|
if (scale)
|
|
{
|
|
scale = false;
|
|
SetScale(prList);
|
|
}
|
|
F.ListPool<Renderer>.Release(prList);
|
|
}
|
|
}
|
|
|
|
public void SetSorting(IList<Renderer> renderers, int sortingLayerID, int sortingOrder)
|
|
{
|
|
foreach (var pr in renderers)
|
|
{
|
|
pr.sortingLayerID = sortingLayerID;
|
|
pr.sortingOrder = sortingOrder + relativeOrder;
|
|
}
|
|
}
|
|
|
|
public void SetSorting(Canvas canvas, int sortingLayerID, int sortingOrder)
|
|
{
|
|
canvas.overrideSorting = true;
|
|
canvas.sortingLayerID = sortingLayerID;
|
|
canvas.sortingOrder = sortingOrder + relativeOrder;
|
|
}
|
|
|
|
public void SetScale(IList<Renderer> renderers)
|
|
{
|
|
Vector2 screenSize = new Vector2(Screen.width, Screen.height);
|
|
CanvasScaler scaler = KUIRoot.Instance.GetComponent<CanvasScaler>();
|
|
if (scaler.screenMatchMode == CanvasScaler.ScreenMatchMode.MatchWidthOrHeight)
|
|
{
|
|
float logWidth = screenSize.x / scaler.referenceResolution.x;
|
|
float logHeight = screenSize.y / scaler.referenceResolution.y;
|
|
var logWeightedAverage = Mathf.Lerp(logHeight, logWidth, scaler.matchWidthOrHeight);
|
|
foreach (var pr in renderers)
|
|
{
|
|
pr.transform.localScale *= logWeightedAverage;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetMask(IList<ParticleSystemRenderer> renderers, SpriteMaskInteraction maskInteraction)
|
|
{
|
|
foreach (var pr in renderers)
|
|
{
|
|
pr.maskInteraction = maskInteraction;
|
|
}
|
|
}
|
|
}
|