using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using static InterfaceManager;
using System;
using DG.Tweening.Core;
using TMPro;
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; }
///
/// 是否启用
///
private bool is_active;
///
/// 是否Init完成
///
private bool is_inited;
///
/// 场景详情数据
/// 包含所有内置或后期新增的场景数据
///
public class SceneItemDetailData
{
///
/// 场景id
///
public string scene_id;
///
/// 场景类型
///
public string scene_type;
///
/// 场景名称
///
public string scene_name;
///
/// 场景描述
///
public string scene_description;
///
/// 相机初始位置
///
public string init_position;
///
/// 相机初始角度
///
public string init_rotation;
///
/// 图片地址
///
public string img_url;
}
private float anchor_position_y;
// Start is called before the first frame update
private void OnEnable()
{
// 显示变大图标();
}
private void Update()
{
}
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);
}));
*/
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);
}
///
/// 手动设置显示隐藏状态
///
///
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);
}
///
/// 虚化
///
public void SetWeakening()
{
DOTween.To(() => canvas_group.alpha, (_v) => canvas_group.alpha = _v, 0.1f, 2f);
}
///
/// 虚化
///
public void 显示变大图标()
{
this.transform.GetChild(5).GetComponent().enabled = true;
this.GetComponent().enabled = false;
Debug.Log(free_scene_item_data.scene_name+"当前选中为");
}
public void 缩回原来的图标()
{
this.transform.GetChild(5).GetComponent().enabled = false;
this.GetComponent().enabled = true;
}
}