ict.shenzhi/Assets/Scripts/UIManager/Items/FreeSceneItem/FreeSceneItem.cs

177 lines
4.6 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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; }
/// <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
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);
}
/// <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);
}
/// <summary>
/// 虚化
/// </summary>
public void ()
{
this.transform.GetChild(5).GetComponent<Image>().enabled = true;
this.GetComponent<Image>().enabled = false;
Debug.Log(free_scene_item_data.scene_name+"当前选中为");
}
public void ()
{
this.transform.GetChild(5).GetComponent<Image>().enabled = false;
this.GetComponent<Image>().enabled = true;
}
}