浏览代码

Pathway Component (#371)

* Pathway component

* Pathway component

* Pathway component

* Pathway component

* Pathway component

* Pathway component

* Update PathwayGizmo.cs

* Update PathwayGizmo.cs

* Update PathwayGizmo.cs

* Update PathwayGizmo.cs

* Update PathwayGizmo.cs

* Update PathwayGizmo.cs

* Pathway component

* Pathway component

* Pathway component

* Pathway component

* Update PathwayEditor.cs

* Pathway component

* Update PathwayEditor.cs

* Pathway component

* Update PathwayGismos.cs

* Pathway component

* Update PathwayEditor.cs

* Update PathwayEditor.cs

* Pathway component

* Pathway component

* Update PathwayEditor.cs

* Update PathwayEditor.cs

* Pathway component

Not doing polls at this time.

* Update PathwayGismos.cs

* Update PathwayGismos.cs

* Pathway component

* Update PathwayEditor.cs

* Update PathwayEditor.cs

* Pathway component

* Pathway component

* Pathway comp...
/UI
GitHub 3 年前
当前提交
4df86a3d
共有 15 个文件被更改,包括 346 次插入0 次删除
  1. 8
      UOP1_Project/Assets/Prefabs/Pathway.meta
  2. 8
      UOP1_Project/Assets/Scripts/Pathway.meta
  3. 53
      UOP1_Project/Assets/Prefabs/Pathway/Pathway.prefab
  4. 7
      UOP1_Project/Assets/Prefabs/Pathway/Pathway.prefab.meta
  5. 116
      UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayEditor.cs
  6. 11
      UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayEditor.cs.meta
  7. 55
      UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayGizmos.cs
  8. 11
      UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayGizmos.cs.meta
  9. 24
      UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayHandles.cs
  10. 11
      UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayHandles.cs.meta
  11. 31
      UOP1_Project/Assets/Scripts/Pathway/Pathway.cs
  12. 11
      UOP1_Project/Assets/Scripts/Pathway/Pathway.cs.meta

8
UOP1_Project/Assets/Prefabs/Pathway.meta


fileFormatVersion: 2
guid: 40e40b1ee07a76f46bd4bdb320066635
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
UOP1_Project/Assets/Scripts/Pathway.meta


fileFormatVersion: 2
guid: aaf94d94b26470e4cabe86e27f3fdb27
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

53
UOP1_Project/Assets/Prefabs/Pathway/Pathway.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &1144487823250550478
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1144487823250550476}
- component: {fileID: 1144487823250550477}
m_Layer: 0
m_Name: Pathway
m_TagString: Untagged
m_Icon: {fileID: 2974397684917235467, guid: 0000000000000000d000000000000000, type: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1144487823250550476
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1144487823250550478}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1144487823250550477
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1144487823250550478}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 12817591b14c6404a8be11b932d21ce1, type: 3}
m_Name:
m_EditorClassIdentifier:
wayPoints: []
_cubeSize: 2.32
_cubeColor: {r: 0.05882354, g: 0.65882355, b: 0.5754239, a: 1}
_lineColor: {r: 0, g: 0, b: 0, a: 1}
_selectedColor: {r: 1, g: 1, b: 1, a: 1}
_textColor: {r: 1, g: 1, b: 1, a: 1}
_drawMesh: {fileID: -9001182816367246566, guid: 45d1d02514297504a9e2d5547ce4333c,
type: 3}

7
UOP1_Project/Assets/Prefabs/Pathway/Pathway.prefab.meta


fileFormatVersion: 2
guid: cf01b2e1eaddde24fac8e690f5e35bfa
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

116
UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayEditor.cs


