Exemple #1
0
        private void PaintInterval(Link link, bool down)
        {
            if (down == true)
            {
                if (storeStates == true)
                {
                    P3dStateManager.StoreAllStates();
                }

                link.Age = interval;
            }

            link.Age += Time.deltaTime;

            if (link.Age >= interval)
            {
                if (interval > 0.0f)
                {
                    link.Age %= interval;
                }
                else
                {
                    link.Age = 0.0f;
                }

                RecordAndPaintAt(link, link.Finger.ScreenPosition, link.ScreenOld, false, link.Finger.Pressure, link);
            }
        }
        private void DoThrow(Vector2 screenPosition)
        {
            if (prefab != null)
            {
                var camera = P3dHelper.GetCamera();

                if (camera != null)
                {
                    if (storeStates == true)
                    {
                        P3dStateManager.StoreAllStates();
                    }

                    // Find the ray for this screen position
                    var ray      = camera.ScreenPointToRay(screenPosition);
                    var rotation = Quaternion.LookRotation(ray.direction);

                    // Loop through all prefabs and spawn them
                    var clone = Instantiate(prefab, ray.origin, rotation);

                    clone.SetActive(true);

                    // Throw with velocity?
                    var cloneRigidbody = clone.GetComponent <Rigidbody>();

                    if (cloneRigidbody != null)
                    {
                        cloneRigidbody.velocity = clone.transform.forward * Speed;
                    }
                }
            }
        }
Exemple #3
0
        protected virtual void LateUpdate()
        {
            if (particles != null)
            {
                var mousePosition = (Vector2)Input.mousePosition;

                if (Input.GetMouseButton(0) == true && P3dInputManager.PointOverGui(mousePosition) == false)
                {
                    if (storeStates == true && particles.isPlaying == false)
                    {
                        P3dStateManager.StoreAllStates();
                    }

                    particles.Play();
                }
                else
                {
                    particles.Stop();
                }
            }

            if (aimSensitivity != 0.0f)
            {
                var sensitivity = AimSensitivity / Screen.width;
                var aimX        = (Input.mousePosition.y - Screen.width * 0.5f) * sensitivity;
                var aimY        = (Input.mousePosition.x - Screen.height * 0.5f) * sensitivity;

                transform.localRotation = Quaternion.Euler(-aimX, aimY, 0.0f);
            }
        }
Exemple #4
0
        protected virtual void Update()
        {
            if (prefab != null && Input.GetMouseButtonDown(0) == true && P3dInputManager.PointOverGui(Input.mousePosition) == false)
            {
                var camera = P3dHelper.GetCamera();

                if (camera != null)
                {
                    if (storeStates == true)
                    {
                        P3dStateManager.StoreAllStates();
                    }

                    // Find the ray for this screen position
                    var ray      = camera.ScreenPointToRay(Input.mousePosition);
                    var rotation = Quaternion.LookRotation(ray.direction);

                    // Loop through all prefabs and spawn them
                    var clone = Instantiate(prefab, ray.origin, rotation);

                    // Throw with velocity?
                    var cloneRigidbody = clone.GetComponent <Rigidbody>();

                    if (cloneRigidbody != null)
                    {
                        cloneRigidbody.velocity = clone.transform.forward * Speed;
                    }
                }
            }
        }
Exemple #5
0
        private void PaintEvery(Link link, bool down)
        {
            if (down == true)
            {
                if (storeStates == true)
                {
                    P3dStateManager.StoreAllStates();
                }
            }

            RecordAndPaintAt(link, link.Finger.ScreenPosition, link.ScreenOld, false, link.Finger.Pressure, link);
        }
Exemple #6
0
        private void PaintRelease(Link link, bool down)
        {
            var preview = true;

            if (link.Finger.Up == true)
            {
                preview = false;

                if (storeStates == true)
                {
                    P3dStateManager.StoreAllStates();
                }
            }

            RecordAndPaintAt(link, link.Finger.ScreenPosition, link.ScreenOld, preview, link.Finger.Pressure, link);
        }
Exemple #7
0
        protected void LateUpdate()
        {
            for (var i = fingers.Count - 1; i >= 0; i--)
            {
                var finger = fingers[i];

                if (finger.Index == P3dInputManager.HOVER_FINGER_INDEX)
                {
                    continue;
                }

                if (finger.Up == true)
                {
                    if (storeStates == true)
                    {
                        P3dStateManager.StoreAllStates();
                    }
                }

                switch (frequency)
                {
                case FrequencyType.StartAndEnd: PaintStartEnd(finger); break;

                case FrequencyType.PixelInterval: PaintStartInterval(finger, interval, false); break;

                case FrequencyType.ScaledPixelInterval: PaintStartInterval(finger, interval / P3dInputManager.ScaleFactor, false); break;

                case FrequencyType.StretchedPixelInterval: PaintStartInterval(finger, interval, true); break;

                case FrequencyType.StretchedScaledPixelInterval: PaintStartInterval(finger, interval / P3dInputManager.ScaleFactor, true); break;

                case FrequencyType.Start: PaintOne(finger, 0.0f); break;

                case FrequencyType.End: PaintOne(finger, 1.0f); break;
                }

                connector.BreakHits(finger);

                if (finger.Up == true)
                {
                    fingers.Remove(finger);
                }
            }
        }
		protected virtual void LateUpdate()
		{
			if (target != null)
			{
				if (Pressing() == true)
				{
					if (storeStates == true && target.isPlaying == false)
					{
						P3dStateManager.StoreAllStates();
					}

					target.Play();
				}
				else
				{
					target.Stop();
				}
			}
		}
        protected virtual void Update()
        {
            if (target != null)
            {
                if (P3dInputManager.IsPressed(key) == true)
                {
                    if (storeStates == true && target.enabled == false)
                    {
                        P3dStateManager.StoreAllStates();
                    }

                    target.enabled = true;
                }
                else
                {
                    target.enabled = false;
                }
            }
        }
Exemple #10
0
        private void PaintSmooth(Link link, bool down, float pixelSpacing)
        {
            var head = link.Finger.GetSmoothScreenPosition(0.0f);

            if (down == true)
            {
                if (storeStates == true)
                {
                    P3dStateManager.StoreAllStates();
                }

                RecordAndPaintAt(link, link.Finger.ScreenPosition, link.ScreenOld, false, link.Finger.Pressure, link);
            }

            if (pixelSpacing > 0.0f)
            {
                var steps = Mathf.Max(1, Mathf.FloorToInt(link.Finger.SmoothScreenPositionDelta));
                var step  = P3dHelper.Reciprocal(steps);

                for (var i = 0; i <= steps; i++)
                {
                    var next = link.Finger.GetSmoothScreenPosition(Mathf.Clamp01(i * step));
                    var dist = Vector2.Distance(head, next);
                    var gaps = Mathf.FloorToInt((link.Distance + dist) / pixelSpacing);

                    for (var j = 0; j < gaps; j++)
                    {
                        var remainder = pixelSpacing - link.Distance;

                        head = Vector2.MoveTowards(head, next, remainder);

                        RecordAndPaintAt(link, head, link.History[link.History.Count - 1], false, link.Finger.Pressure, link);

                        dist -= remainder;

                        link.Distance = 0.0f;
                    }

                    link.Distance += dist;
                    head           = next;
                }
            }
        }
Exemple #11
0
        protected virtual void Update()
        {
            inputManager.Update(key);

            if (prefab != null)
            {
                var fingers = inputManager.Fingers;

                if (fingers.Count == 1 && fingers[0].Down == true && fingers[0].StartedOverGui == false)
                {
                    var camera = P3dHelper.GetCamera();

                    if (camera != null)
                    {
                        if (storeStates == true)
                        {
                            P3dStateManager.StoreAllStates();
                        }

                        // Find the ray for this screen position
                        var ray      = camera.ScreenPointToRay(P3dInputManager.MousePosition);
                        var rotation = Quaternion.LookRotation(ray.direction);

                        // Loop through all prefabs and spawn them
                        var clone = Instantiate(prefab, ray.origin, rotation);

                        clone.SetActive(true);

                        // Throw with velocity?
                        var cloneRigidbody = clone.GetComponent <Rigidbody>();

                        if (cloneRigidbody != null)
                        {
                            cloneRigidbody.velocity = clone.transform.forward * Speed;
                        }
                    }
                }
            }
        }
        protected virtual void LateUpdate()
        {
            if (target != null)
            {
                if (key >= KeyCode.Mouse0 || key <= KeyCode.Mouse6)
                {
                }

                if (P3dInputManager.IsPressed(key) == true)
                {
                    if (storeStates == true && target.isPlaying == false)
                    {
                        P3dStateManager.StoreAllStates();
                    }

                    target.Play();
                }
                else
                {
                    target.Stop();
                }
            }
        }
        protected virtual void Paint(P3dInputManager.Finger finger)
        {
            var link = GetLink(finger);

            if (dragStep > 0.0f)
            {
                if (finger.Down == true)
                {
                    link.LastPoint = finger.ScreenPosition;

                    if (storeStates == true)
                    {
                        P3dStateManager.StoreAllStates();
                    }

                    PaintAt(finger.ScreenPosition, false, finger.Pressure);
                }

                var steps = CalculateSteps(finger.ScreenPosition - link.LastPoint);

                if (steps > 0)
                {
                    var step           = P3dHelper.Reciprocal(steps);
                    var screenPosition = default(Vector2);

                    for (var i = 1; i <= steps; i++)
                    {
                        screenPosition = Vector2.Lerp(link.LastPoint, finger.ScreenPosition, i * step);

                        PaintAt(screenPosition, false, finger.Pressure);
                    }

                    link.LastPoint = screenPosition;
                }
            }
            else
            {
                if (showPreview == true)
                {
                    if (finger.Up == true)
                    {
                        if (storeStates == true)
                        {
                            P3dStateManager.StoreAllStates();
                        }

                        PaintAt(finger.ScreenPosition, false, finger.Pressure);
                    }
                    else
                    {
                        PaintAt(finger.ScreenPosition, true, finger.Pressure);
                    }
                }
                else if (finger.Down == true)
                {
                    if (storeStates == true)
                    {
                        P3dStateManager.StoreAllStates();
                    }

                    PaintAt(finger.ScreenPosition, false, finger.Pressure);
                }
            }
        }
Exemple #14
0
        private void Paint(P3dInputManager.Finger finger, bool down, bool up)
        {
            var link = GetLink(finger);

            if (spacing > 0.0f)
            {
                var tail = finger.SmoothPositions[0];

                if (down == true)
                {
                    link.Distance = 0.0f;

                    if (storeStates == true)
                    {
                        P3dStateManager.StoreAllStates();
                    }

                    PaintAt(link, tail, false, finger.Pressure, link);
                }

                if (finger.SmoothPositions.Count > 1)
                {
                    for (var i = 1; i < finger.SmoothPositions.Count; i++)
                    {
                        var head  = finger.SmoothPositions[i];
                        var dist  = Vector2.Distance(tail, head);
                        var steps = Mathf.FloorToInt((link.Distance + dist) / spacing);

                        for (var j = 0; j < steps; j++)
                        {
                            var remainder = spacing - link.Distance;

                            tail = Vector2.MoveTowards(tail, head, remainder);

                            PaintAt(link, tail, false, finger.Pressure, link);

                            dist -= remainder;

                            link.Distance = 0.0f;
                        }

                        link.Distance += dist;

                        tail = head;
                    }
                }
                else
                {
                    SubmitLastPoint(false, link);
                }
            }
            else
            {
                var preview = true;

                if (showPreview == true)
                {
                    if (spacing == 0.0f)                     // Once
                    {
                        if (up == true)
                        {
                            if (storeStates == true)
                            {
                                P3dStateManager.StoreAllStates();
                            }

                            preview = false;
                        }
                    }
                    else                     // Every frame
                    {
                        if (storeStates == true && down == true)
                        {
                            P3dStateManager.StoreAllStates();
                        }

                        preview = false;
                    }
                }
                else
                {
                    if (spacing == 0.0f)                     // Once
                    {
                        if (down == true)
                        {
                            if (storeStates == true)
                            {
                                P3dStateManager.StoreAllStates();
                            }
                        }
                        else
                        {
                            return;
                        }
                    }
                    else                     // Every frame
                    {
                        if (storeStates == true && down == true)
                        {
                            P3dStateManager.StoreAllStates();
                        }
                    }

                    preview = false;
                }

                PaintAt(link, finger.PositionA, preview, finger.Pressure, link);
            }

            if (up == true)
            {
                BreakHits(link);

                if (fill == FillType.GridOfPoints)
                {
                    PaintGridOfPoints(link);
                }

                link.History.Clear();
            }
        }
Exemple #15
0
 public void RedoAll()
 {
     P3dStateManager.RedoAll();
 }
Exemple #16
0
        protected override void OnInspector()
        {
            var paintables        = FindObjectsOfType <P3dPaintable>();
            var paintableTextures = FindObjectsOfType <P3dPaintableTexture>();

            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
            EditorGUI.BeginDisabledGroup(P3dStateManager.CanUndo == false);
            if (GUILayout.Button(new GUIContent("◄", "Undo"), EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)) == true)
            {
                P3dStateManager.UndoAll();
            }
            EditorGUI.EndDisabledGroup();
            EditorGUI.BeginDisabledGroup(P3dStateManager.CanRedo == false);
            if (GUILayout.Button(new GUIContent("►", "Redo"), EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)) == true)
            {
                P3dStateManager.RedoAll();
            }
            EditorGUI.EndDisabledGroup();

            if (GUILayout.Toggle(currentPage == PageType.Scene, "Scene", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)) == true)
            {
                currentPage = PageType.Scene; selectingTool = selectingMaterial = selectingShape = false;
            }

            if (GUILayout.Toggle(currentPage == PageType.Camera, "Camera", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)) == true)
            {
                currentPage = PageType.Camera;
            }

            if (GUILayout.Toggle(currentPage == PageType.Paint, "Paint", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)) == true)
            {
                currentPage = PageType.Paint;
            }

            if (GUILayout.Toggle(currentPage == PageType.Config, "Config", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)) == true)
            {
                currentPage = PageType.Config;
            }

            EditorGUILayout.Separator();
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();

            if (Application.isPlaying == true)
            {
                if (Settings.CurrentTool == null && P3dTool.CachedTools.Count > 0)
                {
                    Settings.CurrentTool = P3dTool.CachedTools[0];
                }

                if (Settings.CurrentMaterial == null && P3dMaterial.CachedMaterials.Count > 0)
                {
                    Settings.CurrentMaterial = P3dMaterial.CachedMaterials[0];
                }

                if (Settings.CurrentShape == null && P3dShape.CachedShapes.Count > 0)
                {
                    Settings.CurrentShape = P3dShape.CachedShapes[0];
                }
            }
            else
            {
                ClearMaterial();
                ClearTool();
            }

            switch (currentPage)
            {
            case PageType.Scene:
            {
                DrawSceneTab(paintables, paintableTextures);
            }
            break;

            case PageType.Camera:
            {
                DrawCameraTab();
            }
            break;

            case PageType.Paint:
            {
                DrawPaintTab();
            }
            break;

            case PageType.Config:
            {
                DrawConfigTab();
            }
            break;
            }
        }
Exemple #17
0
 public void UndoAll()
 {
     P3dStateManager.UndoAll();
 }
Exemple #18
0
        private void Paint(P3dInputManager.Finger finger, bool down, bool up)
        {
            var link = GetLink(finger);

            if (spacing > 0.0f)
            {
                var head = finger.GetSmoothScreenPosition(0.0f);

                if (down == true)
                {
                    if (storeStates == true)
                    {
                        P3dStateManager.StoreAllStates();
                    }

                    PaintAt(link, head, false, finger.Pressure, link);
                }

                var steps = Mathf.Max(1, Mathf.FloorToInt(finger.SmoothScreenPositionDelta));
                var step  = P3dHelper.Reciprocal(steps);

                for (var i = 0; i <= steps; i++)
                {
                    var next = finger.GetSmoothScreenPosition(Mathf.Clamp01(i * step));
                    var dist = Vector2.Distance(head, next);
                    var gaps = Mathf.FloorToInt((link.Distance + dist) / spacing);

                    for (var j = 0; j < gaps; j++)
                    {
                        var remainder = spacing - link.Distance;

                        head = Vector2.MoveTowards(head, next, remainder);

                        PaintAt(link, head, false, finger.Pressure, link);

                        dist -= remainder;

                        link.Distance = 0.0f;
                    }

                    link.Distance += dist;
                    head           = next;
                }
            }
            else
            {
                var preview = true;

                if (showPreview == true)
                {
                    if (spacing == 0.0f)                     // Once
                    {
                        if (up == true)
                        {
                            if (storeStates == true)
                            {
                                P3dStateManager.StoreAllStates();
                            }

                            preview = false;
                        }
                    }
                    else                     // Every frame
                    {
                        if (storeStates == true && down == true)
                        {
                            P3dStateManager.StoreAllStates();
                        }

                        preview = false;
                    }
                }
                else
                {
                    if (spacing == 0.0f)                     // Once
                    {
                        if (down == true)
                        {
                            if (storeStates == true)
                            {
                                P3dStateManager.StoreAllStates();
                            }
                        }
                        else
                        {
                            return;
                        }
                    }
                    else                     // Every frame
                    {
                        if (storeStates == true && down == true)
                        {
                            P3dStateManager.StoreAllStates();
                        }
                    }

                    preview = false;
                }

                PaintAt(link, finger.PositionA, preview, finger.Pressure, link);
            }

            if (up == true)
            {
                BreakHits(link);

                if (draw == DrawType.PointsIn3DFilled)
                {
                    PaintGridOfPoints(link);
                }

                link.Clear();
            }
        }
Exemple #19
0
        private void Paint(P3dInputManager.Finger finger, bool down, bool up)
        {
            var link = GetLink(finger);

            if (spacing > 0.0f)
            {
                var tail = finger.SmoothPositions[0];

                if (down == true)
                {
                    link.Distance = 0.0f;

                    if (storeStates == true)
                    {
                        P3dStateManager.StoreAllStates();
                    }

                    PaintAt(tail, false, finger.Pressure, link);
                }

                for (var i = 1; i < finger.SmoothPositions.Count; i++)
                {
                    var head  = finger.SmoothPositions[i];
                    var dist  = Vector2.Distance(tail, head);
                    var steps = Mathf.FloorToInt((link.Distance + dist) / spacing);

                    for (var j = 0; j < steps; j++)
                    {
                        var remainder = spacing - link.Distance;

                        tail = Vector2.MoveTowards(tail, head, remainder);

                        PaintAt(tail, false, finger.Pressure, link);

                        dist -= remainder;

                        link.Distance = 0.0f;
                    }

                    link.Distance += dist;

                    tail = head;
                }
            }
            else
            {
                if (showPreview == true)
                {
                    if (up == true)
                    {
                        if (storeStates == true)
                        {
                            P3dStateManager.StoreAllStates();
                        }

                        PaintAt(finger.PositionA, false, finger.Pressure, link);
                    }
                    else
                    {
                        PaintAt(finger.PositionA, true, finger.Pressure, link);
                    }
                }
                else if (down == true)
                {
                    if (storeStates == true)
                    {
                        P3dStateManager.StoreAllStates();
                    }

                    PaintAt(finger.PositionA, false, finger.Pressure, link);
                }
            }

            if (up == true)
            {
                BreakHits(link);
            }
        }
        public void UpdateGripped(P3dVrManager vrManager)
        {
            // Position?
            var position    = default(Vector3);
            var positionSet = false;

            if (vrManager.TryGetPosition(node, ref position) == true)
            {
                positionSet = true;

                if (vrManager.IsSimulation == true)
                {
                    position += transform.rotation * localOffset;

                    if (vrManager.GetTrigger(node) == true)
                    {
                        position += transform.rotation * simulatedKeyOffset;
                    }
                }

                position += transform.rotation * simulatedOffset;
            }

            // Rotation?
            var rotation    = default(Quaternion);
            var rotationSet = false;

            if (vrManager.TryGetRotation(node, ref rotation) == true)
            {
                rotationSet = true;
            }

            // Transition?
            var dampening = 1.0f;

            if (vrManager.IsSimulation == true)
            {
                dampening = P3dHelper.DampenFactor(simulatedDampening, Time.deltaTime);
            }

            if (positionSet == true)
            {
                transform.position = Vector3.Lerp(transform.position, position, dampening);
            }

            if (rotationSet == true)
            {
                transform.rotation = Quaternion.Slerp(transform.rotation, rotation, dampening);
            }

            // Events?
            if (vrManager.GetTriggerPressed(node) == true)
            {
                if (storeStates == true)
                {
                    P3dStateManager.StoreAllStates();
                }

                if (onTriggerPress != null)
                {
                    onTriggerPress.Invoke();
                }
            }

            if (vrManager.GetTriggerReleased(node) == true)
            {
                if (onTriggerRelease != null)
                {
                    onTriggerRelease.Invoke();
                }
            }

            if (vrManager.GetGripPressed(node) == true)
            {
                if (onGripPress != null)
                {
                    onGripPress.Invoke();
                }
            }

            if (vrManager.GetGripReleased(node) == true)
            {
                if (onGripRelease != null)
                {
                    onGripRelease.Invoke();
                }
            }
        }