All Projects → baba-s → UniCommandController

baba-s / UniCommandController

Licence: MIT license
A simple library that can control commands to implement event scripts.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to UniCommandController

TMP FontAssetUpdater
You can automatically update FontAsset when the character you want to include in FontAsset of TextMesh Pro is changed.
Stars: ✭ 17 (+13.33%)
Mutual labels:  unity-scripts, kogane-unity-lib
uni-debug-menu
横向きかつクリックやタップ可能なゲームで使用できるカスタマイズ可能なデバッグメニュー
Stars: ✭ 24 (+60%)
Mutual labels:  kogane-unity-lib
Nvjob Water Shader Simple And Fast
#NVJOB Simple Water Shaders. Free Unity Asset.
Stars: ✭ 172 (+1046.67%)
Mutual labels:  unity-scripts
Unity-Synth-Experiments
A set of simple generative synth scripts for Unity written in C# (OnAudioFilterRead)
Stars: ✭ 97 (+546.67%)
Mutual labels:  unity-scripts
Nativecollections
Native Collection Types for Unity
Stars: ✭ 213 (+1320%)
Mutual labels:  unity-scripts
nvjob-sky-shader-simple-and-fast
#NVJOB Dynamic Sky. Sky Shaders. Free Unity Asset.
Stars: ✭ 103 (+586.67%)
Mutual labels:  unity-scripts
Unityskidmarks
A simple skidmark effect generator for Unity3D
Stars: ✭ 165 (+1000%)
Mutual labels:  unity-scripts
UnityGlobalTextSystem
Allow the user to 'change' the default font in Unity from "Arial" to a font of their liking.
Stars: ✭ 21 (+40%)
Mutual labels:  unity-scripts
Unity-FPS-Counter
#NVJOB FPS Counter and Graph. Free Unity Asset.
Stars: ✭ 44 (+193.33%)
Mutual labels:  unity-scripts
UniProjectWindowMenuCustomizer
Editor extension that allows you to customize the menu that appears when you right-click on Project view.
Stars: ✭ 18 (+20%)
Mutual labels:  kogane-unity-lib
Object-Pooling-for-Unity
Object Pooling for Unity
Stars: ✭ 118 (+686.67%)
Mutual labels:  unity-scripts
Apple Signin Unity
Unity plugin to support Sign In With Apple Id
Stars: ✭ 228 (+1420%)
Mutual labels:  unity-scripts
unity-puzzlesystem-asset
The asset for the Unity Engine that allows to quickly create customisable puzzles.
Stars: ✭ 21 (+40%)
Mutual labels:  unity-scripts
Unitysingleton
The best way to implement singleton pattern in Unity.
Stars: ✭ 185 (+1133.33%)
Mutual labels:  unity-scripts
awesome-unity
A curated list of awesome Unity games! 🎮
Stars: ✭ 346 (+2206.67%)
Mutual labels:  unity-scripts
Unity resources
A list of resources and tutorials for those doing programming in Unity.
Stars: ✭ 170 (+1033.33%)
Mutual labels:  unity-scripts
UnityHexagonLibrary2d
A library to manage 2D hexagonal tiles in Unity.
Stars: ✭ 58 (+286.67%)
Mutual labels:  unity-scripts
ImpossibleOdds-TacticalCamera
Camera system for tactical world overviews in Unity games.
Stars: ✭ 14 (-6.67%)
Mutual labels:  unity-scripts
gocs
GameObject Component System for Unity
Stars: ✭ 102 (+580%)
Mutual labels:  unity-scripts
UGUI-Toolset
No description or website provided.
Stars: ✭ 14 (-6.67%)
Mutual labels:  unity-scripts

UniCommandController

A simple library that can control commands to implement event scripts.

Usage

using System;
using UnityCommandController;
using UnityEngine;

public class Example : MonoBehaviour
{
    private CommandController m_controller;

