undo-redo for create tiled map and property holder

This commit is contained in:
2016-02-02 00:21:21 +06:00
parent 46e2e830b5
commit 1920b49e47
9 changed files with 236 additions and 46 deletions

View File

@@ -68,6 +68,7 @@
<Compile Include="Assets\IsoTools\Tiled\TiledMap.cs" />
<Compile Include="Assets\IsoTools\Tiled\TiledMapAsset.cs" />
<Compile Include="Assets\IsoTools\Tiled\TiledMapLayer.cs" />
<Compile Include="Assets\IsoTools\Tiled\TiledMapProperties.cs" />
<Compile Include="Assets\IsoTools\Tiled\TiledMapTile.cs" />
<Reference Include="UnityEngine.UI">
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll</HintPath>

View File

@@ -61,7 +61,9 @@ namespace IsoTools.Internal {
}
float ZMoveIsoObjects(float delta) {
Undo.RecordObjects(_iso_zpositions.Keys.ToArray(), "Move");
Undo.RecordObjects(
_iso_zpositions.Keys.ToArray(),
_iso_zpositions.Count > 1 ? "Move IsoObjects" : "Move IsoObject");
var is_any_alignment = isAnyAlignment;
return _iso_zpositions.Aggregate(0.0f, (AccIn, pair) => {
var iso_object = pair.Key;
@@ -77,7 +79,9 @@ namespace IsoTools.Internal {
}
Vector3 XYMoveIsoObjects(Vector3 delta) {
Undo.RecordObjects(_positions.Keys.ToArray(), "Move");
Undo.RecordObjects(
_positions.Keys.ToArray(),
_positions.Count > 1 ? "Move IsoObjects" : "Move IsoObject");
var is_any_alignment = isAnyAlignment;
return _positions.Aggregate(Vector3.zero, (AccIn, pair) => {
var iso_object = pair.Key;

View File

@@ -10,11 +10,11 @@ namespace IsoTools {
[ExecuteInEditMode, DisallowMultipleComponent]
public class IsoObject : MonoBehaviour {
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// Mode
//
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
public enum Mode {
Mode2d,
@@ -32,11 +32,11 @@ namespace IsoTools {
}
}
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// Size
//
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
[SerializeField]
Vector3 _size = Vector3.one;
@@ -76,11 +76,11 @@ namespace IsoTools {
get { return new Vector2(sizeX, sizeZ); }
}
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// Position
//
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
[SerializeField]
Vector3 _position = Vector3.zero;
@@ -120,11 +120,11 @@ namespace IsoTools {
get { return new Vector2(positionX, positionZ); }
}
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// TilePosition
//
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
public Vector3 tilePosition {
get { return IsoUtils.Vec3Round(position); }
@@ -158,11 +158,11 @@ namespace IsoTools {
get { return new Vector2(tilePositionX, tilePositionZ); }
}
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// Internal
//
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
public class InternalState {
public bool Dirty = false;
@@ -178,11 +178,11 @@ namespace IsoTools {
public InternalState Internal = new InternalState();
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// For editor
//
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
#if UNITY_EDITOR
Vector3 _lastSize = Vector3.zero;
@@ -203,11 +203,11 @@ namespace IsoTools {
}
#endif
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// Functions
//
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
IsoWorld _isoWorld = null;
public IsoWorld isoWorld {
@@ -270,11 +270,11 @@ namespace IsoTools {
#endif
}
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// Messages
//
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
void Awake() {
Internal.SelfDepends = new HashSet<IsoObject>(new IsoObject[47]);

View File

@@ -33,11 +33,11 @@ namespace IsoTools {
Vector2 _sectorsMaxNumPos = Vector2.zero;
Vector2 _sectorsNumPosCount = Vector2.zero;
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// Constants
//
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
public static readonly float DefTileSize = 32.0f;
public static readonly float MinTileSize = Mathf.Epsilon;
@@ -63,11 +63,11 @@ namespace IsoTools {
public static readonly float MinStartDepth = float.MinValue;
public static readonly float MaxStartDepth = float.MaxValue;
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// Sorting properties
//
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
[SerializeField]
public float _tileSize = DefTileSize;
@@ -129,11 +129,11 @@ namespace IsoTools {
}
}
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// IsoToScreen/ScreenToIso
//
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
public Vector2 IsoToScreen(Vector3 iso_pnt) {
if ( _dirtyMat ) {
@@ -160,11 +160,11 @@ namespace IsoTools {
iso_z);
}
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// TouchIsoPosition
//
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
public Vector3 TouchIsoPosition(int finger_id) {
return TouchIsoPosition(finger_id, 0.0f);
@@ -199,11 +199,11 @@ namespace IsoTools {
return Vector3.zero;
}
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// TouchIsoTilePosition
//
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
public Vector3 TouchIsoTilePosition(int finger_id) {
return IsoUtils.Vec3Floor(TouchIsoPosition(finger_id));
@@ -221,11 +221,11 @@ namespace IsoTools {
return IsoUtils.Vec3Floor(TouchIsoPosition(finger_id, camera, iso_z));
}
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// MouseIsoPosition
//
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
public Vector3 MouseIsoPosition() {
return MouseIsoPosition(0.0f);
@@ -253,11 +253,11 @@ namespace IsoTools {
iso_z);
}
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// MouseIsoTilePosition
//
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
public Vector3 MouseIsoTilePosition() {
return IsoUtils.Vec3Floor(MouseIsoPosition());
@@ -275,11 +275,11 @@ namespace IsoTools {
return IsoUtils.Vec3Floor(MouseIsoPosition(camera, iso_z));
}
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// Internal
//
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
public void MarkDirty() {
if ( !_dirty ) {
@@ -308,11 +308,11 @@ namespace IsoTools {
_oldVisibles.Remove(iso_object);
}
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// Private
//
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
void MarkDirtyIsoMatrix() {
_dirtyMat = true;
@@ -634,11 +634,11 @@ namespace IsoTools {
trans.position = IsoUtils.Vec3ChangeZ(trans.position, depth);
}
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// Messages
//
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
void Start() {
ChangeSortingProperty();

View File

@@ -146,7 +146,7 @@ Camera:
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 3
orthographic size: 6
m_Depth: -1
m_CullingMask:
serializedVersion: 2

View File

@@ -132,6 +132,7 @@ namespace IsoTools.Tiled.Internal {
Debug.LogErrorFormat("Create tiled map error: {0}", e.Message);
DestroyImmediate(map_go, true);
}
Undo.RegisterCreatedObjectUndo(map_go, "Create TiledMap");
}
}
}

View File

@@ -13,17 +13,18 @@ namespace IsoTools.Tiled {
public TiledMapAsset Asset = null;
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// Functions
//
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
//
// Messages
//
// ------------------------------------------------------------------------
// ---------------------------------------------------------------------
void Awake() {
}

View File

@@ -0,0 +1,171 @@
using UnityEngine;
using System.Globalization;
using System.Collections.Generic;
namespace IsoTools.Tiled {
public class TiledMapProperties {
List<string> _properties = null;
// -----------------------------
// Functions
// -----------------------------
public TiledMapProperties(List<string> properties) {
_properties = properties;
}
public bool Has(string property_name) {
if ( _properties != null ) {
for ( var i = 0; i < _properties.Count / 2; ++i ) {
if ( _properties[i * 2] == property_name ) {
return true;
}
}
}
return false;
}
// -----------------------------
// GetAsX
// -----------------------------
public bool GetAsBool(string property_name) {
bool value;
if ( TryGetAsBool(property_name, out value) ) {
return value;
}
throw new UnityException("find or parse parameter error");
}
public short GetAsShort(string property_name) {
short value;
if ( TryGetAsShort(property_name, out value) ) {
return value;
}
throw new UnityException("find or parse parameter error");
}
public int GetAsInt(string property_name) {
int value;
if ( TryGetAsInt(property_name, out value) ) {
return value;
}
throw new UnityException("find or parse parameter error");
}
public long GetAsLong(string property_name) {
long value;
if ( TryGetAsLong(property_name, out value) ) {
return value;
}
throw new UnityException("find or parse parameter error");
}
public float GetAsFloat(string property_name) {
float value;
if ( TryGetAsFloat(property_name, out value) ) {
return value;
}
throw new UnityException("find or parse parameter error");
}
public double GetAsDouble(string property_name) {
double value;
if ( TryGetAsDouble(property_name, out value) ) {
return value;
}
throw new UnityException("find or parse parameter error");
}
public string GetAsString(string property_name) {
string value;
if ( TryGetAsString(property_name, out value) ) {
return value;
}
throw new UnityException("find or parse parameter error");
}
// -----------------------------
// TryGetAsX
// -----------------------------
public bool TryGetAsBool(string property_name, out bool value) {
string property_value;
if ( TryGetAsString(property_name, out property_value) ) {
if ( bool.TryParse(property_value, out value) ) {
return true;
}
}
value = false;
return false;
}
public bool TryGetAsShort(string property_name, out short value) {
string property_value;
if ( TryGetAsString(property_name, out property_value) ) {
if ( short.TryParse(property_value, NumberStyles.Any, CultureInfo.InvariantCulture, out value) ) {
return true;
}
}
value = 0;
return false;
}
public bool TryGetAsInt(string property_name, out int value) {
string property_value;
if ( TryGetAsString(property_name, out property_value) ) {
if ( int.TryParse(property_value, NumberStyles.Any, CultureInfo.InvariantCulture, out value) ) {
return true;
}
}
value = 0;
return false;
}
public bool TryGetAsLong(string property_name, out long value) {
string property_value;
if ( TryGetAsString(property_name, out property_value) ) {
if ( long.TryParse(property_value, NumberStyles.Any, CultureInfo.InvariantCulture, out value) ) {
return true;
}
}
value = 0;
return false;
}
public bool TryGetAsFloat(string property_name, out float value) {
string property_value;
if ( TryGetAsString(property_name, out property_value) ) {
if ( float.TryParse(property_value, NumberStyles.Any, CultureInfo.InvariantCulture, out value) ) {
return true;
}
}
value = 0;
return false;
}
public bool TryGetAsDouble(string property_name, out double value) {
string property_value;
if ( TryGetAsString(property_name, out property_value) ) {
if ( double.TryParse(property_value, NumberStyles.Any, CultureInfo.InvariantCulture, out value) ) {
return true;
}
}
value = 0;
return false;
}
public bool TryGetAsString(string property_name, out string value) {
if ( _properties != null ) {
for ( var i = 0; i < _properties.Count / 2; ++i ) {
if ( _properties[i * 2] == property_name ) {
value = _properties[i * 2 + 1];
return true;
}
}
}
value = string.Empty;
return false;
}
}
} // namespace IsoTools.Tiled

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: fa7b674b7f7ae4c11a2df9172b4020ba
timeCreated: 1454346480
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: