Beispiel #1
0
        internal void Attach(Powerline edge, IPowerable node1, IPowerable node2)
        {
            bool node1Powered = node1.HasPowerGrid() && grids.ContainsKey(node1.PowerGridInstanceID);
            bool node2Powered = node2.HasPowerGrid() && grids.ContainsKey(node2.PowerGridInstanceID);

            if (node1Powered && node2Powered)
            {
                //deprecate node2's power grid by having node1's power grid usurp it
                PowerGrid deprecatedPowergrid = grids[node2.PowerGridInstanceID];

                grids[node1.PowerGridInstanceID].Usurp(deprecatedPowergrid);

                grids.Remove(deprecatedPowergrid.PowerGridInstanceID);
            }
            else if (node1Powered)
            {
                grids[node1.PowerGridInstanceID].Add(node2);
            }
            else if (node2Powered)
            {
                grids[node2.PowerGridInstanceID].Add(node1);
            }
            else
            {
                PowerGrid newPG = new PowerGrid();
                grids.Add(newPG.PowerGridInstanceID, newPG);
                newPG.Add(node1);
                newPG.Add(node2);
            }

            AddEdge(edge, node1);
            AddEdge(edge, node2);
        }
 // Start is called before the first frame update
 void Awake()
 {
     powerline = GetComponent <Powerline>();
     data      = new PowerlineObjectData {
         isPowered = powerline.isPowered
     };                                                                 //get/set
 }
Beispiel #3
0
        protected override void BeforeMarshal(Transform t = null)
        {
            base.BeforeMarshal(t);

            if (From != null)
            {
                FromPowerableInstanceID = From.PowerableInstanceID;
            }
            if (To != null)
            {
                ToPowerableInstanceID = To.PowerableInstanceID;
            }

            LocalScale = t.localScale;

            if (owner == null && t != null)
            {
                owner = t.GetComponent <Powerline>();
            }

            if (owner is Corridor)
            {
                Base.SerializeFlexData(this, owner as Corridor);
            }
        }
    public override void setLoadData(object obj)
    {
        if (powerline == null)
        {
            powerline = GetComponent <Powerline>();
        }

        data = (PowerlineObjectData)obj;
        powerline.isPowered = data.isPowered;
        Debug.Log("data.ispowered:" + data.isPowered);
    }
Beispiel #5
0
 private void AddEdge(Powerline edge, IPowerable node)
 {
     if (Edges.ContainsKey(node))
     {
         Edges[node].Add(edge);
     }
     else
     {
         Edges[node] = new List <Powerline>()
         {
             edge
         }
     };
 }
Beispiel #6
0
        internal void Detach(Powerline edge, IPowerable node1, IPowerable node2)
        {
            PowerGrid splittingPowerGrid = grids[node1.PowerGridInstanceID];

            //let's take care of the easy cases first
            if (Edges[node1].Count == 1 && Edges[node2].Count == 1) //both are each other's leaf
            {
                //so set them both as "unpowered"
                splittingPowerGrid.Remove(node1);
                splittingPowerGrid.Remove(node2);
                Edges.Remove(node1);
                Edges.Remove(node2);
                //and remove this power grid completely
                grids.Clear();
                grids.Remove(splittingPowerGrid.PowerGridInstanceID);
            }
            else if (Edges[node1].Count == 1) //node 1 is a leaf
            {
                splittingPowerGrid.Remove(node1);
                Edges.Remove(node1);
                Edges[node2].Remove(edge);
            }
            else if (Edges[node2].Count == 1) //node 2 is a leaf
            {
                splittingPowerGrid.Remove(node2);
                Edges.Remove(node2);
                Edges[node1].Remove(edge);
            }
            else //node 1 and 2 are connected to a larger graph
            {
                Edges[node1].Remove(edge);
                Edges[node2].Remove(edge);

                BuildNewPowerGrid(node1);
                BuildNewPowerGrid(node2);

                splittingPowerGrid.Clear();
                grids.Remove(splittingPowerGrid.PowerGridInstanceID);
            }
        }
