add function (instantiate when drag)

master
tigerchen 6 years ago
parent ea3f62996a
commit fd48805804
  1. 5
      08_DarkSea/Unity-19050-08-DarkSea/19050-08-DarkSea/Assets/Prefabs/RawImage.prefab
  2. 80
      08_DarkSea/Unity-19050-08-DarkSea/19050-08-DarkSea/Assets/Scripts/movieController.cs
  3. 114
      08_DarkSea/Unity-19050-08-DarkSea/19050-08-DarkSea/Assets/Scripts/tuio_event.cs
  4. 2
      08_DarkSea/Unity-19050-08-DarkSea/19050-08-DarkSea/Assets/Videos/New UltraCombos.DShowClip.asset

@ -38,7 +38,7 @@ RectTransform:
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 300, y: 300}
m_SizeDelta: {x: 200, y: 200}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &2142686115215515799
CanvasRenderer:
@ -88,6 +88,9 @@ MonoBehaviour:
id: 0
fade_speed: 0.05
stat: 0
alpha: 0
destroy_timer: 0
CanDsetroy: 0
--- !u!114 &1996081109
MonoBehaviour:
m_ObjectHideFlags: 0

@ -9,68 +9,38 @@ public class movieController : MonoBehaviour
{
DShowMoviePlayer player;
public int id;
//public tuio_event tuio_event;
public float fade_speed = 0.02f;
public int stat;
float c;
public float alpha;
public float destroy_timer;
float wait_sec = 3f;
//Vector2 pos, pre_pos;
//public Transform trans;
public bool CanDsetroy;
float wait_sec = 2f;
void Awake()
{
player = GetComponent<DShowMoviePlayer>();
//trans = GetComponent<Transform>();
CanDsetroy = true;
stat = 1;
}
void Start()
{
//player = GetComponent<DShowMoviePlayer>();
GetComponent<RawImage>().color = Color.clear;
//pos = Vector2.zero;
}
// Update is called once per frame
void Update()
{
#if false
transform.gameObject.SetActive(true);
trans = GetComponent<Transform>();
//Debug.Log(stat);
pre_pos = pos;
if (tuio_event.tuio_input.touchCount > 0 && id != -1)
{
transform.gameObject.SetActive(true);
//////////////////////
///
/*
int t_c = tuio_event.tuio_input.touchCount;
if (id == t_c)
{
//id -= 1;
Debug.Log("error");
}
//Debug.Log("id = " + id + " / touch count = " + t_c);
if (id >= 0)
{
pos = tuio_event.tuio_input.GetTouch(id).position;
}
else
pos = pre_pos;
GetComponent<RectTransform>().position = new Vector3(pos.x, pos.y, 0);
*/
if(stat == 0){
alpha = 0;
stat = 1;
}
#endif
if (stat == 1)
else if (stat == 1)
{
c += fade_speed;
if (c > 1)
alpha += fade_speed;
if (alpha >= 1)
{
c = 1;
alpha = 1;
stat = 2;
}
@ -80,17 +50,16 @@ public class movieController : MonoBehaviour
float t = Time.time;
if (t - destroy_timer > wait_sec)
{
Debug.Log("fade");
c -= fade_speed;
if (c < 0)
//Debug.Log("fade");
alpha -= fade_speed;
if (alpha < 0 && CanDsetroy)
{
Destroy(this.gameObject);
}
}
}
GetComponent<RawImage>().color = new Color(1f, 1f, 1f, c);
GetComponent<RawImage>().color = new Color(1f, 1f, 1f, alpha);
}
void OnEnable()
@ -100,17 +69,22 @@ public class movieController : MonoBehaviour
GetComponent<RawImage>().enabled = true;
}
//Debug.Log("Hi");
//Debug.Log(id.ToString());
stat = 1;
c = 0f;
Vector3 rot_axis = new Vector3(0, 0, 1);
Vector3 mid_pt = new Vector3(GetComponent<RectTransform>().position.x, GetComponent<RectTransform>().position.y, 0);
float rand_deg = Random.Range(0, 360);
GetComponent<RectTransform>().Rotate(rot_axis, rand_deg);
alpha = 0f;
rotateImg();
}
void OnDestroy()
{
//Debug.Log("Bye");
}
public void rotateImg()
{
Vector3 rot_axis = new Vector3(0, 0, 1);
Vector3 mid_pt = new Vector3(GetComponent<RectTransform>().position.x, GetComponent<RectTransform>().position.y, 0);
float rand_deg = Random.Range(0, 360);
GetComponent<RectTransform>().Rotate(rot_axis, rand_deg);
}
}

