浏览代码

Added Callable to pickup item and effect

/main
Thomas ICHÉ 5 年前
当前提交
0d50ccf5
共有 3 个文件被更改,包括 26 次插入2 次删除
  1. 7
      Editor/Pickup/PickupItemEditor.cs
  2. 16
      Runtime/Actions/SpawnPrefabAction.cs
  3. 5
      Runtime/Pickup/PickupItem.cs

7
Editor/Pickup/PickupItemEditor.cs


public class PickupItemEditor : UnityEditor.Editor
{
ReorderableList m_RList;
SerializedProperty m_OnPickup;
m_OnPickup = serializedObject.FindProperty("OnPickup");
}
void DrawElement(Rect rect, int index, bool isActive, bool isFocused)

{
GUILayout.Space(8);
m_RList.DoLayoutList();
serializedObject.Update();
EditorGUILayout.PropertyField(m_OnPickup,true);
serializedObject.ApplyModifiedProperties();
}
}

16
Runtime/Actions/SpawnPrefabAction.cs


public Transform TargetTransform;
public bool TargetInstigator = false;
public bool AttachToTarget = false;
public bool DontDestroyPrefabsOnLoad = false;

Vector3 position = gameObject.transform.position;
Quaternion rotation = gameObject.transform.rotation;
if(TargetTransform != null)
if(TargetInstigator && instigator != null)
{
position = instigator.transform.position;
rotation = instigator.transform.rotation;
}
else if (TargetTransform != null)
{
position = TargetTransform.position;
rotation = TargetTransform.rotation;

obj.name = name;
if (AttachToTarget)
obj.transform.parent = TargetTransform;
{
if (TargetInstigator && instigator != null)
obj.transform.parent = instigator.transform;
else
obj.transform.parent = TargetTransform;
}
if (DontDestroyPrefabsOnLoad)
DontDestroyOnLoad(obj);

5
Runtime/Pickup/PickupItem.cs


using NaughtyAttributes;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

{
public PickupEffectBase[] effects { get { return GetComponents<PickupEffectBase>(); } }
[ReorderableList]
public Callable[] OnPickup;
private void OnTriggerEnter(Collider other)
{
var owner = other.gameObject.GetComponent<PickupOwnerBase>();

{
Callable.Call(OnPickup, owner.gameObject);
Destroy(this.gameObject);
}
}

正在加载...
取消
保存