示例#1
0
    public static void DoApply()
    {
        Transform[] transforms    = FindObjectsOfType(typeof(Transform)) as Transform[];
        int         numberApplied = 0;

        foreach (Transform transform in transforms)
        {
            TransformSave found = null;

            for (int i = 0; i < transformSaves.Count; i++)
            {
                if (((TransformSave)transformSaves[i]).instanceID == transform.GetInstanceID())
                {
                    found = (TransformSave)transformSaves[i];
                    break;
                }
            }

            if (found != null)
            {
                transform.position   = found.position;
                transform.rotation   = found.rotation;
                transform.localScale = found.localScale;
                numberApplied++;
            }
        }

        //EditorUtility.DisplayDialog("Transform Saver Apply", "Applied " + numberApplied + " Transforms successfully out of " + transformSaves.Count + " possible.", "OK", "");
    }
示例#2
0
    protected override void PlaceGhostInterpolate(MotionBlurGhost rGhost, TransformSave rTransformSaveBegin, TransformSave rTransformSaveEnd, float fCurrentGhostCurrentTimeRangePositionInPercent)
    {
        base.PlaceGhostInterpolate(rGhost, rTransformSaveBegin, rTransformSaveEnd, fCurrentGhostCurrentTimeRangePositionInPercent);

        // Make sure is visible
        rGhost.Show();
    }
示例#3
0
    public static Transform ReturnTransform(TransformSave save)
    {
        GameObject go = new GameObject();

        go.transform.position = new Vector3(save.x, save.y, save.z);
        return(go.transform);
    }
    /// \brief Place Ghost
    protected virtual float PlaceGhost(TransformSave rTransformSaveBegin, TransformSave rTransformSaveEnd, ref int a_iCurrentGhostIndex)
    {
        // Compute the time between two ghost
        float fTimeBetweenTwoGhosts = m_rMotionBlur.persistenceDuration / m_rMotionBlur.quality;

        // Get the range time extremity
        float fCurrentRangeTimeBegin = rTransformSaveBegin.saveTime;
        float fCurrentRangeTimeEnd   = rTransformSaveEnd.saveTime;

        // Compute the current time range duration
        float fCurrentTimeRangeDuration = fCurrentRangeTimeBegin - fCurrentRangeTimeEnd;

        // Compute the current ghost backward time
        float fCurrentGhostBackwardTime = (a_iCurrentGhostIndex) * fTimeBetweenTwoGhosts;

        // Compute the current Ghost time
        float fCurrentTime      = Time.time;
        float fCurrentGhostTime = fCurrentTime - fCurrentGhostBackwardTime;

        // Compute the remaining time since first ghost before the current time range end
        float fRemainingTimeSinceFirstGhostBeforeEndOfCurrentTimeRange = fCurrentGhostTime - fCurrentRangeTimeEnd;

        // Compute the number of ghost to place
        int iNumberOfGhostToPlaceInTheCurrentTimeRange = 1 + Mathf.FloorToInt(fRemainingTimeSinceFirstGhostBeforeEndOfCurrentTimeRange / fTimeBetweenTwoGhosts);

        iNumberOfGhostToPlaceInTheCurrentTimeRange = Mathf.Clamp(iNumberOfGhostToPlaceInTheCurrentTimeRange, 0, m_oGhosts.Count - a_iCurrentGhostIndex);

        // Place the number of ghost needed
        for (int k = 0; k < iNumberOfGhostToPlaceInTheCurrentTimeRange; k++)
        {
            // Update the current ghost backward time
            fCurrentGhostBackwardTime = (a_iCurrentGhostIndex) * fTimeBetweenTwoGhosts;

            // Update the current Ghost time
            fCurrentGhostTime = fCurrentTime - fCurrentGhostBackwardTime;

            // Compute at which percent of the current time range is placed the current ghost
            float fCurrentGhostCurrentTimeRangePositionInPercent = (fCurrentRangeTimeBegin - fCurrentGhostTime) / fCurrentTimeRangeDuration;

            // Grab the current ghost
            MotionBlurGhost rGhost = m_oGhosts[a_iCurrentGhostIndex];

            // Place the ghost
            fCurrentGhostCurrentTimeRangePositionInPercent = Mathf.Max(fCurrentGhostCurrentTimeRangePositionInPercent, 0.0f);
            PlaceGhostInterpolate(rGhost, rTransformSaveBegin, rTransformSaveEnd, fCurrentGhostCurrentTimeRangePositionInPercent);

            // Offset the ghost
            rGhost.transform.position += m_rMotionBlur.offset;

            // Fade out the ghost => the older it is the more transparent
            ApplyGhostFade(rGhost, fCurrentGhostBackwardTime / m_rMotionBlur.persistenceDuration);

            // Pass to the next ghost
            a_iCurrentGhostIndex++;
        }

        // Increment elapsed time since last ghost
        return(fCurrentGhostTime - fCurrentRangeTimeEnd);
    }
    protected virtual void PlaceGhostInterpolate(MotionBlurGhost rGhost, TransformSave rTransformSaveBegin, TransformSave rTransformSaveEnd, float fCurrentGhostCurrentTimeRangePositionInPercent)
    {
        TransformSave.LoadInterpolatedTransform(rGhost.transform, rTransformSaveBegin, rTransformSaveEnd, fCurrentGhostCurrentTimeRangePositionInPercent);

        if (!m_rMotionBlur.progressiveScale)
        {
            rGhost.SetTransformToGhost(m_rMotionBlur.transform);
        }
    }
示例#6
0
    public static TransformSave StoreTransform(GameObject go)
    {
        TransformSave t = new TransformSave();

        t.x = go.transform.position.x;
        t.y = go.transform.position.y;
        t.z = go.transform.position.z;
        return(t);
    }
示例#7
0
    public static void CreateCompanyInfo(Encounter encounter = null, GameObject origin = null, GameObject destination = null)
    {
        CompanyInfo companyInfo = new CompanyInfo();

        companyInfo.targetEncounter = encounter;
        companyInfo.originSave      = TransformSave.StoreTransform(origin);
        companyInfo.destinationSave = TransformSave.StoreTransform(destination);
        encounter.selectedCompany   = companyInfo;
        companies.Add(companyInfo);
    }
    /// \brief  Update world motion blur
    private void UpdateGhostLocalMode(ref int a_iCurrentGhostIndex)
    {
        // Simulate the transform history accordingly to the local velocity
        TransformSave rTransformSaveBegin = new TransformSave(m_rMotionBlur.transform);
        TransformSave rTransformSaveEnd   = new TransformSave(m_rMotionBlur.transform);

        rTransformSaveEnd.position += m_rMotionBlur.persistenceDuration * m_rMotionBlur.localVelocity;
        rTransformSaveEnd.saveTime -= m_rMotionBlur.persistenceDuration;

        PlaceGhost(rTransformSaveBegin, rTransformSaveEnd, ref a_iCurrentGhostIndex);
    }
示例#9
0
    static void DoRecord()
    {
        Transform[] selection = Selection.GetTransforms(SelectionMode.Editable | SelectionMode.ExcludePrefab);
        transformSaves = new ArrayList(selection.Length);

        foreach (Transform selected in selection)
        {
            TransformSave transformSave = new TransformSave(selected.GetInstanceID(), selected.position, selected.rotation, selected.localScale);
            transformSaves.Add(transformSave);
        }

        EditorUtility.DisplayDialog("Transform Saver Record", "Recorded " + transformSaves.Count + " Transforms.", "OK", "");
    }
示例#10
0
    static void DoRecord()
    {
        Transform[] selection = Selection.GetTransforms(SelectionMode.Editable | SelectionMode.ExcludePrefab);
        transformSaves = new ArrayList(selection.Length);

        foreach (Transform selected in selection)
        {
            TransformSave transformSave = new TransformSave(selected.GetInstanceID(), selected.localPosition, selected.localRotation, selected.localScale);
            transformSaves.Add(transformSave);
        }

        EditorUtility.DisplayDialog("Transform Saver Record", "Recorded " + transformSaves.Count + " Transforms.", "OK", "");
    }
示例#11
0
        /// \brief  Load an interpolated transform 
        static public void LoadInterpolatedTransform(Transform a_rTransform, TransformSave a_rTransformBegin, TransformSave a_rTransformEnd, float a_fInterpolationPercent)
        {
            // Linear interpolation the position between begin and end
            a_rTransform.position = a_rTransformBegin.position + (a_rTransformEnd.position - a_rTransformBegin.position) * a_fInterpolationPercent;

            // Rotation
            a_rTransform.rotation = a_rTransformBegin.rotation;

            // Scale
            Transform rParentTransformSave = a_rTransform.parent;
            a_rTransform.parent = null;
            a_rTransform.localScale = a_rTransformBegin.lossyScale;
            a_rTransform.parent = rParentTransformSave;
        }
    protected override void PlaceGhostInterpolate(MotionBlurGhost rGhost, TransformSave rTransformSaveBegin, TransformSave rTransformSaveEnd, float fCurrentGhostCurrentTimeRangePositionInPercent)
    {
        base.PlaceGhostInterpolate(rGhost, rTransformSaveBegin, rTransformSaveEnd, fCurrentGhostCurrentTimeRangePositionInPercent);

        // Render and transform smooth update or not
        if (m_rMotionBlur.progressiveSpriteColor)
        {
            TransformSave2D.LoadInterpolatedTransform(((MotionBlurGhost2D)rGhost).m_rSpriteRendererFilter, (TransformSave2D)rTransformSaveBegin, (TransformSave2D)rTransformSaveEnd, fCurrentGhostCurrentTimeRangePositionInPercent);
        }
        else
        {
            ((MotionBlurGhost2D)rGhost).SetSpriteRendererToGhost(m_rSpriteRenderer);
        }
    }
        /// \brief  Load an interpolated transform
        static public void LoadInterpolatedTransform(Transform a_rTransform, TransformSave a_rTransformBegin, TransformSave a_rTransformEnd, float a_fInterpolationPercent)
        {
            // Linear interpolation the position between begin and end
            a_rTransform.position = a_rTransformBegin.position + (a_rTransformEnd.position - a_rTransformBegin.position) * a_fInterpolationPercent;

            // Rotation
            a_rTransform.rotation = a_rTransformBegin.rotation;

            // Scale
            Transform rParentTransformSave = a_rTransform.parent;

            a_rTransform.parent     = null;
            a_rTransform.localScale = a_rTransformBegin.lossyScale;
            a_rTransform.parent     = rParentTransformSave;
        }
示例#14
0
    private void Update()
    {
        if (!moving)
        {
            return;
        }
        else
        {
            bool endMove = false;
            MapUIManager.uiState = MapUIManager.UIState.noInput;

            if (companyInfo.targetEncounter == null)
            {
                Debug.LogWarning("No encounter to travel to, heading back");
                companyInfo.destination = MapManager.theCastle.transform;
            }

            transform.position = Vector3.MoveTowards(transform.position, companyInfo.destination.position, companyInfo.travelSpeed);

            //check to see if it has reached its destination.
            if (Vector3.Distance(transform.position, companyInfo.destination.transform.position) <= 0.01f)
            {
                companyInfo.currentLocationSave = TransformSave.StoreTransform(companyInfo.destination.gameObject);
            }

            timer += Time.deltaTime;
            if (timer > 1)
            {
                endMove = true;
            }

            if (endMove)
            {
                companyInfo.currentLocationSave = TransformSave.StoreTransform(gameObject);
                MapUIManager.uiState            = MapUIManager.UIState.standard;
                mapManager.CheckForAvailableEncounters();
                mapManager.ReturnCompanysToCastle();
                moving = false;
                timer  = 0;
                return;
            }
        }
    }
示例#15
0
    public void CreateCompany()
    {
        GameObject go         = GameObject.Instantiate(GameAssets.i.company);
        Company    newCompany = go.GetComponent <Company>();

        newCompany.companyInfo = this;
        company     = newCompany;
        origin      = TransformSave.ReturnTransform(originSave);
        destination = TransformSave.ReturnTransform(destinationSave);
        if (currentLocationSave != null)
        {
            newCompany.transform.position = TransformSave.ReturnTransform(currentLocationSave).position;
        }
        else
        {
            newCompany.transform.position = origin.position;
        }
        company.mapManager = GameObject.Find("MapManager").GetComponent <MapManager>();
        company.mapManager.companies.Add(company);
    }
示例#16
0
    void OnApplicationQuit()
    {
        GameObject[] objects   = GameObject.FindGameObjectsWithTag("saveable");
        Transform[]  selection = new Transform[objects.Length];

        for (int i = 0; i < objects.Length; ++i)
        {
            selection[i] = objects[i].transform;
        }

        transformSaves = new ArrayList(selection.Length);

        foreach (Transform selected in selection)
        {
            TransformSave transformSave = new TransformSave(selected.GetInstanceID(), selected.position, selected.rotation, selected.localScale);
            transformSaves.Add(transformSave);
        }

        if (showRecordWindow)
        {
            EditorUtility.DisplayDialog("Transform Saver Record", "Recorded " + transformSaves.Count + " Transforms.", "OK", "");
        }
    }
示例#17
0
    protected override void PlaceGhostInterpolate(MotionBlurGhost rGhost, TransformSave rTransformSaveBegin, TransformSave rTransformSaveEnd, float fCurrentGhostCurrentTimeRangePositionInPercent)
    {
        base.PlaceGhostInterpolate( rGhost, rTransformSaveBegin,  rTransformSaveEnd,  fCurrentGhostCurrentTimeRangePositionInPercent);

        // Render and transform smooth update or not
        if (m_rMotionBlur.progressiveSpriteColor)
        {
            TransformSave2D.LoadInterpolatedTransform( ((MotionBlurGhost2D)rGhost).m_rSpriteRendererFilter, (TransformSave2D)rTransformSaveBegin, (TransformSave2D)rTransformSaveEnd, fCurrentGhostCurrentTimeRangePositionInPercent);
        }
        else
        {
            ((MotionBlurGhost2D)rGhost).SetSpriteRendererToGhost(m_rSpriteRenderer);
        }
    }
示例#18
0
    protected override void PlaceGhostInterpolate(MotionBlurGhost rGhost, TransformSave rTransformSaveBegin, TransformSave rTransformSaveEnd, float fCurrentGhostCurrentTimeRangePositionInPercent)
    {
        base.PlaceGhostInterpolate(rGhost, rTransformSaveBegin, rTransformSaveEnd, fCurrentGhostCurrentTimeRangePositionInPercent);

        // Make sure is visible
        rGhost.Show();
    }
示例#19
0
    protected virtual void PlaceGhostInterpolate(MotionBlurGhost rGhost, TransformSave rTransformSaveBegin, TransformSave rTransformSaveEnd, float fCurrentGhostCurrentTimeRangePositionInPercent)
    {
        TransformSave.LoadInterpolatedTransform(rGhost.transform, rTransformSaveBegin, rTransformSaveEnd, fCurrentGhostCurrentTimeRangePositionInPercent);

        if (!m_rMotionBlur.progressiveScale)
        {
            rGhost.SetTransformToGhost(m_rMotionBlur.transform);
        }

    }
