示例#1
0
        public static GameObject GameWorld(GameObject target)
        {
            GameObject          gameWorld = null;
            ApexComponentMaster master;

            Component identifier = ComponentHelper.FindFirstComponentInScene <GameServicesInitializerComponent>();

            if (identifier == null)
            {
                identifier = ComponentHelper.FindFirstComponentInScene <LoadBalancerComponent>();
            }

            if (identifier != null)
            {
                gameWorld = identifier.gameObject;
                Debug.Log("Existing game world found, updating that.");
            }
            else if (target != null)
            {
                gameWorld = target;
            }
            else
            {
                gameWorld = new GameObject("Game World");
                Debug.Log("No game world found, creating one.");
            }

            bool toggleAll = gameWorld.AddIfMissing <ApexComponentMaster>(false, out master);

            gameWorld.AddIfMissing <GameServicesInitializerComponent>(true);
            gameWorld.AddIfMissing <NavigationSettingsComponent>(true);

            if (gameWorld.AddIfMissing <GridComponent>(true))
            {
                gameWorld.AddIfMissing <GridVisualizer>(false);
            }

            LayerMappingComponent lmc;

            if (gameWorld.AddIfMissing <LayerMappingComponent>(true, out lmc))
            {
                EnsureLayers(lmc);
            }

            gameWorld.AddIfMissing <PathServiceComponent>(true);
            gameWorld.AddIfMissing <LoadBalancerComponent>(true);

            ExtendGameWorld(gameWorld);

            if (toggleAll)
            {
                master.ToggleAll();
            }

            return(gameWorld);
        }
示例#2
0
 internal static void LoadBalancer(GameObject target)
 {
     if (ComponentHelper.FindFirstComponentInScene <LoadBalancerComponent>() != null)
     {
         return;
     }
     if (target != null)
     {
         target.AddComponent <LoadBalancerComponent>();
         return;
     }
     (new GameObject("Load Balancer")).AddComponent <LoadBalancerComponent>();
     Debug.Log("No Load Balancer found, creating one.");
 }
示例#3
0
 public static bool AddIfMissing <T>(this GameObject target, bool entireScene, out T component)
     where T : Component
 {
     if (!entireScene)
     {
         component = target.GetComponent <T>();
     }
     else
     {
         component = ComponentHelper.FindFirstComponentInScene <T>();
     }
     if (component != null)
     {
         return(false);
     }
     component = target.AddComponent <T>();
     return(true);
 }
        internal static void LoadBalancer(GameObject target)
        {
            var lb = ComponentHelper.FindFirstComponentInScene <LoadBalancerComponent>();

            if (lb != null)
            {
                return;
            }
            else if (target != null)
            {
                target.AddComponent <LoadBalancerComponent>();
            }
            else
            {
                var go = new GameObject("Load Balancer");
                go.AddComponent <LoadBalancerComponent>();
                Debug.Log("No Load Balancer found, creating one.");
            }
        }
示例#5
0
        private static T AddGameWorldItem <T>(Initializer <T> init = null) where T : Component
        {
            GameObject gameWorld = null;

            var servicesInitializer = ComponentHelper.FindFirstComponentInScene <GameServicesInitializerComponent>();

            if (servicesInitializer != null)
            {
                gameWorld = servicesInitializer.gameObject;

                T   item;
                var added = gameWorld.AddIfMissing <T>(false, out item);

                if (init != null)
                {
                    init(gameWorld, item, added);
                }

                return(item);
            }

            return(null);
        }
示例#6
0
        public override bool Upgrade()
        {
            bool changed = false;

            changed |= Replace <ApexComponentMasterOld, ApexComponentMaster>(
                (a, b) =>
            {
                SetPrivate(b, "_firstTime", a._firstTime);
            });

            changed |= Replace <LoadBalancerComponentOld, LoadBalancerComponent>(
                (a, b) =>
            {
                SetPrivate(b, "_configurations", a._configurations);
                SetPrivate(b, "_mashallerMaxMillisecondPerFrame", a._mashallerMaxMillisecondPerFrame);
            });

            changed |= Replace <LoadBalancerPerformanceVisualizerOld, LoadBalancerPerformanceVisualizer>();

            changed |= Replace <TurnableUnitComponent, SteerToAlignWithVelocity>(
                (a, b) =>
            {
                b.alignWithElevation = (a.ignoreAxis == WorldGeometry.Axis.None);
            });

            var nscAdded = false;
            var nsc      = AddGameWorldItem <NavigationSettingsComponent>(
                (gw, ns, added) =>
            {
                nscAdded = added;
                if (added)
                {
                    var grid = ComponentHelper.FindFirstComponentInScene <GridComponent>();
                    if (grid == null)
                    {
                        return;
                    }

                    ns.heightSamplingGranularity = grid.heightGranularity;

                    var unitnav                        = ns.unitsHeightNavigationCapability;
                    unitnav.maxClimbHeight             = grid.maxScaleHeight;
                    unitnav.maxSlopeAngle              = grid.maxWalkableSlopeAngle;
                    ns.unitsHeightNavigationCapability = unitnav;
                }

                //Fix old sphere cast option
                if ((int)ns.heightSampling == 3)
                {
                    ns.heightSampling = HeightSamplingMode.Raycast;
                    changed           = true;
                }
            });

            changed |= nscAdded;

            //Ensure each unit has a height navigator
            if (nscAdded && nsc.heightSampling != HeightSamplingMode.NoHeightSampling)
            {
                var suc = GetAllNonPrefabInstances <SteerableUnitComponent>();
                foreach (var c in suc)
                {
                    if (c.As <IHeightNavigator>() == null)
                    {
                        var dhn = c.gameObject.AddComponent <DefaultHeightNavigator>();

                        dhn.gravity = c.gravity;
                        dhn.groundStickynessFactor = c.groundStickynessFactor;
                        dhn.terminalVelocity       = c.terminalVelocity;

                        DefaultHeightNavigatorEditor.EnsureValidProvider(dhn, nsc.heightSampling);

                        //Set the default constraints of the rigidbody, we no longer want to force this on awake
                        var rb = c.GetComponent <Rigidbody>();
                        if (rb != null)
                        {
                            rb.constraints |= RigidbodyConstraints.FreezeRotation;
                        }
                    }
                }
            }

            //Get path finder options from steer for path
            var sfp = GetAllNonPrefabInstances <SteerForPathComponent>();

            changed |= FixPathOptions(sfp);

            //Get selection visual from selectable unit if present
            var selectables = GetAllNonPrefabInstances <SelectableUnitComponent>();

            changed |= FixSelectables(selectables);

            //Set any basic avoidance to the same prio as steer for path
            var sfba = GetAllNonPrefabInstances <SteerForBasicAvoidanceComponent>();

            foreach (var a in sfba)
            {
                if (a.priority == 0)
                {
                    a.priority = 5;
                    changed    = true;
                }
            }

            var units = GetAllNonPrefabInstances <UnitComponent>();
            ApexComponentMaster m;

            foreach (var u in units)
            {
                if (u.gameObject.AddIfMissing <ApexComponentMaster>(false, out m))
                {
                    changed = true;
                    while (UnityEditorInternal.ComponentUtility.MoveComponentUp(m))
                    {
                        /* NOOP */
                    }
                }
            }

            AddGameWorldItem <ApexComponentMaster>((gw, acm, added) => changed |= added);

            return(changed);
        }