Вызов функции принадлежащей классу Editor, из другого класса

161
01 апреля 2021, 06:20

Я нашёл тут ответ на мой вопрос, но он не помог. У меня не видит класс WaypointEditor в другом классе. Я подключил нужный namespace SWS и написал:

...
using SWS;
...
    WaypointEditor editors = (WaypointEditor[])Resources.FindObjectsOfTypeAll(typeof(WaypointEditor));
    if (editors.Length >0)
    {
      editors[0].AddMiniLocalPath(modelListPatn,"111");
    }
...

Но у меня по прежнему ругается на класс WaypointEditor,я даже пробовал написать так SWS.WaypointEditor и всё равно ругается компилятор, что нет такого класса. Сам класс WaypointEditor.cs:

using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
namespace SWS
{
    /// <summary>
    /// Waypoint and path creation editor.
    /// <summary>
    [CustomEditor(typeof(WaypointManager))]
    public class WaypointEditor : Editor
    {
        //manager reference
        private WaypointManager script;
     ...
    }
    public override void OnInspectorGUI()
    {
      ....
    }
    ...
    public void AddMiniLocalPath(List <Vector3> list,string namePath) {
            path = new GameObject(namePath+"cloneMiniPath");
            path.transform.position = script.gameObject.transform.position;
            path.transform.parent = script.gameObject.transform;
            StartPath();
            placing = true;
            for(int i=0;i<list.Count;i++) {
                PlaceWaypoint(list [i]);
            }
            if (wpList.Count < 2)
            {
                Debug.LogWarning("Not enough waypoints placed. Cancelling.");
                if (path) DestroyImmediate(path);
            }
            placing = false;
            wpList.Clear();
            pathName = "";
            Selection.activeGameObject = path;
        }
        ...
}

Класс "UISegmentedControlButtonEditor", в котором надо вызывать функцию AddMiniLocalPath(List list,string namePath), которая принадлежит классу WaypointEditor:

        SavingGroupOFObjects.cs:
        using UnityEngine.UI;
        using UnityEngine.EventSystems;
        using System.Collections;
        using UnityEngine;
        using UnityEditor;
        using System.Collections.Generic;
        using System.Linq;
        using System.IO;
        using SWS;
        [ExecuteInEditMode]
        public class SavingGroupOFObjects  : MonoBehaviour {
            public string groupName;
            public GameObject GamObjList;
            public GameObject GObjCPoint;
            public Vector3 CollectionPoint;
            public SWS.PathManager pathCont;
            public int index;
            public virtual void UpdateNodeGUI(Event e, Rect viewRect, GUISkin viewSkin)
            {
                if (GamObjList != null)
                {
                    EditorUtility.SetDirty(this);
                    //UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty();
                    Debug.Log("Editor Set Dirty");
                }
            }
        }
        [CustomEditor(typeof(SavingGroupOFObjects))]
        public class UISegmentedControlButtonEditor : Editor {
            //private SavingGroupOFObjects saveScripGroup;
            private SerializedObject m_Object;
            private SerializedProperty GamObjList;
            private SerializedProperty groupName;
            private SerializedProperty GObjCPoint;
            private SerializedProperty CollectionPoint;
            private SerializedProperty index;
            //private SerializedProperty SM;
            private SerializedProperty pathCont;
            public override void OnInspectorGUI() {
                m_Object.Update();
                ...
                if(tempGamObjList!=null && tempGObjCPoint!=null) {
                    RTCTankController[]TankC = tempGamObjList.GetComponentsInChildren<RTCTankController> ();
                    for (int i=0;i<TankC.Length;i++) {
                        List <Vector3> modelListPatn = splitLine (TankC [i].transform.position,tempGObjCPoint.transform.position);
                        //SWS.WaypointEditor.AddMiniLocalPath(modelListPatn,"22");
                        GameObject.Find("AllPathManager").GetComponent<SWS.PathManager>();

// тут ошибка /////////////////////////////////////////////////////////////////
                        WaypointEditor editors = (WaypointEditor[])Resources.FindObjectsOfTypeAll(typeof(WaypointEditor));
                        if (editors.Length >0)
                        {
                            editors[0].AddMiniLocalPath(modelListPatn,"111");
                        }
// тут ошибка /////////////////////////////////////////////////////////////////
                    }
                }
                m_Object.ApplyModifiedProperties();
           }
        ...
    }

Что я делаю не так ?

Answer 1

Помогло перемещение WaypointEditor.cs из Assembly-CSharp-Editor в Assembly-CSharp

READ ALSO
NullReferenceException при попытке работы с массивом

NullReferenceException при попытке работы с массивом

При попытке работы с массивом OnlyGreatMarks в последнем методе происходит ошибка:

182
С#. Вызов метода из метода в одном классе

С#. Вызов метода из метода в одном классе

Ну очень глупый вопрос наверное :(

157
Количество элементов на странице в зависимости от введенного числа

Количество элементов на странице в зависимости от введенного числа

Подскажите, пожалуйста, как в ASPNET CORE MVC сделать так, чтобы по вводу нужного числа в текстовом поле во view, появлялось количество элементов (текстовых...

125
Как сообщать об изменениях расчетного привязанного свойства класса в WPF?

Как сообщать об изменениях расчетного привязанного свойства класса в WPF?

Подскажите, пожалуйста, где я не правЯ создал класс Bill, в котором есть ряд полей

176