示例#20
0
    /// \brief Place Ghost
    protected virtual float PlaceGhost(TransformSave rTransformSaveBegin, TransformSave rTransformSaveEnd, ref int a_iCurrentGhostIndex)
    {
        // Compute the time between two ghost
        float fTimeBetweenTwoGhosts = m_rMotionBlur.persistenceDuration / m_rMotionBlur.quality;

        // Get the range time extremity
        float fCurrentRangeTimeBegin = rTransformSaveBegin.saveTime;
        float fCurrentRangeTimeEnd = rTransformSaveEnd.saveTime;

        // Compute the current time range duration 
        float fCurrentTimeRangeDuration = fCurrentRangeTimeBegin - fCurrentRangeTimeEnd;

        // Compute the current ghost backward time
        float fCurrentGhostBackwardTime = (a_iCurrentGhostIndex) * fTimeBetweenTwoGhosts;

        // Compute the current Ghost time
        float fCurrentTime = Time.time;
        float fCurrentGhostTime = fCurrentTime - fCurrentGhostBackwardTime;

        // Compute the remaining time since first ghost before the current time range end
        float fRemainingTimeSinceFirstGhostBeforeEndOfCurrentTimeRange = fCurrentGhostTime - fCurrentRangeTimeEnd;

        // Compute the number of ghost to place
        int iNumberOfGhostToPlaceInTheCurrentTimeRange = 1 + Mathf.FloorToInt(fRemainingTimeSinceFirstGhostBeforeEndOfCurrentTimeRange / fTimeBetweenTwoGhosts);
        iNumberOfGhostToPlaceInTheCurrentTimeRange = Mathf.Clamp(iNumberOfGhostToPlaceInTheCurrentTimeRange, 0, m_oGhosts.Count - a_iCurrentGhostIndex);

        // Place the number of ghost needed
        for (int k = 0; k < iNumberOfGhostToPlaceInTheCurrentTimeRange; k++)
        {
            // Update the current ghost backward time
            fCurrentGhostBackwardTime = (a_iCurrentGhostIndex) * fTimeBetweenTwoGhosts;

            // Update the current Ghost time
            fCurrentGhostTime = fCurrentTime - fCurrentGhostBackwardTime;

            // Compute at which percent of the current time range is placed the current ghost
            float fCurrentGhostCurrentTimeRangePositionInPercent = (fCurrentRangeTimeBegin - fCurrentGhostTime) / fCurrentTimeRangeDuration;

            // Grab the current ghost
            MotionBlurGhost rGhost = m_oGhosts[a_iCurrentGhostIndex];

            // Place the ghost
            fCurrentGhostCurrentTimeRangePositionInPercent = Mathf.Max(fCurrentGhostCurrentTimeRangePositionInPercent, 0.0f);
            PlaceGhostInterpolate(rGhost, rTransformSaveBegin, rTransformSaveEnd, fCurrentGhostCurrentTimeRangePositionInPercent);

            // Offset the ghost
            rGhost.transform.position += m_rMotionBlur.offset;

            // Fade out the ghost => the older it is the more transparent
            ApplyGhostFade(rGhost, fCurrentGhostBackwardTime / m_rMotionBlur.persistenceDuration);

            // Pass to the next ghost
            a_iCurrentGhostIndex++;
        }

        // Increment elapsed time since last ghost
        return fCurrentGhostTime - fCurrentRangeTimeEnd;
    }
示例#21
0
    /// \brief  Update world motion blur
    private void UpdateGhostLocalMode(ref int a_iCurrentGhostIndex)
    {
        // Simulate the transform history accordingly to the local velocity
        TransformSave rTransformSaveBegin = new TransformSave(m_rMotionBlur.transform);
        TransformSave rTransformSaveEnd = new TransformSave(m_rMotionBlur.transform);

        rTransformSaveEnd.position += m_rMotionBlur.persistenceDuration * m_rMotionBlur.localVelocity;
        rTransformSaveEnd.saveTime -= m_rMotionBlur.persistenceDuration;

        PlaceGhost(rTransformSaveBegin, rTransformSaveEnd, ref a_iCurrentGhostIndex);
    }