Example #1
0
    public IEnumerator Appear()
    {
        List <MeshRenderer>           mRends = new List <MeshRenderer>();
        List <ParticleSystemRenderer> pRends = new List <ParticleSystemRenderer>();

        foreach (GameObject p in platforms)
        {
            p.SetActive(true);
            MeshRenderer[] ms = p.GetComponentsInChildren <MeshRenderer>();
            foreach (MeshRenderer m in ms)
            {
                m.sharedMaterial = mMat;
                mRends.Add(m);
            }
            ParticleSystemRenderer[] ps = p.GetComponentsInChildren <ParticleSystemRenderer>();
            foreach (ParticleSystemRenderer pr in ps)
            {
                pr.sharedMaterial = pMat;
                pRends.Add(pr);
            }
        }
        Color mC = mMat.GetColor("_Color");
        Color mP = pMat.GetColor("_Color");

        mMat.SetColor("_Color", mC.A(0));
        pMat.SetColor("_Color", mP.A(0));
        float t = 0;

        while (true)
        {
            t = Mathf.Min(t, 1);
            mMat.SetColor("_Color", Color.Lerp(mC.A(0), mC, t));
            //pMat.SetColor("_Color", Color.Lerp(mP.A(0), mP, t));
            if (t >= 1)
            {
                break;
            }
            float duration = t > 230f / 255f ? 5f : (t > 200f / 255f ? 2f : 0.5f);
            t += Time.deltaTime / duration;
            yield return(null);
        }

        for (int i = 0; i < platforms.Count; ++i)
        {
            if (mRends[i].sharedMaterial == mMat)
            {
                mRends[i].sharedMaterial = defaultM;
                pRends[i].sharedMaterial = defaultP;
            }
        }

        Destroy(gameObject);
        yield return(null);
    }
Example #2
0
        private void CreateCreatureExplosion(Creature creature, CreaturePart part)
        {
            GameObject obj = new GameObject("CreatureExplosionFX");

            obj.transform.position = part.transform.position;

            KSPParticleEmitter particles = obj.AddComponent <KSPParticleEmitter> ();

            CreateKSPParticleEmitter(particles);

            Color color = (Settings.AllowCreatureGore ? creature.Gore.bloodColor : creature.Gore.skinColor);

            particles.color              = color;
            particles.doesAnimateColor   = true;
            particles.colorAnimation     = new Color[5];
            particles.colorAnimation [0] = color;
            particles.colorAnimation [1] = color.A(0.8f);
            particles.colorAnimation [2] = color.A(0.4f);
            particles.colorAnimation [3] = color.A(0.2f);
            particles.colorAnimation [4] = color.A(0f);

            Texture2D bloodParticleTexture = new Texture2D(4, 4);

            bloodParticleTexture.LoadImage(Textures.CreatureBloodExplosionParticle);
            particles.material.SetTexture("_MainTex", bloodParticleTexture);

            particles.maxEmission     = 1000;
            particles.maxEnergy       = 1.5f;
            particles.maxParticleSize = 2.5f;
            particles.maxSize         = 3.5f;
            particles.minEmission     = 1000;
            particles.minEnergy       = 0.5f;
            particles.minSize         = 2f;

            particles.damping            = 0.9f;
            particles.force              = FlightGlobals.getGeeForceAtPosition(obj.transform.position) * 2.5f;
            particles.rndAngularVelocity = 0f;
            particles.rndRotation        = true;
            particles.rndForce           = Vector3.one * 4f * creature.Gore.bloodVelocityMultiplier;
            particles.rndVelocity        = Vector3.one * 8f * creature.Gore.bloodVelocityMultiplier;
            particles.shape3D            = Vector3.one * creature.Gore.bloodSphereSize;

            CreatureExplosion creatureExplosion = obj.AddComponent <CreatureExplosion> ();

            creatureExplosion.particles = particles;
        }
Example #3
0
        protected void DrawSegment(float3 A, float3 B, Color col)
        {
            float3
                nrm = Maths.NormalDir(A, B, float3(0f, 0f, 1f)) * (distance(A, B) * 0.2f),
                mid = lerp(A, B, 0.5f);

            Nebukam.Common.Editor.Draw.Line(mid, mid + nrm, col.A(0.5f));
            Nebukam.Common.Editor.Draw.Line(A, B, col);
        }
Example #4
0
        /// <summary>
        /// 反色
        /// </summary>
        /// <param name="c">C.</param>
        public static Color Opposite(Color c)
        {
            int r = c.R();
            int g = c.G();
            int b = c.B();
            int a = c.A();

            return(FromArgb(a, 255 - r, 255 - g, 255 - b));
        }
Example #5
0
//		public static Color RGB2GRAY (Color c)
//		{
//			int r = c.R ();
//			int g = c.G ();
//			int b = c.B ();
//			int a = c.A ();
//
//			int gray = (int)(r * 0.3f + g * 0.59f + b * 0.11f);
//			gray += (255 - gray) / 4;
//			return FromArgb (a, gray, gray, gray);
//		}

        public static Color RGB2GRAY(Color c)
        {
            float gray = c.r * 0.3f + c.g * 0.59f + c.b * 0.11f;
            float tDis = 0.35f;

            gray *= 1f - (tDis * 2);
            gray += tDis * 1.2f;
            int tGray = (int)(gray * 255);

            return(FromArgb(c.A(), tGray, tGray, tGray));
        }
Example #6
0
        public override void Draw(WriteableBitmap bitmap, Vector2<int> point, Color color, int size, BlendModes? mode)
        {
            var d = (size.Double() / 2.0).Round();
            double x1 = point.X - d, y1 = point.Y - d;
            double x2 = point.X + size - d, y2 = point.Y + size - d;

            if (Hardness < 1)
            {
                var bytes = GetBytes(size);
                bitmap.FillRectangle(x1.Int32(), y1.Int32(), bytes.Transform(i => color.A(i)), mode);
                return;
            }

            bitmap.FillEllipse(x1.Int32(), y1.Int32(), x2.Int32() - 1, y2.Int32() - 1, color, mode);
        }
        private void OnDrawGizmos()
        {
            if (noDebug)
            {
                return;
            }

            model = slotModel?.model;

            if (model == null)
            {
                return;
            }

            brain = new ClusterBrain()
            {
                m_pos         = transform.position,
                m_clusterSize = gridSize
            };

            brain.slotModel = model;


            float3 from = transform.position, pos;

            Gizmos.color = color.A(0.05f);

            // Draw volume handle
            if (!wireOnly)
            {
                float3 b = gridSize * model.size;
                Gizmos.DrawCube((float3)transform.position + b * 0.5f, b);
            }

            Gizmos.color = color;

            // Draw grid

            ByteTrio coords;
            float3   off = model.size * 0.5f;

            for (int z = 0; z < gridSize.z; z++)
            {
                for (int y = 0; y < gridSize.y; y++)
                {
                    for (int x = 0; x < gridSize.x; x++)
                    {
                        coords = new ByteTrio(x, y, z);
                        pos    = brain.ComputePosition(ref coords);
                        Gizmos.DrawWireCube(pos + off, model.size);
                    }
                }
            }

            // Highlight cluster corresponding to active selection

            GameObject[] selection = Selection.gameObjects;
            GameObject   go;

            for (int i = 0, count = selection.Length; i < count; i++)
            {
                go = selection[i];

                if (go == Selection.activeGameObject)
                {
                    Gizmos.color = Color.green.A(0.5f);
                }
                else
                {
                    Gizmos.color = color.A(0.25f);
                }

                if (go == gameObject || go.transform.parent != transform)
                {
                    continue;
                }

                pos = go.transform.position;
                if (brain.TryGetCoordOf(pos, out coords))
                {
                    pos = brain.ComputePosition(ref coords);
                    Gizmos.DrawCube(pos + off, model.size);
                }
            }
        }
Example #8
0
        /// <summary>
        /// Generates planet maps from a PQS
        /// </summary>
        private void GenerateMaps(Int32 width, Body body, PQSMod[] mods, Boolean hasOcean, Double oceanHeight,
                                  Color oceanColor, Single normalStrength, out Texture2D colorMap, out Texture2D heightMap, out Texture2D normalMap)
        {
            // Generate the textures
            Int32 height = width / 2;

            colorMap  = new Texture2D(width, height, TextureFormat.ARGB32, true);
            heightMap = new Texture2D(width, height, TextureFormat.RGB24, true);

            // Create a VertexBuildData
            PQS.VertexBuildData data = new PQS.VertexBuildData();
            Vector3             direction;

            // Build the textures
            for (Int32 y = 0; y < height; y++)
            {
                for (Int32 x = 0; x < width; x++)
                {
                    // Update the build data
                    data.directionFromCenter = QuaternionD.AngleAxis(360d / width * x, Vector3d.up) *
                                               QuaternionD.AngleAxis(90d - 180d / height * y, Vector3d.right) *
                                               Vector3d.forward;
                    data.vertHeight = body.pqs.Value.radius;

                    // Map coords
                    data.latitude = Math.Asin(data.directionFromCenter.y);
                    if (double.IsNaN(data.latitude))
                    {
                        data.latitude = 1.5707963267948966;
                    }
                    direction = new Vector3d(data.directionFromCenter.x, 0.0, data.directionFromCenter.z).normalized;
                    if (direction.magnitude > 0.0)
                    {
                        data.longitude = direction.z >= 0.0 ? Math.Asin(direction.x) : Math.PI - Math.Asin(direction.x);
                    }
                    else
                    {
                        data.longitude = 0.0;
                    }
                    data.v = data.latitude / 3.1415926535897931 + 0.5;
                    data.u = data.longitude / 3.1415926535897931 * 0.5;

                    // Build the height data
                    for (Int32 i = 0; i < mods.Length; i++)
                    {
                        mods[i].OnVertexBuildHeight(data);
                    }

                    // Build the color data
                    for (Int32 i = 0; i < mods.Length; i++)
                    {
                        mods[i].OnVertexBuild(data);
                    }

                    // Process the height
                    Single h = (Single)((data.vertHeight - body.pqs.Value.radius) *
                                        (1d / body.pqs.Value.mapMaxHeight));
                    if (h < 0)
                    {
                        h = 0;
                    }
                    else if (h > 1)
                    {
                        h = 1;
                    }
                    heightMap.SetPixel(x, y, new Color(h, h, h));

                    // Process the color
                    if (hasOcean)
                    {
                        if (h <= oceanHeight)
                        {
                            colorMap.SetPixel(x, y, oceanColor.A(1f));
                        }
                        else
                        {
                            colorMap.SetPixel(x, y, data.vertColor.A(0f));
                        }
                    }
                    else
                    {
                        colorMap.SetPixel(x, y, data.vertColor.A(1f));
                    }
                }
            }

            // Generate the normalmap
            normalMap = Utility.BumpToNormalMap(heightMap, normalStrength);
        }