Exemplo n.º 1
0
        void removeComponents(GameObject target)
        {
            var comEnumerator = FilterableComponent.GetEnumerator();

            if (isForNavMesh && CustomEditorGUI.IsMaskedLayer(layerMask, target))
            {
                var col = target.GetComponent <Collider>();
                if (col && col.enabled && !col.isTrigger)
                {
                    var meshObj = MeshForNavmesh.Bake(col);
                    meshObj.transform.parent = RootForNavMesh;
                    meshObj.isStatic         = true;
                    IsoTile tile = target.GetComponentInParent <IsoTile>();
                    if (tile != null)
                    {
                        meshObj.name = tile.name;
                    }
                }
            }

            while (comEnumerator.MoveNext())
            {
                var type = comEnumerator.Current.Key;
                if ((type.IsSubclassOf(typeof(Component)) || type.IsSubclassOf(typeof(MonoBehaviour)) || type.IsInterface) &&
                    !FilteredComponent.Contains(type))
                {
                    var com = target.GetComponent(type);
                    if (com)
                    {
                        DestroyImmediate(com);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public IsoTile NewTile(Vector3 _at, bool _isCoordinates = true)
        {
            IsoTile _newTile = null;

            if (_referenceTile != null)
            {
                _newTile = GameObject.Instantiate(_referenceTile).GetComponent <IsoTile>();
                Undo.RegisterCreatedObjectUndo(_newTile.gameObject, "IsoTile:Create");
            }
            else if (!IsoMap.IsNull)
            {
                _newTile = IsoMap.instance.NewTile_Raw();
            }

            if (!_newTile)
            {
                return(null);
            }

            if (!_isCoordinates)
            {
                _at = coordinates.PositionToCoordinates(_at);
            }

            _newTile.transform.SetParent(transform, false);
            _newTile.coordinates.Move(_at);
            _newTile.Init();
            _newTile.Rename();
            SizeXZ_Update(_newTile.coordinates);
            addToAttachedList(_newTile);
            return(_newTile);
        }
Exemplo n.º 3
0
        public void Clear()
        {
            Do_With_SensorOff(() =>
            {
                Undo.RecordObject(this, "Bulk : Clear");
                for (int i = _attachedList.Count - 1; i >= 0; --i)
                {
                    IsoTile _tile = _attachedList[i];
                    if (_tile == null)
                    {
                        continue;
                    }

                    GameObject _go = _tile.gameObject;
                    if (_go == null)
                    {
                        continue;
                    }
#if UNITY_EDITOR && UNITY_2018_3_OR_NEWER
                    if (Util.PrefabHelper.IsPrefab(_go))
                    {
                        Debug.LogWarning("In Unity 2018.3 or later, To modify the game object of Prefab, you must open and modify the Prefab. That is new Prefab Work Flow.");
                        continue;
                    }
#endif
                    Undo.DestroyObjectImmediate(_go);
                }
                _attachedList.RemoveAll(a => a == null || a.gameObject == null);
            });
            preventZeroTileBulk();
        }
Exemplo n.º 4
0
        public void Copycat(IsoTile from, bool bCopyChild = true, bool bUndoable = true)
        {
            if (from == this)
            {
                return;
            }

            coordinates.Apply_SnapToGrid();

            if (bCopyChild)
            {
                for (int i = transform.childCount - 1; i >= 0; --i)
                {
                    if (bUndoable)
                    {
                        Undo.DestroyObjectImmediate(transform.GetChild(i).gameObject);
                    }
                    else
                    {
                        DestroyImmediate(transform.GetChild(i).gameObject);
                    }
                }

                foreach (Transform child in from.transform)
                {
                    GameObject _newObj = GameObject.Instantiate(child.gameObject, transform, false);
                    if (bUndoable)
                    {
                        Undo.RegisterCreatedObjectUndo(_newObj, "IsoTile:Copycat");
                    }
                }
            }
            // Update_AttachmentList();
        }
Exemplo n.º 5
0
        virtual protected void OnDrawGizmosSelected()
        {
            if (BC == null)
            {
                return;
            }

            GameObject target = UnityEditor.Selection.activeObject as GameObject;

            if (target == BC.gameObject)
            {
                IsoTile _tile = GetComponentInParent <IsoTile>();
                if (!_tile.GetSideObjects(Iso2DObject.Type.Side_Union, Iso2DObject.Type.Side_X, Iso2DObject.Type.Side_Y, Iso2DObject.Type.Side_Z).All(r => target != r.SC.gameObject))
                {
                    return;
                }

                Gizmos.color = new Color(0.95f, 0.5f, 0.05f, 0.65f);
                Bounds _bounds      = GlobalBounds;
                Bounds _tile_bounds = _tile.GetBounds_SideOnly();
                Gizmos.DrawWireCube(_tile_bounds.center, _tile_bounds.size);
                _bounds.center = new Vector3(_bounds.center.x, _tile_bounds.max.y, _bounds.center.z);
                _bounds.size   = new Vector3(_bounds.size.x, 0, _bounds.size.z);
                Gizmos.DrawWireCube(_bounds.center, _bounds.size);
            }
        }
Exemplo n.º 6
0
        public void addToAttachedList(IsoTile tile)
        {
            if (_attachedList.Contains(tile))
            {
                return;
            }

            int i = 0;

            for (; i < _attachedList.Count; ++i)
            {
                Vector3 va = tile.coordinates._xyz;
                Vector3 vb = _attachedList[i].coordinates._xyz;

                if (bYFirstSort)
                {
                    if (va.y > vb.y ||
                        (va.y == vb.y && (va.x > vb.x ||
                                          (va.x == vb.x && va.z > vb.z))))
                    {
                        break;
                    }
                }
                else
                {
                    if (va.x > vb.x ||
                        (va.x == vb.x && (va.y > vb.y ||
                                          (va.y == vb.y && va.z > vb.z))))
                    {
                        break;
                    }
                }
            }
            _attachedList.Insert(i, tile);
        }
Exemplo n.º 7
0
        public void NoRedundancy()
        {
            Undo.RecordObject(this, "Bulk : No Redundancy");
            List <IsoTile> _UniqueList = new List <IsoTile>();
            List <IsoTile> _DelList    = new List <IsoTile>();

            for (int i = _attachedList.Count - 1; i >= 0; --i)
            {
                IsoTile _lookupTile    = _attachedList[i];
                IsoTile _RedundantTile =
                    _UniqueList.Find(r => r.coordinates.IsSame(_lookupTile.coordinates._xyz));
                if (_RedundantTile != null)
                {
                    if (_lookupTile.GetComponentsInChildren <Iso2DObject>().Length >
                        _RedundantTile.GetComponentsInChildren <Iso2DObject>().Length)
                    {
                        _UniqueList.Remove(_RedundantTile);
                        _RedundantTile = null;
                    }
                }
                _UniqueList.Add(_lookupTile);
                if (_RedundantTile != null)
                {
                    _DelList.Add(_RedundantTile);
                }
            }
            Do_With_SensorOff(() => _DelList.ForEach(r => Undo.DestroyObjectImmediate(r.gameObject)));
        }
Exemplo n.º 8
0
        public static List <Iso2DObject> GetSideListOfTileSelection(params Type[] _types)
        {
            List <Iso2DObject> _result = new List <Iso2DObject>();

            foreach (GameObject _go in UnityEditor.Selection.gameObjects)
            {
                if (_go == null)
                {
                    continue;
                }

                IsoTile _t = _go.GetComponent <IsoTile>();
                if (_t == null)
                {
                    continue;
                }

                if (_types[0] == Type.Side_Union)
                {
                    Iso2DObject _Iso2D = _t.GetSideObject(Type.Side_Union);
                    if (_Iso2D != null)
                    {
                        _result.Add(_Iso2D);
                    }
                }
                else
                {
                    _result.AddRange(_t.GetSideObjects(_types));
                }
            }
            return(_result);
        }
Exemplo n.º 9
0
        void copycat_origin(IsoTile from, bool bCopyBody = true, bool bCopyChild = true, bool bUndoable = true)
        {
            if (from == this)
            {
                return;
            }

            string undoName = "IsoTile:Copycat";

            Undo.RecordObject(gameObject, undoName);

            if (bCopyChild)
            {
                List <GameObject> newList = new List <GameObject>();
                List <IsoLight>   lights  = GetLights();

                foreach (Transform child in from.transform)
                {
                    newList.Add(GameObject.Instantiate(child.gameObject, transform, false));
                    var newOne = newList.Last();
                    if (bUndoable)
                    {
                        Undo.RegisterCreatedObjectUndo(newOne, undoName);
                    }
                }

                LightRecivers_RemoveAll(bUndoable);

                for (int i = transform.childCount - 1; i >= 0; --i)
                {
                    GameObject current = transform.GetChild(i).gameObject;
                    if (newList.Contains(current))
                    {
                        continue;
                    }

                    if (bUndoable)
                    {
                        Undo.DestroyObjectImmediate(current);
                    }
                    else
                    {
                        DestroyImmediate(current);
                    }
                }

                for (int i = 0; i < lights.Count; ++i)
                {
                    if (lights[i] != null)
                    {
                        lights[i].AddTarget(transform.gameObject, true);
                    }
                }
                LightRecivers_UpdateAll();
            }
            sortingOrder.Reset_SortingOrder(0, false);
            coordinates.Apply_SnapToGrid();
            // Update_AttachmentList();
        }
Exemplo n.º 10
0
        public IsoTile Duplicate()
        {
            IsoTile result = GameObject.Instantiate(this);

            result.transform.SetParent(transform.parent, false);
            result.Rename();
            Undo.RegisterCreatedObjectUndo(result.gameObject, "IsoTile:Dulicate");
            return(result);
        }
Exemplo n.º 11
0
 void update_InspectorTile()
 {
     if (_tile_Inspector == null || _tile_Inspector.gameObject != Selection.activeGameObject)
     {
         _tile_Inspector = Selection.activeGameObject == null ? null :
                           Selection.activeGameObject.GetComponent <IsoTile>();
         childInfoUpdate();
     }
 }
Exemplo n.º 12
0
 void update_SceneTile()
 {
     if (_tile_Scene == null || _tile_Scene.gameObject != Selection.activeGameObject)
     {
         _tile_Scene = Selection.activeGameObject == null ? null :
                       Selection.activeGameObject.GetComponent <IsoTile>();
         edgeUpdate();
     }
 }
Exemplo n.º 13
0
 public void Rename()
 {
     _attachedList.ForEach(r => {
         IsoTile _tile = r.GetComponent <IsoTile>();
         if (_tile != null)
         {
             _tile.Rename();
         }
     });
 }
Exemplo n.º 14
0
        public static IsoTile Duplicate(this IsoTile tile)
        {
            IsoTile result = GameObject.Instantiate(tile);

            result.transform.SetParent(tile.transform.parent, false);
#if UNITY_EDITOR
            result.Rename();
            Undo.RegisterCreatedObjectUndo(result.gameObject, "IsoTile:Dulicate");
#endif
            return(result);
        }
Exemplo n.º 15
0
        public IsoTile NewTile_Raw()
        {
            if (TilePrefab == null)
            {
                Debug.LogError("IsoMap : No TilePrefab!");
                return(null);
            }
            IsoTile _newTile = GameObject.Instantiate(TilePrefab).GetComponent <IsoTile>();

            Undo.RegisterCreatedObjectUndo(_newTile.gameObject, "IsoTile:Create");
            return(_newTile);
        }
Exemplo n.º 16
0
 public static IsoTile Extrude(this IsoTile tile, Vector3 _direction, bool _bWithAttachment)
 {
     if (tile.IsLastTile(_direction))
     {
         tile.coordinates.Translate(_direction);
         if (!tile.IsAccumulatedTile_Collider(-_direction))
         {
             return(tile.extrude(-_direction, false, _bWithAttachment));
         }
     }
     return(null);
 }
Exemplo n.º 17
0
 IsoTile tile_Extrude(IsoTile _tile, Vector3 _direction, bool _bWithAttachment)
 {
     if (_tile.IsLastTile(_direction))
     {
         _tile.coordinates.Translate(_direction);
         if (!_tile.IsAccumulatedTile_Collider(-_direction))
         {
             return(_tile.Extrude(-_direction, false, _bWithAttachment));
         }
     }
     return(null);
 }
Exemplo n.º 18
0
 void tile_Press(IsoTile _tile, Vector3 _direction, ref List <IsoTile> _moveList, ref List <GameObject> _removeList)
 {
     if (_tile.IsLastTile(-_direction) && !_tile.IsLastTile(_direction))
     {
         IsoTile _removeTile = _tile.NextTile(_direction);
         _moveList.Add(_tile);
         if (_removeTile != null)
         {
             _removeList.Add(_removeTile.gameObject);
         }
     }
 }
Exemplo n.º 19
0
        public IsoTile Extrude(Vector3 _direction, bool _bContinuously, bool _withAttachment)
        {
            IsoTile _new = Duplicate();

            if (!_withAttachment)
            {
                _new.Clear_Attachment(false);
            }
            Undo.RegisterCreatedObjectUndo(_new.gameObject, "IsoTile:Extrude");
            _new.coordinates.Translate(_direction, "IsoTile:Extrude");
            Undo.RecordObject(gameObject, "IsoTile:Extrude");
            return(_new);
        }
Exemplo n.º 20
0
        public static float DropToFloor(this IsoTile _tile, float _fMaxHeight           = 10f, bool bDontMove = false,
                                        QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.Collide)
        {
            if (_tile == null || _tile.gameObject == null)
            {
                return(0);
            }

            var fResult = DropToFloor(_tile.GetBounds_SideOnly(), _tile.gameObject, _fMaxHeight, bDontMove, queryTriggerInteraction);

            _tile.coordinates.Apply_SnapToGrid();
            return(fResult);
        }
Exemplo n.º 21
0
        public List <IsoTile> GetTileList()
        {
            List <IsoTile> _tiles = new List <IsoTile>();

            for (int i = 0; i < transform.childCount; ++i)
            {
                IsoTile _obj = transform.GetChild(i).GetComponent <IsoTile>();
                if (_obj != null)
                {
                    _tiles.Add(_obj);
                }
            }
            return(_tiles);
        }
Exemplo n.º 22
0
 public void Update_ChildList()
 {
     _attachedList.Clear();
     SizeXZ_Clear();
     for (int i = 0; i < transform.childCount; ++i)
     {
         IsoTile _obj = transform.GetChild(i).GetComponent <IsoTile>();
         if (_obj != null)
         {
             _attachedList.Add(_obj);
             SizeXZ_Update(_obj.coordinates);
         }
     }
     Sort();
 }
Exemplo n.º 23
0
        Vector3 CalcEstimatedGridInterval()
        {
            if (_vEstimatedGridInterval != Vector3.zero)
            {
                return(_vEstimatedGridInterval);
            }

            _vEstimatedGridInterval = CalcEstimatedTileSize();
            var _tiles = GetComponentsInChildren <IsoTile>().GetEnumerator();

            if (!_tiles.MoveNext())
            {
                return(_vEstimatedGridInterval);
            }

            IsoTile _lastTile = _tiles.Current as IsoTile;
            bool    bFindX = false, bFindY = false, bFindZ = false;

            while (_tiles.MoveNext())
            {
                var     _tile             = _tiles.Current as IsoTile;
                Vector3 _vCoordinatesDiff = _tile.coordinates._xyz - _lastTile.coordinates._xyz;
                Vector3 _vPositionDiff    = _tile.transform.position - _lastTile.transform.position;

                if (!bFindX && _vCoordinatesDiff.x != 0)
                {
                    _vEstimatedGridInterval.x = Mathf.Abs(_vPositionDiff.x);
                    bFindX = true;
                }
                if (!bFindY && _vCoordinatesDiff.y != 0)
                {
                    _vEstimatedGridInterval.y = Mathf.Abs(_vPositionDiff.y);
                    bFindY = true;
                }
                if (!bFindZ && _vCoordinatesDiff.z != 0)
                {
                    _vEstimatedGridInterval.z = Mathf.Abs(_vPositionDiff.z);
                    bFindZ = true;
                }

                if (bFindX && bFindY && bFindZ)
                {
                    break;
                }
            }
            return(_vEstimatedGridInterval);
        }
Exemplo n.º 24
0
        static IsoTile extrude(this IsoTile tile, Vector3 _direction, bool _bContinuously, bool _withAttachment)
        {
            IsoTile _new = tile.Duplicate();

            if (!_withAttachment)
            {
                _new.Clear_Attachment(false);
            }
#if UNITY_EDITOR
            Undo.RegisterCreatedObjectUndo(_new.gameObject, "IsoTile:Extrude");
#endif
            _new.coordinates.Translate(_direction, "IsoTile:Extrude");
#if UNITY_EDITOR
            Undo.RecordObject(tile.gameObject, "IsoTile:Extrude");
#endif
            return(_new);
        }
Exemplo n.º 25
0
        public List <IsoTile> GetTileList_At(Vector3 atCoordinates)
        {
            List <IsoTile> _tiles = new List <IsoTile>();

            for (int i = 0; i < transform.childCount; ++i)
            {
                IsoTile _obj = transform.GetChild(i).GetComponent <IsoTile>();
                if (_obj != null)
                {
                    if ((atCoordinates - _obj.coordinates._xyz).magnitude < Grid.fGridTolerance)
                    {
                        _tiles.Add(_obj);
                    }
                }
            }
            return(_tiles);
        }
Exemplo n.º 26
0
        public static bool Press(this IsoTile tile, Vector3 _direction)
        {
            if (tile.IsLastTile(-_direction) && !tile.IsLastTile(_direction))
            {
                IsoTile _removeTile = tile.NextTile(_direction);
                tile.coordinates.Translate(_direction);

                if (_removeTile != null)
                {
#if UNITY_EDITOR
                    Undo.DestroyObjectImmediate(_removeTile.gameObject);
#else
                    GameObject.DestroyImmediate(_removeTile.gameObject);
#endif
                }
            }
            return(true);
        }
Exemplo n.º 27
0
        void handle_Extrude(Vector3 _direction, SelectionType _selectionType, bool _singleAction, bool _bWithAttachment)
        {
            Vector3           _lastPos        = _tile_Scene.coordinates._xyz;
            List <GameObject> _newTileObjects = new List <GameObject>();
            IsoTile           _newTile        = null;

            if (_singleAction)
            {
                if ((_newTile = tile_Extrude(_tile_Scene, _direction, _bWithAttachment)) != null)
                {
                    _newTileObjects.Add(_newTile.gameObject);
                }
            }
            else
            {
                foreach (var obj in Selection.gameObjects)
                {
                    if ((_newTile = tile_Extrude(obj.GetComponent <IsoTile>(), _direction, _bWithAttachment)) != null)
                    {
                        _newTileObjects.Add(_newTile.gameObject);
                    }
                }
            }
            if (_newTileObjects.Count > 0)
            {
                Undo.IncrementCurrentGroup();
                switch (_selectionType)
                {
                case SelectionType.LastTile:
                    Selection.objects = _newTileObjects.ToArray();
                    break;

                case SelectionType.NewTile:
                    break;

                case SelectionType.AllTile:
                    Selection.objects = Selection.objects.Concat(_newTileObjects.ToArray()).ToArray();
                    break;
                }
                edgeUpdate();
            }
        }
        void OnEnable()
        {
            if (target != null && (bPrefab = PrefabUtility.GetPrefabType(target).Equals(PrefabType.Prefab)))
            {
                return;
            }

            _rc = (RegularCollider)target;
            if (_rc == null)
            {
                return;
            }

            _t = _rc.GetComponentInParent <IsoTile>();

            _spIso2DScaleMultiplier = serializedObject.FindProperty("_vIso2DScaleMultiplier");

            update_childIso2D_0();
            // _r.update_subColliders();
        }
Exemplo n.º 29
0
        public void ReParent(float fFindRange = 1)
        {
            Bounds _bound   = GlobalBounds;
            var    position = GlobalBounds.center - Vector3.up * GlobalBounds.size.y * 0.5f;
            var    cols     = Physics.OverlapSphere(position, fFindRange);
            var    tiles    = cols.Select(r => {
                var com = r.GetComponent <RegularCollider>();
                return(com != null ? com.Tile : null);
            }).Where(r => r != null).Distinct();

            if (tiles != null)
            {
                float   fMin       = float.MaxValue;
                IsoTile result     = null;
                var     enumerator = tiles.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    var     current   = enumerator.Current;
                    Bounds  bounds    = current.GetBounds_SideOnly();
                    Vector3 pos2      = bounds.center + Vector3.up * bounds.size.y * 0.5f;
                    float   fdistance = Vector3.Distance(position, pos2);
                    if (fdistance < fMin)
                    {
                        fMin   = fdistance;
                        result = current;
                    }
                }
                if (result != null)
                {
                    if (transform.IsChildOf(result.transform))
                    {
                        return;
                    }

                    UnityEditor.Undo.SetTransformParent(transform, result.transform, "Attachment: Change Tile");
                    UnityEditor.Undo.RecordObject(transform, "Attachment: Change Tile");
                    transform.SetParent(result.transform, true);
                    UnityEditor.EditorGUIUtility.PingObject(result.gameObject);
                }
            }
        }
Exemplo n.º 30
0
 bool colliderBTN(Color color, bool bFlag, bool bTrigger, string msg)
 {
     using (new GUIBackgroundColorScope(color))
     {
         if (GUILayout.Button(msg))
         {
             bool bChanged = false;
             foreach (var _targetObject in targets)
             {
                 IsoTile _tile = (IsoTile)_targetObject;
                 if (_tile == null)
                 {
                     continue;
                 }
                 bChanged |= colliderToggle(_tile.gameObject, bFlag, bTrigger);
             }
             return(bChanged);
         }
     }
     return(false);
 }