Exemplo n.º 1
0
        public virtual void Initialize(GameObject go)
        {
            this.go = go;
            PreRenderBehavior pb = go.AddComponent <PreRenderBehavior>();

            pb.ParentFGO = this;
        }
Exemplo n.º 2
0
        public virtual void Initialize(GameObject go, FGOFlags flags)
        {
            this.go = go;

            bool bEnablePreRender = (flags & FGOFlags.EnablePreRender) != 0;

            if (bEnablePreRender)
            {
                if (go.GetComponent <PreRenderBehavior>() != null)
                {
                    throw new Exception("fGameObject.Initialize: tried to add PreRenderBehavior to this go, but already exists!");
                }
                PreRenderBehavior pb = go.AddComponent <PreRenderBehavior>();
                pb.ParentFGO = this;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// This is very hacky.
        /// </summary>
        public static void AddDropShadow(HUDStandardItem item, Cockpit cockpit, Colorf color,
                                         float falloffWidthPx, Vector2f offset, float fZShift, bool bTrackCockpitScaling = true)
        {
            if (item is IBoxModelElement == false)
            {
                throw new Exception("HUDUtil.AddDropShadow: can only add drop shadow to IBoxModelElement");
            }

            float falloffWidth = falloffWidthPx * cockpit.GetPixelScale();

            // [TODO] need interface that provides a HUDShape?
            var   shape = item as IBoxModelElement;
            float w     = shape.Size2D.x + falloffWidth;
            float h     = shape.Size2D.y + falloffWidth;

            fRectangleGameObject meshGO = GameObjectFactory.CreateRectangleGO("shadow", w, h, color, false);

            meshGO.RotateD(Vector3f.AxisX, -90.0f);
            fMaterial dropMat = MaterialUtil.CreateDropShadowMaterial(color, w, h, falloffWidth);

            meshGO.SetMaterial(dropMat);

            item.AppendNewGO(meshGO, item.RootGameObject, false);
            BoxModel.Translate(meshGO, offset, fZShift);

            if (bTrackCockpitScaling)
            {
                PreRenderBehavior pb = meshGO.AddComponent <PreRenderBehavior>();
                pb.ParentFGO = meshGO;
                pb.AddAction(() => {
                    Vector3f posW = item.RootGameObject.PointToWorld(meshGO.GetLocalPosition());
                    ((Material)dropMat).SetVector("_Center", new Vector4(posW.x, posW.y, posW.z, 0));
                    float curWidth    = falloffWidthPx * cockpit.GetPixelScale();
                    Vector2f origSize = shape.Size2D + falloffWidth * Vector2f.One;
                    Vector2f size     = cockpit.GetScaledDimensions(origSize);
                    float ww          = size.x;
                    float hh          = size.y;
                    ((Material)dropMat).SetVector("_Extents", new Vector4(ww / 2, hh / 2, 0, 0));
                    float newWidth = falloffWidthPx * cockpit.GetPixelScale();
                    ((Material)dropMat).SetFloat("_FalloffWidth", newWidth);
                });
            }
        }
Exemplo n.º 4
0
        public virtual void Initialize(GameObject go, FGOFlags flags)
        {
            this.go = go;

            // Link the go to this fGameObject. Normally the fGameObjectRef would not already exist.
            // But it can in two cases:
            //   1) you created the input go by calling Instantiate() on an existing go which
            //      already had an fGameObjectRef. For example this happens at F3 startup with the Camera duplicates.
            //      In that case, it will not be initialized, so fgo is null
            //   2) you cast the input go to an fGameObject before you called this. In that case a default
            //      fGameObject instance was already created that we no longer want. You should not do this!
            //      (Eventually this will throw an Exception!!)
            if (go.GetComponent <fGameObjectRef>() == null)
            {
                go.AddComponent <fGameObjectRef>();
            }
            else
            {
                // [RMS] print error if duplicate FGO created for a GO. This is helpful.
                // However currently CurveRendererImplementation requires an FGO be created
                // *before* it can be passed to a fCurveGameObject =\
                //if (go.GetComponent<fGameObjectRef>().fgo != null)
                //    DebugUtil.Log("Duplicate fGameObject created for go " + go.name);
            }
            go.GetComponent <fGameObjectRef>().fgo = this;

            bool bEnablePreRender = (flags & FGOFlags.EnablePreRender) != 0;

            if (bEnablePreRender)
            {
                if (go.GetComponent <PreRenderBehavior>() != null)
                {
                    throw new Exception("fGameObject.Initialize: tried to add PreRenderBehavior to this go, but already exists!");
                }
                PreRenderBehavior pb = go.AddComponent <PreRenderBehavior>();
                pb.ParentFGO = this;
            }
        }