コード例 #1
0
        // Apply damage
        public static bool ApplyDamage(RayfireRigid scr, float damageValue, Vector3 damagePoint, float damageRadius = 0f)
        {
            // Initialize if not
            if (scr.initialized == false)
            {
                scr.Initialize();
            }

            // Already demolished or should be
            if (scr.limitations.demolished == true || scr.limitations.demolitionShould == true)
            {
                return(false);
            }

            // Apply damage and get demolition state
            bool demolitionState = Apply(scr, damageValue);

            // TODO demolish first to activate only demolished fragments AND activate if object can't be demolished

            // Set demolition info
            if (demolitionState == true)
            {
                // Demolition available check
                if (scr.DemolitionState() == false)
                {
                    return(false);
                }

                // Set damage position
                scr.limitations.contactVector3     = damagePoint;
                scr.clusterDemolition.damageRadius = damageRadius;

                // Demolish object
                scr.limitations.demolitionShould = true;

                // Demolish
                scr.Demolish();

                // Was demolished
                if (scr.limitations.demolished == true)
                {
                    return(true);
                }
            }

            // Check for activation
            if (scr.activation.byDamage > 0 && scr.damage.currentDamage > scr.activation.byDamage)
            {
                scr.Activate();
            }

            return(false);
        }