refactoring BallPool

master
chwan1 6 years ago
parent 6a363aeba2
commit 9603931761
  1. 40
      Unity-19050-05-BallPool/Assets/Frozen/Character.prefab
  2. 1217
      Unity-19050-05-BallPool/Assets/Frozen/Frozen.unity
  3. 90
      Unity-19050-05-BallPool/Assets/Frozen/Script/CharacterBehaviour.cs
  4. 44
      Unity-19050-05-BallPool/Assets/Frozen/Script/SceneController.cs
  5. 2
      Unity-19050-05-BallPool/Assets/Frozen/Script/SpaceMeshGenerator.cs
  6. 55
      Unity-19050-05-BallPool/Assets/Frozen/Script/TestTouch.cs
  7. 2
      Unity-19050-05-BallPool/Assets/Frozen/Script/TestTouch.cs.meta
  8. 10
      Unity-19050-05-BallPool/Assets/UnityUtilityNativePlugin.meta
  9. 10
      Unity-19050-05-BallPool/Assets/UnityUtilityNativePlugin/Plugins.meta
  10. BIN
      Unity-19050-05-BallPool/Assets/UnityUtilityNativePlugin/Plugins/UnityUtilityNativePlugin.dll
  11. 86
      Unity-19050-05-BallPool/Assets/UnityUtilityNativePlugin/Plugins/UnityUtilityNativePlugin.dll.meta
  12. 10
      Unity-19050-05-BallPool/Assets/UnityUtilityNativePlugin/Script.meta
  13. 80
      Unity-19050-05-BallPool/Assets/UnityUtilityNativePlugin/Script/DrawLine.cs
  14. 11
      Unity-19050-05-BallPool/Assets/UnityUtilityNativePlugin/Script/DrawLine.cs.meta
  15. 28
      Unity-19050-05-BallPool/Assets/UnityUtilityNativePlugin/Script/NativeBufferPool.cs
  16. 158
      Unity-19050-05-BallPool/Assets/UnityUtilityNativePlugin/Script/TextureScale.cs
  17. 11
      Unity-19050-05-BallPool/Assets/UnityUtilityNativePlugin/Script/TextureScale.cs.meta
  18. 117
      Unity-19050-05-BallPool/Assets/UnityUtilityNativePlugin/Script/UtilityNativePlugin.cs
  19. 11
      Unity-19050-05-BallPool/Assets/UnityUtilityNativePlugin/Script/UtilityNativePlugin.cs.meta
  20. 2
      Unity-19050-05-BallPool/Packages/com.ultracombos.chwan1

@ -57,7 +57,7 @@ MeshRenderer:
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 2969b78c14f1c6f4e941656f8f9cb902, type: 2}
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
@ -134,7 +134,7 @@ MeshRenderer:
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 1cdc8e8858ddf8a48ae2acc576bc1ead, type: 2}
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
@ -166,7 +166,7 @@ GameObject:
- component: {fileID: 54049355739133181}
- component: {fileID: 54049355739133177}
m_Layer: 8
m_Name: Anna_day
m_Name: Character
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@ -200,34 +200,22 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 12ea4d85cdda0aa4981a82e5e18fed52, type: 3}
m_Name:
m_EditorClassIdentifier:
appearSataes: 01000000
videoStopTime: 10
disappearTime: 1
area: 2
appearSataes:
List:
videoStopTime: 1.5
disappearTime: 5
area: 0
appearAreas:
specificPositions:
- {fileID: 54049355739133177}
specificPositions: []
roaming: 0
fakeButton: {fileID: 0}
isStandbyLoop: 0
standbyClip: {fileID: 11400000, guid: 6d7b66e288bf3924fbd7a716ae3ac255, type: 2}
triggerClips:
- {fileID: 11400000, guid: 2845fcd21d061464f8f97219a167ba7a, type: 2}
triggerFrame: 45
isStandbyLoop: 1
standbyClip: {fileID: 0}
triggerClips: []
triggerFrame: 0
onTrigger:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 0}
m_MethodName: PlayOneShot
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_Calls: []
mode: 0
info:
--- !u!114 &54049355739133177

