using System;
using UnityEngine;
namespace UnityEditor.U2D.Path.GUIFramework
{
///
/// Represents a generic UI control.
///
public class GenericControl : Control
{
///
/// Func for OnBeginLayout
///
public Func onBeginLayout;
///
/// Action for OnEndLayout
///
public Action onEndLayout;
///
/// Action for OnRepaint
///
public Action onRepaint;
///
/// Func for GetCount
///
public Func count;
///
/// Func for GetPosition
///
public Func position;
///
/// Func for GetDistance
///
public Func distance;
///
/// Func for GetForward
///
public Func forward;
///
/// Func for GetUp
///
public Func up;
///
/// Func for GetRight
///
public Func right;
///
/// Func for GetUserData
///
public Func userData;
///
/// Initializes and returns an instance of GenericControl
///
/// The name of the generic control.
public GenericControl(string name) : base(name)
{
}
///
/// Gets the number of sub-controllers.
///
///
/// By default, this is `1`. If you implement your own controller and want to use multiple sub-controllers within it, you can assign getCount to a function that returns the number of sub-controllers.
///
/// Returns the number of sub-controllers. If you do not assign getCount, this returns 1.
protected override int GetCount()
{
if (count != null)
return count();
return base.GetCount();
}
///
/// Called when the control ends its layout.
///
/// The current state of the custom editor.
protected override void OnEndLayout(IGUIState guiState)
{
if (onEndLayout != null)
onEndLayout(guiState);
}
///
/// Called when the control repaints its contents.
///
/// The current state of the custom editor.
/// Current Index
protected override void OnRepaint(IGUIState guiState, int index)
{
if (onRepaint != null)
onRepaint(guiState, this, index);
}
///
/// Called when the control begins its layout.
///
/// The layout data.
/// The current state of the custom editor.
/// The LayoutData
protected override LayoutData OnBeginLayout(LayoutData data, IGUIState guiState)
{
if (onBeginLayout != null)
return onBeginLayout(guiState);
return data;
}
///
/// Gets the position of the control.
///
/// The current state of the custom editor.
/// The Index
/// The position
protected override Vector3 GetPosition(IGUIState guiState, int index)
{
if (position != null)
return position(index);
return base.GetPosition(guiState,index);
}
///
/// Gets the distance from the Scene view camera to the control.
///
/// The current state of the custom editor.
/// The Index
/// Returns the distance from the Scene view camera to the control.
protected override float GetDistance(IGUIState guiState, int index)
{
if (distance != null)
return distance(guiState, index);
return base.GetDistance(guiState, index);
}
///
/// Gets the forward vector of the control.
///
/// The current state of the custom editor.
/// The Index
/// Returns the generic control's forward vector.
protected override Vector3 GetForward(IGUIState guiState, int index)
{
if (forward != null)
return forward(index);
return base.GetForward(guiState,index);
}
///
/// Gets the up vector of the control.
///
/// The current state of the custom editor.
/// The Index
/// Returns the generic control's up vector.
protected override Vector3 GetUp(IGUIState guiState, int index)
{
if (up != null)
return up(index);
return base.GetUp(guiState,index);
}
///
/// Gets the right vector of the control.
///
/// The current state of the custom editor.
/// The Index
/// Returns the generic control's right vector.
protected override Vector3 GetRight(IGUIState guiState, int index)
{
if (right != null)
return right(index);
return base.GetRight(guiState,index);
}
///
/// Override for GetUserData
///
/// The current state of the custom editor.
/// The Index
/// Return the user data
protected override object GetUserData(IGUIState guiState, int index)
{
if (userData != null)
return userData(index);
return base.GetUserData(guiState,index);
}
}
}