118 lines
2.8 KiB
C#
118 lines
2.8 KiB
C#
|
||
#if UNITY_EDITOR
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
[CreateAssetMenu(menuName = "ScriptableObjects/CubeConfigData")]
|
||
[System.Serializable]
|
||
[ExecuteInEditMode]
|
||
public class CubeConfigData : ScriptableObject
|
||
{
|
||
[Tooltip("0:上,90:右,180:下,270:左")]
|
||
[HideInInspector]
|
||
public int PropDirection = 0;
|
||
public int PropRows = 2; // 行数
|
||
public int PropColumns = 2; // 列数
|
||
public int[] PropArr;
|
||
|
||
[NonSerialized]
|
||
public int[,] TempArr;
|
||
|
||
private int _oidPropRows = 0;
|
||
private int _oidPropColumns = 0;
|
||
void OnValidate()
|
||
{
|
||
if (PropRows != _oidPropRows)
|
||
{
|
||
if(_oidPropRows != 0)
|
||
Reset();
|
||
_oidPropRows = PropRows;
|
||
}
|
||
|
||
if (PropColumns != _oidPropColumns)
|
||
{
|
||
if(_oidPropColumns != 0)
|
||
Reset();
|
||
_oidPropColumns = PropColumns;
|
||
}
|
||
}
|
||
|
||
public void InitializePropGrid()
|
||
{
|
||
PropArr = new int[PropRows * PropColumns];
|
||
}
|
||
|
||
public void Reset()
|
||
{
|
||
PropArr = null;
|
||
TempArr = null;
|
||
}
|
||
|
||
public void Serializable2DArray(int[,] array)
|
||
{
|
||
PropArr = new int[PropRows * PropColumns];
|
||
for (int i = 0; i < PropRows; i++)
|
||
{
|
||
for (int j = 0; j < PropColumns; j++)
|
||
{
|
||
PropArr[i * PropColumns + j] = array[i, j];
|
||
}
|
||
}
|
||
}
|
||
|
||
public int[,] To2DArray()
|
||
{
|
||
int[,] array = new int[PropRows, PropColumns];
|
||
for (int i = 0; i < PropRows; i++)
|
||
{
|
||
for (int j = 0; j < PropColumns; j++)
|
||
{
|
||
array[i, j] = PropArr[i * PropColumns + j];
|
||
}
|
||
}
|
||
return array;
|
||
}
|
||
|
||
public int[,] GetArray()
|
||
{
|
||
if (TempArr != null )
|
||
{
|
||
return TempArr;
|
||
}
|
||
|
||
if (PropArr == null || PropArr.Length == 0)
|
||
{
|
||
InitializePropGrid();
|
||
}
|
||
|
||
TempArr = new int[PropRows, PropColumns];
|
||
for (int i = 0; i < PropRows; i++)
|
||
{
|
||
for (int j = 0; j < PropColumns; j++)
|
||
{
|
||
TempArr[i, j] = PropArr[i * PropColumns + j];
|
||
}
|
||
}
|
||
return TempArr;
|
||
}
|
||
|
||
public CubeConfigData Copy()
|
||
{
|
||
CubeConfigData copy = ScriptableObject.CreateInstance<CubeConfigData>();
|
||
// copy.IdData.EnableId = this.IdData.EnableId;
|
||
// copy.IdData.PropId = this.IdData.PropId;
|
||
copy.PropDirection = this.PropDirection;
|
||
copy.PropRows = this.PropRows;
|
||
copy.PropColumns = this.PropColumns;
|
||
copy.PropArr = this.PropArr;
|
||
return copy;
|
||
}
|
||
public string ToJson()
|
||
{
|
||
return JsonUtility.ToJson(this);
|
||
}
|
||
}
|
||
#endif
|