提交小游戏项目
This commit is contained in:
BIN
Binary file not shown.
@@ -0,0 +1,136 @@
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
using System.Collections;
|
||||
using TowerClimberChronicles;
|
||||
public class ChildItem : MonoBehaviour
|
||||
{
|
||||
// 引用父物体的管理器
|
||||
private ParentItem parentManager;
|
||||
public int type;
|
||||
private GameObject light;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
parentManager = GetComponentInParent<ParentItem>();
|
||||
GameDispatcher.Instance.AddListener(GameMsg.FlowerShowclickAni, ShowclickAni);
|
||||
GameDispatcher.Instance.AddListener(GameMsg.FlowerHideclickAni, HideclickAni);
|
||||
light = transform.Find("light").gameObject;
|
||||
light.GetComponent<SpriteRenderer>().maskInteraction = SpriteMaskInteraction.VisibleOutsideMask;
|
||||
// Debug.Log(light);
|
||||
light.SetActive(false);
|
||||
starPrefab = Resources.Load<GameObject>("flower/scene/star");
|
||||
}
|
||||
|
||||
|
||||
// 子物体自己的逻辑方法
|
||||
private void ShowclickAni(object a = null)
|
||||
{
|
||||
if (CreatFlower.instance.slot_type_list.Contains(type))
|
||||
{
|
||||
if (light == null) return;
|
||||
light.SetActive(true);
|
||||
}
|
||||
DOVirtual.DelayedCall(3, () =>
|
||||
{
|
||||
HideclickAni();
|
||||
});
|
||||
|
||||
}
|
||||
private void HideclickAni(object a = null)
|
||||
{
|
||||
if (light == null) return;
|
||||
light.SetActive(false);
|
||||
}
|
||||
public void OnChildClicked()
|
||||
{
|
||||
parentManager.OnChildClicked(this);
|
||||
// Destroy(gameObject);
|
||||
Debug.Log($"{name} 执行了 DoSomething 方法");
|
||||
transform.GetComponent<Collider2D>().enabled = false;
|
||||
|
||||
Vector3 euler = transform.eulerAngles;
|
||||
euler.z = 0f;
|
||||
transform.eulerAngles = euler;
|
||||
|
||||
|
||||
SpriteRenderer sprite_render = transform.GetComponent<SpriteRenderer>();
|
||||
sprite_render.maskInteraction = SpriteMaskInteraction.None;
|
||||
|
||||
GameObject top_area = GameObject.Find("top_area");
|
||||
|
||||
SetParentAndFly(top_area.transform, CreatFlower.instance.AddFlowerInTemp(gameObject, type), 0.5f);
|
||||
|
||||
CreatFlower.instance.CheckPot();
|
||||
|
||||
|
||||
}
|
||||
void OnDestroy()
|
||||
{
|
||||
GameDispatcher.Instance.RemoveListener(GameMsg.FlowerShowclickAni, ShowclickAni);
|
||||
GameDispatcher.Instance.RemoveListener(GameMsg.FlowerHideclickAni, HideclickAni);
|
||||
}
|
||||
|
||||
|
||||
public GameObject starPrefab; // 拖尾星星的预制体(SpriteRenderer)
|
||||
public float fadeDuration = 0.5f; // 星星淡出时间
|
||||
|
||||
private bool isTrailing = false;
|
||||
|
||||
private int frameCounter = 0;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!isTrailing) return;
|
||||
|
||||
frameCounter++;
|
||||
|
||||
// 每隔 1 帧生成一次(即隔帧调用)
|
||||
if (frameCounter % 2 == 0)
|
||||
{
|
||||
GameObject star = Instantiate(starPrefab, transform.position, Quaternion.identity);
|
||||
star.transform.SetParent(null);
|
||||
|
||||
SpriteRenderer sr = star.GetComponent<SpriteRenderer>();
|
||||
if (sr != null)
|
||||
{
|
||||
sr.DOFade(0.2f, fadeDuration).OnComplete(() =>
|
||||
{
|
||||
Destroy(star);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(star, fadeDuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SetParentAndFly(Transform newParent, Transform targetChild, float duration)
|
||||
{
|
||||
if (newParent == null || targetChild == null)
|
||||
{
|
||||
Debug.LogError("父物体或目标子物体为空!");
|
||||
return;
|
||||
}
|
||||
|
||||
transform.SetParent(newParent);
|
||||
|
||||
// 开启拖尾
|
||||
isTrailing = true;
|
||||
|
||||
|
||||
// 移动和旋转
|
||||
DG.Tweening.Sequence seq = DOTween.Sequence();
|
||||
seq.Join(transform.DOMove(targetChild.position, duration).SetEase(Ease.InOutQuad));
|
||||
seq.Join(transform.DORotateQuaternion(targetChild.rotation, duration).SetEase(Ease.InOutQuad));
|
||||
|
||||
// 动画完成后关闭拖尾
|
||||
seq.OnComplete(() =>
|
||||
{
|
||||
isTrailing = false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d36b4db7768574658b0af567ae83168c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2edd6e49f33604b82beefe1918c5adc1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
using SGModule.ConfigLoader;
|
||||
|
||||
namespace TowerClimberChronicles
|
||||
{
|
||||
[ConfigKey("FlowerMatch")]
|
||||
public class FlowerMatch
|
||||
{
|
||||
public int id;
|
||||
public int level;
|
||||
public int ElementTypes;
|
||||
public int ElementCount;
|
||||
public int TypeDistribution;
|
||||
public float[] Difficulty;
|
||||
public float[] Accuracy;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d5795c849fae44be5bbe57cbc583626b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Spine.Unity;
|
||||
using UnityEngine;
|
||||
|
||||
public class ParentItem : MonoBehaviour
|
||||
{
|
||||
public List<ChildItem> children = new List<ChildItem>();
|
||||
public SkeletonAnimation destory_ani;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// 自动收集子物体上的 ChildItem 脚本
|
||||
children.AddRange(GetComponentsInChildren<ChildItem>());
|
||||
destory_ani = GetComponentInChildren<SkeletonAnimation>();
|
||||
destory_ani.gameObject.SetActive(false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 当某个子物体被点击时调用
|
||||
public void OnChildClicked(ChildItem child)
|
||||
{
|
||||
Debug.Log($"父物体收到点击事件:{child.name}");
|
||||
// 可以在这里统一管理,比如调用子物体的方法
|
||||
children.Remove(child);
|
||||
if (children.Count <= 0)
|
||||
{
|
||||
// Destroy(gameObject);
|
||||
GetComponent<Collider2D>().enabled = false;
|
||||
GetComponent<SpriteRenderer>().enabled = false;
|
||||
GetComponent<Rigidbody2D>().simulated = false;
|
||||
destory_ani.gameObject.SetActive(true);
|
||||
destory_ani.state.SetAnimation(0, "animation", false);
|
||||
|
||||
destory_ani.state.Complete += (trackEntry) =>
|
||||
{
|
||||
Destroy(gameObject);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f70d3bdb2508243ecabf6c20fe2ce399
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user