    private void Awake()
    {
        // Type list of commands to use.
        var commandTypes = new []
        {
            typeof( LogCommand ),
            typeof( CreateCommand ),
            typeof( SetPositionCommand ),
            typeof( MoveCommand ),
            typeof( JumpCommand ),
            typeof( WaitCommand ),
            typeof( ClickCommand ),
        };

        // Create instances to control commands.
        m_controller = new CommandController( commandTypes );

        // Create a list of commands.
        var commands = new[]
        {
            "LogCommand|Pikachu",
            "LogCommand|Raichu",
            "CreateCommand|cube|0|1|2",
            "SetPositionCommand|1|2|3",
            "MoveCommand|-1|0|1|1",
            "JumpCommand|6",
            "LogCommand|Ignored here.",
            "LogCommand|Jumped here.",
            "WaitCommand|1",
            "ClickCommand",
        };

        // Objects and parameters controlled by command.
        GameObject cube = null;
        var startPos = Vector3.zero;
        var endPos = Vector3.zero;

        // Set command event.
        CreateCommand.OnCreate += go => cube = go;
        SetPositionCommand.OnSetPosition += pos => cube.transform.localPosition = pos;
        MoveCommand.OnMoveStart += pos =>
        {
            startPos = cube.transform.localPosition;
            endPos = pos;
        };
        MoveCommand.OnMove += amount =>
        {
            cube.transform.localPosition = Vector3.Lerp( startPos, endPos, amount );
        };
        MoveCommand.OnMoveEnd += () => cube.transform.localPosition = endPos;
        JumpCommand.OnJump += index => m_controller.JumpToIndex( index );

        // Called when all commands are finished.
        m_controller.OnEnd += () => print( "Finished." );

        // Command start.
        m_controller.Start( commands );
    }

    private void Update()
    {
        // Command update.
        m_controller.Update();
    }
}

public class LogCommand : CommandBase
{
    private string m_message;

    public LogCommand( CommandArugments args )
    {
        m_message = args[ 1 ];
    }

    protected override void DoStart()
    {
        Debug.Log( m_message );
    }
}

public class CreateCommand : CommandBase
{
    private string m_name;
    private Vector3 m_pos;

    public static event Action<GameObject> OnCreate = delegate { };

    public CreateCommand( CommandArugments args )
    {
        m_name = args[ 1 ];
        m_pos = new Vector3
        (
            args.ToFloat( 2 ),
            args.ToFloat( 3 ),
            args.ToFloat( 4 )
        );
    }

    protected override void DoStart()
    {
        var go = GameObject.CreatePrimitive( PrimitiveType.Cube );
        go.name = m_name;
        go.transform.localPosition = m_pos;
        OnCreate( go );
        Debug.Log( "Object creation complete." );
    }
}

public class SetPositionCommand : CommandBase
{
    private Vector3 m_pos;

    public static event Action<Vector3> OnSetPosition = delegate { };

    public SetPositionCommand( CommandArugments args )
    {
        m_pos = new Vector3
        (
            args.ToFloat( 1 ),
            args.ToFloat( 2 ),
            args.ToFloat( 3 )
        );
    }

    protected override void DoStart()
    {
        OnSetPosition( m_pos );
        Debug.Log( "Object position setting complete." );
    }
}

public class MoveCommand : CommandBase
{
    private Vector3 m_pos;
    private float m_duration;
    private float m_elapsedTime;

    public override bool IsEnd { get { return m_duration <= m_elapsedTime; } }

    public static event Action<Vector3> OnMoveStart = delegate { };
    public static event Action<float> OnMove = delegate { };
    public static event Action OnMoveEnd = delegate { };

    public MoveCommand( CommandArugments args )
    {
        m_pos = new Vector3
        (
            args.ToFloat( 1 ),
            args.ToFloat( 2 ),
            args.ToFloat( 3 )
        );
        m_duration = args.ToFloat( 4 );
    }

    protected override void DoStart()
    {
        OnMoveStart( m_pos );
        Debug.Log( "Object movement start." );
    }

    protected override void DoUpdate()
    {
        m_elapsedTime += Time.deltaTime;
        OnMove( m_elapsedTime / m_duration );
    }

    protected override void DoDispose()
    {
        OnMoveEnd();
        Debug.Log( "End of object movement." );
    }
}

public class JumpCommand : CommandBase
{
    private int m_index;

    public static event Action<int> OnJump = delegate { };

    public JumpCommand( CommandArugments args )
    {
        m_index = args.ToInt( 1 );
    }

    protected override void DoStart()
    {
        OnJump( m_index );
    }
}

public class WaitCommand : CommandBase
{
    private float m_time;
    private float m_elapsedTime;

    public override bool IsEnd { get { return m_time <= m_elapsedTime; } }

    public WaitCommand( CommandArugments args )
    {
        m_time = args.ToFloat( 1 );
    }

    protected override void DoStart()
    {
        Debug.Log( "Standby start." );
    }

    protected override void DoUpdate()
    {
        m_elapsedTime += Time.deltaTime;
    }

    protected override void DoDispose()
    {
        Debug.Log( "Wait end." );
    }
}

public class ClickCommand : CommandBase
{
    public override bool IsEnd { get { return Input.GetMouseButtonDown( 0 ); } }

    public ClickCommand( CommandArugments args ) { }

    protected override void DoStart()
    {
        Debug.Log( "Wait for input." );
    }

    protected override void DoDispose()
    {
        Debug.Log( "Input confirmation." );
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].