@ -9,6 +9,8 @@ public class tuio_event : MonoBehaviour
public Transform canvas;
//public UltraCombos.GlobalMKHookInput tuio_input;
Dictionary<int, movieController> movies = new Dictionary<int, movieController>();
Dictionary<int, Vector2> pre_pos = new Dictionary<int, Vector2>();
void Update()
{
var touches = TUIOManager.Instance.touches;
@ -24,11 +26,43 @@ public class tuio_event : MonoBehaviour
movie.id = id;
movies.Add(id, movie);
movie.transform.position = touches[id].position;
pre_pos.Add(id, touches[id].position);
}
else //update
{
if (Time.frameCount % 10 == 0)
{
float delta_pos = Vector2.Distance(pre_pos[id], touches[id].position);
if (delta_pos > 200)
{
Debug.Log("generate new one");
GameObject g = Instantiate(img, canvas);
int clone_id = id + Random.Range(5000, 10000);
g.name = clone_id.ToString();
movie = g.AddComponent<movieController>();
movie.id = clone_id;
movies.Add(clone_id, movie);
movie.transform.position = pre_pos[id];
movie.transform.localRotation = movies[id].transform.localRotation;
movie.alpha = 0.9f;
movies[id].stat = 0;
movies[id].transform.position = touches[id].position;
movies[id].CanDsetroy = false;
movies[id].rotateImg();
pre_pos[id] = touches[id].position;
}
else
{
//movies[id].transform.position = touches[id].position;
}
}
else
{
movie = movies[id];
}
}
//update or after adding
//Debug.Log("Update");
//movie.transform.position = touches[id].position;
@ -45,92 +79,16 @@ public class tuio_event : MonoBehaviour
}
foreach (var id in removes)
{
if (movies[id].stat == 2)
if (movies[id].stat == 2 || movies[id].stat == 3)
{
movies[id].stat = 3;
movies[id].destroy_timer = Time.time;
movies[id].CanDsetroy = true;
movies.Remove(id);
Debug.Log("Remove");
}
//movies[id].destroy_timer = Time.time;
}
//movies.Remove(id);
}
#else
// Start is called before the first frame update
public GameObject img;
public GameObject canvas;
public UltraCombos.GlobalMKHookInput tuio_input;
List<int> cur_ids = new List<int>();
List<int> pre_ids = new List<int>();
int pre_count;
int cur_count;
void Start()
{
cur_count = 0;
}
void Update()
{
reset_id();
pre_count = cur_count;
pre_ids.Clear();
cur_ids.ForEach(i => pre_ids.Add(i));
cur_count = tuio_input.touchCount;
cur_ids.Clear();
for (int i = 0; i < cur_count; i++)
{
cur_ids.Add(tuio_input.GetTouch(i).fingerId);
}
if (cur_count > pre_count) // Add
{
//Debug.Log("Add");
for (int i = 0; i < cur_count; i++)
{
int f_id = tuio_input.GetTouch(i).fingerId;
bool isOldTouch = pre_ids.Contains(f_id);
if (isOldTouch == false)
{
GameObject g = Instantiate(img, canvas.GetComponent<Transform>());
g.name = f_id.ToString();
//g.GetComponent<movieController>().id = i;
}
}
}
else if (cur_count < pre_count) // Remove
{
//Debug.Log("Remove");
int exit_id;
for (int i = 0; i < pre_count; i++)
{
int _id = pre_ids[i];
bool isExitTouch = !cur_ids.Contains(_id);
if (isExitTouch)
{
exit_id = _id;
//GameObject.Find(_id.ToString()).GetComponent<movieController>().stat = 2;
Destroy(GameObject.Find(_id.ToString()));
}
}
}
reset_id();
}
void reset_id()
{
GameObject[] objs = GameObject.FindGameObjectsWithTag("onFoot");
//Debug.Log(objs.Length);
for (int i = 0; i < objs.Length; i++)
{
objs[i].GetComponent<movieController>().id = i - 1;
Debug.Log(objs[i].name + " / id = " + objs[i].GetComponent<movieController>().id.ToString());
}
}
#endif
}

@ -13,5 +13,5 @@ MonoBehaviour:
m_Name: New UltraCombos.DShowClip
m_EditorClassIdentifier:
m_VideoLocation: 1
m_VideoPath: ..\..\..\..\_Deploy_PC\08_DarkSea\Material\1928-01-D.avi
m_VideoPath: ..\..\..\..\_Deploy_PC\08_DarkSea\Material\Video_buttombracket.avi
animationClip: {fileID: 0}

Loading…
Cancel
Save