File diff suppressed because it is too large Load Diff

@ -33,7 +33,7 @@ namespace UltraCombos.Frozen
[SerializeField]
private RectTransform fakeButton;
private CanvasGroup canvas_group;
// private CanvasGroup canvas_group;
[Header("DShow Player")]
[SerializeField]
@ -109,26 +109,32 @@ namespace UltraCombos.Frozen
{
if (fakeButton != null)
return;
GameObject obj = new GameObject(gameObject.name);
obj.transform.parent = GameObject.Find("Final Canvas").transform.Find("RawImage");
fakeButton = obj.AddComponent<RectTransform>();
fakeButton.anchorMin = new Vector2(0, 0);
fakeButton.anchorMax = new Vector2(0, 0);
fakeButton.pivot = new Vector2(0.5f, 0.5f);
var standby_scale = renderers[(int)Status.STANDBY].transform.localScale;
fakeButton.sizeDelta = new Vector2(standby_scale.x, standby_scale.y) * FrozenScreenToWorldSpace.Instance.finalPixelsByMeter;
fakeButton.sizeDelta = Vector2.Min(fakeButton.sizeDelta, Vector2.one * 100.0f);
fakeButton.sizeDelta = Vector2.Max(fakeButton.sizeDelta, Vector2.one * 60.0f);
fakeButton.anchoredPosition3D = new Vector3(0, 0, 0);
fakeButton.localScale = Vector3.one;
fakeButton.gameObject.AddComponent<RawImage>();
fakeButton.GetComponent<RawImage>().color = new Color(1, 1, 1, 0);
TouchArea touch_area = fakeButton.gameObject.AddComponent<TouchArea>();
touch_area.PointerDown.AddListener((data) => { Trigger(data); });
touch_area.PointerDrag.AddListener((data) => { Trigger(data); });
canvas_group = fakeButton.gameObject.AddComponent<CanvasGroup>();
canvas_group.blocksRaycasts = true;
canvas_group.interactable = true;
// GameObject obj = new GameObject(gameObject.name);
// obj.transform.parent = GameObject.Find("Final Canvas").transform.Find("RawImage");
// fakeButton = obj.AddComponent<RectTransform>();
// fakeButton.anchorMin = new Vector2(0, 0);
// fakeButton.anchorMax = new Vector2(0, 0);
// fakeButton.pivot = new Vector2(0.5f, 0.5f);
// var standby_scale = renderers[(int)Status.STANDBY].transform.localScale;
// fakeButton.sizeDelta = new Vector2(standby_scale.x, standby_scale.y) * FrozenScreenToWorldSpace.Instance.finalPixelsByMeter;
// fakeButton.sizeDelta = Vector2.Min(fakeButton.sizeDelta, Vector2.one * 100.0f);
// fakeButton.sizeDelta = Vector2.Max(fakeButton.sizeDelta, Vector2.one * 60.0f);
// fakeButton.anchoredPosition3D = new Vector3(0, 0, 0);
// fakeButton.localScale = Vector3.one;
// fakeButton.gameObject.AddComponent<RawImage>();
// fakeButton.GetComponent<RawImage>().color = new Color(1, 1, 1, 0);
// TouchArea touch_area = fakeButton.gameObject.AddComponent<TouchArea>();
// touch_area.PointerDown.AddListener((data) => { Trigger(data); });
// touch_area.PointerDrag.AddListener((data) => { Trigger(data); });
TestTouch test_touch = GetComponentInChildren<TestTouch>();
if (test_touch != null)
{
test_touch.onPointerDown.AddListener((data) => { Trigger(data); });
test_touch.onPointerDrag.AddListener((data) => { Trigger(data); });
}
// canvas_group = fakeButton.gameObject.AddComponent<CanvasGroup>();
// canvas_group.blocksRaycasts = true;
// canvas_group.interactable = true;
}
private void Start()
@ -154,10 +160,9 @@ namespace UltraCombos.Frozen
if (fakeButton != null)
{
fakeButton.gameObject.SetActive(true);
canvas_group.interactable = true;
canvas_group.blocksRaycasts = true;
// canvas_group.interactable = true;
// canvas_group.blocksRaycasts = true;
}
}
private void OnDisable()
@ -165,8 +170,8 @@ namespace UltraCombos.Frozen
if (fakeButton != null)
{
fakeButton.gameObject.SetActive(false);
canvas_group.interactable = false;
canvas_group.blocksRaycasts = false;
// canvas_group.interactable = false;
// canvas_group.blocksRaycasts = false;
}
}
@ -246,8 +251,8 @@ namespace UltraCombos.Frozen
if (mode) info = "STANDBY";
// standby
{
canvas_group.interactable = true;
canvas_group.blocksRaycasts = true;
// canvas_group.interactable = true;
// canvas_group.blocksRaycasts = true;
status = Status.STANDBY;
var player = StatePlayer;
player.Loop = isStandbyLoop;
@ -274,8 +279,8 @@ namespace UltraCombos.Frozen
if (mode) info = "TRIGGER";
// trigger
{
canvas_group.interactable = false;
canvas_group.blocksRaycasts = false;
// canvas_group.interactable = false;
// canvas_group.blocksRaycasts = false;
onTrigger.Invoke();
status = Status.TRIGGER;
var player = StatePlayer;
@ -451,7 +456,6 @@ namespace UltraCombos.Frozen
void RandomPos()
{
float minX = renderers[(int)Status.TRIGGER].transform.localScale.x / 2;
#if true
switch (area)
{
case Area.TopWall:
@ -462,13 +466,7 @@ namespace UltraCombos.Frozen
wallRoi.x = Random.Range(minX, FrozenScreenToWorldSpace.Instance.depth - minX) / FrozenScreenToWorldSpace.Instance.depth;
break;
}
#else
Vector3 randomPos = transform.localPosition;
if (randomPos.x == 0)
wallRoi.x = Random.Range(minX, FrozenScreenToWorldSpace.Instance.width - minX) / FrozenScreenToWorldSpace.Instance.width;
else
wallRoi.x = Random.Range(minX, FrozenScreenToWorldSpace.Instance.length - minX) / FrozenScreenToWorldSpace.Instance.length;
#endif
wallRoi.y = origin_height / FrozenScreenToWorldSpace.Instance.height;
UpdatePos();
UpdateButtonPos();
@ -476,7 +474,6 @@ namespace UltraCombos.Frozen
void UpdatePos()
{
#if true
Vector3 n_pos = transform.position;
switch (area)
{
@ -490,16 +487,6 @@ namespace UltraCombos.Frozen
}
n_pos.y = Mathf.Lerp(0.0f, FrozenScreenToWorldSpace.Instance.height, wallRoi.y);
transform.position = n_pos + FrozenScreenToWorldSpace.Instance.Position;
#else
Vector3 n_pos = transform.localPosition;
if (area == Area.TopWall)
n_pos.x = Mathf.Lerp(-FrozenScreenToWorldSpace.Instance.width / 2, FrozenScreenToWorldSpace.Instance.width / 2, wallRoi.x);
else
n_pos.z = Mathf.Lerp(-FrozenScreenToWorldSpace.Instance.length / 2, FrozenScreenToWorldSpace.Instance.length / 2, wallRoi.x);
n_pos.y = Mathf.Lerp(0, (float)FrozenScreenToWorldSpace.Instance.height, wallRoi.y);
transform.localPosition = n_pos;
#endif
//SetButtonPos();
}
@ -508,8 +495,8 @@ namespace UltraCombos.Frozen
//Vector2 newScreenPos = FrozenScreenToWorldSpace.Instance.GetFinalScreenPos(area, wallRoi);
var roi = FrozenScreenToWorldSpace.Instance.GetWallRoiFromPosition(area, renderers[(int)Status.STANDBY].transform.position);
Vector2 newScreenPos = FrozenScreenToWorldSpace.Instance.GetFinalScreenPos(area, roi);
newScreenPos.x = newScreenPos.x / 1830 * 1260;
fakeButton.anchoredPosition = newScreenPos;
// newScreenPos.x = newScreenPos.x / 1830 * 1260;
// fakeButton.anchoredPosition = newScreenPos;
}
void SetSpecificPos()
@ -536,6 +523,5 @@ namespace UltraCombos.Frozen
isTriggered = true;
}
}
}

