コード例 #1
0
        /// <summary>
        /// Merges all matching results collected by the enforcer into a single decision.
        /// </summary>
        /// <param name="policyEffectType"></param>
        /// <param name="effects"></param>
        /// <param name="results"></param>
        /// <returns></returns>
        private bool MergeEffects(PolicyEffectType policyEffectType, Span <Effect> effects, Span <float> results)
        {
            bool finalResult = false;

            foreach (var effect in effects)
            {
                if (EffectEvaluator.TryEvaluate(effect, policyEffectType, ref finalResult))
                {
                    return(finalResult);
                }
            }
            return(finalResult);
        }
コード例 #2
0
ファイル: DefaultEffector.cs プロジェクト: waodng/Casbin.NET
        /// <summary>
        /// Merges all matching results collected by the enforcer into a single decision.
        /// </summary>
        /// <param name="policyEffectType"></param>
        /// <param name="effects"></param>
        /// <param name="results"></param>
        /// <param name="hitPolicyIndex"></param>
        /// <returns></returns>
        private static bool MergeEffects(PolicyEffectType policyEffectType, Span <Effect> effects, Span <float> results, out int hitPolicyIndex)
        {
            bool finalResult = false;

            hitPolicyIndex = -1;
            for (int index = 0; index < effects.Length; index++)
            {
                if (EffectEvaluator.TryEvaluate(effects[index], policyEffectType,
                                                ref finalResult, out bool hitPolicy))
                {
                    if (hitPolicy)
                    {
                        hitPolicyIndex = index;
                    }
                    return(finalResult);
                }
            }

            return(finalResult);
        }
コード例 #3
0
        public bool TryChain(Effect effect)
        {
            if (CanChain is false)
            {
                return(false);
            }

            bool result = Result;

            if (EffectEvaluator.TryEvaluate(effect, PolicyEffectType,
                                            ref result, out bool hitPolicy))
            {
                CanChain       = false;
                Result         = result;
                HitPolicy      = hitPolicy;
                HitPolicyCount = hitPolicy ? ++HitPolicyCount : HitPolicyCount;
                return(true);
            }

            Result         = result;
            HitPolicy      = hitPolicy;
            HitPolicyCount = hitPolicy ? ++HitPolicyCount : HitPolicyCount;
            return(true);
        }
コード例 #4
0
        public bool Chain(Effect effect)
        {
            if (CanChain is false)
            {
                throw new InvalidOperationException();
            }

            bool result = Result;

            if (EffectEvaluator.TryEvaluate(effect, PolicyEffectType,
                                            ref result, out bool hitPolicy))
            {
                CanChain       = false;
                Result         = result;
                HitPolicy      = hitPolicy;
                HitPolicyCount = hitPolicy ? ++HitPolicyCount : HitPolicyCount;
                return(true);
            }

            Result         = result;
            HitPolicy      = hitPolicy;
            HitPolicyCount = hitPolicy ? ++HitPolicyCount : HitPolicyCount;
            return(true);
        }
コード例 #5
0
 public ThreeAxisEffector(EffectEvaluator x, EffectEvaluator y, EffectEvaluator z, bool enabled) : base(enabled)
 {
     this.x = x;
     this.y = y;
     this.z = z;
 }
コード例 #6
0
 public TwoAxisEffector(EffectEvaluator x, EffectEvaluator y, bool enabled) : base(enabled)
 {
     this.x = x;
     this.y = y;
 }
コード例 #7
0
        //TODO: REFACTOR THIS !!

        public static bool SetPreset <T>(
            bool isAppearance,
            T values,
            ref EffectEvaluator movementX,
            ref EffectEvaluator movementY,
            ref EffectEvaluator movementZ,
            ref bool setMovement,
            ref float showDuration,
            ref Vector3 scaleVec,
            ref bool setScale,
            ref EffectEvaluator scaleX,
            ref EffectEvaluator scaleY,
            ref float scaleXDuration,
            ref float scaleYDuration,
            ref bool setRotation,
            ref Quaternion rotationQua,
            ref EffectEvaluator rotX,
            ref EffectEvaluator rotY,
            ref EffectEvaluator rotZ,
            ref bool hasTransformEffects,
            ref bool setColor,
            ref ColorCurve colorCurve
            ) where T : PresetBaseValues
        {
            values.Initialize(isAppearance);
            showDuration = values.GetMaxDuration();

            setMovement = values.movementX.enabled || values.movementY.enabled || values.movementZ.enabled;
            if (setMovement)
            {
                movementX = values.movementX;
                movementY = values.movementY;
                movementZ = values.movementZ;
            }

            scaleVec = Vector3.one;
            setScale = values.scaleX.enabled || values.scaleY.enabled;
            if (setScale)
            {
                scaleX = values.scaleX;
                scaleY = values.scaleY;

                scaleVec.z = 1;

                scaleXDuration = scaleX.GetDuration();
                scaleYDuration = scaleY.GetDuration();
            }

            setRotation = values.rotX.enabled || values.rotY.enabled || values.rotZ.enabled;
            rotationQua = Quaternion.identity;
            if (setRotation)
            {
                rotX = values.rotX;
                rotY = values.rotY;
                rotZ = values.rotZ;
            }

            hasTransformEffects = setMovement || setRotation || setScale;

            setColor = values.color.enabled;
            if (setColor)
            {
                colorCurve = values.color;
                colorCurve.Initialize(isAppearance);
            }

            return(hasTransformEffects || setColor);
        }
