블로그 이미지
Every unexpected event is a path to learning for you. blueasa

카테고리

분류 전체보기 (2794)
Unity3D (852)
Programming (478)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (185)
협업 (11)
3DS Max (3)
Game (12)
Utility (68)
Etc (98)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (55)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday

Unity 2021.3.37f1

Lunar Mobile Console - Pro v1.8.5

----

Lunar Mobile Console - Pro에서 Actions and Variables를 사용할 수 있는데,

이번에 enum 넣으면서 참조 링크를 다시 봤는데 enum 관련 작성을 제대로 안해놔서 좀 헤메서..

변수 타입별 사용방법 정리 겸 샘플 작성해서 올려 둠.

 

 

using UnityEngine;
using System.Collections;
using LunarConsolePlugin;

public class AnLunarConsole_Actions_Variables_Manager : MonoBehaviour
{
    public enum eVariablesType
    {
        One,
        Two,
        Three
    }

    [CVarContainer]
    public static class Variables
    {
        public static readonly CVar myBool = new CVar("My boolean value", true);
        public static CVarChangedDelegate CVarChangedDelegate_myBool = null;
        public static readonly CVar myFloat = new CVar("My float value", 3.14f);
        public static CVarChangedDelegate CVarChangedDelegate_myFloat = null;
        public static readonly CVar myInt = new CVar("My integer value", 10);
        public static CVarChangedDelegate CVarChangedDelegate_myInt = null;
        public static readonly CVar myString = new CVar("My string value", "Test");
        public static CVarChangedDelegate CVarChangedDelegate_myString = null;
        public static readonly CEnumVar<eVariablesType> myEnum = new CEnumVar<eVariablesType>("My enum value", eVariablesType.Two);
        public static CVarChangedDelegate CVarChangedDelegate_myEnum = null;
    }

    IEnumerator Start()
    {
        yield return null;

        InitActions();
        InitVariables();

        AddAction();
        AddDelegate();
    }

    void OnDestroy()
    {
        RemoveAction();
        RemoveDelegate();
    }

    #region Actions
    void InitActions()
    {

    }

    void AddAction()
    {
        LunarConsole.RegisterAction("[Common] Action Common 1", Action_Common_1);
        LunarConsole.RegisterAction("[Common] Action Common 2_1", () => Action_Common_2(1));
        LunarConsole.RegisterAction("[Common] Action Common 2_2", () => Action_Common_2(2));
        LunarConsole.RegisterAction("[InGame] Action InGame", Action_InGame);
        LunarConsole.RegisterAction("[OutGame] Action OutGame", Action_OutGame);
    }

    void RemoveAction()
    {
        LunarConsole.UnregisterAllActions(this); // don't forget to unregister!
    }

    void Action_Common_1()
    {
        // do something..
    }

    void Action_Common_2(int _iValue)
    {
        // do something..
    }

    void Action_InGame()
    {
        // do something..
    }

    void Action_OutGame()
    {
        // do something..
    }
    #endregion

    #region Variables
    void InitVariables()
    {
        Variables.myBool.BoolValue = true;
        Variables.myFloat.FloatValue = 3.14f;
        Variables.myInt.IntValue = 10;
        Variables.myString.Value = "Test";
        //Variables.myEnum.EnumValue = eVariablesType.Two;  // Can't
    }

    void AddDelegate()
    {
        // myBool
        Variables.CVarChangedDelegate_myBool = (value) =>
        {
            UnityEngine.Debug.Log("[myBool is] " + value);
            OnCVarChangedDelegate_myBool(value);
        };
        Variables.myBool.AddDelegate(Variables.CVarChangedDelegate_myBool);

        // myFloat
        Variables.CVarChangedDelegate_myFloat = (value) =>
        {
            UnityEngine.Debug.Log("[myFloat is] " + value);
            OnCVarChangedDelegate_myFloat(value);
        };
        Variables.myFloat.AddDelegate(Variables.CVarChangedDelegate_myFloat);

        // myInt
        Variables.CVarChangedDelegate_myInt = (value) =>
        {
            UnityEngine.Debug.Log("[myInt is] " + value);
            OnCVarChangedDelegate_myInt(value);
        };
        Variables.myInt.AddDelegate(Variables.CVarChangedDelegate_myInt);

        // myString
        Variables.CVarChangedDelegate_myString = (value) =>
        {
            UnityEngine.Debug.Log("[myString is] " + value);
            OnCVarChangedDelegate_myString(value);
        };
        Variables.myString.AddDelegate(Variables.CVarChangedDelegate_myBool);

        // myEnum
        Variables.CVarChangedDelegate_myEnum = (value) =>
        {
            UnityEngine.Debug.Log("[myEnum is] " + value);
            CEnumVar<eVariablesType> cEnumVar = (CEnumVar<eVariablesType>)value;
            eVariablesType eEnumValue = cEnumVar.EnumValue;
            OnCVarChangedDelegate_myEnum(eEnumValue);
        };
        Variables.myEnum.AddDelegate(Variables.CVarChangedDelegate_myEnum);
    }

    void RemoveDelegate()
    {
        Variables.myBool.RemoveDelegate(Variables.CVarChangedDelegate_myBool);
        Variables.myFloat.RemoveDelegate(Variables.CVarChangedDelegate_myFloat);
        Variables.myInt.RemoveDelegate(Variables.CVarChangedDelegate_myInt);
        Variables.myString.RemoveDelegate(Variables.CVarChangedDelegate_myString);
        Variables.myEnum.RemoveDelegate(Variables.CVarChangedDelegate_myEnum);
    }

    void OnCVarChangedDelegate_myBool(bool _bValue)
    {
        // do something..
    }

    void OnCVarChangedDelegate_myFloat(float _fValue)
    {
        // do something..
    }

    void OnCVarChangedDelegate_myInt(int _iValue)
    {
        // do something..
    }

    void OnCVarChangedDelegate_myString(string _strValue)
    {
        // do something..
    }

    void OnCVarChangedDelegate_myEnum(eVariablesType _eVariablesType)
    {
        // do something..
    }
    #endregion
}

 

 

[참조] https://github.com/SpaceMadness/lunar-unity-console/wiki/Actions-and-Variables#listening-for-variable-changes

 

Actions and Variables

High-performance Unity iOS/Android logger built with native platform UI - SpaceMadness/lunar-unity-console

github.com

 

반응형
Posted by blueasa
, |