@ -3,6 +3,8 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UltraCombos.Utility;
using System.Linq;
using UltraCombos.Utility.Attributes;
namespace UltraCombos.Frozen
{
@ -18,33 +20,24 @@ namespace UltraCombos.Frozen
public State state = State.Standby;
public float standbyTime = 10.0f;
[Range(0, 1)]
public float rate = 0.0f;
public List<Material> spaceMaterials = new List<Material>();
[SerializeField, Range(0.0f, 0.1f)]
float daySnowSize = 0.01f;
[SerializeField, Range(0.0f, 0.1f)]
float nightSnowSize = 0.01f;
[SerializeField]
Material snowMaterial;
List<CharacterBehaviour> characters;
float target_rate = 0.0f;
public UnityEvent onSceneStandby = new UnityEvent();
public UnityEvent onSceneDay = new UnityEvent();
public UnityEvent onSceneNight = new UnityEvent();
[SerializeField, Header("Debug")]
[Header("Debug")]
[SerializeField]
float stamp = 0.0f;
[Range(0, 1), ReadOnly]
public float rate = 0.0f;
float target_rate = 0.0f;
[ReadOnly]
public List<Material> spaceMaterials = new List<Material>();
[ReadOnly, SerializeField]
List<CharacterBehaviour> characters;
private void Start()
{
var cbs = FindObjectsOfType<CharacterBehaviour>();
characters = new List<CharacterBehaviour>(cbs);
characters = FindObjectsOfType<CharacterBehaviour>().ToList();
}
private void Update()
@ -61,26 +54,15 @@ namespace UltraCombos.Frozen
}
}
if (state == State.Standby)
{
target_rate = 0.0f;
}
else if (state == State.Day)
{
if (state == State.Standby || state == State.Day)
target_rate = 0.0f;
}
else if (state == State.Night)
{
target_rate = 1.0f;
}
rate = Mathf.Lerp(rate, target_rate, 0.02f);
foreach (var mat in spaceMaterials)
mat.SetFloat("_Rate", rate);
snowMaterial.SetFloat("_Size", Mathf.Lerp(daySnowSize, nightSnowSize, rate));
foreach (var chr in characters)
{
chr.Active = chr.appearSataes.List.Contains(state);

@ -56,8 +56,6 @@ namespace UltraCombos.Frozen
ta.materials.Clear();
ta.materials.Add(renderers[1].material);
}
}
}
}

