protected override void OnActivateTool()
    {
        base.OnActivateTool();
        Vector3    cursorPos       = PlayerController.GetCursorPos(KInputManager.GetMousePos());
        GameObject buildingPreview = def.BuildingPreview;
        Vector3    position        = cursorPos;

        Grid.SceneLayer sceneLayer = Grid.SceneLayer.Ore;
        int             gameLayer  = LayerMask.NameToLayer("Place");

        visualizer = GameUtil.KInstantiate(buildingPreview, position, sceneLayer, null, gameLayer);
        KBatchedAnimController component = visualizer.GetComponent <KBatchedAnimController>();

        if ((Object)component != (Object)null)
        {
            component.visibilityType = KAnimControllerBase.VisibilityType.Always;
            component.isMovable      = true;
            component.SetDirty();
        }
        visualizer.SetActive(true);
        Play(visualizer, "None_Place");
        BuildToolHoverTextCard component2 = GetComponent <BuildToolHoverTextCard>();

        component2.currentDef = def;
        ResourceRemainingDisplayScreen.instance.ActivateDisplay(visualizer);
        IHaveUtilityNetworkMgr component3 = def.BuildingComplete.GetComponent <IHaveUtilityNetworkMgr>();

        conduitMgr = component3.GetNetworkManager();
    }
Example #2
0
    private void UpdateFrame()
    {
        forceUpdate = false;
        bool symbolVisible = false;

        KAnim.Anim currentAnim = controller.CurrentAnim;
        if (currentAnim != null)
        {
            Matrix2x3 symbolLocalTransform = controller.GetSymbolLocalTransform(symbol, out symbolVisible);
            Vector3   position             = controller.transform.GetPosition();
            if (symbolVisible && (previousMatrix != symbolLocalTransform || position != previousPosition || useTargetPoint))
            {
                previousMatrix   = symbolLocalTransform;
                previousPosition = position;
                Matrix2x3 overrideTransformMatrix = controller.GetTransformMatrix() * symbolLocalTransform;
                Vector3   position2 = base.transform.GetPosition();
                float     z         = position2.z;
                base.transform.SetPosition(overrideTransformMatrix.MultiplyPoint(offset));
                if (useTargetPoint)
                {
                    Vector3 position3 = base.transform.GetPosition();
                    position3.z = 0f;
                    Vector3 from = targetPoint - position3;
                    float   num  = Vector3.Angle(from, Vector3.right);
                    if (from.y < 0f)
                    {
                        num = 360f - num;
                    }
                    base.transform.localRotation = Quaternion.identity;
                    base.transform.RotateAround(position3, new Vector3(0f, 0f, 1f), num);
                    float sqrMagnitude = from.sqrMagnitude;
                    KBatchedAnimInstanceData batchInstanceData = myAnim.GetBatchInstanceData();
                    Vector3 position4 = base.transform.GetPosition();
                    float   x         = position4.x;
                    Vector3 position5 = base.transform.GetPosition();
                    batchInstanceData.SetClipRadius(x, position5.y, sqrMagnitude, true);
                }
                else
                {
                    Vector3 v  = (!controller.FlipX) ? Vector3.right : Vector3.left;
                    Vector3 v2 = (!controller.FlipY) ? Vector3.up : Vector3.down;
                    base.transform.up    = overrideTransformMatrix.MultiplyVector(v2);
                    base.transform.right = overrideTransformMatrix.MultiplyVector(v);
                    if ((Object)myAnim != (Object)null)
                    {
                        myAnim.GetBatchInstanceData()?.SetOverrideTransformMatrix(overrideTransformMatrix);
                    }
                }
                Transform transform = base.transform;
                Vector3   position6 = base.transform.GetPosition();
                float     x2        = position6.x;
                Vector3   position7 = base.transform.GetPosition();
                transform.SetPosition(new Vector3(x2, position7.y, z));
                myAnim.SetDirty();
            }
        }
        if ((Object)myAnim != (Object)null && symbolVisible != myAnim.enabled)
        {
            myAnim.enabled = symbolVisible;
        }
    }
Example #3
0
        /// <summary>
        /// Updates an active batched anim controller.
        /// </summary>
        /// <param name="instance">The controller to update.</param>
        /// <param name="dt">The time since the last update.</param>
        private static void UpdateActive(KBatchedAnimController instance, float dt)
        {
            Transform transform;
            var       batch   = instance.batch;
            var       visType = instance.visibilityType;
            bool      visible = instance.IsVisible();

            // Check if moved, do this even if offscreen as it may move the anim on screen
            if (batch != null && (transform = instance.transform).hasChanged)
            {
                var      lastChunk = instance.lastChunkXY;
                Vector3  pos = transform.position, posWithOffset = pos + instance.Offset;
                float    z = pos.z;
                Vector2I cellXY;
                bool     always = visType == KAnimControllerBase.VisibilityType.Always;
                transform.hasChanged = false;
                // If this is the only anim in the batch, and the Z coordinate changed,
                // override the Z in the batch
                if (batch.group.maxGroupSize == 1 && instance.lastPos.z != z)
                {
                    batch.OverrideZ(z);
                }
                instance.lastPos = posWithOffset;
                // This is basically GetCellXY() with less accesses to __instance.transform
                if (Grid.CellSizeInMeters == 0.0f)
                {
                    // Handle out-of-game
                    cellXY = new Vector2I((int)posWithOffset.x, (int)posWithOffset.y);
                }
                else
                {
                    cellXY = Grid.PosToXY(posWithOffset);
                }
                if (!always && lastChunk != KBatchedAnimUpdater.INVALID_CHUNK_ID &&
                    KAnimBatchManager.CellXYToChunkXY(cellXY) != lastChunk)
                {
                    // Re-register in a different batch
                    instance.DeRegister();
                    instance.Register();
                }
                else if (visible || always)
                {
                    // Only set dirty if it is on-screen now - changing visible sets dirty
                    // If it moved into a different chunk, Register sets dirty
                    instance.SetDirty();
                }
            }
            // If it has a batch, and is active
            if (instance.batchGroupID != KAnimBatchManager.NO_BATCH)
            {
                var   anim = instance.curAnim;
                var   mode = instance.mode;
                bool  force = instance.forceRebuild, stopped = instance.stopped;
                float t = instance.elapsedTime, increment = dt * instance.playSpeed;
                // Suspend updates if: not currently suspended, not force update, and one
                // of (paused, stopped, no anim, one time and finished with no more to play)
                if (!instance.suspendUpdates && !force && (mode == KAnim.PlayMode.Paused ||
                                                           stopped || anim == null || (mode == KAnim.PlayMode.Once && (t > anim.
                                                                                                                       totalTime || anim.totalTime <= 0f) && instance.animQueue.Count == 0)))
                {
                    instance.SuspendUpdates(true);
                }
                if (visible || force)
                {
                    var aem    = instance.aem;
                    var handle = instance.eventManagerHandle;
                    instance.curAnimFrameIdx = instance.GetFrameIdx(t, true);
                    // Trigger anim event manager if time advanced more than 0.01s
                    if (handle.IsValid() && aem != null)
                    {
                        float elapsedTime = aem.GetElapsedTime(handle);
                        if (Math.Abs(t - elapsedTime) > 0.01f)
                        {
                            aem.SetElapsedTime(handle, t);
                        }
                    }
                    instance.UpdateFrame(t);
                    // Time can be mutated by UpdateFrame
                    if (!stopped && mode != KAnim.PlayMode.Paused)
                    {
                        instance.SetElapsedTime(instance.elapsedTime + increment);
                    }
                    instance.forceRebuild = false;
                }
                else if (visType == KAnimControllerBase.VisibilityType.OffscreenUpdate &&
                         !stopped && mode != KAnim.PlayMode.Paused)
                {
                    // If invisible, only advance if offscreen update is enabled
                    instance.SetElapsedTime(t + increment);
                }
            }
        }
Example #4
0
        // This method syncs the object to the transform of the neck snap point in the dupe
        void LateUpdate()
        {
            bool symbolVisible = false;

            if (dupeAnim.CurrentAnim != null)
            {
                var batch = dupeAnim.GetBatch();
                var frame = batch.group.data.GetFrame(dupeAnim.GetCurrentFrameIndex());
                if (frame != KAnim.Anim.Frame.InvalidFrame)
                {
                    for (int i = 0; i < frame.numElements; i++)
                    {
                        int num = frame.firstElementIdx + i;
                        if (num < batch.group.data.frameElements.Count)
                        {
                            KAnim.Anim.FrameElement frameElement = batch.group.data.frameElements[num];
                            if (frameElement.symbol == symbol)
                            {
                                if (frameElement.frame == 0)
                                {
                                    if (facing <= 0)
                                    {
                                        myAnim.Play(front_anim);
                                        facing = 1;
                                    }
                                }
                                else
                                {
                                    if (facing >= 0)
                                    {
                                        myAnim.Play(back_anim);
                                        facing = -1;
                                    }
                                }
                            }
                        }
                    }
                }

                symbolVisible = dupeAnim.GetSymbolVisiblity(symbol);
                bool      unusedBool;
                Matrix2x3 symbolLocalTransform = dupeAnim.GetSymbolLocalTransform(symbol, out unusedBool);
                Vector3   position             = dupeAnim.transform.GetPosition();
                if (symbolVisible && (previousMatrix != symbolLocalTransform || position != previousPosition))
                {
                    previousMatrix   = symbolLocalTransform;
                    previousPosition = position;
                    Matrix2x3 overrideTransformMatrix = dupeAnim.GetTransformMatrix() * symbolLocalTransform;
                    float     z = base.transform.GetPosition().z;
                    base.transform.SetPosition(overrideTransformMatrix.MultiplyPoint(offset));

                    Vector3 v  = dupeAnim.FlipX ? Vector3.left : Vector3.right;
                    Vector3 v2 = dupeAnim.FlipY ? Vector3.down : Vector3.up;
                    base.transform.up    = overrideTransformMatrix.MultiplyVector(v2);
                    base.transform.right = overrideTransformMatrix.MultiplyVector(v);
                    if (myAnim != null)
                    {
                        myAnim.GetBatchInstanceData()?.SetOverrideTransformMatrix(overrideTransformMatrix);
                    }

                    base.transform.SetPosition(new Vector3(base.transform.GetPosition().x, base.transform.GetPosition().y, z));

                    myAnim.Offset = dupeAnim.Offset;
                    myAnim.SetDirty();
                }
            }
            if (myAnim != null && symbolVisible != myAnim.enabled)
            {
                myAnim.enabled = symbolVisible;
            }
        }