// Use this for initialization
    void Start()
    {
        BGCurveBaseMath.Config cfg = new BGCurveBaseMath.Config(BGCurveBaseMath.Fields.PositionAndTangent);
        cMath = new BGCurveBaseMath(curve, cfg);
        //curveDistance = 1f;

        curveTotal = cMath.GetDistance();
    }
Beispiel #2
0
        //after math was created (or inited)
        private void InitAabbVisibleAfter(BGCurveBaseMath.Config config)
        {
            if (!Application.isPlaying)
            {
                return;
            }

            math.ChangeRequested += MathOnChangeRequested;
        }
Beispiel #3
0
        private void InitMath(object sender, EventArgs e)
        {
            //New math
            var config = new BGCurveBaseMath.Config(fields)
            {
                Parts = sectionParts,
                UsePointPositionsToCalcTangents = usePositionToCalculateTangents,
                OptimizeStraightLines           = optimizeStraightLines,
                Fields = fields
            };

            if (updateMode != UpdateModeEnum.Always && Application.isPlaying)
            {
                switch (updateMode)
                {
                case UpdateModeEnum.AabbVisible:
                    InitAabbVisibleBefore(config);
                    break;

                case UpdateModeEnum.RendererVisible:
                    InitRendererVisible(config);
                    break;
                }
            }

            if (math == null)
            {
/*
 *              math = mathType == MathTypeEnum.Base
 *                  ? new BGCurveBaseMath(Curve, config)
 *                  : new BGCurveAdaptiveSplitMath(Curve, config);
 */
                math = new BGCurveBaseMath(Curve, config);

                ChangedParams += InitMath;
                math.Changed  += MathWasChanged;
            }
            else
            {
                math.ChangeRequested -= MathOnChangeRequested;
                math.Init(config);
            }

            if (updateMode == UpdateModeEnum.AabbVisible)
            {
                InitAabbVisibleAfter(config);
            }
        }
            public TestCurves(BGCurve curve, BGCurveBaseMath.Config config, MeshRenderer objectToMove, Material lineRendererMaterial)
                : base(curve.gameObject, lineRendererMaterial, Color.green)
            {
                Curve        = curve;
                Math         = new BGCurveBaseMath(curve, config);
                ObjectToMove = objectToMove;

                AddObject(objectToMove.gameObject);
                AddObjects(ObjectsCount - 1, objectToMove, curve.transform);

                const float offset = 1 / (float)ObjectsCount;

                for (var i = 0; i < ObjectsCount; i++)
                {
                    DistanceRatios.Add(i * offset);
                }
            }
    // Use this for initialization
    void Start()
    {
        hp = maxHp;
        BGCurveBaseMath.Config cfg = new BGCurveBaseMath.Config(BGCurveBaseMath.Fields.PositionAndTangent);
        cMath         = new BGCurveBaseMath(curve, cfg);
        curveDistance = 1f;

        curveTotal = cMath.GetDistance();
        animator   = GetComponentInChildren <Animator>();

        rbs     = transform.GetComponentsInChildren <Rigidbody>();
        rbRends = new List <Renderer>();
        foreach (Rigidbody r in rbs)
        {
            rbRends.Add(r.gameObject.GetComponent <Renderer>());
        }
    }
Beispiel #6
0
        //attach visibility check component to target GameObject (the one, the renderer is attached to)
        private void InitVisibilityCheck(BGCurveBaseMath.Config config, Renderer renderer)
        {
            if (visibilityCheck != null)
            {
                visibilityCheck.BecameVisible -= BecameVisible;
                Destroy(visibilityCheck);
            }

            if (renderer == null)
            {
                return;
            }

            visibilityCheck = renderer.gameObject.AddComponent <VisibilityCheck>();

            visibilityCheck.BecameVisible += BecameVisible;

            config.ShouldUpdate = () => visibilityCheck.Visible;
        }
Beispiel #7
0
        //before math was created (or inited)
        private void InitAabbVisibleBefore(BGCurveBaseMath.Config config)
        {
            if (!Application.isPlaying)
            {
                return;
            }

            if (meshFilter != null)
            {
                Destroy(meshFilter.gameObject);
            }

            var aabbGameObject = new GameObject("AabbBox");

            aabbGameObject.transform.parent = transform;
            var renderer = aabbGameObject.AddComponent <MeshRenderer>();

            meshFilter      = aabbGameObject.AddComponent <MeshFilter>();
            meshFilter.mesh = new Mesh();
            MathOnChangeRequested(null, null);
            InitVisibilityCheck(config, renderer);
        }
            public CurveData(TestCurves testCurves, string name, string description, Vector3 position, BGCurveBaseMath.Config config, MathTypeEnum mathType)
                : base(new GameObject(name), testCurves.LineRendererMaterial, Color.magenta)
            {
                this.testCurves  = testCurves;
                this.description = description;

                //game object
                GameObject.transform.position = position;
                origin = position;

                //curve
                Curve        = GameObject.AddComponent <BGCurve>();
                Curve.Closed = testCurves.Curve.Closed;

                //add points
                for (var i = 0; i < testCurves.Curve.PointsCount; i++)
                {
                    var point      = testCurves.Curve[i];
                    var clonePoint = new BGCurvePoint(Curve, point.PositionLocal, point.ControlType, point.ControlFirstLocal, point.ControlSecondLocal);
                    Curve.AddPoint(clonePoint);
                }

                //init math after points are added
                switch (mathType)
                {
                case MathTypeEnum.Base:
                    Math = new BGCurveBaseMath(Curve, config);
                    break;

                case MathTypeEnum.Formula:
#pragma warning disable 0618
                    Math = new BGCurveFormulaMath(Curve, config);
#pragma warning restore 0618

                    break;

                case MathTypeEnum.Adaptive:
                    Math = new BGCurveAdaptiveMath(Curve, (BGCurveAdaptiveMath.ConfigAdaptive)config);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("mathType", mathType, null);
                }

                AddObjects(ObjectsCount, testCurves.ObjectToMove, GameObject.transform);

                //scale down
                GameObject.transform.localScale = originalScale;
            }
Beispiel #9
0
 //setup renderer visible option for update mode
 private void InitRendererVisible(BGCurveBaseMath.Config config)
 {
     InitVisibilityCheck(config, RendererForUpdateCheck);
 }
Beispiel #10
0
            public SomeCurveData(MyCurveData referenceCurve, string name, Vector3 position, BGCurveBaseMath.Config config)
                : base(new GameObject(name), referenceCurve.LineRendererMaterial, Color.magenta)
            {
                this.referenceCurve = referenceCurve;

                //game object
                GameObject.transform.parent     = referenceCurve.GameObject.transform.parent;
                GameObject.transform.localScale = localScale;
                GameObject.transform.position   = position;
                origin = position;

                //curve
                Curve        = GameObject.AddComponent <BGCurve>();
                Curve.Closed = referenceCurve.Curve.Closed;

                //add points
                for (var i = 0; i < referenceCurve.Curve.PointsCount; i++)
                {
                    Curve.AddPoint(referenceCurve.Curve[i].CloneTo(Curve));
                }

                //init math after points are added
                Math = new BGCurveBaseMath(Curve, config);

                AddObjects(ObjectsCount, referenceCurve.ObjectToMove, referenceCurve.Curve.transform.parent);
            }