예제 #1
0
        private void Start()
        {
            Log.Normal("Using tumbler style widget");


            // make a copy of the funds widget
            Log.Normal("Cloning stock funds widget");
            var copy = (GameObject)GameObject.Instantiate(realFundsWidget.gameObject);

            copy.name = "AlignedCurrencyIndicator.TumblerWidget";

            copy.transform.position = realCostWidget.transform.position;
            copy.transform.parent   = realCostWidget.transform.parent;

            Log.Normal("Cloned stock widget");
            newCostWidget = copy.GetComponent <FundsWidget>();

#if !DEBUG
            Log.Normal("Hiding stock cost widget");

            // hide the stock cost widget
            realCostWidget.gameObject.GetComponentsInChildren <Renderer>().ToList().ForEach(r => r.enabled = false);
#else
            // move the stock cost widget off to the side for comparison
            realCostWidget.transform.Translate(new Vector3(300f, 0f, 0f));
#endif
            Log.Debug("Fixing currency icon");

            newCostWidget.transform.Find("fundsGreen").renderer.enabled = false;
            //newCostWidget.transform.Find("fundsRef").renderer.enabled = true;


            Log.Debug("Modifying TumblerWidget shaders");
            var tumblers = newCostWidget.GetComponentInChildren <Tumblers>();

            foreach (var t in tumblers.GetComponentsInChildren <Tumbler>())
            {
                var mat = t.renderer.material;

                // this is good enough to do what we want
                mat.shader = Shader.Find("Transparent/Specular");
                mat.SetColor("_Color", Color.black);
                mat.SetColor("_SpecColor", Color.red);
                mat.SetFloat("_Shininess", 0f);
            }

            Log.Normal("TumblerWidget: Subscribing to events");
            GameEvents.onGUILaunchScreenVesselSelected.Add(VesselSelected);
            GameEvents.onEditorShipModified.Add(ShipModified);
            GameEvents.OnFundsChanged.Add(FundsChanged);

            CameraListener.Instance.Enqueue(RefreshCost);

            StartCoroutine(WaitForStart());
        }
예제 #2
0
        private void SetCost(double total)
        {
            Tumblers tumblers = newCostWidget.GetComponentInChildren <Tumblers>();

            tumblers.setValue(total);

            // [Log]: AlignedCurrencyIndicator, Tumbler shader: Unlit/Transparent Tint
            //  note to self: tried various methods, couldn't figure out how to change "tint"
            //  so modified shader in start
            tumblers.GetComponentsInChildren <Tumbler>().ToList().ForEach(t =>
            {
                if (t.renderer != null && t.renderer.material != null)
                {
                    t.renderer.material.SetFloat("_Shininess", total > Funding.Instance.Funds ? 0f : 1f);
                }
            });
        }
예제 #3
0
        private System.Collections.IEnumerator WaitForStart()
        {
            Tumblers tumblers = realFundsWidget.GetComponentInChildren <Tumblers>();
            double   current  = tumblers.value;

            while (tumblers.value == current)
            {
                yield return(0);
            }


            // aaaaaaaand one more frame necessary
            yield return(new WaitForEndOfFrame());

            CameraListener.Instance.Enqueue(RefreshCost);

            Log.Normal("TumblerWidget ready");
        }