Added player character and step in/out of dialogue in scene 101
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityEditor.ProBuilder
|
||||
{
|
||||
[Serializable]
|
||||
abstract class ShapeState
|
||||
{
|
||||
public static ShapeState s_defaultState;
|
||||
// UAC1005: direct self-reference cycle in serialized class
|
||||
[SerializeReference] public ShapeState m_nextState = null;
|
||||
public static DrawShapeTool tool;
|
||||
|
||||
public static ShapeState StartStateMachine()
|
||||
{
|
||||
if(s_defaultState == null)
|
||||
{
|
||||
Debug.LogError("Cannot start FSM, default state has not be set");
|
||||
return null;
|
||||
}
|
||||
|
||||
s_defaultState.InitState();
|
||||
return s_defaultState;
|
||||
}
|
||||
|
||||
protected virtual void InitState()
|
||||
{
|
||||
}
|
||||
|
||||
public abstract ShapeState DoState(Event evt);
|
||||
|
||||
protected virtual void EndState()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual ShapeState NextState()
|
||||
{
|
||||
EndState();
|
||||
if(m_nextState == null)
|
||||
return ResetState();
|
||||
|
||||
m_nextState.InitState();
|
||||
SceneView.RepaintAll();
|
||||
return m_nextState;
|
||||
}
|
||||
|
||||
public static ShapeState ResetTool(DrawShapeTool t)
|
||||
{
|
||||
tool = t;
|
||||
if (tool.m_ProBuilderShape != null)
|
||||
UnityEngine.Object.DestroyImmediate(tool.m_ProBuilderShape.gameObject);
|
||||
|
||||
s_defaultState.InitState();
|
||||
SceneView.RepaintAll();
|
||||
return s_defaultState;
|
||||
}
|
||||
|
||||
public static ShapeState ResetState()
|
||||
{
|
||||
if (tool.m_ProBuilderShape != null)
|
||||
UnityEngine.Object.DestroyImmediate(tool.m_ProBuilderShape.gameObject);
|
||||
|
||||
s_defaultState.InitState();
|
||||
SceneView.RepaintAll();
|
||||
return s_defaultState;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e04a5f326f647a40badbac91f38a704
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.ProBuilder;
|
||||
using UnityEngine.ProBuilder.Shapes;
|
||||
|
||||
namespace UnityEditor.ProBuilder
|
||||
{
|
||||
internal class ShapeState_DrawBaseShape : ShapeState
|
||||
{
|
||||
bool m_IsDragging = false;
|
||||
|
||||
protected override void InitState()
|
||||
{
|
||||
m_IsDragging = false;
|
||||
}
|
||||
|
||||
public override ShapeState DoState(Event evt)
|
||||
{
|
||||
if(evt.type == EventType.KeyDown)
|
||||
{
|
||||
switch(evt.keyCode)
|
||||
{
|
||||
case KeyCode.Delete:
|
||||
case KeyCode.Escape:
|
||||
return ResetState();
|
||||
}
|
||||
}
|
||||
|
||||
if(evt.type == EventType.Repaint && m_IsDragging)
|
||||
tool.DrawBoundingBox();
|
||||
|
||||
if(evt.isMouse)
|
||||
{
|
||||
switch(evt.type)
|
||||
{
|
||||
case EventType.MouseDrag:
|
||||
if(evt.button == 0)
|
||||
{
|
||||
m_IsDragging = true;
|
||||
|
||||
if (tool.m_DuplicateGO != null)
|
||||
tool.m_DuplicateGO.GetComponent<MeshRenderer>().enabled = false;
|
||||
|
||||
Drag(evt.mousePosition);
|
||||
}
|
||||
break;
|
||||
|
||||
case EventType.MouseMove:
|
||||
if(evt.button == 0 && m_IsDragging)
|
||||
Drag(evt.mousePosition);
|
||||
break;
|
||||
|
||||
case EventType.MouseUp:
|
||||
if(evt.button == 0)
|
||||
{
|
||||
if (!m_IsDragging && evt.shift)
|
||||
{
|
||||
CreateLastShape();
|
||||
return ResetState();
|
||||
}
|
||||
|
||||
if(Vector3.Distance(tool.m_BB_OppositeCorner, tool.m_BB_Origin) <= Mathf.Min(0.01f, tool.minSnapSize))
|
||||
return ResetState();
|
||||
|
||||
|
||||
tool.m_LastNonDuplicateCenterToOrigin = Quaternion.Inverse(tool.m_PlaneRotation) * ((tool.m_BB_Origin - tool.m_BB_OppositeCorner) * 0.5f);
|
||||
return NextState();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
void Drag(Vector2 mousePosition)
|
||||
{
|
||||
Ray ray = HandleUtility.GUIPointToWorldRay(mousePosition);
|
||||
float distance;
|
||||
|
||||
if(tool.m_Plane.Raycast(ray, out distance))
|
||||
UpdateShapeBase(ray, distance);
|
||||
}
|
||||
|
||||
void UpdateShapeBase(Ray ray, float distance)
|
||||
{
|
||||
var deltaPoint = ray.GetPoint(distance) - tool.m_BB_Origin;
|
||||
deltaPoint = Quaternion.Inverse(tool.m_PlaneRotation) * deltaPoint;
|
||||
deltaPoint = tool.GetPoint(deltaPoint, EditorSnapSettings.snapEnabled);
|
||||
tool.m_BB_OppositeCorner = tool.m_PlaneRotation * deltaPoint + tool.m_BB_Origin;
|
||||
tool.m_BB_HeightCorner = tool.m_BB_OppositeCorner;
|
||||
tool.RebuildShape();
|
||||
}
|
||||
|
||||
public void CreateLastShape()
|
||||
{
|
||||
tool.handleSelectionChange = false;
|
||||
var shape = ShapeFactory.Instantiate(DrawShapeTool.activeShapeType).GetComponent<ProBuilderShape>();
|
||||
UndoUtility.RegisterCreatedObjectUndo(shape.gameObject, $"Create Shape");
|
||||
EditorUtility.InitObject(shape.mesh);
|
||||
tool.ApplyPrefsSettings(shape);
|
||||
|
||||
EditorShapeUtility.CopyLastParams(shape.shape, shape.shape.GetType());
|
||||
shape.Rebuild(tool.previewPivotPosition, tool.m_PlaneRotation, tool.m_Bounds);
|
||||
|
||||
//Finish initializing object and collider once it's completed
|
||||
ProBuilderEditor.Refresh(false);
|
||||
|
||||
tool.m_ProBuilderShape = null;
|
||||
tool.m_LastShapeCreated = shape;
|
||||
if (tool.m_DuplicateGO != null)
|
||||
tool.m_DuplicateGO.GetComponent<MeshRenderer>().enabled = false;
|
||||
|
||||
Selection.activeGameObject = shape.gameObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd9d2fd81ebf44cca2949d833dd3a295
|
||||
timeCreated: 1598617351
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Math = UnityEngine.ProBuilder.Math;
|
||||
using Plane = UnityEngine.ProBuilder.Shapes.Plane;
|
||||
|
||||
namespace UnityEditor.ProBuilder
|
||||
{
|
||||
internal class ShapeState_DrawHeightShape : ShapeState
|
||||
{
|
||||
protected override void EndState()
|
||||
{
|
||||
tool.handleSelectionChange = false;
|
||||
|
||||
// Get the current undo group
|
||||
var group = Undo.GetCurrentGroup();
|
||||
var shape = tool.currentShapeInOverlay.gameObject;
|
||||
UndoUtility.RegisterCreatedObjectUndo(shape, "Draw Shape");
|
||||
|
||||
// Actually generate the shape
|
||||
tool.m_ProBuilderShape.gameObject.hideFlags = HideFlags.None;
|
||||
|
||||
EditorUtility.InitObject(tool.m_ProBuilderShape.mesh);
|
||||
tool.RebuildShape();
|
||||
Selection.activeObject = shape;
|
||||
|
||||
// Make sure that the whole shape creation process is a single undo group
|
||||
Undo.CollapseUndoOperations(group);
|
||||
|
||||
// Update tool
|
||||
DrawShapeTool.s_ActiveShapeIndex.value = Array.IndexOf(EditorShapeUtility.availableShapeTypes, tool.m_ProBuilderShape.shape.GetType());
|
||||
tool.SaveShapeParams(tool.m_ProBuilderShape);
|
||||
tool.m_LastShapeCreated = tool.m_ProBuilderShape;
|
||||
tool.m_ProBuilderShape = null;
|
||||
}
|
||||
|
||||
ShapeState ValidateShape()
|
||||
{
|
||||
return NextState();
|
||||
}
|
||||
|
||||
public override ShapeState DoState(Event evt)
|
||||
{
|
||||
if((tool.m_ProBuilderShape.shape is Plane)
|
||||
|| (tool.m_ProBuilderShape.shape is UnityEngine.ProBuilder.Shapes.Sprite))
|
||||
{
|
||||
//Skip Height definition for plane
|
||||
return ValidateShape();
|
||||
}
|
||||
|
||||
if(evt.type == EventType.KeyDown)
|
||||
{
|
||||
switch(evt.keyCode)
|
||||
{
|
||||
case KeyCode.Space:
|
||||
case KeyCode.Return:
|
||||
case KeyCode.Escape:
|
||||
return ValidateShape();
|
||||
|
||||
case KeyCode.Delete:
|
||||
return ResetState();
|
||||
}
|
||||
}
|
||||
|
||||
if(evt.type == EventType.Repaint)
|
||||
tool.DrawBoundingBox();
|
||||
|
||||
if(evt.isMouse)
|
||||
{
|
||||
switch(evt.type)
|
||||
{
|
||||
case EventType.MouseMove:
|
||||
case EventType.MouseDrag:
|
||||
Ray ray = HandleUtility.GUIPointToWorldRay(evt.mousePosition);
|
||||
Vector3 heightPoint = Math.GetNearestPointRayRay(tool.m_BB_OppositeCorner, tool.m_Plane.normal, ray.origin, ray.direction);
|
||||
var dot = Vector3.Dot(tool.m_Plane.normal, ray.direction);
|
||||
var isHeightPointNaN = float.IsNaN(heightPoint.x) || float.IsNaN(heightPoint.y) || float.IsNaN(heightPoint.z);
|
||||
if (!isHeightPointNaN)
|
||||
{
|
||||
var deltaPoint = (dot == 0 ? ray.origin - tool.m_Plane.ClosestPointOnPlane(ray.origin) : heightPoint - tool.m_BB_OppositeCorner);
|
||||
deltaPoint = Quaternion.Inverse(tool.m_PlaneRotation) * deltaPoint;
|
||||
deltaPoint = tool.GetPoint(deltaPoint, EditorSnapSettings.snapEnabled);
|
||||
tool.m_BB_HeightCorner = tool.m_PlaneRotation * deltaPoint + tool.m_BB_OppositeCorner;
|
||||
tool.RebuildShape();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case EventType.MouseUp:
|
||||
{
|
||||
tool.m_LastNonDuplicateCenterToOrigin = Quaternion.Inverse(tool.m_PlaneRotation) * ((tool.m_BB_Origin - tool.m_BB_HeightCorner) * 0.5f);
|
||||
return ValidateShape();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 217ead35f8b54dcda0676459e0d25fdf
|
||||
timeCreated: 1598617828
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEditor.EditorTools;
|
||||
using UnityEngine;
|
||||
using UnityEngine.ProBuilder;
|
||||
using Math = UnityEngine.ProBuilder.Math;
|
||||
|
||||
namespace UnityEditor.ProBuilder
|
||||
{
|
||||
class ShapeState_InitShape : ShapeState
|
||||
{
|
||||
//NOTE: All class attributes are used for handle display
|
||||
EditorShapeUtility.FaceData[] m_Faces;
|
||||
|
||||
Vector3 m_HitPosition = Vector3.positiveInfinity;
|
||||
|
||||
protected override void InitState()
|
||||
{
|
||||
tool.m_IsShapeInit = false;
|
||||
|
||||
m_Faces = new EditorShapeUtility.FaceData[6];
|
||||
for (int i = 0; i < m_Faces.Length; i++)
|
||||
m_Faces[i] = new EditorShapeUtility.FaceData();
|
||||
|
||||
m_HitPosition = Vector3.positiveInfinity;
|
||||
|
||||
if (tool.m_DuplicateGO != null)
|
||||
tool.m_DuplicateGO.GetComponent<MeshRenderer>().enabled = false;
|
||||
}
|
||||
|
||||
public override ShapeState DoState(Event evt)
|
||||
{
|
||||
tool.handleSelectionChange = true;
|
||||
if (tool.m_LastShapeCreated != null)
|
||||
{
|
||||
EditShapeTool.DoEditingHandles(tool.m_LastShapeCreated, tool);
|
||||
|
||||
if(evt.isKey && evt.type == EventType.KeyDown && evt.keyCode == KeyCode.Return)
|
||||
{
|
||||
ToolManager.RestorePreviousPersistentTool();
|
||||
return ResetState();
|
||||
}
|
||||
}
|
||||
|
||||
// Scene View in use or pressing alt to orbit
|
||||
if(EditorHandleUtility.SceneViewInUse(evt))
|
||||
return this;
|
||||
|
||||
if(evt.isMouse && HandleUtility.nearestControl == tool.controlID)
|
||||
{
|
||||
var res = EditorHandleUtility.FindBestPlaneAndBitangent(evt.mousePosition, tool.m_DuplicateGO);
|
||||
Ray ray = HandleUtility.GUIPointToWorldRay(evt.mousePosition);
|
||||
float hit;
|
||||
|
||||
if (res.item1.Raycast(ray, out hit))
|
||||
{
|
||||
var planeNormal = res.item1.normal;
|
||||
var planeCenter = res.item1.normal * -res.item1.distance;
|
||||
|
||||
// if hit point on plane is cardinal axis and on grid, snap to grid.
|
||||
if (Math.IsCardinalAxis(planeNormal))
|
||||
{
|
||||
const float epsilon = .00001f;
|
||||
bool offGrid = false;
|
||||
Vector3 snapVal = EditorSnapping.activeMoveSnapValue;
|
||||
Vector3 center =
|
||||
Vector3.Scale(ProBuilderSnapping.GetSnappingMaskBasedOnNormalVector(planeNormal),
|
||||
planeCenter);
|
||||
for (int i = 0; i < 3; i++)
|
||||
offGrid |= Mathf.Abs(snapVal[i] % center[i]) > epsilon;
|
||||
tool.m_IsOnGrid = !offGrid;
|
||||
}
|
||||
else
|
||||
{
|
||||
tool.m_IsOnGrid = false;
|
||||
}
|
||||
|
||||
m_HitPosition = tool.GetPoint(ray.GetPoint(hit));
|
||||
|
||||
//Click has been done => Define a plane for the tool
|
||||
if (evt.type == EventType.MouseDown && evt.button == 0)
|
||||
{
|
||||
//Plane init (persist for subsequent states)
|
||||
tool.m_Plane = res.item1;
|
||||
tool.m_PlaneForward = res.item2;
|
||||
tool.m_PlaneRight = Vector3.Cross(tool.m_Plane.normal, tool.m_PlaneForward);
|
||||
|
||||
//BB init
|
||||
tool.m_BB_Origin = m_HitPosition;
|
||||
tool.m_BB_HeightCorner = tool.m_BB_Origin;
|
||||
tool.m_BB_OppositeCorner = tool.m_BB_Origin;
|
||||
|
||||
return NextState();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_HitPosition = Vector3.positiveInfinity;
|
||||
}
|
||||
}
|
||||
|
||||
if (!Math.IsNumber(m_HitPosition))
|
||||
return this;
|
||||
|
||||
tool.DoDuplicateShapePreviewHandle(m_HitPosition);
|
||||
|
||||
// Repaint to visualize the placement preview dot
|
||||
if (evt.type == EventType.MouseMove && HandleUtility.nearestControl == tool.controlID)
|
||||
HandleUtility.Repaint();
|
||||
|
||||
if(evt.type == EventType.Repaint)
|
||||
{
|
||||
if(GUIUtility.hotControl == 0 && HandleUtility.nearestControl == tool.controlID)
|
||||
{
|
||||
using(new Handles.DrawingScope(EditorHandleDrawing.vertexSelectedColor))
|
||||
{
|
||||
Handles.DotHandleCap(-1, m_HitPosition, Quaternion.identity,
|
||||
HandleUtility.GetHandleSize(m_HitPosition) * 0.05f, EventType.Repaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53c376f349984575aa8d0dfd15cddc99
|
||||
timeCreated: 1598616376
|
||||
Reference in New Issue
Block a user