Пример #1
0
        public static IEnumerable <Block> GetAllBlocks(AllConstruct c)
        {
            var iBlocks = c.AllBasics;

            return(iBlocks.AliveAndDead.Blocks
                   .Concat(iBlocks.SubConstructList.SelectMany(x => GetAllBlocks(x))));
        }
Пример #2
0
        private void Awake()
        {
            ProfileManager.Instance.SaveAll();

            transform.parent = null;

            if (cBuild.GetSingleton().buildMode != enumBuildMode.inactive)
            {
                c = cBuild.GetSingleton().GetC();
            }
            else
            {
                c = ClientInterface.GetInterface().Get_I_All_ConstructableSelector().Get_LookSC_LookC_CloseCRay_CloseC();
            }

            visualizer = BuildingToolsPlugin.bundle.LoadAllAssets <ComputeShader>()[0];

            camera             = gameObject.AddComponent <Camera>();
            camera.tag         = "MainCamera";
            camera.cullingMask = 0;
            camera.clearFlags  = CameraClearFlags.Nothing;

            QualitySettings.vSyncCount  = 1;
            Application.targetFrameRate = -1;

            InitializeShaderParameters();

            //DisableAllScripts();
            gameObject.AddComponent <FlyCamera>();
            //transform.position = new Vector3(0, -50, 0);

            foreach (var i in SceneManager.GetActiveScene().GetRootGameObjects())
            {
                if (i != gameObject)
                {
                    Destroy(i);
                }
            }

            Cursor.visible   = false;
            Cursor.lockState = CursorLockMode.Locked;
        }
Пример #3
0
        public Vector3i SetBlockDataFromConstruct(AllConstruct construct)
        {
            var min = construct.AllBasics.GetMin();
            var max = construct.AllBasics.GetMax();

            print(min);
            print(max);

            var size = max - min + 1;

            print(size);

            int[,,] idData       = new int[size.x, size.y, size.z];
            float[,,] armorData  = new float[size.x, size.y, size.z];
            float[,,] healthData = new float[size.x, size.y, size.z];

            int x1 = size.x;
            int y1 = size.y;
            int z1 = size.z;

            int x2 = 0;
            int y2 = 0;
            int z2 = 0;

            for (int x = 0; x < size.x; x++)
            {
                for (int y = 0; y < size.y; y++)
                {
                    for (int z = 0; z < size.z; z++)
                    {
                        var block = construct.AllBasics[x + min.x, y + min.y, z + min.z];
                        idData[x, y, z] = block?.GetHashCode() ?? -1;
                        if (block != null)
                        {
                            armorData[x, y, z] = block.item.ExtraSettings.StructuralComponent
                                ? block.item.ArmourClass
                                : -block.item.ArmourClass;
                            healthData[x, y, z] = block.item.Health;

                            if (x < x1)
                            {
                                x1 = x;
                            }
                            if (y < y1)
                            {
                                y1 = y;
                            }
                            if (z < z1)
                            {
                                z1 = z;
                            }

                            if (x > x2)
                            {
                                x2 = x;
                            }
                            if (y > y2)
                            {
                                y2 = y;
                            }
                            if (z > z2)
                            {
                                z2 = z;
                            }
                        }
                    }
                }
            }
            ;

            var shape = new Vector3i(x2 - x1, y2 - y1, z2 - z1);

            print(shape);

            int[]   idFlattened     = new int[shape.x * shape.y * shape.z];
            float[] armorFlattened  = new float[shape.x * shape.y * shape.z];
            float[] healthFlattened = new float[shape.x * shape.y * shape.z];

            for (int x = x1; x < x2; x++)
            {
                for (int y = y1; y < y2; y++)
                {
                    for (int z = z1; z < z2; z++)
                    {
                        idFlattened[x - x1 + shape.x * (y - y1 + shape.y * (z - z1))]     = idData[x, y, z];
                        armorFlattened[x - x1 + shape.x * (y - y1 + shape.y * (z - z1))]  = armorData[x, y, z];
                        healthFlattened[x - x1 + shape.x * (y - y1 + shape.y * (z - z1))] = healthData[x, y, z];
                    }
                }
            }

            id = new ComputeBuffer(idFlattened.Length, 4);
            id.SetData(idFlattened);

            armor = new ComputeBuffer(armorFlattened.Length, 4);
            armor.SetData(armorFlattened);

            health = new ComputeBuffer(healthFlattened.Length, 4);
            health.SetData(healthFlattened);

            return(shape);
        }