using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
[CustomEditor(typeof(Pathway))]
public class PathwayEditor : Editor
{
private ReorderableList _reorderableList;
private Pathway _pathway;
private PathwayHandles _pathwayHandles;
public void OnSceneGUI()
{
_pathwayHandles.DispalyHandles();
}
public override void OnInspectorGUI()
{
DrawDefaultInspector();
serializedObject.Update();
_reorderableList.DoLayoutList();
serializedObject.ApplyModifiedProperties();
}
private void OnEnable()
{
Undo.undoRedoPerformed += DoUndo;
_reorderableList = new ReorderableList(serializedObject, serializedObject.FindProperty("Waypoints"), true, true, true, true);
_reorderableList.drawHeaderCallback += DrawHeader;
_reorderableList.drawElementCallback += DrawElement;
_reorderableList.onAddCallback += AddItem;
_reorderableList.onRemoveCallback += RemoveItem;
_reorderableList.onSelectCallback += SelectItem;
_reorderableList.onChangedCallback += ListModified;
_pathway = (target as Pathway);
_pathwayHandles = new PathwayHandles(_pathway);
}
private void OnDisable()
{
Undo.undoRedoPerformed -= DoUndo;
_reorderableList.drawHeaderCallback -= DrawHeader;
_reorderableList.drawElementCallback -= DrawElement;
_reorderableList.onAddCallback -= AddItem;
_reorderableList.onRemoveCallback -= RemoveItem;
_reorderableList.onSelectCallback -= SelectItem;
_reorderableList.onChangedCallback -= ListModified;
}
private void DrawHeader(Rect rect)
{
GUI.Label(rect, Pathway.TITLE_LABEL);
}
private void DrawElement(Rect rect, int index, bool active, bool focused)
{
SerializedProperty item = _reorderableList.serializedProperty.GetArrayElementAtIndex(index);
item.vector3Value = EditorGUI.Vector3Field(rect, Pathway.FIELD_LABEL + index, item.vector3Value);
}
private void AddItem(ReorderableList list)
{
int index = list.index;
if (index > -1 && list.serializedProperty.arraySize >= 1)
{
list.serializedProperty.InsertArrayElementAtIndex(index + 1);
Vector3 previous = list.serializedProperty.GetArrayElementAtIndex(index).vector3Value;
list.serializedProperty.GetArrayElementAtIndex(index + 1).vector3Value = new Vector3(previous.x + 2, previous.y, previous.z + 2);
}
else
{
list.serializedProperty.InsertArrayElementAtIndex(list.serializedProperty.arraySize);
Vector3 previous = _pathway.transform.position;
list.serializedProperty.GetArrayElementAtIndex(list.serializedProperty.arraySize - 1).vector3Value = new Vector3(previous.x + 2, previous.y, previous.z + 2);
}
list.index++;
}
private void RemoveItem(ReorderableList list)
{
int index = list.index;
list.serializedProperty.DeleteArrayElementAtIndex(index);
if (list.index == list.serializedProperty.arraySize)
{
list.index--;
}
}
private void SelectItem(ReorderableList list)
{
InternalEditorUtility.RepaintAllViews();
}
private void ListModified(ReorderableList list)
{
list.serializedProperty.serializedObject.ApplyModifiedProperties();
}
private void DoUndo()
{
serializedObject.UpdateIfRequiredOrScript();
if (_reorderableList.index >= _reorderableList.serializedProperty.arraySize )
{
_reorderableList.index = _reorderableList.serializedProperty.arraySize-1;
}
}
}

11
UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayEditor.cs.meta


fileFormatVersion: 2
guid: 69db5c2486715ce408863f0c9c620ca8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

55
UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayGizmos.cs


using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
public class PathwayGizmos
{
[DrawGizmo(GizmoType.Selected)]
private static void DrawGizmosSelected(Pathway pathway, GizmoType gizmoType)
{
DrawHandlesPath(pathway);
}
private static void DrawElements(Pathway pathway, List<Vector3> path, int index)
{
GUIStyle style = new GUIStyle();
Vector3 textHeight = Vector3.up;
style.normal.textColor = pathway.TextColor;
style.fontSize = pathway.TextSize;
Handles.Label(path[index] + textHeight, index.ToString(), style);
}
private static void DrawHandlesPath(Pathway pathway)
{
if (pathway.Waypoints.Count != 0) {
DrawElements(pathway, pathway.Waypoints, 0);
}
for (int i = 0; i < pathway.Waypoints.Count; i++)
{
if (i != 0 && pathway.Waypoints.Count > 1)
{
DrawElements(pathway, pathway.Waypoints, i);
using (new Handles.DrawingScope(pathway.LineColor))
{
Handles.DrawDottedLine(pathway.Waypoints[i - 1], pathway.Waypoints[i], 2);
}
}
}
if (pathway.Waypoints.Count > 2)
{
using (new Handles.DrawingScope(pathway.LineColor))
{
Handles.DrawDottedLine(pathway.Waypoints[0], pathway.Waypoints[pathway.Waypoints.Count - 1], 2);
}
}
}
}

11
UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayGizmos.cs.meta


fileFormatVersion: 2
guid: baca1f7fba1a3e04aa3968a4cf90f58b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

24
UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayHandles.cs


using UnityEngine;
using UnityEditor;
public class PathwayHandles
{
private Pathway _pathway;
public PathwayHandles(Pathway pathway)
{
_pathway = pathway;
}
public void DispalyHandles()
{
EditorGUI.BeginChangeCheck();
for (int i = 0; i < _pathway.Waypoints.Count; i++)
{
_pathway.Waypoints[i] = Handles.PositionHandle(_pathway.Waypoints[i], Quaternion.identity);
}
}
}

11
UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayHandles.cs.meta


fileFormatVersion: 2
guid: a8dcb713973bd474e9d3eb21e77c8fa4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

31
UOP1_Project/Assets/Scripts/Pathway/Pathway.cs


using System.Collections.Generic;
using UnityEngine;
public class Pathway : MonoBehaviour
{
[HideInInspector]
public List<Vector3> Waypoints;
#if UNITY_EDITOR
[SerializeField]
private Color _lineColor = Color.black;
[SerializeField, Range(0, 100)]
private int _textSize = 10;
[SerializeField]
private Color _textColor = Color.white;
public const string FIELD_LABEL = "Point ";
public const string TITLE_LABEL = "Waypoints";
public Color LineColor { get => _lineColor; }
public Color TextColor { get => _textColor; }
public int TextSize { get => _textSize; }
#endif
}

11
UOP1_Project/Assets/Scripts/Pathway/Pathway.cs.meta


fileFormatVersion: 2
guid: 12817591b14c6404a8be11b932d21ce1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存