146 lines
3.9 KiB
C#
146 lines
3.9 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using DG.Tweening;
|
||
using static InterfaceManager;
|
||
using System;
|
||
using DG.Tweening.Core;
|
||
|
||
public class FreeSceneItem : MonoBehaviour
|
||
{
|
||
public Image image_icon;
|
||
public RectTransform rect_transform;
|
||
public CanvasGroup canvas_group;
|
||
public SceneItemDetailData free_scene_item_data { get; private set; }
|
||
|
||
/// <summary>
|
||
/// 是否启用
|
||
/// </summary>
|
||
private bool is_active;
|
||
/// <summary>
|
||
/// 是否Init完成
|
||
/// </summary>
|
||
private bool is_inited;
|
||
|
||
/// <summary>
|
||
/// 场景详情数据
|
||
/// 包含所有内置或后期新增的场景数据
|
||
/// </summary>
|
||
public class SceneItemDetailData
|
||
{
|
||
/// <summary>
|
||
/// 场景id
|
||
/// </summary>
|
||
public string scene_id;
|
||
/// <summary>
|
||
/// 场景类型
|
||
/// </summary>
|
||
public string scene_type;
|
||
/// <summary>
|
||
/// 场景名称
|
||
/// </summary>
|
||
public string scene_name;
|
||
/// <summary>
|
||
/// 场景描述
|
||
/// </summary>
|
||
public string scene_description;
|
||
/// <summary>
|
||
/// 相机初始位置
|
||
/// </summary>
|
||
public string init_position;
|
||
/// <summary>
|
||
/// 相机初始角度
|
||
/// </summary>
|
||
public string init_rotation;
|
||
/// <summary>
|
||
/// 图片地址
|
||
/// </summary>
|
||
public string img_url;
|
||
}
|
||
|
||
private float anchor_position_y;
|
||
// Start is called before the first frame update
|
||
void Start()
|
||
{
|
||
|
||
}
|
||
|
||
public void Init(SceneItemDetailData _free_scene_item_data = null, Action _callback = null)
|
||
{
|
||
is_inited = false;
|
||
anchor_position_y = rect_transform.anchoredPosition.y;
|
||
|
||
if (_free_scene_item_data != null)
|
||
free_scene_item_data = _free_scene_item_data;
|
||
|
||
if (free_scene_item_data != null)
|
||
{
|
||
//从streamingasset文件夹读取场景图片
|
||
StartCoroutine(GetSprite(Application.streamingAssetsPath+"/"+free_scene_item_data.img_url, (_sprite) =>
|
||
{
|
||
is_inited = true;
|
||
Debug.Log(free_scene_item_data.scene_name);
|
||
image_icon.sprite = _sprite;
|
||
gameObject.SetActive(is_active);
|
||
}));
|
||
}
|
||
}
|
||
|
||
private void SetAnchoredPositionX(float _x)
|
||
{
|
||
rect_transform.anchoredPosition = new Vector2(_x, anchor_position_y);
|
||
}
|
||
private void SetAnchoredPositionX(float _x, float _y)
|
||
{
|
||
//rect_transform.anchoredPosition = new Vector2(_x, _y);
|
||
rect_transform.DOAnchorPos(new Vector2(_x, _y), 0.25f);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 手动设置显示隐藏状态
|
||
/// </summary>
|
||
/// <param name="_active"></param>
|
||
public void SetActiveManual(bool _active)
|
||
{
|
||
is_active = _active;
|
||
}
|
||
|
||
public void SetAnchoredPositionMiddle(bool _active)
|
||
{
|
||
SetAnchoredPositionX(0, anchor_position_y);
|
||
canvas_group.alpha = 1f;
|
||
transform.SetAsLastSibling();
|
||
if (!is_inited)
|
||
is_active = _active;//若尚未完成Init,则在Init完成后执行SetActive
|
||
else
|
||
gameObject.SetActive(_active);
|
||
}
|
||
|
||
public void SetAnchoredPositionRight()
|
||
{
|
||
SetAnchoredPositionX(rect_transform.rect.width / 2, 0);
|
||
canvas_group.alpha = 0.5f;
|
||
transform.SetSiblingIndex(transform.parent.childCount - 2);
|
||
is_active = true;
|
||
gameObject.SetActive(true);
|
||
}
|
||
|
||
public void SetAnchoredPositionLeft()
|
||
{
|
||
SetAnchoredPositionX(-rect_transform.rect.width / 2, 0);
|
||
canvas_group.alpha = 0.5f;
|
||
transform.SetSiblingIndex(transform.parent.childCount - 3);
|
||
is_active = true;
|
||
gameObject.SetActive(true);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 虚化
|
||
/// </summary>
|
||
public void SetWeakening()
|
||
{
|
||
DOTween.To(() => canvas_group.alpha, (_v) => canvas_group.alpha = _v, 0.1f, 2f);
|
||
}
|
||
}
|