void Awake()
        {
            graphic      = transform.Find("Graphic").GetComponent <SpriteRenderer>();
            nameText     = transform.Find("Name").GetComponent <TextMesh>();
            statusText   = transform.Find("Status").GetComponent <TextMesh>();
            relComponent = GetComponent <ShipComponent>();

            baseColor = graphic.color;
        }
示例#2
0
        /// <summary>
        /// The main logic of the flow. Runs as a coroutine to allow adding delays
        /// to play animations
        /// </summary>
        virtual protected IEnumerator FlowRoutine()
        {
            // Avoids running two flows at once
            yield return(new WaitUntil(() => !runningFlow));

            runningFlow = true;
            Queue <ShipComponent.Output> queue = new Queue <ShipComponent.Output>();

            // Start with origins
            foreach (ShipComponent c in allComponents)
            {
                c.ResetIncoming();
                if (c.IsOrigin())
                {
                    // Creates an empty output that goes to the origins to start the flow process through them
                    ShipComponent.Output originComponent = new ShipComponent.Output(c, ElementTypes.None, 0f);
                    queue.Enqueue(originComponent);
                }
            }

            while (queue.Count > 0)
            {
                ShipComponent.Output transmission = queue.Dequeue();
                ShipComponent        curr         = transmission.component;
                curr.UpdateInput(transmission.type, transmission.amount);
                float delay = 0f;
                yield return(new WaitForSeconds(delay));

                int remainingIncoming = curr.GetRemainingIncoming();
                if (remainingIncoming > 0)
                {
                    continue;
                }

                List <ShipComponent.Output> children = curr.Process();
                foreach (ShipComponent.Output t in children)
                {
                    queue.Enqueue(t);
                }
            }

            runningFlow = false;
        }
示例#3
0
        protected override List <Output> InnerProcess()
        {
            List <Output> outputs  = new List <Output>();
            ElementTypes  passType = (ElementTypes)incoming[0].type;

            for (int i = 0; i < children.Length; i++)
            {
                ShipComponent child = children[i];
                Output        t     = new Output(child, passType, distribution[i] * incoming[0].amount);
                outputs.Add(t);
            }

            string textualDistribution = "";

            foreach (float percentage in distribution)
            {
                textualDistribution += (int)(percentage * 100) + "% - ";
            }
            SetStatus("Distributing " + incoming[0].amount + " " + passType + " by " +
                      // Removing the extra ' - ' from the distribution text
                      textualDistribution.Substring(0, textualDistribution.Length - 3));
            return(outputs);
        }
示例#4
0
 public Output(ShipComponent comp, ElementTypes type, float amount)
 {
     this.component = comp;
     this.type      = type;
     this.amount    = amount;
 }