备份CatanBuilding瘦身独立工程
This commit is contained in:
117
Assets/Scripts/SandDigEditorScript/Scriptable/CubeConfigData.cs
Normal file
117
Assets/Scripts/SandDigEditorScript/Scriptable/CubeConfigData.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
|
||||
#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
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44be26f5034e36f4fbc04cc64aedd5b2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
[CustomEditor(typeof(CubeConfigData))]
|
||||
[ExecuteInEditMode]
|
||||
public class PropDataEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
CubeConfigData gridData = (CubeConfigData)target;
|
||||
|
||||
DrawDefaultInspector();
|
||||
|
||||
if (GUILayout.Button("Initialize Grid"))
|
||||
{
|
||||
gridData.InitializePropGrid();
|
||||
}
|
||||
var arr = gridData.GetArray();
|
||||
// 显示和编辑二维数组
|
||||
if (gridData.PropArr != null)
|
||||
{
|
||||
for (int i = gridData.PropRows - 1; i >= 0; i--)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
for (int j = 0; j < gridData.PropColumns; j++)
|
||||
{
|
||||
// arr[i, j] = EditorGUILayout.IntField(i + "x" + j,arr[i, j]);
|
||||
// Debug.Log(i + "x" + j);
|
||||
arr[i, j] = EditorGUILayout.IntField(arr[i, j]);
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Save Grid"))
|
||||
{
|
||||
gridData.Serializable2DArray(arr);
|
||||
// 修改数据后
|
||||
EditorUtility.SetDirty(gridData);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71f7ac147135573479477bcf96432d0c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user