コード例 #8
0
        public override void SetDefaultValues(AppearanceDefaultValues data)
        {
            int GetPresetIndex()
            {
                for (int i = 0; i < data.presets.Length; i++)
                {
                    if (data.presets[i].effectTag == effectTag)
                    {
                        return(i);
                    }
                }
                return(-1);
            }

            showDuration = 0;

            int presetIndex = GetPresetIndex();

            if (presetIndex >= 0) //found preset
            {
                movementVec = Vector3.zero;

                data.presets[presetIndex].Initialize();
                showDuration = data.presets[presetIndex].GetMaxDuration();

                setMovement = data.presets[presetIndex].movementX.enabled || data.presets[presetIndex].movementY.enabled || data.presets[presetIndex].movementZ.enabled;
                if (setMovement)
                {
                    movementX = data.presets[presetIndex].movementX;
                    movementY = data.presets[presetIndex].movementY;
                    movementZ = data.presets[presetIndex].movementZ;
                }

                scaleVec = Vector3.one;
                setScale = data.presets[presetIndex].scaleX.enabled || data.presets[presetIndex].scaleY.enabled;
                if (setScale)
                {
                    scaleX = data.presets[presetIndex].scaleX;
                    scaleY = data.presets[presetIndex].scaleY;

                    scaleVec.z = 1;

                    scaleXDuration = scaleX.GetDuration();
                    scaleYDuration = scaleY.GetDuration();
                }

                setRotation = data.presets[presetIndex].rotX.enabled || data.presets[presetIndex].rotY.enabled || data.presets[presetIndex].rotZ.enabled;
                rotationQua = Quaternion.identity;
                if (setRotation)
                {
                    rotX = data.presets[presetIndex].rotX;
                    rotY = data.presets[presetIndex].rotY;
                    rotZ = data.presets[presetIndex].rotZ;
                }

                hasTransformEffects = setMovement || setRotation || setScale;

                setColor = data.presets[presetIndex].color.enabled;
                if (setColor)
                {
                    colorCurve = data.presets[presetIndex].color;
                    colorCurve.Initialize();
                }

                enabled = hasTransformEffects || setColor;
            }
        }
コード例 #9
0
ファイル: PresetAppearance.cs プロジェクト: Juno12343412/MANA
 public ThreeAxisEffector(EffectEvaluator x, EffectEvaluator y, EffectEvaluator z)
 {
     this.x = x;
     this.y = y;
     this.z = z;
 }
コード例 #10
0
ファイル: PresetAppearance.cs プロジェクト: Juno12343412/MANA
 public TwoAxisEffector(EffectEvaluator x, EffectEvaluator y)
 {
     this.x = x;
     this.y = y;
 }
コード例 #11
0
        public override void SetDefaultValues(BehaviorDefaultValues data)
        {
            int GetPresetIndex()
            {
                for (int i = 0; i < data.presets.Length; i++)
                {
                    if (data.presets[i].effectTag == effectTag)
                    {
                        return(i);
                    }
                }
                return(-1);
            }

            weightMult = 1;
            timeSpeed  = 1;

            uniformEffectTime = 0;
            weight            = 0;
            isOnOneCharacter  = false;

            int presetIndex = GetPresetIndex();

            if (presetIndex >= 0) //found preset
            {
                data.presets[presetIndex].Initialize();

                emissionControl = data.presets[presetIndex].emission;

                movementVec = Vector3.zero;

                setMovement = data.presets[presetIndex].movementX.enabled || data.presets[presetIndex].movementY.enabled || data.presets[presetIndex].movementZ.enabled;
                if (setMovement)
                {
                    movementX = data.presets[presetIndex].movementX;
                    movementY = data.presets[presetIndex].movementY;
                    movementZ = data.presets[presetIndex].movementZ;
                }

                scaleVec = Vector3.one;
                setScale = data.presets[presetIndex].scaleX.enabled || data.presets[presetIndex].scaleY.enabled;
                if (setScale)
                {
                    scaleX = data.presets[presetIndex].scaleX;
                    scaleY = data.presets[presetIndex].scaleY;

                    scaleVec.z = 1;
                }

                setRotation = data.presets[presetIndex].rotX.enabled || data.presets[presetIndex].rotY.enabled || data.presets[presetIndex].rotZ.enabled;
                rotationQua = Quaternion.identity;
                if (setRotation)
                {
                    rotX = data.presets[presetIndex].rotX;
                    rotY = data.presets[presetIndex].rotY;
                    rotZ = data.presets[presetIndex].rotZ;
                }

                hasTransformEffects = setMovement || setRotation || setScale;

                setColor = data.presets[presetIndex].color.enabled;
                if (setColor)
                {
                    colorCurve = data.presets[presetIndex].color;
                    colorCurve.Initialize();
                }

                enabled = hasTransformEffects || setColor;
            }
        }