Skip to content

Instantly share code, notes, and snippets.

@shubhank008
Created February 18, 2023 07:07
Show Gist options
  • Save shubhank008/8f6b4ec8b8a0206411473ab1ce5b0ad0 to your computer and use it in GitHub Desktop.
Save shubhank008/8f6b4ec8b8a0206411473ab1ce5b0ad0 to your computer and use it in GitHub Desktop.
Show EntityId and DataId as readonly properties in inspector/editor for MMORPGKIT
using UnityEngine;
using UnityEngine.Serialization;
using System;
using Unity.Collections;
using LiteNetLib;
using LiteNetLibManager;
using LiteNetLib.Utils;
using ReadOnlyAttribute = Unity.Collections.ReadOnlyAttribute;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace MultiplayerARPG
{
public abstract partial class BaseGameData : ScriptableObject, IGameData, IComparable
{
[Category("DataId/EntityId")]
[Header("DataId/EntityId")]
[ReadOnly]
public int dataId_readonly;
public int entityId_readonly;
//Need to add call to this method in OnValidate() of BaseGameData.cs
void ShowDataIdReadOnly()
{
this.dataId_readonly = this.DataId;
}
}
public abstract partial class BasePlayerCharacterEntity
{
void ShowDataIdReadOnly()
{
this.entityId_readonly = this.EntityId;
this.dataId_readonly = this.DataId;
}
#if UNITY_EDITOR
protected override void OnValidate()
{
base.OnValidate();
this.ShowDataIdReadOnly();
}
#endif
}
public abstract partial class BaseMonsterCharacterEntity
{
void ShowDataIdReadOnly()
{
this.entityId_readonly = this.EntityId;
this.dataId_readonly = this.DataId;
}
#if UNITY_EDITOR
protected override void OnValidate()
{
base.OnValidate();
this.ShowDataIdReadOnly();
}
#endif
}
public abstract partial class DamageableEntity
{
[Category("DataId/EntityId")]
[Header("DataId/EntityId")]
[ReadOnly]
public int dataId_readonly;
public int entityId_readonly;
void ShowDataIdReadOnly()
{
this.entityId_readonly = this.EntityId;
this.dataId_readonly = 0;
}
#if UNITY_EDITOR
protected override void OnValidate()
{
base.OnValidate();
this.ShowDataIdReadOnly();
}
#endif
}
}
@shubhank008
Copy link
Author

shubhank008 commented Feb 18, 2023

Need to add call to ShowDataIdReadOnly() method in OnValidate() of BaseGameData.cs
Not needed for all other classes

#if UNITY_EDITOR
        protected void OnValidate()
        {
            if (Validate())
                EditorUtility.SetDirty(this);

            //TODO: #COREEDIT Show dataid in inspector
            ShowDataIdReadOnly();
        }
#endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment