update 3D object add 2D canvas collider

master
yuan 8 years ago
parent b7e823d0e9
commit 58eb05058f
  1. 15
      Unity_2018_Frozen/Assets/Frozen/DSAsset/SnowStandby.asset
  2. 10
      Unity_2018_Frozen/Assets/Frozen/DSAsset/SnowStandby.asset.meta
  3. 15
      Unity_2018_Frozen/Assets/Frozen/DSAsset/SnowTrigger.asset
  4. 10
      Unity_2018_Frozen/Assets/Frozen/DSAsset/SnowTrigger.asset.meta
  5. 505
      Unity_2018_Frozen/Assets/Frozen/FrozenTwo.unity
  6. 208
      Unity_2018_Frozen/Assets/Frozen/Script/CharacterBehaviour.cs
  7. 39
      Unity_2018_Frozen/Assets/Frozen/Script/FrozenCharacterController.cs
  8. 13
      Unity_2018_Frozen/Assets/Frozen/Script/FrozenCharacterController.cs.meta
  9. 58
      Unity_2018_Frozen/Assets/Frozen/Script/FrozenScreenToWorldSpace.cs
  10. 75
      Unity_2018_Frozen/Assets/Frozen/Script/TouchArea.cs
  11. 13
      Unity_2018_Frozen/Assets/Frozen/Script/TouchArea.cs.meta
  12. 67
      Unity_2018_Frozen/Assets/Frozen/Shader/UnlitColorAlpha.shader
  13. 10
      Unity_2018_Frozen/Assets/Frozen/Shader/UnlitColorAlpha.shader.meta
  14. 2
      Unity_2018_Frozen/Assets/UnityUtils

@ -0,0 +1,15 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b7eca376a120a0e49a97afa024778843, type: 3}
m_Name: SnowStandby
m_EditorClassIdentifier:
m_VideoLocation: 1
m_VideoPath: ../Material/Model_B-standby.avi

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: fb02941bf56531748886776e54c8f2d0
timeCreated: 1524210684
licenseType: Free
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,15 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b7eca376a120a0e49a97afa024778843, type: 3}
m_Name: SnowTrigger
m_EditorClassIdentifier:
m_VideoLocation: 1
m_VideoPath: ../Material/Model_B-play.avi

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 86cfefcea0dbaf349b192625aa06ef6a
timeCreated: 1524453128
licenseType: Free
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because one or more lines are too long

@ -1,29 +1,229 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class CharacterBehaviour : MonoBehaviour { public class CharacterBehaviour : MonoBehaviour {
[SerializeField]
private bool standby = true;
public Material mat; public Material mat;
public Area area;
public Vector2 WallROI;
public float wallDistance = 0;
[SerializeField]
private RectTransform m_recttrans;
public DShowClip standbyclip;
public DShowClip TriggerClip;
[SerializeField]
private DShowMoviePlayer[] players;
private MeshRenderer m_meshRender;
public Color color;
private bool isSleep;
private void Awake() private void Awake()
{ {
mat = new Material(Shader.Find("Standard")); m_meshRender = GetComponent<MeshRenderer>();
GetComponent<MeshRenderer>().material = mat; mat = new Material(Shader.Find("Unlit/ColorTransparent"));
m_meshRender.material = mat;
List<Material> mats = new List<Material>(); List<Material> mats = new List<Material>();
mats.Add(mat); mats.Add(mat);
GetComponent<MovieTextureApply>().materials = mats; InitialDSPlayer();
} }
void InitialDSPlayer()
{
GameObject TriggerObj = new GameObject("Trigger");
TriggerObj.transform.parent = this.transform;
SetClip(TriggerObj.AddComponent<DShowMoviePlayer>(), TriggerClip);
GameObject standbyObj = new GameObject("Standby");
standbyObj.transform.parent = this.transform;
SetClip(standbyObj.AddComponent<DShowMoviePlayer>(), standbyclip);
players = GetComponentsInChildren<DShowMoviePlayer>();
}
void SetClip(DShowMoviePlayer player,DShowClip clip)
{
player.VideoAsset = clip;
player.Load();
}
void InitialTouchButton()
{
if (m_recttrans != null)
return;
GameObject obj = new GameObject(gameObject.name);
obj.transform.parent = GameObject.Find("Final Canvas").transform;
m_recttrans = obj.AddComponent<RectTransform>();
m_recttrans.anchorMin = new Vector2(0, 0);
m_recttrans.anchorMax = new Vector2(0, 0);
m_recttrans.pivot = new Vector2(0.5f, 0.5f);
m_recttrans.sizeDelta = new Vector2(transform.localScale.x, transform.localScale.y) * FrozenScreenToWorldSpace.Instance.finalPixelsByMeter;
m_recttrans.gameObject.AddComponent<RawImage>();
m_recttrans.GetComponent<RawImage>().color = new Color(1, 1, 1, 0);
TouchArea toucharea = m_recttrans.gameObject.AddComponent<TouchArea>();
toucharea.PointerDown.AddListener((data)=> { Trigger(data); });
toucharea.PointerDrag.AddListener((data) => { Trigger(data); });
}
// Use this for initialization // Use this for initialization
void Start () { void Start () {
standby = true;
isSleep = false;
mat.mainTextureScale = new Vector2(1, -1);
mat.mainTextureOffset = new Vector2(0,-1);
StartCoroutine(PlayOnStart());
InitialTouchButton();
RandomAppearWall();
}
IEnumerator PlayOnStart()
{
DShowMoviePlayer player = currentPlayer;
player.Loop = true;
while (!player.IsPlaying)
{
player.Play();
yield return null;
}
} }
// Update is called once per frame // Update is called once per frame
void Update () { void Update () {
if (Input.GetKeyDown(KeyCode.R))
RandomAppearWall();
if(!isSleep)
{
if (!standby)
CheckPlayFinished();
}
}
void UpdateMaterial()
{
mat.mainTexture = currentPlayer.Texture;
mat.SetColor("_Color", color);
}
void CheckPlayFinished()
{
if(currentPlayer.IsFinished)
{
StartCoroutine(Sleep());
}
} }
void RandomAppearWall()
{
Vector3 newPos = Vector3.zero;
area = (Area)Random.Range(0, 3);
Quaternion q = new Quaternion();
if (area == Area.LeftWall)
{
newPos.x = -FrozenScreenToWorldSpace.Instance.length / 2 + wallDistance;
q.SetLookRotation(Vector3.left);
}
if (area == Area.RightWall)
{
newPos.x = FrozenScreenToWorldSpace.Instance.length / 2 - wallDistance;
q.SetLookRotation(Vector3.right);
}
if (area == Area.TopWall)
{
newPos.z = FrozenScreenToWorldSpace.Instance.width / 2 - wallDistance;
q.SetLookRotation(Vector3.forward);
}
transform.rotation = q;
transform.localPosition = newPos;
RandomPos();
}
void UpdatePos()
{
Vector3 n_pos = transform.localPosition;
if (area == Area.TopWall)
n_pos.x = Mathf.Lerp(-FrozenScreenToWorldSpace.Instance.length / 2, FrozenScreenToWorldSpace.Instance.length / 2, WallROI.x);
else
n_pos.z = Mathf.Lerp(-FrozenScreenToWorldSpace.Instance.width / 2, FrozenScreenToWorldSpace.Instance.width / 2, WallROI.x);
n_pos.y = Mathf.Lerp(0, (float)FrozenScreenToWorldSpace.Instance.height, WallROI.y);
transform.localPosition = n_pos;
SetButtonPos();
}
void RandomPos()
{
Vector3 randomPos = transform.localPosition;
float minX = transform.localScale.x / 2;
if (randomPos.x == 0)
WallROI.x = Random.Range(minX, FrozenScreenToWorldSpace.Instance.length - minX) / FrozenScreenToWorldSpace.Instance.length;
else
WallROI.x = Random.Range(minX, FrozenScreenToWorldSpace.Instance.width - minX) / FrozenScreenToWorldSpace.Instance.width;
WallROI.y = Random.Range(0.5f, FrozenCharacterController.Instance.Maxheight) / (float)FrozenScreenToWorldSpace.Instance.height;
UpdatePos();
SetButtonPos();
}
void SetButtonPos()
{
Vector2 newScreenPos = FrozenScreenToWorldSpace.Instance.GetFinalScreenPos(area, WallROI);
m_recttrans.anchoredPosition = newScreenPos;
}
private void Trigger(PointerEventData data)
{
if (!standby || isSleep)
return;
standby = false;
currentPlayer.Play();
mat.mainTexture = currentPlayer.Texture;
}
void Idle()
{
standby = true;
currentPlayer.Play();
}
DShowMoviePlayer currentPlayer { get { return players[System.Convert.ToInt32(standby)]; } }
IEnumerator Sleep()
{
isSleep = true;
currentPlayer.Pause();
currentPlayer.Frame = 0;
yield return StartCoroutine(Fade(0));
m_meshRender.enabled = false;
yield return new WaitForSeconds(FrozenCharacterController.Instance.GetDisAppear());
RandomAppearWall();
standby = true;
currentPlayer.Play();
mat.mainTexture = currentPlayer.Texture;
m_meshRender.enabled = true;
yield return StartCoroutine(Fade(1));
isSleep = false;
Idle();
}
IEnumerator Fade(float targetA)
{
float value = 0;
float origin = color.a;
while(value < 1)
{
value = Mathf.Clamp(value + Time.deltaTime, 0,1);
color.a = Mathf.Lerp(origin, targetA, value);
yield return null;
}
}
} }

@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FrozenCharacterController : MonoBehaviour {
public static FrozenCharacterController Instance { get { return instance; } }
private static FrozenCharacterController instance;
[Range(3,15)]
public float DisAppearTime;
public float Maxheight = 0.65f;
private void Awake()
{
instance = this;
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public float GetDisAppear()
{
float distime = DisAppearTime - Random.Range(0, DisAppearTime / 2);
distime = DisAppearTime * distime - distime * distime + 0.5f * distime;
return distime;
}
}

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 7e9aa98273b5dc84189684d4767d23b4
timeCreated: 1524475879
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -2,21 +2,35 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class FrozenScreenToWorldSpace : MonoBehaviour { public enum Area
{
public enum Area
{
LeftWall, LeftWall,
RightWall, RightWall,
TopWall, TopWall,
Floor Floor
} }
public class FrozenScreenToWorldSpace : MonoBehaviour {
public static FrozenScreenToWorldSpace Instance {
get {
/*
if (instacnce == null && GameObject.Find("FrozenScreenToWorldSpace").GetComponent<FrozenScreenToWorldSpace>() != null)
instacnce = GameObject.Find("FrozenScreenToWorldSpace").GetComponent<FrozenScreenToWorldSpace>();
else
instacnce = new GameObject("FrozenScreenToWorldSpace").AddComponent<FrozenScreenToWorldSpace>();
*/
return instacnce;
}
}
private static FrozenScreenToWorldSpace instacnce;
public float width = 5; public float width = 5;
public float length = 8; public float length = 8;
public float height = 3; public float height = 3;
public float blackLength = 0.89f; public float blackLength = 0.89f;
public float PixelsByMeter = 360;
public float finalPixelsByMeter = 90;
[System.Serializable] [System.Serializable]
public class RenderTextureROI public class RenderTextureROI
{ {
@ -47,9 +61,10 @@ public class FrozenScreenToWorldSpace : MonoBehaviour {
private float totalLength; private float totalLength;
private float totalWidth; private float totalWidth;
// Use this for initialization
void Start() private void Awake()
{ {
instacnce = this;
InitailROISetting(); InitailROISetting();
} }
@ -73,4 +88,33 @@ public class FrozenScreenToWorldSpace : MonoBehaviour {
return RenderTextureROIList[area]; return RenderTextureROIList[area];
return null; return null;
} }
public Vector2 GetFinalScreenPos(Area area,Vector2 wallROI)
{
if(!RenderTextureROIList.ContainsKey(area))
return Vector2.zero;
RenderTextureROI textureROI = GetROI(area);
Vector2 currenPos = Vector2.zero;
if (area == Area.LeftWall)
{
float x = textureROI.X + (1 - wallROI.y) * textureROI.ROI_X;
float y = textureROI.Y + (1 - wallROI.x) * textureROI.ROI_Y;
currenPos = new Vector2(x,y);
}
if (area == Area.RightWall)
{
float x = textureROI.X + wallROI.y * textureROI.ROI_X;
float y = textureROI.Y + (1 - wallROI.x) * textureROI.ROI_Y;
currenPos = new Vector2(x, y);
}
if (area == Area.TopWall)
{
float x = textureROI.X + wallROI.x * textureROI.ROI_X;
float y = textureROI.Y + (1 - wallROI.y) * textureROI.ROI_Y;
currenPos = new Vector2(x, y);
}
currenPos = new Vector2(currenPos.x * Screen.width,( 1 - currenPos.y) * Screen.height);
return currenPos;
}
} }

@ -0,0 +1,75 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;
public class TouchArea : MonoBehaviour ,IPointerDownHandler,IDragHandler,IPointerExitHandler, IPointerUpHandler
{
[HideInInspector]
public Image img;
public bool MouseOnly = false;
[System.Serializable]
public class OnPointerDownEvent : UnityEvent<PointerEventData> { };
public OnPointerDownEvent PointerDown = new OnPointerDownEvent();
[System.Serializable]
public class OnPointerDragEvent : UnityEvent<PointerEventData> { };
public OnPointerDragEvent PointerDrag = new OnPointerDragEvent();
[System.Serializable]
public class OnPointerUpEvent : UnityEvent<PointerEventData> { };
public OnPointerUpEvent PointerUp = new OnPointerUpEvent();
[System.Serializable]
public class OnPointerExitEvent : UnityEvent<PointerEventData> { };
public OnPointerExitEvent PointerExit = new OnPointerExitEvent();
private void Awake()
{
img = GetComponent<Image>();
}
public void OnPointerDown(PointerEventData eventData)
{
if (PointerDown == null)
return;
if (skip_on_mouse_only(eventData))
return;
PointerDown.Invoke(eventData);
}
public void OnDrag(PointerEventData eventData)
{
if (PointerDrag == null)
return;
if (skip_on_mouse_only(eventData))
return;
PointerDrag.Invoke(eventData);
}
public void OnPointerUp(PointerEventData eventData)
{
if (PointerUp == null)
return;
if (skip_on_mouse_only(eventData))
return;
PointerUp.Invoke(eventData);
}
public void OnPointerExit(PointerEventData eventData)
{
if (PointerExit == null)
return;
if (skip_on_mouse_only(eventData))
return;
PointerExit.Invoke(eventData);
}
private bool skip_on_mouse_only(PointerEventData eventData)
{
return MouseOnly && eventData.pointerId != -1;
}
}

@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: a7c5e8323feda4b4499c3089d5c22e11
timeCreated: 1524470056
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,67 @@
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
// Unlit alpha-blended shader.
// - no lighting
// - no lightmap support
// - no per-material color
Shader "Unlit/ColorTransparent" {
Properties {
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
_Color("Color",Color) = (1,1,1,1)
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 100
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata_t {
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f {
float4 vertex : SV_POSITION;
float2 texcoord : TEXCOORD0;
UNITY_FOG_COORDS(1)
UNITY_VERTEX_OUTPUT_STEREO
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _Color;
v2f vert (appdata_t v)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = UnityObjectToClipPos(v.vertex);
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.texcoord) * _Color;
UNITY_APPLY_FOG(i.fogCoord, col);
return col;
}
ENDCG
}
}
}

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: a76fe72ab9c198948a9233662c9407f3
timeCreated: 1524480512
licenseType: Free
ShaderImporter:
externalObjects: {}
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

@ -1 +1 @@
Subproject commit 96aa7c3c0edb1bc529e2223f7a9b87a302eb671d Subproject commit 14d7e35c8053e94dcfc79b7181585fa022c70829
Loading…
Cancel
Save