поигрался с корутинами

This commit is contained in:
vladislove 2026-09-22 14:21:35 +03:00
parent 02a1d74b2d
commit 2746850727
6 changed files with 165 additions and 21 deletions

View File

@ -1,8 +1,6 @@
# Default ignored files # Default ignored files
/shelf/ /shelf/
/workspace.xml /workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Rider ignored files # Rider ignored files
/modules.xml /modules.xml
/contentModel.xml /contentModel.xml
@ -13,3 +11,5 @@
# Datasource local storage ignored files # Datasource local storage ignored files
/dataSources/ /dataSources/
/dataSources.local.xml /dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
</component> </component>
</project> </project>

View File

@ -1734,6 +1734,7 @@ RectTransform:
m_Children: m_Children:
- {fileID: 1230166625} - {fileID: 1230166625}
- {fileID: 474561345} - {fileID: 474561345}
- {fileID: 642913449}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
@ -11747,6 +11748,97 @@ PrefabInstance:
m_AddedGameObjects: [] m_AddedGameObjects: []
m_AddedComponents: [] m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 51510de34f82041149d25090ec962e10, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 51510de34f82041149d25090ec962e10, type: 3}
--- !u!1 &642913448
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 642913449}
- component: {fileID: 642913452}
- component: {fileID: 642913451}
- component: {fileID: 642913450}
m_Layer: 5
m_Name: Image
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &642913449
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 642913448}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 101073168}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 384, y: 214}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &642913450
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 642913448}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8cf1795fc21943f48878d4a8f1b0a792, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::_Project.Scripts.ColorChanger
target: {fileID: 642913448}
TimeForChange: 100
isStarted: 0
--- !u!114 &642913451
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 642913448}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier: UnityEngine.UI::UnityEngine.UI.Image
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 0}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &642913452
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 642913448}
m_CullTransparentMesh: 1
--- !u!1001 &648963308 --- !u!1001 &648963308
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -1,21 +1,5 @@
%YAML 1.1 %YAML 1.1
%TAG !u! tag:unity3d.com,2011: %TAG !u! tag:unity3d.com,2011:
--- !u!114 &-3822165081800644479
MonoBehaviour:
m_ObjectHideFlags: 3
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 81180773991d8724ab7f2d216912b564, type: 3}
m_Name: ChromaticAberration
m_EditorClassIdentifier: Unity.RenderPipelines.Universal.Runtime::UnityEngine.Rendering.Universal.ChromaticAberration
active: 1
intensity:
m_OverrideState: 1
m_Value: 0.505
--- !u!114 &-2000355431073123474 --- !u!114 &-2000355431073123474
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 3 m_ObjectHideFlags: 3
@ -84,7 +68,6 @@ MonoBehaviour:
- {fileID: 1341611271618981203} - {fileID: 1341611271618981203}
- {fileID: 7813832346886808349} - {fileID: 7813832346886808349}
- {fileID: 331411648365755657} - {fileID: 331411648365755657}
- {fileID: -3822165081800644479}
--- !u!114 &331411648365755657 --- !u!114 &331411648365755657
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 3 m_ObjectHideFlags: 3
@ -100,7 +83,7 @@ MonoBehaviour:
active: 1 active: 1
mode: mode:
m_OverrideState: 1 m_OverrideState: 1
m_Value: 0 m_Value: 1
quality: quality:
m_OverrideState: 1 m_OverrideState: 1
m_Value: 0 m_Value: 0

View File

@ -0,0 +1,66 @@
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
namespace _Project.Scripts
{//Only for learning ideas
public class ColorChanger : MonoBehaviour
{
Coroutine coroutine;
Image image;
[SerializeField] GameObject target;
private Color prevColor;
[SerializeField] private float TimeForChange;
[SerializeField] private bool isStarted = false;
private bool isWorking = false;
[SerializeField]private bool isLooped = false;
void Start()
{
image = target.GetComponent<Image>();
prevColor = image.color;
}
void Update()
{
if (isStarted && !isWorking && isLooped)
{
while (isLooped)
{
isStarted = false;
isWorking = true;
coroutine = StartCoroutine(ColorCoroutine());
}
}
if (isStarted && !isWorking)
{
isStarted = false;
isWorking = true;
coroutine = StartCoroutine(ColorCoroutine());
}
}
IEnumerator ColorCoroutine()
{
float elapsedTime = 0f;
while (elapsedTime < TimeForChange)
{
image.color = Color.Lerp(prevColor, Color.clear, elapsedTime / TimeForChange);
elapsedTime += Time.deltaTime;
yield return null;
}
elapsedTime = 0f;
while (elapsedTime < TimeForChange)
{
elapsedTime += Time.deltaTime;
image.color = Color.Lerp( Color.clear,prevColor, elapsedTime / TimeForChange);
yield return null;
}
coroutine = null;
isWorking = false;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8cf1795fc21943f48878d4a8f1b0a792
timeCreated: 1790073521