Example #1
0
        // TODO: damageType, collisionFlags

        public Hurtbox(uint lifeSpan, uint damage, HurtboxType hurtboxType, uint tickRate = 60, Entity sourceEntity = null) : base(100, 100)
        {
            physicsLayer = 0;

            if (lifeSpan <= 0)
            {
                Debug.warn("Lifespan must be more than 0");
                return;
            }

            if (tickRate <= 0)
            {
                // Default the tickrate to 60 or lifespan, whichever is less
                Debug.warn("tickRate must be more than 0; Setting default");
                tickRate = lifeSpan > 60 ? 60 : lifeSpan;
            }

            this.lifeSpan    = lifeSpan;
            this.damage      = damage;
            this.tickRate    = tickRate;
            this.hurtboxType = hurtboxType;

            if (sourceEntity != null)
            {
                this.sourceEntity = sourceEntity;
            }

            damagedEntities = new List <Entity>();
        }
        public static Color GetHurtboxColor(HurtboxType type)
        {
            Color typeColor;

            if (HurtboxTypeColors.TryGetValue(type, out typeColor))
            {
                return(typeColor);
            }
            return(Color.grey);
        }
Example #3
0
        void SetAllHurtboxTypes(HurtboxType type)
        {
            var serializedObjs = GetAllChildren <Hurtbox>();

            Undo.IncrementCurrentGroup();
            var hurtboxes = serializedObjs.Select(obj => obj.targetObject as Hurtbox);
            var objs      = hurtboxes.Cast <Object>().ToArray();

            Undo.RecordObjects(objs, "Change Hurtbox Type");
            foreach (var hurtbox in hurtboxes)
            {
                hurtbox.Type = type;
            }
            Undo.FlushUndoRecordObjects();
        }
Example #4
0
            public Color32 GetHurtboxColor(HurtboxType type)
            {
                switch (type)
                {
                case HurtboxType.DAMAGEABLE: return(Damageable);

                case HurtboxType.INVINCIBLE: return(Invincible);

                case HurtboxType.INTANGIBLE: return(Intangible);

                case HurtboxType.SHIELD: return(Shield);

                case HurtboxType.GRAZING: return(Grazing);

                default: return(Color.grey);
                }
            }
Example #5
0
        /// <summary>
        /// OnGUI is called for rendering and handling GUI events.
        /// This function can be called multiple times per frame (one call per event).
        /// </summary>
        void OnGUI()
        {
            if (table == null)
            {
                BuildTable();
            }
            var pos = position;

            pos.x       = 0f;
            pos.y       = 0f;
            pos.height -= 16f;

            _roots = _roots ?? new GameObject[0];

            table.Draw(pos, GetAllChildren <Hitbox>().Concat(GetAllChildren <Hurtbox>()));

            pos.y      = pos.y + pos.height;
            pos.height = 16f;
            pos.width -= 200;

            hurtboxType = (HurtboxType)EditorGUI.EnumPopup(pos, hurtboxType);

            pos.x    += pos.width;
            pos.width = 200;

            if (GUI.Button(pos, "Set Hurtbox Type"))
            {
                SetAllHurtboxTypes(hurtboxType);
            }

            // Force Repaint the animation view if something changed.
            if (GUI.changed)
            {
                InternalEditorUtility.RepaintAllViews();
            }
        }
 public HurtboxBuilder WithType(HurtboxType type)
 {
     Hurtbox.Type = type;
     return(this);
 }