Files

69 lines
1.8 KiB
C#

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;
}
}
}