Exemplo n.º 1
0
            internal void ApplyTo(FlightUIModeController controller)
            {
                Debug.Log("CustomNavBall.ApplyTo", "controller = " + controller);

                if (Nyan.forever)
                {
                    NyanNavBall.ApplyTo(controller);
                    return;
                }

                if (controller == null)
                {
                    return;
                }

                Transform original = DefaultNavBall.Instance?.transform;


                Material newNavball   = controller?.gameObject?.GetChild("NavBall")?.GetComponent <Renderer>()?.material;
                Material stockNavball = original?.gameObject?.GetChild("NavBall")?.GetComponent <Renderer>()?.material;

                Debug.Log("StockTexturesAndColors", "NavBall = " + stockNavball?.GetColor("_TintColor") + "NavBallTex = " + stockNavball?.GetTexture("_MainTexture"));
                if (newNavball != null)
                {
                    newNavball.SetTintColor(NavBall, stockNavball);
                    newNavball.SetMainTexture(NavBallTex, stockNavball);
                }


                GameObject newShadingObj   = controller?.gameObject?.GetChild("NavBall_OverlayMask");
                GameObject stockShadingObj = original?.gameObject?.GetChild("NavBall_OverlayMask");

                if (newShadingObj != null)
                {
                    Image newShading   = newShadingObj?.GetChild("shadingOverlay")?.GetComponent <Image>();
                    Image stockShading = stockShadingObj?.GetChild("shadingOverlay")?.GetComponent <Image>();
                    Debug.Log("StockTexturesAndColors", "Shading = " + stockShading?.color + "ShadingTex = " + stockShading?.sprite?.texture);
                    if (newShading != null)
                    {
                        newShading.SetColor(Shading, stockShading);
                        newShading.SetTexture(ShadingTex, stockShading, true);
                    }

                    Image newShadingMask   = newShadingObj.GetComponent <Image>();
                    Image stockShadingMask = stockShadingObj.GetComponent <Image>();
                    Debug.Log("StockTexturesAndColors", "ShadingMaskTex = " + stockShadingMask?.sprite?.texture);
                    if (newShadingMask != null)
                    {
                        newShadingMask.SetTexture(ShadingMaskTex, stockShadingMask, true);
                    }
                }


                Image newCursor   = controller?.gameObject?.GetChild("NavBallCursor")?.GetComponent <Image>();
                Image stockCursor = original?.gameObject?.GetChild("NavBallCursor")?.GetComponent <Image>();

                Debug.Log("StockTexturesAndColors", "Cursor = " + stockCursor?.color + "CursorTex = " + stockCursor?.sprite?.texture);
                if (newCursor != null)
                {
                    newCursor.SetColor(Cursor, stockCursor);
                    newCursor.SetTexture(CursorTex, stockCursor);
                }


                Renderer[] newVectors   = controller?.gameObject?.GetChild("NavBallVectorsPivot")?.GetComponentsInChildren <Renderer>(true);
                Renderer[] stockVectors = original?.gameObject?.GetChild("NavBallVectorsPivot")?.GetComponentsInChildren <Renderer>(true);

                for (int i = 0; i < newVectors?.Length; i++)
                {
                    string name = newVectors[i]?.name;

                    Material material = newVectors[i]?.material;
                    if (material == null)
                    {
                        continue;
                    }

                    Material stock = stockVectors?.Length > i ? stockVectors[i]?.material : null;

                    if (name == "ProgradeVector")
                    {
                        Debug.Log("StockTexturesAndColors", "ProgradeVector = " + stock?.GetColor("_TintColor") + "ProgradeVectorTex = " + stock?.GetTexture("_MainTexture"));
                        material.SetTintColor(ProgradeVector ?? Vectors, stock);
                        material.SetMainTexture(ProgradeVectorTex ?? VectorsTex, stock);
                    }

                    else

                    if (name == "ProgradeWaypoint")
                    {
                        Debug.Log("StockTexturesAndColors", "ProgradeWaypoint = " + stock?.GetColor("_TintColor") + "ProgradeWaypointTex = " + stock?.GetTexture("_MainTexture"));
                        material.SetTintColor(ProgradeWaypoint ?? Vectors, stock);
                        material.SetMainTexture(ProgradeWaypointTex ?? VectorsTex, stock);
                    }

                    else

                    if (name == "RetrogradeVector")
                    {
                        Debug.Log("StockTexturesAndColors", "RetrogradeVector = " + stock?.GetColor("_TintColor") + "RetrogradeVectorTex = " + stock?.GetTexture("_MainTexture"));
                        material.SetTintColor(RetrogradeVector ?? Vectors, stock);
                        material.SetMainTexture(RetrogradeVectorTex ?? VectorsTex, stock);
                    }

                    else

                    if (name == "RetrogradeWaypoint")
                    {
                        Debug.Log("StockTexturesAndColors", "RetrogradeWaypoint = " + stock?.GetColor("_TintColor") + "RetrogradeWaypointTex = " + stock?.GetTexture("_MainTexture"));
                        material.SetTintColor(RetrogradeWaypoint ?? Vectors, stock);
                        material.SetMainTexture(RetrogradeWaypointTex ?? VectorsTex, stock);
                    }

                    else

                    if (name == "RadialInVector")
                    {
                        Debug.Log("StockTexturesAndColors", "RadialInVector = " + stock?.GetColor("_TintColor") + "RadialInVectorTex = " + stock?.GetTexture("_MainTexture"));
                        material.SetTintColor(RadialInVector ?? Maneuvers, stock);
                        material.SetMainTexture(RadialInVectorTex ?? ManeuversTex, stock);
                    }

                    else

                    if (name == "RadialOutVector")
                    {
                        Debug.Log("StockTexturesAndColors", "RadialOutVector = " + stock?.GetColor("_TintColor") + "RadialOutVectorTex = " + stock?.GetTexture("_MainTexture"));
                        material.SetTintColor(RadialOutVector ?? Maneuvers, stock);
                        material.SetMainTexture(RadialOutVectorTex ?? ManeuversTex, stock);
                    }

                    else

                    if (name == "NormalVector")
                    {
                        Debug.Log("StockTexturesAndColors", "NormalVector = " + stock?.GetColor("_TintColor") + "NormalVectorTex = " + stock?.GetTexture("_MainTexture"));
                        material.SetTintColor(NormalVector ?? Maneuvers, stock);
                        material.SetMainTexture(NormalVectorTex ?? ManeuversTex, stock);
                    }

                    else

                    if (name == "AntiNormalVector")
                    {
                        Debug.Log("StockTexturesAndColors", "AntiNormalVector = " + stock?.GetColor("_TintColor") + "AntiNormalVectorTex = " + stock?.GetTexture("_MainTexture"));
                        material.SetTintColor(AntiNormalVector ?? Maneuvers, stock);
                        material.SetMainTexture(AntiNormalVectorTex ?? ManeuversTex, stock);
                    }

                    else

                    if (name == "BurnVector")
                    {
                        Debug.Log("StockTexturesAndColors", "BurnVector = " + stock?.GetColor("_TintColor") + "BurnVectorTex = " + stock?.GetTexture("_MainTexture"));
                        material.SetTintColor(BurnVector ?? Maneuvers, stock);
                        material.SetMainTexture(BurnVectorTex ?? ManeuversTex, stock);
                    }

                    else

                    if (name == "BurnVectorArrow")
                    {
                        material.SetTintColor(Arrows, stock);
                        material.SetMainTexture(ArrowsTex, stock);
                    }
                }


                UIStateImage[] newButtons   = controller?.gameObject?.GetComponentsInChildren <UIStateImage>();
                UIStateImage[] stockButtons = original?.gameObject?.GetComponentsInChildren <UIStateImage>();

                for (int i = 0; i < newButtons?.Length; i++)
                {
                    string name = newButtons[i]?.name;
                    if (name == "RCS" || name == "SAS")
                    {
                        UIStateImage button = newButtons[i];
                        UIStateImage stock  = stockButtons?.Length > i ? stockButtons[i] : null;

                        button.SetColor(Buttons, stock);
                        button.SetTexture(ButtonsTex, stock);
                    }
                }


                Image newToggle   = controller?.gameObject?.GetChild("ButtonTabToggle")?.GetComponent <Image>();
                Image stockToggle = original?.gameObject?.GetChild("ButtonTabToggle")?.GetComponent <Image>();

                Debug.Log("StockTexturesAndColors", "ButtonsTex = " + stockToggle?.sprite?.texture);
                if (newToggle != null)
                {
                    newToggle.SetColor(Buttons, stockToggle);
                    newToggle.SetTexture(ButtonsTex, stockToggle);
                    newToggle.rectTransform.SetAsLastSibling();
                }


                Image[] newGauges   = controller?.gameObject?.GetChild("SideGauges")?.GetComponentsInChildren <Image>(true);
                Image[] stockGauges = original?.gameObject?.GetChild("SideGauges")?.GetComponentsInChildren <Image>(true);

                for (int i = 0; i < newGauges?.Length; i++)
                {
                    string name = newGauges[i]?.name;

                    if (name == "ThrottleGaugePointerImage" || name == "GeeGaugePointerImage")
                    {
                        Image stock = stockGauges?.Length > i ? stockGauges[i] : null;
                        newGauges[i].SetColor(Buttons, stock);
                        newGauges[i].SetTexture(ButtonsTex, stock);
                    }
                }


                UIStateToggleButton[] newModes   = controller?.gameObject?.GetChild("AutopilotModes")?.GetComponentsInChildren <UIStateToggleButton>(true);
                UIStateToggleButton[] stockModes = original?.gameObject?.GetChild("AutopilotModes")?.GetComponentsInChildren <UIStateToggleButton>(true);

                for (int i = 0; i < newModes?.Length; i++)
                {
                    UIStateToggleButton mode  = newModes[i];
                    UIStateToggleButton stock = stockModes?.Length > i ? stockModes[i] : null;

                    mode.SetColor(Buttons, stock);
                    mode.SetTexture(ButtonsTex, stock);
                }


                Image newFrame   = controller?.gameObject?.GetChild("Frame")?.GetComponent <Image>();
                Image stockFrame = original?.gameObject?.GetChild("Frame")?.GetComponent <Image>();

                Debug.Log("StockTexturesAndColors", "Frame = " + stockFrame?.color + ", FrameTex = " + stockFrame?.sprite?.texture);
                if (newFrame != null)
                {
                    newFrame.SetColor(Frame, stockFrame);
                    newFrame.SetTexture(FrameTex, stockFrame, true, true, FrameTexRes);
                }


                Image headingframe = controller?.gameObject?.GetChild("HeadingFrame")?.GetComponent <Image>();

                if (headingframe != null)
                {
                    headingframe.color = new Color(0, 0, 0, 0);
                }
            }