Пример #4
0
        static void Postfix(cCameraControl __instance, FocusCameraSettings settings)
        {
            cCameraControl_IEFocusExternalCameraOnThis_Patch.xRotVel = 0f;
            cCameraControl_IEFocusExternalCameraOnThis_Patch.yRotVel = 0f;
            Main.subject  = null;
            Main.rotation = null;
            IPositionReturn pof = settings.PositionOfFocus;

            switch (pof)
            {
            case PositionAndRotationReturnConstruct parrc:     // I can't find where this is created...
                FieldInfo    fic = typeof(PositionAndRotationReturnConstruct).GetField("_c", BindingFlags.NonPublic | BindingFlags.Instance);
                AllConstruct c   = (AllConstruct)fic.GetValue(parrc);
                Main.rotation     = parrc;
                Main.lastRotation = parrc.Rotation;
                if (c is MainConstruct mc)
                {
                    Main.subject = mc;
                }
                break;

            case PositionReturnBlock prb:     // FocusCameraSettings were directed to some construct's block.
                FieldInfo        fib = typeof(PositionReturnBlock).GetField("_b", BindingFlags.NonPublic | BindingFlags.Instance);
                IBlockForReturns b   = (IBlockForReturns)fib.GetValue(prb);
                if (b is Block block)
                {
                    IAllConstructBlock acb = block.GetConstructableOrSubConstructable();
                    if (acb is AllConstruct ac)
                    {
                        Main.rotation = new RotationReturnConstruct(ac);
                    }
                    else     // Should not be the case.
                    {
                        Main.rotation = new RotationReturnBlock(b);
                    }
                    Main.lastRotation = Main.rotation.Rotation;
                    Main.subject      = block.GetConstructable() as MainConstruct;
                }
                break;

            case PositionReturnForce prf:     // FocusCameraSettings were created from the strategic view.
                FieldInfo fif = typeof(PositionReturnForce).GetField("_f", BindingFlags.NonPublic | BindingFlags.Instance);
                Force     f   = (Force)fif.GetValue(prf);
                if (f.C != null)
                {
                    // Center camera on CoM if coming from strategic map.
                    PositionAndRotationReturnConstruct yeah = new PositionAndRotationReturnConstruct(f.C, PositionReturnConstructReferenceSelection.CenterOfMass);
                    settings.PositionOfFocus = yeah;
                    Main.rotation            = yeah;
                    Main.lastRotation        = yeah.Rotation;
                    Main.subject             = f.C;
                }
                else
                {
                    // This produces results hysterically bad for filming.
                    // This only should happen if the camera focuses on an out-of-play force.
                    Main.rotation     = new RotationReturnForce(f);
                    Main.lastRotation = Main.rotation.Rotation;
                    if (f.IsInPlay)
                    {
                        AdvLogger.LogInfo("PositionOfFocus set to a PositionReturnForce in play, but there is no construct object!");
                    }
                }
                break;

            case PositionReturnTransform prt:     // FocusCameraSettings were directed to a projectile.
                FieldInfo fit = typeof(PositionReturnTransform).GetField("_t", BindingFlags.NonPublic | BindingFlags.Instance);
                Transform t   = (Transform)fit.GetValue(prt);
                Main.rotation     = new RotationReturnTransform(t);
                Main.lastRotation = Main.rotation.Rotation;
                break;

            default:     // Other focus subjects won't be tracked rotation-wise. (Don't think there are any others.)
                AdvLogger.LogInfo(string.Format("Received a unknown IPositionReturn: {0}", pof.GetType().FullName));
                break;
            }
        }