Example #1
0
 /// <summary>
 /// Names all stations in this path correctly
 /// </summary>
 private void NameAllCorrectly(Path path)
 {
     for (int k = 0; k < path.StationsCount; k++)
     {
         // if it still has the default name
         if (path.GetStation(k).gameObject.name.StartsWith(stationNames))
         {
             path.GetStation(k).gameObject.name = stationNames + (k + 1);
         }
     }
 }
Example #2
0
        public void OnEnable()
        {
            path             = (Path)target;
            isCircleProperty = serializedObject.FindProperty("isCircle");

            // ====== GUI STYLES ===========
            errorLabel                  = new GUIStyle();
            errorLabel.fontSize         = 16;
            errorLabel.normal.textColor = Color.red;

            // ======= REORDERABLE LIST ==========
            list = new ReorderableList(path.GetAllStationWARNING(), typeof(Station));
            list.drawHeaderCallback = (Rect rect) => {
                EditorGUI.LabelField(rect, "Stations");
            };

            list.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => {
                GameObject station = ((Station)list.list[index]).gameObject;

                EditorGUI.Vector2Field(rect, station.name + ":", station.transform.position);
            };

            list.onAddCallback = (ReorderableList list) => {
                Vector3 newStationPosition;

                // if no station yet use path parent position otherwise the last station position
                if (path.StationsCount == 0)
                {
                    newStationPosition = path.transform.position;
                }
                else
                {
                    newStationPosition = path.GetStation(path.StationsCount - 1).transform.position;
                }

                // set all attributes
                GameObject newStation = new GameObject(stationNames + (path.StationsCount + 1));
                newStation.transform.position = newStationPosition;
                newStation.transform.parent   = path.transform;
                path.AddStation(newStation);

                if (editMode)
                {
                    Selection.activeGameObject = newStation;
                    list.index = list.count;
                }
            };

            list.onRemoveCallback = (ReorderableList list) => {
                GameObject selected = (GameObject)list.serializedProperty.GetArrayElementAtIndex(list.index).objectReferenceValue;

                // DELETE
                GUI.color = Color.red;
                {
                    DestroyImmediate(selected);
                    ((Path)target).RemoveStationAt(list.index);

                    NameAllCorrectly(path);
                }
                GUI.color = Color.white;
            };

            list.onReorderCallback = (ReorderableList list) => {
                NameAllCorrectly(path);
                path.ReCalculateStationWeights();
            };

            list.onSelectCallback = (ReorderableList list) => {
                if (editMode)
                {
                    Selection.activeGameObject = ((Station)list.list[list.index]).gameObject;
                }
            };
        }