TylerTemp / SaintsField

A Unity Inspector extension tool focusing on script fields inspector enhancement
MIT License
162 stars 9 forks source link

is there a way to GetComponent in self and parent? #41

Closed laurentopia closed 2 months ago

laurentopia commented 3 months ago

Because this image is causing that image

TylerTemp commented 3 months ago

Hi,

seems like MCUnit is not a Component (usu. a MonoBehaviour).

Here is what I tested on Unity 2022.2 with UI Toolkit:

// MCUnit.cs
public class MCUnit : MonoBehaviour
{
}

// Issue41GetComp.cs
public class Issue41GetComp : MonoBehaviour
{
    [GetComponent] [GetComponentInParent] public MCUnit mcUnit;
}

Example of geting it from self:

image

from parent:

image

Can you give a small example of how MCUnit look like?

laurentopia commented 2 months ago

It's solved and ... I don't remember what I did 🗡️ Here is MCUnit


using System.Collections.Generic;
using SaintsField;
using SaintsField.Playa;
using Panda;
using UnityEngine.AI;
using Vertx.Debugging;
using Gizmos = UnityEngine.Gizmos;
using Random = UnityEngine.Random;
#if UNITY_EDITOR
#endif

#pragma warning disable 0649
public enum Team { ENEMY = 0, PLAYER = 1 }
public class MCUnit : MonoBehaviour
{
    [GetComponent]
    public MCAttackSelector attackSelector;
    [GetComponent]
    public AnimationController anim;
    public float detectionRange = 100;
    public int score = 0,
                        threat = 1;
    public Team team = Team.ENEMY;
    public LayerMask enemyLayer,
                                    friendLayer;
    public bool noPanda;
    [SepTitle(EColor.Violet)]
    [SerializeField]
    float health = 10.0f;```
TylerTemp commented 2 months ago

Hi, this issue is closed as no feature actions required. If you still have related issue, please comment below and I'll open it again