Files
back_cantanBuilding/Assets/Scripts/SandDigEditorScript/Scriptable/CubeConfigData.cs
2026-05-26 16:15:54 +08:00

118 lines
2.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#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("090180270左")]
[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