Beispiel #7
0
        private void DeserializeModules(Dictionary <string, IPowerable> powerableMap)
        {
            _DestroyCurrent <ResourcelessGameplay>();
            _DestroyCurrent <SingleResourceModuleGameplay>();
            _DestroyCurrent <MultipleResourceModuleGameplay>(typeof(Habitat));
            Habitat[] allHabs = Transform.FindObjectsOfType <Habitat>().Where(x => x.isActiveAndEnabled).ToArray();

            Dictionary <string, ModuleGameplay> moduleMap = new Dictionary <string, ModuleGameplay>();

#if UNITY_EDITOR
            reflectionRuns = 0;
            reflectionCheckTime.Reset();
            reflectionPropertyTime.Reset();
#endif

            //we have to look at each data to figure out which prefab to use
            foreach (ResourcelessModuleData data in ResourcelessData)
            {
                Transform t = GameObject.Instantiate(ModuleBridge.Instance.Modules[(int)data.ModuleType], data.Position, data.Rotation) as Transform;

                ResourcelessGameplay r = t.GetComponent <ResourcelessGameplay>();

                r.Data = data;

                moduleMap.Add(data.ModuleInstanceID, r);

                if (!String.IsNullOrEmpty(data.PowerableInstanceID))
                {
                    powerableMap.Add(data.PowerableInstanceID, r);
                }

                DeserializeFlexData(data, r);
            }
            foreach (SingleResourceModuleData data in SingleResourceContainerData)
            {
                Transform t = GameObject.Instantiate(ModuleBridge.Instance.Modules[(int)data.ModuleType], data.Position, data.Rotation) as Transform;

                SingleResourceModuleGameplay r = t.GetComponent <SingleResourceModuleGameplay>();

                r.Data = data;

                moduleMap.Add(data.ModuleInstanceID, r);

                if (!String.IsNullOrEmpty(data.PowerableInstanceID))
                {
                    powerableMap.Add(data.PowerableInstanceID, r);
                }

                DeserializeFlexData(data, r);
            }
            foreach (MultipleResourceModuleData data in MultiResourceContainerData)
            {
                if (data.ModuleType == Buildings.Module.Habitat)
                {
                    SyncToHabitat(allHabs, data, moduleMap, powerableMap);
                }
                else
                {
                    Transform t = GameObject.Instantiate(ModuleBridge.Instance.Modules[(int)data.ModuleType], data.Position, data.Rotation) as Transform;

                    MultipleResourceModuleGameplay r = t.GetComponent <MultipleResourceModuleGameplay>();

                    r.Data = data;

                    moduleMap.Add(data.ModuleInstanceID, r);

                    if (!String.IsNullOrEmpty(data.PowerableInstanceID))
                    {
                        powerableMap.Add(data.PowerableInstanceID, r);
                    }

                    DeserializeFlexData(data, r);
                }
            }
            foreach (PipelineData data in PipeData)
            {
                Transform t = GameObject.Instantiate(PlayerInput.Instance.gasPipePrefab, data.Position, data.Rotation) as Transform;
                t.localScale = data.LocalScale;

                Pipe r = t.GetComponent <Pipe>();
                r.Data = data;
                r.AssignConnections(data.MatterType, moduleMap[data.FromModuleInstanceID], moduleMap[data.ToModuleInstanceID], null, null);
            }
            foreach (PowerlineData data in PowerData)
            {
                Transform prefab = null;
                switch (data.Type)
                {
                default:
                case PowerlineType.Powerline:
                    prefab = PlayerInput.Instance.powerlinePrefab;
                    break;

                case PowerlineType.Umbilical:
                    prefab = PlayerInput.Instance.umbilicalPrefab;
                    break;

                case PowerlineType.Corridor:
                    prefab = PlayerInput.Instance.tubePrefab;
                    break;
                }

                Transform t = GameObject.Instantiate(prefab, data.Position, data.Rotation) as Transform;
                t.localScale = data.LocalScale;

                Powerline r = t.GetComponent <Powerline>();
                r.Data = data;
                DeserializeFlexData(data, r);
                r.AssignConnections(powerableMap[data.FromPowerableInstanceID], powerableMap[data.ToPowerableInstanceID], null, null);
            }
#if UNITY_EDITOR
            UnityEngine.Debug.Log(String.Format("deserialize reflection: {0} run, type checks: {1}ms, property reflection: {2}ms", reflectionRuns, reflectionCheckTime.ElapsedMilliseconds, reflectionPropertyTime.ElapsedMilliseconds));
#endif
        }