@ -0,0 +1,55 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using Random = UnityEngine.Random;
public class TestTouch : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler, IPointerExitHandler
{
public bool MouseOnly = false;
[System.Serializable]
public class PointerEvent : UnityEvent<PointerEventData> { };
public PointerEvent onPointerDown = new PointerEvent();
public PointerEvent onPointerUp = new PointerEvent();
public PointerEvent onPointerDrag = new PointerEvent();
public PointerEvent onPointerExit = new PointerEvent();
public void OnPointerDown(PointerEventData eventData)
{
LogPointerEvent(eventData);
onPointerDown.Invoke(eventData);
}
public void OnPointerUp(PointerEventData eventData)
{
LogPointerEvent(eventData);
onPointerUp.Invoke(eventData);
}
public void OnDrag(PointerEventData eventData)
{
LogPointerEvent(eventData);
onPointerDrag.Invoke(eventData);
}
public void OnPointerExit(PointerEventData eventData)
{
LogPointerEvent(eventData);
// if (skip_on_mouse_only(eventData))
// return;
onPointerExit.Invoke(eventData);
}
void LogPointerEvent(PointerEventData eventData)
{
// Debug.Log(eventData);
}
// private bool skip_on_mouse_only(PointerEventData eventData)
// {
// return MouseOnly && eventData.pointerId != -1;
// }
}

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 977dba8f8a298824fb413e7f143abbd4
guid: 03a44ad9104fd3349addf7d3ff2435a6
MonoImporter:
externalObjects: {}
serializedVersion: 2

@ -1,10 +0,0 @@
fileFormatVersion: 2
guid: 89866ed2890c65949bb4f6c771ffac15
folderAsset: yes
timeCreated: 1519716678
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -1,10 +0,0 @@
fileFormatVersion: 2
guid: 59275d3d928b20244807781974ba2018
folderAsset: yes
timeCreated: 1519716678
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -1,86 +0,0 @@
fileFormatVersion: 2
guid: c65d1765230ad954980c187315d86736
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
isPreloaded: 0
isOverridable: 0
platformData:
- first:
'': Any
second:
enabled: 0
settings:
Exclude Editor: 0
Exclude Linux: 0
Exclude Linux64: 0
Exclude LinuxUniversal: 0
Exclude OSXUniversal: 0
Exclude Win: 1
Exclude Win64: 0
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 1
settings:
CPU: x86_64
DefaultValueInitialized: true
OS: Windows
- first:
Facebook: Win
second:
enabled: 0
settings:
CPU: None
- first:
Facebook: Win64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Linux
second:
enabled: 1
settings:
CPU: x86
- first:
Standalone: Linux64
second:
enabled: 1
settings:
CPU: x86_64
- first:
Standalone: LinuxUniversal
second:
enabled: 1
settings:
CPU: AnyCPU
- first:
Standalone: OSXUniversal
second:
enabled: 1
settings:
CPU: AnyCPU
- first:
Standalone: Win
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win64
second:
enabled: 1
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:

@ -1,10 +0,0 @@
fileFormatVersion: 2
guid: 0ee950eb7409c6a47adf64c4fd3c860b
folderAsset: yes
timeCreated: 1519716678
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -1,80 +0,0 @@
using System;
using UnityEngine;
public class Drawing
{
//****************************************************************************************************
// static function DrawLine(rect : Rect) : void
// static function DrawLine(rect : Rect, color : Color) : void
// static function DrawLine(rect : Rect, width : float) : void
// static function DrawLine(rect : Rect, color : Color, width : float) : void
// static function DrawLine(Vector2 pointA, Vector2 pointB) : void
// static function DrawLine(Vector2 pointA, Vector2 pointB, color : Color) : void
// static function DrawLine(Vector2 pointA, Vector2 pointB, width : float) : void
// static function DrawLine(Vector2 pointA, Vector2 pointB, color : Color, width : float) : void
//
// Draws a GUI line on the screen.
//
// DrawLine makes up for the severe lack of 2D line rendering in the Unity runtime GUI system.
// This function works by drawing a 1x1 texture filled with a color, which is then scaled
// and rotated by altering the GUI matrix. The matrix is restored afterwards.
//****************************************************************************************************
public static Texture2D lineTex;
public static void DrawLine(Rect rect) { DrawLine(rect, GUI.contentColor, 1.0f); }
public static void DrawLine(Rect rect, Color color) { DrawLine(rect, color, 1.0f); }
public static void DrawLine(Rect rect, float width) { DrawLine(rect, GUI.contentColor, width); }
public static void DrawLine(Rect rect, Color color, float width) { DrawLine(new Vector2(rect.x, rect.y), new Vector2(rect.x + rect.width, rect.y + rect.height), color, width); }
public static void DrawLine(Vector2 pointA, Vector2 pointB) { DrawLine(pointA, pointB, GUI.contentColor, 1.0f); }
public static void DrawLine(Vector2 pointA, Vector2 pointB, Color color) { DrawLine(pointA, pointB, color, 1.0f); }
public static void DrawLine(Vector2 pointA, Vector2 pointB, float width) { DrawLine(pointA, pointB, GUI.contentColor, width); }
public static void DrawLine(Vector2 pointA, Vector2 pointB, Color color, float width)
{
// Save the current GUI matrix, since we're going to make changes to it.
Matrix4x4 matrix = GUI.matrix;
// Generate a single pixel texture if it doesn't exist
if (!lineTex) { lineTex = new Texture2D(1, 1); }
// Store current GUI color, so we can switch it back later,
// and set the GUI color to the color parameter
Color savedColor = GUI.color;
GUI.color = color;
// Determine the angle of the line.
float angle = Vector3.Angle(pointB - pointA, Vector2.right);
// Vector3.Angle always returns a positive number.
// If pointB is above pointA, then angle needs to be negative.
if (pointA.y > pointB.y) { angle = -angle; }
// Use ScaleAroundPivot to adjust the size of the line.
// We could do this when we draw the texture, but by scaling it here we can use
// non-integer values for the width and length (such as sub 1 pixel widths).
// Note that the pivot point is at +.5 from pointA.y, this is so that the width of the line
// is centered on the origin at pointA.
GUIUtility.ScaleAroundPivot(new Vector2((pointB - pointA).magnitude, width), new Vector2(pointA.x, pointA.y + 0.5f));
// Set the rotation for the line.
// The angle was calculated with pointA as the origin.
GUIUtility.RotateAroundPivot(angle, pointA);
// Finally, draw the actual line.
// We're really only drawing a 1x1 texture from pointA.
// The matrix operations done with ScaleAroundPivot and RotateAroundPivot will make this
// render with the proper width, length, and angle.
GUI.DrawTexture(new Rect(pointA.x, pointA.y, 1, 1), lineTex);
// We're done. Restore the GUI matrix and GUI color to whatever they were before.
GUI.matrix = matrix;
GUI.color = savedColor;
}
public static void DrawPoint(Vector2 point, float size) { DrawPoint(point, GUI.contentColor, size); }
public static void DrawPoint(Vector2 point, Color color, float size)
{
var offset = new Vector2(size, 0);
DrawLine(point - offset, point + offset, color, size * 2);
}
}

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 1bb6e5028f6629747a492c9dd625d83d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -1,28 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UltraCombos.Utility
{
public sealed class NativeBufferPool : Singleton<NativeBufferPool>
{
private NativeBufferPool() { }
Dictionary<System.IntPtr, System.IntPtr> references = new Dictionary<System.IntPtr, System.IntPtr>();
public System.IntPtr GetReference(System.IntPtr bufferHandle)
{
if (references.ContainsKey(bufferHandle) == false)
references.Add(bufferHandle, Buffer.Create(bufferHandle));
return references[bufferHandle];
}
private void OnDestroy()
{
foreach (var buf in references.Values)
{
Buffer.Release(buf);
}
}
}
}

@ -1,158 +0,0 @@
// Only works on ARGB32, RGB24 and Alpha8 textures that are marked readable
using System.Threading;
using UnityEngine;
public class TextureScale
{
public class ThreadData
{
public int start;
public int end;
public ThreadData(int s, int e)
{
start = s;
end = e;
}
}
private static Color[] texColors;
private static Color[] newColors;
private static int w;
private static float ratioX;
private static float ratioY;
private static int w2;
private static int finishCount;
private static Mutex mutex;
public static void Point(Texture2D tex, int newWidth, int newHeight)
{
ThreadedScale(tex, newWidth, newHeight, false);
}
public static void Bilinear(Texture2D tex, int newWidth, int newHeight)
{
ThreadedScale(tex, newWidth, newHeight, true);
}
private static void ThreadedScale(Texture2D tex, int newWidth, int newHeight, bool useBilinear)
{
texColors = tex.GetPixels();
newColors = new Color[newWidth * newHeight];
if (useBilinear)
{
ratioX = 1.0f / ((float)newWidth / (tex.width - 1));
ratioY = 1.0f / ((float)newHeight / (tex.height - 1));
}
else
{
ratioX = ((float)tex.width) / newWidth;
ratioY = ((float)tex.height) / newHeight;
}
w = tex.width;
w2 = newWidth;
var cores = Mathf.Min(SystemInfo.processorCount, newHeight);
var slice = newHeight / cores;
finishCount = 0;
if (mutex == null)
{
mutex = new Mutex(false);
}
if (cores > 1)
{
int i = 0;
ThreadData threadData;
for (i = 0; i < cores - 1; i++)
{
threadData = new ThreadData(slice * i, slice * (i + 1));
ParameterizedThreadStart ts = useBilinear ? new ParameterizedThreadStart(BilinearScale) : new ParameterizedThreadStart(PointScale);
Thread thread = new Thread(ts);
thread.Start(threadData);
}
threadData = new ThreadData(slice * i, newHeight);
if (useBilinear)
{
BilinearScale(threadData);
}
else
{
PointScale(threadData);
}
while (finishCount < cores)
{
Thread.Sleep(1);
}
}
else
{
ThreadData threadData = new ThreadData(0, newHeight);
if (useBilinear)
{
BilinearScale(threadData);
}
else
{
PointScale(threadData);
}
}
tex.Resize(newWidth, newHeight);
tex.SetPixels(newColors);
tex.Apply();
texColors = null;
newColors = null;
}
public static void BilinearScale(System.Object obj)
{
ThreadData threadData = (ThreadData)obj;
for (var y = threadData.start; y < threadData.end; y++)
{
int yFloor = (int)Mathf.Floor(y * ratioY);
var y1 = yFloor * w;
var y2 = (yFloor + 1) * w;
var yw = y * w2;
for (var x = 0; x < w2; x++)
{
int xFloor = (int)Mathf.Floor(x * ratioX);
var xLerp = x * ratioX - xFloor;
newColors[yw + x] = ColorLerpUnclamped(ColorLerpUnclamped(texColors[y1 + xFloor], texColors[y1 + xFloor + 1], xLerp),
ColorLerpUnclamped(texColors[y2 + xFloor], texColors[y2 + xFloor + 1], xLerp),
y * ratioY - yFloor);
}
}
mutex.WaitOne();
finishCount++;
mutex.ReleaseMutex();
}
public static void PointScale(System.Object obj)
{
ThreadData threadData = (ThreadData)obj;
for (var y = threadData.start; y < threadData.end; y++)
{
var thisY = (int)(ratioY * y) * w;
var yw = y * w2;
for (var x = 0; x < w2; x++)
{
newColors[yw + x] = texColors[(int)(thisY + ratioX * x)];
}
}
mutex.WaitOne();
finishCount++;
mutex.ReleaseMutex();
}
private static Color ColorLerpUnclamped(Color c1, Color c2, float value)
{
return new Color(c1.r + (c2.r - c1.r) * value,
c1.g + (c2.g - c1.g) * value,
c1.b + (c2.b - c1.b) * value,
c1.a + (c2.a - c1.a) * value);
}
}

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 152cd88bb1500e64599b85d755e284eb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -1,117 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
namespace UltraCombos.Utility
{
public class D3D
{
const string dllName = "UnityUtilityNativePlugin";
[DllImport(dllName, EntryPoint = "GetDevice")]
public static extern IntPtr GetDevice();
[DllImport(dllName, EntryPoint = "GetContext")]
public static extern IntPtr GetContext();
[DllImport(dllName, EntryPoint = "ReleaseContext")]
public static extern void ReleaseContext(IntPtr context);
}
public class Buffer
{
const string dllName = "UnityUtilityNativePlugin";
[DllImport(dllName, EntryPoint = "CreateBuffer")]
public static extern IntPtr Create(IntPtr bufferHandle);
[DllImport(dllName, EntryPoint = "SetBufferData")]
public static extern bool SetData(IntPtr bufferHandle, IntPtr data, int dataSize);
[DllImport(dllName, EntryPoint = "GetBufferData")]
public static extern bool GetData(IntPtr bufferHandle, IntPtr data, int dataSize);
[DllImport(dllName, EntryPoint = "CopyResource")]
public static extern void Copy(IntPtr dstHandle, IntPtr srcHandle);
[DllImport(dllName, EntryPoint = "ReleaseBuffer")]
public static extern void Release(IntPtr bufferHandle);
[DllImport(dllName, EntryPoint = "GetBufferSize")]
public static extern int GetSize(IntPtr bufferHandle);
[DllImport(dllName, EntryPoint = "GetBufferStride")]
public static extern int GetStride(IntPtr bufferHandle);
public static void GetDataImpl(IntPtr bufferHandle, IntPtr data, int dataSize)
{
IntPtr handle = NativeBufferPool.Instance.GetReference(bufferHandle);
Copy(handle, bufferHandle);
if (GetData(handle, data, dataSize) == false)
Debug.Log("GetDataImpl fail");
}
public static void SetDataImpl(IntPtr bufferHandle, IntPtr data, int dataSize)
{
IntPtr handle = NativeBufferPool.Instance.GetReference(bufferHandle);
if (SetData(handle, data, dataSize))
Copy(bufferHandle, handle);
else Debug.Log("SetDataImpl fail");
}
}
public class Texture
{
const string dllName = "UnityUtilityNativePlugin";
[DllImport(dllName, EntryPoint = "CreateTexture")]
public static extern IntPtr Create(IntPtr textureHandle, ref int height, ref int width);
[DllImport(dllName, EntryPoint = "SetTextureData")]
public static extern void SetData(IntPtr textureHandle, IntPtr data, int height, int width);
[DllImport(dllName, EntryPoint = "GetTextureData")]
public static extern void GetData(IntPtr textureHandle, IntPtr data, int height, int width);
[DllImport(dllName, EntryPoint = "CopyResource")]
public static extern void Copy(IntPtr dstHandle, IntPtr srcHandle);
[DllImport(dllName, EntryPoint = "ReleaseTexture")]
public static extern void Release(IntPtr textureHandle);
/*
public static void SetDataImpl(IntPtr bufferHandle, IntPtr data, int dataSize)
{
IntPtr handle = NativeBufferPool.Instance.GetReference(bufferHandle);
SetData(handle, data, dataSize);
Copy(bufferHandle, handle);
}
*/
}
public class Flatbuffers
{
const string dllName = "UnityUtilityNativePlugin";
[DllImport(dllName, EntryPoint = "FlatbuffersParse")]
public static extern IntPtr Parse([MarshalAs(UnmanagedType.LPStr)]string schemafile, IntPtr flatbuffer);
}
public class Memory
{
[DllImport("msvcrt.dll", EntryPoint = "memcpy")]
public static extern void Copy(IntPtr dst, IntPtr src, int size);
[DllImport("msvcrt.dll", EntryPoint = "memset")]
public static extern void Set(IntPtr dst, int val, int size);
public static void Swap<T>(ref T lhs, ref T rhs)
{
T temp = lhs;
lhs = rhs;
rhs = temp;
}
}
}

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: f1983112498f3184585e273b1f48bc20
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -1 +1 @@
Subproject commit 831947fd2875cfbbedb0bf0dbe8bf53b60d88dfe
Subproject commit cf7a223b2a1d2d77fe6eec0d7c4c9c25f1a9de2a
Loading…
Cancel
Save